]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.13.0-201401281848.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.13.0-201401281848.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 b8b7f74..1f3d7c8 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..bf69468 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, ____m(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(____m(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 cbb1571..47952f5 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..c2c7f17
64114 --- /dev/null
64115 +++ b/grsecurity/Kconfig
64116 @@ -0,0 +1,1146 @@
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 + help
64334 + If you say Y here, the layouts of a number of sensitive kernel
64335 + structures (task, fs, cred, etc) and all structures composed entirely
64336 + of function pointers (aka "ops" structs) will be randomized at compile-time.
64337 + This can introduce the requirement of an additional infoleak
64338 + vulnerability for exploits targeting these structure types.
64339 +
64340 + Enabling this feature will introduce some performance impact, slightly
64341 + increase memory usage, and prevent the use of forensic tools like
64342 + Volatility against the system (unless the kernel source tree isn't
64343 + cleaned after kernel installation).
64344 +
64345 + The seed used for compilation is located at tools/gcc/randstruct.seed.
64346 + It remains after a make clean to allow for external modules to be compiled
64347 + with the existing seed and will be removed by a make mrproper or
64348 + make distclean.
64349 +
64350 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
64351 + bool "Use cacheline-aware structure randomization"
64352 + depends on GRKERNSEC_RANDSTRUCT
64353 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
64354 + help
64355 + If you say Y here, the RANDSTRUCT randomization will make a best effort
64356 + at restricting randomization to cacheline-sized groups of elements. It
64357 + will further not randomize bitfields in structures. This reduces the
64358 + performance hit of RANDSTRUCT at the cost of weakened randomization.
64359 +
64360 +config GRKERNSEC_KERN_LOCKOUT
64361 + bool "Active kernel exploit response"
64362 + default y if GRKERNSEC_CONFIG_AUTO
64363 + depends on X86 || ARM || PPC || SPARC
64364 + help
64365 + If you say Y here, when a PaX alert is triggered due to suspicious
64366 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
64367 + or an OOPS occurs due to bad memory accesses, instead of just
64368 + terminating the offending process (and potentially allowing
64369 + a subsequent exploit from the same user), we will take one of two
64370 + actions:
64371 + If the user was root, we will panic the system
64372 + If the user was non-root, we will log the attempt, terminate
64373 + all processes owned by the user, then prevent them from creating
64374 + any new processes until the system is restarted
64375 + This deters repeated kernel exploitation/bruteforcing attempts
64376 + and is useful for later forensics.
64377 +
64378 +config GRKERNSEC_OLD_ARM_USERLAND
64379 + bool "Old ARM userland compatibility"
64380 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
64381 + help
64382 + If you say Y here, stubs of executable code to perform such operations
64383 + as "compare-exchange" will be placed at fixed locations in the ARM vector
64384 + table. This is unfortunately needed for old ARM userland meant to run
64385 + across a wide range of processors. Without this option enabled,
64386 + the get_tls and data memory barrier stubs will be emulated by the kernel,
64387 + which is enough for Linaro userlands or other userlands designed for v6
64388 + and newer ARM CPUs. It's recommended that you try without this option enabled
64389 + first, and only enable it if your userland does not boot (it will likely fail
64390 + at init time).
64391 +
64392 +endmenu
64393 +menu "Role Based Access Control Options"
64394 +depends on GRKERNSEC
64395 +
64396 +config GRKERNSEC_RBAC_DEBUG
64397 + bool
64398 +
64399 +config GRKERNSEC_NO_RBAC
64400 + bool "Disable RBAC system"
64401 + help
64402 + If you say Y here, the /dev/grsec device will be removed from the kernel,
64403 + preventing the RBAC system from being enabled. You should only say Y
64404 + here if you have no intention of using the RBAC system, so as to prevent
64405 + an attacker with root access from misusing the RBAC system to hide files
64406 + and processes when loadable module support and /dev/[k]mem have been
64407 + locked down.
64408 +
64409 +config GRKERNSEC_ACL_HIDEKERN
64410 + bool "Hide kernel processes"
64411 + help
64412 + If you say Y here, all kernel threads will be hidden to all
64413 + processes but those whose subject has the "view hidden processes"
64414 + flag.
64415 +
64416 +config GRKERNSEC_ACL_MAXTRIES
64417 + int "Maximum tries before password lockout"
64418 + default 3
64419 + help
64420 + This option enforces the maximum number of times a user can attempt
64421 + to authorize themselves with the grsecurity RBAC system before being
64422 + denied the ability to attempt authorization again for a specified time.
64423 + The lower the number, the harder it will be to brute-force a password.
64424 +
64425 +config GRKERNSEC_ACL_TIMEOUT
64426 + int "Time to wait after max password tries, in seconds"
64427 + default 30
64428 + help
64429 + This option specifies the time the user must wait after attempting to
64430 + authorize to the RBAC system with the maximum number of invalid
64431 + passwords. The higher the number, the harder it will be to brute-force
64432 + a password.
64433 +
64434 +endmenu
64435 +menu "Filesystem Protections"
64436 +depends on GRKERNSEC
64437 +
64438 +config GRKERNSEC_PROC
64439 + bool "Proc restrictions"
64440 + default y if GRKERNSEC_CONFIG_AUTO
64441 + help
64442 + If you say Y here, the permissions of the /proc filesystem
64443 + will be altered to enhance system security and privacy. You MUST
64444 + choose either a user only restriction or a user and group restriction.
64445 + Depending upon the option you choose, you can either restrict users to
64446 + see only the processes they themselves run, or choose a group that can
64447 + view all processes and files normally restricted to root if you choose
64448 + the "restrict to user only" option. NOTE: If you're running identd or
64449 + ntpd as a non-root user, you will have to run it as the group you
64450 + specify here.
64451 +
64452 +config GRKERNSEC_PROC_USER
64453 + bool "Restrict /proc to user only"
64454 + depends on GRKERNSEC_PROC
64455 + help
64456 + If you say Y here, non-root users will only be able to view their own
64457 + processes, and restricts them from viewing network-related information,
64458 + and viewing kernel symbol and module information.
64459 +
64460 +config GRKERNSEC_PROC_USERGROUP
64461 + bool "Allow special group"
64462 + default y if GRKERNSEC_CONFIG_AUTO
64463 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
64464 + help
64465 + If you say Y here, you will be able to select a group that will be
64466 + able to view all processes and network-related information. If you've
64467 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
64468 + remain hidden. This option is useful if you want to run identd as
64469 + a non-root user. The group you select may also be chosen at boot time
64470 + via "grsec_proc_gid=" on the kernel commandline.
64471 +
64472 +config GRKERNSEC_PROC_GID
64473 + int "GID for special group"
64474 + depends on GRKERNSEC_PROC_USERGROUP
64475 + default 1001
64476 +
64477 +config GRKERNSEC_PROC_ADD
64478 + bool "Additional restrictions"
64479 + default y if GRKERNSEC_CONFIG_AUTO
64480 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
64481 + help
64482 + If you say Y here, additional restrictions will be placed on
64483 + /proc that keep normal users from viewing device information and
64484 + slabinfo information that could be useful for exploits.
64485 +
64486 +config GRKERNSEC_LINK
64487 + bool "Linking restrictions"
64488 + default y if GRKERNSEC_CONFIG_AUTO
64489 + help
64490 + If you say Y here, /tmp race exploits will be prevented, since users
64491 + will no longer be able to follow symlinks owned by other users in
64492 + world-writable +t directories (e.g. /tmp), unless the owner of the
64493 + symlink is the owner of the directory. users will also not be
64494 + able to hardlink to files they do not own. If the sysctl option is
64495 + enabled, a sysctl option with name "linking_restrictions" is created.
64496 +
64497 +config GRKERNSEC_SYMLINKOWN
64498 + bool "Kernel-enforced SymlinksIfOwnerMatch"
64499 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
64500 + help
64501 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
64502 + that prevents it from being used as a security feature. As Apache
64503 + verifies the symlink by performing a stat() against the target of
64504 + the symlink before it is followed, an attacker can setup a symlink
64505 + to point to a same-owned file, then replace the symlink with one
64506 + that targets another user's file just after Apache "validates" the
64507 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
64508 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
64509 + will be in place for the group you specify. If the sysctl option
64510 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
64511 + created.
64512 +
64513 +config GRKERNSEC_SYMLINKOWN_GID
64514 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
64515 + depends on GRKERNSEC_SYMLINKOWN
64516 + default 1006
64517 + help
64518 + Setting this GID determines what group kernel-enforced
64519 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
64520 + is enabled, a sysctl option with name "symlinkown_gid" is created.
64521 +
64522 +config GRKERNSEC_FIFO
64523 + bool "FIFO restrictions"
64524 + default y if GRKERNSEC_CONFIG_AUTO
64525 + help
64526 + If you say Y here, users will not be able to write to FIFOs they don't
64527 + own in world-writable +t directories (e.g. /tmp), unless the owner of
64528 + the FIFO is the same owner of the directory it's held in. If the sysctl
64529 + option is enabled, a sysctl option with name "fifo_restrictions" is
64530 + created.
64531 +
64532 +config GRKERNSEC_SYSFS_RESTRICT
64533 + bool "Sysfs/debugfs restriction"
64534 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64535 + depends on SYSFS
64536 + help
64537 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
64538 + any filesystem normally mounted under it (e.g. debugfs) will be
64539 + mostly accessible only by root. These filesystems generally provide access
64540 + to hardware and debug information that isn't appropriate for unprivileged
64541 + users of the system. Sysfs and debugfs have also become a large source
64542 + of new vulnerabilities, ranging from infoleaks to local compromise.
64543 + There has been very little oversight with an eye toward security involved
64544 + in adding new exporters of information to these filesystems, so their
64545 + use is discouraged.
64546 + For reasons of compatibility, a few directories have been whitelisted
64547 + for access by non-root users:
64548 + /sys/fs/selinux
64549 + /sys/fs/fuse
64550 + /sys/devices/system/cpu
64551 +
64552 +config GRKERNSEC_ROFS
64553 + bool "Runtime read-only mount protection"
64554 + depends on SYSCTL
64555 + help
64556 + If you say Y here, a sysctl option with name "romount_protect" will
64557 + be created. By setting this option to 1 at runtime, filesystems
64558 + will be protected in the following ways:
64559 + * No new writable mounts will be allowed
64560 + * Existing read-only mounts won't be able to be remounted read/write
64561 + * Write operations will be denied on all block devices
64562 + This option acts independently of grsec_lock: once it is set to 1,
64563 + it cannot be turned off. Therefore, please be mindful of the resulting
64564 + behavior if this option is enabled in an init script on a read-only
64565 + filesystem.
64566 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
64567 + and GRKERNSEC_IO should be enabled and module loading disabled via
64568 + config or at runtime.
64569 + This feature is mainly intended for secure embedded systems.
64570 +
64571 +
64572 +config GRKERNSEC_DEVICE_SIDECHANNEL
64573 + bool "Eliminate stat/notify-based device sidechannels"
64574 + default y if GRKERNSEC_CONFIG_AUTO
64575 + help
64576 + If you say Y here, timing analyses on block or character
64577 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
64578 + will be thwarted for unprivileged users. If a process without
64579 + CAP_MKNOD stats such a device, the last access and last modify times
64580 + will match the device's create time. No access or modify events
64581 + will be triggered through inotify/dnotify/fanotify for such devices.
64582 + This feature will prevent attacks that may at a minimum
64583 + allow an attacker to determine the administrator's password length.
64584 +
64585 +config GRKERNSEC_CHROOT
64586 + bool "Chroot jail restrictions"
64587 + default y if GRKERNSEC_CONFIG_AUTO
64588 + help
64589 + If you say Y here, you will be able to choose several options that will
64590 + make breaking out of a chrooted jail much more difficult. If you
64591 + encounter no software incompatibilities with the following options, it
64592 + is recommended that you enable each one.
64593 +
64594 +config GRKERNSEC_CHROOT_MOUNT
64595 + bool "Deny mounts"
64596 + default y if GRKERNSEC_CONFIG_AUTO
64597 + depends on GRKERNSEC_CHROOT
64598 + help
64599 + If you say Y here, processes inside a chroot will not be able to
64600 + mount or remount filesystems. If the sysctl option is enabled, a
64601 + sysctl option with name "chroot_deny_mount" is created.
64602 +
64603 +config GRKERNSEC_CHROOT_DOUBLE
64604 + bool "Deny double-chroots"
64605 + default y if GRKERNSEC_CONFIG_AUTO
64606 + depends on GRKERNSEC_CHROOT
64607 + help
64608 + If you say Y here, processes inside a chroot will not be able to chroot
64609 + again outside the chroot. This is a widely used method of breaking
64610 + out of a chroot jail and should not be allowed. If the sysctl
64611 + option is enabled, a sysctl option with name
64612 + "chroot_deny_chroot" is created.
64613 +
64614 +config GRKERNSEC_CHROOT_PIVOT
64615 + bool "Deny pivot_root in chroot"
64616 + default y if GRKERNSEC_CONFIG_AUTO
64617 + depends on GRKERNSEC_CHROOT
64618 + help
64619 + If you say Y here, processes inside a chroot will not be able to use
64620 + a function called pivot_root() that was introduced in Linux 2.3.41. It
64621 + works similar to chroot in that it changes the root filesystem. This
64622 + function could be misused in a chrooted process to attempt to break out
64623 + of the chroot, and therefore should not be allowed. If the sysctl
64624 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
64625 + created.
64626 +
64627 +config GRKERNSEC_CHROOT_CHDIR
64628 + bool "Enforce chdir(\"/\") on all chroots"
64629 + default y if GRKERNSEC_CONFIG_AUTO
64630 + depends on GRKERNSEC_CHROOT
64631 + help
64632 + If you say Y here, the current working directory of all newly-chrooted
64633 + applications will be set to the the root directory of the chroot.
64634 + The man page on chroot(2) states:
64635 + Note that this call does not change the current working
64636 + directory, so that `.' can be outside the tree rooted at
64637 + `/'. In particular, the super-user can escape from a
64638 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
64639 +
64640 + It is recommended that you say Y here, since it's not known to break
64641 + any software. If the sysctl option is enabled, a sysctl option with
64642 + name "chroot_enforce_chdir" is created.
64643 +
64644 +config GRKERNSEC_CHROOT_CHMOD
64645 + bool "Deny (f)chmod +s"
64646 + default y if GRKERNSEC_CONFIG_AUTO
64647 + depends on GRKERNSEC_CHROOT
64648 + help
64649 + If you say Y here, processes inside a chroot will not be able to chmod
64650 + or fchmod files to make them have suid or sgid bits. This protects
64651 + against another published method of breaking a chroot. If the sysctl
64652 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
64653 + created.
64654 +
64655 +config GRKERNSEC_CHROOT_FCHDIR
64656 + bool "Deny fchdir out of chroot"
64657 + default y if GRKERNSEC_CONFIG_AUTO
64658 + depends on GRKERNSEC_CHROOT
64659 + help
64660 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
64661 + to a file descriptor of the chrooting process that points to a directory
64662 + outside the filesystem will be stopped. If the sysctl option
64663 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
64664 +
64665 +config GRKERNSEC_CHROOT_MKNOD
64666 + bool "Deny mknod"
64667 + default y if GRKERNSEC_CONFIG_AUTO
64668 + depends on GRKERNSEC_CHROOT
64669 + help
64670 + If you say Y here, processes inside a chroot will not be allowed to
64671 + mknod. The problem with using mknod inside a chroot is that it
64672 + would allow an attacker to create a device entry that is the same
64673 + as one on the physical root of your system, which could range from
64674 + anything from the console device to a device for your harddrive (which
64675 + they could then use to wipe the drive or steal data). It is recommended
64676 + that you say Y here, unless you run into software incompatibilities.
64677 + If the sysctl option is enabled, a sysctl option with name
64678 + "chroot_deny_mknod" is created.
64679 +
64680 +config GRKERNSEC_CHROOT_SHMAT
64681 + bool "Deny shmat() out of chroot"
64682 + default y if GRKERNSEC_CONFIG_AUTO
64683 + depends on GRKERNSEC_CHROOT
64684 + help
64685 + If you say Y here, processes inside a chroot will not be able to attach
64686 + to shared memory segments that were created outside of the chroot jail.
64687 + It is recommended that you say Y here. If the sysctl option is enabled,
64688 + a sysctl option with name "chroot_deny_shmat" is created.
64689 +
64690 +config GRKERNSEC_CHROOT_UNIX
64691 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
64692 + default y if GRKERNSEC_CONFIG_AUTO
64693 + depends on GRKERNSEC_CHROOT
64694 + help
64695 + If you say Y here, processes inside a chroot will not be able to
64696 + connect to abstract (meaning not belonging to a filesystem) Unix
64697 + domain sockets that were bound outside of a chroot. It is recommended
64698 + that you say Y here. If the sysctl option is enabled, a sysctl option
64699 + with name "chroot_deny_unix" is created.
64700 +
64701 +config GRKERNSEC_CHROOT_FINDTASK
64702 + bool "Protect outside processes"
64703 + default y if GRKERNSEC_CONFIG_AUTO
64704 + depends on GRKERNSEC_CHROOT
64705 + help
64706 + If you say Y here, processes inside a chroot will not be able to
64707 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
64708 + getsid, or view any process outside of the chroot. If the sysctl
64709 + option is enabled, a sysctl option with name "chroot_findtask" is
64710 + created.
64711 +
64712 +config GRKERNSEC_CHROOT_NICE
64713 + bool "Restrict priority changes"
64714 + default y if GRKERNSEC_CONFIG_AUTO
64715 + depends on GRKERNSEC_CHROOT
64716 + help
64717 + If you say Y here, processes inside a chroot will not be able to raise
64718 + the priority of processes in the chroot, or alter the priority of
64719 + processes outside the chroot. This provides more security than simply
64720 + removing CAP_SYS_NICE from the process' capability set. If the
64721 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
64722 + is created.
64723 +
64724 +config GRKERNSEC_CHROOT_SYSCTL
64725 + bool "Deny sysctl writes"
64726 + default y if GRKERNSEC_CONFIG_AUTO
64727 + depends on GRKERNSEC_CHROOT
64728 + help
64729 + If you say Y here, an attacker in a chroot will not be able to
64730 + write to sysctl entries, either by sysctl(2) or through a /proc
64731 + interface. It is strongly recommended that you say Y here. If the
64732 + sysctl option is enabled, a sysctl option with name
64733 + "chroot_deny_sysctl" is created.
64734 +
64735 +config GRKERNSEC_CHROOT_CAPS
64736 + bool "Capability restrictions"
64737 + default y if GRKERNSEC_CONFIG_AUTO
64738 + depends on GRKERNSEC_CHROOT
64739 + help
64740 + If you say Y here, the capabilities on all processes within a
64741 + chroot jail will be lowered to stop module insertion, raw i/o,
64742 + system and net admin tasks, rebooting the system, modifying immutable
64743 + files, modifying IPC owned by another, and changing the system time.
64744 + This is left an option because it can break some apps. Disable this
64745 + if your chrooted apps are having problems performing those kinds of
64746 + tasks. If the sysctl option is enabled, a sysctl option with
64747 + name "chroot_caps" is created.
64748 +
64749 +config GRKERNSEC_CHROOT_INITRD
64750 + bool "Exempt initrd tasks from restrictions"
64751 + default y if GRKERNSEC_CONFIG_AUTO
64752 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
64753 + help
64754 + If you say Y here, tasks started prior to init will be exempted from
64755 + grsecurity's chroot restrictions. This option is mainly meant to
64756 + resolve Plymouth's performing privileged operations unnecessarily
64757 + in a chroot.
64758 +
64759 +endmenu
64760 +menu "Kernel Auditing"
64761 +depends on GRKERNSEC
64762 +
64763 +config GRKERNSEC_AUDIT_GROUP
64764 + bool "Single group for auditing"
64765 + help
64766 + If you say Y here, the exec and chdir logging features will only operate
64767 + on a group you specify. This option is recommended if you only want to
64768 + watch certain users instead of having a large amount of logs from the
64769 + entire system. If the sysctl option is enabled, a sysctl option with
64770 + name "audit_group" is created.
64771 +
64772 +config GRKERNSEC_AUDIT_GID
64773 + int "GID for auditing"
64774 + depends on GRKERNSEC_AUDIT_GROUP
64775 + default 1007
64776 +
64777 +config GRKERNSEC_EXECLOG
64778 + bool "Exec logging"
64779 + help
64780 + If you say Y here, all execve() calls will be logged (since the
64781 + other exec*() calls are frontends to execve(), all execution
64782 + will be logged). Useful for shell-servers that like to keep track
64783 + of their users. If the sysctl option is enabled, a sysctl option with
64784 + name "exec_logging" is created.
64785 + WARNING: This option when enabled will produce a LOT of logs, especially
64786 + on an active system.
64787 +
64788 +config GRKERNSEC_RESLOG
64789 + bool "Resource logging"
64790 + default y if GRKERNSEC_CONFIG_AUTO
64791 + help
64792 + If you say Y here, all attempts to overstep resource limits will
64793 + be logged with the resource name, the requested size, and the current
64794 + limit. It is highly recommended that you say Y here. If the sysctl
64795 + option is enabled, a sysctl option with name "resource_logging" is
64796 + created. If the RBAC system is enabled, the sysctl value is ignored.
64797 +
64798 +config GRKERNSEC_CHROOT_EXECLOG
64799 + bool "Log execs within chroot"
64800 + help
64801 + If you say Y here, all executions inside a chroot jail will be logged
64802 + to syslog. This can cause a large amount of logs if certain
64803 + applications (eg. djb's daemontools) are installed on the system, and
64804 + is therefore left as an option. If the sysctl option is enabled, a
64805 + sysctl option with name "chroot_execlog" is created.
64806 +
64807 +config GRKERNSEC_AUDIT_PTRACE
64808 + bool "Ptrace logging"
64809 + help
64810 + If you say Y here, all attempts to attach to a process via ptrace
64811 + will be logged. If the sysctl option is enabled, a sysctl option
64812 + with name "audit_ptrace" is created.
64813 +
64814 +config GRKERNSEC_AUDIT_CHDIR
64815 + bool "Chdir logging"
64816 + help
64817 + If you say Y here, all chdir() calls will be logged. If the sysctl
64818 + option is enabled, a sysctl option with name "audit_chdir" is created.
64819 +
64820 +config GRKERNSEC_AUDIT_MOUNT
64821 + bool "(Un)Mount logging"
64822 + help
64823 + If you say Y here, all mounts and unmounts will be logged. If the
64824 + sysctl option is enabled, a sysctl option with name "audit_mount" is
64825 + created.
64826 +
64827 +config GRKERNSEC_SIGNAL
64828 + bool "Signal logging"
64829 + default y if GRKERNSEC_CONFIG_AUTO
64830 + help
64831 + If you say Y here, certain important signals will be logged, such as
64832 + SIGSEGV, which will as a result inform you of when a error in a program
64833 + occurred, which in some cases could mean a possible exploit attempt.
64834 + If the sysctl option is enabled, a sysctl option with name
64835 + "signal_logging" is created.
64836 +
64837 +config GRKERNSEC_FORKFAIL
64838 + bool "Fork failure logging"
64839 + help
64840 + If you say Y here, all failed fork() attempts will be logged.
64841 + This could suggest a fork bomb, or someone attempting to overstep
64842 + their process limit. If the sysctl option is enabled, a sysctl option
64843 + with name "forkfail_logging" is created.
64844 +
64845 +config GRKERNSEC_TIME
64846 + bool "Time change logging"
64847 + default y if GRKERNSEC_CONFIG_AUTO
64848 + help
64849 + If you say Y here, any changes of the system clock will be logged.
64850 + If the sysctl option is enabled, a sysctl option with name
64851 + "timechange_logging" is created.
64852 +
64853 +config GRKERNSEC_PROC_IPADDR
64854 + bool "/proc/<pid>/ipaddr support"
64855 + default y if GRKERNSEC_CONFIG_AUTO
64856 + help
64857 + If you say Y here, a new entry will be added to each /proc/<pid>
64858 + directory that contains the IP address of the person using the task.
64859 + The IP is carried across local TCP and AF_UNIX stream sockets.
64860 + This information can be useful for IDS/IPSes to perform remote response
64861 + to a local attack. The entry is readable by only the owner of the
64862 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
64863 + the RBAC system), and thus does not create privacy concerns.
64864 +
64865 +config GRKERNSEC_RWXMAP_LOG
64866 + bool 'Denied RWX mmap/mprotect logging'
64867 + default y if GRKERNSEC_CONFIG_AUTO
64868 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
64869 + help
64870 + If you say Y here, calls to mmap() and mprotect() with explicit
64871 + usage of PROT_WRITE and PROT_EXEC together will be logged when
64872 + denied by the PAX_MPROTECT feature. This feature will also
64873 + log other problematic scenarios that can occur when PAX_MPROTECT
64874 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
64875 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
64876 + is created.
64877 +
64878 +endmenu
64879 +
64880 +menu "Executable Protections"
64881 +depends on GRKERNSEC
64882 +
64883 +config GRKERNSEC_DMESG
64884 + bool "Dmesg(8) restriction"
64885 + default y if GRKERNSEC_CONFIG_AUTO
64886 + help
64887 + If you say Y here, non-root users will not be able to use dmesg(8)
64888 + to view the contents of the kernel's circular log buffer.
64889 + The kernel's log buffer often contains kernel addresses and other
64890 + identifying information useful to an attacker in fingerprinting a
64891 + system for a targeted exploit.
64892 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
64893 + created.
64894 +
64895 +config GRKERNSEC_HARDEN_PTRACE
64896 + bool "Deter ptrace-based process snooping"
64897 + default y if GRKERNSEC_CONFIG_AUTO
64898 + help
64899 + If you say Y here, TTY sniffers and other malicious monitoring
64900 + programs implemented through ptrace will be defeated. If you
64901 + have been using the RBAC system, this option has already been
64902 + enabled for several years for all users, with the ability to make
64903 + fine-grained exceptions.
64904 +
64905 + This option only affects the ability of non-root users to ptrace
64906 + processes that are not a descendent of the ptracing process.
64907 + This means that strace ./binary and gdb ./binary will still work,
64908 + but attaching to arbitrary processes will not. If the sysctl
64909 + option is enabled, a sysctl option with name "harden_ptrace" is
64910 + created.
64911 +
64912 +config GRKERNSEC_PTRACE_READEXEC
64913 + bool "Require read access to ptrace sensitive binaries"
64914 + default y if GRKERNSEC_CONFIG_AUTO
64915 + help
64916 + If you say Y here, unprivileged users will not be able to ptrace unreadable
64917 + binaries. This option is useful in environments that
64918 + remove the read bits (e.g. file mode 4711) from suid binaries to
64919 + prevent infoleaking of their contents. This option adds
64920 + consistency to the use of that file mode, as the binary could normally
64921 + be read out when run without privileges while ptracing.
64922 +
64923 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
64924 + is created.
64925 +
64926 +config GRKERNSEC_SETXID
64927 + bool "Enforce consistent multithreaded privileges"
64928 + default y if GRKERNSEC_CONFIG_AUTO
64929 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
64930 + help
64931 + If you say Y here, a change from a root uid to a non-root uid
64932 + in a multithreaded application will cause the resulting uids,
64933 + gids, supplementary groups, and capabilities in that thread
64934 + to be propagated to the other threads of the process. In most
64935 + cases this is unnecessary, as glibc will emulate this behavior
64936 + on behalf of the application. Other libcs do not act in the
64937 + same way, allowing the other threads of the process to continue
64938 + running with root privileges. If the sysctl option is enabled,
64939 + a sysctl option with name "consistent_setxid" is created.
64940 +
64941 +config GRKERNSEC_HARDEN_IPC
64942 + bool "Disallow access to overly-permissive IPC objects"
64943 + default y if GRKERNSEC_CONFIG_AUTO
64944 + depends on SYSVIPC
64945 + help
64946 + If you say Y here, access to overly-permissive IPC objects (shared
64947 + memory, message queues, and semaphores) will be denied for processes
64948 + given the following criteria beyond normal permission checks:
64949 + 1) If the IPC object is world-accessible and the euid doesn't match
64950 + that of the creator or current uid for the IPC object
64951 + 2) If the IPC object is group-accessible and the egid doesn't
64952 + match that of the creator or current gid for the IPC object
64953 + It's a common error to grant too much permission to these objects,
64954 + with impact ranging from denial of service and information leaking to
64955 + privilege escalation. This feature was developed in response to
64956 + research by Tim Brown:
64957 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
64958 + who found hundreds of such insecure usages. Processes with
64959 + CAP_IPC_OWNER are still permitted to access these IPC objects.
64960 + If the sysctl option is enabled, a sysctl option with name
64961 + "harden_ipc" is created.
64962 +
64963 +config GRKERNSEC_TPE
64964 + bool "Trusted Path Execution (TPE)"
64965 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
64966 + help
64967 + If you say Y here, you will be able to choose a gid to add to the
64968 + supplementary groups of users you want to mark as "untrusted."
64969 + These users will not be able to execute any files that are not in
64970 + root-owned directories writable only by root. If the sysctl option
64971 + is enabled, a sysctl option with name "tpe" is created.
64972 +
64973 +config GRKERNSEC_TPE_ALL
64974 + bool "Partially restrict all non-root users"
64975 + depends on GRKERNSEC_TPE
64976 + help
64977 + If you say Y here, all non-root users will be covered under
64978 + a weaker TPE restriction. This is separate from, and in addition to,
64979 + the main TPE options that you have selected elsewhere. Thus, if a
64980 + "trusted" GID is chosen, this restriction applies to even that GID.
64981 + Under this restriction, all non-root users will only be allowed to
64982 + execute files in directories they own that are not group or
64983 + world-writable, or in directories owned by root and writable only by
64984 + root. If the sysctl option is enabled, a sysctl option with name
64985 + "tpe_restrict_all" is created.
64986 +
64987 +config GRKERNSEC_TPE_INVERT
64988 + bool "Invert GID option"
64989 + depends on GRKERNSEC_TPE
64990 + help
64991 + If you say Y here, the group you specify in the TPE configuration will
64992 + decide what group TPE restrictions will be *disabled* for. This
64993 + option is useful if you want TPE restrictions to be applied to most
64994 + users on the system. If the sysctl option is enabled, a sysctl option
64995 + with name "tpe_invert" is created. Unlike other sysctl options, this
64996 + entry will default to on for backward-compatibility.
64997 +
64998 +config GRKERNSEC_TPE_GID
64999 + int
65000 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
65001 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
65002 +
65003 +config GRKERNSEC_TPE_UNTRUSTED_GID
65004 + int "GID for TPE-untrusted users"
65005 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
65006 + default 1005
65007 + help
65008 + Setting this GID determines what group TPE restrictions will be
65009 + *enabled* for. If the sysctl option is enabled, a sysctl option
65010 + with name "tpe_gid" is created.
65011 +
65012 +config GRKERNSEC_TPE_TRUSTED_GID
65013 + int "GID for TPE-trusted users"
65014 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
65015 + default 1005
65016 + help
65017 + Setting this GID determines what group TPE restrictions will be
65018 + *disabled* for. If the sysctl option is enabled, a sysctl option
65019 + with name "tpe_gid" is created.
65020 +
65021 +endmenu
65022 +menu "Network Protections"
65023 +depends on GRKERNSEC
65024 +
65025 +config GRKERNSEC_RANDNET
65026 + bool "Larger entropy pools"
65027 + default y if GRKERNSEC_CONFIG_AUTO
65028 + help
65029 + If you say Y here, the entropy pools used for many features of Linux
65030 + and grsecurity will be doubled in size. Since several grsecurity
65031 + features use additional randomness, it is recommended that you say Y
65032 + here. Saying Y here has a similar effect as modifying
65033 + /proc/sys/kernel/random/poolsize.
65034 +
65035 +config GRKERNSEC_BLACKHOLE
65036 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
65037 + default y if GRKERNSEC_CONFIG_AUTO
65038 + depends on NET
65039 + help
65040 + If you say Y here, neither TCP resets nor ICMP
65041 + destination-unreachable packets will be sent in response to packets
65042 + sent to ports for which no associated listening process exists.
65043 + This feature supports both IPV4 and IPV6 and exempts the
65044 + loopback interface from blackholing. Enabling this feature
65045 + makes a host more resilient to DoS attacks and reduces network
65046 + visibility against scanners.
65047 +
65048 + The blackhole feature as-implemented is equivalent to the FreeBSD
65049 + blackhole feature, as it prevents RST responses to all packets, not
65050 + just SYNs. Under most application behavior this causes no
65051 + problems, but applications (like haproxy) may not close certain
65052 + connections in a way that cleanly terminates them on the remote
65053 + end, leaving the remote host in LAST_ACK state. Because of this
65054 + side-effect and to prevent intentional LAST_ACK DoSes, this
65055 + feature also adds automatic mitigation against such attacks.
65056 + The mitigation drastically reduces the amount of time a socket
65057 + can spend in LAST_ACK state. If you're using haproxy and not
65058 + all servers it connects to have this option enabled, consider
65059 + disabling this feature on the haproxy host.
65060 +
65061 + If the sysctl option is enabled, two sysctl options with names
65062 + "ip_blackhole" and "lastack_retries" will be created.
65063 + While "ip_blackhole" takes the standard zero/non-zero on/off
65064 + toggle, "lastack_retries" uses the same kinds of values as
65065 + "tcp_retries1" and "tcp_retries2". The default value of 4
65066 + prevents a socket from lasting more than 45 seconds in LAST_ACK
65067 + state.
65068 +
65069 +config GRKERNSEC_NO_SIMULT_CONNECT
65070 + bool "Disable TCP Simultaneous Connect"
65071 + default y if GRKERNSEC_CONFIG_AUTO
65072 + depends on NET
65073 + help
65074 + If you say Y here, a feature by Willy Tarreau will be enabled that
65075 + removes a weakness in Linux's strict implementation of TCP that
65076 + allows two clients to connect to each other without either entering
65077 + a listening state. The weakness allows an attacker to easily prevent
65078 + a client from connecting to a known server provided the source port
65079 + for the connection is guessed correctly.
65080 +
65081 + As the weakness could be used to prevent an antivirus or IPS from
65082 + fetching updates, or prevent an SSL gateway from fetching a CRL,
65083 + it should be eliminated by enabling this option. Though Linux is
65084 + one of few operating systems supporting simultaneous connect, it
65085 + has no legitimate use in practice and is rarely supported by firewalls.
65086 +
65087 +config GRKERNSEC_SOCKET
65088 + bool "Socket restrictions"
65089 + depends on NET
65090 + help
65091 + If you say Y here, you will be able to choose from several options.
65092 + If you assign a GID on your system and add it to the supplementary
65093 + groups of users you want to restrict socket access to, this patch
65094 + will perform up to three things, based on the option(s) you choose.
65095 +
65096 +config GRKERNSEC_SOCKET_ALL
65097 + bool "Deny any sockets to group"
65098 + depends on GRKERNSEC_SOCKET
65099 + help
65100 + If you say Y here, you will be able to choose a GID of whose users will
65101 + be unable to connect to other hosts from your machine or run server
65102 + applications from your machine. If the sysctl option is enabled, a
65103 + sysctl option with name "socket_all" is created.
65104 +
65105 +config GRKERNSEC_SOCKET_ALL_GID
65106 + int "GID to deny all sockets for"
65107 + depends on GRKERNSEC_SOCKET_ALL
65108 + default 1004
65109 + help
65110 + Here you can choose the GID to disable socket access for. Remember to
65111 + add the users you want socket access disabled for to the GID
65112 + specified here. If the sysctl option is enabled, a sysctl option
65113 + with name "socket_all_gid" is created.
65114 +
65115 +config GRKERNSEC_SOCKET_CLIENT
65116 + bool "Deny client sockets to group"
65117 + depends on GRKERNSEC_SOCKET
65118 + help
65119 + If you say Y here, you will be able to choose a GID of whose users will
65120 + be unable to connect to other hosts from your machine, but will be
65121 + able to run servers. If this option is enabled, all users in the group
65122 + you specify will have to use passive mode when initiating ftp transfers
65123 + from the shell on your machine. If the sysctl option is enabled, a
65124 + sysctl option with name "socket_client" is created.
65125 +
65126 +config GRKERNSEC_SOCKET_CLIENT_GID
65127 + int "GID to deny client sockets for"
65128 + depends on GRKERNSEC_SOCKET_CLIENT
65129 + default 1003
65130 + help
65131 + Here you can choose the GID to disable client socket access for.
65132 + Remember to add the users you want client socket access disabled for to
65133 + the GID specified here. If the sysctl option is enabled, a sysctl
65134 + option with name "socket_client_gid" is created.
65135 +
65136 +config GRKERNSEC_SOCKET_SERVER
65137 + bool "Deny server sockets to group"
65138 + depends on GRKERNSEC_SOCKET
65139 + help
65140 + If you say Y here, you will be able to choose a GID of whose users will
65141 + be unable to run server applications from your machine. If the sysctl
65142 + option is enabled, a sysctl option with name "socket_server" is created.
65143 +
65144 +config GRKERNSEC_SOCKET_SERVER_GID
65145 + int "GID to deny server sockets for"
65146 + depends on GRKERNSEC_SOCKET_SERVER
65147 + default 1002
65148 + help
65149 + Here you can choose the GID to disable server socket access for.
65150 + Remember to add the users you want server socket access disabled for to
65151 + the GID specified here. If the sysctl option is enabled, a sysctl
65152 + option with name "socket_server_gid" is created.
65153 +
65154 +endmenu
65155 +
65156 +menu "Physical Protections"
65157 +depends on GRKERNSEC
65158 +
65159 +config GRKERNSEC_DENYUSB
65160 + bool "Deny new USB connections after toggle"
65161 + default y if GRKERNSEC_CONFIG_AUTO
65162 + depends on SYSCTL && USB_SUPPORT
65163 + help
65164 + If you say Y here, a new sysctl option with name "deny_new_usb"
65165 + will be created. Setting its value to 1 will prevent any new
65166 + USB devices from being recognized by the OS. Any attempted USB
65167 + device insertion will be logged. This option is intended to be
65168 + used against custom USB devices designed to exploit vulnerabilities
65169 + in various USB device drivers.
65170 +
65171 + For greatest effectiveness, this sysctl should be set after any
65172 + relevant init scripts. This option is safe to enable in distros
65173 + as each user can choose whether or not to toggle the sysctl.
65174 +
65175 +config GRKERNSEC_DENYUSB_FORCE
65176 + bool "Reject all USB devices not connected at boot"
65177 + select USB
65178 + depends on GRKERNSEC_DENYUSB
65179 + help
65180 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
65181 + that doesn't involve a sysctl entry. This option should only be
65182 + enabled if you're sure you want to deny all new USB connections
65183 + at runtime and don't want to modify init scripts. This should not
65184 + be enabled by distros. It forces the core USB code to be built
65185 + into the kernel image so that all devices connected at boot time
65186 + can be recognized and new USB device connections can be prevented
65187 + prior to init running.
65188 +
65189 +endmenu
65190 +
65191 +menu "Sysctl Support"
65192 +depends on GRKERNSEC && SYSCTL
65193 +
65194 +config GRKERNSEC_SYSCTL
65195 + bool "Sysctl support"
65196 + default y if GRKERNSEC_CONFIG_AUTO
65197 + help
65198 + If you say Y here, you will be able to change the options that
65199 + grsecurity runs with at bootup, without having to recompile your
65200 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
65201 + to enable (1) or disable (0) various features. All the sysctl entries
65202 + are mutable until the "grsec_lock" entry is set to a non-zero value.
65203 + All features enabled in the kernel configuration are disabled at boot
65204 + if you do not say Y to the "Turn on features by default" option.
65205 + All options should be set at startup, and the grsec_lock entry should
65206 + be set to a non-zero value after all the options are set.
65207 + *THIS IS EXTREMELY IMPORTANT*
65208 +
65209 +config GRKERNSEC_SYSCTL_DISTRO
65210 + bool "Extra sysctl support for distro makers (READ HELP)"
65211 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
65212 + help
65213 + If you say Y here, additional sysctl options will be created
65214 + for features that affect processes running as root. Therefore,
65215 + it is critical when using this option that the grsec_lock entry be
65216 + enabled after boot. Only distros with prebuilt kernel packages
65217 + with this option enabled that can ensure grsec_lock is enabled
65218 + after boot should use this option.
65219 + *Failure to set grsec_lock after boot makes all grsec features
65220 + this option covers useless*
65221 +
65222 + Currently this option creates the following sysctl entries:
65223 + "Disable Privileged I/O": "disable_priv_io"
65224 +
65225 +config GRKERNSEC_SYSCTL_ON
65226 + bool "Turn on features by default"
65227 + default y if GRKERNSEC_CONFIG_AUTO
65228 + depends on GRKERNSEC_SYSCTL
65229 + help
65230 + If you say Y here, instead of having all features enabled in the
65231 + kernel configuration disabled at boot time, the features will be
65232 + enabled at boot time. It is recommended you say Y here unless
65233 + there is some reason you would want all sysctl-tunable features to
65234 + be disabled by default. As mentioned elsewhere, it is important
65235 + to enable the grsec_lock entry once you have finished modifying
65236 + the sysctl entries.
65237 +
65238 +endmenu
65239 +menu "Logging Options"
65240 +depends on GRKERNSEC
65241 +
65242 +config GRKERNSEC_FLOODTIME
65243 + int "Seconds in between log messages (minimum)"
65244 + default 10
65245 + help
65246 + This option allows you to enforce the number of seconds between
65247 + grsecurity log messages. The default should be suitable for most
65248 + people, however, if you choose to change it, choose a value small enough
65249 + to allow informative logs to be produced, but large enough to
65250 + prevent flooding.
65251 +
65252 +config GRKERNSEC_FLOODBURST
65253 + int "Number of messages in a burst (maximum)"
65254 + default 6
65255 + help
65256 + This option allows you to choose the maximum number of messages allowed
65257 + within the flood time interval you chose in a separate option. The
65258 + default should be suitable for most people, however if you find that
65259 + many of your logs are being interpreted as flooding, you may want to
65260 + raise this value.
65261 +
65262 +endmenu
65263 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
65264 new file mode 100644
65265 index 0000000..d1344d2
65266 --- /dev/null
65267 +++ b/grsecurity/Makefile
65268 @@ -0,0 +1,43 @@
65269 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
65270 +# during 2001-2009 it has been completely redesigned by Brad Spengler
65271 +# into an RBAC system
65272 +#
65273 +# All code in this directory and various hooks inserted throughout the kernel
65274 +# are copyright Brad Spengler - Open Source Security, Inc., and released
65275 +# under the GPL v2
65276 +
65277 +KBUILD_CFLAGS += -Werror
65278 +
65279 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
65280 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
65281 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
65282 + grsec_usb.o grsec_ipc.o
65283 +
65284 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
65285 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
65286 + gracl_learn.o grsec_log.o gracl_policy.o
65287 +ifdef CONFIG_COMPAT
65288 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
65289 +endif
65290 +
65291 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
65292 +
65293 +ifdef CONFIG_NET
65294 +obj-y += grsec_sock.o
65295 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
65296 +endif
65297 +
65298 +ifndef CONFIG_GRKERNSEC
65299 +obj-y += grsec_disabled.o
65300 +endif
65301 +
65302 +ifdef CONFIG_GRKERNSEC_HIDESYM
65303 +extra-y := grsec_hidesym.o
65304 +$(obj)/grsec_hidesym.o:
65305 + @-chmod -f 500 /boot
65306 + @-chmod -f 500 /lib/modules
65307 + @-chmod -f 500 /lib64/modules
65308 + @-chmod -f 500 /lib32/modules
65309 + @-chmod -f 700 .
65310 + @echo ' grsec: protected kernel image paths'
65311 +endif
65312 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
65313 new file mode 100644
65314 index 0000000..7232a45
65315 --- /dev/null
65316 +++ b/grsecurity/gracl.c
65317 @@ -0,0 +1,2677 @@
65318 +#include <linux/kernel.h>
65319 +#include <linux/module.h>
65320 +#include <linux/sched.h>
65321 +#include <linux/mm.h>
65322 +#include <linux/file.h>
65323 +#include <linux/fs.h>
65324 +#include <linux/namei.h>
65325 +#include <linux/mount.h>
65326 +#include <linux/tty.h>
65327 +#include <linux/proc_fs.h>
65328 +#include <linux/lglock.h>
65329 +#include <linux/slab.h>
65330 +#include <linux/vmalloc.h>
65331 +#include <linux/types.h>
65332 +#include <linux/sysctl.h>
65333 +#include <linux/netdevice.h>
65334 +#include <linux/ptrace.h>
65335 +#include <linux/gracl.h>
65336 +#include <linux/gralloc.h>
65337 +#include <linux/security.h>
65338 +#include <linux/grinternal.h>
65339 +#include <linux/pid_namespace.h>
65340 +#include <linux/stop_machine.h>
65341 +#include <linux/fdtable.h>
65342 +#include <linux/percpu.h>
65343 +#include <linux/lglock.h>
65344 +#include <linux/hugetlb.h>
65345 +#include <linux/posix-timers.h>
65346 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
65347 +#include <linux/magic.h>
65348 +#include <linux/pagemap.h>
65349 +#include "../fs/btrfs/async-thread.h"
65350 +#include "../fs/btrfs/ctree.h"
65351 +#include "../fs/btrfs/btrfs_inode.h"
65352 +#endif
65353 +#include "../fs/mount.h"
65354 +
65355 +#include <asm/uaccess.h>
65356 +#include <asm/errno.h>
65357 +#include <asm/mman.h>
65358 +
65359 +#define FOR_EACH_ROLE_START(role) \
65360 + role = running_polstate.role_list; \
65361 + while (role) {
65362 +
65363 +#define FOR_EACH_ROLE_END(role) \
65364 + role = role->prev; \
65365 + }
65366 +
65367 +extern struct path gr_real_root;
65368 +
65369 +static struct gr_policy_state running_polstate;
65370 +struct gr_policy_state *polstate = &running_polstate;
65371 +extern struct gr_alloc_state *current_alloc_state;
65372 +
65373 +extern char *gr_shared_page[4];
65374 +DEFINE_RWLOCK(gr_inode_lock);
65375 +
65376 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
65377 +
65378 +#ifdef CONFIG_NET
65379 +extern struct vfsmount *sock_mnt;
65380 +#endif
65381 +
65382 +extern struct vfsmount *pipe_mnt;
65383 +extern struct vfsmount *shm_mnt;
65384 +
65385 +#ifdef CONFIG_HUGETLBFS
65386 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
65387 +#endif
65388 +
65389 +extern u16 acl_sp_role_value;
65390 +extern struct acl_object_label *fakefs_obj_rw;
65391 +extern struct acl_object_label *fakefs_obj_rwx;
65392 +
65393 +int gr_acl_is_enabled(void)
65394 +{
65395 + return (gr_status & GR_READY);
65396 +}
65397 +
65398 +void gr_enable_rbac_system(void)
65399 +{
65400 + pax_open_kernel();
65401 + gr_status |= GR_READY;
65402 + pax_close_kernel();
65403 +}
65404 +
65405 +int gr_rbac_disable(void *unused)
65406 +{
65407 + pax_open_kernel();
65408 + gr_status &= ~GR_READY;
65409 + pax_close_kernel();
65410 +
65411 + return 0;
65412 +}
65413 +
65414 +static inline dev_t __get_dev(const struct dentry *dentry)
65415 +{
65416 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
65417 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
65418 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
65419 + else
65420 +#endif
65421 + return dentry->d_sb->s_dev;
65422 +}
65423 +
65424 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
65425 +{
65426 + return __get_dev(dentry);
65427 +}
65428 +
65429 +static char gr_task_roletype_to_char(struct task_struct *task)
65430 +{
65431 + switch (task->role->roletype &
65432 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
65433 + GR_ROLE_SPECIAL)) {
65434 + case GR_ROLE_DEFAULT:
65435 + return 'D';
65436 + case GR_ROLE_USER:
65437 + return 'U';
65438 + case GR_ROLE_GROUP:
65439 + return 'G';
65440 + case GR_ROLE_SPECIAL:
65441 + return 'S';
65442 + }
65443 +
65444 + return 'X';
65445 +}
65446 +
65447 +char gr_roletype_to_char(void)
65448 +{
65449 + return gr_task_roletype_to_char(current);
65450 +}
65451 +
65452 +__inline__ int
65453 +gr_acl_tpe_check(void)
65454 +{
65455 + if (unlikely(!(gr_status & GR_READY)))
65456 + return 0;
65457 + if (current->role->roletype & GR_ROLE_TPE)
65458 + return 1;
65459 + else
65460 + return 0;
65461 +}
65462 +
65463 +int
65464 +gr_handle_rawio(const struct inode *inode)
65465 +{
65466 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65467 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
65468 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
65469 + !capable(CAP_SYS_RAWIO))
65470 + return 1;
65471 +#endif
65472 + return 0;
65473 +}
65474 +
65475 +int
65476 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
65477 +{
65478 + if (likely(lena != lenb))
65479 + return 0;
65480 +
65481 + return !memcmp(a, b, lena);
65482 +}
65483 +
65484 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
65485 +{
65486 + *buflen -= namelen;
65487 + if (*buflen < 0)
65488 + return -ENAMETOOLONG;
65489 + *buffer -= namelen;
65490 + memcpy(*buffer, str, namelen);
65491 + return 0;
65492 +}
65493 +
65494 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
65495 +{
65496 + return prepend(buffer, buflen, name->name, name->len);
65497 +}
65498 +
65499 +static int prepend_path(const struct path *path, struct path *root,
65500 + char **buffer, int *buflen)
65501 +{
65502 + struct dentry *dentry = path->dentry;
65503 + struct vfsmount *vfsmnt = path->mnt;
65504 + struct mount *mnt = real_mount(vfsmnt);
65505 + bool slash = false;
65506 + int error = 0;
65507 +
65508 + while (dentry != root->dentry || vfsmnt != root->mnt) {
65509 + struct dentry * parent;
65510 +
65511 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
65512 + /* Global root? */
65513 + if (!mnt_has_parent(mnt)) {
65514 + goto out;
65515 + }
65516 + dentry = mnt->mnt_mountpoint;
65517 + mnt = mnt->mnt_parent;
65518 + vfsmnt = &mnt->mnt;
65519 + continue;
65520 + }
65521 + parent = dentry->d_parent;
65522 + prefetch(parent);
65523 + spin_lock(&dentry->d_lock);
65524 + error = prepend_name(buffer, buflen, &dentry->d_name);
65525 + spin_unlock(&dentry->d_lock);
65526 + if (!error)
65527 + error = prepend(buffer, buflen, "/", 1);
65528 + if (error)
65529 + break;
65530 +
65531 + slash = true;
65532 + dentry = parent;
65533 + }
65534 +
65535 +out:
65536 + if (!error && !slash)
65537 + error = prepend(buffer, buflen, "/", 1);
65538 +
65539 + return error;
65540 +}
65541 +
65542 +/* this must be called with mount_lock and rename_lock held */
65543 +
65544 +static char *__our_d_path(const struct path *path, struct path *root,
65545 + char *buf, int buflen)
65546 +{
65547 + char *res = buf + buflen;
65548 + int error;
65549 +
65550 + prepend(&res, &buflen, "\0", 1);
65551 + error = prepend_path(path, root, &res, &buflen);
65552 + if (error)
65553 + return ERR_PTR(error);
65554 +
65555 + return res;
65556 +}
65557 +
65558 +static char *
65559 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
65560 +{
65561 + char *retval;
65562 +
65563 + retval = __our_d_path(path, root, buf, buflen);
65564 + if (unlikely(IS_ERR(retval)))
65565 + retval = strcpy(buf, "<path too long>");
65566 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
65567 + retval[1] = '\0';
65568 +
65569 + return retval;
65570 +}
65571 +
65572 +static char *
65573 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
65574 + char *buf, int buflen)
65575 +{
65576 + struct path path;
65577 + char *res;
65578 +
65579 + path.dentry = (struct dentry *)dentry;
65580 + path.mnt = (struct vfsmount *)vfsmnt;
65581 +
65582 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
65583 + by the RBAC system */
65584 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
65585 +
65586 + return res;
65587 +}
65588 +
65589 +static char *
65590 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
65591 + char *buf, int buflen)
65592 +{
65593 + char *res;
65594 + struct path path;
65595 + struct path root;
65596 + struct task_struct *reaper = init_pid_ns.child_reaper;
65597 +
65598 + path.dentry = (struct dentry *)dentry;
65599 + path.mnt = (struct vfsmount *)vfsmnt;
65600 +
65601 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
65602 + get_fs_root(reaper->fs, &root);
65603 +
65604 + read_seqlock_excl(&mount_lock);
65605 + write_seqlock(&rename_lock);
65606 + res = gen_full_path(&path, &root, buf, buflen);
65607 + write_sequnlock(&rename_lock);
65608 + read_sequnlock_excl(&mount_lock);
65609 +
65610 + path_put(&root);
65611 + return res;
65612 +}
65613 +
65614 +char *
65615 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
65616 +{
65617 + char *ret;
65618 + read_seqlock_excl(&mount_lock);
65619 + write_seqlock(&rename_lock);
65620 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
65621 + PAGE_SIZE);
65622 + write_sequnlock(&rename_lock);
65623 + read_sequnlock_excl(&mount_lock);
65624 + return ret;
65625 +}
65626 +
65627 +static char *
65628 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
65629 +{
65630 + char *ret;
65631 + char *buf;
65632 + int buflen;
65633 +
65634 + read_seqlock_excl(&mount_lock);
65635 + write_seqlock(&rename_lock);
65636 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
65637 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
65638 + buflen = (int)(ret - buf);
65639 + if (buflen >= 5)
65640 + prepend(&ret, &buflen, "/proc", 5);
65641 + else
65642 + ret = strcpy(buf, "<path too long>");
65643 + write_sequnlock(&rename_lock);
65644 + read_sequnlock_excl(&mount_lock);
65645 + return ret;
65646 +}
65647 +
65648 +char *
65649 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
65650 +{
65651 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
65652 + PAGE_SIZE);
65653 +}
65654 +
65655 +char *
65656 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
65657 +{
65658 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
65659 + PAGE_SIZE);
65660 +}
65661 +
65662 +char *
65663 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
65664 +{
65665 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
65666 + PAGE_SIZE);
65667 +}
65668 +
65669 +char *
65670 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
65671 +{
65672 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
65673 + PAGE_SIZE);
65674 +}
65675 +
65676 +char *
65677 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
65678 +{
65679 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
65680 + PAGE_SIZE);
65681 +}
65682 +
65683 +__inline__ __u32
65684 +to_gr_audit(const __u32 reqmode)
65685 +{
65686 + /* masks off auditable permission flags, then shifts them to create
65687 + auditing flags, and adds the special case of append auditing if
65688 + we're requesting write */
65689 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
65690 +}
65691 +
65692 +struct acl_role_label *
65693 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
65694 + const gid_t gid)
65695 +{
65696 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
65697 + struct acl_role_label *match;
65698 + struct role_allowed_ip *ipp;
65699 + unsigned int x;
65700 + u32 curr_ip = task->signal->saved_ip;
65701 +
65702 + match = state->acl_role_set.r_hash[index];
65703 +
65704 + while (match) {
65705 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
65706 + for (x = 0; x < match->domain_child_num; x++) {
65707 + if (match->domain_children[x] == uid)
65708 + goto found;
65709 + }
65710 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
65711 + break;
65712 + match = match->next;
65713 + }
65714 +found:
65715 + if (match == NULL) {
65716 + try_group:
65717 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
65718 + match = state->acl_role_set.r_hash[index];
65719 +
65720 + while (match) {
65721 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
65722 + for (x = 0; x < match->domain_child_num; x++) {
65723 + if (match->domain_children[x] == gid)
65724 + goto found2;
65725 + }
65726 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
65727 + break;
65728 + match = match->next;
65729 + }
65730 +found2:
65731 + if (match == NULL)
65732 + match = state->default_role;
65733 + if (match->allowed_ips == NULL)
65734 + return match;
65735 + else {
65736 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
65737 + if (likely
65738 + ((ntohl(curr_ip) & ipp->netmask) ==
65739 + (ntohl(ipp->addr) & ipp->netmask)))
65740 + return match;
65741 + }
65742 + match = state->default_role;
65743 + }
65744 + } else if (match->allowed_ips == NULL) {
65745 + return match;
65746 + } else {
65747 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
65748 + if (likely
65749 + ((ntohl(curr_ip) & ipp->netmask) ==
65750 + (ntohl(ipp->addr) & ipp->netmask)))
65751 + return match;
65752 + }
65753 + goto try_group;
65754 + }
65755 +
65756 + return match;
65757 +}
65758 +
65759 +static struct acl_role_label *
65760 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
65761 + const gid_t gid)
65762 +{
65763 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
65764 +}
65765 +
65766 +struct acl_subject_label *
65767 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
65768 + const struct acl_role_label *role)
65769 +{
65770 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
65771 + struct acl_subject_label *match;
65772 +
65773 + match = role->subj_hash[index];
65774 +
65775 + while (match && (match->inode != ino || match->device != dev ||
65776 + (match->mode & GR_DELETED))) {
65777 + match = match->next;
65778 + }
65779 +
65780 + if (match && !(match->mode & GR_DELETED))
65781 + return match;
65782 + else
65783 + return NULL;
65784 +}
65785 +
65786 +struct acl_subject_label *
65787 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
65788 + const struct acl_role_label *role)
65789 +{
65790 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
65791 + struct acl_subject_label *match;
65792 +
65793 + match = role->subj_hash[index];
65794 +
65795 + while (match && (match->inode != ino || match->device != dev ||
65796 + !(match->mode & GR_DELETED))) {
65797 + match = match->next;
65798 + }
65799 +
65800 + if (match && (match->mode & GR_DELETED))
65801 + return match;
65802 + else
65803 + return NULL;
65804 +}
65805 +
65806 +static struct acl_object_label *
65807 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
65808 + const struct acl_subject_label *subj)
65809 +{
65810 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
65811 + struct acl_object_label *match;
65812 +
65813 + match = subj->obj_hash[index];
65814 +
65815 + while (match && (match->inode != ino || match->device != dev ||
65816 + (match->mode & GR_DELETED))) {
65817 + match = match->next;
65818 + }
65819 +
65820 + if (match && !(match->mode & GR_DELETED))
65821 + return match;
65822 + else
65823 + return NULL;
65824 +}
65825 +
65826 +static struct acl_object_label *
65827 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
65828 + const struct acl_subject_label *subj)
65829 +{
65830 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
65831 + struct acl_object_label *match;
65832 +
65833 + match = subj->obj_hash[index];
65834 +
65835 + while (match && (match->inode != ino || match->device != dev ||
65836 + !(match->mode & GR_DELETED))) {
65837 + match = match->next;
65838 + }
65839 +
65840 + if (match && (match->mode & GR_DELETED))
65841 + return match;
65842 +
65843 + match = subj->obj_hash[index];
65844 +
65845 + while (match && (match->inode != ino || match->device != dev ||
65846 + (match->mode & GR_DELETED))) {
65847 + match = match->next;
65848 + }
65849 +
65850 + if (match && !(match->mode & GR_DELETED))
65851 + return match;
65852 + else
65853 + return NULL;
65854 +}
65855 +
65856 +struct name_entry *
65857 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
65858 +{
65859 + unsigned int len = strlen(name);
65860 + unsigned int key = full_name_hash(name, len);
65861 + unsigned int index = key % state->name_set.n_size;
65862 + struct name_entry *match;
65863 +
65864 + match = state->name_set.n_hash[index];
65865 +
65866 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
65867 + match = match->next;
65868 +
65869 + return match;
65870 +}
65871 +
65872 +static struct name_entry *
65873 +lookup_name_entry(const char *name)
65874 +{
65875 + return __lookup_name_entry(&running_polstate, name);
65876 +}
65877 +
65878 +static struct name_entry *
65879 +lookup_name_entry_create(const char *name)
65880 +{
65881 + unsigned int len = strlen(name);
65882 + unsigned int key = full_name_hash(name, len);
65883 + unsigned int index = key % running_polstate.name_set.n_size;
65884 + struct name_entry *match;
65885 +
65886 + match = running_polstate.name_set.n_hash[index];
65887 +
65888 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
65889 + !match->deleted))
65890 + match = match->next;
65891 +
65892 + if (match && match->deleted)
65893 + return match;
65894 +
65895 + match = running_polstate.name_set.n_hash[index];
65896 +
65897 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
65898 + match->deleted))
65899 + match = match->next;
65900 +
65901 + if (match && !match->deleted)
65902 + return match;
65903 + else
65904 + return NULL;
65905 +}
65906 +
65907 +static struct inodev_entry *
65908 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
65909 +{
65910 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
65911 + struct inodev_entry *match;
65912 +
65913 + match = running_polstate.inodev_set.i_hash[index];
65914 +
65915 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
65916 + match = match->next;
65917 +
65918 + return match;
65919 +}
65920 +
65921 +void
65922 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
65923 +{
65924 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
65925 + state->inodev_set.i_size);
65926 + struct inodev_entry **curr;
65927 +
65928 + entry->prev = NULL;
65929 +
65930 + curr = &state->inodev_set.i_hash[index];
65931 + if (*curr != NULL)
65932 + (*curr)->prev = entry;
65933 +
65934 + entry->next = *curr;
65935 + *curr = entry;
65936 +
65937 + return;
65938 +}
65939 +
65940 +static void
65941 +insert_inodev_entry(struct inodev_entry *entry)
65942 +{
65943 + __insert_inodev_entry(&running_polstate, entry);
65944 +}
65945 +
65946 +void
65947 +insert_acl_obj_label(struct acl_object_label *obj,
65948 + struct acl_subject_label *subj)
65949 +{
65950 + unsigned int index =
65951 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
65952 + struct acl_object_label **curr;
65953 +
65954 + obj->prev = NULL;
65955 +
65956 + curr = &subj->obj_hash[index];
65957 + if (*curr != NULL)
65958 + (*curr)->prev = obj;
65959 +
65960 + obj->next = *curr;
65961 + *curr = obj;
65962 +
65963 + return;
65964 +}
65965 +
65966 +void
65967 +insert_acl_subj_label(struct acl_subject_label *obj,
65968 + struct acl_role_label *role)
65969 +{
65970 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
65971 + struct acl_subject_label **curr;
65972 +
65973 + obj->prev = NULL;
65974 +
65975 + curr = &role->subj_hash[index];
65976 + if (*curr != NULL)
65977 + (*curr)->prev = obj;
65978 +
65979 + obj->next = *curr;
65980 + *curr = obj;
65981 +
65982 + return;
65983 +}
65984 +
65985 +/* derived from glibc fnmatch() 0: match, 1: no match*/
65986 +
65987 +static int
65988 +glob_match(const char *p, const char *n)
65989 +{
65990 + char c;
65991 +
65992 + while ((c = *p++) != '\0') {
65993 + switch (c) {
65994 + case '?':
65995 + if (*n == '\0')
65996 + return 1;
65997 + else if (*n == '/')
65998 + return 1;
65999 + break;
66000 + case '\\':
66001 + if (*n != c)
66002 + return 1;
66003 + break;
66004 + case '*':
66005 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
66006 + if (*n == '/')
66007 + return 1;
66008 + else if (c == '?') {
66009 + if (*n == '\0')
66010 + return 1;
66011 + else
66012 + ++n;
66013 + }
66014 + }
66015 + if (c == '\0') {
66016 + return 0;
66017 + } else {
66018 + const char *endp;
66019 +
66020 + if ((endp = strchr(n, '/')) == NULL)
66021 + endp = n + strlen(n);
66022 +
66023 + if (c == '[') {
66024 + for (--p; n < endp; ++n)
66025 + if (!glob_match(p, n))
66026 + return 0;
66027 + } else if (c == '/') {
66028 + while (*n != '\0' && *n != '/')
66029 + ++n;
66030 + if (*n == '/' && !glob_match(p, n + 1))
66031 + return 0;
66032 + } else {
66033 + for (--p; n < endp; ++n)
66034 + if (*n == c && !glob_match(p, n))
66035 + return 0;
66036 + }
66037 +
66038 + return 1;
66039 + }
66040 + case '[':
66041 + {
66042 + int not;
66043 + char cold;
66044 +
66045 + if (*n == '\0' || *n == '/')
66046 + return 1;
66047 +
66048 + not = (*p == '!' || *p == '^');
66049 + if (not)
66050 + ++p;
66051 +
66052 + c = *p++;
66053 + for (;;) {
66054 + unsigned char fn = (unsigned char)*n;
66055 +
66056 + if (c == '\0')
66057 + return 1;
66058 + else {
66059 + if (c == fn)
66060 + goto matched;
66061 + cold = c;
66062 + c = *p++;
66063 +
66064 + if (c == '-' && *p != ']') {
66065 + unsigned char cend = *p++;
66066 +
66067 + if (cend == '\0')
66068 + return 1;
66069 +
66070 + if (cold <= fn && fn <= cend)
66071 + goto matched;
66072 +
66073 + c = *p++;
66074 + }
66075 + }
66076 +
66077 + if (c == ']')
66078 + break;
66079 + }
66080 + if (!not)
66081 + return 1;
66082 + break;
66083 + matched:
66084 + while (c != ']') {
66085 + if (c == '\0')
66086 + return 1;
66087 +
66088 + c = *p++;
66089 + }
66090 + if (not)
66091 + return 1;
66092 + }
66093 + break;
66094 + default:
66095 + if (c != *n)
66096 + return 1;
66097 + }
66098 +
66099 + ++n;
66100 + }
66101 +
66102 + if (*n == '\0')
66103 + return 0;
66104 +
66105 + if (*n == '/')
66106 + return 0;
66107 +
66108 + return 1;
66109 +}
66110 +
66111 +static struct acl_object_label *
66112 +chk_glob_label(struct acl_object_label *globbed,
66113 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
66114 +{
66115 + struct acl_object_label *tmp;
66116 +
66117 + if (*path == NULL)
66118 + *path = gr_to_filename_nolock(dentry, mnt);
66119 +
66120 + tmp = globbed;
66121 +
66122 + while (tmp) {
66123 + if (!glob_match(tmp->filename, *path))
66124 + return tmp;
66125 + tmp = tmp->next;
66126 + }
66127 +
66128 + return NULL;
66129 +}
66130 +
66131 +static struct acl_object_label *
66132 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
66133 + const ino_t curr_ino, const dev_t curr_dev,
66134 + const struct acl_subject_label *subj, char **path, const int checkglob)
66135 +{
66136 + struct acl_subject_label *tmpsubj;
66137 + struct acl_object_label *retval;
66138 + struct acl_object_label *retval2;
66139 +
66140 + tmpsubj = (struct acl_subject_label *) subj;
66141 + read_lock(&gr_inode_lock);
66142 + do {
66143 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
66144 + if (retval) {
66145 + if (checkglob && retval->globbed) {
66146 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
66147 + if (retval2)
66148 + retval = retval2;
66149 + }
66150 + break;
66151 + }
66152 + } while ((tmpsubj = tmpsubj->parent_subject));
66153 + read_unlock(&gr_inode_lock);
66154 +
66155 + return retval;
66156 +}
66157 +
66158 +static __inline__ struct acl_object_label *
66159 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
66160 + struct dentry *curr_dentry,
66161 + const struct acl_subject_label *subj, char **path, const int checkglob)
66162 +{
66163 + int newglob = checkglob;
66164 + ino_t inode;
66165 + dev_t device;
66166 +
66167 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
66168 + as we don't want a / * rule to match instead of the / object
66169 + don't do this for create lookups that call this function though, since they're looking up
66170 + on the parent and thus need globbing checks on all paths
66171 + */
66172 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
66173 + newglob = GR_NO_GLOB;
66174 +
66175 + spin_lock(&curr_dentry->d_lock);
66176 + inode = curr_dentry->d_inode->i_ino;
66177 + device = __get_dev(curr_dentry);
66178 + spin_unlock(&curr_dentry->d_lock);
66179 +
66180 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
66181 +}
66182 +
66183 +#ifdef CONFIG_HUGETLBFS
66184 +static inline bool
66185 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
66186 +{
66187 + int i;
66188 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
66189 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
66190 + return true;
66191 + }
66192 +
66193 + return false;
66194 +}
66195 +#endif
66196 +
66197 +static struct acl_object_label *
66198 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66199 + const struct acl_subject_label *subj, char *path, const int checkglob)
66200 +{
66201 + struct dentry *dentry = (struct dentry *) l_dentry;
66202 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
66203 + struct mount *real_mnt = real_mount(mnt);
66204 + struct acl_object_label *retval;
66205 + struct dentry *parent;
66206 +
66207 + read_seqlock_excl(&mount_lock);
66208 + write_seqlock(&rename_lock);
66209 +
66210 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
66211 +#ifdef CONFIG_NET
66212 + mnt == sock_mnt ||
66213 +#endif
66214 +#ifdef CONFIG_HUGETLBFS
66215 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
66216 +#endif
66217 + /* ignore Eric Biederman */
66218 + IS_PRIVATE(l_dentry->d_inode))) {
66219 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
66220 + goto out;
66221 + }
66222 +
66223 + for (;;) {
66224 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
66225 + break;
66226 +
66227 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
66228 + if (!mnt_has_parent(real_mnt))
66229 + break;
66230 +
66231 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66232 + if (retval != NULL)
66233 + goto out;
66234 +
66235 + dentry = real_mnt->mnt_mountpoint;
66236 + real_mnt = real_mnt->mnt_parent;
66237 + mnt = &real_mnt->mnt;
66238 + continue;
66239 + }
66240 +
66241 + parent = dentry->d_parent;
66242 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66243 + if (retval != NULL)
66244 + goto out;
66245 +
66246 + dentry = parent;
66247 + }
66248 +
66249 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66250 +
66251 + /* gr_real_root is pinned so we don't have to hold a reference */
66252 + if (retval == NULL)
66253 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
66254 +out:
66255 + write_sequnlock(&rename_lock);
66256 + read_sequnlock_excl(&mount_lock);
66257 +
66258 + BUG_ON(retval == NULL);
66259 +
66260 + return retval;
66261 +}
66262 +
66263 +static __inline__ struct acl_object_label *
66264 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66265 + const struct acl_subject_label *subj)
66266 +{
66267 + char *path = NULL;
66268 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
66269 +}
66270 +
66271 +static __inline__ struct acl_object_label *
66272 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66273 + const struct acl_subject_label *subj)
66274 +{
66275 + char *path = NULL;
66276 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
66277 +}
66278 +
66279 +static __inline__ struct acl_object_label *
66280 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66281 + const struct acl_subject_label *subj, char *path)
66282 +{
66283 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
66284 +}
66285 +
66286 +struct acl_subject_label *
66287 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66288 + const struct acl_role_label *role)
66289 +{
66290 + struct dentry *dentry = (struct dentry *) l_dentry;
66291 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
66292 + struct mount *real_mnt = real_mount(mnt);
66293 + struct acl_subject_label *retval;
66294 + struct dentry *parent;
66295 +
66296 + read_seqlock_excl(&mount_lock);
66297 + write_seqlock(&rename_lock);
66298 +
66299 + for (;;) {
66300 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
66301 + break;
66302 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
66303 + if (!mnt_has_parent(real_mnt))
66304 + break;
66305 +
66306 + spin_lock(&dentry->d_lock);
66307 + read_lock(&gr_inode_lock);
66308 + retval =
66309 + lookup_acl_subj_label(dentry->d_inode->i_ino,
66310 + __get_dev(dentry), role);
66311 + read_unlock(&gr_inode_lock);
66312 + spin_unlock(&dentry->d_lock);
66313 + if (retval != NULL)
66314 + goto out;
66315 +
66316 + dentry = real_mnt->mnt_mountpoint;
66317 + real_mnt = real_mnt->mnt_parent;
66318 + mnt = &real_mnt->mnt;
66319 + continue;
66320 + }
66321 +
66322 + spin_lock(&dentry->d_lock);
66323 + read_lock(&gr_inode_lock);
66324 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
66325 + __get_dev(dentry), role);
66326 + read_unlock(&gr_inode_lock);
66327 + parent = dentry->d_parent;
66328 + spin_unlock(&dentry->d_lock);
66329 +
66330 + if (retval != NULL)
66331 + goto out;
66332 +
66333 + dentry = parent;
66334 + }
66335 +
66336 + spin_lock(&dentry->d_lock);
66337 + read_lock(&gr_inode_lock);
66338 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
66339 + __get_dev(dentry), role);
66340 + read_unlock(&gr_inode_lock);
66341 + spin_unlock(&dentry->d_lock);
66342 +
66343 + if (unlikely(retval == NULL)) {
66344 + /* gr_real_root is pinned, we don't need to hold a reference */
66345 + read_lock(&gr_inode_lock);
66346 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
66347 + __get_dev(gr_real_root.dentry), role);
66348 + read_unlock(&gr_inode_lock);
66349 + }
66350 +out:
66351 + write_sequnlock(&rename_lock);
66352 + read_sequnlock_excl(&mount_lock);
66353 +
66354 + BUG_ON(retval == NULL);
66355 +
66356 + return retval;
66357 +}
66358 +
66359 +void
66360 +assign_special_role(const char *rolename)
66361 +{
66362 + struct acl_object_label *obj;
66363 + struct acl_role_label *r;
66364 + struct acl_role_label *assigned = NULL;
66365 + struct task_struct *tsk;
66366 + struct file *filp;
66367 +
66368 + FOR_EACH_ROLE_START(r)
66369 + if (!strcmp(rolename, r->rolename) &&
66370 + (r->roletype & GR_ROLE_SPECIAL)) {
66371 + assigned = r;
66372 + break;
66373 + }
66374 + FOR_EACH_ROLE_END(r)
66375 +
66376 + if (!assigned)
66377 + return;
66378 +
66379 + read_lock(&tasklist_lock);
66380 + read_lock(&grsec_exec_file_lock);
66381 +
66382 + tsk = current->real_parent;
66383 + if (tsk == NULL)
66384 + goto out_unlock;
66385 +
66386 + filp = tsk->exec_file;
66387 + if (filp == NULL)
66388 + goto out_unlock;
66389 +
66390 + tsk->is_writable = 0;
66391 + tsk->inherited = 0;
66392 +
66393 + tsk->acl_sp_role = 1;
66394 + tsk->acl_role_id = ++acl_sp_role_value;
66395 + tsk->role = assigned;
66396 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
66397 +
66398 + /* ignore additional mmap checks for processes that are writable
66399 + by the default ACL */
66400 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
66401 + if (unlikely(obj->mode & GR_WRITE))
66402 + tsk->is_writable = 1;
66403 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
66404 + if (unlikely(obj->mode & GR_WRITE))
66405 + tsk->is_writable = 1;
66406 +
66407 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66408 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
66409 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
66410 +#endif
66411 +
66412 +out_unlock:
66413 + read_unlock(&grsec_exec_file_lock);
66414 + read_unlock(&tasklist_lock);
66415 + return;
66416 +}
66417 +
66418 +
66419 +static void
66420 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
66421 +{
66422 + struct task_struct *task = current;
66423 + const struct cred *cred = current_cred();
66424 +
66425 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
66426 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66427 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66428 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
66429 +
66430 + return;
66431 +}
66432 +
66433 +static void
66434 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
66435 +{
66436 + struct task_struct *task = current;
66437 + const struct cred *cred = current_cred();
66438 +
66439 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
66440 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66441 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66442 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
66443 +
66444 + return;
66445 +}
66446 +
66447 +static void
66448 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
66449 +{
66450 + struct task_struct *task = current;
66451 + const struct cred *cred = current_cred();
66452 +
66453 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
66454 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66455 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66456 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
66457 +
66458 + return;
66459 +}
66460 +
66461 +static void
66462 +gr_set_proc_res(struct task_struct *task)
66463 +{
66464 + struct acl_subject_label *proc;
66465 + unsigned short i;
66466 +
66467 + proc = task->acl;
66468 +
66469 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
66470 + return;
66471 +
66472 + for (i = 0; i < RLIM_NLIMITS; i++) {
66473 + if (!(proc->resmask & (1U << i)))
66474 + continue;
66475 +
66476 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
66477 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
66478 +
66479 + if (i == RLIMIT_CPU)
66480 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
66481 + }
66482 +
66483 + return;
66484 +}
66485 +
66486 +/* both of the below must be called with
66487 + rcu_read_lock();
66488 + read_lock(&tasklist_lock);
66489 + read_lock(&grsec_exec_file_lock);
66490 +*/
66491 +
66492 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
66493 +{
66494 + char *tmpname;
66495 + struct acl_subject_label *tmpsubj;
66496 + struct file *filp;
66497 + struct name_entry *nmatch;
66498 +
66499 + filp = task->exec_file;
66500 + if (filp == NULL)
66501 + return NULL;
66502 +
66503 + /* the following is to apply the correct subject
66504 + on binaries running when the RBAC system
66505 + is enabled, when the binaries have been
66506 + replaced or deleted since their execution
66507 + -----
66508 + when the RBAC system starts, the inode/dev
66509 + from exec_file will be one the RBAC system
66510 + is unaware of. It only knows the inode/dev
66511 + of the present file on disk, or the absence
66512 + of it.
66513 + */
66514 +
66515 + if (filename)
66516 + nmatch = __lookup_name_entry(state, filename);
66517 + else {
66518 + preempt_disable();
66519 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
66520 +
66521 + nmatch = __lookup_name_entry(state, tmpname);
66522 + preempt_enable();
66523 + }
66524 + tmpsubj = NULL;
66525 + if (nmatch) {
66526 + if (nmatch->deleted)
66527 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
66528 + else
66529 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
66530 + }
66531 + /* this also works for the reload case -- if we don't match a potentially inherited subject
66532 + then we fall back to a normal lookup based on the binary's ino/dev
66533 + */
66534 + if (tmpsubj == NULL)
66535 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
66536 +
66537 + return tmpsubj;
66538 +}
66539 +
66540 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
66541 +{
66542 + return __gr_get_subject_for_task(&running_polstate, task, filename);
66543 +}
66544 +
66545 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
66546 +{
66547 + struct acl_object_label *obj;
66548 + struct file *filp;
66549 +
66550 + filp = task->exec_file;
66551 +
66552 + task->acl = subj;
66553 + task->is_writable = 0;
66554 + /* ignore additional mmap checks for processes that are writable
66555 + by the default ACL */
66556 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
66557 + if (unlikely(obj->mode & GR_WRITE))
66558 + task->is_writable = 1;
66559 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
66560 + if (unlikely(obj->mode & GR_WRITE))
66561 + task->is_writable = 1;
66562 +
66563 + gr_set_proc_res(task);
66564 +
66565 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66566 + 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);
66567 +#endif
66568 +}
66569 +
66570 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
66571 +{
66572 + __gr_apply_subject_to_task(&running_polstate, task, subj);
66573 +}
66574 +
66575 +__u32
66576 +gr_search_file(const struct dentry * dentry, const __u32 mode,
66577 + const struct vfsmount * mnt)
66578 +{
66579 + __u32 retval = mode;
66580 + struct acl_subject_label *curracl;
66581 + struct acl_object_label *currobj;
66582 +
66583 + if (unlikely(!(gr_status & GR_READY)))
66584 + return (mode & ~GR_AUDITS);
66585 +
66586 + curracl = current->acl;
66587 +
66588 + currobj = chk_obj_label(dentry, mnt, curracl);
66589 + retval = currobj->mode & mode;
66590 +
66591 + /* if we're opening a specified transfer file for writing
66592 + (e.g. /dev/initctl), then transfer our role to init
66593 + */
66594 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
66595 + current->role->roletype & GR_ROLE_PERSIST)) {
66596 + struct task_struct *task = init_pid_ns.child_reaper;
66597 +
66598 + if (task->role != current->role) {
66599 + struct acl_subject_label *subj;
66600 +
66601 + task->acl_sp_role = 0;
66602 + task->acl_role_id = current->acl_role_id;
66603 + task->role = current->role;
66604 + rcu_read_lock();
66605 + read_lock(&grsec_exec_file_lock);
66606 + subj = gr_get_subject_for_task(task, NULL);
66607 + gr_apply_subject_to_task(task, subj);
66608 + read_unlock(&grsec_exec_file_lock);
66609 + rcu_read_unlock();
66610 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
66611 + }
66612 + }
66613 +
66614 + if (unlikely
66615 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
66616 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
66617 + __u32 new_mode = mode;
66618 +
66619 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
66620 +
66621 + retval = new_mode;
66622 +
66623 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
66624 + new_mode |= GR_INHERIT;
66625 +
66626 + if (!(mode & GR_NOLEARN))
66627 + gr_log_learn(dentry, mnt, new_mode);
66628 + }
66629 +
66630 + return retval;
66631 +}
66632 +
66633 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
66634 + const struct dentry *parent,
66635 + const struct vfsmount *mnt)
66636 +{
66637 + struct name_entry *match;
66638 + struct acl_object_label *matchpo;
66639 + struct acl_subject_label *curracl;
66640 + char *path;
66641 +
66642 + if (unlikely(!(gr_status & GR_READY)))
66643 + return NULL;
66644 +
66645 + preempt_disable();
66646 + path = gr_to_filename_rbac(new_dentry, mnt);
66647 + match = lookup_name_entry_create(path);
66648 +
66649 + curracl = current->acl;
66650 +
66651 + if (match) {
66652 + read_lock(&gr_inode_lock);
66653 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
66654 + read_unlock(&gr_inode_lock);
66655 +
66656 + if (matchpo) {
66657 + preempt_enable();
66658 + return matchpo;
66659 + }
66660 + }
66661 +
66662 + // lookup parent
66663 +
66664 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
66665 +
66666 + preempt_enable();
66667 + return matchpo;
66668 +}
66669 +
66670 +__u32
66671 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
66672 + const struct vfsmount * mnt, const __u32 mode)
66673 +{
66674 + struct acl_object_label *matchpo;
66675 + __u32 retval;
66676 +
66677 + if (unlikely(!(gr_status & GR_READY)))
66678 + return (mode & ~GR_AUDITS);
66679 +
66680 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
66681 +
66682 + retval = matchpo->mode & mode;
66683 +
66684 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
66685 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
66686 + __u32 new_mode = mode;
66687 +
66688 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
66689 +
66690 + gr_log_learn(new_dentry, mnt, new_mode);
66691 + return new_mode;
66692 + }
66693 +
66694 + return retval;
66695 +}
66696 +
66697 +__u32
66698 +gr_check_link(const struct dentry * new_dentry,
66699 + const struct dentry * parent_dentry,
66700 + const struct vfsmount * parent_mnt,
66701 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
66702 +{
66703 + struct acl_object_label *obj;
66704 + __u32 oldmode, newmode;
66705 + __u32 needmode;
66706 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
66707 + GR_DELETE | GR_INHERIT;
66708 +
66709 + if (unlikely(!(gr_status & GR_READY)))
66710 + return (GR_CREATE | GR_LINK);
66711 +
66712 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
66713 + oldmode = obj->mode;
66714 +
66715 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
66716 + newmode = obj->mode;
66717 +
66718 + needmode = newmode & checkmodes;
66719 +
66720 + // old name for hardlink must have at least the permissions of the new name
66721 + if ((oldmode & needmode) != needmode)
66722 + goto bad;
66723 +
66724 + // if old name had restrictions/auditing, make sure the new name does as well
66725 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
66726 +
66727 + // don't allow hardlinking of suid/sgid/fcapped files without permission
66728 + if (is_privileged_binary(old_dentry))
66729 + needmode |= GR_SETID;
66730 +
66731 + if ((newmode & needmode) != needmode)
66732 + goto bad;
66733 +
66734 + // enforce minimum permissions
66735 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
66736 + return newmode;
66737 +bad:
66738 + needmode = oldmode;
66739 + if (is_privileged_binary(old_dentry))
66740 + needmode |= GR_SETID;
66741 +
66742 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
66743 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
66744 + return (GR_CREATE | GR_LINK);
66745 + } else if (newmode & GR_SUPPRESS)
66746 + return GR_SUPPRESS;
66747 + else
66748 + return 0;
66749 +}
66750 +
66751 +int
66752 +gr_check_hidden_task(const struct task_struct *task)
66753 +{
66754 + if (unlikely(!(gr_status & GR_READY)))
66755 + return 0;
66756 +
66757 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
66758 + return 1;
66759 +
66760 + return 0;
66761 +}
66762 +
66763 +int
66764 +gr_check_protected_task(const struct task_struct *task)
66765 +{
66766 + if (unlikely(!(gr_status & GR_READY) || !task))
66767 + return 0;
66768 +
66769 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
66770 + task->acl != current->acl)
66771 + return 1;
66772 +
66773 + return 0;
66774 +}
66775 +
66776 +int
66777 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
66778 +{
66779 + struct task_struct *p;
66780 + int ret = 0;
66781 +
66782 + if (unlikely(!(gr_status & GR_READY) || !pid))
66783 + return ret;
66784 +
66785 + read_lock(&tasklist_lock);
66786 + do_each_pid_task(pid, type, p) {
66787 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
66788 + p->acl != current->acl) {
66789 + ret = 1;
66790 + goto out;
66791 + }
66792 + } while_each_pid_task(pid, type, p);
66793 +out:
66794 + read_unlock(&tasklist_lock);
66795 +
66796 + return ret;
66797 +}
66798 +
66799 +void
66800 +gr_copy_label(struct task_struct *tsk)
66801 +{
66802 + struct task_struct *p = current;
66803 +
66804 + tsk->inherited = p->inherited;
66805 + tsk->acl_sp_role = 0;
66806 + tsk->acl_role_id = p->acl_role_id;
66807 + tsk->acl = p->acl;
66808 + tsk->role = p->role;
66809 + tsk->signal->used_accept = 0;
66810 + tsk->signal->curr_ip = p->signal->curr_ip;
66811 + tsk->signal->saved_ip = p->signal->saved_ip;
66812 + if (p->exec_file)
66813 + get_file(p->exec_file);
66814 + tsk->exec_file = p->exec_file;
66815 + tsk->is_writable = p->is_writable;
66816 + if (unlikely(p->signal->used_accept)) {
66817 + p->signal->curr_ip = 0;
66818 + p->signal->saved_ip = 0;
66819 + }
66820 +
66821 + return;
66822 +}
66823 +
66824 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
66825 +
66826 +int
66827 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
66828 +{
66829 + unsigned int i;
66830 + __u16 num;
66831 + uid_t *uidlist;
66832 + uid_t curuid;
66833 + int realok = 0;
66834 + int effectiveok = 0;
66835 + int fsok = 0;
66836 + uid_t globalreal, globaleffective, globalfs;
66837 +
66838 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
66839 + struct user_struct *user;
66840 +
66841 + if (!uid_valid(real))
66842 + goto skipit;
66843 +
66844 + /* find user based on global namespace */
66845 +
66846 + globalreal = GR_GLOBAL_UID(real);
66847 +
66848 + user = find_user(make_kuid(&init_user_ns, globalreal));
66849 + if (user == NULL)
66850 + goto skipit;
66851 +
66852 + if (gr_process_kernel_setuid_ban(user)) {
66853 + /* for find_user */
66854 + free_uid(user);
66855 + return 1;
66856 + }
66857 +
66858 + /* for find_user */
66859 + free_uid(user);
66860 +
66861 +skipit:
66862 +#endif
66863 +
66864 + if (unlikely(!(gr_status & GR_READY)))
66865 + return 0;
66866 +
66867 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66868 + gr_log_learn_uid_change(real, effective, fs);
66869 +
66870 + num = current->acl->user_trans_num;
66871 + uidlist = current->acl->user_transitions;
66872 +
66873 + if (uidlist == NULL)
66874 + return 0;
66875 +
66876 + if (!uid_valid(real)) {
66877 + realok = 1;
66878 + globalreal = (uid_t)-1;
66879 + } else {
66880 + globalreal = GR_GLOBAL_UID(real);
66881 + }
66882 + if (!uid_valid(effective)) {
66883 + effectiveok = 1;
66884 + globaleffective = (uid_t)-1;
66885 + } else {
66886 + globaleffective = GR_GLOBAL_UID(effective);
66887 + }
66888 + if (!uid_valid(fs)) {
66889 + fsok = 1;
66890 + globalfs = (uid_t)-1;
66891 + } else {
66892 + globalfs = GR_GLOBAL_UID(fs);
66893 + }
66894 +
66895 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
66896 + for (i = 0; i < num; i++) {
66897 + curuid = uidlist[i];
66898 + if (globalreal == curuid)
66899 + realok = 1;
66900 + if (globaleffective == curuid)
66901 + effectiveok = 1;
66902 + if (globalfs == curuid)
66903 + fsok = 1;
66904 + }
66905 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
66906 + for (i = 0; i < num; i++) {
66907 + curuid = uidlist[i];
66908 + if (globalreal == curuid)
66909 + break;
66910 + if (globaleffective == curuid)
66911 + break;
66912 + if (globalfs == curuid)
66913 + break;
66914 + }
66915 + /* not in deny list */
66916 + if (i == num) {
66917 + realok = 1;
66918 + effectiveok = 1;
66919 + fsok = 1;
66920 + }
66921 + }
66922 +
66923 + if (realok && effectiveok && fsok)
66924 + return 0;
66925 + else {
66926 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
66927 + return 1;
66928 + }
66929 +}
66930 +
66931 +int
66932 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
66933 +{
66934 + unsigned int i;
66935 + __u16 num;
66936 + gid_t *gidlist;
66937 + gid_t curgid;
66938 + int realok = 0;
66939 + int effectiveok = 0;
66940 + int fsok = 0;
66941 + gid_t globalreal, globaleffective, globalfs;
66942 +
66943 + if (unlikely(!(gr_status & GR_READY)))
66944 + return 0;
66945 +
66946 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66947 + gr_log_learn_gid_change(real, effective, fs);
66948 +
66949 + num = current->acl->group_trans_num;
66950 + gidlist = current->acl->group_transitions;
66951 +
66952 + if (gidlist == NULL)
66953 + return 0;
66954 +
66955 + if (!gid_valid(real)) {
66956 + realok = 1;
66957 + globalreal = (gid_t)-1;
66958 + } else {
66959 + globalreal = GR_GLOBAL_GID(real);
66960 + }
66961 + if (!gid_valid(effective)) {
66962 + effectiveok = 1;
66963 + globaleffective = (gid_t)-1;
66964 + } else {
66965 + globaleffective = GR_GLOBAL_GID(effective);
66966 + }
66967 + if (!gid_valid(fs)) {
66968 + fsok = 1;
66969 + globalfs = (gid_t)-1;
66970 + } else {
66971 + globalfs = GR_GLOBAL_GID(fs);
66972 + }
66973 +
66974 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
66975 + for (i = 0; i < num; i++) {
66976 + curgid = gidlist[i];
66977 + if (globalreal == curgid)
66978 + realok = 1;
66979 + if (globaleffective == curgid)
66980 + effectiveok = 1;
66981 + if (globalfs == curgid)
66982 + fsok = 1;
66983 + }
66984 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
66985 + for (i = 0; i < num; i++) {
66986 + curgid = gidlist[i];
66987 + if (globalreal == curgid)
66988 + break;
66989 + if (globaleffective == curgid)
66990 + break;
66991 + if (globalfs == curgid)
66992 + break;
66993 + }
66994 + /* not in deny list */
66995 + if (i == num) {
66996 + realok = 1;
66997 + effectiveok = 1;
66998 + fsok = 1;
66999 + }
67000 + }
67001 +
67002 + if (realok && effectiveok && fsok)
67003 + return 0;
67004 + else {
67005 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
67006 + return 1;
67007 + }
67008 +}
67009 +
67010 +extern int gr_acl_is_capable(const int cap);
67011 +
67012 +void
67013 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
67014 +{
67015 + struct acl_role_label *role = task->role;
67016 + struct acl_subject_label *subj = NULL;
67017 + struct acl_object_label *obj;
67018 + struct file *filp;
67019 + uid_t uid;
67020 + gid_t gid;
67021 +
67022 + if (unlikely(!(gr_status & GR_READY)))
67023 + return;
67024 +
67025 + uid = GR_GLOBAL_UID(kuid);
67026 + gid = GR_GLOBAL_GID(kgid);
67027 +
67028 + filp = task->exec_file;
67029 +
67030 + /* kernel process, we'll give them the kernel role */
67031 + if (unlikely(!filp)) {
67032 + task->role = running_polstate.kernel_role;
67033 + task->acl = running_polstate.kernel_role->root_label;
67034 + return;
67035 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
67036 + /* save the current ip at time of role lookup so that the proper
67037 + IP will be learned for role_allowed_ip */
67038 + task->signal->saved_ip = task->signal->curr_ip;
67039 + role = lookup_acl_role_label(task, uid, gid);
67040 + }
67041 +
67042 + /* don't change the role if we're not a privileged process */
67043 + if (role && task->role != role &&
67044 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
67045 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
67046 + return;
67047 +
67048 + /* perform subject lookup in possibly new role
67049 + we can use this result below in the case where role == task->role
67050 + */
67051 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
67052 +
67053 + /* if we changed uid/gid, but result in the same role
67054 + and are using inheritance, don't lose the inherited subject
67055 + if current subject is other than what normal lookup
67056 + would result in, we arrived via inheritance, don't
67057 + lose subject
67058 + */
67059 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
67060 + (subj == task->acl)))
67061 + task->acl = subj;
67062 +
67063 + /* leave task->inherited unaffected */
67064 +
67065 + task->role = role;
67066 +
67067 + task->is_writable = 0;
67068 +
67069 + /* ignore additional mmap checks for processes that are writable
67070 + by the default ACL */
67071 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67072 + if (unlikely(obj->mode & GR_WRITE))
67073 + task->is_writable = 1;
67074 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67075 + if (unlikely(obj->mode & GR_WRITE))
67076 + task->is_writable = 1;
67077 +
67078 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67079 + 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);
67080 +#endif
67081 +
67082 + gr_set_proc_res(task);
67083 +
67084 + return;
67085 +}
67086 +
67087 +int
67088 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
67089 + const int unsafe_flags)
67090 +{
67091 + struct task_struct *task = current;
67092 + struct acl_subject_label *newacl;
67093 + struct acl_object_label *obj;
67094 + __u32 retmode;
67095 +
67096 + if (unlikely(!(gr_status & GR_READY)))
67097 + return 0;
67098 +
67099 + newacl = chk_subj_label(dentry, mnt, task->role);
67100 +
67101 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
67102 + did an exec
67103 + */
67104 + rcu_read_lock();
67105 + read_lock(&tasklist_lock);
67106 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
67107 + (task->parent->acl->mode & GR_POVERRIDE))) {
67108 + read_unlock(&tasklist_lock);
67109 + rcu_read_unlock();
67110 + goto skip_check;
67111 + }
67112 + read_unlock(&tasklist_lock);
67113 + rcu_read_unlock();
67114 +
67115 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
67116 + !(task->role->roletype & GR_ROLE_GOD) &&
67117 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
67118 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67119 + if (unsafe_flags & LSM_UNSAFE_SHARE)
67120 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
67121 + else
67122 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
67123 + return -EACCES;
67124 + }
67125 +
67126 +skip_check:
67127 +
67128 + obj = chk_obj_label(dentry, mnt, task->acl);
67129 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
67130 +
67131 + if (!(task->acl->mode & GR_INHERITLEARN) &&
67132 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
67133 + if (obj->nested)
67134 + task->acl = obj->nested;
67135 + else
67136 + task->acl = newacl;
67137 + task->inherited = 0;
67138 + } else {
67139 + task->inherited = 1;
67140 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
67141 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
67142 + }
67143 +
67144 + task->is_writable = 0;
67145 +
67146 + /* ignore additional mmap checks for processes that are writable
67147 + by the default ACL */
67148 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
67149 + if (unlikely(obj->mode & GR_WRITE))
67150 + task->is_writable = 1;
67151 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
67152 + if (unlikely(obj->mode & GR_WRITE))
67153 + task->is_writable = 1;
67154 +
67155 + gr_set_proc_res(task);
67156 +
67157 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67158 + 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);
67159 +#endif
67160 + return 0;
67161 +}
67162 +
67163 +/* always called with valid inodev ptr */
67164 +static void
67165 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
67166 +{
67167 + struct acl_object_label *matchpo;
67168 + struct acl_subject_label *matchps;
67169 + struct acl_subject_label *subj;
67170 + struct acl_role_label *role;
67171 + unsigned int x;
67172 +
67173 + FOR_EACH_ROLE_START(role)
67174 + FOR_EACH_SUBJECT_START(role, subj, x)
67175 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
67176 + matchpo->mode |= GR_DELETED;
67177 + FOR_EACH_SUBJECT_END(subj,x)
67178 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
67179 + /* nested subjects aren't in the role's subj_hash table */
67180 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
67181 + matchpo->mode |= GR_DELETED;
67182 + FOR_EACH_NESTED_SUBJECT_END(subj)
67183 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
67184 + matchps->mode |= GR_DELETED;
67185 + FOR_EACH_ROLE_END(role)
67186 +
67187 + inodev->nentry->deleted = 1;
67188 +
67189 + return;
67190 +}
67191 +
67192 +void
67193 +gr_handle_delete(const ino_t ino, const dev_t dev)
67194 +{
67195 + struct inodev_entry *inodev;
67196 +
67197 + if (unlikely(!(gr_status & GR_READY)))
67198 + return;
67199 +
67200 + write_lock(&gr_inode_lock);
67201 + inodev = lookup_inodev_entry(ino, dev);
67202 + if (inodev != NULL)
67203 + do_handle_delete(inodev, ino, dev);
67204 + write_unlock(&gr_inode_lock);
67205 +
67206 + return;
67207 +}
67208 +
67209 +static void
67210 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
67211 + const ino_t newinode, const dev_t newdevice,
67212 + struct acl_subject_label *subj)
67213 +{
67214 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
67215 + struct acl_object_label *match;
67216 +
67217 + match = subj->obj_hash[index];
67218 +
67219 + while (match && (match->inode != oldinode ||
67220 + match->device != olddevice ||
67221 + !(match->mode & GR_DELETED)))
67222 + match = match->next;
67223 +
67224 + if (match && (match->inode == oldinode)
67225 + && (match->device == olddevice)
67226 + && (match->mode & GR_DELETED)) {
67227 + if (match->prev == NULL) {
67228 + subj->obj_hash[index] = match->next;
67229 + if (match->next != NULL)
67230 + match->next->prev = NULL;
67231 + } else {
67232 + match->prev->next = match->next;
67233 + if (match->next != NULL)
67234 + match->next->prev = match->prev;
67235 + }
67236 + match->prev = NULL;
67237 + match->next = NULL;
67238 + match->inode = newinode;
67239 + match->device = newdevice;
67240 + match->mode &= ~GR_DELETED;
67241 +
67242 + insert_acl_obj_label(match, subj);
67243 + }
67244 +
67245 + return;
67246 +}
67247 +
67248 +static void
67249 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
67250 + const ino_t newinode, const dev_t newdevice,
67251 + struct acl_role_label *role)
67252 +{
67253 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
67254 + struct acl_subject_label *match;
67255 +
67256 + match = role->subj_hash[index];
67257 +
67258 + while (match && (match->inode != oldinode ||
67259 + match->device != olddevice ||
67260 + !(match->mode & GR_DELETED)))
67261 + match = match->next;
67262 +
67263 + if (match && (match->inode == oldinode)
67264 + && (match->device == olddevice)
67265 + && (match->mode & GR_DELETED)) {
67266 + if (match->prev == NULL) {
67267 + role->subj_hash[index] = match->next;
67268 + if (match->next != NULL)
67269 + match->next->prev = NULL;
67270 + } else {
67271 + match->prev->next = match->next;
67272 + if (match->next != NULL)
67273 + match->next->prev = match->prev;
67274 + }
67275 + match->prev = NULL;
67276 + match->next = NULL;
67277 + match->inode = newinode;
67278 + match->device = newdevice;
67279 + match->mode &= ~GR_DELETED;
67280 +
67281 + insert_acl_subj_label(match, role);
67282 + }
67283 +
67284 + return;
67285 +}
67286 +
67287 +static void
67288 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
67289 + const ino_t newinode, const dev_t newdevice)
67290 +{
67291 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
67292 + struct inodev_entry *match;
67293 +
67294 + match = running_polstate.inodev_set.i_hash[index];
67295 +
67296 + while (match && (match->nentry->inode != oldinode ||
67297 + match->nentry->device != olddevice || !match->nentry->deleted))
67298 + match = match->next;
67299 +
67300 + if (match && (match->nentry->inode == oldinode)
67301 + && (match->nentry->device == olddevice) &&
67302 + match->nentry->deleted) {
67303 + if (match->prev == NULL) {
67304 + running_polstate.inodev_set.i_hash[index] = match->next;
67305 + if (match->next != NULL)
67306 + match->next->prev = NULL;
67307 + } else {
67308 + match->prev->next = match->next;
67309 + if (match->next != NULL)
67310 + match->next->prev = match->prev;
67311 + }
67312 + match->prev = NULL;
67313 + match->next = NULL;
67314 + match->nentry->inode = newinode;
67315 + match->nentry->device = newdevice;
67316 + match->nentry->deleted = 0;
67317 +
67318 + insert_inodev_entry(match);
67319 + }
67320 +
67321 + return;
67322 +}
67323 +
67324 +static void
67325 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
67326 +{
67327 + struct acl_subject_label *subj;
67328 + struct acl_role_label *role;
67329 + unsigned int x;
67330 +
67331 + FOR_EACH_ROLE_START(role)
67332 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
67333 +
67334 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
67335 + if ((subj->inode == ino) && (subj->device == dev)) {
67336 + subj->inode = ino;
67337 + subj->device = dev;
67338 + }
67339 + /* nested subjects aren't in the role's subj_hash table */
67340 + update_acl_obj_label(matchn->inode, matchn->device,
67341 + ino, dev, subj);
67342 + FOR_EACH_NESTED_SUBJECT_END(subj)
67343 + FOR_EACH_SUBJECT_START(role, subj, x)
67344 + update_acl_obj_label(matchn->inode, matchn->device,
67345 + ino, dev, subj);
67346 + FOR_EACH_SUBJECT_END(subj,x)
67347 + FOR_EACH_ROLE_END(role)
67348 +
67349 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
67350 +
67351 + return;
67352 +}
67353 +
67354 +static void
67355 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
67356 + const struct vfsmount *mnt)
67357 +{
67358 + ino_t ino = dentry->d_inode->i_ino;
67359 + dev_t dev = __get_dev(dentry);
67360 +
67361 + __do_handle_create(matchn, ino, dev);
67362 +
67363 + return;
67364 +}
67365 +
67366 +void
67367 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
67368 +{
67369 + struct name_entry *matchn;
67370 +
67371 + if (unlikely(!(gr_status & GR_READY)))
67372 + return;
67373 +
67374 + preempt_disable();
67375 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
67376 +
67377 + if (unlikely((unsigned long)matchn)) {
67378 + write_lock(&gr_inode_lock);
67379 + do_handle_create(matchn, dentry, mnt);
67380 + write_unlock(&gr_inode_lock);
67381 + }
67382 + preempt_enable();
67383 +
67384 + return;
67385 +}
67386 +
67387 +void
67388 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
67389 +{
67390 + struct name_entry *matchn;
67391 +
67392 + if (unlikely(!(gr_status & GR_READY)))
67393 + return;
67394 +
67395 + preempt_disable();
67396 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
67397 +
67398 + if (unlikely((unsigned long)matchn)) {
67399 + write_lock(&gr_inode_lock);
67400 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
67401 + write_unlock(&gr_inode_lock);
67402 + }
67403 + preempt_enable();
67404 +
67405 + return;
67406 +}
67407 +
67408 +void
67409 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
67410 + struct dentry *old_dentry,
67411 + struct dentry *new_dentry,
67412 + struct vfsmount *mnt, const __u8 replace)
67413 +{
67414 + struct name_entry *matchn;
67415 + struct inodev_entry *inodev;
67416 + struct inode *inode = new_dentry->d_inode;
67417 + ino_t old_ino = old_dentry->d_inode->i_ino;
67418 + dev_t old_dev = __get_dev(old_dentry);
67419 +
67420 + /* vfs_rename swaps the name and parent link for old_dentry and
67421 + new_dentry
67422 + at this point, old_dentry has the new name, parent link, and inode
67423 + for the renamed file
67424 + if a file is being replaced by a rename, new_dentry has the inode
67425 + and name for the replaced file
67426 + */
67427 +
67428 + if (unlikely(!(gr_status & GR_READY)))
67429 + return;
67430 +
67431 + preempt_disable();
67432 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
67433 +
67434 + /* we wouldn't have to check d_inode if it weren't for
67435 + NFS silly-renaming
67436 + */
67437 +
67438 + write_lock(&gr_inode_lock);
67439 + if (unlikely(replace && inode)) {
67440 + ino_t new_ino = inode->i_ino;
67441 + dev_t new_dev = __get_dev(new_dentry);
67442 +
67443 + inodev = lookup_inodev_entry(new_ino, new_dev);
67444 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
67445 + do_handle_delete(inodev, new_ino, new_dev);
67446 + }
67447 +
67448 + inodev = lookup_inodev_entry(old_ino, old_dev);
67449 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
67450 + do_handle_delete(inodev, old_ino, old_dev);
67451 +
67452 + if (unlikely((unsigned long)matchn))
67453 + do_handle_create(matchn, old_dentry, mnt);
67454 +
67455 + write_unlock(&gr_inode_lock);
67456 + preempt_enable();
67457 +
67458 + return;
67459 +}
67460 +
67461 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
67462 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
67463 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
67464 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
67465 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
67466 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
67467 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
67468 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
67469 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
67470 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
67471 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
67472 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
67473 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
67474 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
67475 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
67476 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
67477 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
67478 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
67479 +};
67480 +
67481 +void
67482 +gr_learn_resource(const struct task_struct *task,
67483 + const int res, const unsigned long wanted, const int gt)
67484 +{
67485 + struct acl_subject_label *acl;
67486 + const struct cred *cred;
67487 +
67488 + if (unlikely((gr_status & GR_READY) &&
67489 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
67490 + goto skip_reslog;
67491 +
67492 + gr_log_resource(task, res, wanted, gt);
67493 +skip_reslog:
67494 +
67495 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
67496 + return;
67497 +
67498 + acl = task->acl;
67499 +
67500 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
67501 + !(acl->resmask & (1U << (unsigned short) res))))
67502 + return;
67503 +
67504 + if (wanted >= acl->res[res].rlim_cur) {
67505 + unsigned long res_add;
67506 +
67507 + res_add = wanted + res_learn_bumps[res];
67508 +
67509 + acl->res[res].rlim_cur = res_add;
67510 +
67511 + if (wanted > acl->res[res].rlim_max)
67512 + acl->res[res].rlim_max = res_add;
67513 +
67514 + /* only log the subject filename, since resource logging is supported for
67515 + single-subject learning only */
67516 + rcu_read_lock();
67517 + cred = __task_cred(task);
67518 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
67519 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
67520 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
67521 + "", (unsigned long) res, &task->signal->saved_ip);
67522 + rcu_read_unlock();
67523 + }
67524 +
67525 + return;
67526 +}
67527 +EXPORT_SYMBOL(gr_learn_resource);
67528 +#endif
67529 +
67530 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
67531 +void
67532 +pax_set_initial_flags(struct linux_binprm *bprm)
67533 +{
67534 + struct task_struct *task = current;
67535 + struct acl_subject_label *proc;
67536 + unsigned long flags;
67537 +
67538 + if (unlikely(!(gr_status & GR_READY)))
67539 + return;
67540 +
67541 + flags = pax_get_flags(task);
67542 +
67543 + proc = task->acl;
67544 +
67545 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
67546 + flags &= ~MF_PAX_PAGEEXEC;
67547 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
67548 + flags &= ~MF_PAX_SEGMEXEC;
67549 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
67550 + flags &= ~MF_PAX_RANDMMAP;
67551 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
67552 + flags &= ~MF_PAX_EMUTRAMP;
67553 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
67554 + flags &= ~MF_PAX_MPROTECT;
67555 +
67556 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
67557 + flags |= MF_PAX_PAGEEXEC;
67558 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
67559 + flags |= MF_PAX_SEGMEXEC;
67560 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
67561 + flags |= MF_PAX_RANDMMAP;
67562 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
67563 + flags |= MF_PAX_EMUTRAMP;
67564 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
67565 + flags |= MF_PAX_MPROTECT;
67566 +
67567 + pax_set_flags(task, flags);
67568 +
67569 + return;
67570 +}
67571 +#endif
67572 +
67573 +int
67574 +gr_handle_proc_ptrace(struct task_struct *task)
67575 +{
67576 + struct file *filp;
67577 + struct task_struct *tmp = task;
67578 + struct task_struct *curtemp = current;
67579 + __u32 retmode;
67580 +
67581 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67582 + if (unlikely(!(gr_status & GR_READY)))
67583 + return 0;
67584 +#endif
67585 +
67586 + read_lock(&tasklist_lock);
67587 + read_lock(&grsec_exec_file_lock);
67588 + filp = task->exec_file;
67589 +
67590 + while (task_pid_nr(tmp) > 0) {
67591 + if (tmp == curtemp)
67592 + break;
67593 + tmp = tmp->real_parent;
67594 + }
67595 +
67596 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67597 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
67598 + read_unlock(&grsec_exec_file_lock);
67599 + read_unlock(&tasklist_lock);
67600 + return 1;
67601 + }
67602 +
67603 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67604 + if (!(gr_status & GR_READY)) {
67605 + read_unlock(&grsec_exec_file_lock);
67606 + read_unlock(&tasklist_lock);
67607 + return 0;
67608 + }
67609 +#endif
67610 +
67611 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
67612 + read_unlock(&grsec_exec_file_lock);
67613 + read_unlock(&tasklist_lock);
67614 +
67615 + if (retmode & GR_NOPTRACE)
67616 + return 1;
67617 +
67618 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
67619 + && (current->acl != task->acl || (current->acl != current->role->root_label
67620 + && task_pid_nr(current) != task_pid_nr(task))))
67621 + return 1;
67622 +
67623 + return 0;
67624 +}
67625 +
67626 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
67627 +{
67628 + if (unlikely(!(gr_status & GR_READY)))
67629 + return;
67630 +
67631 + if (!(current->role->roletype & GR_ROLE_GOD))
67632 + return;
67633 +
67634 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
67635 + p->role->rolename, gr_task_roletype_to_char(p),
67636 + p->acl->filename);
67637 +}
67638 +
67639 +int
67640 +gr_handle_ptrace(struct task_struct *task, const long request)
67641 +{
67642 + struct task_struct *tmp = task;
67643 + struct task_struct *curtemp = current;
67644 + __u32 retmode;
67645 +
67646 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67647 + if (unlikely(!(gr_status & GR_READY)))
67648 + return 0;
67649 +#endif
67650 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67651 + read_lock(&tasklist_lock);
67652 + while (task_pid_nr(tmp) > 0) {
67653 + if (tmp == curtemp)
67654 + break;
67655 + tmp = tmp->real_parent;
67656 + }
67657 +
67658 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67659 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
67660 + read_unlock(&tasklist_lock);
67661 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67662 + return 1;
67663 + }
67664 + read_unlock(&tasklist_lock);
67665 + }
67666 +
67667 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67668 + if (!(gr_status & GR_READY))
67669 + return 0;
67670 +#endif
67671 +
67672 + read_lock(&grsec_exec_file_lock);
67673 + if (unlikely(!task->exec_file)) {
67674 + read_unlock(&grsec_exec_file_lock);
67675 + return 0;
67676 + }
67677 +
67678 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
67679 + read_unlock(&grsec_exec_file_lock);
67680 +
67681 + if (retmode & GR_NOPTRACE) {
67682 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67683 + return 1;
67684 + }
67685 +
67686 + if (retmode & GR_PTRACERD) {
67687 + switch (request) {
67688 + case PTRACE_SEIZE:
67689 + case PTRACE_POKETEXT:
67690 + case PTRACE_POKEDATA:
67691 + case PTRACE_POKEUSR:
67692 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
67693 + case PTRACE_SETREGS:
67694 + case PTRACE_SETFPREGS:
67695 +#endif
67696 +#ifdef CONFIG_X86
67697 + case PTRACE_SETFPXREGS:
67698 +#endif
67699 +#ifdef CONFIG_ALTIVEC
67700 + case PTRACE_SETVRREGS:
67701 +#endif
67702 + return 1;
67703 + default:
67704 + return 0;
67705 + }
67706 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
67707 + !(current->role->roletype & GR_ROLE_GOD) &&
67708 + (current->acl != task->acl)) {
67709 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67710 + return 1;
67711 + }
67712 +
67713 + return 0;
67714 +}
67715 +
67716 +static int is_writable_mmap(const struct file *filp)
67717 +{
67718 + struct task_struct *task = current;
67719 + struct acl_object_label *obj, *obj2;
67720 +
67721 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
67722 + !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))) {
67723 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67724 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
67725 + task->role->root_label);
67726 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
67727 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
67728 + return 1;
67729 + }
67730 + }
67731 + return 0;
67732 +}
67733 +
67734 +int
67735 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
67736 +{
67737 + __u32 mode;
67738 +
67739 + if (unlikely(!file || !(prot & PROT_EXEC)))
67740 + return 1;
67741 +
67742 + if (is_writable_mmap(file))
67743 + return 0;
67744 +
67745 + mode =
67746 + gr_search_file(file->f_path.dentry,
67747 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67748 + file->f_path.mnt);
67749 +
67750 + if (!gr_tpe_allow(file))
67751 + return 0;
67752 +
67753 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67754 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67755 + return 0;
67756 + } else if (unlikely(!(mode & GR_EXEC))) {
67757 + return 0;
67758 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67759 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67760 + return 1;
67761 + }
67762 +
67763 + return 1;
67764 +}
67765 +
67766 +int
67767 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
67768 +{
67769 + __u32 mode;
67770 +
67771 + if (unlikely(!file || !(prot & PROT_EXEC)))
67772 + return 1;
67773 +
67774 + if (is_writable_mmap(file))
67775 + return 0;
67776 +
67777 + mode =
67778 + gr_search_file(file->f_path.dentry,
67779 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67780 + file->f_path.mnt);
67781 +
67782 + if (!gr_tpe_allow(file))
67783 + return 0;
67784 +
67785 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67786 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67787 + return 0;
67788 + } else if (unlikely(!(mode & GR_EXEC))) {
67789 + return 0;
67790 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67791 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67792 + return 1;
67793 + }
67794 +
67795 + return 1;
67796 +}
67797 +
67798 +void
67799 +gr_acl_handle_psacct(struct task_struct *task, const long code)
67800 +{
67801 + unsigned long runtime;
67802 + unsigned long cputime;
67803 + unsigned int wday, cday;
67804 + __u8 whr, chr;
67805 + __u8 wmin, cmin;
67806 + __u8 wsec, csec;
67807 + struct timespec timeval;
67808 +
67809 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
67810 + !(task->acl->mode & GR_PROCACCT)))
67811 + return;
67812 +
67813 + do_posix_clock_monotonic_gettime(&timeval);
67814 + runtime = timeval.tv_sec - task->start_time.tv_sec;
67815 + wday = runtime / (3600 * 24);
67816 + runtime -= wday * (3600 * 24);
67817 + whr = runtime / 3600;
67818 + runtime -= whr * 3600;
67819 + wmin = runtime / 60;
67820 + runtime -= wmin * 60;
67821 + wsec = runtime;
67822 +
67823 + cputime = (task->utime + task->stime) / HZ;
67824 + cday = cputime / (3600 * 24);
67825 + cputime -= cday * (3600 * 24);
67826 + chr = cputime / 3600;
67827 + cputime -= chr * 3600;
67828 + cmin = cputime / 60;
67829 + cputime -= cmin * 60;
67830 + csec = cputime;
67831 +
67832 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
67833 +
67834 + return;
67835 +}
67836 +
67837 +#ifdef CONFIG_TASKSTATS
67838 +int gr_is_taskstats_denied(int pid)
67839 +{
67840 + struct task_struct *task;
67841 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67842 + const struct cred *cred;
67843 +#endif
67844 + int ret = 0;
67845 +
67846 + /* restrict taskstats viewing to un-chrooted root users
67847 + who have the 'view' subject flag if the RBAC system is enabled
67848 + */
67849 +
67850 + rcu_read_lock();
67851 + read_lock(&tasklist_lock);
67852 + task = find_task_by_vpid(pid);
67853 + if (task) {
67854 +#ifdef CONFIG_GRKERNSEC_CHROOT
67855 + if (proc_is_chrooted(task))
67856 + ret = -EACCES;
67857 +#endif
67858 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67859 + cred = __task_cred(task);
67860 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67861 + if (gr_is_global_nonroot(cred->uid))
67862 + ret = -EACCES;
67863 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67864 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
67865 + ret = -EACCES;
67866 +#endif
67867 +#endif
67868 + if (gr_status & GR_READY) {
67869 + if (!(task->acl->mode & GR_VIEW))
67870 + ret = -EACCES;
67871 + }
67872 + } else
67873 + ret = -ENOENT;
67874 +
67875 + read_unlock(&tasklist_lock);
67876 + rcu_read_unlock();
67877 +
67878 + return ret;
67879 +}
67880 +#endif
67881 +
67882 +/* AUXV entries are filled via a descendant of search_binary_handler
67883 + after we've already applied the subject for the target
67884 +*/
67885 +int gr_acl_enable_at_secure(void)
67886 +{
67887 + if (unlikely(!(gr_status & GR_READY)))
67888 + return 0;
67889 +
67890 + if (current->acl->mode & GR_ATSECURE)
67891 + return 1;
67892 +
67893 + return 0;
67894 +}
67895 +
67896 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
67897 +{
67898 + struct task_struct *task = current;
67899 + struct dentry *dentry = file->f_path.dentry;
67900 + struct vfsmount *mnt = file->f_path.mnt;
67901 + struct acl_object_label *obj, *tmp;
67902 + struct acl_subject_label *subj;
67903 + unsigned int bufsize;
67904 + int is_not_root;
67905 + char *path;
67906 + dev_t dev = __get_dev(dentry);
67907 +
67908 + if (unlikely(!(gr_status & GR_READY)))
67909 + return 1;
67910 +
67911 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67912 + return 1;
67913 +
67914 + /* ignore Eric Biederman */
67915 + if (IS_PRIVATE(dentry->d_inode))
67916 + return 1;
67917 +
67918 + subj = task->acl;
67919 + read_lock(&gr_inode_lock);
67920 + do {
67921 + obj = lookup_acl_obj_label(ino, dev, subj);
67922 + if (obj != NULL) {
67923 + read_unlock(&gr_inode_lock);
67924 + return (obj->mode & GR_FIND) ? 1 : 0;
67925 + }
67926 + } while ((subj = subj->parent_subject));
67927 + read_unlock(&gr_inode_lock);
67928 +
67929 + /* this is purely an optimization since we're looking for an object
67930 + for the directory we're doing a readdir on
67931 + if it's possible for any globbed object to match the entry we're
67932 + filling into the directory, then the object we find here will be
67933 + an anchor point with attached globbed objects
67934 + */
67935 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
67936 + if (obj->globbed == NULL)
67937 + return (obj->mode & GR_FIND) ? 1 : 0;
67938 +
67939 + is_not_root = ((obj->filename[0] == '/') &&
67940 + (obj->filename[1] == '\0')) ? 0 : 1;
67941 + bufsize = PAGE_SIZE - namelen - is_not_root;
67942 +
67943 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
67944 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
67945 + return 1;
67946 +
67947 + preempt_disable();
67948 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67949 + bufsize);
67950 +
67951 + bufsize = strlen(path);
67952 +
67953 + /* if base is "/", don't append an additional slash */
67954 + if (is_not_root)
67955 + *(path + bufsize) = '/';
67956 + memcpy(path + bufsize + is_not_root, name, namelen);
67957 + *(path + bufsize + namelen + is_not_root) = '\0';
67958 +
67959 + tmp = obj->globbed;
67960 + while (tmp) {
67961 + if (!glob_match(tmp->filename, path)) {
67962 + preempt_enable();
67963 + return (tmp->mode & GR_FIND) ? 1 : 0;
67964 + }
67965 + tmp = tmp->next;
67966 + }
67967 + preempt_enable();
67968 + return (obj->mode & GR_FIND) ? 1 : 0;
67969 +}
67970 +
67971 +void gr_put_exec_file(struct task_struct *task)
67972 +{
67973 + struct file *filp;
67974 +
67975 + write_lock(&grsec_exec_file_lock);
67976 + filp = task->exec_file;
67977 + task->exec_file = NULL;
67978 + write_unlock(&grsec_exec_file_lock);
67979 +
67980 + if (filp)
67981 + fput(filp);
67982 +
67983 + return;
67984 +}
67985 +
67986 +
67987 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
67988 +EXPORT_SYMBOL(gr_acl_is_enabled);
67989 +#endif
67990 +#ifdef CONFIG_SECURITY
67991 +EXPORT_SYMBOL(gr_check_user_change);
67992 +EXPORT_SYMBOL(gr_check_group_change);
67993 +#endif
67994 +
67995 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
67996 new file mode 100644
67997 index 0000000..18ffbbd
67998 --- /dev/null
67999 +++ b/grsecurity/gracl_alloc.c
68000 @@ -0,0 +1,105 @@
68001 +#include <linux/kernel.h>
68002 +#include <linux/mm.h>
68003 +#include <linux/slab.h>
68004 +#include <linux/vmalloc.h>
68005 +#include <linux/gracl.h>
68006 +#include <linux/grsecurity.h>
68007 +
68008 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
68009 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
68010 +
68011 +static __inline__ int
68012 +alloc_pop(void)
68013 +{
68014 + if (current_alloc_state->alloc_stack_next == 1)
68015 + return 0;
68016 +
68017 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
68018 +
68019 + current_alloc_state->alloc_stack_next--;
68020 +
68021 + return 1;
68022 +}
68023 +
68024 +static __inline__ int
68025 +alloc_push(void *buf)
68026 +{
68027 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
68028 + return 1;
68029 +
68030 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
68031 +
68032 + current_alloc_state->alloc_stack_next++;
68033 +
68034 + return 0;
68035 +}
68036 +
68037 +void *
68038 +acl_alloc(unsigned long len)
68039 +{
68040 + void *ret = NULL;
68041 +
68042 + if (!len || len > PAGE_SIZE)
68043 + goto out;
68044 +
68045 + ret = kmalloc(len, GFP_KERNEL);
68046 +
68047 + if (ret) {
68048 + if (alloc_push(ret)) {
68049 + kfree(ret);
68050 + ret = NULL;
68051 + }
68052 + }
68053 +
68054 +out:
68055 + return ret;
68056 +}
68057 +
68058 +void *
68059 +acl_alloc_num(unsigned long num, unsigned long len)
68060 +{
68061 + if (!len || (num > (PAGE_SIZE / len)))
68062 + return NULL;
68063 +
68064 + return acl_alloc(num * len);
68065 +}
68066 +
68067 +void
68068 +acl_free_all(void)
68069 +{
68070 + if (!current_alloc_state->alloc_stack)
68071 + return;
68072 +
68073 + while (alloc_pop()) ;
68074 +
68075 + if (current_alloc_state->alloc_stack) {
68076 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
68077 + kfree(current_alloc_state->alloc_stack);
68078 + else
68079 + vfree(current_alloc_state->alloc_stack);
68080 + }
68081 +
68082 + current_alloc_state->alloc_stack = NULL;
68083 + current_alloc_state->alloc_stack_size = 1;
68084 + current_alloc_state->alloc_stack_next = 1;
68085 +
68086 + return;
68087 +}
68088 +
68089 +int
68090 +acl_alloc_stack_init(unsigned long size)
68091 +{
68092 + if ((size * sizeof (void *)) <= PAGE_SIZE)
68093 + current_alloc_state->alloc_stack =
68094 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
68095 + else
68096 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
68097 +
68098 + current_alloc_state->alloc_stack_size = size;
68099 + current_alloc_state->alloc_stack_next = 1;
68100 +
68101 + if (!current_alloc_state->alloc_stack)
68102 + return 0;
68103 + else
68104 + return 1;
68105 +}
68106 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
68107 new file mode 100644
68108 index 0000000..bdd51ea
68109 --- /dev/null
68110 +++ b/grsecurity/gracl_cap.c
68111 @@ -0,0 +1,110 @@
68112 +#include <linux/kernel.h>
68113 +#include <linux/module.h>
68114 +#include <linux/sched.h>
68115 +#include <linux/gracl.h>
68116 +#include <linux/grsecurity.h>
68117 +#include <linux/grinternal.h>
68118 +
68119 +extern const char *captab_log[];
68120 +extern int captab_log_entries;
68121 +
68122 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68123 +{
68124 + struct acl_subject_label *curracl;
68125 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
68126 + kernel_cap_t cap_audit = __cap_empty_set;
68127 +
68128 + if (!gr_acl_is_enabled())
68129 + return 1;
68130 +
68131 + curracl = task->acl;
68132 +
68133 + cap_drop = curracl->cap_lower;
68134 + cap_mask = curracl->cap_mask;
68135 + cap_audit = curracl->cap_invert_audit;
68136 +
68137 + while ((curracl = curracl->parent_subject)) {
68138 + /* if the cap isn't specified in the current computed mask but is specified in the
68139 + current level subject, and is lowered in the current level subject, then add
68140 + it to the set of dropped capabilities
68141 + otherwise, add the current level subject's mask to the current computed mask
68142 + */
68143 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
68144 + cap_raise(cap_mask, cap);
68145 + if (cap_raised(curracl->cap_lower, cap))
68146 + cap_raise(cap_drop, cap);
68147 + if (cap_raised(curracl->cap_invert_audit, cap))
68148 + cap_raise(cap_audit, cap);
68149 + }
68150 + }
68151 +
68152 + if (!cap_raised(cap_drop, cap)) {
68153 + if (cap_raised(cap_audit, cap))
68154 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
68155 + return 1;
68156 + }
68157 +
68158 + curracl = task->acl;
68159 +
68160 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
68161 + && cap_raised(cred->cap_effective, cap)) {
68162 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68163 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
68164 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
68165 + gr_to_filename(task->exec_file->f_path.dentry,
68166 + task->exec_file->f_path.mnt) : curracl->filename,
68167 + curracl->filename, 0UL,
68168 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
68169 + return 1;
68170 + }
68171 +
68172 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
68173 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
68174 +
68175 + return 0;
68176 +}
68177 +
68178 +int
68179 +gr_acl_is_capable(const int cap)
68180 +{
68181 + return gr_task_acl_is_capable(current, current_cred(), cap);
68182 +}
68183 +
68184 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
68185 +{
68186 + struct acl_subject_label *curracl;
68187 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
68188 +
68189 + if (!gr_acl_is_enabled())
68190 + return 1;
68191 +
68192 + curracl = task->acl;
68193 +
68194 + cap_drop = curracl->cap_lower;
68195 + cap_mask = curracl->cap_mask;
68196 +
68197 + while ((curracl = curracl->parent_subject)) {
68198 + /* if the cap isn't specified in the current computed mask but is specified in the
68199 + current level subject, and is lowered in the current level subject, then add
68200 + it to the set of dropped capabilities
68201 + otherwise, add the current level subject's mask to the current computed mask
68202 + */
68203 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
68204 + cap_raise(cap_mask, cap);
68205 + if (cap_raised(curracl->cap_lower, cap))
68206 + cap_raise(cap_drop, cap);
68207 + }
68208 + }
68209 +
68210 + if (!cap_raised(cap_drop, cap))
68211 + return 1;
68212 +
68213 + return 0;
68214 +}
68215 +
68216 +int
68217 +gr_acl_is_capable_nolog(const int cap)
68218 +{
68219 + return gr_task_acl_is_capable_nolog(current, cap);
68220 +}
68221 +
68222 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
68223 new file mode 100644
68224 index 0000000..ca25605
68225 --- /dev/null
68226 +++ b/grsecurity/gracl_compat.c
68227 @@ -0,0 +1,270 @@
68228 +#include <linux/kernel.h>
68229 +#include <linux/gracl.h>
68230 +#include <linux/compat.h>
68231 +#include <linux/gracl_compat.h>
68232 +
68233 +#include <asm/uaccess.h>
68234 +
68235 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
68236 +{
68237 + struct gr_arg_wrapper_compat uwrapcompat;
68238 +
68239 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
68240 + return -EFAULT;
68241 +
68242 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
68243 + (uwrapcompat.version != 0x2901)) ||
68244 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
68245 + return -EINVAL;
68246 +
68247 + uwrap->arg = compat_ptr(uwrapcompat.arg);
68248 + uwrap->version = uwrapcompat.version;
68249 + uwrap->size = sizeof(struct gr_arg);
68250 +
68251 + return 0;
68252 +}
68253 +
68254 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
68255 +{
68256 + struct gr_arg_compat argcompat;
68257 +
68258 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
68259 + return -EFAULT;
68260 +
68261 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
68262 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
68263 + arg->role_db.num_roles = argcompat.role_db.num_roles;
68264 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
68265 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
68266 + arg->role_db.num_objects = argcompat.role_db.num_objects;
68267 +
68268 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
68269 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
68270 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
68271 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
68272 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
68273 + arg->segv_device = argcompat.segv_device;
68274 + arg->segv_inode = argcompat.segv_inode;
68275 + arg->segv_uid = argcompat.segv_uid;
68276 + arg->num_sprole_pws = argcompat.num_sprole_pws;
68277 + arg->mode = argcompat.mode;
68278 +
68279 + return 0;
68280 +}
68281 +
68282 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
68283 +{
68284 + struct acl_object_label_compat objcompat;
68285 +
68286 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
68287 + return -EFAULT;
68288 +
68289 + obj->filename = compat_ptr(objcompat.filename);
68290 + obj->inode = objcompat.inode;
68291 + obj->device = objcompat.device;
68292 + obj->mode = objcompat.mode;
68293 +
68294 + obj->nested = compat_ptr(objcompat.nested);
68295 + obj->globbed = compat_ptr(objcompat.globbed);
68296 +
68297 + obj->prev = compat_ptr(objcompat.prev);
68298 + obj->next = compat_ptr(objcompat.next);
68299 +
68300 + return 0;
68301 +}
68302 +
68303 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
68304 +{
68305 + unsigned int i;
68306 + struct acl_subject_label_compat subjcompat;
68307 +
68308 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
68309 + return -EFAULT;
68310 +
68311 + subj->filename = compat_ptr(subjcompat.filename);
68312 + subj->inode = subjcompat.inode;
68313 + subj->device = subjcompat.device;
68314 + subj->mode = subjcompat.mode;
68315 + subj->cap_mask = subjcompat.cap_mask;
68316 + subj->cap_lower = subjcompat.cap_lower;
68317 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
68318 +
68319 + for (i = 0; i < GR_NLIMITS; i++) {
68320 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
68321 + subj->res[i].rlim_cur = RLIM_INFINITY;
68322 + else
68323 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
68324 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
68325 + subj->res[i].rlim_max = RLIM_INFINITY;
68326 + else
68327 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
68328 + }
68329 + subj->resmask = subjcompat.resmask;
68330 +
68331 + subj->user_trans_type = subjcompat.user_trans_type;
68332 + subj->group_trans_type = subjcompat.group_trans_type;
68333 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
68334 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
68335 + subj->user_trans_num = subjcompat.user_trans_num;
68336 + subj->group_trans_num = subjcompat.group_trans_num;
68337 +
68338 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
68339 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
68340 + subj->ip_type = subjcompat.ip_type;
68341 + subj->ips = compat_ptr(subjcompat.ips);
68342 + subj->ip_num = subjcompat.ip_num;
68343 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
68344 +
68345 + subj->crashes = subjcompat.crashes;
68346 + subj->expires = subjcompat.expires;
68347 +
68348 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
68349 + subj->hash = compat_ptr(subjcompat.hash);
68350 + subj->prev = compat_ptr(subjcompat.prev);
68351 + subj->next = compat_ptr(subjcompat.next);
68352 +
68353 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
68354 + subj->obj_hash_size = subjcompat.obj_hash_size;
68355 + subj->pax_flags = subjcompat.pax_flags;
68356 +
68357 + return 0;
68358 +}
68359 +
68360 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
68361 +{
68362 + struct acl_role_label_compat rolecompat;
68363 +
68364 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
68365 + return -EFAULT;
68366 +
68367 + role->rolename = compat_ptr(rolecompat.rolename);
68368 + role->uidgid = rolecompat.uidgid;
68369 + role->roletype = rolecompat.roletype;
68370 +
68371 + role->auth_attempts = rolecompat.auth_attempts;
68372 + role->expires = rolecompat.expires;
68373 +
68374 + role->root_label = compat_ptr(rolecompat.root_label);
68375 + role->hash = compat_ptr(rolecompat.hash);
68376 +
68377 + role->prev = compat_ptr(rolecompat.prev);
68378 + role->next = compat_ptr(rolecompat.next);
68379 +
68380 + role->transitions = compat_ptr(rolecompat.transitions);
68381 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
68382 + role->domain_children = compat_ptr(rolecompat.domain_children);
68383 + role->domain_child_num = rolecompat.domain_child_num;
68384 +
68385 + role->umask = rolecompat.umask;
68386 +
68387 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
68388 + role->subj_hash_size = rolecompat.subj_hash_size;
68389 +
68390 + return 0;
68391 +}
68392 +
68393 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
68394 +{
68395 + struct role_allowed_ip_compat roleip_compat;
68396 +
68397 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
68398 + return -EFAULT;
68399 +
68400 + roleip->addr = roleip_compat.addr;
68401 + roleip->netmask = roleip_compat.netmask;
68402 +
68403 + roleip->prev = compat_ptr(roleip_compat.prev);
68404 + roleip->next = compat_ptr(roleip_compat.next);
68405 +
68406 + return 0;
68407 +}
68408 +
68409 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
68410 +{
68411 + struct role_transition_compat trans_compat;
68412 +
68413 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
68414 + return -EFAULT;
68415 +
68416 + trans->rolename = compat_ptr(trans_compat.rolename);
68417 +
68418 + trans->prev = compat_ptr(trans_compat.prev);
68419 + trans->next = compat_ptr(trans_compat.next);
68420 +
68421 + return 0;
68422 +
68423 +}
68424 +
68425 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
68426 +{
68427 + struct gr_hash_struct_compat hash_compat;
68428 +
68429 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
68430 + return -EFAULT;
68431 +
68432 + hash->table = compat_ptr(hash_compat.table);
68433 + hash->nametable = compat_ptr(hash_compat.nametable);
68434 + hash->first = compat_ptr(hash_compat.first);
68435 +
68436 + hash->table_size = hash_compat.table_size;
68437 + hash->used_size = hash_compat.used_size;
68438 +
68439 + hash->type = hash_compat.type;
68440 +
68441 + return 0;
68442 +}
68443 +
68444 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
68445 +{
68446 + compat_uptr_t ptrcompat;
68447 +
68448 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
68449 + return -EFAULT;
68450 +
68451 + *(void **)ptr = compat_ptr(ptrcompat);
68452 +
68453 + return 0;
68454 +}
68455 +
68456 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
68457 +{
68458 + struct acl_ip_label_compat ip_compat;
68459 +
68460 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
68461 + return -EFAULT;
68462 +
68463 + ip->iface = compat_ptr(ip_compat.iface);
68464 + ip->addr = ip_compat.addr;
68465 + ip->netmask = ip_compat.netmask;
68466 + ip->low = ip_compat.low;
68467 + ip->high = ip_compat.high;
68468 + ip->mode = ip_compat.mode;
68469 + ip->type = ip_compat.type;
68470 +
68471 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
68472 +
68473 + ip->prev = compat_ptr(ip_compat.prev);
68474 + ip->next = compat_ptr(ip_compat.next);
68475 +
68476 + return 0;
68477 +}
68478 +
68479 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
68480 +{
68481 + struct sprole_pw_compat pw_compat;
68482 +
68483 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
68484 + return -EFAULT;
68485 +
68486 + pw->rolename = compat_ptr(pw_compat.rolename);
68487 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
68488 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
68489 +
68490 + return 0;
68491 +}
68492 +
68493 +size_t get_gr_arg_wrapper_size_compat(void)
68494 +{
68495 + return sizeof(struct gr_arg_wrapper_compat);
68496 +}
68497 +
68498 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
68499 new file mode 100644
68500 index 0000000..a89b1f4
68501 --- /dev/null
68502 +++ b/grsecurity/gracl_fs.c
68503 @@ -0,0 +1,437 @@
68504 +#include <linux/kernel.h>
68505 +#include <linux/sched.h>
68506 +#include <linux/types.h>
68507 +#include <linux/fs.h>
68508 +#include <linux/file.h>
68509 +#include <linux/stat.h>
68510 +#include <linux/grsecurity.h>
68511 +#include <linux/grinternal.h>
68512 +#include <linux/gracl.h>
68513 +
68514 +umode_t
68515 +gr_acl_umask(void)
68516 +{
68517 + if (unlikely(!gr_acl_is_enabled()))
68518 + return 0;
68519 +
68520 + return current->role->umask;
68521 +}
68522 +
68523 +__u32
68524 +gr_acl_handle_hidden_file(const struct dentry * dentry,
68525 + const struct vfsmount * mnt)
68526 +{
68527 + __u32 mode;
68528 +
68529 + if (unlikely(d_is_negative(dentry)))
68530 + return GR_FIND;
68531 +
68532 + mode =
68533 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
68534 +
68535 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
68536 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68537 + return mode;
68538 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
68539 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68540 + return 0;
68541 + } else if (unlikely(!(mode & GR_FIND)))
68542 + return 0;
68543 +
68544 + return GR_FIND;
68545 +}
68546 +
68547 +__u32
68548 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68549 + int acc_mode)
68550 +{
68551 + __u32 reqmode = GR_FIND;
68552 + __u32 mode;
68553 +
68554 + if (unlikely(d_is_negative(dentry)))
68555 + return reqmode;
68556 +
68557 + if (acc_mode & MAY_APPEND)
68558 + reqmode |= GR_APPEND;
68559 + else if (acc_mode & MAY_WRITE)
68560 + reqmode |= GR_WRITE;
68561 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
68562 + reqmode |= GR_READ;
68563 +
68564 + mode =
68565 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68566 + mnt);
68567 +
68568 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68569 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68570 + reqmode & GR_READ ? " reading" : "",
68571 + reqmode & GR_WRITE ? " writing" : reqmode &
68572 + GR_APPEND ? " appending" : "");
68573 + return reqmode;
68574 + } else
68575 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68576 + {
68577 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68578 + reqmode & GR_READ ? " reading" : "",
68579 + reqmode & GR_WRITE ? " writing" : reqmode &
68580 + GR_APPEND ? " appending" : "");
68581 + return 0;
68582 + } else if (unlikely((mode & reqmode) != reqmode))
68583 + return 0;
68584 +
68585 + return reqmode;
68586 +}
68587 +
68588 +__u32
68589 +gr_acl_handle_creat(const struct dentry * dentry,
68590 + const struct dentry * p_dentry,
68591 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
68592 + const int imode)
68593 +{
68594 + __u32 reqmode = GR_WRITE | GR_CREATE;
68595 + __u32 mode;
68596 +
68597 + if (acc_mode & MAY_APPEND)
68598 + reqmode |= GR_APPEND;
68599 + // if a directory was required or the directory already exists, then
68600 + // don't count this open as a read
68601 + if ((acc_mode & MAY_READ) &&
68602 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
68603 + reqmode |= GR_READ;
68604 + if ((open_flags & O_CREAT) &&
68605 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68606 + reqmode |= GR_SETID;
68607 +
68608 + mode =
68609 + gr_check_create(dentry, p_dentry, p_mnt,
68610 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68611 +
68612 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68613 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68614 + reqmode & GR_READ ? " reading" : "",
68615 + reqmode & GR_WRITE ? " writing" : reqmode &
68616 + GR_APPEND ? " appending" : "");
68617 + return reqmode;
68618 + } else
68619 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68620 + {
68621 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68622 + reqmode & GR_READ ? " reading" : "",
68623 + reqmode & GR_WRITE ? " writing" : reqmode &
68624 + GR_APPEND ? " appending" : "");
68625 + return 0;
68626 + } else if (unlikely((mode & reqmode) != reqmode))
68627 + return 0;
68628 +
68629 + return reqmode;
68630 +}
68631 +
68632 +__u32
68633 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
68634 + const int fmode)
68635 +{
68636 + __u32 mode, reqmode = GR_FIND;
68637 +
68638 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
68639 + reqmode |= GR_EXEC;
68640 + if (fmode & S_IWOTH)
68641 + reqmode |= GR_WRITE;
68642 + if (fmode & S_IROTH)
68643 + reqmode |= GR_READ;
68644 +
68645 + mode =
68646 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68647 + mnt);
68648 +
68649 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68650 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68651 + reqmode & GR_READ ? " reading" : "",
68652 + reqmode & GR_WRITE ? " writing" : "",
68653 + reqmode & GR_EXEC ? " executing" : "");
68654 + return reqmode;
68655 + } else
68656 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68657 + {
68658 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68659 + reqmode & GR_READ ? " reading" : "",
68660 + reqmode & GR_WRITE ? " writing" : "",
68661 + reqmode & GR_EXEC ? " executing" : "");
68662 + return 0;
68663 + } else if (unlikely((mode & reqmode) != reqmode))
68664 + return 0;
68665 +
68666 + return reqmode;
68667 +}
68668 +
68669 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
68670 +{
68671 + __u32 mode;
68672 +
68673 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
68674 +
68675 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68676 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
68677 + return mode;
68678 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68679 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
68680 + return 0;
68681 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
68682 + return 0;
68683 +
68684 + return (reqmode);
68685 +}
68686 +
68687 +__u32
68688 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68689 +{
68690 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
68691 +}
68692 +
68693 +__u32
68694 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
68695 +{
68696 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
68697 +}
68698 +
68699 +__u32
68700 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
68701 +{
68702 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
68703 +}
68704 +
68705 +__u32
68706 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
68707 +{
68708 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
68709 +}
68710 +
68711 +__u32
68712 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
68713 + umode_t *modeptr)
68714 +{
68715 + umode_t mode;
68716 +
68717 + *modeptr &= ~gr_acl_umask();
68718 + mode = *modeptr;
68719 +
68720 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
68721 + return 1;
68722 +
68723 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
68724 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
68725 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
68726 + GR_CHMOD_ACL_MSG);
68727 + } else {
68728 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
68729 + }
68730 +}
68731 +
68732 +__u32
68733 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
68734 +{
68735 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
68736 +}
68737 +
68738 +__u32
68739 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
68740 +{
68741 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
68742 +}
68743 +
68744 +__u32
68745 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
68746 +{
68747 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
68748 +}
68749 +
68750 +__u32
68751 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
68752 +{
68753 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
68754 +}
68755 +
68756 +__u32
68757 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
68758 +{
68759 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
68760 + GR_UNIXCONNECT_ACL_MSG);
68761 +}
68762 +
68763 +/* hardlinks require at minimum create and link permission,
68764 + any additional privilege required is based on the
68765 + privilege of the file being linked to
68766 +*/
68767 +__u32
68768 +gr_acl_handle_link(const struct dentry * new_dentry,
68769 + const struct dentry * parent_dentry,
68770 + const struct vfsmount * parent_mnt,
68771 + const struct dentry * old_dentry,
68772 + const struct vfsmount * old_mnt, const struct filename *to)
68773 +{
68774 + __u32 mode;
68775 + __u32 needmode = GR_CREATE | GR_LINK;
68776 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
68777 +
68778 + mode =
68779 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
68780 + old_mnt);
68781 +
68782 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
68783 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68784 + return mode;
68785 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68786 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68787 + return 0;
68788 + } else if (unlikely((mode & needmode) != needmode))
68789 + return 0;
68790 +
68791 + return 1;
68792 +}
68793 +
68794 +__u32
68795 +gr_acl_handle_symlink(const struct dentry * new_dentry,
68796 + const struct dentry * parent_dentry,
68797 + const struct vfsmount * parent_mnt, const struct filename *from)
68798 +{
68799 + __u32 needmode = GR_WRITE | GR_CREATE;
68800 + __u32 mode;
68801 +
68802 + mode =
68803 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
68804 + GR_CREATE | GR_AUDIT_CREATE |
68805 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
68806 +
68807 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
68808 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68809 + return mode;
68810 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68811 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68812 + return 0;
68813 + } else if (unlikely((mode & needmode) != needmode))
68814 + return 0;
68815 +
68816 + return (GR_WRITE | GR_CREATE);
68817 +}
68818 +
68819 +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)
68820 +{
68821 + __u32 mode;
68822 +
68823 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68824 +
68825 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68826 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
68827 + return mode;
68828 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68829 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
68830 + return 0;
68831 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
68832 + return 0;
68833 +
68834 + return (reqmode);
68835 +}
68836 +
68837 +__u32
68838 +gr_acl_handle_mknod(const struct dentry * new_dentry,
68839 + const struct dentry * parent_dentry,
68840 + const struct vfsmount * parent_mnt,
68841 + const int mode)
68842 +{
68843 + __u32 reqmode = GR_WRITE | GR_CREATE;
68844 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68845 + reqmode |= GR_SETID;
68846 +
68847 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68848 + reqmode, GR_MKNOD_ACL_MSG);
68849 +}
68850 +
68851 +__u32
68852 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
68853 + const struct dentry *parent_dentry,
68854 + const struct vfsmount *parent_mnt)
68855 +{
68856 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68857 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
68858 +}
68859 +
68860 +#define RENAME_CHECK_SUCCESS(old, new) \
68861 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
68862 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
68863 +
68864 +int
68865 +gr_acl_handle_rename(struct dentry *new_dentry,
68866 + struct dentry *parent_dentry,
68867 + const struct vfsmount *parent_mnt,
68868 + struct dentry *old_dentry,
68869 + struct inode *old_parent_inode,
68870 + struct vfsmount *old_mnt, const struct filename *newname)
68871 +{
68872 + __u32 comp1, comp2;
68873 + int error = 0;
68874 +
68875 + if (unlikely(!gr_acl_is_enabled()))
68876 + return 0;
68877 +
68878 + if (d_is_negative(new_dentry)) {
68879 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
68880 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
68881 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
68882 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
68883 + GR_DELETE | GR_AUDIT_DELETE |
68884 + GR_AUDIT_READ | GR_AUDIT_WRITE |
68885 + GR_SUPPRESS, old_mnt);
68886 + } else {
68887 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
68888 + GR_CREATE | GR_DELETE |
68889 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
68890 + GR_AUDIT_READ | GR_AUDIT_WRITE |
68891 + GR_SUPPRESS, parent_mnt);
68892 + comp2 =
68893 + gr_search_file(old_dentry,
68894 + GR_READ | GR_WRITE | GR_AUDIT_READ |
68895 + GR_DELETE | GR_AUDIT_DELETE |
68896 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
68897 + }
68898 +
68899 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
68900 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
68901 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
68902 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
68903 + && !(comp2 & GR_SUPPRESS)) {
68904 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
68905 + error = -EACCES;
68906 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
68907 + error = -EACCES;
68908 +
68909 + return error;
68910 +}
68911 +
68912 +void
68913 +gr_acl_handle_exit(void)
68914 +{
68915 + u16 id;
68916 + char *rolename;
68917 +
68918 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
68919 + !(current->role->roletype & GR_ROLE_PERSIST))) {
68920 + id = current->acl_role_id;
68921 + rolename = current->role->rolename;
68922 + gr_set_acls(1);
68923 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
68924 + }
68925 +
68926 + gr_put_exec_file(current);
68927 + return;
68928 +}
68929 +
68930 +int
68931 +gr_acl_handle_procpidmem(const struct task_struct *task)
68932 +{
68933 + if (unlikely(!gr_acl_is_enabled()))
68934 + return 0;
68935 +
68936 + if (task != current && task->acl->mode & GR_PROTPROCFD)
68937 + return -EACCES;
68938 +
68939 + return 0;
68940 +}
68941 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
68942 new file mode 100644
68943 index 0000000..f056b81
68944 --- /dev/null
68945 +++ b/grsecurity/gracl_ip.c
68946 @@ -0,0 +1,386 @@
68947 +#include <linux/kernel.h>
68948 +#include <asm/uaccess.h>
68949 +#include <asm/errno.h>
68950 +#include <net/sock.h>
68951 +#include <linux/file.h>
68952 +#include <linux/fs.h>
68953 +#include <linux/net.h>
68954 +#include <linux/in.h>
68955 +#include <linux/skbuff.h>
68956 +#include <linux/ip.h>
68957 +#include <linux/udp.h>
68958 +#include <linux/types.h>
68959 +#include <linux/sched.h>
68960 +#include <linux/netdevice.h>
68961 +#include <linux/inetdevice.h>
68962 +#include <linux/gracl.h>
68963 +#include <linux/grsecurity.h>
68964 +#include <linux/grinternal.h>
68965 +
68966 +#define GR_BIND 0x01
68967 +#define GR_CONNECT 0x02
68968 +#define GR_INVERT 0x04
68969 +#define GR_BINDOVERRIDE 0x08
68970 +#define GR_CONNECTOVERRIDE 0x10
68971 +#define GR_SOCK_FAMILY 0x20
68972 +
68973 +static const char * gr_protocols[IPPROTO_MAX] = {
68974 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
68975 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
68976 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
68977 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
68978 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
68979 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
68980 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
68981 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
68982 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
68983 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
68984 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
68985 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
68986 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
68987 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
68988 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
68989 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
68990 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
68991 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
68992 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
68993 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
68994 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
68995 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
68996 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
68997 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
68998 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
68999 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
69000 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
69001 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
69002 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
69003 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
69004 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
69005 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
69006 + };
69007 +
69008 +static const char * gr_socktypes[SOCK_MAX] = {
69009 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
69010 + "unknown:7", "unknown:8", "unknown:9", "packet"
69011 + };
69012 +
69013 +static const char * gr_sockfamilies[AF_MAX+1] = {
69014 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
69015 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
69016 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
69017 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
69018 + };
69019 +
69020 +const char *
69021 +gr_proto_to_name(unsigned char proto)
69022 +{
69023 + return gr_protocols[proto];
69024 +}
69025 +
69026 +const char *
69027 +gr_socktype_to_name(unsigned char type)
69028 +{
69029 + return gr_socktypes[type];
69030 +}
69031 +
69032 +const char *
69033 +gr_sockfamily_to_name(unsigned char family)
69034 +{
69035 + return gr_sockfamilies[family];
69036 +}
69037 +
69038 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
69039 +
69040 +int
69041 +gr_search_socket(const int domain, const int type, const int protocol)
69042 +{
69043 + struct acl_subject_label *curr;
69044 + const struct cred *cred = current_cred();
69045 +
69046 + if (unlikely(!gr_acl_is_enabled()))
69047 + goto exit;
69048 +
69049 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
69050 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
69051 + goto exit; // let the kernel handle it
69052 +
69053 + curr = current->acl;
69054 +
69055 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
69056 + /* the family is allowed, if this is PF_INET allow it only if
69057 + the extra sock type/protocol checks pass */
69058 + if (domain == PF_INET)
69059 + goto inet_check;
69060 + goto exit;
69061 + } else {
69062 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69063 + __u32 fakeip = 0;
69064 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69065 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69066 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69067 + gr_to_filename(current->exec_file->f_path.dentry,
69068 + current->exec_file->f_path.mnt) :
69069 + curr->filename, curr->filename,
69070 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
69071 + &current->signal->saved_ip);
69072 + goto exit;
69073 + }
69074 + goto exit_fail;
69075 + }
69076 +
69077 +inet_check:
69078 + /* the rest of this checking is for IPv4 only */
69079 + if (!curr->ips)
69080 + goto exit;
69081 +
69082 + if ((curr->ip_type & (1U << type)) &&
69083 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
69084 + goto exit;
69085 +
69086 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69087 + /* we don't place acls on raw sockets , and sometimes
69088 + dgram/ip sockets are opened for ioctl and not
69089 + bind/connect, so we'll fake a bind learn log */
69090 + if (type == SOCK_RAW || type == SOCK_PACKET) {
69091 + __u32 fakeip = 0;
69092 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69093 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69094 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69095 + gr_to_filename(current->exec_file->f_path.dentry,
69096 + current->exec_file->f_path.mnt) :
69097 + curr->filename, curr->filename,
69098 + &fakeip, 0, type,
69099 + protocol, GR_CONNECT, &current->signal->saved_ip);
69100 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
69101 + __u32 fakeip = 0;
69102 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69103 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69104 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69105 + gr_to_filename(current->exec_file->f_path.dentry,
69106 + current->exec_file->f_path.mnt) :
69107 + curr->filename, curr->filename,
69108 + &fakeip, 0, type,
69109 + protocol, GR_BIND, &current->signal->saved_ip);
69110 + }
69111 + /* we'll log when they use connect or bind */
69112 + goto exit;
69113 + }
69114 +
69115 +exit_fail:
69116 + if (domain == PF_INET)
69117 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
69118 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
69119 + else if (rcu_access_pointer(net_families[domain]) != NULL)
69120 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
69121 + gr_socktype_to_name(type), protocol);
69122 +
69123 + return 0;
69124 +exit:
69125 + return 1;
69126 +}
69127 +
69128 +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)
69129 +{
69130 + if ((ip->mode & mode) &&
69131 + (ip_port >= ip->low) &&
69132 + (ip_port <= ip->high) &&
69133 + ((ntohl(ip_addr) & our_netmask) ==
69134 + (ntohl(our_addr) & our_netmask))
69135 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
69136 + && (ip->type & (1U << type))) {
69137 + if (ip->mode & GR_INVERT)
69138 + return 2; // specifically denied
69139 + else
69140 + return 1; // allowed
69141 + }
69142 +
69143 + return 0; // not specifically allowed, may continue parsing
69144 +}
69145 +
69146 +static int
69147 +gr_search_connectbind(const int full_mode, struct sock *sk,
69148 + struct sockaddr_in *addr, const int type)
69149 +{
69150 + char iface[IFNAMSIZ] = {0};
69151 + struct acl_subject_label *curr;
69152 + struct acl_ip_label *ip;
69153 + struct inet_sock *isk;
69154 + struct net_device *dev;
69155 + struct in_device *idev;
69156 + unsigned long i;
69157 + int ret;
69158 + int mode = full_mode & (GR_BIND | GR_CONNECT);
69159 + __u32 ip_addr = 0;
69160 + __u32 our_addr;
69161 + __u32 our_netmask;
69162 + char *p;
69163 + __u16 ip_port = 0;
69164 + const struct cred *cred = current_cred();
69165 +
69166 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
69167 + return 0;
69168 +
69169 + curr = current->acl;
69170 + isk = inet_sk(sk);
69171 +
69172 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
69173 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
69174 + addr->sin_addr.s_addr = curr->inaddr_any_override;
69175 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
69176 + struct sockaddr_in saddr;
69177 + int err;
69178 +
69179 + saddr.sin_family = AF_INET;
69180 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
69181 + saddr.sin_port = isk->inet_sport;
69182 +
69183 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
69184 + if (err)
69185 + return err;
69186 +
69187 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
69188 + if (err)
69189 + return err;
69190 + }
69191 +
69192 + if (!curr->ips)
69193 + return 0;
69194 +
69195 + ip_addr = addr->sin_addr.s_addr;
69196 + ip_port = ntohs(addr->sin_port);
69197 +
69198 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69199 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69200 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69201 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69202 + gr_to_filename(current->exec_file->f_path.dentry,
69203 + current->exec_file->f_path.mnt) :
69204 + curr->filename, curr->filename,
69205 + &ip_addr, ip_port, type,
69206 + sk->sk_protocol, mode, &current->signal->saved_ip);
69207 + return 0;
69208 + }
69209 +
69210 + for (i = 0; i < curr->ip_num; i++) {
69211 + ip = *(curr->ips + i);
69212 + if (ip->iface != NULL) {
69213 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
69214 + p = strchr(iface, ':');
69215 + if (p != NULL)
69216 + *p = '\0';
69217 + dev = dev_get_by_name(sock_net(sk), iface);
69218 + if (dev == NULL)
69219 + continue;
69220 + idev = in_dev_get(dev);
69221 + if (idev == NULL) {
69222 + dev_put(dev);
69223 + continue;
69224 + }
69225 + rcu_read_lock();
69226 + for_ifa(idev) {
69227 + if (!strcmp(ip->iface, ifa->ifa_label)) {
69228 + our_addr = ifa->ifa_address;
69229 + our_netmask = 0xffffffff;
69230 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
69231 + if (ret == 1) {
69232 + rcu_read_unlock();
69233 + in_dev_put(idev);
69234 + dev_put(dev);
69235 + return 0;
69236 + } else if (ret == 2) {
69237 + rcu_read_unlock();
69238 + in_dev_put(idev);
69239 + dev_put(dev);
69240 + goto denied;
69241 + }
69242 + }
69243 + } endfor_ifa(idev);
69244 + rcu_read_unlock();
69245 + in_dev_put(idev);
69246 + dev_put(dev);
69247 + } else {
69248 + our_addr = ip->addr;
69249 + our_netmask = ip->netmask;
69250 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
69251 + if (ret == 1)
69252 + return 0;
69253 + else if (ret == 2)
69254 + goto denied;
69255 + }
69256 + }
69257 +
69258 +denied:
69259 + if (mode == GR_BIND)
69260 + 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));
69261 + else if (mode == GR_CONNECT)
69262 + 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));
69263 +
69264 + return -EACCES;
69265 +}
69266 +
69267 +int
69268 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
69269 +{
69270 + /* always allow disconnection of dgram sockets with connect */
69271 + if (addr->sin_family == AF_UNSPEC)
69272 + return 0;
69273 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
69274 +}
69275 +
69276 +int
69277 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
69278 +{
69279 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
69280 +}
69281 +
69282 +int gr_search_listen(struct socket *sock)
69283 +{
69284 + struct sock *sk = sock->sk;
69285 + struct sockaddr_in addr;
69286 +
69287 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
69288 + addr.sin_port = inet_sk(sk)->inet_sport;
69289 +
69290 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
69291 +}
69292 +
69293 +int gr_search_accept(struct socket *sock)
69294 +{
69295 + struct sock *sk = sock->sk;
69296 + struct sockaddr_in addr;
69297 +
69298 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
69299 + addr.sin_port = inet_sk(sk)->inet_sport;
69300 +
69301 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
69302 +}
69303 +
69304 +int
69305 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
69306 +{
69307 + if (addr)
69308 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
69309 + else {
69310 + struct sockaddr_in sin;
69311 + const struct inet_sock *inet = inet_sk(sk);
69312 +
69313 + sin.sin_addr.s_addr = inet->inet_daddr;
69314 + sin.sin_port = inet->inet_dport;
69315 +
69316 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
69317 + }
69318 +}
69319 +
69320 +int
69321 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
69322 +{
69323 + struct sockaddr_in sin;
69324 +
69325 + if (unlikely(skb->len < sizeof (struct udphdr)))
69326 + return 0; // skip this packet
69327 +
69328 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
69329 + sin.sin_port = udp_hdr(skb)->source;
69330 +
69331 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
69332 +}
69333 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
69334 new file mode 100644
69335 index 0000000..25f54ef
69336 --- /dev/null
69337 +++ b/grsecurity/gracl_learn.c
69338 @@ -0,0 +1,207 @@
69339 +#include <linux/kernel.h>
69340 +#include <linux/mm.h>
69341 +#include <linux/sched.h>
69342 +#include <linux/poll.h>
69343 +#include <linux/string.h>
69344 +#include <linux/file.h>
69345 +#include <linux/types.h>
69346 +#include <linux/vmalloc.h>
69347 +#include <linux/grinternal.h>
69348 +
69349 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
69350 + size_t count, loff_t *ppos);
69351 +extern int gr_acl_is_enabled(void);
69352 +
69353 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
69354 +static int gr_learn_attached;
69355 +
69356 +/* use a 512k buffer */
69357 +#define LEARN_BUFFER_SIZE (512 * 1024)
69358 +
69359 +static DEFINE_SPINLOCK(gr_learn_lock);
69360 +static DEFINE_MUTEX(gr_learn_user_mutex);
69361 +
69362 +/* we need to maintain two buffers, so that the kernel context of grlearn
69363 + uses a semaphore around the userspace copying, and the other kernel contexts
69364 + use a spinlock when copying into the buffer, since they cannot sleep
69365 +*/
69366 +static char *learn_buffer;
69367 +static char *learn_buffer_user;
69368 +static int learn_buffer_len;
69369 +static int learn_buffer_user_len;
69370 +
69371 +static ssize_t
69372 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
69373 +{
69374 + DECLARE_WAITQUEUE(wait, current);
69375 + ssize_t retval = 0;
69376 +
69377 + add_wait_queue(&learn_wait, &wait);
69378 + set_current_state(TASK_INTERRUPTIBLE);
69379 + do {
69380 + mutex_lock(&gr_learn_user_mutex);
69381 + spin_lock(&gr_learn_lock);
69382 + if (learn_buffer_len)
69383 + break;
69384 + spin_unlock(&gr_learn_lock);
69385 + mutex_unlock(&gr_learn_user_mutex);
69386 + if (file->f_flags & O_NONBLOCK) {
69387 + retval = -EAGAIN;
69388 + goto out;
69389 + }
69390 + if (signal_pending(current)) {
69391 + retval = -ERESTARTSYS;
69392 + goto out;
69393 + }
69394 +
69395 + schedule();
69396 + } while (1);
69397 +
69398 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
69399 + learn_buffer_user_len = learn_buffer_len;
69400 + retval = learn_buffer_len;
69401 + learn_buffer_len = 0;
69402 +
69403 + spin_unlock(&gr_learn_lock);
69404 +
69405 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
69406 + retval = -EFAULT;
69407 +
69408 + mutex_unlock(&gr_learn_user_mutex);
69409 +out:
69410 + set_current_state(TASK_RUNNING);
69411 + remove_wait_queue(&learn_wait, &wait);
69412 + return retval;
69413 +}
69414 +
69415 +static unsigned int
69416 +poll_learn(struct file * file, poll_table * wait)
69417 +{
69418 + poll_wait(file, &learn_wait, wait);
69419 +
69420 + if (learn_buffer_len)
69421 + return (POLLIN | POLLRDNORM);
69422 +
69423 + return 0;
69424 +}
69425 +
69426 +void
69427 +gr_clear_learn_entries(void)
69428 +{
69429 + char *tmp;
69430 +
69431 + mutex_lock(&gr_learn_user_mutex);
69432 + spin_lock(&gr_learn_lock);
69433 + tmp = learn_buffer;
69434 + learn_buffer = NULL;
69435 + spin_unlock(&gr_learn_lock);
69436 + if (tmp)
69437 + vfree(tmp);
69438 + if (learn_buffer_user != NULL) {
69439 + vfree(learn_buffer_user);
69440 + learn_buffer_user = NULL;
69441 + }
69442 + learn_buffer_len = 0;
69443 + mutex_unlock(&gr_learn_user_mutex);
69444 +
69445 + return;
69446 +}
69447 +
69448 +void
69449 +gr_add_learn_entry(const char *fmt, ...)
69450 +{
69451 + va_list args;
69452 + unsigned int len;
69453 +
69454 + if (!gr_learn_attached)
69455 + return;
69456 +
69457 + spin_lock(&gr_learn_lock);
69458 +
69459 + /* leave a gap at the end so we know when it's "full" but don't have to
69460 + compute the exact length of the string we're trying to append
69461 + */
69462 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
69463 + spin_unlock(&gr_learn_lock);
69464 + wake_up_interruptible(&learn_wait);
69465 + return;
69466 + }
69467 + if (learn_buffer == NULL) {
69468 + spin_unlock(&gr_learn_lock);
69469 + return;
69470 + }
69471 +
69472 + va_start(args, fmt);
69473 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
69474 + va_end(args);
69475 +
69476 + learn_buffer_len += len + 1;
69477 +
69478 + spin_unlock(&gr_learn_lock);
69479 + wake_up_interruptible(&learn_wait);
69480 +
69481 + return;
69482 +}
69483 +
69484 +static int
69485 +open_learn(struct inode *inode, struct file *file)
69486 +{
69487 + if (file->f_mode & FMODE_READ && gr_learn_attached)
69488 + return -EBUSY;
69489 + if (file->f_mode & FMODE_READ) {
69490 + int retval = 0;
69491 + mutex_lock(&gr_learn_user_mutex);
69492 + if (learn_buffer == NULL)
69493 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
69494 + if (learn_buffer_user == NULL)
69495 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
69496 + if (learn_buffer == NULL) {
69497 + retval = -ENOMEM;
69498 + goto out_error;
69499 + }
69500 + if (learn_buffer_user == NULL) {
69501 + retval = -ENOMEM;
69502 + goto out_error;
69503 + }
69504 + learn_buffer_len = 0;
69505 + learn_buffer_user_len = 0;
69506 + gr_learn_attached = 1;
69507 +out_error:
69508 + mutex_unlock(&gr_learn_user_mutex);
69509 + return retval;
69510 + }
69511 + return 0;
69512 +}
69513 +
69514 +static int
69515 +close_learn(struct inode *inode, struct file *file)
69516 +{
69517 + if (file->f_mode & FMODE_READ) {
69518 + char *tmp = NULL;
69519 + mutex_lock(&gr_learn_user_mutex);
69520 + spin_lock(&gr_learn_lock);
69521 + tmp = learn_buffer;
69522 + learn_buffer = NULL;
69523 + spin_unlock(&gr_learn_lock);
69524 + if (tmp)
69525 + vfree(tmp);
69526 + if (learn_buffer_user != NULL) {
69527 + vfree(learn_buffer_user);
69528 + learn_buffer_user = NULL;
69529 + }
69530 + learn_buffer_len = 0;
69531 + learn_buffer_user_len = 0;
69532 + gr_learn_attached = 0;
69533 + mutex_unlock(&gr_learn_user_mutex);
69534 + }
69535 +
69536 + return 0;
69537 +}
69538 +
69539 +const struct file_operations grsec_fops = {
69540 + .read = read_learn,
69541 + .write = write_grsec_handler,
69542 + .open = open_learn,
69543 + .release = close_learn,
69544 + .poll = poll_learn,
69545 +};
69546 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
69547 new file mode 100644
69548 index 0000000..361a099
69549 --- /dev/null
69550 +++ b/grsecurity/gracl_policy.c
69551 @@ -0,0 +1,1782 @@
69552 +#include <linux/kernel.h>
69553 +#include <linux/module.h>
69554 +#include <linux/sched.h>
69555 +#include <linux/mm.h>
69556 +#include <linux/file.h>
69557 +#include <linux/fs.h>
69558 +#include <linux/namei.h>
69559 +#include <linux/mount.h>
69560 +#include <linux/tty.h>
69561 +#include <linux/proc_fs.h>
69562 +#include <linux/lglock.h>
69563 +#include <linux/slab.h>
69564 +#include <linux/vmalloc.h>
69565 +#include <linux/types.h>
69566 +#include <linux/sysctl.h>
69567 +#include <linux/netdevice.h>
69568 +#include <linux/ptrace.h>
69569 +#include <linux/gracl.h>
69570 +#include <linux/gralloc.h>
69571 +#include <linux/security.h>
69572 +#include <linux/grinternal.h>
69573 +#include <linux/pid_namespace.h>
69574 +#include <linux/stop_machine.h>
69575 +#include <linux/fdtable.h>
69576 +#include <linux/percpu.h>
69577 +#include <linux/lglock.h>
69578 +#include <linux/hugetlb.h>
69579 +#include <linux/posix-timers.h>
69580 +#include "../fs/mount.h"
69581 +
69582 +#include <asm/uaccess.h>
69583 +#include <asm/errno.h>
69584 +#include <asm/mman.h>
69585 +
69586 +extern struct gr_policy_state *polstate;
69587 +
69588 +#define FOR_EACH_ROLE_START(role) \
69589 + role = polstate->role_list; \
69590 + while (role) {
69591 +
69592 +#define FOR_EACH_ROLE_END(role) \
69593 + role = role->prev; \
69594 + }
69595 +
69596 +struct path gr_real_root;
69597 +
69598 +extern struct gr_alloc_state *current_alloc_state;
69599 +
69600 +u16 acl_sp_role_value;
69601 +
69602 +static DEFINE_MUTEX(gr_dev_mutex);
69603 +
69604 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
69605 +extern void gr_clear_learn_entries(void);
69606 +
69607 +static struct gr_arg gr_usermode;
69608 +static unsigned char gr_system_salt[GR_SALT_LEN];
69609 +static unsigned char gr_system_sum[GR_SHA_LEN];
69610 +
69611 +static unsigned int gr_auth_attempts = 0;
69612 +static unsigned long gr_auth_expires = 0UL;
69613 +
69614 +struct acl_object_label *fakefs_obj_rw;
69615 +struct acl_object_label *fakefs_obj_rwx;
69616 +
69617 +extern int gr_init_uidset(void);
69618 +extern void gr_free_uidset(void);
69619 +extern void gr_remove_uid(uid_t uid);
69620 +extern int gr_find_uid(uid_t uid);
69621 +
69622 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
69623 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
69624 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
69625 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
69626 +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);
69627 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
69628 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
69629 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
69630 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
69631 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
69632 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
69633 +extern void assign_special_role(const char *rolename);
69634 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
69635 +extern int gr_rbac_disable(void *unused);
69636 +extern void gr_enable_rbac_system(void);
69637 +
69638 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
69639 +{
69640 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
69641 + return -EFAULT;
69642 +
69643 + return 0;
69644 +}
69645 +
69646 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69647 +{
69648 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
69649 + return -EFAULT;
69650 +
69651 + return 0;
69652 +}
69653 +
69654 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69655 +{
69656 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
69657 + return -EFAULT;
69658 +
69659 + return 0;
69660 +}
69661 +
69662 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
69663 +{
69664 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
69665 + return -EFAULT;
69666 +
69667 + return 0;
69668 +}
69669 +
69670 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69671 +{
69672 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
69673 + return -EFAULT;
69674 +
69675 + return 0;
69676 +}
69677 +
69678 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69679 +{
69680 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
69681 + return -EFAULT;
69682 +
69683 + return 0;
69684 +}
69685 +
69686 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69687 +{
69688 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
69689 + return -EFAULT;
69690 +
69691 + return 0;
69692 +}
69693 +
69694 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
69695 +{
69696 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
69697 + return -EFAULT;
69698 +
69699 + return 0;
69700 +}
69701 +
69702 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
69703 +{
69704 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
69705 + return -EFAULT;
69706 +
69707 + return 0;
69708 +}
69709 +
69710 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
69711 +{
69712 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
69713 + return -EFAULT;
69714 +
69715 + if (((uwrap->version != GRSECURITY_VERSION) &&
69716 + (uwrap->version != 0x2901)) ||
69717 + (uwrap->size != sizeof(struct gr_arg)))
69718 + return -EINVAL;
69719 +
69720 + return 0;
69721 +}
69722 +
69723 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
69724 +{
69725 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
69726 + return -EFAULT;
69727 +
69728 + return 0;
69729 +}
69730 +
69731 +static size_t get_gr_arg_wrapper_size_normal(void)
69732 +{
69733 + return sizeof(struct gr_arg_wrapper);
69734 +}
69735 +
69736 +#ifdef CONFIG_COMPAT
69737 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
69738 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
69739 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
69740 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
69741 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
69742 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
69743 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
69744 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
69745 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
69746 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
69747 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
69748 +extern size_t get_gr_arg_wrapper_size_compat(void);
69749 +
69750 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
69751 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
69752 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
69753 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
69754 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
69755 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
69756 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
69757 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
69758 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
69759 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
69760 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
69761 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
69762 +
69763 +#else
69764 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
69765 +#define copy_gr_arg copy_gr_arg_normal
69766 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
69767 +#define copy_acl_object_label copy_acl_object_label_normal
69768 +#define copy_acl_subject_label copy_acl_subject_label_normal
69769 +#define copy_acl_role_label copy_acl_role_label_normal
69770 +#define copy_acl_ip_label copy_acl_ip_label_normal
69771 +#define copy_pointer_from_array copy_pointer_from_array_normal
69772 +#define copy_sprole_pw copy_sprole_pw_normal
69773 +#define copy_role_transition copy_role_transition_normal
69774 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
69775 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
69776 +#endif
69777 +
69778 +static struct acl_subject_label *
69779 +lookup_subject_map(const struct acl_subject_label *userp)
69780 +{
69781 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
69782 + struct subject_map *match;
69783 +
69784 + match = polstate->subj_map_set.s_hash[index];
69785 +
69786 + while (match && match->user != userp)
69787 + match = match->next;
69788 +
69789 + if (match != NULL)
69790 + return match->kernel;
69791 + else
69792 + return NULL;
69793 +}
69794 +
69795 +static void
69796 +insert_subj_map_entry(struct subject_map *subjmap)
69797 +{
69798 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
69799 + struct subject_map **curr;
69800 +
69801 + subjmap->prev = NULL;
69802 +
69803 + curr = &polstate->subj_map_set.s_hash[index];
69804 + if (*curr != NULL)
69805 + (*curr)->prev = subjmap;
69806 +
69807 + subjmap->next = *curr;
69808 + *curr = subjmap;
69809 +
69810 + return;
69811 +}
69812 +
69813 +static void
69814 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
69815 +{
69816 + unsigned int index =
69817 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
69818 + struct acl_role_label **curr;
69819 + struct acl_role_label *tmp, *tmp2;
69820 +
69821 + curr = &polstate->acl_role_set.r_hash[index];
69822 +
69823 + /* simple case, slot is empty, just set it to our role */
69824 + if (*curr == NULL) {
69825 + *curr = role;
69826 + } else {
69827 + /* example:
69828 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
69829 + 2 -> 3
69830 + */
69831 + /* first check to see if we can already be reached via this slot */
69832 + tmp = *curr;
69833 + while (tmp && tmp != role)
69834 + tmp = tmp->next;
69835 + if (tmp == role) {
69836 + /* we don't need to add ourselves to this slot's chain */
69837 + return;
69838 + }
69839 + /* we need to add ourselves to this chain, two cases */
69840 + if (role->next == NULL) {
69841 + /* simple case, append the current chain to our role */
69842 + role->next = *curr;
69843 + *curr = role;
69844 + } else {
69845 + /* 1 -> 2 -> 3 -> 4
69846 + 2 -> 3 -> 4
69847 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
69848 + */
69849 + /* trickier case: walk our role's chain until we find
69850 + the role for the start of the current slot's chain */
69851 + tmp = role;
69852 + tmp2 = *curr;
69853 + while (tmp->next && tmp->next != tmp2)
69854 + tmp = tmp->next;
69855 + if (tmp->next == tmp2) {
69856 + /* from example above, we found 3, so just
69857 + replace this slot's chain with ours */
69858 + *curr = role;
69859 + } else {
69860 + /* we didn't find a subset of our role's chain
69861 + in the current slot's chain, so append their
69862 + chain to ours, and set us as the first role in
69863 + the slot's chain
69864 +
69865 + we could fold this case with the case above,
69866 + but making it explicit for clarity
69867 + */
69868 + tmp->next = tmp2;
69869 + *curr = role;
69870 + }
69871 + }
69872 + }
69873 +
69874 + return;
69875 +}
69876 +
69877 +static void
69878 +insert_acl_role_label(struct acl_role_label *role)
69879 +{
69880 + int i;
69881 +
69882 + if (polstate->role_list == NULL) {
69883 + polstate->role_list = role;
69884 + role->prev = NULL;
69885 + } else {
69886 + role->prev = polstate->role_list;
69887 + polstate->role_list = role;
69888 + }
69889 +
69890 + /* used for hash chains */
69891 + role->next = NULL;
69892 +
69893 + if (role->roletype & GR_ROLE_DOMAIN) {
69894 + for (i = 0; i < role->domain_child_num; i++)
69895 + __insert_acl_role_label(role, role->domain_children[i]);
69896 + } else
69897 + __insert_acl_role_label(role, role->uidgid);
69898 +}
69899 +
69900 +static int
69901 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
69902 +{
69903 + struct name_entry **curr, *nentry;
69904 + struct inodev_entry *ientry;
69905 + unsigned int len = strlen(name);
69906 + unsigned int key = full_name_hash(name, len);
69907 + unsigned int index = key % polstate->name_set.n_size;
69908 +
69909 + curr = &polstate->name_set.n_hash[index];
69910 +
69911 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
69912 + curr = &((*curr)->next);
69913 +
69914 + if (*curr != NULL)
69915 + return 1;
69916 +
69917 + nentry = acl_alloc(sizeof (struct name_entry));
69918 + if (nentry == NULL)
69919 + return 0;
69920 + ientry = acl_alloc(sizeof (struct inodev_entry));
69921 + if (ientry == NULL)
69922 + return 0;
69923 + ientry->nentry = nentry;
69924 +
69925 + nentry->key = key;
69926 + nentry->name = name;
69927 + nentry->inode = inode;
69928 + nentry->device = device;
69929 + nentry->len = len;
69930 + nentry->deleted = deleted;
69931 +
69932 + nentry->prev = NULL;
69933 + curr = &polstate->name_set.n_hash[index];
69934 + if (*curr != NULL)
69935 + (*curr)->prev = nentry;
69936 + nentry->next = *curr;
69937 + *curr = nentry;
69938 +
69939 + /* insert us into the table searchable by inode/dev */
69940 + __insert_inodev_entry(polstate, ientry);
69941 +
69942 + return 1;
69943 +}
69944 +
69945 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
69946 +
69947 +static void *
69948 +create_table(__u32 * len, int elementsize)
69949 +{
69950 + unsigned int table_sizes[] = {
69951 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
69952 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
69953 + 4194301, 8388593, 16777213, 33554393, 67108859
69954 + };
69955 + void *newtable = NULL;
69956 + unsigned int pwr = 0;
69957 +
69958 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
69959 + table_sizes[pwr] <= *len)
69960 + pwr++;
69961 +
69962 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
69963 + return newtable;
69964 +
69965 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
69966 + newtable =
69967 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
69968 + else
69969 + newtable = vmalloc(table_sizes[pwr] * elementsize);
69970 +
69971 + *len = table_sizes[pwr];
69972 +
69973 + return newtable;
69974 +}
69975 +
69976 +static int
69977 +init_variables(const struct gr_arg *arg, bool reload)
69978 +{
69979 + struct task_struct *reaper = init_pid_ns.child_reaper;
69980 + unsigned int stacksize;
69981 +
69982 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
69983 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
69984 + polstate->name_set.n_size = arg->role_db.num_objects;
69985 + polstate->inodev_set.i_size = arg->role_db.num_objects;
69986 +
69987 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
69988 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
69989 + return 1;
69990 +
69991 + if (!reload) {
69992 + if (!gr_init_uidset())
69993 + return 1;
69994 + }
69995 +
69996 + /* set up the stack that holds allocation info */
69997 +
69998 + stacksize = arg->role_db.num_pointers + 5;
69999 +
70000 + if (!acl_alloc_stack_init(stacksize))
70001 + return 1;
70002 +
70003 + if (!reload) {
70004 + /* grab reference for the real root dentry and vfsmount */
70005 + get_fs_root(reaper->fs, &gr_real_root);
70006 +
70007 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70008 + 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);
70009 +#endif
70010 +
70011 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
70012 + if (fakefs_obj_rw == NULL)
70013 + return 1;
70014 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
70015 +
70016 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
70017 + if (fakefs_obj_rwx == NULL)
70018 + return 1;
70019 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
70020 + }
70021 +
70022 + polstate->subj_map_set.s_hash =
70023 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
70024 + polstate->acl_role_set.r_hash =
70025 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
70026 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
70027 + polstate->inodev_set.i_hash =
70028 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
70029 +
70030 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
70031 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
70032 + return 1;
70033 +
70034 + memset(polstate->subj_map_set.s_hash, 0,
70035 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
70036 + memset(polstate->acl_role_set.r_hash, 0,
70037 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
70038 + memset(polstate->name_set.n_hash, 0,
70039 + sizeof (struct name_entry *) * polstate->name_set.n_size);
70040 + memset(polstate->inodev_set.i_hash, 0,
70041 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
70042 +
70043 + return 0;
70044 +}
70045 +
70046 +/* free information not needed after startup
70047 + currently contains user->kernel pointer mappings for subjects
70048 +*/
70049 +
70050 +static void
70051 +free_init_variables(void)
70052 +{
70053 + __u32 i;
70054 +
70055 + if (polstate->subj_map_set.s_hash) {
70056 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
70057 + if (polstate->subj_map_set.s_hash[i]) {
70058 + kfree(polstate->subj_map_set.s_hash[i]);
70059 + polstate->subj_map_set.s_hash[i] = NULL;
70060 + }
70061 + }
70062 +
70063 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
70064 + PAGE_SIZE)
70065 + kfree(polstate->subj_map_set.s_hash);
70066 + else
70067 + vfree(polstate->subj_map_set.s_hash);
70068 + }
70069 +
70070 + return;
70071 +}
70072 +
70073 +static void
70074 +free_variables(bool reload)
70075 +{
70076 + struct acl_subject_label *s;
70077 + struct acl_role_label *r;
70078 + struct task_struct *task, *task2;
70079 + unsigned int x;
70080 +
70081 + if (!reload) {
70082 + gr_clear_learn_entries();
70083 +
70084 + read_lock(&tasklist_lock);
70085 + do_each_thread(task2, task) {
70086 + task->acl_sp_role = 0;
70087 + task->acl_role_id = 0;
70088 + task->inherited = 0;
70089 + task->acl = NULL;
70090 + task->role = NULL;
70091 + } while_each_thread(task2, task);
70092 + read_unlock(&tasklist_lock);
70093 +
70094 + kfree(fakefs_obj_rw);
70095 + fakefs_obj_rw = NULL;
70096 + kfree(fakefs_obj_rwx);
70097 + fakefs_obj_rwx = NULL;
70098 +
70099 + /* release the reference to the real root dentry and vfsmount */
70100 + path_put(&gr_real_root);
70101 + memset(&gr_real_root, 0, sizeof(gr_real_root));
70102 + }
70103 +
70104 + /* free all object hash tables */
70105 +
70106 + FOR_EACH_ROLE_START(r)
70107 + if (r->subj_hash == NULL)
70108 + goto next_role;
70109 + FOR_EACH_SUBJECT_START(r, s, x)
70110 + if (s->obj_hash == NULL)
70111 + break;
70112 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
70113 + kfree(s->obj_hash);
70114 + else
70115 + vfree(s->obj_hash);
70116 + FOR_EACH_SUBJECT_END(s, x)
70117 + FOR_EACH_NESTED_SUBJECT_START(r, s)
70118 + if (s->obj_hash == NULL)
70119 + break;
70120 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
70121 + kfree(s->obj_hash);
70122 + else
70123 + vfree(s->obj_hash);
70124 + FOR_EACH_NESTED_SUBJECT_END(s)
70125 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
70126 + kfree(r->subj_hash);
70127 + else
70128 + vfree(r->subj_hash);
70129 + r->subj_hash = NULL;
70130 +next_role:
70131 + FOR_EACH_ROLE_END(r)
70132 +
70133 + acl_free_all();
70134 +
70135 + if (polstate->acl_role_set.r_hash) {
70136 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
70137 + PAGE_SIZE)
70138 + kfree(polstate->acl_role_set.r_hash);
70139 + else
70140 + vfree(polstate->acl_role_set.r_hash);
70141 + }
70142 + if (polstate->name_set.n_hash) {
70143 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
70144 + PAGE_SIZE)
70145 + kfree(polstate->name_set.n_hash);
70146 + else
70147 + vfree(polstate->name_set.n_hash);
70148 + }
70149 +
70150 + if (polstate->inodev_set.i_hash) {
70151 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
70152 + PAGE_SIZE)
70153 + kfree(polstate->inodev_set.i_hash);
70154 + else
70155 + vfree(polstate->inodev_set.i_hash);
70156 + }
70157 +
70158 + if (!reload)
70159 + gr_free_uidset();
70160 +
70161 + memset(&polstate->name_set, 0, sizeof (struct name_db));
70162 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
70163 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
70164 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
70165 +
70166 + polstate->default_role = NULL;
70167 + polstate->kernel_role = NULL;
70168 + polstate->role_list = NULL;
70169 +
70170 + return;
70171 +}
70172 +
70173 +static struct acl_subject_label *
70174 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
70175 +
70176 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
70177 +{
70178 + unsigned int len = strnlen_user(*name, maxlen);
70179 + char *tmp;
70180 +
70181 + if (!len || len >= maxlen)
70182 + return -EINVAL;
70183 +
70184 + if ((tmp = (char *) acl_alloc(len)) == NULL)
70185 + return -ENOMEM;
70186 +
70187 + if (copy_from_user(tmp, *name, len))
70188 + return -EFAULT;
70189 +
70190 + tmp[len-1] = '\0';
70191 + *name = tmp;
70192 +
70193 + return 0;
70194 +}
70195 +
70196 +static int
70197 +copy_user_glob(struct acl_object_label *obj)
70198 +{
70199 + struct acl_object_label *g_tmp, **guser;
70200 + int error;
70201 +
70202 + if (obj->globbed == NULL)
70203 + return 0;
70204 +
70205 + guser = &obj->globbed;
70206 + while (*guser) {
70207 + g_tmp = (struct acl_object_label *)
70208 + acl_alloc(sizeof (struct acl_object_label));
70209 + if (g_tmp == NULL)
70210 + return -ENOMEM;
70211 +
70212 + if (copy_acl_object_label(g_tmp, *guser))
70213 + return -EFAULT;
70214 +
70215 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
70216 + if (error)
70217 + return error;
70218 +
70219 + *guser = g_tmp;
70220 + guser = &(g_tmp->next);
70221 + }
70222 +
70223 + return 0;
70224 +}
70225 +
70226 +static int
70227 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
70228 + struct acl_role_label *role)
70229 +{
70230 + struct acl_object_label *o_tmp;
70231 + int ret;
70232 +
70233 + while (userp) {
70234 + if ((o_tmp = (struct acl_object_label *)
70235 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
70236 + return -ENOMEM;
70237 +
70238 + if (copy_acl_object_label(o_tmp, userp))
70239 + return -EFAULT;
70240 +
70241 + userp = o_tmp->prev;
70242 +
70243 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
70244 + if (ret)
70245 + return ret;
70246 +
70247 + insert_acl_obj_label(o_tmp, subj);
70248 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
70249 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
70250 + return -ENOMEM;
70251 +
70252 + ret = copy_user_glob(o_tmp);
70253 + if (ret)
70254 + return ret;
70255 +
70256 + if (o_tmp->nested) {
70257 + int already_copied;
70258 +
70259 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
70260 + if (IS_ERR(o_tmp->nested))
70261 + return PTR_ERR(o_tmp->nested);
70262 +
70263 + /* insert into nested subject list if we haven't copied this one yet
70264 + to prevent duplicate entries */
70265 + if (!already_copied) {
70266 + o_tmp->nested->next = role->hash->first;
70267 + role->hash->first = o_tmp->nested;
70268 + }
70269 + }
70270 + }
70271 +
70272 + return 0;
70273 +}
70274 +
70275 +static __u32
70276 +count_user_subjs(struct acl_subject_label *userp)
70277 +{
70278 + struct acl_subject_label s_tmp;
70279 + __u32 num = 0;
70280 +
70281 + while (userp) {
70282 + if (copy_acl_subject_label(&s_tmp, userp))
70283 + break;
70284 +
70285 + userp = s_tmp.prev;
70286 + }
70287 +
70288 + return num;
70289 +}
70290 +
70291 +static int
70292 +copy_user_allowedips(struct acl_role_label *rolep)
70293 +{
70294 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
70295 +
70296 + ruserip = rolep->allowed_ips;
70297 +
70298 + while (ruserip) {
70299 + rlast = rtmp;
70300 +
70301 + if ((rtmp = (struct role_allowed_ip *)
70302 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
70303 + return -ENOMEM;
70304 +
70305 + if (copy_role_allowed_ip(rtmp, ruserip))
70306 + return -EFAULT;
70307 +
70308 + ruserip = rtmp->prev;
70309 +
70310 + if (!rlast) {
70311 + rtmp->prev = NULL;
70312 + rolep->allowed_ips = rtmp;
70313 + } else {
70314 + rlast->next = rtmp;
70315 + rtmp->prev = rlast;
70316 + }
70317 +
70318 + if (!ruserip)
70319 + rtmp->next = NULL;
70320 + }
70321 +
70322 + return 0;
70323 +}
70324 +
70325 +static int
70326 +copy_user_transitions(struct acl_role_label *rolep)
70327 +{
70328 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
70329 + int error;
70330 +
70331 + rusertp = rolep->transitions;
70332 +
70333 + while (rusertp) {
70334 + rlast = rtmp;
70335 +
70336 + if ((rtmp = (struct role_transition *)
70337 + acl_alloc(sizeof (struct role_transition))) == NULL)
70338 + return -ENOMEM;
70339 +
70340 + if (copy_role_transition(rtmp, rusertp))
70341 + return -EFAULT;
70342 +
70343 + rusertp = rtmp->prev;
70344 +
70345 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
70346 + if (error)
70347 + return error;
70348 +
70349 + if (!rlast) {
70350 + rtmp->prev = NULL;
70351 + rolep->transitions = rtmp;
70352 + } else {
70353 + rlast->next = rtmp;
70354 + rtmp->prev = rlast;
70355 + }
70356 +
70357 + if (!rusertp)
70358 + rtmp->next = NULL;
70359 + }
70360 +
70361 + return 0;
70362 +}
70363 +
70364 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
70365 +{
70366 + struct acl_object_label o_tmp;
70367 + __u32 num = 0;
70368 +
70369 + while (userp) {
70370 + if (copy_acl_object_label(&o_tmp, userp))
70371 + break;
70372 +
70373 + userp = o_tmp.prev;
70374 + num++;
70375 + }
70376 +
70377 + return num;
70378 +}
70379 +
70380 +static struct acl_subject_label *
70381 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
70382 +{
70383 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
70384 + __u32 num_objs;
70385 + struct acl_ip_label **i_tmp, *i_utmp2;
70386 + struct gr_hash_struct ghash;
70387 + struct subject_map *subjmap;
70388 + unsigned int i_num;
70389 + int err;
70390 +
70391 + if (already_copied != NULL)
70392 + *already_copied = 0;
70393 +
70394 + s_tmp = lookup_subject_map(userp);
70395 +
70396 + /* we've already copied this subject into the kernel, just return
70397 + the reference to it, and don't copy it over again
70398 + */
70399 + if (s_tmp) {
70400 + if (already_copied != NULL)
70401 + *already_copied = 1;
70402 + return(s_tmp);
70403 + }
70404 +
70405 + if ((s_tmp = (struct acl_subject_label *)
70406 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
70407 + return ERR_PTR(-ENOMEM);
70408 +
70409 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
70410 + if (subjmap == NULL)
70411 + return ERR_PTR(-ENOMEM);
70412 +
70413 + subjmap->user = userp;
70414 + subjmap->kernel = s_tmp;
70415 + insert_subj_map_entry(subjmap);
70416 +
70417 + if (copy_acl_subject_label(s_tmp, userp))
70418 + return ERR_PTR(-EFAULT);
70419 +
70420 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
70421 + if (err)
70422 + return ERR_PTR(err);
70423 +
70424 + if (!strcmp(s_tmp->filename, "/"))
70425 + role->root_label = s_tmp;
70426 +
70427 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
70428 + return ERR_PTR(-EFAULT);
70429 +
70430 + /* copy user and group transition tables */
70431 +
70432 + if (s_tmp->user_trans_num) {
70433 + uid_t *uidlist;
70434 +
70435 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
70436 + if (uidlist == NULL)
70437 + return ERR_PTR(-ENOMEM);
70438 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
70439 + return ERR_PTR(-EFAULT);
70440 +
70441 + s_tmp->user_transitions = uidlist;
70442 + }
70443 +
70444 + if (s_tmp->group_trans_num) {
70445 + gid_t *gidlist;
70446 +
70447 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
70448 + if (gidlist == NULL)
70449 + return ERR_PTR(-ENOMEM);
70450 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
70451 + return ERR_PTR(-EFAULT);
70452 +
70453 + s_tmp->group_transitions = gidlist;
70454 + }
70455 +
70456 + /* set up object hash table */
70457 + num_objs = count_user_objs(ghash.first);
70458 +
70459 + s_tmp->obj_hash_size = num_objs;
70460 + s_tmp->obj_hash =
70461 + (struct acl_object_label **)
70462 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
70463 +
70464 + if (!s_tmp->obj_hash)
70465 + return ERR_PTR(-ENOMEM);
70466 +
70467 + memset(s_tmp->obj_hash, 0,
70468 + s_tmp->obj_hash_size *
70469 + sizeof (struct acl_object_label *));
70470 +
70471 + /* add in objects */
70472 + err = copy_user_objs(ghash.first, s_tmp, role);
70473 +
70474 + if (err)
70475 + return ERR_PTR(err);
70476 +
70477 + /* set pointer for parent subject */
70478 + if (s_tmp->parent_subject) {
70479 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
70480 +
70481 + if (IS_ERR(s_tmp2))
70482 + return s_tmp2;
70483 +
70484 + s_tmp->parent_subject = s_tmp2;
70485 + }
70486 +
70487 + /* add in ip acls */
70488 +
70489 + if (!s_tmp->ip_num) {
70490 + s_tmp->ips = NULL;
70491 + goto insert;
70492 + }
70493 +
70494 + i_tmp =
70495 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
70496 + sizeof (struct acl_ip_label *));
70497 +
70498 + if (!i_tmp)
70499 + return ERR_PTR(-ENOMEM);
70500 +
70501 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
70502 + *(i_tmp + i_num) =
70503 + (struct acl_ip_label *)
70504 + acl_alloc(sizeof (struct acl_ip_label));
70505 + if (!*(i_tmp + i_num))
70506 + return ERR_PTR(-ENOMEM);
70507 +
70508 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
70509 + return ERR_PTR(-EFAULT);
70510 +
70511 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
70512 + return ERR_PTR(-EFAULT);
70513 +
70514 + if ((*(i_tmp + i_num))->iface == NULL)
70515 + continue;
70516 +
70517 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
70518 + if (err)
70519 + return ERR_PTR(err);
70520 + }
70521 +
70522 + s_tmp->ips = i_tmp;
70523 +
70524 +insert:
70525 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
70526 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
70527 + return ERR_PTR(-ENOMEM);
70528 +
70529 + return s_tmp;
70530 +}
70531 +
70532 +static int
70533 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
70534 +{
70535 + struct acl_subject_label s_pre;
70536 + struct acl_subject_label * ret;
70537 + int err;
70538 +
70539 + while (userp) {
70540 + if (copy_acl_subject_label(&s_pre, userp))
70541 + return -EFAULT;
70542 +
70543 + ret = do_copy_user_subj(userp, role, NULL);
70544 +
70545 + err = PTR_ERR(ret);
70546 + if (IS_ERR(ret))
70547 + return err;
70548 +
70549 + insert_acl_subj_label(ret, role);
70550 +
70551 + userp = s_pre.prev;
70552 + }
70553 +
70554 + return 0;
70555 +}
70556 +
70557 +static int
70558 +copy_user_acl(struct gr_arg *arg)
70559 +{
70560 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
70561 + struct acl_subject_label *subj_list;
70562 + struct sprole_pw *sptmp;
70563 + struct gr_hash_struct *ghash;
70564 + uid_t *domainlist;
70565 + unsigned int r_num;
70566 + int err = 0;
70567 + __u16 i;
70568 + __u32 num_subjs;
70569 +
70570 + /* we need a default and kernel role */
70571 + if (arg->role_db.num_roles < 2)
70572 + return -EINVAL;
70573 +
70574 + /* copy special role authentication info from userspace */
70575 +
70576 + polstate->num_sprole_pws = arg->num_sprole_pws;
70577 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
70578 +
70579 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
70580 + return -ENOMEM;
70581 +
70582 + for (i = 0; i < polstate->num_sprole_pws; i++) {
70583 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
70584 + if (!sptmp)
70585 + return -ENOMEM;
70586 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
70587 + return -EFAULT;
70588 +
70589 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
70590 + if (err)
70591 + return err;
70592 +
70593 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70594 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
70595 +#endif
70596 +
70597 + polstate->acl_special_roles[i] = sptmp;
70598 + }
70599 +
70600 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
70601 +
70602 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
70603 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
70604 +
70605 + if (!r_tmp)
70606 + return -ENOMEM;
70607 +
70608 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
70609 + return -EFAULT;
70610 +
70611 + if (copy_acl_role_label(r_tmp, r_utmp2))
70612 + return -EFAULT;
70613 +
70614 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
70615 + if (err)
70616 + return err;
70617 +
70618 + if (!strcmp(r_tmp->rolename, "default")
70619 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
70620 + polstate->default_role = r_tmp;
70621 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
70622 + polstate->kernel_role = r_tmp;
70623 + }
70624 +
70625 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
70626 + return -ENOMEM;
70627 +
70628 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
70629 + return -EFAULT;
70630 +
70631 + r_tmp->hash = ghash;
70632 +
70633 + num_subjs = count_user_subjs(r_tmp->hash->first);
70634 +
70635 + r_tmp->subj_hash_size = num_subjs;
70636 + r_tmp->subj_hash =
70637 + (struct acl_subject_label **)
70638 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
70639 +
70640 + if (!r_tmp->subj_hash)
70641 + return -ENOMEM;
70642 +
70643 + err = copy_user_allowedips(r_tmp);
70644 + if (err)
70645 + return err;
70646 +
70647 + /* copy domain info */
70648 + if (r_tmp->domain_children != NULL) {
70649 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
70650 + if (domainlist == NULL)
70651 + return -ENOMEM;
70652 +
70653 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
70654 + return -EFAULT;
70655 +
70656 + r_tmp->domain_children = domainlist;
70657 + }
70658 +
70659 + err = copy_user_transitions(r_tmp);
70660 + if (err)
70661 + return err;
70662 +
70663 + memset(r_tmp->subj_hash, 0,
70664 + r_tmp->subj_hash_size *
70665 + sizeof (struct acl_subject_label *));
70666 +
70667 + /* acquire the list of subjects, then NULL out
70668 + the list prior to parsing the subjects for this role,
70669 + as during this parsing the list is replaced with a list
70670 + of *nested* subjects for the role
70671 + */
70672 + subj_list = r_tmp->hash->first;
70673 +
70674 + /* set nested subject list to null */
70675 + r_tmp->hash->first = NULL;
70676 +
70677 + err = copy_user_subjs(subj_list, r_tmp);
70678 +
70679 + if (err)
70680 + return err;
70681 +
70682 + insert_acl_role_label(r_tmp);
70683 + }
70684 +
70685 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
70686 + return -EINVAL;
70687 +
70688 + return err;
70689 +}
70690 +
70691 +static int gracl_reload_apply_policies(void *reload)
70692 +{
70693 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
70694 + struct task_struct *task, *task2;
70695 + struct acl_role_label *role, *rtmp;
70696 + struct acl_subject_label *subj;
70697 + const struct cred *cred;
70698 + int role_applied;
70699 + int ret = 0;
70700 +
70701 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
70702 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
70703 +
70704 + /* first make sure we'll be able to apply the new policy cleanly */
70705 + do_each_thread(task2, task) {
70706 + if (task->exec_file == NULL)
70707 + continue;
70708 + role_applied = 0;
70709 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
70710 + /* preserve special roles */
70711 + FOR_EACH_ROLE_START(role)
70712 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
70713 + rtmp = task->role;
70714 + task->role = role;
70715 + role_applied = 1;
70716 + break;
70717 + }
70718 + FOR_EACH_ROLE_END(role)
70719 + }
70720 + if (!role_applied) {
70721 + cred = __task_cred(task);
70722 + rtmp = task->role;
70723 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
70724 + }
70725 + /* this handles non-nested inherited subjects, nested subjects will still
70726 + be dropped currently */
70727 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
70728 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
70729 + /* change the role back so that we've made no modifications to the policy */
70730 + task->role = rtmp;
70731 +
70732 + if (subj == NULL || task->tmpacl == NULL) {
70733 + ret = -EINVAL;
70734 + goto out;
70735 + }
70736 + } while_each_thread(task2, task);
70737 +
70738 + /* now actually apply the policy */
70739 +
70740 + do_each_thread(task2, task) {
70741 + if (task->exec_file) {
70742 + role_applied = 0;
70743 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
70744 + /* preserve special roles */
70745 + FOR_EACH_ROLE_START(role)
70746 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
70747 + task->role = role;
70748 + role_applied = 1;
70749 + break;
70750 + }
70751 + FOR_EACH_ROLE_END(role)
70752 + }
70753 + if (!role_applied) {
70754 + cred = __task_cred(task);
70755 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
70756 + }
70757 + /* this handles non-nested inherited subjects, nested subjects will still
70758 + be dropped currently */
70759 + if (!reload_state->oldmode && task->inherited)
70760 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
70761 + else {
70762 + /* looked up and tagged to the task previously */
70763 + subj = task->tmpacl;
70764 + }
70765 + /* subj will be non-null */
70766 + __gr_apply_subject_to_task(polstate, task, subj);
70767 + if (reload_state->oldmode) {
70768 + task->acl_role_id = 0;
70769 + task->acl_sp_role = 0;
70770 + task->inherited = 0;
70771 + }
70772 + } else {
70773 + // it's a kernel process
70774 + task->role = polstate->kernel_role;
70775 + task->acl = polstate->kernel_role->root_label;
70776 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
70777 + task->acl->mode &= ~GR_PROCFIND;
70778 +#endif
70779 + }
70780 + } while_each_thread(task2, task);
70781 +
70782 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
70783 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
70784 +
70785 +out:
70786 +
70787 + return ret;
70788 +}
70789 +
70790 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
70791 +{
70792 + struct gr_reload_state new_reload_state = { };
70793 + int err;
70794 +
70795 + new_reload_state.oldpolicy_ptr = polstate;
70796 + new_reload_state.oldalloc_ptr = current_alloc_state;
70797 + new_reload_state.oldmode = oldmode;
70798 +
70799 + current_alloc_state = &new_reload_state.newalloc;
70800 + polstate = &new_reload_state.newpolicy;
70801 +
70802 + /* everything relevant is now saved off, copy in the new policy */
70803 + if (init_variables(args, true)) {
70804 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
70805 + err = -ENOMEM;
70806 + goto error;
70807 + }
70808 +
70809 + err = copy_user_acl(args);
70810 + free_init_variables();
70811 + if (err)
70812 + goto error;
70813 + /* the new policy is copied in, with the old policy available via saved_state
70814 + first go through applying roles, making sure to preserve special roles
70815 + then apply new subjects, making sure to preserve inherited and nested subjects,
70816 + though currently only inherited subjects will be preserved
70817 + */
70818 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
70819 + if (err)
70820 + goto error;
70821 +
70822 + /* we've now applied the new policy, so restore the old policy state to free it */
70823 + polstate = &new_reload_state.oldpolicy;
70824 + current_alloc_state = &new_reload_state.oldalloc;
70825 + free_variables(true);
70826 +
70827 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
70828 + to running_polstate/current_alloc_state inside stop_machine
70829 + */
70830 + err = 0;
70831 + goto out;
70832 +error:
70833 + /* on error of loading the new policy, we'll just keep the previous
70834 + policy set around
70835 + */
70836 + free_variables(true);
70837 +
70838 + /* doesn't affect runtime, but maintains consistent state */
70839 +out:
70840 + polstate = new_reload_state.oldpolicy_ptr;
70841 + current_alloc_state = new_reload_state.oldalloc_ptr;
70842 +
70843 + return err;
70844 +}
70845 +
70846 +static int
70847 +gracl_init(struct gr_arg *args)
70848 +{
70849 + int error = 0;
70850 +
70851 + memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
70852 + memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
70853 +
70854 + if (init_variables(args, false)) {
70855 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
70856 + error = -ENOMEM;
70857 + goto out;
70858 + }
70859 +
70860 + error = copy_user_acl(args);
70861 + free_init_variables();
70862 + if (error)
70863 + goto out;
70864 +
70865 + error = gr_set_acls(0);
70866 + if (error)
70867 + goto out;
70868 +
70869 + gr_enable_rbac_system();
70870 +
70871 + return 0;
70872 +
70873 +out:
70874 + free_variables(false);
70875 + return error;
70876 +}
70877 +
70878 +static int
70879 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
70880 + unsigned char **sum)
70881 +{
70882 + struct acl_role_label *r;
70883 + struct role_allowed_ip *ipp;
70884 + struct role_transition *trans;
70885 + unsigned int i;
70886 + int found = 0;
70887 + u32 curr_ip = current->signal->curr_ip;
70888 +
70889 + current->signal->saved_ip = curr_ip;
70890 +
70891 + /* check transition table */
70892 +
70893 + for (trans = current->role->transitions; trans; trans = trans->next) {
70894 + if (!strcmp(rolename, trans->rolename)) {
70895 + found = 1;
70896 + break;
70897 + }
70898 + }
70899 +
70900 + if (!found)
70901 + return 0;
70902 +
70903 + /* handle special roles that do not require authentication
70904 + and check ip */
70905 +
70906 + FOR_EACH_ROLE_START(r)
70907 + if (!strcmp(rolename, r->rolename) &&
70908 + (r->roletype & GR_ROLE_SPECIAL)) {
70909 + found = 0;
70910 + if (r->allowed_ips != NULL) {
70911 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
70912 + if ((ntohl(curr_ip) & ipp->netmask) ==
70913 + (ntohl(ipp->addr) & ipp->netmask))
70914 + found = 1;
70915 + }
70916 + } else
70917 + found = 2;
70918 + if (!found)
70919 + return 0;
70920 +
70921 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
70922 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
70923 + *salt = NULL;
70924 + *sum = NULL;
70925 + return 1;
70926 + }
70927 + }
70928 + FOR_EACH_ROLE_END(r)
70929 +
70930 + for (i = 0; i < polstate->num_sprole_pws; i++) {
70931 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
70932 + *salt = polstate->acl_special_roles[i]->salt;
70933 + *sum = polstate->acl_special_roles[i]->sum;
70934 + return 1;
70935 + }
70936 + }
70937 +
70938 + return 0;
70939 +}
70940 +
70941 +int gr_check_secure_terminal(struct task_struct *task)
70942 +{
70943 + struct task_struct *p, *p2, *p3;
70944 + struct files_struct *files;
70945 + struct fdtable *fdt;
70946 + struct file *our_file = NULL, *file;
70947 + int i;
70948 +
70949 + if (task->signal->tty == NULL)
70950 + return 1;
70951 +
70952 + files = get_files_struct(task);
70953 + if (files != NULL) {
70954 + rcu_read_lock();
70955 + fdt = files_fdtable(files);
70956 + for (i=0; i < fdt->max_fds; i++) {
70957 + file = fcheck_files(files, i);
70958 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
70959 + get_file(file);
70960 + our_file = file;
70961 + }
70962 + }
70963 + rcu_read_unlock();
70964 + put_files_struct(files);
70965 + }
70966 +
70967 + if (our_file == NULL)
70968 + return 1;
70969 +
70970 + read_lock(&tasklist_lock);
70971 + do_each_thread(p2, p) {
70972 + files = get_files_struct(p);
70973 + if (files == NULL ||
70974 + (p->signal && p->signal->tty == task->signal->tty)) {
70975 + if (files != NULL)
70976 + put_files_struct(files);
70977 + continue;
70978 + }
70979 + rcu_read_lock();
70980 + fdt = files_fdtable(files);
70981 + for (i=0; i < fdt->max_fds; i++) {
70982 + file = fcheck_files(files, i);
70983 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
70984 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
70985 + p3 = task;
70986 + while (task_pid_nr(p3) > 0) {
70987 + if (p3 == p)
70988 + break;
70989 + p3 = p3->real_parent;
70990 + }
70991 + if (p3 == p)
70992 + break;
70993 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
70994 + gr_handle_alertkill(p);
70995 + rcu_read_unlock();
70996 + put_files_struct(files);
70997 + read_unlock(&tasklist_lock);
70998 + fput(our_file);
70999 + return 0;
71000 + }
71001 + }
71002 + rcu_read_unlock();
71003 + put_files_struct(files);
71004 + } while_each_thread(p2, p);
71005 + read_unlock(&tasklist_lock);
71006 +
71007 + fput(our_file);
71008 + return 1;
71009 +}
71010 +
71011 +ssize_t
71012 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
71013 +{
71014 + struct gr_arg_wrapper uwrap;
71015 + unsigned char *sprole_salt = NULL;
71016 + unsigned char *sprole_sum = NULL;
71017 + int error = 0;
71018 + int error2 = 0;
71019 + size_t req_count = 0;
71020 + unsigned char oldmode = 0;
71021 +
71022 + mutex_lock(&gr_dev_mutex);
71023 +
71024 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
71025 + error = -EPERM;
71026 + goto out;
71027 + }
71028 +
71029 +#ifdef CONFIG_COMPAT
71030 + pax_open_kernel();
71031 + if (is_compat_task()) {
71032 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
71033 + copy_gr_arg = &copy_gr_arg_compat;
71034 + copy_acl_object_label = &copy_acl_object_label_compat;
71035 + copy_acl_subject_label = &copy_acl_subject_label_compat;
71036 + copy_acl_role_label = &copy_acl_role_label_compat;
71037 + copy_acl_ip_label = &copy_acl_ip_label_compat;
71038 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
71039 + copy_role_transition = &copy_role_transition_compat;
71040 + copy_sprole_pw = &copy_sprole_pw_compat;
71041 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
71042 + copy_pointer_from_array = &copy_pointer_from_array_compat;
71043 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
71044 + } else {
71045 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
71046 + copy_gr_arg = &copy_gr_arg_normal;
71047 + copy_acl_object_label = &copy_acl_object_label_normal;
71048 + copy_acl_subject_label = &copy_acl_subject_label_normal;
71049 + copy_acl_role_label = &copy_acl_role_label_normal;
71050 + copy_acl_ip_label = &copy_acl_ip_label_normal;
71051 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
71052 + copy_role_transition = &copy_role_transition_normal;
71053 + copy_sprole_pw = &copy_sprole_pw_normal;
71054 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
71055 + copy_pointer_from_array = &copy_pointer_from_array_normal;
71056 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
71057 + }
71058 + pax_close_kernel();
71059 +#endif
71060 +
71061 + req_count = get_gr_arg_wrapper_size();
71062 +
71063 + if (count != req_count) {
71064 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
71065 + error = -EINVAL;
71066 + goto out;
71067 + }
71068 +
71069 +
71070 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
71071 + gr_auth_expires = 0;
71072 + gr_auth_attempts = 0;
71073 + }
71074 +
71075 + error = copy_gr_arg_wrapper(buf, &uwrap);
71076 + if (error)
71077 + goto out;
71078 +
71079 + error = copy_gr_arg(uwrap.arg, &gr_usermode);
71080 + if (error)
71081 + goto out;
71082 +
71083 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
71084 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
71085 + time_after(gr_auth_expires, get_seconds())) {
71086 + error = -EBUSY;
71087 + goto out;
71088 + }
71089 +
71090 + /* if non-root trying to do anything other than use a special role,
71091 + do not attempt authentication, do not count towards authentication
71092 + locking
71093 + */
71094 +
71095 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
71096 + gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
71097 + gr_is_global_nonroot(current_uid())) {
71098 + error = -EPERM;
71099 + goto out;
71100 + }
71101 +
71102 + /* ensure pw and special role name are null terminated */
71103 +
71104 + gr_usermode.pw[GR_PW_LEN - 1] = '\0';
71105 + gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
71106 +
71107 + /* Okay.
71108 + * We have our enough of the argument structure..(we have yet
71109 + * to copy_from_user the tables themselves) . Copy the tables
71110 + * only if we need them, i.e. for loading operations. */
71111 +
71112 + switch (gr_usermode.mode) {
71113 + case GR_STATUS:
71114 + if (gr_acl_is_enabled()) {
71115 + error = 1;
71116 + if (!gr_check_secure_terminal(current))
71117 + error = 3;
71118 + } else
71119 + error = 2;
71120 + goto out;
71121 + case GR_SHUTDOWN:
71122 + if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71123 + stop_machine(gr_rbac_disable, NULL, NULL);
71124 + free_variables(false);
71125 + memset(&gr_usermode, 0, sizeof(gr_usermode));
71126 + memset(&gr_system_salt, 0, sizeof(gr_system_salt));
71127 + memset(&gr_system_sum, 0, sizeof(gr_system_sum));
71128 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
71129 + } else if (gr_acl_is_enabled()) {
71130 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
71131 + error = -EPERM;
71132 + } else {
71133 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
71134 + error = -EAGAIN;
71135 + }
71136 + break;
71137 + case GR_ENABLE:
71138 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
71139 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
71140 + else {
71141 + if (gr_acl_is_enabled())
71142 + error = -EAGAIN;
71143 + else
71144 + error = error2;
71145 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
71146 + }
71147 + break;
71148 + case GR_OLDRELOAD:
71149 + oldmode = 1;
71150 + case GR_RELOAD:
71151 + if (!gr_acl_is_enabled()) {
71152 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
71153 + error = -EAGAIN;
71154 + } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71155 + error2 = gracl_reload(&gr_usermode, oldmode);
71156 + if (!error2)
71157 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
71158 + else {
71159 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
71160 + error = error2;
71161 + }
71162 + } else {
71163 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
71164 + error = -EPERM;
71165 + }
71166 + break;
71167 + case GR_SEGVMOD:
71168 + if (unlikely(!gr_acl_is_enabled())) {
71169 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
71170 + error = -EAGAIN;
71171 + break;
71172 + }
71173 +
71174 + if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71175 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
71176 + if (gr_usermode.segv_device && gr_usermode.segv_inode) {
71177 + struct acl_subject_label *segvacl;
71178 + segvacl =
71179 + lookup_acl_subj_label(gr_usermode.segv_inode,
71180 + gr_usermode.segv_device,
71181 + current->role);
71182 + if (segvacl) {
71183 + segvacl->crashes = 0;
71184 + segvacl->expires = 0;
71185 + }
71186 + } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
71187 + gr_remove_uid(gr_usermode.segv_uid);
71188 + }
71189 + } else {
71190 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
71191 + error = -EPERM;
71192 + }
71193 + break;
71194 + case GR_SPROLE:
71195 + case GR_SPROLEPAM:
71196 + if (unlikely(!gr_acl_is_enabled())) {
71197 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
71198 + error = -EAGAIN;
71199 + break;
71200 + }
71201 +
71202 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
71203 + current->role->expires = 0;
71204 + current->role->auth_attempts = 0;
71205 + }
71206 +
71207 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
71208 + time_after(current->role->expires, get_seconds())) {
71209 + error = -EBUSY;
71210 + goto out;
71211 + }
71212 +
71213 + if (lookup_special_role_auth
71214 + (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
71215 + && ((!sprole_salt && !sprole_sum)
71216 + || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
71217 + char *p = "";
71218 + assign_special_role(gr_usermode.sp_role);
71219 + read_lock(&tasklist_lock);
71220 + if (current->real_parent)
71221 + p = current->real_parent->role->rolename;
71222 + read_unlock(&tasklist_lock);
71223 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
71224 + p, acl_sp_role_value);
71225 + } else {
71226 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
71227 + error = -EPERM;
71228 + if(!(current->role->auth_attempts++))
71229 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
71230 +
71231 + goto out;
71232 + }
71233 + break;
71234 + case GR_UNSPROLE:
71235 + if (unlikely(!gr_acl_is_enabled())) {
71236 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
71237 + error = -EAGAIN;
71238 + break;
71239 + }
71240 +
71241 + if (current->role->roletype & GR_ROLE_SPECIAL) {
71242 + char *p = "";
71243 + int i = 0;
71244 +
71245 + read_lock(&tasklist_lock);
71246 + if (current->real_parent) {
71247 + p = current->real_parent->role->rolename;
71248 + i = current->real_parent->acl_role_id;
71249 + }
71250 + read_unlock(&tasklist_lock);
71251 +
71252 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
71253 + gr_set_acls(1);
71254 + } else {
71255 + error = -EPERM;
71256 + goto out;
71257 + }
71258 + break;
71259 + default:
71260 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
71261 + error = -EINVAL;
71262 + break;
71263 + }
71264 +
71265 + if (error != -EPERM)
71266 + goto out;
71267 +
71268 + if(!(gr_auth_attempts++))
71269 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
71270 +
71271 + out:
71272 + mutex_unlock(&gr_dev_mutex);
71273 +
71274 + if (!error)
71275 + error = req_count;
71276 +
71277 + return error;
71278 +}
71279 +
71280 +int
71281 +gr_set_acls(const int type)
71282 +{
71283 + struct task_struct *task, *task2;
71284 + struct acl_role_label *role = current->role;
71285 + struct acl_subject_label *subj;
71286 + __u16 acl_role_id = current->acl_role_id;
71287 + const struct cred *cred;
71288 + int ret;
71289 +
71290 + rcu_read_lock();
71291 + read_lock(&tasklist_lock);
71292 + read_lock(&grsec_exec_file_lock);
71293 + do_each_thread(task2, task) {
71294 + /* check to see if we're called from the exit handler,
71295 + if so, only replace ACLs that have inherited the admin
71296 + ACL */
71297 +
71298 + if (type && (task->role != role ||
71299 + task->acl_role_id != acl_role_id))
71300 + continue;
71301 +
71302 + task->acl_role_id = 0;
71303 + task->acl_sp_role = 0;
71304 + task->inherited = 0;
71305 +
71306 + if (task->exec_file) {
71307 + cred = __task_cred(task);
71308 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71309 + subj = __gr_get_subject_for_task(polstate, task, NULL);
71310 + if (subj == NULL) {
71311 + ret = -EINVAL;
71312 + read_unlock(&grsec_exec_file_lock);
71313 + read_unlock(&tasklist_lock);
71314 + rcu_read_unlock();
71315 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
71316 + return ret;
71317 + }
71318 + __gr_apply_subject_to_task(polstate, task, subj);
71319 + } else {
71320 + // it's a kernel process
71321 + task->role = polstate->kernel_role;
71322 + task->acl = polstate->kernel_role->root_label;
71323 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
71324 + task->acl->mode &= ~GR_PROCFIND;
71325 +#endif
71326 + }
71327 + } while_each_thread(task2, task);
71328 + read_unlock(&grsec_exec_file_lock);
71329 + read_unlock(&tasklist_lock);
71330 + rcu_read_unlock();
71331 +
71332 + return 0;
71333 +}
71334 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
71335 new file mode 100644
71336 index 0000000..39645c9
71337 --- /dev/null
71338 +++ b/grsecurity/gracl_res.c
71339 @@ -0,0 +1,68 @@
71340 +#include <linux/kernel.h>
71341 +#include <linux/sched.h>
71342 +#include <linux/gracl.h>
71343 +#include <linux/grinternal.h>
71344 +
71345 +static const char *restab_log[] = {
71346 + [RLIMIT_CPU] = "RLIMIT_CPU",
71347 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
71348 + [RLIMIT_DATA] = "RLIMIT_DATA",
71349 + [RLIMIT_STACK] = "RLIMIT_STACK",
71350 + [RLIMIT_CORE] = "RLIMIT_CORE",
71351 + [RLIMIT_RSS] = "RLIMIT_RSS",
71352 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
71353 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
71354 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
71355 + [RLIMIT_AS] = "RLIMIT_AS",
71356 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
71357 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
71358 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
71359 + [RLIMIT_NICE] = "RLIMIT_NICE",
71360 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
71361 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
71362 + [GR_CRASH_RES] = "RLIMIT_CRASH"
71363 +};
71364 +
71365 +void
71366 +gr_log_resource(const struct task_struct *task,
71367 + const int res, const unsigned long wanted, const int gt)
71368 +{
71369 + const struct cred *cred;
71370 + unsigned long rlim;
71371 +
71372 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
71373 + return;
71374 +
71375 + // not yet supported resource
71376 + if (unlikely(!restab_log[res]))
71377 + return;
71378 +
71379 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
71380 + rlim = task_rlimit_max(task, res);
71381 + else
71382 + rlim = task_rlimit(task, res);
71383 +
71384 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
71385 + return;
71386 +
71387 + rcu_read_lock();
71388 + cred = __task_cred(task);
71389 +
71390 + if (res == RLIMIT_NPROC &&
71391 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
71392 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
71393 + goto out_rcu_unlock;
71394 + else if (res == RLIMIT_MEMLOCK &&
71395 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
71396 + goto out_rcu_unlock;
71397 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
71398 + goto out_rcu_unlock;
71399 + rcu_read_unlock();
71400 +
71401 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
71402 +
71403 + return;
71404 +out_rcu_unlock:
71405 + rcu_read_unlock();
71406 + return;
71407 +}
71408 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
71409 new file mode 100644
71410 index 0000000..2040e61
71411 --- /dev/null
71412 +++ b/grsecurity/gracl_segv.c
71413 @@ -0,0 +1,313 @@
71414 +#include <linux/kernel.h>
71415 +#include <linux/mm.h>
71416 +#include <asm/uaccess.h>
71417 +#include <asm/errno.h>
71418 +#include <asm/mman.h>
71419 +#include <net/sock.h>
71420 +#include <linux/file.h>
71421 +#include <linux/fs.h>
71422 +#include <linux/net.h>
71423 +#include <linux/in.h>
71424 +#include <linux/slab.h>
71425 +#include <linux/types.h>
71426 +#include <linux/sched.h>
71427 +#include <linux/timer.h>
71428 +#include <linux/gracl.h>
71429 +#include <linux/grsecurity.h>
71430 +#include <linux/grinternal.h>
71431 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
71432 +#include <linux/magic.h>
71433 +#include <linux/pagemap.h>
71434 +#include "../fs/btrfs/async-thread.h"
71435 +#include "../fs/btrfs/ctree.h"
71436 +#include "../fs/btrfs/btrfs_inode.h"
71437 +#endif
71438 +
71439 +static struct crash_uid *uid_set;
71440 +static unsigned short uid_used;
71441 +static DEFINE_SPINLOCK(gr_uid_lock);
71442 +extern rwlock_t gr_inode_lock;
71443 +extern struct acl_subject_label *
71444 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
71445 + struct acl_role_label *role);
71446 +
71447 +static inline dev_t __get_dev(const struct dentry *dentry)
71448 +{
71449 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
71450 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
71451 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
71452 + else
71453 +#endif
71454 + return dentry->d_sb->s_dev;
71455 +}
71456 +
71457 +int
71458 +gr_init_uidset(void)
71459 +{
71460 + uid_set =
71461 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
71462 + uid_used = 0;
71463 +
71464 + return uid_set ? 1 : 0;
71465 +}
71466 +
71467 +void
71468 +gr_free_uidset(void)
71469 +{
71470 + if (uid_set) {
71471 + struct crash_uid *tmpset;
71472 + spin_lock(&gr_uid_lock);
71473 + tmpset = uid_set;
71474 + uid_set = NULL;
71475 + uid_used = 0;
71476 + spin_unlock(&gr_uid_lock);
71477 + if (tmpset)
71478 + kfree(tmpset);
71479 + }
71480 +
71481 + return;
71482 +}
71483 +
71484 +int
71485 +gr_find_uid(const uid_t uid)
71486 +{
71487 + struct crash_uid *tmp = uid_set;
71488 + uid_t buid;
71489 + int low = 0, high = uid_used - 1, mid;
71490 +
71491 + while (high >= low) {
71492 + mid = (low + high) >> 1;
71493 + buid = tmp[mid].uid;
71494 + if (buid == uid)
71495 + return mid;
71496 + if (buid > uid)
71497 + high = mid - 1;
71498 + if (buid < uid)
71499 + low = mid + 1;
71500 + }
71501 +
71502 + return -1;
71503 +}
71504 +
71505 +static __inline__ void
71506 +gr_insertsort(void)
71507 +{
71508 + unsigned short i, j;
71509 + struct crash_uid index;
71510 +
71511 + for (i = 1; i < uid_used; i++) {
71512 + index = uid_set[i];
71513 + j = i;
71514 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
71515 + uid_set[j] = uid_set[j - 1];
71516 + j--;
71517 + }
71518 + uid_set[j] = index;
71519 + }
71520 +
71521 + return;
71522 +}
71523 +
71524 +static __inline__ void
71525 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
71526 +{
71527 + int loc;
71528 + uid_t uid = GR_GLOBAL_UID(kuid);
71529 +
71530 + if (uid_used == GR_UIDTABLE_MAX)
71531 + return;
71532 +
71533 + loc = gr_find_uid(uid);
71534 +
71535 + if (loc >= 0) {
71536 + uid_set[loc].expires = expires;
71537 + return;
71538 + }
71539 +
71540 + uid_set[uid_used].uid = uid;
71541 + uid_set[uid_used].expires = expires;
71542 + uid_used++;
71543 +
71544 + gr_insertsort();
71545 +
71546 + return;
71547 +}
71548 +
71549 +void
71550 +gr_remove_uid(const unsigned short loc)
71551 +{
71552 + unsigned short i;
71553 +
71554 + for (i = loc + 1; i < uid_used; i++)
71555 + uid_set[i - 1] = uid_set[i];
71556 +
71557 + uid_used--;
71558 +
71559 + return;
71560 +}
71561 +
71562 +int
71563 +gr_check_crash_uid(const kuid_t kuid)
71564 +{
71565 + int loc;
71566 + int ret = 0;
71567 + uid_t uid;
71568 +
71569 + if (unlikely(!gr_acl_is_enabled()))
71570 + return 0;
71571 +
71572 + uid = GR_GLOBAL_UID(kuid);
71573 +
71574 + spin_lock(&gr_uid_lock);
71575 + loc = gr_find_uid(uid);
71576 +
71577 + if (loc < 0)
71578 + goto out_unlock;
71579 +
71580 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
71581 + gr_remove_uid(loc);
71582 + else
71583 + ret = 1;
71584 +
71585 +out_unlock:
71586 + spin_unlock(&gr_uid_lock);
71587 + return ret;
71588 +}
71589 +
71590 +static __inline__ int
71591 +proc_is_setxid(const struct cred *cred)
71592 +{
71593 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
71594 + !uid_eq(cred->uid, cred->fsuid))
71595 + return 1;
71596 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
71597 + !gid_eq(cred->gid, cred->fsgid))
71598 + return 1;
71599 +
71600 + return 0;
71601 +}
71602 +
71603 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
71604 +
71605 +void
71606 +gr_handle_crash(struct task_struct *task, const int sig)
71607 +{
71608 + struct acl_subject_label *curr;
71609 + struct task_struct *tsk, *tsk2;
71610 + const struct cred *cred;
71611 + const struct cred *cred2;
71612 +
71613 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
71614 + return;
71615 +
71616 + if (unlikely(!gr_acl_is_enabled()))
71617 + return;
71618 +
71619 + curr = task->acl;
71620 +
71621 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
71622 + return;
71623 +
71624 + if (time_before_eq(curr->expires, get_seconds())) {
71625 + curr->expires = 0;
71626 + curr->crashes = 0;
71627 + }
71628 +
71629 + curr->crashes++;
71630 +
71631 + if (!curr->expires)
71632 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
71633 +
71634 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
71635 + time_after(curr->expires, get_seconds())) {
71636 + rcu_read_lock();
71637 + cred = __task_cred(task);
71638 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
71639 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
71640 + spin_lock(&gr_uid_lock);
71641 + gr_insert_uid(cred->uid, curr->expires);
71642 + spin_unlock(&gr_uid_lock);
71643 + curr->expires = 0;
71644 + curr->crashes = 0;
71645 + read_lock(&tasklist_lock);
71646 + do_each_thread(tsk2, tsk) {
71647 + cred2 = __task_cred(tsk);
71648 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
71649 + gr_fake_force_sig(SIGKILL, tsk);
71650 + } while_each_thread(tsk2, tsk);
71651 + read_unlock(&tasklist_lock);
71652 + } else {
71653 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
71654 + read_lock(&tasklist_lock);
71655 + read_lock(&grsec_exec_file_lock);
71656 + do_each_thread(tsk2, tsk) {
71657 + if (likely(tsk != task)) {
71658 + // if this thread has the same subject as the one that triggered
71659 + // RES_CRASH and it's the same binary, kill it
71660 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
71661 + gr_fake_force_sig(SIGKILL, tsk);
71662 + }
71663 + } while_each_thread(tsk2, tsk);
71664 + read_unlock(&grsec_exec_file_lock);
71665 + read_unlock(&tasklist_lock);
71666 + }
71667 + rcu_read_unlock();
71668 + }
71669 +
71670 + return;
71671 +}
71672 +
71673 +int
71674 +gr_check_crash_exec(const struct file *filp)
71675 +{
71676 + struct acl_subject_label *curr;
71677 +
71678 + if (unlikely(!gr_acl_is_enabled()))
71679 + return 0;
71680 +
71681 + read_lock(&gr_inode_lock);
71682 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
71683 + __get_dev(filp->f_path.dentry),
71684 + current->role);
71685 + read_unlock(&gr_inode_lock);
71686 +
71687 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
71688 + (!curr->crashes && !curr->expires))
71689 + return 0;
71690 +
71691 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
71692 + time_after(curr->expires, get_seconds()))
71693 + return 1;
71694 + else if (time_before_eq(curr->expires, get_seconds())) {
71695 + curr->crashes = 0;
71696 + curr->expires = 0;
71697 + }
71698 +
71699 + return 0;
71700 +}
71701 +
71702 +void
71703 +gr_handle_alertkill(struct task_struct *task)
71704 +{
71705 + struct acl_subject_label *curracl;
71706 + __u32 curr_ip;
71707 + struct task_struct *p, *p2;
71708 +
71709 + if (unlikely(!gr_acl_is_enabled()))
71710 + return;
71711 +
71712 + curracl = task->acl;
71713 + curr_ip = task->signal->curr_ip;
71714 +
71715 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
71716 + read_lock(&tasklist_lock);
71717 + do_each_thread(p2, p) {
71718 + if (p->signal->curr_ip == curr_ip)
71719 + gr_fake_force_sig(SIGKILL, p);
71720 + } while_each_thread(p2, p);
71721 + read_unlock(&tasklist_lock);
71722 + } else if (curracl->mode & GR_KILLPROC)
71723 + gr_fake_force_sig(SIGKILL, task);
71724 +
71725 + return;
71726 +}
71727 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
71728 new file mode 100644
71729 index 0000000..98011b0
71730 --- /dev/null
71731 +++ b/grsecurity/gracl_shm.c
71732 @@ -0,0 +1,40 @@
71733 +#include <linux/kernel.h>
71734 +#include <linux/mm.h>
71735 +#include <linux/sched.h>
71736 +#include <linux/file.h>
71737 +#include <linux/ipc.h>
71738 +#include <linux/gracl.h>
71739 +#include <linux/grsecurity.h>
71740 +#include <linux/grinternal.h>
71741 +
71742 +int
71743 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
71744 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
71745 +{
71746 + struct task_struct *task;
71747 +
71748 + if (!gr_acl_is_enabled())
71749 + return 1;
71750 +
71751 + rcu_read_lock();
71752 + read_lock(&tasklist_lock);
71753 +
71754 + task = find_task_by_vpid(shm_cprid);
71755 +
71756 + if (unlikely(!task))
71757 + task = find_task_by_vpid(shm_lapid);
71758 +
71759 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
71760 + (task_pid_nr(task) == shm_lapid)) &&
71761 + (task->acl->mode & GR_PROTSHM) &&
71762 + (task->acl != current->acl))) {
71763 + read_unlock(&tasklist_lock);
71764 + rcu_read_unlock();
71765 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
71766 + return 0;
71767 + }
71768 + read_unlock(&tasklist_lock);
71769 + rcu_read_unlock();
71770 +
71771 + return 1;
71772 +}
71773 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
71774 new file mode 100644
71775 index 0000000..bc0be01
71776 --- /dev/null
71777 +++ b/grsecurity/grsec_chdir.c
71778 @@ -0,0 +1,19 @@
71779 +#include <linux/kernel.h>
71780 +#include <linux/sched.h>
71781 +#include <linux/fs.h>
71782 +#include <linux/file.h>
71783 +#include <linux/grsecurity.h>
71784 +#include <linux/grinternal.h>
71785 +
71786 +void
71787 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
71788 +{
71789 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71790 + if ((grsec_enable_chdir && grsec_enable_group &&
71791 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
71792 + !grsec_enable_group)) {
71793 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
71794 + }
71795 +#endif
71796 + return;
71797 +}
71798 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
71799 new file mode 100644
71800 index 0000000..e10b319
71801 --- /dev/null
71802 +++ b/grsecurity/grsec_chroot.c
71803 @@ -0,0 +1,370 @@
71804 +#include <linux/kernel.h>
71805 +#include <linux/module.h>
71806 +#include <linux/sched.h>
71807 +#include <linux/file.h>
71808 +#include <linux/fs.h>
71809 +#include <linux/mount.h>
71810 +#include <linux/types.h>
71811 +#include "../fs/mount.h"
71812 +#include <linux/grsecurity.h>
71813 +#include <linux/grinternal.h>
71814 +
71815 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71816 +int gr_init_ran;
71817 +#endif
71818 +
71819 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
71820 +{
71821 +#ifdef CONFIG_GRKERNSEC
71822 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
71823 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
71824 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71825 + && gr_init_ran
71826 +#endif
71827 + )
71828 + task->gr_is_chrooted = 1;
71829 + else {
71830 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71831 + if (task_pid_nr(task) == 1 && !gr_init_ran)
71832 + gr_init_ran = 1;
71833 +#endif
71834 + task->gr_is_chrooted = 0;
71835 + }
71836 +
71837 + task->gr_chroot_dentry = path->dentry;
71838 +#endif
71839 + return;
71840 +}
71841 +
71842 +void gr_clear_chroot_entries(struct task_struct *task)
71843 +{
71844 +#ifdef CONFIG_GRKERNSEC
71845 + task->gr_is_chrooted = 0;
71846 + task->gr_chroot_dentry = NULL;
71847 +#endif
71848 + return;
71849 +}
71850 +
71851 +int
71852 +gr_handle_chroot_unix(const pid_t pid)
71853 +{
71854 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
71855 + struct task_struct *p;
71856 +
71857 + if (unlikely(!grsec_enable_chroot_unix))
71858 + return 1;
71859 +
71860 + if (likely(!proc_is_chrooted(current)))
71861 + return 1;
71862 +
71863 + rcu_read_lock();
71864 + read_lock(&tasklist_lock);
71865 + p = find_task_by_vpid_unrestricted(pid);
71866 + if (unlikely(p && !have_same_root(current, p))) {
71867 + read_unlock(&tasklist_lock);
71868 + rcu_read_unlock();
71869 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
71870 + return 0;
71871 + }
71872 + read_unlock(&tasklist_lock);
71873 + rcu_read_unlock();
71874 +#endif
71875 + return 1;
71876 +}
71877 +
71878 +int
71879 +gr_handle_chroot_nice(void)
71880 +{
71881 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71882 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
71883 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
71884 + return -EPERM;
71885 + }
71886 +#endif
71887 + return 0;
71888 +}
71889 +
71890 +int
71891 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
71892 +{
71893 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71894 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
71895 + && proc_is_chrooted(current)) {
71896 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
71897 + return -EACCES;
71898 + }
71899 +#endif
71900 + return 0;
71901 +}
71902 +
71903 +int
71904 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
71905 +{
71906 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71907 + struct task_struct *p;
71908 + int ret = 0;
71909 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
71910 + return ret;
71911 +
71912 + read_lock(&tasklist_lock);
71913 + do_each_pid_task(pid, type, p) {
71914 + if (!have_same_root(current, p)) {
71915 + ret = 1;
71916 + goto out;
71917 + }
71918 + } while_each_pid_task(pid, type, p);
71919 +out:
71920 + read_unlock(&tasklist_lock);
71921 + return ret;
71922 +#endif
71923 + return 0;
71924 +}
71925 +
71926 +int
71927 +gr_pid_is_chrooted(struct task_struct *p)
71928 +{
71929 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71930 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
71931 + return 0;
71932 +
71933 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
71934 + !have_same_root(current, p)) {
71935 + return 1;
71936 + }
71937 +#endif
71938 + return 0;
71939 +}
71940 +
71941 +EXPORT_SYMBOL(gr_pid_is_chrooted);
71942 +
71943 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
71944 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
71945 +{
71946 + struct path path, currentroot;
71947 + int ret = 0;
71948 +
71949 + path.dentry = (struct dentry *)u_dentry;
71950 + path.mnt = (struct vfsmount *)u_mnt;
71951 + get_fs_root(current->fs, &currentroot);
71952 + if (path_is_under(&path, &currentroot))
71953 + ret = 1;
71954 + path_put(&currentroot);
71955 +
71956 + return ret;
71957 +}
71958 +#endif
71959 +
71960 +int
71961 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
71962 +{
71963 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
71964 + if (!grsec_enable_chroot_fchdir)
71965 + return 1;
71966 +
71967 + if (!proc_is_chrooted(current))
71968 + return 1;
71969 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
71970 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
71971 + return 0;
71972 + }
71973 +#endif
71974 + return 1;
71975 +}
71976 +
71977 +int
71978 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
71979 + const time_t shm_createtime)
71980 +{
71981 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
71982 + struct task_struct *p;
71983 + time_t starttime;
71984 +
71985 + if (unlikely(!grsec_enable_chroot_shmat))
71986 + return 1;
71987 +
71988 + if (likely(!proc_is_chrooted(current)))
71989 + return 1;
71990 +
71991 + rcu_read_lock();
71992 + read_lock(&tasklist_lock);
71993 +
71994 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
71995 + starttime = p->start_time.tv_sec;
71996 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
71997 + if (have_same_root(current, p)) {
71998 + goto allow;
71999 + } else {
72000 + read_unlock(&tasklist_lock);
72001 + rcu_read_unlock();
72002 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72003 + return 0;
72004 + }
72005 + }
72006 + /* creator exited, pid reuse, fall through to next check */
72007 + }
72008 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
72009 + if (unlikely(!have_same_root(current, p))) {
72010 + read_unlock(&tasklist_lock);
72011 + rcu_read_unlock();
72012 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72013 + return 0;
72014 + }
72015 + }
72016 +
72017 +allow:
72018 + read_unlock(&tasklist_lock);
72019 + rcu_read_unlock();
72020 +#endif
72021 + return 1;
72022 +}
72023 +
72024 +void
72025 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
72026 +{
72027 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
72028 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
72029 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
72030 +#endif
72031 + return;
72032 +}
72033 +
72034 +int
72035 +gr_handle_chroot_mknod(const struct dentry *dentry,
72036 + const struct vfsmount *mnt, const int mode)
72037 +{
72038 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
72039 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
72040 + proc_is_chrooted(current)) {
72041 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
72042 + return -EPERM;
72043 + }
72044 +#endif
72045 + return 0;
72046 +}
72047 +
72048 +int
72049 +gr_handle_chroot_mount(const struct dentry *dentry,
72050 + const struct vfsmount *mnt, const char *dev_name)
72051 +{
72052 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
72053 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
72054 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
72055 + return -EPERM;
72056 + }
72057 +#endif
72058 + return 0;
72059 +}
72060 +
72061 +int
72062 +gr_handle_chroot_pivot(void)
72063 +{
72064 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
72065 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
72066 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
72067 + return -EPERM;
72068 + }
72069 +#endif
72070 + return 0;
72071 +}
72072 +
72073 +int
72074 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
72075 +{
72076 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
72077 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
72078 + !gr_is_outside_chroot(dentry, mnt)) {
72079 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
72080 + return -EPERM;
72081 + }
72082 +#endif
72083 + return 0;
72084 +}
72085 +
72086 +extern const char *captab_log[];
72087 +extern int captab_log_entries;
72088 +
72089 +int
72090 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72091 +{
72092 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72093 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
72094 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
72095 + if (cap_raised(chroot_caps, cap)) {
72096 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
72097 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
72098 + }
72099 + return 0;
72100 + }
72101 + }
72102 +#endif
72103 + return 1;
72104 +}
72105 +
72106 +int
72107 +gr_chroot_is_capable(const int cap)
72108 +{
72109 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72110 + return gr_task_chroot_is_capable(current, current_cred(), cap);
72111 +#endif
72112 + return 1;
72113 +}
72114 +
72115 +int
72116 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
72117 +{
72118 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72119 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
72120 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
72121 + if (cap_raised(chroot_caps, cap)) {
72122 + return 0;
72123 + }
72124 + }
72125 +#endif
72126 + return 1;
72127 +}
72128 +
72129 +int
72130 +gr_chroot_is_capable_nolog(const int cap)
72131 +{
72132 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72133 + return gr_task_chroot_is_capable_nolog(current, cap);
72134 +#endif
72135 + return 1;
72136 +}
72137 +
72138 +int
72139 +gr_handle_chroot_sysctl(const int op)
72140 +{
72141 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
72142 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
72143 + proc_is_chrooted(current))
72144 + return -EACCES;
72145 +#endif
72146 + return 0;
72147 +}
72148 +
72149 +void
72150 +gr_handle_chroot_chdir(const struct path *path)
72151 +{
72152 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
72153 + if (grsec_enable_chroot_chdir)
72154 + set_fs_pwd(current->fs, path);
72155 +#endif
72156 + return;
72157 +}
72158 +
72159 +int
72160 +gr_handle_chroot_chmod(const struct dentry *dentry,
72161 + const struct vfsmount *mnt, const int mode)
72162 +{
72163 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
72164 + /* allow chmod +s on directories, but not files */
72165 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
72166 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
72167 + proc_is_chrooted(current)) {
72168 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
72169 + return -EPERM;
72170 + }
72171 +#endif
72172 + return 0;
72173 +}
72174 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
72175 new file mode 100644
72176 index 0000000..52b3e30
72177 --- /dev/null
72178 +++ b/grsecurity/grsec_disabled.c
72179 @@ -0,0 +1,433 @@
72180 +#include <linux/kernel.h>
72181 +#include <linux/module.h>
72182 +#include <linux/sched.h>
72183 +#include <linux/file.h>
72184 +#include <linux/fs.h>
72185 +#include <linux/kdev_t.h>
72186 +#include <linux/net.h>
72187 +#include <linux/in.h>
72188 +#include <linux/ip.h>
72189 +#include <linux/skbuff.h>
72190 +#include <linux/sysctl.h>
72191 +
72192 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
72193 +void
72194 +pax_set_initial_flags(struct linux_binprm *bprm)
72195 +{
72196 + return;
72197 +}
72198 +#endif
72199 +
72200 +#ifdef CONFIG_SYSCTL
72201 +__u32
72202 +gr_handle_sysctl(const struct ctl_table * table, const int op)
72203 +{
72204 + return 0;
72205 +}
72206 +#endif
72207 +
72208 +#ifdef CONFIG_TASKSTATS
72209 +int gr_is_taskstats_denied(int pid)
72210 +{
72211 + return 0;
72212 +}
72213 +#endif
72214 +
72215 +int
72216 +gr_acl_is_enabled(void)
72217 +{
72218 + return 0;
72219 +}
72220 +
72221 +void
72222 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
72223 +{
72224 + return;
72225 +}
72226 +
72227 +int
72228 +gr_handle_rawio(const struct inode *inode)
72229 +{
72230 + return 0;
72231 +}
72232 +
72233 +void
72234 +gr_acl_handle_psacct(struct task_struct *task, const long code)
72235 +{
72236 + return;
72237 +}
72238 +
72239 +int
72240 +gr_handle_ptrace(struct task_struct *task, const long request)
72241 +{
72242 + return 0;
72243 +}
72244 +
72245 +int
72246 +gr_handle_proc_ptrace(struct task_struct *task)
72247 +{
72248 + return 0;
72249 +}
72250 +
72251 +int
72252 +gr_set_acls(const int type)
72253 +{
72254 + return 0;
72255 +}
72256 +
72257 +int
72258 +gr_check_hidden_task(const struct task_struct *tsk)
72259 +{
72260 + return 0;
72261 +}
72262 +
72263 +int
72264 +gr_check_protected_task(const struct task_struct *task)
72265 +{
72266 + return 0;
72267 +}
72268 +
72269 +int
72270 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
72271 +{
72272 + return 0;
72273 +}
72274 +
72275 +void
72276 +gr_copy_label(struct task_struct *tsk)
72277 +{
72278 + return;
72279 +}
72280 +
72281 +void
72282 +gr_set_pax_flags(struct task_struct *task)
72283 +{
72284 + return;
72285 +}
72286 +
72287 +int
72288 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
72289 + const int unsafe_share)
72290 +{
72291 + return 0;
72292 +}
72293 +
72294 +void
72295 +gr_handle_delete(const ino_t ino, const dev_t dev)
72296 +{
72297 + return;
72298 +}
72299 +
72300 +void
72301 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
72302 +{
72303 + return;
72304 +}
72305 +
72306 +void
72307 +gr_handle_crash(struct task_struct *task, const int sig)
72308 +{
72309 + return;
72310 +}
72311 +
72312 +int
72313 +gr_check_crash_exec(const struct file *filp)
72314 +{
72315 + return 0;
72316 +}
72317 +
72318 +int
72319 +gr_check_crash_uid(const kuid_t uid)
72320 +{
72321 + return 0;
72322 +}
72323 +
72324 +void
72325 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
72326 + struct dentry *old_dentry,
72327 + struct dentry *new_dentry,
72328 + struct vfsmount *mnt, const __u8 replace)
72329 +{
72330 + return;
72331 +}
72332 +
72333 +int
72334 +gr_search_socket(const int family, const int type, const int protocol)
72335 +{
72336 + return 1;
72337 +}
72338 +
72339 +int
72340 +gr_search_connectbind(const int mode, const struct socket *sock,
72341 + const struct sockaddr_in *addr)
72342 +{
72343 + return 0;
72344 +}
72345 +
72346 +void
72347 +gr_handle_alertkill(struct task_struct *task)
72348 +{
72349 + return;
72350 +}
72351 +
72352 +__u32
72353 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
72354 +{
72355 + return 1;
72356 +}
72357 +
72358 +__u32
72359 +gr_acl_handle_hidden_file(const struct dentry * dentry,
72360 + const struct vfsmount * mnt)
72361 +{
72362 + return 1;
72363 +}
72364 +
72365 +__u32
72366 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72367 + int acc_mode)
72368 +{
72369 + return 1;
72370 +}
72371 +
72372 +__u32
72373 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72374 +{
72375 + return 1;
72376 +}
72377 +
72378 +__u32
72379 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
72380 +{
72381 + return 1;
72382 +}
72383 +
72384 +int
72385 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
72386 + unsigned int *vm_flags)
72387 +{
72388 + return 1;
72389 +}
72390 +
72391 +__u32
72392 +gr_acl_handle_truncate(const struct dentry * dentry,
72393 + const struct vfsmount * mnt)
72394 +{
72395 + return 1;
72396 +}
72397 +
72398 +__u32
72399 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
72400 +{
72401 + return 1;
72402 +}
72403 +
72404 +__u32
72405 +gr_acl_handle_access(const struct dentry * dentry,
72406 + const struct vfsmount * mnt, const int fmode)
72407 +{
72408 + return 1;
72409 +}
72410 +
72411 +__u32
72412 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
72413 + umode_t *mode)
72414 +{
72415 + return 1;
72416 +}
72417 +
72418 +__u32
72419 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
72420 +{
72421 + return 1;
72422 +}
72423 +
72424 +__u32
72425 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
72426 +{
72427 + return 1;
72428 +}
72429 +
72430 +__u32
72431 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
72432 +{
72433 + return 1;
72434 +}
72435 +
72436 +void
72437 +grsecurity_init(void)
72438 +{
72439 + return;
72440 +}
72441 +
72442 +umode_t gr_acl_umask(void)
72443 +{
72444 + return 0;
72445 +}
72446 +
72447 +__u32
72448 +gr_acl_handle_mknod(const struct dentry * new_dentry,
72449 + const struct dentry * parent_dentry,
72450 + const struct vfsmount * parent_mnt,
72451 + const int mode)
72452 +{
72453 + return 1;
72454 +}
72455 +
72456 +__u32
72457 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
72458 + const struct dentry * parent_dentry,
72459 + const struct vfsmount * parent_mnt)
72460 +{
72461 + return 1;
72462 +}
72463 +
72464 +__u32
72465 +gr_acl_handle_symlink(const struct dentry * new_dentry,
72466 + const struct dentry * parent_dentry,
72467 + const struct vfsmount * parent_mnt, const struct filename *from)
72468 +{
72469 + return 1;
72470 +}
72471 +
72472 +__u32
72473 +gr_acl_handle_link(const struct dentry * new_dentry,
72474 + const struct dentry * parent_dentry,
72475 + const struct vfsmount * parent_mnt,
72476 + const struct dentry * old_dentry,
72477 + const struct vfsmount * old_mnt, const struct filename *to)
72478 +{
72479 + return 1;
72480 +}
72481 +
72482 +int
72483 +gr_acl_handle_rename(const struct dentry *new_dentry,
72484 + const struct dentry *parent_dentry,
72485 + const struct vfsmount *parent_mnt,
72486 + const struct dentry *old_dentry,
72487 + const struct inode *old_parent_inode,
72488 + const struct vfsmount *old_mnt, const struct filename *newname)
72489 +{
72490 + return 0;
72491 +}
72492 +
72493 +int
72494 +gr_acl_handle_filldir(const struct file *file, const char *name,
72495 + const int namelen, const ino_t ino)
72496 +{
72497 + return 1;
72498 +}
72499 +
72500 +int
72501 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72502 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
72503 +{
72504 + return 1;
72505 +}
72506 +
72507 +int
72508 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
72509 +{
72510 + return 0;
72511 +}
72512 +
72513 +int
72514 +gr_search_accept(const struct socket *sock)
72515 +{
72516 + return 0;
72517 +}
72518 +
72519 +int
72520 +gr_search_listen(const struct socket *sock)
72521 +{
72522 + return 0;
72523 +}
72524 +
72525 +int
72526 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
72527 +{
72528 + return 0;
72529 +}
72530 +
72531 +__u32
72532 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
72533 +{
72534 + return 1;
72535 +}
72536 +
72537 +__u32
72538 +gr_acl_handle_creat(const struct dentry * dentry,
72539 + const struct dentry * p_dentry,
72540 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72541 + const int imode)
72542 +{
72543 + return 1;
72544 +}
72545 +
72546 +void
72547 +gr_acl_handle_exit(void)
72548 +{
72549 + return;
72550 +}
72551 +
72552 +int
72553 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72554 +{
72555 + return 1;
72556 +}
72557 +
72558 +void
72559 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
72560 +{
72561 + return;
72562 +}
72563 +
72564 +int
72565 +gr_acl_handle_procpidmem(const struct task_struct *task)
72566 +{
72567 + return 0;
72568 +}
72569 +
72570 +int
72571 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
72572 +{
72573 + return 0;
72574 +}
72575 +
72576 +int
72577 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
72578 +{
72579 + return 0;
72580 +}
72581 +
72582 +int
72583 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
72584 +{
72585 + return 0;
72586 +}
72587 +
72588 +int
72589 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
72590 +{
72591 + return 0;
72592 +}
72593 +
72594 +int gr_acl_enable_at_secure(void)
72595 +{
72596 + return 0;
72597 +}
72598 +
72599 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
72600 +{
72601 + return dentry->d_sb->s_dev;
72602 +}
72603 +
72604 +void gr_put_exec_file(struct task_struct *task)
72605 +{
72606 + return;
72607 +}
72608 +
72609 +#ifdef CONFIG_SECURITY
72610 +EXPORT_SYMBOL(gr_check_user_change);
72611 +EXPORT_SYMBOL(gr_check_group_change);
72612 +#endif
72613 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
72614 new file mode 100644
72615 index 0000000..387032b
72616 --- /dev/null
72617 +++ b/grsecurity/grsec_exec.c
72618 @@ -0,0 +1,187 @@
72619 +#include <linux/kernel.h>
72620 +#include <linux/sched.h>
72621 +#include <linux/file.h>
72622 +#include <linux/binfmts.h>
72623 +#include <linux/fs.h>
72624 +#include <linux/types.h>
72625 +#include <linux/grdefs.h>
72626 +#include <linux/grsecurity.h>
72627 +#include <linux/grinternal.h>
72628 +#include <linux/capability.h>
72629 +#include <linux/module.h>
72630 +#include <linux/compat.h>
72631 +
72632 +#include <asm/uaccess.h>
72633 +
72634 +#ifdef CONFIG_GRKERNSEC_EXECLOG
72635 +static char gr_exec_arg_buf[132];
72636 +static DEFINE_MUTEX(gr_exec_arg_mutex);
72637 +#endif
72638 +
72639 +struct user_arg_ptr {
72640 +#ifdef CONFIG_COMPAT
72641 + bool is_compat;
72642 +#endif
72643 + union {
72644 + const char __user *const __user *native;
72645 +#ifdef CONFIG_COMPAT
72646 + const compat_uptr_t __user *compat;
72647 +#endif
72648 + } ptr;
72649 +};
72650 +
72651 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
72652 +
72653 +void
72654 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
72655 +{
72656 +#ifdef CONFIG_GRKERNSEC_EXECLOG
72657 + char *grarg = gr_exec_arg_buf;
72658 + unsigned int i, x, execlen = 0;
72659 + char c;
72660 +
72661 + if (!((grsec_enable_execlog && grsec_enable_group &&
72662 + in_group_p(grsec_audit_gid))
72663 + || (grsec_enable_execlog && !grsec_enable_group)))
72664 + return;
72665 +
72666 + mutex_lock(&gr_exec_arg_mutex);
72667 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
72668 +
72669 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
72670 + const char __user *p;
72671 + unsigned int len;
72672 +
72673 + p = get_user_arg_ptr(argv, i);
72674 + if (IS_ERR(p))
72675 + goto log;
72676 +
72677 + len = strnlen_user(p, 128 - execlen);
72678 + if (len > 128 - execlen)
72679 + len = 128 - execlen;
72680 + else if (len > 0)
72681 + len--;
72682 + if (copy_from_user(grarg + execlen, p, len))
72683 + goto log;
72684 +
72685 + /* rewrite unprintable characters */
72686 + for (x = 0; x < len; x++) {
72687 + c = *(grarg + execlen + x);
72688 + if (c < 32 || c > 126)
72689 + *(grarg + execlen + x) = ' ';
72690 + }
72691 +
72692 + execlen += len;
72693 + *(grarg + execlen) = ' ';
72694 + *(grarg + execlen + 1) = '\0';
72695 + execlen++;
72696 + }
72697 +
72698 + log:
72699 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
72700 + bprm->file->f_path.mnt, grarg);
72701 + mutex_unlock(&gr_exec_arg_mutex);
72702 +#endif
72703 + return;
72704 +}
72705 +
72706 +#ifdef CONFIG_GRKERNSEC
72707 +extern int gr_acl_is_capable(const int cap);
72708 +extern int gr_acl_is_capable_nolog(const int cap);
72709 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
72710 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
72711 +extern int gr_chroot_is_capable(const int cap);
72712 +extern int gr_chroot_is_capable_nolog(const int cap);
72713 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
72714 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
72715 +#endif
72716 +
72717 +const char *captab_log[] = {
72718 + "CAP_CHOWN",
72719 + "CAP_DAC_OVERRIDE",
72720 + "CAP_DAC_READ_SEARCH",
72721 + "CAP_FOWNER",
72722 + "CAP_FSETID",
72723 + "CAP_KILL",
72724 + "CAP_SETGID",
72725 + "CAP_SETUID",
72726 + "CAP_SETPCAP",
72727 + "CAP_LINUX_IMMUTABLE",
72728 + "CAP_NET_BIND_SERVICE",
72729 + "CAP_NET_BROADCAST",
72730 + "CAP_NET_ADMIN",
72731 + "CAP_NET_RAW",
72732 + "CAP_IPC_LOCK",
72733 + "CAP_IPC_OWNER",
72734 + "CAP_SYS_MODULE",
72735 + "CAP_SYS_RAWIO",
72736 + "CAP_SYS_CHROOT",
72737 + "CAP_SYS_PTRACE",
72738 + "CAP_SYS_PACCT",
72739 + "CAP_SYS_ADMIN",
72740 + "CAP_SYS_BOOT",
72741 + "CAP_SYS_NICE",
72742 + "CAP_SYS_RESOURCE",
72743 + "CAP_SYS_TIME",
72744 + "CAP_SYS_TTY_CONFIG",
72745 + "CAP_MKNOD",
72746 + "CAP_LEASE",
72747 + "CAP_AUDIT_WRITE",
72748 + "CAP_AUDIT_CONTROL",
72749 + "CAP_SETFCAP",
72750 + "CAP_MAC_OVERRIDE",
72751 + "CAP_MAC_ADMIN",
72752 + "CAP_SYSLOG",
72753 + "CAP_WAKE_ALARM"
72754 +};
72755 +
72756 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
72757 +
72758 +int gr_is_capable(const int cap)
72759 +{
72760 +#ifdef CONFIG_GRKERNSEC
72761 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
72762 + return 1;
72763 + return 0;
72764 +#else
72765 + return 1;
72766 +#endif
72767 +}
72768 +
72769 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72770 +{
72771 +#ifdef CONFIG_GRKERNSEC
72772 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
72773 + return 1;
72774 + return 0;
72775 +#else
72776 + return 1;
72777 +#endif
72778 +}
72779 +
72780 +int gr_is_capable_nolog(const int cap)
72781 +{
72782 +#ifdef CONFIG_GRKERNSEC
72783 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
72784 + return 1;
72785 + return 0;
72786 +#else
72787 + return 1;
72788 +#endif
72789 +}
72790 +
72791 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
72792 +{
72793 +#ifdef CONFIG_GRKERNSEC
72794 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
72795 + return 1;
72796 + return 0;
72797 +#else
72798 + return 1;
72799 +#endif
72800 +}
72801 +
72802 +EXPORT_SYMBOL(gr_is_capable);
72803 +EXPORT_SYMBOL(gr_is_capable_nolog);
72804 +EXPORT_SYMBOL(gr_task_is_capable);
72805 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
72806 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
72807 new file mode 100644
72808 index 0000000..06cc6ea
72809 --- /dev/null
72810 +++ b/grsecurity/grsec_fifo.c
72811 @@ -0,0 +1,24 @@
72812 +#include <linux/kernel.h>
72813 +#include <linux/sched.h>
72814 +#include <linux/fs.h>
72815 +#include <linux/file.h>
72816 +#include <linux/grinternal.h>
72817 +
72818 +int
72819 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
72820 + const struct dentry *dir, const int flag, const int acc_mode)
72821 +{
72822 +#ifdef CONFIG_GRKERNSEC_FIFO
72823 + const struct cred *cred = current_cred();
72824 +
72825 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
72826 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
72827 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
72828 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
72829 + if (!inode_permission(dentry->d_inode, acc_mode))
72830 + 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));
72831 + return -EACCES;
72832 + }
72833 +#endif
72834 + return 0;
72835 +}
72836 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
72837 new file mode 100644
72838 index 0000000..8ca18bf
72839 --- /dev/null
72840 +++ b/grsecurity/grsec_fork.c
72841 @@ -0,0 +1,23 @@
72842 +#include <linux/kernel.h>
72843 +#include <linux/sched.h>
72844 +#include <linux/grsecurity.h>
72845 +#include <linux/grinternal.h>
72846 +#include <linux/errno.h>
72847 +
72848 +void
72849 +gr_log_forkfail(const int retval)
72850 +{
72851 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
72852 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
72853 + switch (retval) {
72854 + case -EAGAIN:
72855 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
72856 + break;
72857 + case -ENOMEM:
72858 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
72859 + break;
72860 + }
72861 + }
72862 +#endif
72863 + return;
72864 +}
72865 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
72866 new file mode 100644
72867 index 0000000..a88e901
72868 --- /dev/null
72869 +++ b/grsecurity/grsec_init.c
72870 @@ -0,0 +1,272 @@
72871 +#include <linux/kernel.h>
72872 +#include <linux/sched.h>
72873 +#include <linux/mm.h>
72874 +#include <linux/gracl.h>
72875 +#include <linux/slab.h>
72876 +#include <linux/vmalloc.h>
72877 +#include <linux/percpu.h>
72878 +#include <linux/module.h>
72879 +
72880 +int grsec_enable_ptrace_readexec;
72881 +int grsec_enable_setxid;
72882 +int grsec_enable_symlinkown;
72883 +kgid_t grsec_symlinkown_gid;
72884 +int grsec_enable_brute;
72885 +int grsec_enable_link;
72886 +int grsec_enable_dmesg;
72887 +int grsec_enable_harden_ptrace;
72888 +int grsec_enable_harden_ipc;
72889 +int grsec_enable_fifo;
72890 +int grsec_enable_execlog;
72891 +int grsec_enable_signal;
72892 +int grsec_enable_forkfail;
72893 +int grsec_enable_audit_ptrace;
72894 +int grsec_enable_time;
72895 +int grsec_enable_group;
72896 +kgid_t grsec_audit_gid;
72897 +int grsec_enable_chdir;
72898 +int grsec_enable_mount;
72899 +int grsec_enable_rofs;
72900 +int grsec_deny_new_usb;
72901 +int grsec_enable_chroot_findtask;
72902 +int grsec_enable_chroot_mount;
72903 +int grsec_enable_chroot_shmat;
72904 +int grsec_enable_chroot_fchdir;
72905 +int grsec_enable_chroot_double;
72906 +int grsec_enable_chroot_pivot;
72907 +int grsec_enable_chroot_chdir;
72908 +int grsec_enable_chroot_chmod;
72909 +int grsec_enable_chroot_mknod;
72910 +int grsec_enable_chroot_nice;
72911 +int grsec_enable_chroot_execlog;
72912 +int grsec_enable_chroot_caps;
72913 +int grsec_enable_chroot_sysctl;
72914 +int grsec_enable_chroot_unix;
72915 +int grsec_enable_tpe;
72916 +kgid_t grsec_tpe_gid;
72917 +int grsec_enable_blackhole;
72918 +#ifdef CONFIG_IPV6_MODULE
72919 +EXPORT_SYMBOL(grsec_enable_blackhole);
72920 +#endif
72921 +int grsec_lastack_retries;
72922 +int grsec_enable_tpe_all;
72923 +int grsec_enable_tpe_invert;
72924 +int grsec_enable_socket_all;
72925 +kgid_t grsec_socket_all_gid;
72926 +int grsec_enable_socket_client;
72927 +kgid_t grsec_socket_client_gid;
72928 +int grsec_enable_socket_server;
72929 +kgid_t grsec_socket_server_gid;
72930 +int grsec_resource_logging;
72931 +int grsec_disable_privio;
72932 +int grsec_enable_log_rwxmaps;
72933 +int grsec_lock;
72934 +
72935 +DEFINE_SPINLOCK(grsec_alert_lock);
72936 +unsigned long grsec_alert_wtime = 0;
72937 +unsigned long grsec_alert_fyet = 0;
72938 +
72939 +DEFINE_SPINLOCK(grsec_audit_lock);
72940 +
72941 +DEFINE_RWLOCK(grsec_exec_file_lock);
72942 +
72943 +char *gr_shared_page[4];
72944 +
72945 +char *gr_alert_log_fmt;
72946 +char *gr_audit_log_fmt;
72947 +char *gr_alert_log_buf;
72948 +char *gr_audit_log_buf;
72949 +
72950 +void __init
72951 +grsecurity_init(void)
72952 +{
72953 + int j;
72954 + /* create the per-cpu shared pages */
72955 +
72956 +#ifdef CONFIG_X86
72957 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
72958 +#endif
72959 +
72960 + for (j = 0; j < 4; j++) {
72961 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
72962 + if (gr_shared_page[j] == NULL) {
72963 + panic("Unable to allocate grsecurity shared page");
72964 + return;
72965 + }
72966 + }
72967 +
72968 + /* allocate log buffers */
72969 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
72970 + if (!gr_alert_log_fmt) {
72971 + panic("Unable to allocate grsecurity alert log format buffer");
72972 + return;
72973 + }
72974 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
72975 + if (!gr_audit_log_fmt) {
72976 + panic("Unable to allocate grsecurity audit log format buffer");
72977 + return;
72978 + }
72979 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
72980 + if (!gr_alert_log_buf) {
72981 + panic("Unable to allocate grsecurity alert log buffer");
72982 + return;
72983 + }
72984 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
72985 + if (!gr_audit_log_buf) {
72986 + panic("Unable to allocate grsecurity audit log buffer");
72987 + return;
72988 + }
72989 +
72990 +#ifdef CONFIG_GRKERNSEC_IO
72991 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
72992 + grsec_disable_privio = 1;
72993 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
72994 + grsec_disable_privio = 1;
72995 +#else
72996 + grsec_disable_privio = 0;
72997 +#endif
72998 +#endif
72999 +
73000 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
73001 + /* for backward compatibility, tpe_invert always defaults to on if
73002 + enabled in the kernel
73003 + */
73004 + grsec_enable_tpe_invert = 1;
73005 +#endif
73006 +
73007 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
73008 +#ifndef CONFIG_GRKERNSEC_SYSCTL
73009 + grsec_lock = 1;
73010 +#endif
73011 +
73012 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73013 + grsec_enable_log_rwxmaps = 1;
73014 +#endif
73015 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
73016 + grsec_enable_group = 1;
73017 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
73018 +#endif
73019 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
73020 + grsec_enable_ptrace_readexec = 1;
73021 +#endif
73022 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73023 + grsec_enable_chdir = 1;
73024 +#endif
73025 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
73026 + grsec_enable_harden_ptrace = 1;
73027 +#endif
73028 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
73029 + grsec_enable_harden_ipc = 1;
73030 +#endif
73031 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73032 + grsec_enable_mount = 1;
73033 +#endif
73034 +#ifdef CONFIG_GRKERNSEC_LINK
73035 + grsec_enable_link = 1;
73036 +#endif
73037 +#ifdef CONFIG_GRKERNSEC_BRUTE
73038 + grsec_enable_brute = 1;
73039 +#endif
73040 +#ifdef CONFIG_GRKERNSEC_DMESG
73041 + grsec_enable_dmesg = 1;
73042 +#endif
73043 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73044 + grsec_enable_blackhole = 1;
73045 + grsec_lastack_retries = 4;
73046 +#endif
73047 +#ifdef CONFIG_GRKERNSEC_FIFO
73048 + grsec_enable_fifo = 1;
73049 +#endif
73050 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73051 + grsec_enable_execlog = 1;
73052 +#endif
73053 +#ifdef CONFIG_GRKERNSEC_SETXID
73054 + grsec_enable_setxid = 1;
73055 +#endif
73056 +#ifdef CONFIG_GRKERNSEC_SIGNAL
73057 + grsec_enable_signal = 1;
73058 +#endif
73059 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
73060 + grsec_enable_forkfail = 1;
73061 +#endif
73062 +#ifdef CONFIG_GRKERNSEC_TIME
73063 + grsec_enable_time = 1;
73064 +#endif
73065 +#ifdef CONFIG_GRKERNSEC_RESLOG
73066 + grsec_resource_logging = 1;
73067 +#endif
73068 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73069 + grsec_enable_chroot_findtask = 1;
73070 +#endif
73071 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73072 + grsec_enable_chroot_unix = 1;
73073 +#endif
73074 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73075 + grsec_enable_chroot_mount = 1;
73076 +#endif
73077 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73078 + grsec_enable_chroot_fchdir = 1;
73079 +#endif
73080 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73081 + grsec_enable_chroot_shmat = 1;
73082 +#endif
73083 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
73084 + grsec_enable_audit_ptrace = 1;
73085 +#endif
73086 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73087 + grsec_enable_chroot_double = 1;
73088 +#endif
73089 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73090 + grsec_enable_chroot_pivot = 1;
73091 +#endif
73092 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73093 + grsec_enable_chroot_chdir = 1;
73094 +#endif
73095 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73096 + grsec_enable_chroot_chmod = 1;
73097 +#endif
73098 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73099 + grsec_enable_chroot_mknod = 1;
73100 +#endif
73101 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73102 + grsec_enable_chroot_nice = 1;
73103 +#endif
73104 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73105 + grsec_enable_chroot_execlog = 1;
73106 +#endif
73107 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73108 + grsec_enable_chroot_caps = 1;
73109 +#endif
73110 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73111 + grsec_enable_chroot_sysctl = 1;
73112 +#endif
73113 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
73114 + grsec_enable_symlinkown = 1;
73115 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
73116 +#endif
73117 +#ifdef CONFIG_GRKERNSEC_TPE
73118 + grsec_enable_tpe = 1;
73119 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
73120 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
73121 + grsec_enable_tpe_all = 1;
73122 +#endif
73123 +#endif
73124 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
73125 + grsec_enable_socket_all = 1;
73126 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
73127 +#endif
73128 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
73129 + grsec_enable_socket_client = 1;
73130 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
73131 +#endif
73132 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
73133 + grsec_enable_socket_server = 1;
73134 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
73135 +#endif
73136 +#endif
73137 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
73138 + grsec_deny_new_usb = 1;
73139 +#endif
73140 +
73141 + return;
73142 +}
73143 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
73144 new file mode 100644
73145 index 0000000..78d1680
73146 --- /dev/null
73147 +++ b/grsecurity/grsec_ipc.c
73148 @@ -0,0 +1,48 @@
73149 +#include <linux/kernel.h>
73150 +#include <linux/mm.h>
73151 +#include <linux/sched.h>
73152 +#include <linux/file.h>
73153 +#include <linux/ipc.h>
73154 +#include <linux/ipc_namespace.h>
73155 +#include <linux/grsecurity.h>
73156 +#include <linux/grinternal.h>
73157 +
73158 +int
73159 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
73160 +{
73161 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
73162 + int write;
73163 + int orig_granted_mode;
73164 + kuid_t euid;
73165 + kgid_t egid;
73166 +
73167 + if (!grsec_enable_harden_ipc)
73168 + return 0;
73169 +
73170 + euid = current_euid();
73171 + egid = current_egid();
73172 +
73173 + write = requested_mode & 00002;
73174 + orig_granted_mode = ipcp->mode;
73175 +
73176 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
73177 + orig_granted_mode >>= 6;
73178 + else {
73179 + /* if likely wrong permissions, lock to user */
73180 + if (orig_granted_mode & 0007)
73181 + orig_granted_mode = 0;
73182 + /* otherwise do a egid-only check */
73183 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
73184 + orig_granted_mode >>= 3;
73185 + /* otherwise, no access */
73186 + else
73187 + orig_granted_mode = 0;
73188 + }
73189 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
73190 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
73191 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
73192 + return 0;
73193 + }
73194 +#endif
73195 + return 1;
73196 +}
73197 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
73198 new file mode 100644
73199 index 0000000..5e05e20
73200 --- /dev/null
73201 +++ b/grsecurity/grsec_link.c
73202 @@ -0,0 +1,58 @@
73203 +#include <linux/kernel.h>
73204 +#include <linux/sched.h>
73205 +#include <linux/fs.h>
73206 +#include <linux/file.h>
73207 +#include <linux/grinternal.h>
73208 +
73209 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
73210 +{
73211 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
73212 + const struct inode *link_inode = link->dentry->d_inode;
73213 +
73214 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
73215 + /* ignore root-owned links, e.g. /proc/self */
73216 + gr_is_global_nonroot(link_inode->i_uid) && target &&
73217 + !uid_eq(link_inode->i_uid, target->i_uid)) {
73218 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
73219 + return 1;
73220 + }
73221 +#endif
73222 + return 0;
73223 +}
73224 +
73225 +int
73226 +gr_handle_follow_link(const struct inode *parent,
73227 + const struct inode *inode,
73228 + const struct dentry *dentry, const struct vfsmount *mnt)
73229 +{
73230 +#ifdef CONFIG_GRKERNSEC_LINK
73231 + const struct cred *cred = current_cred();
73232 +
73233 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
73234 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
73235 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
73236 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
73237 + return -EACCES;
73238 + }
73239 +#endif
73240 + return 0;
73241 +}
73242 +
73243 +int
73244 +gr_handle_hardlink(const struct dentry *dentry,
73245 + const struct vfsmount *mnt,
73246 + struct inode *inode, const int mode, const struct filename *to)
73247 +{
73248 +#ifdef CONFIG_GRKERNSEC_LINK
73249 + const struct cred *cred = current_cred();
73250 +
73251 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
73252 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
73253 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
73254 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
73255 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
73256 + return -EPERM;
73257 + }
73258 +#endif
73259 + return 0;
73260 +}
73261 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
73262 new file mode 100644
73263 index 0000000..dbe0a6b
73264 --- /dev/null
73265 +++ b/grsecurity/grsec_log.c
73266 @@ -0,0 +1,341 @@
73267 +#include <linux/kernel.h>
73268 +#include <linux/sched.h>
73269 +#include <linux/file.h>
73270 +#include <linux/tty.h>
73271 +#include <linux/fs.h>
73272 +#include <linux/mm.h>
73273 +#include <linux/grinternal.h>
73274 +
73275 +#ifdef CONFIG_TREE_PREEMPT_RCU
73276 +#define DISABLE_PREEMPT() preempt_disable()
73277 +#define ENABLE_PREEMPT() preempt_enable()
73278 +#else
73279 +#define DISABLE_PREEMPT()
73280 +#define ENABLE_PREEMPT()
73281 +#endif
73282 +
73283 +#define BEGIN_LOCKS(x) \
73284 + DISABLE_PREEMPT(); \
73285 + rcu_read_lock(); \
73286 + read_lock(&tasklist_lock); \
73287 + read_lock(&grsec_exec_file_lock); \
73288 + if (x != GR_DO_AUDIT) \
73289 + spin_lock(&grsec_alert_lock); \
73290 + else \
73291 + spin_lock(&grsec_audit_lock)
73292 +
73293 +#define END_LOCKS(x) \
73294 + if (x != GR_DO_AUDIT) \
73295 + spin_unlock(&grsec_alert_lock); \
73296 + else \
73297 + spin_unlock(&grsec_audit_lock); \
73298 + read_unlock(&grsec_exec_file_lock); \
73299 + read_unlock(&tasklist_lock); \
73300 + rcu_read_unlock(); \
73301 + ENABLE_PREEMPT(); \
73302 + if (x == GR_DONT_AUDIT) \
73303 + gr_handle_alertkill(current)
73304 +
73305 +enum {
73306 + FLOODING,
73307 + NO_FLOODING
73308 +};
73309 +
73310 +extern char *gr_alert_log_fmt;
73311 +extern char *gr_audit_log_fmt;
73312 +extern char *gr_alert_log_buf;
73313 +extern char *gr_audit_log_buf;
73314 +
73315 +static int gr_log_start(int audit)
73316 +{
73317 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
73318 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
73319 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73320 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
73321 + unsigned long curr_secs = get_seconds();
73322 +
73323 + if (audit == GR_DO_AUDIT)
73324 + goto set_fmt;
73325 +
73326 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
73327 + grsec_alert_wtime = curr_secs;
73328 + grsec_alert_fyet = 0;
73329 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
73330 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
73331 + grsec_alert_fyet++;
73332 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
73333 + grsec_alert_wtime = curr_secs;
73334 + grsec_alert_fyet++;
73335 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
73336 + return FLOODING;
73337 + }
73338 + else return FLOODING;
73339 +
73340 +set_fmt:
73341 +#endif
73342 + memset(buf, 0, PAGE_SIZE);
73343 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
73344 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
73345 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
73346 + } else if (current->signal->curr_ip) {
73347 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
73348 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
73349 + } else if (gr_acl_is_enabled()) {
73350 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
73351 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
73352 + } else {
73353 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
73354 + strcpy(buf, fmt);
73355 + }
73356 +
73357 + return NO_FLOODING;
73358 +}
73359 +
73360 +static void gr_log_middle(int audit, const char *msg, va_list ap)
73361 + __attribute__ ((format (printf, 2, 0)));
73362 +
73363 +static void gr_log_middle(int audit, const char *msg, va_list ap)
73364 +{
73365 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73366 + unsigned int len = strlen(buf);
73367 +
73368 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
73369 +
73370 + return;
73371 +}
73372 +
73373 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
73374 + __attribute__ ((format (printf, 2, 3)));
73375 +
73376 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
73377 +{
73378 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73379 + unsigned int len = strlen(buf);
73380 + va_list ap;
73381 +
73382 + va_start(ap, msg);
73383 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
73384 + va_end(ap);
73385 +
73386 + return;
73387 +}
73388 +
73389 +static void gr_log_end(int audit, int append_default)
73390 +{
73391 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73392 + if (append_default) {
73393 + struct task_struct *task = current;
73394 + struct task_struct *parent = task->real_parent;
73395 + const struct cred *cred = __task_cred(task);
73396 + const struct cred *pcred = __task_cred(parent);
73397 + unsigned int len = strlen(buf);
73398 +
73399 + 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));
73400 + }
73401 +
73402 + printk("%s\n", buf);
73403 +
73404 + return;
73405 +}
73406 +
73407 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
73408 +{
73409 + int logtype;
73410 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
73411 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
73412 + void *voidptr = NULL;
73413 + int num1 = 0, num2 = 0;
73414 + unsigned long ulong1 = 0, ulong2 = 0;
73415 + struct dentry *dentry = NULL;
73416 + struct vfsmount *mnt = NULL;
73417 + struct file *file = NULL;
73418 + struct task_struct *task = NULL;
73419 + struct vm_area_struct *vma = NULL;
73420 + const struct cred *cred, *pcred;
73421 + va_list ap;
73422 +
73423 + BEGIN_LOCKS(audit);
73424 + logtype = gr_log_start(audit);
73425 + if (logtype == FLOODING) {
73426 + END_LOCKS(audit);
73427 + return;
73428 + }
73429 + va_start(ap, argtypes);
73430 + switch (argtypes) {
73431 + case GR_TTYSNIFF:
73432 + task = va_arg(ap, struct task_struct *);
73433 + 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));
73434 + break;
73435 + case GR_SYSCTL_HIDDEN:
73436 + str1 = va_arg(ap, char *);
73437 + gr_log_middle_varargs(audit, msg, result, str1);
73438 + break;
73439 + case GR_RBAC:
73440 + dentry = va_arg(ap, struct dentry *);
73441 + mnt = va_arg(ap, struct vfsmount *);
73442 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
73443 + break;
73444 + case GR_RBAC_STR:
73445 + dentry = va_arg(ap, struct dentry *);
73446 + mnt = va_arg(ap, struct vfsmount *);
73447 + str1 = va_arg(ap, char *);
73448 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
73449 + break;
73450 + case GR_STR_RBAC:
73451 + str1 = va_arg(ap, char *);
73452 + dentry = va_arg(ap, struct dentry *);
73453 + mnt = va_arg(ap, struct vfsmount *);
73454 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
73455 + break;
73456 + case GR_RBAC_MODE2:
73457 + dentry = va_arg(ap, struct dentry *);
73458 + mnt = va_arg(ap, struct vfsmount *);
73459 + str1 = va_arg(ap, char *);
73460 + str2 = va_arg(ap, char *);
73461 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
73462 + break;
73463 + case GR_RBAC_MODE3:
73464 + dentry = va_arg(ap, struct dentry *);
73465 + mnt = va_arg(ap, struct vfsmount *);
73466 + str1 = va_arg(ap, char *);
73467 + str2 = va_arg(ap, char *);
73468 + str3 = va_arg(ap, char *);
73469 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
73470 + break;
73471 + case GR_FILENAME:
73472 + dentry = va_arg(ap, struct dentry *);
73473 + mnt = va_arg(ap, struct vfsmount *);
73474 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
73475 + break;
73476 + case GR_STR_FILENAME:
73477 + str1 = va_arg(ap, char *);
73478 + dentry = va_arg(ap, struct dentry *);
73479 + mnt = va_arg(ap, struct vfsmount *);
73480 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
73481 + break;
73482 + case GR_FILENAME_STR:
73483 + dentry = va_arg(ap, struct dentry *);
73484 + mnt = va_arg(ap, struct vfsmount *);
73485 + str1 = va_arg(ap, char *);
73486 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
73487 + break;
73488 + case GR_FILENAME_TWO_INT:
73489 + dentry = va_arg(ap, struct dentry *);
73490 + mnt = va_arg(ap, struct vfsmount *);
73491 + num1 = va_arg(ap, int);
73492 + num2 = va_arg(ap, int);
73493 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
73494 + break;
73495 + case GR_FILENAME_TWO_INT_STR:
73496 + dentry = va_arg(ap, struct dentry *);
73497 + mnt = va_arg(ap, struct vfsmount *);
73498 + num1 = va_arg(ap, int);
73499 + num2 = va_arg(ap, int);
73500 + str1 = va_arg(ap, char *);
73501 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
73502 + break;
73503 + case GR_TEXTREL:
73504 + file = va_arg(ap, struct file *);
73505 + ulong1 = va_arg(ap, unsigned long);
73506 + ulong2 = va_arg(ap, unsigned long);
73507 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
73508 + break;
73509 + case GR_PTRACE:
73510 + task = va_arg(ap, struct task_struct *);
73511 + 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));
73512 + break;
73513 + case GR_RESOURCE:
73514 + task = va_arg(ap, struct task_struct *);
73515 + cred = __task_cred(task);
73516 + pcred = __task_cred(task->real_parent);
73517 + ulong1 = va_arg(ap, unsigned long);
73518 + str1 = va_arg(ap, char *);
73519 + ulong2 = va_arg(ap, unsigned long);
73520 + 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));
73521 + break;
73522 + case GR_CAP:
73523 + task = va_arg(ap, struct task_struct *);
73524 + cred = __task_cred(task);
73525 + pcred = __task_cred(task->real_parent);
73526 + str1 = va_arg(ap, char *);
73527 + 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));
73528 + break;
73529 + case GR_SIG:
73530 + str1 = va_arg(ap, char *);
73531 + voidptr = va_arg(ap, void *);
73532 + gr_log_middle_varargs(audit, msg, str1, voidptr);
73533 + break;
73534 + case GR_SIG2:
73535 + task = va_arg(ap, struct task_struct *);
73536 + cred = __task_cred(task);
73537 + pcred = __task_cred(task->real_parent);
73538 + num1 = va_arg(ap, int);
73539 + 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));
73540 + break;
73541 + case GR_CRASH1:
73542 + task = va_arg(ap, struct task_struct *);
73543 + cred = __task_cred(task);
73544 + pcred = __task_cred(task->real_parent);
73545 + ulong1 = va_arg(ap, unsigned long);
73546 + 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);
73547 + break;
73548 + case GR_CRASH2:
73549 + task = va_arg(ap, struct task_struct *);
73550 + cred = __task_cred(task);
73551 + pcred = __task_cred(task->real_parent);
73552 + ulong1 = va_arg(ap, unsigned long);
73553 + 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);
73554 + break;
73555 + case GR_RWXMAP:
73556 + file = va_arg(ap, struct file *);
73557 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
73558 + break;
73559 + case GR_RWXMAPVMA:
73560 + vma = va_arg(ap, struct vm_area_struct *);
73561 + if (vma->vm_file)
73562 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
73563 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
73564 + str1 = "<stack>";
73565 + else if (vma->vm_start <= current->mm->brk &&
73566 + vma->vm_end >= current->mm->start_brk)
73567 + str1 = "<heap>";
73568 + else
73569 + str1 = "<anonymous mapping>";
73570 + gr_log_middle_varargs(audit, msg, str1);
73571 + break;
73572 + case GR_PSACCT:
73573 + {
73574 + unsigned int wday, cday;
73575 + __u8 whr, chr;
73576 + __u8 wmin, cmin;
73577 + __u8 wsec, csec;
73578 + char cur_tty[64] = { 0 };
73579 + char parent_tty[64] = { 0 };
73580 +
73581 + task = va_arg(ap, struct task_struct *);
73582 + wday = va_arg(ap, unsigned int);
73583 + cday = va_arg(ap, unsigned int);
73584 + whr = va_arg(ap, int);
73585 + chr = va_arg(ap, int);
73586 + wmin = va_arg(ap, int);
73587 + cmin = va_arg(ap, int);
73588 + wsec = va_arg(ap, int);
73589 + csec = va_arg(ap, int);
73590 + ulong1 = va_arg(ap, unsigned long);
73591 + cred = __task_cred(task);
73592 + pcred = __task_cred(task->real_parent);
73593 +
73594 + 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));
73595 + }
73596 + break;
73597 + default:
73598 + gr_log_middle(audit, msg, ap);
73599 + }
73600 + va_end(ap);
73601 + // these don't need DEFAULTSECARGS printed on the end
73602 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
73603 + gr_log_end(audit, 0);
73604 + else
73605 + gr_log_end(audit, 1);
73606 + END_LOCKS(audit);
73607 +}
73608 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
73609 new file mode 100644
73610 index 0000000..f536303
73611 --- /dev/null
73612 +++ b/grsecurity/grsec_mem.c
73613 @@ -0,0 +1,40 @@
73614 +#include <linux/kernel.h>
73615 +#include <linux/sched.h>
73616 +#include <linux/mm.h>
73617 +#include <linux/mman.h>
73618 +#include <linux/grinternal.h>
73619 +
73620 +void
73621 +gr_handle_ioperm(void)
73622 +{
73623 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
73624 + return;
73625 +}
73626 +
73627 +void
73628 +gr_handle_iopl(void)
73629 +{
73630 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
73631 + return;
73632 +}
73633 +
73634 +void
73635 +gr_handle_mem_readwrite(u64 from, u64 to)
73636 +{
73637 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
73638 + return;
73639 +}
73640 +
73641 +void
73642 +gr_handle_vm86(void)
73643 +{
73644 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
73645 + return;
73646 +}
73647 +
73648 +void
73649 +gr_log_badprocpid(const char *entry)
73650 +{
73651 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
73652 + return;
73653 +}
73654 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
73655 new file mode 100644
73656 index 0000000..cd9e124
73657 --- /dev/null
73658 +++ b/grsecurity/grsec_mount.c
73659 @@ -0,0 +1,65 @@
73660 +#include <linux/kernel.h>
73661 +#include <linux/sched.h>
73662 +#include <linux/mount.h>
73663 +#include <linux/major.h>
73664 +#include <linux/grsecurity.h>
73665 +#include <linux/grinternal.h>
73666 +
73667 +void
73668 +gr_log_remount(const char *devname, const int retval)
73669 +{
73670 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73671 + if (grsec_enable_mount && (retval >= 0))
73672 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
73673 +#endif
73674 + return;
73675 +}
73676 +
73677 +void
73678 +gr_log_unmount(const char *devname, const int retval)
73679 +{
73680 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73681 + if (grsec_enable_mount && (retval >= 0))
73682 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
73683 +#endif
73684 + return;
73685 +}
73686 +
73687 +void
73688 +gr_log_mount(const char *from, const char *to, const int retval)
73689 +{
73690 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73691 + if (grsec_enable_mount && (retval >= 0))
73692 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
73693 +#endif
73694 + return;
73695 +}
73696 +
73697 +int
73698 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
73699 +{
73700 +#ifdef CONFIG_GRKERNSEC_ROFS
73701 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
73702 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
73703 + return -EPERM;
73704 + } else
73705 + return 0;
73706 +#endif
73707 + return 0;
73708 +}
73709 +
73710 +int
73711 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
73712 +{
73713 +#ifdef CONFIG_GRKERNSEC_ROFS
73714 + struct inode *inode = dentry->d_inode;
73715 +
73716 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
73717 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
73718 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
73719 + return -EPERM;
73720 + } else
73721 + return 0;
73722 +#endif
73723 + return 0;
73724 +}
73725 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
73726 new file mode 100644
73727 index 0000000..6ee9d50
73728 --- /dev/null
73729 +++ b/grsecurity/grsec_pax.c
73730 @@ -0,0 +1,45 @@
73731 +#include <linux/kernel.h>
73732 +#include <linux/sched.h>
73733 +#include <linux/mm.h>
73734 +#include <linux/file.h>
73735 +#include <linux/grinternal.h>
73736 +#include <linux/grsecurity.h>
73737 +
73738 +void
73739 +gr_log_textrel(struct vm_area_struct * vma)
73740 +{
73741 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73742 + if (grsec_enable_log_rwxmaps)
73743 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
73744 +#endif
73745 + return;
73746 +}
73747 +
73748 +void gr_log_ptgnustack(struct file *file)
73749 +{
73750 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73751 + if (grsec_enable_log_rwxmaps)
73752 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
73753 +#endif
73754 + return;
73755 +}
73756 +
73757 +void
73758 +gr_log_rwxmmap(struct file *file)
73759 +{
73760 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73761 + if (grsec_enable_log_rwxmaps)
73762 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
73763 +#endif
73764 + return;
73765 +}
73766 +
73767 +void
73768 +gr_log_rwxmprotect(struct vm_area_struct *vma)
73769 +{
73770 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73771 + if (grsec_enable_log_rwxmaps)
73772 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
73773 +#endif
73774 + return;
73775 +}
73776 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
73777 new file mode 100644
73778 index 0000000..f7f29aa
73779 --- /dev/null
73780 +++ b/grsecurity/grsec_ptrace.c
73781 @@ -0,0 +1,30 @@
73782 +#include <linux/kernel.h>
73783 +#include <linux/sched.h>
73784 +#include <linux/grinternal.h>
73785 +#include <linux/security.h>
73786 +
73787 +void
73788 +gr_audit_ptrace(struct task_struct *task)
73789 +{
73790 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
73791 + if (grsec_enable_audit_ptrace)
73792 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
73793 +#endif
73794 + return;
73795 +}
73796 +
73797 +int
73798 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
73799 +{
73800 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
73801 + const struct dentry *dentry = file->f_path.dentry;
73802 + const struct vfsmount *mnt = file->f_path.mnt;
73803 +
73804 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
73805 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
73806 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
73807 + return -EACCES;
73808 + }
73809 +#endif
73810 + return 0;
73811 +}
73812 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
73813 new file mode 100644
73814 index 0000000..3860c7e
73815 --- /dev/null
73816 +++ b/grsecurity/grsec_sig.c
73817 @@ -0,0 +1,236 @@
73818 +#include <linux/kernel.h>
73819 +#include <linux/sched.h>
73820 +#include <linux/fs.h>
73821 +#include <linux/delay.h>
73822 +#include <linux/grsecurity.h>
73823 +#include <linux/grinternal.h>
73824 +#include <linux/hardirq.h>
73825 +
73826 +char *signames[] = {
73827 + [SIGSEGV] = "Segmentation fault",
73828 + [SIGILL] = "Illegal instruction",
73829 + [SIGABRT] = "Abort",
73830 + [SIGBUS] = "Invalid alignment/Bus error"
73831 +};
73832 +
73833 +void
73834 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
73835 +{
73836 +#ifdef CONFIG_GRKERNSEC_SIGNAL
73837 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
73838 + (sig == SIGABRT) || (sig == SIGBUS))) {
73839 + if (task_pid_nr(t) == task_pid_nr(current)) {
73840 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
73841 + } else {
73842 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
73843 + }
73844 + }
73845 +#endif
73846 + return;
73847 +}
73848 +
73849 +int
73850 +gr_handle_signal(const struct task_struct *p, const int sig)
73851 +{
73852 +#ifdef CONFIG_GRKERNSEC
73853 + /* ignore the 0 signal for protected task checks */
73854 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
73855 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
73856 + return -EPERM;
73857 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
73858 + return -EPERM;
73859 + }
73860 +#endif
73861 + return 0;
73862 +}
73863 +
73864 +#ifdef CONFIG_GRKERNSEC
73865 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
73866 +
73867 +int gr_fake_force_sig(int sig, struct task_struct *t)
73868 +{
73869 + unsigned long int flags;
73870 + int ret, blocked, ignored;
73871 + struct k_sigaction *action;
73872 +
73873 + spin_lock_irqsave(&t->sighand->siglock, flags);
73874 + action = &t->sighand->action[sig-1];
73875 + ignored = action->sa.sa_handler == SIG_IGN;
73876 + blocked = sigismember(&t->blocked, sig);
73877 + if (blocked || ignored) {
73878 + action->sa.sa_handler = SIG_DFL;
73879 + if (blocked) {
73880 + sigdelset(&t->blocked, sig);
73881 + recalc_sigpending_and_wake(t);
73882 + }
73883 + }
73884 + if (action->sa.sa_handler == SIG_DFL)
73885 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
73886 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
73887 +
73888 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
73889 +
73890 + return ret;
73891 +}
73892 +#endif
73893 +
73894 +#define GR_USER_BAN_TIME (15 * 60)
73895 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
73896 +
73897 +void gr_handle_brute_attach(int dumpable)
73898 +{
73899 +#ifdef CONFIG_GRKERNSEC_BRUTE
73900 + struct task_struct *p = current;
73901 + kuid_t uid = GLOBAL_ROOT_UID;
73902 + int daemon = 0;
73903 +
73904 + if (!grsec_enable_brute)
73905 + return;
73906 +
73907 + rcu_read_lock();
73908 + read_lock(&tasklist_lock);
73909 + read_lock(&grsec_exec_file_lock);
73910 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
73911 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
73912 + p->real_parent->brute = 1;
73913 + daemon = 1;
73914 + } else {
73915 + const struct cred *cred = __task_cred(p), *cred2;
73916 + struct task_struct *tsk, *tsk2;
73917 +
73918 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
73919 + struct user_struct *user;
73920 +
73921 + uid = cred->uid;
73922 +
73923 + /* this is put upon execution past expiration */
73924 + user = find_user(uid);
73925 + if (user == NULL)
73926 + goto unlock;
73927 + user->suid_banned = 1;
73928 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
73929 + if (user->suid_ban_expires == ~0UL)
73930 + user->suid_ban_expires--;
73931 +
73932 + /* only kill other threads of the same binary, from the same user */
73933 + do_each_thread(tsk2, tsk) {
73934 + cred2 = __task_cred(tsk);
73935 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
73936 + gr_fake_force_sig(SIGKILL, tsk);
73937 + } while_each_thread(tsk2, tsk);
73938 + }
73939 + }
73940 +unlock:
73941 + read_unlock(&grsec_exec_file_lock);
73942 + read_unlock(&tasklist_lock);
73943 + rcu_read_unlock();
73944 +
73945 + if (gr_is_global_nonroot(uid))
73946 + 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);
73947 + else if (daemon)
73948 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
73949 +
73950 +#endif
73951 + return;
73952 +}
73953 +
73954 +void gr_handle_brute_check(void)
73955 +{
73956 +#ifdef CONFIG_GRKERNSEC_BRUTE
73957 + struct task_struct *p = current;
73958 +
73959 + if (unlikely(p->brute)) {
73960 + if (!grsec_enable_brute)
73961 + p->brute = 0;
73962 + else if (time_before(get_seconds(), p->brute_expires))
73963 + msleep(30 * 1000);
73964 + }
73965 +#endif
73966 + return;
73967 +}
73968 +
73969 +void gr_handle_kernel_exploit(void)
73970 +{
73971 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
73972 + const struct cred *cred;
73973 + struct task_struct *tsk, *tsk2;
73974 + struct user_struct *user;
73975 + kuid_t uid;
73976 +
73977 + if (in_irq() || in_serving_softirq() || in_nmi())
73978 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
73979 +
73980 + uid = current_uid();
73981 +
73982 + if (gr_is_global_root(uid))
73983 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
73984 + else {
73985 + /* kill all the processes of this user, hold a reference
73986 + to their creds struct, and prevent them from creating
73987 + another process until system reset
73988 + */
73989 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
73990 + GR_GLOBAL_UID(uid));
73991 + /* we intentionally leak this ref */
73992 + user = get_uid(current->cred->user);
73993 + if (user)
73994 + user->kernel_banned = 1;
73995 +
73996 + /* kill all processes of this user */
73997 + read_lock(&tasklist_lock);
73998 + do_each_thread(tsk2, tsk) {
73999 + cred = __task_cred(tsk);
74000 + if (uid_eq(cred->uid, uid))
74001 + gr_fake_force_sig(SIGKILL, tsk);
74002 + } while_each_thread(tsk2, tsk);
74003 + read_unlock(&tasklist_lock);
74004 + }
74005 +#endif
74006 +}
74007 +
74008 +#ifdef CONFIG_GRKERNSEC_BRUTE
74009 +static bool suid_ban_expired(struct user_struct *user)
74010 +{
74011 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
74012 + user->suid_banned = 0;
74013 + user->suid_ban_expires = 0;
74014 + free_uid(user);
74015 + return true;
74016 + }
74017 +
74018 + return false;
74019 +}
74020 +#endif
74021 +
74022 +int gr_process_kernel_exec_ban(void)
74023 +{
74024 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74025 + if (unlikely(current->cred->user->kernel_banned))
74026 + return -EPERM;
74027 +#endif
74028 + return 0;
74029 +}
74030 +
74031 +int gr_process_kernel_setuid_ban(struct user_struct *user)
74032 +{
74033 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74034 + if (unlikely(user->kernel_banned))
74035 + gr_fake_force_sig(SIGKILL, current);
74036 +#endif
74037 + return 0;
74038 +}
74039 +
74040 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
74041 +{
74042 +#ifdef CONFIG_GRKERNSEC_BRUTE
74043 + struct user_struct *user = current->cred->user;
74044 + if (unlikely(user->suid_banned)) {
74045 + if (suid_ban_expired(user))
74046 + return 0;
74047 + /* disallow execution of suid binaries only */
74048 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
74049 + return -EPERM;
74050 + }
74051 +#endif
74052 + return 0;
74053 +}
74054 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
74055 new file mode 100644
74056 index 0000000..4030d57
74057 --- /dev/null
74058 +++ b/grsecurity/grsec_sock.c
74059 @@ -0,0 +1,244 @@
74060 +#include <linux/kernel.h>
74061 +#include <linux/module.h>
74062 +#include <linux/sched.h>
74063 +#include <linux/file.h>
74064 +#include <linux/net.h>
74065 +#include <linux/in.h>
74066 +#include <linux/ip.h>
74067 +#include <net/sock.h>
74068 +#include <net/inet_sock.h>
74069 +#include <linux/grsecurity.h>
74070 +#include <linux/grinternal.h>
74071 +#include <linux/gracl.h>
74072 +
74073 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
74074 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
74075 +
74076 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
74077 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
74078 +
74079 +#ifdef CONFIG_UNIX_MODULE
74080 +EXPORT_SYMBOL(gr_acl_handle_unix);
74081 +EXPORT_SYMBOL(gr_acl_handle_mknod);
74082 +EXPORT_SYMBOL(gr_handle_chroot_unix);
74083 +EXPORT_SYMBOL(gr_handle_create);
74084 +#endif
74085 +
74086 +#ifdef CONFIG_GRKERNSEC
74087 +#define gr_conn_table_size 32749
74088 +struct conn_table_entry {
74089 + struct conn_table_entry *next;
74090 + struct signal_struct *sig;
74091 +};
74092 +
74093 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
74094 +DEFINE_SPINLOCK(gr_conn_table_lock);
74095 +
74096 +extern const char * gr_socktype_to_name(unsigned char type);
74097 +extern const char * gr_proto_to_name(unsigned char proto);
74098 +extern const char * gr_sockfamily_to_name(unsigned char family);
74099 +
74100 +static __inline__ int
74101 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
74102 +{
74103 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
74104 +}
74105 +
74106 +static __inline__ int
74107 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
74108 + __u16 sport, __u16 dport)
74109 +{
74110 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
74111 + sig->gr_sport == sport && sig->gr_dport == dport))
74112 + return 1;
74113 + else
74114 + return 0;
74115 +}
74116 +
74117 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
74118 +{
74119 + struct conn_table_entry **match;
74120 + unsigned int index;
74121 +
74122 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
74123 + sig->gr_sport, sig->gr_dport,
74124 + gr_conn_table_size);
74125 +
74126 + newent->sig = sig;
74127 +
74128 + match = &gr_conn_table[index];
74129 + newent->next = *match;
74130 + *match = newent;
74131 +
74132 + return;
74133 +}
74134 +
74135 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
74136 +{
74137 + struct conn_table_entry *match, *last = NULL;
74138 + unsigned int index;
74139 +
74140 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
74141 + sig->gr_sport, sig->gr_dport,
74142 + gr_conn_table_size);
74143 +
74144 + match = gr_conn_table[index];
74145 + while (match && !conn_match(match->sig,
74146 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
74147 + sig->gr_dport)) {
74148 + last = match;
74149 + match = match->next;
74150 + }
74151 +
74152 + if (match) {
74153 + if (last)
74154 + last->next = match->next;
74155 + else
74156 + gr_conn_table[index] = NULL;
74157 + kfree(match);
74158 + }
74159 +
74160 + return;
74161 +}
74162 +
74163 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
74164 + __u16 sport, __u16 dport)
74165 +{
74166 + struct conn_table_entry *match;
74167 + unsigned int index;
74168 +
74169 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
74170 +
74171 + match = gr_conn_table[index];
74172 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
74173 + match = match->next;
74174 +
74175 + if (match)
74176 + return match->sig;
74177 + else
74178 + return NULL;
74179 +}
74180 +
74181 +#endif
74182 +
74183 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
74184 +{
74185 +#ifdef CONFIG_GRKERNSEC
74186 + struct signal_struct *sig = task->signal;
74187 + struct conn_table_entry *newent;
74188 +
74189 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
74190 + if (newent == NULL)
74191 + return;
74192 + /* no bh lock needed since we are called with bh disabled */
74193 + spin_lock(&gr_conn_table_lock);
74194 + gr_del_task_from_ip_table_nolock(sig);
74195 + sig->gr_saddr = inet->inet_rcv_saddr;
74196 + sig->gr_daddr = inet->inet_daddr;
74197 + sig->gr_sport = inet->inet_sport;
74198 + sig->gr_dport = inet->inet_dport;
74199 + gr_add_to_task_ip_table_nolock(sig, newent);
74200 + spin_unlock(&gr_conn_table_lock);
74201 +#endif
74202 + return;
74203 +}
74204 +
74205 +void gr_del_task_from_ip_table(struct task_struct *task)
74206 +{
74207 +#ifdef CONFIG_GRKERNSEC
74208 + spin_lock_bh(&gr_conn_table_lock);
74209 + gr_del_task_from_ip_table_nolock(task->signal);
74210 + spin_unlock_bh(&gr_conn_table_lock);
74211 +#endif
74212 + return;
74213 +}
74214 +
74215 +void
74216 +gr_attach_curr_ip(const struct sock *sk)
74217 +{
74218 +#ifdef CONFIG_GRKERNSEC
74219 + struct signal_struct *p, *set;
74220 + const struct inet_sock *inet = inet_sk(sk);
74221 +
74222 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
74223 + return;
74224 +
74225 + set = current->signal;
74226 +
74227 + spin_lock_bh(&gr_conn_table_lock);
74228 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
74229 + inet->inet_dport, inet->inet_sport);
74230 + if (unlikely(p != NULL)) {
74231 + set->curr_ip = p->curr_ip;
74232 + set->used_accept = 1;
74233 + gr_del_task_from_ip_table_nolock(p);
74234 + spin_unlock_bh(&gr_conn_table_lock);
74235 + return;
74236 + }
74237 + spin_unlock_bh(&gr_conn_table_lock);
74238 +
74239 + set->curr_ip = inet->inet_daddr;
74240 + set->used_accept = 1;
74241 +#endif
74242 + return;
74243 +}
74244 +
74245 +int
74246 +gr_handle_sock_all(const int family, const int type, const int protocol)
74247 +{
74248 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74249 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
74250 + (family != AF_UNIX)) {
74251 + if (family == AF_INET)
74252 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
74253 + else
74254 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
74255 + return -EACCES;
74256 + }
74257 +#endif
74258 + return 0;
74259 +}
74260 +
74261 +int
74262 +gr_handle_sock_server(const struct sockaddr *sck)
74263 +{
74264 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74265 + if (grsec_enable_socket_server &&
74266 + in_group_p(grsec_socket_server_gid) &&
74267 + sck && (sck->sa_family != AF_UNIX) &&
74268 + (sck->sa_family != AF_LOCAL)) {
74269 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
74270 + return -EACCES;
74271 + }
74272 +#endif
74273 + return 0;
74274 +}
74275 +
74276 +int
74277 +gr_handle_sock_server_other(const struct sock *sck)
74278 +{
74279 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74280 + if (grsec_enable_socket_server &&
74281 + in_group_p(grsec_socket_server_gid) &&
74282 + sck && (sck->sk_family != AF_UNIX) &&
74283 + (sck->sk_family != AF_LOCAL)) {
74284 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
74285 + return -EACCES;
74286 + }
74287 +#endif
74288 + return 0;
74289 +}
74290 +
74291 +int
74292 +gr_handle_sock_client(const struct sockaddr *sck)
74293 +{
74294 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74295 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
74296 + sck && (sck->sa_family != AF_UNIX) &&
74297 + (sck->sa_family != AF_LOCAL)) {
74298 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
74299 + return -EACCES;
74300 + }
74301 +#endif
74302 + return 0;
74303 +}
74304 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
74305 new file mode 100644
74306 index 0000000..8159888
74307 --- /dev/null
74308 +++ b/grsecurity/grsec_sysctl.c
74309 @@ -0,0 +1,479 @@
74310 +#include <linux/kernel.h>
74311 +#include <linux/sched.h>
74312 +#include <linux/sysctl.h>
74313 +#include <linux/grsecurity.h>
74314 +#include <linux/grinternal.h>
74315 +
74316 +int
74317 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
74318 +{
74319 +#ifdef CONFIG_GRKERNSEC_SYSCTL
74320 + if (dirname == NULL || name == NULL)
74321 + return 0;
74322 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
74323 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
74324 + return -EACCES;
74325 + }
74326 +#endif
74327 + return 0;
74328 +}
74329 +
74330 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
74331 +static int __maybe_unused __read_only one = 1;
74332 +#endif
74333 +
74334 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
74335 + defined(CONFIG_GRKERNSEC_DENYUSB)
74336 +struct ctl_table grsecurity_table[] = {
74337 +#ifdef CONFIG_GRKERNSEC_SYSCTL
74338 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
74339 +#ifdef CONFIG_GRKERNSEC_IO
74340 + {
74341 + .procname = "disable_priv_io",
74342 + .data = &grsec_disable_privio,
74343 + .maxlen = sizeof(int),
74344 + .mode = 0600,
74345 + .proc_handler = &proc_dointvec,
74346 + },
74347 +#endif
74348 +#endif
74349 +#ifdef CONFIG_GRKERNSEC_LINK
74350 + {
74351 + .procname = "linking_restrictions",
74352 + .data = &grsec_enable_link,
74353 + .maxlen = sizeof(int),
74354 + .mode = 0600,
74355 + .proc_handler = &proc_dointvec,
74356 + },
74357 +#endif
74358 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74359 + {
74360 + .procname = "enforce_symlinksifowner",
74361 + .data = &grsec_enable_symlinkown,
74362 + .maxlen = sizeof(int),
74363 + .mode = 0600,
74364 + .proc_handler = &proc_dointvec,
74365 + },
74366 + {
74367 + .procname = "symlinkown_gid",
74368 + .data = &grsec_symlinkown_gid,
74369 + .maxlen = sizeof(int),
74370 + .mode = 0600,
74371 + .proc_handler = &proc_dointvec,
74372 + },
74373 +#endif
74374 +#ifdef CONFIG_GRKERNSEC_BRUTE
74375 + {
74376 + .procname = "deter_bruteforce",
74377 + .data = &grsec_enable_brute,
74378 + .maxlen = sizeof(int),
74379 + .mode = 0600,
74380 + .proc_handler = &proc_dointvec,
74381 + },
74382 +#endif
74383 +#ifdef CONFIG_GRKERNSEC_FIFO
74384 + {
74385 + .procname = "fifo_restrictions",
74386 + .data = &grsec_enable_fifo,
74387 + .maxlen = sizeof(int),
74388 + .mode = 0600,
74389 + .proc_handler = &proc_dointvec,
74390 + },
74391 +#endif
74392 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74393 + {
74394 + .procname = "ptrace_readexec",
74395 + .data = &grsec_enable_ptrace_readexec,
74396 + .maxlen = sizeof(int),
74397 + .mode = 0600,
74398 + .proc_handler = &proc_dointvec,
74399 + },
74400 +#endif
74401 +#ifdef CONFIG_GRKERNSEC_SETXID
74402 + {
74403 + .procname = "consistent_setxid",
74404 + .data = &grsec_enable_setxid,
74405 + .maxlen = sizeof(int),
74406 + .mode = 0600,
74407 + .proc_handler = &proc_dointvec,
74408 + },
74409 +#endif
74410 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74411 + {
74412 + .procname = "ip_blackhole",
74413 + .data = &grsec_enable_blackhole,
74414 + .maxlen = sizeof(int),
74415 + .mode = 0600,
74416 + .proc_handler = &proc_dointvec,
74417 + },
74418 + {
74419 + .procname = "lastack_retries",
74420 + .data = &grsec_lastack_retries,
74421 + .maxlen = sizeof(int),
74422 + .mode = 0600,
74423 + .proc_handler = &proc_dointvec,
74424 + },
74425 +#endif
74426 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74427 + {
74428 + .procname = "exec_logging",
74429 + .data = &grsec_enable_execlog,
74430 + .maxlen = sizeof(int),
74431 + .mode = 0600,
74432 + .proc_handler = &proc_dointvec,
74433 + },
74434 +#endif
74435 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74436 + {
74437 + .procname = "rwxmap_logging",
74438 + .data = &grsec_enable_log_rwxmaps,
74439 + .maxlen = sizeof(int),
74440 + .mode = 0600,
74441 + .proc_handler = &proc_dointvec,
74442 + },
74443 +#endif
74444 +#ifdef CONFIG_GRKERNSEC_SIGNAL
74445 + {
74446 + .procname = "signal_logging",
74447 + .data = &grsec_enable_signal,
74448 + .maxlen = sizeof(int),
74449 + .mode = 0600,
74450 + .proc_handler = &proc_dointvec,
74451 + },
74452 +#endif
74453 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74454 + {
74455 + .procname = "forkfail_logging",
74456 + .data = &grsec_enable_forkfail,
74457 + .maxlen = sizeof(int),
74458 + .mode = 0600,
74459 + .proc_handler = &proc_dointvec,
74460 + },
74461 +#endif
74462 +#ifdef CONFIG_GRKERNSEC_TIME
74463 + {
74464 + .procname = "timechange_logging",
74465 + .data = &grsec_enable_time,
74466 + .maxlen = sizeof(int),
74467 + .mode = 0600,
74468 + .proc_handler = &proc_dointvec,
74469 + },
74470 +#endif
74471 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74472 + {
74473 + .procname = "chroot_deny_shmat",
74474 + .data = &grsec_enable_chroot_shmat,
74475 + .maxlen = sizeof(int),
74476 + .mode = 0600,
74477 + .proc_handler = &proc_dointvec,
74478 + },
74479 +#endif
74480 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74481 + {
74482 + .procname = "chroot_deny_unix",
74483 + .data = &grsec_enable_chroot_unix,
74484 + .maxlen = sizeof(int),
74485 + .mode = 0600,
74486 + .proc_handler = &proc_dointvec,
74487 + },
74488 +#endif
74489 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74490 + {
74491 + .procname = "chroot_deny_mount",
74492 + .data = &grsec_enable_chroot_mount,
74493 + .maxlen = sizeof(int),
74494 + .mode = 0600,
74495 + .proc_handler = &proc_dointvec,
74496 + },
74497 +#endif
74498 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74499 + {
74500 + .procname = "chroot_deny_fchdir",
74501 + .data = &grsec_enable_chroot_fchdir,
74502 + .maxlen = sizeof(int),
74503 + .mode = 0600,
74504 + .proc_handler = &proc_dointvec,
74505 + },
74506 +#endif
74507 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74508 + {
74509 + .procname = "chroot_deny_chroot",
74510 + .data = &grsec_enable_chroot_double,
74511 + .maxlen = sizeof(int),
74512 + .mode = 0600,
74513 + .proc_handler = &proc_dointvec,
74514 + },
74515 +#endif
74516 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74517 + {
74518 + .procname = "chroot_deny_pivot",
74519 + .data = &grsec_enable_chroot_pivot,
74520 + .maxlen = sizeof(int),
74521 + .mode = 0600,
74522 + .proc_handler = &proc_dointvec,
74523 + },
74524 +#endif
74525 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74526 + {
74527 + .procname = "chroot_enforce_chdir",
74528 + .data = &grsec_enable_chroot_chdir,
74529 + .maxlen = sizeof(int),
74530 + .mode = 0600,
74531 + .proc_handler = &proc_dointvec,
74532 + },
74533 +#endif
74534 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74535 + {
74536 + .procname = "chroot_deny_chmod",
74537 + .data = &grsec_enable_chroot_chmod,
74538 + .maxlen = sizeof(int),
74539 + .mode = 0600,
74540 + .proc_handler = &proc_dointvec,
74541 + },
74542 +#endif
74543 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74544 + {
74545 + .procname = "chroot_deny_mknod",
74546 + .data = &grsec_enable_chroot_mknod,
74547 + .maxlen = sizeof(int),
74548 + .mode = 0600,
74549 + .proc_handler = &proc_dointvec,
74550 + },
74551 +#endif
74552 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74553 + {
74554 + .procname = "chroot_restrict_nice",
74555 + .data = &grsec_enable_chroot_nice,
74556 + .maxlen = sizeof(int),
74557 + .mode = 0600,
74558 + .proc_handler = &proc_dointvec,
74559 + },
74560 +#endif
74561 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74562 + {
74563 + .procname = "chroot_execlog",
74564 + .data = &grsec_enable_chroot_execlog,
74565 + .maxlen = sizeof(int),
74566 + .mode = 0600,
74567 + .proc_handler = &proc_dointvec,
74568 + },
74569 +#endif
74570 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74571 + {
74572 + .procname = "chroot_caps",
74573 + .data = &grsec_enable_chroot_caps,
74574 + .maxlen = sizeof(int),
74575 + .mode = 0600,
74576 + .proc_handler = &proc_dointvec,
74577 + },
74578 +#endif
74579 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74580 + {
74581 + .procname = "chroot_deny_sysctl",
74582 + .data = &grsec_enable_chroot_sysctl,
74583 + .maxlen = sizeof(int),
74584 + .mode = 0600,
74585 + .proc_handler = &proc_dointvec,
74586 + },
74587 +#endif
74588 +#ifdef CONFIG_GRKERNSEC_TPE
74589 + {
74590 + .procname = "tpe",
74591 + .data = &grsec_enable_tpe,
74592 + .maxlen = sizeof(int),
74593 + .mode = 0600,
74594 + .proc_handler = &proc_dointvec,
74595 + },
74596 + {
74597 + .procname = "tpe_gid",
74598 + .data = &grsec_tpe_gid,
74599 + .maxlen = sizeof(int),
74600 + .mode = 0600,
74601 + .proc_handler = &proc_dointvec,
74602 + },
74603 +#endif
74604 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74605 + {
74606 + .procname = "tpe_invert",
74607 + .data = &grsec_enable_tpe_invert,
74608 + .maxlen = sizeof(int),
74609 + .mode = 0600,
74610 + .proc_handler = &proc_dointvec,
74611 + },
74612 +#endif
74613 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
74614 + {
74615 + .procname = "tpe_restrict_all",
74616 + .data = &grsec_enable_tpe_all,
74617 + .maxlen = sizeof(int),
74618 + .mode = 0600,
74619 + .proc_handler = &proc_dointvec,
74620 + },
74621 +#endif
74622 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74623 + {
74624 + .procname = "socket_all",
74625 + .data = &grsec_enable_socket_all,
74626 + .maxlen = sizeof(int),
74627 + .mode = 0600,
74628 + .proc_handler = &proc_dointvec,
74629 + },
74630 + {
74631 + .procname = "socket_all_gid",
74632 + .data = &grsec_socket_all_gid,
74633 + .maxlen = sizeof(int),
74634 + .mode = 0600,
74635 + .proc_handler = &proc_dointvec,
74636 + },
74637 +#endif
74638 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74639 + {
74640 + .procname = "socket_client",
74641 + .data = &grsec_enable_socket_client,
74642 + .maxlen = sizeof(int),
74643 + .mode = 0600,
74644 + .proc_handler = &proc_dointvec,
74645 + },
74646 + {
74647 + .procname = "socket_client_gid",
74648 + .data = &grsec_socket_client_gid,
74649 + .maxlen = sizeof(int),
74650 + .mode = 0600,
74651 + .proc_handler = &proc_dointvec,
74652 + },
74653 +#endif
74654 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74655 + {
74656 + .procname = "socket_server",
74657 + .data = &grsec_enable_socket_server,
74658 + .maxlen = sizeof(int),
74659 + .mode = 0600,
74660 + .proc_handler = &proc_dointvec,
74661 + },
74662 + {
74663 + .procname = "socket_server_gid",
74664 + .data = &grsec_socket_server_gid,
74665 + .maxlen = sizeof(int),
74666 + .mode = 0600,
74667 + .proc_handler = &proc_dointvec,
74668 + },
74669 +#endif
74670 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74671 + {
74672 + .procname = "audit_group",
74673 + .data = &grsec_enable_group,
74674 + .maxlen = sizeof(int),
74675 + .mode = 0600,
74676 + .proc_handler = &proc_dointvec,
74677 + },
74678 + {
74679 + .procname = "audit_gid",
74680 + .data = &grsec_audit_gid,
74681 + .maxlen = sizeof(int),
74682 + .mode = 0600,
74683 + .proc_handler = &proc_dointvec,
74684 + },
74685 +#endif
74686 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74687 + {
74688 + .procname = "audit_chdir",
74689 + .data = &grsec_enable_chdir,
74690 + .maxlen = sizeof(int),
74691 + .mode = 0600,
74692 + .proc_handler = &proc_dointvec,
74693 + },
74694 +#endif
74695 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74696 + {
74697 + .procname = "audit_mount",
74698 + .data = &grsec_enable_mount,
74699 + .maxlen = sizeof(int),
74700 + .mode = 0600,
74701 + .proc_handler = &proc_dointvec,
74702 + },
74703 +#endif
74704 +#ifdef CONFIG_GRKERNSEC_DMESG
74705 + {
74706 + .procname = "dmesg",
74707 + .data = &grsec_enable_dmesg,
74708 + .maxlen = sizeof(int),
74709 + .mode = 0600,
74710 + .proc_handler = &proc_dointvec,
74711 + },
74712 +#endif
74713 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74714 + {
74715 + .procname = "chroot_findtask",
74716 + .data = &grsec_enable_chroot_findtask,
74717 + .maxlen = sizeof(int),
74718 + .mode = 0600,
74719 + .proc_handler = &proc_dointvec,
74720 + },
74721 +#endif
74722 +#ifdef CONFIG_GRKERNSEC_RESLOG
74723 + {
74724 + .procname = "resource_logging",
74725 + .data = &grsec_resource_logging,
74726 + .maxlen = sizeof(int),
74727 + .mode = 0600,
74728 + .proc_handler = &proc_dointvec,
74729 + },
74730 +#endif
74731 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74732 + {
74733 + .procname = "audit_ptrace",
74734 + .data = &grsec_enable_audit_ptrace,
74735 + .maxlen = sizeof(int),
74736 + .mode = 0600,
74737 + .proc_handler = &proc_dointvec,
74738 + },
74739 +#endif
74740 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74741 + {
74742 + .procname = "harden_ptrace",
74743 + .data = &grsec_enable_harden_ptrace,
74744 + .maxlen = sizeof(int),
74745 + .mode = 0600,
74746 + .proc_handler = &proc_dointvec,
74747 + },
74748 +#endif
74749 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74750 + {
74751 + .procname = "harden_ipc",
74752 + .data = &grsec_enable_harden_ipc,
74753 + .maxlen = sizeof(int),
74754 + .mode = 0600,
74755 + .proc_handler = &proc_dointvec,
74756 + },
74757 +#endif
74758 + {
74759 + .procname = "grsec_lock",
74760 + .data = &grsec_lock,
74761 + .maxlen = sizeof(int),
74762 + .mode = 0600,
74763 + .proc_handler = &proc_dointvec,
74764 + },
74765 +#endif
74766 +#ifdef CONFIG_GRKERNSEC_ROFS
74767 + {
74768 + .procname = "romount_protect",
74769 + .data = &grsec_enable_rofs,
74770 + .maxlen = sizeof(int),
74771 + .mode = 0600,
74772 + .proc_handler = &proc_dointvec_minmax,
74773 + .extra1 = &one,
74774 + .extra2 = &one,
74775 + },
74776 +#endif
74777 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
74778 + {
74779 + .procname = "deny_new_usb",
74780 + .data = &grsec_deny_new_usb,
74781 + .maxlen = sizeof(int),
74782 + .mode = 0600,
74783 + .proc_handler = &proc_dointvec,
74784 + },
74785 +#endif
74786 + { }
74787 +};
74788 +#endif
74789 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
74790 new file mode 100644
74791 index 0000000..0dc13c3
74792 --- /dev/null
74793 +++ b/grsecurity/grsec_time.c
74794 @@ -0,0 +1,16 @@
74795 +#include <linux/kernel.h>
74796 +#include <linux/sched.h>
74797 +#include <linux/grinternal.h>
74798 +#include <linux/module.h>
74799 +
74800 +void
74801 +gr_log_timechange(void)
74802 +{
74803 +#ifdef CONFIG_GRKERNSEC_TIME
74804 + if (grsec_enable_time)
74805 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
74806 +#endif
74807 + return;
74808 +}
74809 +
74810 +EXPORT_SYMBOL(gr_log_timechange);
74811 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
74812 new file mode 100644
74813 index 0000000..ee57dcf
74814 --- /dev/null
74815 +++ b/grsecurity/grsec_tpe.c
74816 @@ -0,0 +1,73 @@
74817 +#include <linux/kernel.h>
74818 +#include <linux/sched.h>
74819 +#include <linux/file.h>
74820 +#include <linux/fs.h>
74821 +#include <linux/grinternal.h>
74822 +
74823 +extern int gr_acl_tpe_check(void);
74824 +
74825 +int
74826 +gr_tpe_allow(const struct file *file)
74827 +{
74828 +#ifdef CONFIG_GRKERNSEC
74829 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
74830 + const struct cred *cred = current_cred();
74831 + char *msg = NULL;
74832 + char *msg2 = NULL;
74833 +
74834 + // never restrict root
74835 + if (gr_is_global_root(cred->uid))
74836 + return 1;
74837 +
74838 + if (grsec_enable_tpe) {
74839 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74840 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
74841 + msg = "not being in trusted group";
74842 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
74843 + msg = "being in untrusted group";
74844 +#else
74845 + if (in_group_p(grsec_tpe_gid))
74846 + msg = "being in untrusted group";
74847 +#endif
74848 + }
74849 + if (!msg && gr_acl_tpe_check())
74850 + msg = "being in untrusted role";
74851 +
74852 + // not in any affected group/role
74853 + if (!msg)
74854 + goto next_check;
74855 +
74856 + if (gr_is_global_nonroot(inode->i_uid))
74857 + msg2 = "file in non-root-owned directory";
74858 + else if (inode->i_mode & S_IWOTH)
74859 + msg2 = "file in world-writable directory";
74860 + else if (inode->i_mode & S_IWGRP)
74861 + msg2 = "file in group-writable directory";
74862 +
74863 + if (msg && msg2) {
74864 + char fullmsg[70] = {0};
74865 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
74866 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
74867 + return 0;
74868 + }
74869 + msg = NULL;
74870 +next_check:
74871 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
74872 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
74873 + return 1;
74874 +
74875 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
74876 + msg = "directory not owned by user";
74877 + else if (inode->i_mode & S_IWOTH)
74878 + msg = "file in world-writable directory";
74879 + else if (inode->i_mode & S_IWGRP)
74880 + msg = "file in group-writable directory";
74881 +
74882 + if (msg) {
74883 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
74884 + return 0;
74885 + }
74886 +#endif
74887 +#endif
74888 + return 1;
74889 +}
74890 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
74891 new file mode 100644
74892 index 0000000..ae02d8e
74893 --- /dev/null
74894 +++ b/grsecurity/grsec_usb.c
74895 @@ -0,0 +1,15 @@
74896 +#include <linux/kernel.h>
74897 +#include <linux/grinternal.h>
74898 +#include <linux/module.h>
74899 +
74900 +int gr_handle_new_usb(void)
74901 +{
74902 +#ifdef CONFIG_GRKERNSEC_DENYUSB
74903 + if (grsec_deny_new_usb) {
74904 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
74905 + return 1;
74906 + }
74907 +#endif
74908 + return 0;
74909 +}
74910 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
74911 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
74912 new file mode 100644
74913 index 0000000..9f7b1ac
74914 --- /dev/null
74915 +++ b/grsecurity/grsum.c
74916 @@ -0,0 +1,61 @@
74917 +#include <linux/err.h>
74918 +#include <linux/kernel.h>
74919 +#include <linux/sched.h>
74920 +#include <linux/mm.h>
74921 +#include <linux/scatterlist.h>
74922 +#include <linux/crypto.h>
74923 +#include <linux/gracl.h>
74924 +
74925 +
74926 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
74927 +#error "crypto and sha256 must be built into the kernel"
74928 +#endif
74929 +
74930 +int
74931 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
74932 +{
74933 + char *p;
74934 + struct crypto_hash *tfm;
74935 + struct hash_desc desc;
74936 + struct scatterlist sg;
74937 + unsigned char temp_sum[GR_SHA_LEN];
74938 + volatile int retval = 0;
74939 + volatile int dummy = 0;
74940 + unsigned int i;
74941 +
74942 + sg_init_table(&sg, 1);
74943 +
74944 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
74945 + if (IS_ERR(tfm)) {
74946 + /* should never happen, since sha256 should be built in */
74947 + return 1;
74948 + }
74949 +
74950 + desc.tfm = tfm;
74951 + desc.flags = 0;
74952 +
74953 + crypto_hash_init(&desc);
74954 +
74955 + p = salt;
74956 + sg_set_buf(&sg, p, GR_SALT_LEN);
74957 + crypto_hash_update(&desc, &sg, sg.length);
74958 +
74959 + p = entry->pw;
74960 + sg_set_buf(&sg, p, strlen(p));
74961 +
74962 + crypto_hash_update(&desc, &sg, sg.length);
74963 +
74964 + crypto_hash_final(&desc, temp_sum);
74965 +
74966 + memset(entry->pw, 0, GR_PW_LEN);
74967 +
74968 + for (i = 0; i < GR_SHA_LEN; i++)
74969 + if (sum[i] != temp_sum[i])
74970 + retval = 1;
74971 + else
74972 + dummy = 1; // waste a cycle
74973 +
74974 + crypto_free_hash(tfm);
74975 +
74976 + return retval;
74977 +}
74978 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
74979 index 77ff547..181834f 100644
74980 --- a/include/asm-generic/4level-fixup.h
74981 +++ b/include/asm-generic/4level-fixup.h
74982 @@ -13,8 +13,10 @@
74983 #define pmd_alloc(mm, pud, address) \
74984 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
74985 NULL: pmd_offset(pud, address))
74986 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
74987
74988 #define pud_alloc(mm, pgd, address) (pgd)
74989 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
74990 #define pud_offset(pgd, start) (pgd)
74991 #define pud_none(pud) 0
74992 #define pud_bad(pud) 0
74993 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
74994 index b7babf0..97f4c4f 100644
74995 --- a/include/asm-generic/atomic-long.h
74996 +++ b/include/asm-generic/atomic-long.h
74997 @@ -22,6 +22,12 @@
74998
74999 typedef atomic64_t atomic_long_t;
75000
75001 +#ifdef CONFIG_PAX_REFCOUNT
75002 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
75003 +#else
75004 +typedef atomic64_t atomic_long_unchecked_t;
75005 +#endif
75006 +
75007 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
75008
75009 static inline long atomic_long_read(atomic_long_t *l)
75010 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
75011 return (long)atomic64_read(v);
75012 }
75013
75014 +#ifdef CONFIG_PAX_REFCOUNT
75015 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
75016 +{
75017 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75018 +
75019 + return (long)atomic64_read_unchecked(v);
75020 +}
75021 +#endif
75022 +
75023 static inline void atomic_long_set(atomic_long_t *l, long i)
75024 {
75025 atomic64_t *v = (atomic64_t *)l;
75026 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
75027 atomic64_set(v, i);
75028 }
75029
75030 +#ifdef CONFIG_PAX_REFCOUNT
75031 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
75032 +{
75033 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75034 +
75035 + atomic64_set_unchecked(v, i);
75036 +}
75037 +#endif
75038 +
75039 static inline void atomic_long_inc(atomic_long_t *l)
75040 {
75041 atomic64_t *v = (atomic64_t *)l;
75042 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
75043 atomic64_inc(v);
75044 }
75045
75046 +#ifdef CONFIG_PAX_REFCOUNT
75047 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
75048 +{
75049 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75050 +
75051 + atomic64_inc_unchecked(v);
75052 +}
75053 +#endif
75054 +
75055 static inline void atomic_long_dec(atomic_long_t *l)
75056 {
75057 atomic64_t *v = (atomic64_t *)l;
75058 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
75059 atomic64_dec(v);
75060 }
75061
75062 +#ifdef CONFIG_PAX_REFCOUNT
75063 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
75064 +{
75065 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75066 +
75067 + atomic64_dec_unchecked(v);
75068 +}
75069 +#endif
75070 +
75071 static inline void atomic_long_add(long i, atomic_long_t *l)
75072 {
75073 atomic64_t *v = (atomic64_t *)l;
75074 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
75075 atomic64_add(i, v);
75076 }
75077
75078 +#ifdef CONFIG_PAX_REFCOUNT
75079 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
75080 +{
75081 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75082 +
75083 + atomic64_add_unchecked(i, v);
75084 +}
75085 +#endif
75086 +
75087 static inline void atomic_long_sub(long i, atomic_long_t *l)
75088 {
75089 atomic64_t *v = (atomic64_t *)l;
75090 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
75091 atomic64_sub(i, v);
75092 }
75093
75094 +#ifdef CONFIG_PAX_REFCOUNT
75095 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
75096 +{
75097 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75098 +
75099 + atomic64_sub_unchecked(i, v);
75100 +}
75101 +#endif
75102 +
75103 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
75104 {
75105 atomic64_t *v = (atomic64_t *)l;
75106 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
75107 return atomic64_add_negative(i, v);
75108 }
75109
75110 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
75111 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
75112 {
75113 atomic64_t *v = (atomic64_t *)l;
75114
75115 return (long)atomic64_add_return(i, v);
75116 }
75117
75118 +#ifdef CONFIG_PAX_REFCOUNT
75119 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
75120 +{
75121 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75122 +
75123 + return (long)atomic64_add_return_unchecked(i, v);
75124 +}
75125 +#endif
75126 +
75127 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
75128 {
75129 atomic64_t *v = (atomic64_t *)l;
75130 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
75131 return (long)atomic64_inc_return(v);
75132 }
75133
75134 +#ifdef CONFIG_PAX_REFCOUNT
75135 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
75136 +{
75137 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75138 +
75139 + return (long)atomic64_inc_return_unchecked(v);
75140 +}
75141 +#endif
75142 +
75143 static inline long atomic_long_dec_return(atomic_long_t *l)
75144 {
75145 atomic64_t *v = (atomic64_t *)l;
75146 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
75147
75148 typedef atomic_t atomic_long_t;
75149
75150 +#ifdef CONFIG_PAX_REFCOUNT
75151 +typedef atomic_unchecked_t atomic_long_unchecked_t;
75152 +#else
75153 +typedef atomic_t atomic_long_unchecked_t;
75154 +#endif
75155 +
75156 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
75157 static inline long atomic_long_read(atomic_long_t *l)
75158 {
75159 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
75160 return (long)atomic_read(v);
75161 }
75162
75163 +#ifdef CONFIG_PAX_REFCOUNT
75164 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
75165 +{
75166 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75167 +
75168 + return (long)atomic_read_unchecked(v);
75169 +}
75170 +#endif
75171 +
75172 static inline void atomic_long_set(atomic_long_t *l, long i)
75173 {
75174 atomic_t *v = (atomic_t *)l;
75175 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
75176 atomic_set(v, i);
75177 }
75178
75179 +#ifdef CONFIG_PAX_REFCOUNT
75180 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
75181 +{
75182 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75183 +
75184 + atomic_set_unchecked(v, i);
75185 +}
75186 +#endif
75187 +
75188 static inline void atomic_long_inc(atomic_long_t *l)
75189 {
75190 atomic_t *v = (atomic_t *)l;
75191 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
75192 atomic_inc(v);
75193 }
75194
75195 +#ifdef CONFIG_PAX_REFCOUNT
75196 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
75197 +{
75198 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75199 +
75200 + atomic_inc_unchecked(v);
75201 +}
75202 +#endif
75203 +
75204 static inline void atomic_long_dec(atomic_long_t *l)
75205 {
75206 atomic_t *v = (atomic_t *)l;
75207 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
75208 atomic_dec(v);
75209 }
75210
75211 +#ifdef CONFIG_PAX_REFCOUNT
75212 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
75213 +{
75214 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75215 +
75216 + atomic_dec_unchecked(v);
75217 +}
75218 +#endif
75219 +
75220 static inline void atomic_long_add(long i, atomic_long_t *l)
75221 {
75222 atomic_t *v = (atomic_t *)l;
75223 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
75224 atomic_add(i, v);
75225 }
75226
75227 +#ifdef CONFIG_PAX_REFCOUNT
75228 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
75229 +{
75230 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75231 +
75232 + atomic_add_unchecked(i, v);
75233 +}
75234 +#endif
75235 +
75236 static inline void atomic_long_sub(long i, atomic_long_t *l)
75237 {
75238 atomic_t *v = (atomic_t *)l;
75239 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
75240 atomic_sub(i, v);
75241 }
75242
75243 +#ifdef CONFIG_PAX_REFCOUNT
75244 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
75245 +{
75246 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75247 +
75248 + atomic_sub_unchecked(i, v);
75249 +}
75250 +#endif
75251 +
75252 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
75253 {
75254 atomic_t *v = (atomic_t *)l;
75255 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
75256 return (long)atomic_add_return(i, v);
75257 }
75258
75259 +#ifdef CONFIG_PAX_REFCOUNT
75260 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
75261 +{
75262 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75263 +
75264 + return (long)atomic_add_return_unchecked(i, v);
75265 +}
75266 +
75267 +#endif
75268 +
75269 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
75270 {
75271 atomic_t *v = (atomic_t *)l;
75272 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
75273 return (long)atomic_inc_return(v);
75274 }
75275
75276 +#ifdef CONFIG_PAX_REFCOUNT
75277 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
75278 +{
75279 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75280 +
75281 + return (long)atomic_inc_return_unchecked(v);
75282 +}
75283 +#endif
75284 +
75285 static inline long atomic_long_dec_return(atomic_long_t *l)
75286 {
75287 atomic_t *v = (atomic_t *)l;
75288 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
75289
75290 #endif /* BITS_PER_LONG == 64 */
75291
75292 +#ifdef CONFIG_PAX_REFCOUNT
75293 +static inline void pax_refcount_needs_these_functions(void)
75294 +{
75295 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
75296 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
75297 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
75298 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
75299 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
75300 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
75301 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
75302 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
75303 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
75304 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
75305 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
75306 +#ifdef CONFIG_X86
75307 + atomic_clear_mask_unchecked(0, NULL);
75308 + atomic_set_mask_unchecked(0, NULL);
75309 +#endif
75310 +
75311 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
75312 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
75313 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
75314 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
75315 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
75316 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
75317 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
75318 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
75319 +}
75320 +#else
75321 +#define atomic_read_unchecked(v) atomic_read(v)
75322 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
75323 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
75324 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
75325 +#define atomic_inc_unchecked(v) atomic_inc(v)
75326 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
75327 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
75328 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
75329 +#define atomic_dec_unchecked(v) atomic_dec(v)
75330 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
75331 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
75332 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
75333 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
75334 +
75335 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
75336 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
75337 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
75338 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
75339 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
75340 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
75341 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
75342 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
75343 +#endif
75344 +
75345 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
75346 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
75347 index 33bd2de..f31bff97 100644
75348 --- a/include/asm-generic/atomic.h
75349 +++ b/include/asm-generic/atomic.h
75350 @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
75351 * Atomically clears the bits set in @mask from @v
75352 */
75353 #ifndef atomic_clear_mask
75354 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
75355 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
75356 {
75357 unsigned long flags;
75358
75359 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
75360 index b18ce4f..2ee2843 100644
75361 --- a/include/asm-generic/atomic64.h
75362 +++ b/include/asm-generic/atomic64.h
75363 @@ -16,6 +16,8 @@ typedef struct {
75364 long long counter;
75365 } atomic64_t;
75366
75367 +typedef atomic64_t atomic64_unchecked_t;
75368 +
75369 #define ATOMIC64_INIT(i) { (i) }
75370
75371 extern long long atomic64_read(const atomic64_t *v);
75372 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
75373 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
75374 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
75375
75376 +#define atomic64_read_unchecked(v) atomic64_read(v)
75377 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
75378 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
75379 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
75380 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
75381 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
75382 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
75383 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
75384 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
75385 +
75386 #endif /* _ASM_GENERIC_ATOMIC64_H */
75387 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
75388 index a60a7cc..0fe12f2 100644
75389 --- a/include/asm-generic/bitops/__fls.h
75390 +++ b/include/asm-generic/bitops/__fls.h
75391 @@ -9,7 +9,7 @@
75392 *
75393 * Undefined if no set bit exists, so code should check against 0 first.
75394 */
75395 -static __always_inline unsigned long __fls(unsigned long word)
75396 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
75397 {
75398 int num = BITS_PER_LONG - 1;
75399
75400 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
75401 index 0576d1f..dad6c71 100644
75402 --- a/include/asm-generic/bitops/fls.h
75403 +++ b/include/asm-generic/bitops/fls.h
75404 @@ -9,7 +9,7 @@
75405 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
75406 */
75407
75408 -static __always_inline int fls(int x)
75409 +static __always_inline int __intentional_overflow(-1) fls(int x)
75410 {
75411 int r = 32;
75412
75413 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
75414 index b097cf8..3d40e14 100644
75415 --- a/include/asm-generic/bitops/fls64.h
75416 +++ b/include/asm-generic/bitops/fls64.h
75417 @@ -15,7 +15,7 @@
75418 * at position 64.
75419 */
75420 #if BITS_PER_LONG == 32
75421 -static __always_inline int fls64(__u64 x)
75422 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
75423 {
75424 __u32 h = x >> 32;
75425 if (h)
75426 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
75427 return fls(x);
75428 }
75429 #elif BITS_PER_LONG == 64
75430 -static __always_inline int fls64(__u64 x)
75431 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
75432 {
75433 if (x == 0)
75434 return 0;
75435 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
75436 index 1bfcfe5..e04c5c9 100644
75437 --- a/include/asm-generic/cache.h
75438 +++ b/include/asm-generic/cache.h
75439 @@ -6,7 +6,7 @@
75440 * cache lines need to provide their own cache.h.
75441 */
75442
75443 -#define L1_CACHE_SHIFT 5
75444 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
75445 +#define L1_CACHE_SHIFT 5UL
75446 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
75447
75448 #endif /* __ASM_GENERIC_CACHE_H */
75449 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
75450 index 0d68a1e..b74a761 100644
75451 --- a/include/asm-generic/emergency-restart.h
75452 +++ b/include/asm-generic/emergency-restart.h
75453 @@ -1,7 +1,7 @@
75454 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
75455 #define _ASM_GENERIC_EMERGENCY_RESTART_H
75456
75457 -static inline void machine_emergency_restart(void)
75458 +static inline __noreturn void machine_emergency_restart(void)
75459 {
75460 machine_restart(NULL);
75461 }
75462 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
75463 index 90f99c7..00ce236 100644
75464 --- a/include/asm-generic/kmap_types.h
75465 +++ b/include/asm-generic/kmap_types.h
75466 @@ -2,9 +2,9 @@
75467 #define _ASM_GENERIC_KMAP_TYPES_H
75468
75469 #ifdef __WITH_KM_FENCE
75470 -# define KM_TYPE_NR 41
75471 +# define KM_TYPE_NR 42
75472 #else
75473 -# define KM_TYPE_NR 20
75474 +# define KM_TYPE_NR 21
75475 #endif
75476
75477 #endif
75478 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
75479 index 9ceb03b..62b0b8f 100644
75480 --- a/include/asm-generic/local.h
75481 +++ b/include/asm-generic/local.h
75482 @@ -23,24 +23,37 @@ typedef struct
75483 atomic_long_t a;
75484 } local_t;
75485
75486 +typedef struct {
75487 + atomic_long_unchecked_t a;
75488 +} local_unchecked_t;
75489 +
75490 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
75491
75492 #define local_read(l) atomic_long_read(&(l)->a)
75493 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
75494 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
75495 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
75496 #define local_inc(l) atomic_long_inc(&(l)->a)
75497 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
75498 #define local_dec(l) atomic_long_dec(&(l)->a)
75499 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
75500 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
75501 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
75502 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
75503 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
75504
75505 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
75506 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
75507 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
75508 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
75509 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
75510 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
75511 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
75512 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
75513 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
75514
75515 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
75516 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
75517 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
75518 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
75519 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
75520 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
75521 index 725612b..9cc513a 100644
75522 --- a/include/asm-generic/pgtable-nopmd.h
75523 +++ b/include/asm-generic/pgtable-nopmd.h
75524 @@ -1,14 +1,19 @@
75525 #ifndef _PGTABLE_NOPMD_H
75526 #define _PGTABLE_NOPMD_H
75527
75528 -#ifndef __ASSEMBLY__
75529 -
75530 #include <asm-generic/pgtable-nopud.h>
75531
75532 -struct mm_struct;
75533 -
75534 #define __PAGETABLE_PMD_FOLDED
75535
75536 +#define PMD_SHIFT PUD_SHIFT
75537 +#define PTRS_PER_PMD 1
75538 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
75539 +#define PMD_MASK (~(PMD_SIZE-1))
75540 +
75541 +#ifndef __ASSEMBLY__
75542 +
75543 +struct mm_struct;
75544 +
75545 /*
75546 * Having the pmd type consist of a pud gets the size right, and allows
75547 * us to conceptually access the pud entry that this pmd is folded into
75548 @@ -16,11 +21,6 @@ struct mm_struct;
75549 */
75550 typedef struct { pud_t pud; } pmd_t;
75551
75552 -#define PMD_SHIFT PUD_SHIFT
75553 -#define PTRS_PER_PMD 1
75554 -#define PMD_SIZE (1UL << PMD_SHIFT)
75555 -#define PMD_MASK (~(PMD_SIZE-1))
75556 -
75557 /*
75558 * The "pud_xxx()" functions here are trivial for a folded two-level
75559 * setup: the pmd is never bad, and a pmd always exists (as it's folded
75560 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
75561 index 810431d..0ec4804f 100644
75562 --- a/include/asm-generic/pgtable-nopud.h
75563 +++ b/include/asm-generic/pgtable-nopud.h
75564 @@ -1,10 +1,15 @@
75565 #ifndef _PGTABLE_NOPUD_H
75566 #define _PGTABLE_NOPUD_H
75567
75568 -#ifndef __ASSEMBLY__
75569 -
75570 #define __PAGETABLE_PUD_FOLDED
75571
75572 +#define PUD_SHIFT PGDIR_SHIFT
75573 +#define PTRS_PER_PUD 1
75574 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
75575 +#define PUD_MASK (~(PUD_SIZE-1))
75576 +
75577 +#ifndef __ASSEMBLY__
75578 +
75579 /*
75580 * Having the pud type consist of a pgd gets the size right, and allows
75581 * us to conceptually access the pgd entry that this pud is folded into
75582 @@ -12,11 +17,6 @@
75583 */
75584 typedef struct { pgd_t pgd; } pud_t;
75585
75586 -#define PUD_SHIFT PGDIR_SHIFT
75587 -#define PTRS_PER_PUD 1
75588 -#define PUD_SIZE (1UL << PUD_SHIFT)
75589 -#define PUD_MASK (~(PUD_SIZE-1))
75590 -
75591 /*
75592 * The "pgd_xxx()" functions here are trivial for a folded two-level
75593 * setup: the pud is never bad, and a pud always exists (as it's folded
75594 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
75595 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
75596
75597 #define pgd_populate(mm, pgd, pud) do { } while (0)
75598 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
75599 /*
75600 * (puds are folded into pgds so this doesn't get actually called,
75601 * but the define is needed for a generic inline function.)
75602 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
75603 index db09234..86683e3 100644
75604 --- a/include/asm-generic/pgtable.h
75605 +++ b/include/asm-generic/pgtable.h
75606 @@ -736,6 +736,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
75607 }
75608 #endif /* CONFIG_NUMA_BALANCING */
75609
75610 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
75611 +#ifdef CONFIG_PAX_KERNEXEC
75612 +#error KERNEXEC requires pax_open_kernel
75613 +#else
75614 +static inline unsigned long pax_open_kernel(void) { return 0; }
75615 +#endif
75616 +#endif
75617 +
75618 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
75619 +#ifdef CONFIG_PAX_KERNEXEC
75620 +#error KERNEXEC requires pax_close_kernel
75621 +#else
75622 +static inline unsigned long pax_close_kernel(void) { return 0; }
75623 +#endif
75624 +#endif
75625 +
75626 #endif /* CONFIG_MMU */
75627
75628 #endif /* !__ASSEMBLY__ */
75629 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
75630 index dc1269c..48a4f51 100644
75631 --- a/include/asm-generic/uaccess.h
75632 +++ b/include/asm-generic/uaccess.h
75633 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
75634 return __clear_user(to, n);
75635 }
75636
75637 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
75638 +#ifdef CONFIG_PAX_MEMORY_UDEREF
75639 +#error UDEREF requires pax_open_userland
75640 +#else
75641 +static inline unsigned long pax_open_userland(void) { return 0; }
75642 +#endif
75643 +#endif
75644 +
75645 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
75646 +#ifdef CONFIG_PAX_MEMORY_UDEREF
75647 +#error UDEREF requires pax_close_userland
75648 +#else
75649 +static inline unsigned long pax_close_userland(void) { return 0; }
75650 +#endif
75651 +#endif
75652 +
75653 #endif /* __ASM_GENERIC_UACCESS_H */
75654 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
75655 index bc2121f..2f41f9a 100644
75656 --- a/include/asm-generic/vmlinux.lds.h
75657 +++ b/include/asm-generic/vmlinux.lds.h
75658 @@ -232,6 +232,7 @@
75659 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
75660 VMLINUX_SYMBOL(__start_rodata) = .; \
75661 *(.rodata) *(.rodata.*) \
75662 + *(.data..read_only) \
75663 *(__vermagic) /* Kernel version magic */ \
75664 . = ALIGN(8); \
75665 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
75666 @@ -716,17 +717,18 @@
75667 * section in the linker script will go there too. @phdr should have
75668 * a leading colon.
75669 *
75670 - * Note that this macros defines __per_cpu_load as an absolute symbol.
75671 + * Note that this macros defines per_cpu_load as an absolute symbol.
75672 * If there is no need to put the percpu section at a predetermined
75673 * address, use PERCPU_SECTION.
75674 */
75675 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
75676 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
75677 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
75678 + per_cpu_load = .; \
75679 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
75680 - LOAD_OFFSET) { \
75681 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
75682 PERCPU_INPUT(cacheline) \
75683 } phdr \
75684 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
75685 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
75686
75687 /**
75688 * PERCPU_SECTION - define output section for percpu area, simple version
75689 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
75690 index e73c19e..5b89e00 100644
75691 --- a/include/crypto/algapi.h
75692 +++ b/include/crypto/algapi.h
75693 @@ -34,7 +34,7 @@ struct crypto_type {
75694 unsigned int maskclear;
75695 unsigned int maskset;
75696 unsigned int tfmsize;
75697 -};
75698 +} __do_const;
75699
75700 struct crypto_instance {
75701 struct crypto_alg alg;
75702 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
75703 index 1d4a920..53a3229 100644
75704 --- a/include/drm/drmP.h
75705 +++ b/include/drm/drmP.h
75706 @@ -66,6 +66,7 @@
75707 #include <linux/workqueue.h>
75708 #include <linux/poll.h>
75709 #include <asm/pgalloc.h>
75710 +#include <asm/local.h>
75711 #include <drm/drm.h>
75712 #include <drm/drm_sarea.h>
75713 #include <drm/drm_vma_manager.h>
75714 @@ -278,10 +279,12 @@ do { \
75715 * \param cmd command.
75716 * \param arg argument.
75717 */
75718 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
75719 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
75720 + struct drm_file *file_priv);
75721 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
75722 struct drm_file *file_priv);
75723
75724 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
75725 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
75726 unsigned long arg);
75727
75728 #define DRM_IOCTL_NR(n) _IOC_NR(n)
75729 @@ -297,10 +300,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
75730 struct drm_ioctl_desc {
75731 unsigned int cmd;
75732 int flags;
75733 - drm_ioctl_t *func;
75734 + drm_ioctl_t func;
75735 unsigned int cmd_drv;
75736 const char *name;
75737 -};
75738 +} __do_const;
75739
75740 /**
75741 * Creates a driver or general drm_ioctl_desc array entry for the given
75742 @@ -1013,7 +1016,7 @@ struct drm_info_list {
75743 int (*show)(struct seq_file*, void*); /** show callback */
75744 u32 driver_features; /**< Required driver features for this entry */
75745 void *data;
75746 -};
75747 +} __do_const;
75748
75749 /**
75750 * debugfs node structure. This structure represents a debugfs file.
75751 @@ -1097,7 +1100,7 @@ struct drm_device {
75752
75753 /** \name Usage Counters */
75754 /*@{ */
75755 - int open_count; /**< Outstanding files open */
75756 + local_t open_count; /**< Outstanding files open */
75757 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
75758 atomic_t vma_count; /**< Outstanding vma areas open */
75759 int buf_use; /**< Buffers in use -- cannot alloc */
75760 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
75761 index ef6ad3a..be34b16 100644
75762 --- a/include/drm/drm_crtc_helper.h
75763 +++ b/include/drm/drm_crtc_helper.h
75764 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
75765 struct drm_connector *connector);
75766 /* disable encoder when not in use - more explicit than dpms off */
75767 void (*disable)(struct drm_encoder *encoder);
75768 -};
75769 +} __no_const;
75770
75771 /**
75772 * drm_connector_helper_funcs - helper operations for connectors
75773 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
75774 index 940ece4..8cb727f 100644
75775 --- a/include/drm/i915_pciids.h
75776 +++ b/include/drm/i915_pciids.h
75777 @@ -37,7 +37,7 @@
75778 */
75779 #define INTEL_VGA_DEVICE(id, info) { \
75780 0x8086, id, \
75781 - ~0, ~0, \
75782 + PCI_ANY_ID, PCI_ANY_ID, \
75783 0x030000, 0xff0000, \
75784 (unsigned long) info }
75785
75786 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
75787 index 72dcbe8..8db58d7 100644
75788 --- a/include/drm/ttm/ttm_memory.h
75789 +++ b/include/drm/ttm/ttm_memory.h
75790 @@ -48,7 +48,7 @@
75791
75792 struct ttm_mem_shrink {
75793 int (*do_shrink) (struct ttm_mem_shrink *);
75794 -};
75795 +} __no_const;
75796
75797 /**
75798 * struct ttm_mem_global - Global memory accounting structure.
75799 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
75800 index 4b840e8..155d235 100644
75801 --- a/include/keys/asymmetric-subtype.h
75802 +++ b/include/keys/asymmetric-subtype.h
75803 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
75804 /* Verify the signature on a key of this subtype (optional) */
75805 int (*verify_signature)(const struct key *key,
75806 const struct public_key_signature *sig);
75807 -};
75808 +} __do_const;
75809
75810 /**
75811 * asymmetric_key_subtype - Get the subtype from an asymmetric key
75812 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
75813 index c1da539..1dcec55 100644
75814 --- a/include/linux/atmdev.h
75815 +++ b/include/linux/atmdev.h
75816 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
75817 #endif
75818
75819 struct k_atm_aal_stats {
75820 -#define __HANDLE_ITEM(i) atomic_t i
75821 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
75822 __AAL_STAT_ITEMS
75823 #undef __HANDLE_ITEM
75824 };
75825 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
75826 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
75827 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
75828 struct module *owner;
75829 -};
75830 +} __do_const ;
75831
75832 struct atmphy_ops {
75833 int (*start)(struct atm_dev *dev);
75834 diff --git a/include/linux/audit.h b/include/linux/audit.h
75835 index a406419..c2bb164 100644
75836 --- a/include/linux/audit.h
75837 +++ b/include/linux/audit.h
75838 @@ -195,7 +195,7 @@ static inline void audit_ptrace(struct task_struct *t)
75839 extern unsigned int audit_serial(void);
75840 extern int auditsc_get_stamp(struct audit_context *ctx,
75841 struct timespec *t, unsigned int *serial);
75842 -extern int audit_set_loginuid(kuid_t loginuid);
75843 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
75844
75845 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
75846 {
75847 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
75848 index fd8bf32..2cccd5a 100644
75849 --- a/include/linux/binfmts.h
75850 +++ b/include/linux/binfmts.h
75851 @@ -74,8 +74,10 @@ struct linux_binfmt {
75852 int (*load_binary)(struct linux_binprm *);
75853 int (*load_shlib)(struct file *);
75854 int (*core_dump)(struct coredump_params *cprm);
75855 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
75856 + void (*handle_mmap)(struct file *);
75857 unsigned long min_coredump; /* minimal dump size */
75858 -};
75859 +} __do_const;
75860
75861 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
75862
75863 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
75864 index abc9ca7..e54ee27 100644
75865 --- a/include/linux/bitops.h
75866 +++ b/include/linux/bitops.h
75867 @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
75868 * @word: value to rotate
75869 * @shift: bits to roll
75870 */
75871 -static inline __u32 rol32(__u32 word, unsigned int shift)
75872 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
75873 {
75874 return (word << shift) | (word >> (32 - shift));
75875 }
75876 @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
75877 * @word: value to rotate
75878 * @shift: bits to roll
75879 */
75880 -static inline __u32 ror32(__u32 word, unsigned int shift)
75881 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
75882 {
75883 return (word >> shift) | (word << (32 - shift));
75884 }
75885 @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
75886 return (__s32)(value << shift) >> shift;
75887 }
75888
75889 -static inline unsigned fls_long(unsigned long l)
75890 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
75891 {
75892 if (sizeof(l) == 4)
75893 return fls(l);
75894 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
75895 index 1b135d4..59fc876 100644
75896 --- a/include/linux/blkdev.h
75897 +++ b/include/linux/blkdev.h
75898 @@ -1578,7 +1578,7 @@ struct block_device_operations {
75899 /* this callback is with swap_lock and sometimes page table lock held */
75900 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
75901 struct module *owner;
75902 -};
75903 +} __do_const;
75904
75905 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
75906 unsigned long);
75907 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
75908 index afc1343..9735539 100644
75909 --- a/include/linux/blktrace_api.h
75910 +++ b/include/linux/blktrace_api.h
75911 @@ -25,7 +25,7 @@ struct blk_trace {
75912 struct dentry *dropped_file;
75913 struct dentry *msg_file;
75914 struct list_head running_list;
75915 - atomic_t dropped;
75916 + atomic_unchecked_t dropped;
75917 };
75918
75919 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
75920 diff --git a/include/linux/cache.h b/include/linux/cache.h
75921 index 4c57065..40346da 100644
75922 --- a/include/linux/cache.h
75923 +++ b/include/linux/cache.h
75924 @@ -16,6 +16,14 @@
75925 #define __read_mostly
75926 #endif
75927
75928 +#ifndef __read_only
75929 +#ifdef CONFIG_PAX_KERNEXEC
75930 +#error KERNEXEC requires __read_only
75931 +#else
75932 +#define __read_only __read_mostly
75933 +#endif
75934 +#endif
75935 +
75936 #ifndef ____cacheline_aligned
75937 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
75938 #endif
75939 diff --git a/include/linux/capability.h b/include/linux/capability.h
75940 index a6ee1f9..e1ca49d 100644
75941 --- a/include/linux/capability.h
75942 +++ b/include/linux/capability.h
75943 @@ -212,8 +212,13 @@ extern bool capable(int cap);
75944 extern bool ns_capable(struct user_namespace *ns, int cap);
75945 extern bool inode_capable(const struct inode *inode, int cap);
75946 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
75947 +extern bool capable_nolog(int cap);
75948 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
75949 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
75950
75951 /* audit system wants to get cap info from files as well */
75952 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
75953
75954 +extern int is_privileged_binary(const struct dentry *dentry);
75955 +
75956 #endif /* !_LINUX_CAPABILITY_H */
75957 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
75958 index 8609d57..86e4d79 100644
75959 --- a/include/linux/cdrom.h
75960 +++ b/include/linux/cdrom.h
75961 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
75962
75963 /* driver specifications */
75964 const int capability; /* capability flags */
75965 - int n_minors; /* number of active minor devices */
75966 /* handle uniform packets for scsi type devices (scsi,atapi) */
75967 int (*generic_packet) (struct cdrom_device_info *,
75968 struct packet_command *);
75969 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
75970 index 4ce9056..86caac6 100644
75971 --- a/include/linux/cleancache.h
75972 +++ b/include/linux/cleancache.h
75973 @@ -31,7 +31,7 @@ struct cleancache_ops {
75974 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
75975 void (*invalidate_inode)(int, struct cleancache_filekey);
75976 void (*invalidate_fs)(int);
75977 -};
75978 +} __no_const;
75979
75980 extern struct cleancache_ops *
75981 cleancache_register_ops(struct cleancache_ops *ops);
75982 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
75983 index 7e59253..d6e4cae 100644
75984 --- a/include/linux/clk-provider.h
75985 +++ b/include/linux/clk-provider.h
75986 @@ -141,6 +141,7 @@ struct clk_ops {
75987 unsigned long);
75988 void (*init)(struct clk_hw *hw);
75989 };
75990 +typedef struct clk_ops __no_const clk_ops_no_const;
75991
75992 /**
75993 * struct clk_init_data - holds init data that's common to all clocks and is
75994 diff --git a/include/linux/compat.h b/include/linux/compat.h
75995 index eb8a49d..6b66ed9 100644
75996 --- a/include/linux/compat.h
75997 +++ b/include/linux/compat.h
75998 @@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
75999 compat_size_t __user *len_ptr);
76000
76001 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
76002 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
76003 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
76004 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
76005 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
76006 compat_ssize_t msgsz, int msgflg);
76007 @@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
76008 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
76009 compat_ulong_t addr, compat_ulong_t data);
76010 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
76011 - compat_long_t addr, compat_long_t data);
76012 + compat_ulong_t addr, compat_ulong_t data);
76013
76014 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
76015 /*
76016 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
76017 index ded4299..ddcbe31 100644
76018 --- a/include/linux/compiler-gcc4.h
76019 +++ b/include/linux/compiler-gcc4.h
76020 @@ -39,9 +39,34 @@
76021 # define __compiletime_warning(message) __attribute__((warning(message)))
76022 # define __compiletime_error(message) __attribute__((error(message)))
76023 #endif /* __CHECKER__ */
76024 +
76025 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
76026 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
76027 +#define __bos0(ptr) __bos((ptr), 0)
76028 +#define __bos1(ptr) __bos((ptr), 1)
76029 #endif /* GCC_VERSION >= 40300 */
76030
76031 #if GCC_VERSION >= 40500
76032 +
76033 +#ifdef RANDSTRUCT_PLUGIN
76034 +#define __randomize_layout __attribute__((randomize_layout))
76035 +#define __no_randomize_layout __attribute__((no_randomize_layout))
76036 +#endif
76037 +
76038 +#ifdef CONSTIFY_PLUGIN
76039 +#define __no_const __attribute__((no_const))
76040 +#define __do_const __attribute__((do_const))
76041 +#endif
76042 +
76043 +#ifdef SIZE_OVERFLOW_PLUGIN
76044 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
76045 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
76046 +#endif
76047 +
76048 +#ifdef LATENT_ENTROPY_PLUGIN
76049 +#define __latent_entropy __attribute__((latent_entropy))
76050 +#endif
76051 +
76052 /*
76053 * Mark a position in code as unreachable. This can be used to
76054 * suppress control flow warnings after asm blocks that transfer
76055 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
76056 index 92669cd..cc564c0 100644
76057 --- a/include/linux/compiler.h
76058 +++ b/include/linux/compiler.h
76059 @@ -5,11 +5,14 @@
76060
76061 #ifdef __CHECKER__
76062 # define __user __attribute__((noderef, address_space(1)))
76063 +# define __force_user __force __user
76064 # define __kernel __attribute__((address_space(0)))
76065 +# define __force_kernel __force __kernel
76066 # define __safe __attribute__((safe))
76067 # define __force __attribute__((force))
76068 # define __nocast __attribute__((nocast))
76069 # define __iomem __attribute__((noderef, address_space(2)))
76070 +# define __force_iomem __force __iomem
76071 # define __must_hold(x) __attribute__((context(x,1,1)))
76072 # define __acquires(x) __attribute__((context(x,0,1)))
76073 # define __releases(x) __attribute__((context(x,1,0)))
76074 @@ -17,20 +20,37 @@
76075 # define __release(x) __context__(x,-1)
76076 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
76077 # define __percpu __attribute__((noderef, address_space(3)))
76078 +# define __force_percpu __force __percpu
76079 #ifdef CONFIG_SPARSE_RCU_POINTER
76080 # define __rcu __attribute__((noderef, address_space(4)))
76081 +# define __force_rcu __force __rcu
76082 #else
76083 # define __rcu
76084 +# define __force_rcu
76085 #endif
76086 extern void __chk_user_ptr(const volatile void __user *);
76087 extern void __chk_io_ptr(const volatile void __iomem *);
76088 #else
76089 -# define __user
76090 -# define __kernel
76091 +# ifdef CHECKER_PLUGIN
76092 +//# define __user
76093 +//# define __force_user
76094 +//# define __kernel
76095 +//# define __force_kernel
76096 +# else
76097 +# ifdef STRUCTLEAK_PLUGIN
76098 +# define __user __attribute__((user))
76099 +# else
76100 +# define __user
76101 +# endif
76102 +# define __force_user
76103 +# define __kernel
76104 +# define __force_kernel
76105 +# endif
76106 # define __safe
76107 # define __force
76108 # define __nocast
76109 # define __iomem
76110 +# define __force_iomem
76111 # define __chk_user_ptr(x) (void)0
76112 # define __chk_io_ptr(x) (void)0
76113 # define __builtin_warning(x, y...) (1)
76114 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
76115 # define __release(x) (void)0
76116 # define __cond_lock(x,c) (c)
76117 # define __percpu
76118 +# define __force_percpu
76119 # define __rcu
76120 +# define __force_rcu
76121 #endif
76122
76123 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
76124 @@ -275,6 +297,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76125 # define __attribute_const__ /* unimplemented */
76126 #endif
76127
76128 +#ifndef __randomize_layout
76129 +# define __randomize_layout
76130 +#endif
76131 +
76132 +#ifndef __no_randomize_layout
76133 +# define __no_randomize_layout
76134 +#endif
76135 +
76136 +#ifndef __no_const
76137 +# define __no_const
76138 +#endif
76139 +
76140 +#ifndef __do_const
76141 +# define __do_const
76142 +#endif
76143 +
76144 +#ifndef __size_overflow
76145 +# define __size_overflow(...)
76146 +#endif
76147 +
76148 +#ifndef __intentional_overflow
76149 +# define __intentional_overflow(...)
76150 +#endif
76151 +
76152 +#ifndef __latent_entropy
76153 +# define __latent_entropy
76154 +#endif
76155 +
76156 /*
76157 * Tell gcc if a function is cold. The compiler will assume any path
76158 * directly leading to the call is unlikely.
76159 @@ -284,6 +334,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76160 #define __cold
76161 #endif
76162
76163 +#ifndef __alloc_size
76164 +#define __alloc_size(...)
76165 +#endif
76166 +
76167 +#ifndef __bos
76168 +#define __bos(ptr, arg)
76169 +#endif
76170 +
76171 +#ifndef __bos0
76172 +#define __bos0(ptr)
76173 +#endif
76174 +
76175 +#ifndef __bos1
76176 +#define __bos1(ptr)
76177 +#endif
76178 +
76179 /* Simple shorthand for a section definition */
76180 #ifndef __section
76181 # define __section(S) __attribute__ ((__section__(#S)))
76182 @@ -349,7 +415,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76183 * use is to mediate communication between process-level code and irq/NMI
76184 * handlers, all running on the same CPU.
76185 */
76186 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
76187 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
76188 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
76189
76190 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
76191 #ifdef CONFIG_KPROBES
76192 diff --git a/include/linux/completion.h b/include/linux/completion.h
76193 index 5d5aaae..0ea9b84 100644
76194 --- a/include/linux/completion.h
76195 +++ b/include/linux/completion.h
76196 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
76197
76198 extern void wait_for_completion(struct completion *);
76199 extern void wait_for_completion_io(struct completion *);
76200 -extern int wait_for_completion_interruptible(struct completion *x);
76201 -extern int wait_for_completion_killable(struct completion *x);
76202 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
76203 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
76204 extern unsigned long wait_for_completion_timeout(struct completion *x,
76205 - unsigned long timeout);
76206 + unsigned long timeout) __intentional_overflow(-1);
76207 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
76208 - unsigned long timeout);
76209 + unsigned long timeout) __intentional_overflow(-1);
76210 extern long wait_for_completion_interruptible_timeout(
76211 - struct completion *x, unsigned long timeout);
76212 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
76213 extern long wait_for_completion_killable_timeout(
76214 - struct completion *x, unsigned long timeout);
76215 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
76216 extern bool try_wait_for_completion(struct completion *x);
76217 extern bool completion_done(struct completion *x);
76218
76219 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
76220 index 34025df..d94bbbc 100644
76221 --- a/include/linux/configfs.h
76222 +++ b/include/linux/configfs.h
76223 @@ -125,7 +125,7 @@ struct configfs_attribute {
76224 const char *ca_name;
76225 struct module *ca_owner;
76226 umode_t ca_mode;
76227 -};
76228 +} __do_const;
76229
76230 /*
76231 * Users often need to create attribute structures for their configurable
76232 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
76233 index dc196bb..c55a50f 100644
76234 --- a/include/linux/cpufreq.h
76235 +++ b/include/linux/cpufreq.h
76236 @@ -189,6 +189,7 @@ struct global_attr {
76237 ssize_t (*store)(struct kobject *a, struct attribute *b,
76238 const char *c, size_t count);
76239 };
76240 +typedef struct global_attr __no_const global_attr_no_const;
76241
76242 #define define_one_global_ro(_name) \
76243 static struct global_attr _name = \
76244 @@ -225,7 +226,7 @@ struct cpufreq_driver {
76245 int (*suspend) (struct cpufreq_policy *policy);
76246 int (*resume) (struct cpufreq_policy *policy);
76247 struct freq_attr **attr;
76248 -};
76249 +} __do_const;
76250
76251 /* flags */
76252 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
76253 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
76254 index 50fcbb0..9d2dbd9 100644
76255 --- a/include/linux/cpuidle.h
76256 +++ b/include/linux/cpuidle.h
76257 @@ -50,7 +50,8 @@ struct cpuidle_state {
76258 int index);
76259
76260 int (*enter_dead) (struct cpuidle_device *dev, int index);
76261 -};
76262 +} __do_const;
76263 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
76264
76265 /* Idle State Flags */
76266 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
76267 @@ -192,7 +193,7 @@ struct cpuidle_governor {
76268 void (*reflect) (struct cpuidle_device *dev, int index);
76269
76270 struct module *owner;
76271 -};
76272 +} __do_const;
76273
76274 #ifdef CONFIG_CPU_IDLE
76275 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
76276 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
76277 index d08e4d2..95fad61 100644
76278 --- a/include/linux/cpumask.h
76279 +++ b/include/linux/cpumask.h
76280 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
76281 }
76282
76283 /* Valid inputs for n are -1 and 0. */
76284 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76285 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
76286 {
76287 return n+1;
76288 }
76289
76290 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76291 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
76292 {
76293 return n+1;
76294 }
76295
76296 -static inline unsigned int cpumask_next_and(int n,
76297 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
76298 const struct cpumask *srcp,
76299 const struct cpumask *andp)
76300 {
76301 @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
76302 *
76303 * Returns >= nr_cpu_ids if no further cpus set.
76304 */
76305 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76306 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
76307 {
76308 /* -1 is a legal arg here. */
76309 if (n != -1)
76310 @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76311 *
76312 * Returns >= nr_cpu_ids if no further cpus unset.
76313 */
76314 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76315 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
76316 {
76317 /* -1 is a legal arg here. */
76318 if (n != -1)
76319 @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76320 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
76321 }
76322
76323 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
76324 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
76325 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
76326
76327 /**
76328 diff --git a/include/linux/cred.h b/include/linux/cred.h
76329 index 04421e8..117e17a 100644
76330 --- a/include/linux/cred.h
76331 +++ b/include/linux/cred.h
76332 @@ -35,7 +35,7 @@ struct group_info {
76333 int nblocks;
76334 kgid_t small_block[NGROUPS_SMALL];
76335 kgid_t *blocks[0];
76336 -};
76337 +} __randomize_layout;
76338
76339 /**
76340 * get_group_info - Get a reference to a group info structure
76341 @@ -136,7 +136,7 @@ struct cred {
76342 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
76343 struct group_info *group_info; /* supplementary groups for euid/fsgid */
76344 struct rcu_head rcu; /* RCU deletion hook */
76345 -};
76346 +} __randomize_layout;
76347
76348 extern void __put_cred(struct cred *);
76349 extern void exit_creds(struct task_struct *);
76350 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
76351 static inline void validate_process_creds(void)
76352 {
76353 }
76354 +static inline void validate_task_creds(struct task_struct *task)
76355 +{
76356 +}
76357 #endif
76358
76359 /**
76360 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
76361 index b92eadf..b4ecdc1 100644
76362 --- a/include/linux/crypto.h
76363 +++ b/include/linux/crypto.h
76364 @@ -373,7 +373,7 @@ struct cipher_tfm {
76365 const u8 *key, unsigned int keylen);
76366 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
76367 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
76368 -};
76369 +} __no_const;
76370
76371 struct hash_tfm {
76372 int (*init)(struct hash_desc *desc);
76373 @@ -394,13 +394,13 @@ struct compress_tfm {
76374 int (*cot_decompress)(struct crypto_tfm *tfm,
76375 const u8 *src, unsigned int slen,
76376 u8 *dst, unsigned int *dlen);
76377 -};
76378 +} __no_const;
76379
76380 struct rng_tfm {
76381 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
76382 unsigned int dlen);
76383 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
76384 -};
76385 +} __no_const;
76386
76387 #define crt_ablkcipher crt_u.ablkcipher
76388 #define crt_aead crt_u.aead
76389 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
76390 index 653589e..4ef254a 100644
76391 --- a/include/linux/ctype.h
76392 +++ b/include/linux/ctype.h
76393 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
76394 * Fast implementation of tolower() for internal usage. Do not use in your
76395 * code.
76396 */
76397 -static inline char _tolower(const char c)
76398 +static inline unsigned char _tolower(const unsigned char c)
76399 {
76400 return c | 0x20;
76401 }
76402 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
76403 index bf72e9a..4ca7927 100644
76404 --- a/include/linux/dcache.h
76405 +++ b/include/linux/dcache.h
76406 @@ -133,7 +133,7 @@ struct dentry {
76407 } d_u;
76408 struct list_head d_subdirs; /* our children */
76409 struct hlist_node d_alias; /* inode alias list */
76410 -};
76411 +} __randomize_layout;
76412
76413 /*
76414 * dentry->d_lock spinlock nesting subclasses:
76415 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
76416 index 7925bf0..d5143d2 100644
76417 --- a/include/linux/decompress/mm.h
76418 +++ b/include/linux/decompress/mm.h
76419 @@ -77,7 +77,7 @@ static void free(void *where)
76420 * warnings when not needed (indeed large_malloc / large_free are not
76421 * needed by inflate */
76422
76423 -#define malloc(a) kmalloc(a, GFP_KERNEL)
76424 +#define malloc(a) kmalloc((a), GFP_KERNEL)
76425 #define free(a) kfree(a)
76426
76427 #define large_malloc(a) vmalloc(a)
76428 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
76429 index d48dc00..211ee54 100644
76430 --- a/include/linux/devfreq.h
76431 +++ b/include/linux/devfreq.h
76432 @@ -114,7 +114,7 @@ struct devfreq_governor {
76433 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
76434 int (*event_handler)(struct devfreq *devfreq,
76435 unsigned int event, void *data);
76436 -};
76437 +} __do_const;
76438
76439 /**
76440 * struct devfreq - Device devfreq structure
76441 diff --git a/include/linux/device.h b/include/linux/device.h
76442 index 952b010..d5b7691 100644
76443 --- a/include/linux/device.h
76444 +++ b/include/linux/device.h
76445 @@ -310,7 +310,7 @@ struct subsys_interface {
76446 struct list_head node;
76447 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
76448 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
76449 -};
76450 +} __do_const;
76451
76452 int subsys_interface_register(struct subsys_interface *sif);
76453 void subsys_interface_unregister(struct subsys_interface *sif);
76454 @@ -506,7 +506,7 @@ struct device_type {
76455 void (*release)(struct device *dev);
76456
76457 const struct dev_pm_ops *pm;
76458 -};
76459 +} __do_const;
76460
76461 /* interface for exporting device attributes */
76462 struct device_attribute {
76463 @@ -516,11 +516,12 @@ struct device_attribute {
76464 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
76465 const char *buf, size_t count);
76466 };
76467 +typedef struct device_attribute __no_const device_attribute_no_const;
76468
76469 struct dev_ext_attribute {
76470 struct device_attribute attr;
76471 void *var;
76472 -};
76473 +} __do_const;
76474
76475 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
76476 char *buf);
76477 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
76478 index fd4aee2..1f28db9 100644
76479 --- a/include/linux/dma-mapping.h
76480 +++ b/include/linux/dma-mapping.h
76481 @@ -54,7 +54,7 @@ struct dma_map_ops {
76482 u64 (*get_required_mask)(struct device *dev);
76483 #endif
76484 int is_phys;
76485 -};
76486 +} __do_const;
76487
76488 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
76489
76490 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
76491 index 41cf0c3..f3b771c 100644
76492 --- a/include/linux/dmaengine.h
76493 +++ b/include/linux/dmaengine.h
76494 @@ -1114,9 +1114,9 @@ struct dma_pinned_list {
76495 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
76496 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
76497
76498 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
76499 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
76500 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
76501 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
76502 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
76503 struct dma_pinned_list *pinned_list, struct page *page,
76504 unsigned int offset, size_t len);
76505
76506 diff --git a/include/linux/efi.h b/include/linux/efi.h
76507 index 11ce678..7b8c69c 100644
76508 --- a/include/linux/efi.h
76509 +++ b/include/linux/efi.h
76510 @@ -764,6 +764,7 @@ struct efivar_operations {
76511 efi_set_variable_t *set_variable;
76512 efi_query_variable_store_t *query_variable_store;
76513 };
76514 +typedef struct efivar_operations __no_const efivar_operations_no_const;
76515
76516 struct efivars {
76517 /*
76518 diff --git a/include/linux/elf.h b/include/linux/elf.h
76519 index 67a5fa7..b817372 100644
76520 --- a/include/linux/elf.h
76521 +++ b/include/linux/elf.h
76522 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
76523 #define elf_note elf32_note
76524 #define elf_addr_t Elf32_Off
76525 #define Elf_Half Elf32_Half
76526 +#define elf_dyn Elf32_Dyn
76527
76528 #else
76529
76530 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
76531 #define elf_note elf64_note
76532 #define elf_addr_t Elf64_Off
76533 #define Elf_Half Elf64_Half
76534 +#define elf_dyn Elf64_Dyn
76535
76536 #endif
76537
76538 diff --git a/include/linux/err.h b/include/linux/err.h
76539 index 15f92e0..e825a8e 100644
76540 --- a/include/linux/err.h
76541 +++ b/include/linux/err.h
76542 @@ -19,12 +19,12 @@
76543
76544 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
76545
76546 -static inline void * __must_check ERR_PTR(long error)
76547 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
76548 {
76549 return (void *) error;
76550 }
76551
76552 -static inline long __must_check PTR_ERR(__force const void *ptr)
76553 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
76554 {
76555 return (long) ptr;
76556 }
76557 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
76558 index 21c59af..6057a03 100644
76559 --- a/include/linux/extcon.h
76560 +++ b/include/linux/extcon.h
76561 @@ -135,7 +135,7 @@ struct extcon_dev {
76562 /* /sys/class/extcon/.../mutually_exclusive/... */
76563 struct attribute_group attr_g_muex;
76564 struct attribute **attrs_muex;
76565 - struct device_attribute *d_attrs_muex;
76566 + device_attribute_no_const *d_attrs_muex;
76567 };
76568
76569 /**
76570 diff --git a/include/linux/fb.h b/include/linux/fb.h
76571 index 70c4836..ff3daec 100644
76572 --- a/include/linux/fb.h
76573 +++ b/include/linux/fb.h
76574 @@ -304,7 +304,7 @@ struct fb_ops {
76575 /* called at KDB enter and leave time to prepare the console */
76576 int (*fb_debug_enter)(struct fb_info *info);
76577 int (*fb_debug_leave)(struct fb_info *info);
76578 -};
76579 +} __do_const;
76580
76581 #ifdef CONFIG_FB_TILEBLITTING
76582 #define FB_TILE_CURSOR_NONE 0
76583 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
76584 index 085197b..0fa6f0b 100644
76585 --- a/include/linux/fdtable.h
76586 +++ b/include/linux/fdtable.h
76587 @@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
76588 void put_files_struct(struct files_struct *fs);
76589 void reset_files_struct(struct files_struct *);
76590 int unshare_files(struct files_struct **);
76591 -struct files_struct *dup_fd(struct files_struct *, int *);
76592 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
76593 void do_close_on_exec(struct files_struct *);
76594 int iterate_fd(struct files_struct *, unsigned,
76595 int (*)(const void *, struct file *, unsigned),
76596 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
76597 index 8293262..2b3b8bd 100644
76598 --- a/include/linux/frontswap.h
76599 +++ b/include/linux/frontswap.h
76600 @@ -11,7 +11,7 @@ struct frontswap_ops {
76601 int (*load)(unsigned, pgoff_t, struct page *);
76602 void (*invalidate_page)(unsigned, pgoff_t);
76603 void (*invalidate_area)(unsigned);
76604 -};
76605 +} __no_const;
76606
76607 extern bool frontswap_enabled;
76608 extern struct frontswap_ops *
76609 diff --git a/include/linux/fs.h b/include/linux/fs.h
76610 index 121f11f..0f2a863 100644
76611 --- a/include/linux/fs.h
76612 +++ b/include/linux/fs.h
76613 @@ -423,7 +423,7 @@ struct address_space {
76614 spinlock_t private_lock; /* for use by the address_space */
76615 struct list_head private_list; /* ditto */
76616 void *private_data; /* ditto */
76617 -} __attribute__((aligned(sizeof(long))));
76618 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
76619 /*
76620 * On most architectures that alignment is already the case; but
76621 * must be enforced here for CRIS, to let the least significant bit
76622 @@ -466,7 +466,7 @@ struct block_device {
76623 int bd_fsfreeze_count;
76624 /* Mutex for freeze */
76625 struct mutex bd_fsfreeze_mutex;
76626 -};
76627 +} __randomize_layout;
76628
76629 /*
76630 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
76631 @@ -610,7 +610,7 @@ struct inode {
76632 atomic_t i_readcount; /* struct files open RO */
76633 #endif
76634 void *i_private; /* fs or device private pointer */
76635 -};
76636 +} __randomize_layout;
76637
76638 static inline int inode_unhashed(struct inode *inode)
76639 {
76640 @@ -808,7 +808,7 @@ struct file {
76641 #ifdef CONFIG_DEBUG_WRITECOUNT
76642 unsigned long f_mnt_write_state;
76643 #endif
76644 -};
76645 +} __randomize_layout;
76646
76647 struct file_handle {
76648 __u32 handle_bytes;
76649 @@ -978,7 +978,7 @@ struct file_lock {
76650 int state; /* state of grant or error if -ve */
76651 } afs;
76652 } fl_u;
76653 -};
76654 +} __randomize_layout;
76655
76656 /* The following constant reflects the upper bound of the file/locking space */
76657 #ifndef OFFSET_MAX
76658 @@ -1325,7 +1325,7 @@ struct super_block {
76659 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
76660 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
76661 struct rcu_head rcu;
76662 -};
76663 +} __randomize_layout;
76664
76665 extern struct timespec current_fs_time(struct super_block *sb);
76666
76667 @@ -1547,7 +1547,8 @@ struct file_operations {
76668 long (*fallocate)(struct file *file, int mode, loff_t offset,
76669 loff_t len);
76670 int (*show_fdinfo)(struct seq_file *m, struct file *f);
76671 -};
76672 +} __do_const __randomize_layout;
76673 +typedef struct file_operations __no_const file_operations_no_const;
76674
76675 struct inode_operations {
76676 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
76677 @@ -2808,4 +2809,14 @@ static inline bool dir_relax(struct inode *inode)
76678 return !IS_DEADDIR(inode);
76679 }
76680
76681 +static inline bool is_sidechannel_device(const struct inode *inode)
76682 +{
76683 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
76684 + umode_t mode = inode->i_mode;
76685 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
76686 +#else
76687 + return false;
76688 +#endif
76689 +}
76690 +
76691 #endif /* _LINUX_FS_H */
76692 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
76693 index 0efc3e6..fd23610 100644
76694 --- a/include/linux/fs_struct.h
76695 +++ b/include/linux/fs_struct.h
76696 @@ -6,13 +6,13 @@
76697 #include <linux/seqlock.h>
76698
76699 struct fs_struct {
76700 - int users;
76701 + atomic_t users;
76702 spinlock_t lock;
76703 seqcount_t seq;
76704 int umask;
76705 int in_exec;
76706 struct path root, pwd;
76707 -};
76708 +} __randomize_layout;
76709
76710 extern struct kmem_cache *fs_cachep;
76711
76712 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
76713 index 7714849..a4a5c7a 100644
76714 --- a/include/linux/fscache-cache.h
76715 +++ b/include/linux/fscache-cache.h
76716 @@ -113,7 +113,7 @@ struct fscache_operation {
76717 fscache_operation_release_t release;
76718 };
76719
76720 -extern atomic_t fscache_op_debug_id;
76721 +extern atomic_unchecked_t fscache_op_debug_id;
76722 extern void fscache_op_work_func(struct work_struct *work);
76723
76724 extern void fscache_enqueue_operation(struct fscache_operation *);
76725 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
76726 INIT_WORK(&op->work, fscache_op_work_func);
76727 atomic_set(&op->usage, 1);
76728 op->state = FSCACHE_OP_ST_INITIALISED;
76729 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
76730 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
76731 op->processor = processor;
76732 op->release = release;
76733 INIT_LIST_HEAD(&op->pend_link);
76734 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
76735 index 115bb81..e7b812b 100644
76736 --- a/include/linux/fscache.h
76737 +++ b/include/linux/fscache.h
76738 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
76739 * - this is mandatory for any object that may have data
76740 */
76741 void (*now_uncached)(void *cookie_netfs_data);
76742 -};
76743 +} __do_const;
76744
76745 /*
76746 * fscache cached network filesystem type
76747 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
76748 index 1c804b0..1432c2b 100644
76749 --- a/include/linux/fsnotify.h
76750 +++ b/include/linux/fsnotify.h
76751 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
76752 struct inode *inode = file_inode(file);
76753 __u32 mask = FS_ACCESS;
76754
76755 + if (is_sidechannel_device(inode))
76756 + return;
76757 +
76758 if (S_ISDIR(inode->i_mode))
76759 mask |= FS_ISDIR;
76760
76761 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
76762 struct inode *inode = file_inode(file);
76763 __u32 mask = FS_MODIFY;
76764
76765 + if (is_sidechannel_device(inode))
76766 + return;
76767 +
76768 if (S_ISDIR(inode->i_mode))
76769 mask |= FS_ISDIR;
76770
76771 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
76772 */
76773 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
76774 {
76775 - return kstrdup(name, GFP_KERNEL);
76776 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
76777 }
76778
76779 /*
76780 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
76781 index 9f3c275..8bdff5d 100644
76782 --- a/include/linux/genhd.h
76783 +++ b/include/linux/genhd.h
76784 @@ -194,7 +194,7 @@ struct gendisk {
76785 struct kobject *slave_dir;
76786
76787 struct timer_rand_state *random;
76788 - atomic_t sync_io; /* RAID */
76789 + atomic_unchecked_t sync_io; /* RAID */
76790 struct disk_events *ev;
76791 #ifdef CONFIG_BLK_DEV_INTEGRITY
76792 struct blk_integrity *integrity;
76793 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
76794 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
76795
76796 /* drivers/char/random.c */
76797 -extern void add_disk_randomness(struct gendisk *disk);
76798 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
76799 extern void rand_initialize_disk(struct gendisk *disk);
76800
76801 static inline sector_t get_start_sect(struct block_device *bdev)
76802 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
76803 index c0894dd..2fbf10c 100644
76804 --- a/include/linux/genl_magic_func.h
76805 +++ b/include/linux/genl_magic_func.h
76806 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
76807 },
76808
76809 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
76810 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
76811 +static struct genl_ops ZZZ_genl_ops[] = {
76812 #include GENL_MAGIC_INCLUDE_FILE
76813 };
76814
76815 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
76816 index 9b4dd49..61fd41d 100644
76817 --- a/include/linux/gfp.h
76818 +++ b/include/linux/gfp.h
76819 @@ -35,6 +35,13 @@ struct vm_area_struct;
76820 #define ___GFP_NO_KSWAPD 0x400000u
76821 #define ___GFP_OTHER_NODE 0x800000u
76822 #define ___GFP_WRITE 0x1000000u
76823 +
76824 +#ifdef CONFIG_PAX_USERCOPY_SLABS
76825 +#define ___GFP_USERCOPY 0x2000000u
76826 +#else
76827 +#define ___GFP_USERCOPY 0
76828 +#endif
76829 +
76830 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
76831
76832 /*
76833 @@ -92,6 +99,7 @@ struct vm_area_struct;
76834 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
76835 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
76836 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
76837 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
76838
76839 /*
76840 * This may seem redundant, but it's a way of annotating false positives vs.
76841 @@ -99,7 +107,7 @@ struct vm_area_struct;
76842 */
76843 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
76844
76845 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
76846 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
76847 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
76848
76849 /* This equals 0, but use constants in case they ever change */
76850 @@ -153,6 +161,8 @@ struct vm_area_struct;
76851 /* 4GB DMA on some platforms */
76852 #define GFP_DMA32 __GFP_DMA32
76853
76854 +#define GFP_USERCOPY __GFP_USERCOPY
76855 +
76856 /* Convert GFP flags to their corresponding migrate type */
76857 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
76858 {
76859 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
76860 new file mode 100644
76861 index 0000000..edb2cb6
76862 --- /dev/null
76863 +++ b/include/linux/gracl.h
76864 @@ -0,0 +1,340 @@
76865 +#ifndef GR_ACL_H
76866 +#define GR_ACL_H
76867 +
76868 +#include <linux/grdefs.h>
76869 +#include <linux/resource.h>
76870 +#include <linux/capability.h>
76871 +#include <linux/dcache.h>
76872 +#include <asm/resource.h>
76873 +
76874 +/* Major status information */
76875 +
76876 +#define GR_VERSION "grsecurity 3.0"
76877 +#define GRSECURITY_VERSION 0x3000
76878 +
76879 +enum {
76880 + GR_SHUTDOWN = 0,
76881 + GR_ENABLE = 1,
76882 + GR_SPROLE = 2,
76883 + GR_OLDRELOAD = 3,
76884 + GR_SEGVMOD = 4,
76885 + GR_STATUS = 5,
76886 + GR_UNSPROLE = 6,
76887 + GR_PASSSET = 7,
76888 + GR_SPROLEPAM = 8,
76889 + GR_RELOAD = 9,
76890 +};
76891 +
76892 +/* Password setup definitions
76893 + * kernel/grhash.c */
76894 +enum {
76895 + GR_PW_LEN = 128,
76896 + GR_SALT_LEN = 16,
76897 + GR_SHA_LEN = 32,
76898 +};
76899 +
76900 +enum {
76901 + GR_SPROLE_LEN = 64,
76902 +};
76903 +
76904 +enum {
76905 + GR_NO_GLOB = 0,
76906 + GR_REG_GLOB,
76907 + GR_CREATE_GLOB
76908 +};
76909 +
76910 +#define GR_NLIMITS 32
76911 +
76912 +/* Begin Data Structures */
76913 +
76914 +struct sprole_pw {
76915 + unsigned char *rolename;
76916 + unsigned char salt[GR_SALT_LEN];
76917 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
76918 +};
76919 +
76920 +struct name_entry {
76921 + __u32 key;
76922 + ino_t inode;
76923 + dev_t device;
76924 + char *name;
76925 + __u16 len;
76926 + __u8 deleted;
76927 + struct name_entry *prev;
76928 + struct name_entry *next;
76929 +};
76930 +
76931 +struct inodev_entry {
76932 + struct name_entry *nentry;
76933 + struct inodev_entry *prev;
76934 + struct inodev_entry *next;
76935 +};
76936 +
76937 +struct acl_role_db {
76938 + struct acl_role_label **r_hash;
76939 + __u32 r_size;
76940 +};
76941 +
76942 +struct inodev_db {
76943 + struct inodev_entry **i_hash;
76944 + __u32 i_size;
76945 +};
76946 +
76947 +struct name_db {
76948 + struct name_entry **n_hash;
76949 + __u32 n_size;
76950 +};
76951 +
76952 +struct crash_uid {
76953 + uid_t uid;
76954 + unsigned long expires;
76955 +};
76956 +
76957 +struct gr_hash_struct {
76958 + void **table;
76959 + void **nametable;
76960 + void *first;
76961 + __u32 table_size;
76962 + __u32 used_size;
76963 + int type;
76964 +};
76965 +
76966 +/* Userspace Grsecurity ACL data structures */
76967 +
76968 +struct acl_subject_label {
76969 + char *filename;
76970 + ino_t inode;
76971 + dev_t device;
76972 + __u32 mode;
76973 + kernel_cap_t cap_mask;
76974 + kernel_cap_t cap_lower;
76975 + kernel_cap_t cap_invert_audit;
76976 +
76977 + struct rlimit res[GR_NLIMITS];
76978 + __u32 resmask;
76979 +
76980 + __u8 user_trans_type;
76981 + __u8 group_trans_type;
76982 + uid_t *user_transitions;
76983 + gid_t *group_transitions;
76984 + __u16 user_trans_num;
76985 + __u16 group_trans_num;
76986 +
76987 + __u32 sock_families[2];
76988 + __u32 ip_proto[8];
76989 + __u32 ip_type;
76990 + struct acl_ip_label **ips;
76991 + __u32 ip_num;
76992 + __u32 inaddr_any_override;
76993 +
76994 + __u32 crashes;
76995 + unsigned long expires;
76996 +
76997 + struct acl_subject_label *parent_subject;
76998 + struct gr_hash_struct *hash;
76999 + struct acl_subject_label *prev;
77000 + struct acl_subject_label *next;
77001 +
77002 + struct acl_object_label **obj_hash;
77003 + __u32 obj_hash_size;
77004 + __u16 pax_flags;
77005 +};
77006 +
77007 +struct role_allowed_ip {
77008 + __u32 addr;
77009 + __u32 netmask;
77010 +
77011 + struct role_allowed_ip *prev;
77012 + struct role_allowed_ip *next;
77013 +};
77014 +
77015 +struct role_transition {
77016 + char *rolename;
77017 +
77018 + struct role_transition *prev;
77019 + struct role_transition *next;
77020 +};
77021 +
77022 +struct acl_role_label {
77023 + char *rolename;
77024 + uid_t uidgid;
77025 + __u16 roletype;
77026 +
77027 + __u16 auth_attempts;
77028 + unsigned long expires;
77029 +
77030 + struct acl_subject_label *root_label;
77031 + struct gr_hash_struct *hash;
77032 +
77033 + struct acl_role_label *prev;
77034 + struct acl_role_label *next;
77035 +
77036 + struct role_transition *transitions;
77037 + struct role_allowed_ip *allowed_ips;
77038 + uid_t *domain_children;
77039 + __u16 domain_child_num;
77040 +
77041 + umode_t umask;
77042 +
77043 + struct acl_subject_label **subj_hash;
77044 + __u32 subj_hash_size;
77045 +};
77046 +
77047 +struct user_acl_role_db {
77048 + struct acl_role_label **r_table;
77049 + __u32 num_pointers; /* Number of allocations to track */
77050 + __u32 num_roles; /* Number of roles */
77051 + __u32 num_domain_children; /* Number of domain children */
77052 + __u32 num_subjects; /* Number of subjects */
77053 + __u32 num_objects; /* Number of objects */
77054 +};
77055 +
77056 +struct acl_object_label {
77057 + char *filename;
77058 + ino_t inode;
77059 + dev_t device;
77060 + __u32 mode;
77061 +
77062 + struct acl_subject_label *nested;
77063 + struct acl_object_label *globbed;
77064 +
77065 + /* next two structures not used */
77066 +
77067 + struct acl_object_label *prev;
77068 + struct acl_object_label *next;
77069 +};
77070 +
77071 +struct acl_ip_label {
77072 + char *iface;
77073 + __u32 addr;
77074 + __u32 netmask;
77075 + __u16 low, high;
77076 + __u8 mode;
77077 + __u32 type;
77078 + __u32 proto[8];
77079 +
77080 + /* next two structures not used */
77081 +
77082 + struct acl_ip_label *prev;
77083 + struct acl_ip_label *next;
77084 +};
77085 +
77086 +struct gr_arg {
77087 + struct user_acl_role_db role_db;
77088 + unsigned char pw[GR_PW_LEN];
77089 + unsigned char salt[GR_SALT_LEN];
77090 + unsigned char sum[GR_SHA_LEN];
77091 + unsigned char sp_role[GR_SPROLE_LEN];
77092 + struct sprole_pw *sprole_pws;
77093 + dev_t segv_device;
77094 + ino_t segv_inode;
77095 + uid_t segv_uid;
77096 + __u16 num_sprole_pws;
77097 + __u16 mode;
77098 +};
77099 +
77100 +struct gr_arg_wrapper {
77101 + struct gr_arg *arg;
77102 + __u32 version;
77103 + __u32 size;
77104 +};
77105 +
77106 +struct subject_map {
77107 + struct acl_subject_label *user;
77108 + struct acl_subject_label *kernel;
77109 + struct subject_map *prev;
77110 + struct subject_map *next;
77111 +};
77112 +
77113 +struct acl_subj_map_db {
77114 + struct subject_map **s_hash;
77115 + __u32 s_size;
77116 +};
77117 +
77118 +struct gr_policy_state {
77119 + struct sprole_pw **acl_special_roles;
77120 + __u16 num_sprole_pws;
77121 + struct acl_role_label *kernel_role;
77122 + struct acl_role_label *role_list;
77123 + struct acl_role_label *default_role;
77124 + struct acl_role_db acl_role_set;
77125 + struct acl_subj_map_db subj_map_set;
77126 + struct name_db name_set;
77127 + struct inodev_db inodev_set;
77128 +};
77129 +
77130 +struct gr_alloc_state {
77131 + unsigned long alloc_stack_next;
77132 + unsigned long alloc_stack_size;
77133 + void **alloc_stack;
77134 +};
77135 +
77136 +struct gr_reload_state {
77137 + struct gr_policy_state oldpolicy;
77138 + struct gr_alloc_state oldalloc;
77139 + struct gr_policy_state newpolicy;
77140 + struct gr_alloc_state newalloc;
77141 + struct gr_policy_state *oldpolicy_ptr;
77142 + struct gr_alloc_state *oldalloc_ptr;
77143 + unsigned char oldmode;
77144 +};
77145 +
77146 +/* End Data Structures Section */
77147 +
77148 +/* Hash functions generated by empirical testing by Brad Spengler
77149 + Makes good use of the low bits of the inode. Generally 0-1 times
77150 + in loop for successful match. 0-3 for unsuccessful match.
77151 + Shift/add algorithm with modulus of table size and an XOR*/
77152 +
77153 +static __inline__ unsigned int
77154 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
77155 +{
77156 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
77157 +}
77158 +
77159 + static __inline__ unsigned int
77160 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
77161 +{
77162 + return ((const unsigned long)userp % sz);
77163 +}
77164 +
77165 +static __inline__ unsigned int
77166 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
77167 +{
77168 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
77169 +}
77170 +
77171 +static __inline__ unsigned int
77172 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
77173 +{
77174 + return full_name_hash((const unsigned char *)name, len) % sz;
77175 +}
77176 +
77177 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
77178 + subj = NULL; \
77179 + iter = 0; \
77180 + while (iter < role->subj_hash_size) { \
77181 + if (subj == NULL) \
77182 + subj = role->subj_hash[iter]; \
77183 + if (subj == NULL) { \
77184 + iter++; \
77185 + continue; \
77186 + }
77187 +
77188 +#define FOR_EACH_SUBJECT_END(subj,iter) \
77189 + subj = subj->next; \
77190 + if (subj == NULL) \
77191 + iter++; \
77192 + }
77193 +
77194 +
77195 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
77196 + subj = role->hash->first; \
77197 + while (subj != NULL) {
77198 +
77199 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
77200 + subj = subj->next; \
77201 + }
77202 +
77203 +#endif
77204 +
77205 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
77206 new file mode 100644
77207 index 0000000..33ebd1f
77208 --- /dev/null
77209 +++ b/include/linux/gracl_compat.h
77210 @@ -0,0 +1,156 @@
77211 +#ifndef GR_ACL_COMPAT_H
77212 +#define GR_ACL_COMPAT_H
77213 +
77214 +#include <linux/resource.h>
77215 +#include <asm/resource.h>
77216 +
77217 +struct sprole_pw_compat {
77218 + compat_uptr_t rolename;
77219 + unsigned char salt[GR_SALT_LEN];
77220 + unsigned char sum[GR_SHA_LEN];
77221 +};
77222 +
77223 +struct gr_hash_struct_compat {
77224 + compat_uptr_t table;
77225 + compat_uptr_t nametable;
77226 + compat_uptr_t first;
77227 + __u32 table_size;
77228 + __u32 used_size;
77229 + int type;
77230 +};
77231 +
77232 +struct acl_subject_label_compat {
77233 + compat_uptr_t filename;
77234 + compat_ino_t inode;
77235 + __u32 device;
77236 + __u32 mode;
77237 + kernel_cap_t cap_mask;
77238 + kernel_cap_t cap_lower;
77239 + kernel_cap_t cap_invert_audit;
77240 +
77241 + struct compat_rlimit res[GR_NLIMITS];
77242 + __u32 resmask;
77243 +
77244 + __u8 user_trans_type;
77245 + __u8 group_trans_type;
77246 + compat_uptr_t user_transitions;
77247 + compat_uptr_t group_transitions;
77248 + __u16 user_trans_num;
77249 + __u16 group_trans_num;
77250 +
77251 + __u32 sock_families[2];
77252 + __u32 ip_proto[8];
77253 + __u32 ip_type;
77254 + compat_uptr_t ips;
77255 + __u32 ip_num;
77256 + __u32 inaddr_any_override;
77257 +
77258 + __u32 crashes;
77259 + compat_ulong_t expires;
77260 +
77261 + compat_uptr_t parent_subject;
77262 + compat_uptr_t hash;
77263 + compat_uptr_t prev;
77264 + compat_uptr_t next;
77265 +
77266 + compat_uptr_t obj_hash;
77267 + __u32 obj_hash_size;
77268 + __u16 pax_flags;
77269 +};
77270 +
77271 +struct role_allowed_ip_compat {
77272 + __u32 addr;
77273 + __u32 netmask;
77274 +
77275 + compat_uptr_t prev;
77276 + compat_uptr_t next;
77277 +};
77278 +
77279 +struct role_transition_compat {
77280 + compat_uptr_t rolename;
77281 +
77282 + compat_uptr_t prev;
77283 + compat_uptr_t next;
77284 +};
77285 +
77286 +struct acl_role_label_compat {
77287 + compat_uptr_t rolename;
77288 + uid_t uidgid;
77289 + __u16 roletype;
77290 +
77291 + __u16 auth_attempts;
77292 + compat_ulong_t expires;
77293 +
77294 + compat_uptr_t root_label;
77295 + compat_uptr_t hash;
77296 +
77297 + compat_uptr_t prev;
77298 + compat_uptr_t next;
77299 +
77300 + compat_uptr_t transitions;
77301 + compat_uptr_t allowed_ips;
77302 + compat_uptr_t domain_children;
77303 + __u16 domain_child_num;
77304 +
77305 + umode_t umask;
77306 +
77307 + compat_uptr_t subj_hash;
77308 + __u32 subj_hash_size;
77309 +};
77310 +
77311 +struct user_acl_role_db_compat {
77312 + compat_uptr_t r_table;
77313 + __u32 num_pointers;
77314 + __u32 num_roles;
77315 + __u32 num_domain_children;
77316 + __u32 num_subjects;
77317 + __u32 num_objects;
77318 +};
77319 +
77320 +struct acl_object_label_compat {
77321 + compat_uptr_t filename;
77322 + compat_ino_t inode;
77323 + __u32 device;
77324 + __u32 mode;
77325 +
77326 + compat_uptr_t nested;
77327 + compat_uptr_t globbed;
77328 +
77329 + compat_uptr_t prev;
77330 + compat_uptr_t next;
77331 +};
77332 +
77333 +struct acl_ip_label_compat {
77334 + compat_uptr_t iface;
77335 + __u32 addr;
77336 + __u32 netmask;
77337 + __u16 low, high;
77338 + __u8 mode;
77339 + __u32 type;
77340 + __u32 proto[8];
77341 +
77342 + compat_uptr_t prev;
77343 + compat_uptr_t next;
77344 +};
77345 +
77346 +struct gr_arg_compat {
77347 + struct user_acl_role_db_compat role_db;
77348 + unsigned char pw[GR_PW_LEN];
77349 + unsigned char salt[GR_SALT_LEN];
77350 + unsigned char sum[GR_SHA_LEN];
77351 + unsigned char sp_role[GR_SPROLE_LEN];
77352 + compat_uptr_t sprole_pws;
77353 + __u32 segv_device;
77354 + compat_ino_t segv_inode;
77355 + uid_t segv_uid;
77356 + __u16 num_sprole_pws;
77357 + __u16 mode;
77358 +};
77359 +
77360 +struct gr_arg_wrapper_compat {
77361 + compat_uptr_t arg;
77362 + __u32 version;
77363 + __u32 size;
77364 +};
77365 +
77366 +#endif
77367 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
77368 new file mode 100644
77369 index 0000000..323ecf2
77370 --- /dev/null
77371 +++ b/include/linux/gralloc.h
77372 @@ -0,0 +1,9 @@
77373 +#ifndef __GRALLOC_H
77374 +#define __GRALLOC_H
77375 +
77376 +void acl_free_all(void);
77377 +int acl_alloc_stack_init(unsigned long size);
77378 +void *acl_alloc(unsigned long len);
77379 +void *acl_alloc_num(unsigned long num, unsigned long len);
77380 +
77381 +#endif
77382 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
77383 new file mode 100644
77384 index 0000000..be66033
77385 --- /dev/null
77386 +++ b/include/linux/grdefs.h
77387 @@ -0,0 +1,140 @@
77388 +#ifndef GRDEFS_H
77389 +#define GRDEFS_H
77390 +
77391 +/* Begin grsecurity status declarations */
77392 +
77393 +enum {
77394 + GR_READY = 0x01,
77395 + GR_STATUS_INIT = 0x00 // disabled state
77396 +};
77397 +
77398 +/* Begin ACL declarations */
77399 +
77400 +/* Role flags */
77401 +
77402 +enum {
77403 + GR_ROLE_USER = 0x0001,
77404 + GR_ROLE_GROUP = 0x0002,
77405 + GR_ROLE_DEFAULT = 0x0004,
77406 + GR_ROLE_SPECIAL = 0x0008,
77407 + GR_ROLE_AUTH = 0x0010,
77408 + GR_ROLE_NOPW = 0x0020,
77409 + GR_ROLE_GOD = 0x0040,
77410 + GR_ROLE_LEARN = 0x0080,
77411 + GR_ROLE_TPE = 0x0100,
77412 + GR_ROLE_DOMAIN = 0x0200,
77413 + GR_ROLE_PAM = 0x0400,
77414 + GR_ROLE_PERSIST = 0x0800
77415 +};
77416 +
77417 +/* ACL Subject and Object mode flags */
77418 +enum {
77419 + GR_DELETED = 0x80000000
77420 +};
77421 +
77422 +/* ACL Object-only mode flags */
77423 +enum {
77424 + GR_READ = 0x00000001,
77425 + GR_APPEND = 0x00000002,
77426 + GR_WRITE = 0x00000004,
77427 + GR_EXEC = 0x00000008,
77428 + GR_FIND = 0x00000010,
77429 + GR_INHERIT = 0x00000020,
77430 + GR_SETID = 0x00000040,
77431 + GR_CREATE = 0x00000080,
77432 + GR_DELETE = 0x00000100,
77433 + GR_LINK = 0x00000200,
77434 + GR_AUDIT_READ = 0x00000400,
77435 + GR_AUDIT_APPEND = 0x00000800,
77436 + GR_AUDIT_WRITE = 0x00001000,
77437 + GR_AUDIT_EXEC = 0x00002000,
77438 + GR_AUDIT_FIND = 0x00004000,
77439 + GR_AUDIT_INHERIT= 0x00008000,
77440 + GR_AUDIT_SETID = 0x00010000,
77441 + GR_AUDIT_CREATE = 0x00020000,
77442 + GR_AUDIT_DELETE = 0x00040000,
77443 + GR_AUDIT_LINK = 0x00080000,
77444 + GR_PTRACERD = 0x00100000,
77445 + GR_NOPTRACE = 0x00200000,
77446 + GR_SUPPRESS = 0x00400000,
77447 + GR_NOLEARN = 0x00800000,
77448 + GR_INIT_TRANSFER= 0x01000000
77449 +};
77450 +
77451 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
77452 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
77453 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
77454 +
77455 +/* ACL subject-only mode flags */
77456 +enum {
77457 + GR_KILL = 0x00000001,
77458 + GR_VIEW = 0x00000002,
77459 + GR_PROTECTED = 0x00000004,
77460 + GR_LEARN = 0x00000008,
77461 + GR_OVERRIDE = 0x00000010,
77462 + /* just a placeholder, this mode is only used in userspace */
77463 + GR_DUMMY = 0x00000020,
77464 + GR_PROTSHM = 0x00000040,
77465 + GR_KILLPROC = 0x00000080,
77466 + GR_KILLIPPROC = 0x00000100,
77467 + /* just a placeholder, this mode is only used in userspace */
77468 + GR_NOTROJAN = 0x00000200,
77469 + GR_PROTPROCFD = 0x00000400,
77470 + GR_PROCACCT = 0x00000800,
77471 + GR_RELAXPTRACE = 0x00001000,
77472 + //GR_NESTED = 0x00002000,
77473 + GR_INHERITLEARN = 0x00004000,
77474 + GR_PROCFIND = 0x00008000,
77475 + GR_POVERRIDE = 0x00010000,
77476 + GR_KERNELAUTH = 0x00020000,
77477 + GR_ATSECURE = 0x00040000,
77478 + GR_SHMEXEC = 0x00080000
77479 +};
77480 +
77481 +enum {
77482 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
77483 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
77484 + GR_PAX_ENABLE_MPROTECT = 0x0004,
77485 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
77486 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
77487 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
77488 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
77489 + GR_PAX_DISABLE_MPROTECT = 0x0400,
77490 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
77491 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
77492 +};
77493 +
77494 +enum {
77495 + GR_ID_USER = 0x01,
77496 + GR_ID_GROUP = 0x02,
77497 +};
77498 +
77499 +enum {
77500 + GR_ID_ALLOW = 0x01,
77501 + GR_ID_DENY = 0x02,
77502 +};
77503 +
77504 +#define GR_CRASH_RES 31
77505 +#define GR_UIDTABLE_MAX 500
77506 +
77507 +/* begin resource learning section */
77508 +enum {
77509 + GR_RLIM_CPU_BUMP = 60,
77510 + GR_RLIM_FSIZE_BUMP = 50000,
77511 + GR_RLIM_DATA_BUMP = 10000,
77512 + GR_RLIM_STACK_BUMP = 1000,
77513 + GR_RLIM_CORE_BUMP = 10000,
77514 + GR_RLIM_RSS_BUMP = 500000,
77515 + GR_RLIM_NPROC_BUMP = 1,
77516 + GR_RLIM_NOFILE_BUMP = 5,
77517 + GR_RLIM_MEMLOCK_BUMP = 50000,
77518 + GR_RLIM_AS_BUMP = 500000,
77519 + GR_RLIM_LOCKS_BUMP = 2,
77520 + GR_RLIM_SIGPENDING_BUMP = 5,
77521 + GR_RLIM_MSGQUEUE_BUMP = 10000,
77522 + GR_RLIM_NICE_BUMP = 1,
77523 + GR_RLIM_RTPRIO_BUMP = 1,
77524 + GR_RLIM_RTTIME_BUMP = 1000000
77525 +};
77526 +
77527 +#endif
77528 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
77529 new file mode 100644
77530 index 0000000..d25522e
77531 --- /dev/null
77532 +++ b/include/linux/grinternal.h
77533 @@ -0,0 +1,229 @@
77534 +#ifndef __GRINTERNAL_H
77535 +#define __GRINTERNAL_H
77536 +
77537 +#ifdef CONFIG_GRKERNSEC
77538 +
77539 +#include <linux/fs.h>
77540 +#include <linux/mnt_namespace.h>
77541 +#include <linux/nsproxy.h>
77542 +#include <linux/gracl.h>
77543 +#include <linux/grdefs.h>
77544 +#include <linux/grmsg.h>
77545 +
77546 +void gr_add_learn_entry(const char *fmt, ...)
77547 + __attribute__ ((format (printf, 1, 2)));
77548 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
77549 + const struct vfsmount *mnt);
77550 +__u32 gr_check_create(const struct dentry *new_dentry,
77551 + const struct dentry *parent,
77552 + const struct vfsmount *mnt, const __u32 mode);
77553 +int gr_check_protected_task(const struct task_struct *task);
77554 +__u32 to_gr_audit(const __u32 reqmode);
77555 +int gr_set_acls(const int type);
77556 +int gr_acl_is_enabled(void);
77557 +char gr_roletype_to_char(void);
77558 +
77559 +void gr_handle_alertkill(struct task_struct *task);
77560 +char *gr_to_filename(const struct dentry *dentry,
77561 + const struct vfsmount *mnt);
77562 +char *gr_to_filename1(const struct dentry *dentry,
77563 + const struct vfsmount *mnt);
77564 +char *gr_to_filename2(const struct dentry *dentry,
77565 + const struct vfsmount *mnt);
77566 +char *gr_to_filename3(const struct dentry *dentry,
77567 + const struct vfsmount *mnt);
77568 +
77569 +extern int grsec_enable_ptrace_readexec;
77570 +extern int grsec_enable_harden_ptrace;
77571 +extern int grsec_enable_link;
77572 +extern int grsec_enable_fifo;
77573 +extern int grsec_enable_execve;
77574 +extern int grsec_enable_shm;
77575 +extern int grsec_enable_execlog;
77576 +extern int grsec_enable_signal;
77577 +extern int grsec_enable_audit_ptrace;
77578 +extern int grsec_enable_forkfail;
77579 +extern int grsec_enable_time;
77580 +extern int grsec_enable_rofs;
77581 +extern int grsec_deny_new_usb;
77582 +extern int grsec_enable_chroot_shmat;
77583 +extern int grsec_enable_chroot_mount;
77584 +extern int grsec_enable_chroot_double;
77585 +extern int grsec_enable_chroot_pivot;
77586 +extern int grsec_enable_chroot_chdir;
77587 +extern int grsec_enable_chroot_chmod;
77588 +extern int grsec_enable_chroot_mknod;
77589 +extern int grsec_enable_chroot_fchdir;
77590 +extern int grsec_enable_chroot_nice;
77591 +extern int grsec_enable_chroot_execlog;
77592 +extern int grsec_enable_chroot_caps;
77593 +extern int grsec_enable_chroot_sysctl;
77594 +extern int grsec_enable_chroot_unix;
77595 +extern int grsec_enable_symlinkown;
77596 +extern kgid_t grsec_symlinkown_gid;
77597 +extern int grsec_enable_tpe;
77598 +extern kgid_t grsec_tpe_gid;
77599 +extern int grsec_enable_tpe_all;
77600 +extern int grsec_enable_tpe_invert;
77601 +extern int grsec_enable_socket_all;
77602 +extern kgid_t grsec_socket_all_gid;
77603 +extern int grsec_enable_socket_client;
77604 +extern kgid_t grsec_socket_client_gid;
77605 +extern int grsec_enable_socket_server;
77606 +extern kgid_t grsec_socket_server_gid;
77607 +extern kgid_t grsec_audit_gid;
77608 +extern int grsec_enable_group;
77609 +extern int grsec_enable_log_rwxmaps;
77610 +extern int grsec_enable_mount;
77611 +extern int grsec_enable_chdir;
77612 +extern int grsec_resource_logging;
77613 +extern int grsec_enable_blackhole;
77614 +extern int grsec_lastack_retries;
77615 +extern int grsec_enable_brute;
77616 +extern int grsec_enable_harden_ipc;
77617 +extern int grsec_lock;
77618 +
77619 +extern spinlock_t grsec_alert_lock;
77620 +extern unsigned long grsec_alert_wtime;
77621 +extern unsigned long grsec_alert_fyet;
77622 +
77623 +extern spinlock_t grsec_audit_lock;
77624 +
77625 +extern rwlock_t grsec_exec_file_lock;
77626 +
77627 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
77628 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
77629 + (tsk)->exec_file->f_path.mnt) : "/")
77630 +
77631 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
77632 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
77633 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
77634 +
77635 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
77636 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
77637 + (tsk)->exec_file->f_path.mnt) : "/")
77638 +
77639 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
77640 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
77641 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
77642 +
77643 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
77644 +
77645 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
77646 +
77647 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
77648 +{
77649 + if (file1 && file2) {
77650 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
77651 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
77652 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
77653 + return true;
77654 + }
77655 +
77656 + return false;
77657 +}
77658 +
77659 +#define GR_CHROOT_CAPS {{ \
77660 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
77661 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
77662 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
77663 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
77664 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
77665 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
77666 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
77667 +
77668 +#define security_learn(normal_msg,args...) \
77669 +({ \
77670 + read_lock(&grsec_exec_file_lock); \
77671 + gr_add_learn_entry(normal_msg "\n", ## args); \
77672 + read_unlock(&grsec_exec_file_lock); \
77673 +})
77674 +
77675 +enum {
77676 + GR_DO_AUDIT,
77677 + GR_DONT_AUDIT,
77678 + /* used for non-audit messages that we shouldn't kill the task on */
77679 + GR_DONT_AUDIT_GOOD
77680 +};
77681 +
77682 +enum {
77683 + GR_TTYSNIFF,
77684 + GR_RBAC,
77685 + GR_RBAC_STR,
77686 + GR_STR_RBAC,
77687 + GR_RBAC_MODE2,
77688 + GR_RBAC_MODE3,
77689 + GR_FILENAME,
77690 + GR_SYSCTL_HIDDEN,
77691 + GR_NOARGS,
77692 + GR_ONE_INT,
77693 + GR_ONE_INT_TWO_STR,
77694 + GR_ONE_STR,
77695 + GR_STR_INT,
77696 + GR_TWO_STR_INT,
77697 + GR_TWO_INT,
77698 + GR_TWO_U64,
77699 + GR_THREE_INT,
77700 + GR_FIVE_INT_TWO_STR,
77701 + GR_TWO_STR,
77702 + GR_THREE_STR,
77703 + GR_FOUR_STR,
77704 + GR_STR_FILENAME,
77705 + GR_FILENAME_STR,
77706 + GR_FILENAME_TWO_INT,
77707 + GR_FILENAME_TWO_INT_STR,
77708 + GR_TEXTREL,
77709 + GR_PTRACE,
77710 + GR_RESOURCE,
77711 + GR_CAP,
77712 + GR_SIG,
77713 + GR_SIG2,
77714 + GR_CRASH1,
77715 + GR_CRASH2,
77716 + GR_PSACCT,
77717 + GR_RWXMAP,
77718 + GR_RWXMAPVMA
77719 +};
77720 +
77721 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
77722 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
77723 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
77724 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
77725 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
77726 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
77727 +#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)
77728 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
77729 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
77730 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
77731 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
77732 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
77733 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
77734 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
77735 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
77736 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
77737 +#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)
77738 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
77739 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
77740 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
77741 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
77742 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
77743 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
77744 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
77745 +#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)
77746 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
77747 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
77748 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
77749 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
77750 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
77751 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
77752 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
77753 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
77754 +#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)
77755 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
77756 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
77757 +
77758 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
77759 +
77760 +#endif
77761 +
77762 +#endif
77763 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
77764 new file mode 100644
77765 index 0000000..195cbe4
77766 --- /dev/null
77767 +++ b/include/linux/grmsg.h
77768 @@ -0,0 +1,115 @@
77769 +#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"
77770 +#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"
77771 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
77772 +#define GR_STOPMOD_MSG "denied modification of module state by "
77773 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
77774 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
77775 +#define GR_IOPERM_MSG "denied use of ioperm() by "
77776 +#define GR_IOPL_MSG "denied use of iopl() by "
77777 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
77778 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
77779 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
77780 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
77781 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
77782 +#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"
77783 +#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"
77784 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
77785 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
77786 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
77787 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
77788 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
77789 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
77790 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
77791 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
77792 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
77793 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
77794 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
77795 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
77796 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
77797 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
77798 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
77799 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
77800 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
77801 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
77802 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
77803 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
77804 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
77805 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
77806 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
77807 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
77808 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
77809 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
77810 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
77811 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
77812 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
77813 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
77814 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
77815 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
77816 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
77817 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
77818 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
77819 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
77820 +#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"
77821 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
77822 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
77823 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
77824 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
77825 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
77826 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
77827 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
77828 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
77829 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
77830 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
77831 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
77832 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
77833 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
77834 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
77835 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
77836 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
77837 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
77838 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
77839 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
77840 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
77841 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
77842 +#define GR_NICE_CHROOT_MSG "denied priority change by "
77843 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
77844 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
77845 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
77846 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
77847 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
77848 +#define GR_TIME_MSG "time set by "
77849 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
77850 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
77851 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
77852 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
77853 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
77854 +#define GR_BIND_MSG "denied bind() by "
77855 +#define GR_CONNECT_MSG "denied connect() by "
77856 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
77857 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
77858 +#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"
77859 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
77860 +#define GR_CAP_ACL_MSG "use of %s denied for "
77861 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
77862 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
77863 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
77864 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
77865 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
77866 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
77867 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
77868 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
77869 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
77870 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
77871 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
77872 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
77873 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
77874 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
77875 +#define GR_VM86_MSG "denied use of vm86 by "
77876 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
77877 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
77878 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
77879 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
77880 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
77881 +#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 "
77882 +#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 "
77883 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
77884 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
77885 new file mode 100644
77886 index 0000000..d8b5b48
77887 --- /dev/null
77888 +++ b/include/linux/grsecurity.h
77889 @@ -0,0 +1,245 @@
77890 +#ifndef GR_SECURITY_H
77891 +#define GR_SECURITY_H
77892 +#include <linux/fs.h>
77893 +#include <linux/fs_struct.h>
77894 +#include <linux/binfmts.h>
77895 +#include <linux/gracl.h>
77896 +
77897 +/* notify of brain-dead configs */
77898 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77899 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
77900 +#endif
77901 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
77902 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
77903 +#endif
77904 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
77905 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
77906 +#endif
77907 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
77908 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
77909 +#endif
77910 +
77911 +int gr_handle_new_usb(void);
77912 +
77913 +void gr_handle_brute_attach(int dumpable);
77914 +void gr_handle_brute_check(void);
77915 +void gr_handle_kernel_exploit(void);
77916 +
77917 +char gr_roletype_to_char(void);
77918 +
77919 +int gr_acl_enable_at_secure(void);
77920 +
77921 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
77922 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
77923 +
77924 +void gr_del_task_from_ip_table(struct task_struct *p);
77925 +
77926 +int gr_pid_is_chrooted(struct task_struct *p);
77927 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
77928 +int gr_handle_chroot_nice(void);
77929 +int gr_handle_chroot_sysctl(const int op);
77930 +int gr_handle_chroot_setpriority(struct task_struct *p,
77931 + const int niceval);
77932 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
77933 +int gr_handle_chroot_chroot(const struct dentry *dentry,
77934 + const struct vfsmount *mnt);
77935 +void gr_handle_chroot_chdir(const struct path *path);
77936 +int gr_handle_chroot_chmod(const struct dentry *dentry,
77937 + const struct vfsmount *mnt, const int mode);
77938 +int gr_handle_chroot_mknod(const struct dentry *dentry,
77939 + const struct vfsmount *mnt, const int mode);
77940 +int gr_handle_chroot_mount(const struct dentry *dentry,
77941 + const struct vfsmount *mnt,
77942 + const char *dev_name);
77943 +int gr_handle_chroot_pivot(void);
77944 +int gr_handle_chroot_unix(const pid_t pid);
77945 +
77946 +int gr_handle_rawio(const struct inode *inode);
77947 +
77948 +void gr_handle_ioperm(void);
77949 +void gr_handle_iopl(void);
77950 +
77951 +umode_t gr_acl_umask(void);
77952 +
77953 +int gr_tpe_allow(const struct file *file);
77954 +
77955 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
77956 +void gr_clear_chroot_entries(struct task_struct *task);
77957 +
77958 +void gr_log_forkfail(const int retval);
77959 +void gr_log_timechange(void);
77960 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
77961 +void gr_log_chdir(const struct dentry *dentry,
77962 + const struct vfsmount *mnt);
77963 +void gr_log_chroot_exec(const struct dentry *dentry,
77964 + const struct vfsmount *mnt);
77965 +void gr_log_remount(const char *devname, const int retval);
77966 +void gr_log_unmount(const char *devname, const int retval);
77967 +void gr_log_mount(const char *from, const char *to, const int retval);
77968 +void gr_log_textrel(struct vm_area_struct *vma);
77969 +void gr_log_ptgnustack(struct file *file);
77970 +void gr_log_rwxmmap(struct file *file);
77971 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
77972 +
77973 +int gr_handle_follow_link(const struct inode *parent,
77974 + const struct inode *inode,
77975 + const struct dentry *dentry,
77976 + const struct vfsmount *mnt);
77977 +int gr_handle_fifo(const struct dentry *dentry,
77978 + const struct vfsmount *mnt,
77979 + const struct dentry *dir, const int flag,
77980 + const int acc_mode);
77981 +int gr_handle_hardlink(const struct dentry *dentry,
77982 + const struct vfsmount *mnt,
77983 + struct inode *inode,
77984 + const int mode, const struct filename *to);
77985 +
77986 +int gr_is_capable(const int cap);
77987 +int gr_is_capable_nolog(const int cap);
77988 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77989 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
77990 +
77991 +void gr_copy_label(struct task_struct *tsk);
77992 +void gr_handle_crash(struct task_struct *task, const int sig);
77993 +int gr_handle_signal(const struct task_struct *p, const int sig);
77994 +int gr_check_crash_uid(const kuid_t uid);
77995 +int gr_check_protected_task(const struct task_struct *task);
77996 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
77997 +int gr_acl_handle_mmap(const struct file *file,
77998 + const unsigned long prot);
77999 +int gr_acl_handle_mprotect(const struct file *file,
78000 + const unsigned long prot);
78001 +int gr_check_hidden_task(const struct task_struct *tsk);
78002 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
78003 + const struct vfsmount *mnt);
78004 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
78005 + const struct vfsmount *mnt);
78006 +__u32 gr_acl_handle_access(const struct dentry *dentry,
78007 + const struct vfsmount *mnt, const int fmode);
78008 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
78009 + const struct vfsmount *mnt, umode_t *mode);
78010 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
78011 + const struct vfsmount *mnt);
78012 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
78013 + const struct vfsmount *mnt);
78014 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
78015 + const struct vfsmount *mnt);
78016 +int gr_handle_ptrace(struct task_struct *task, const long request);
78017 +int gr_handle_proc_ptrace(struct task_struct *task);
78018 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
78019 + const struct vfsmount *mnt);
78020 +int gr_check_crash_exec(const struct file *filp);
78021 +int gr_acl_is_enabled(void);
78022 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
78023 + const kgid_t gid);
78024 +int gr_set_proc_label(const struct dentry *dentry,
78025 + const struct vfsmount *mnt,
78026 + const int unsafe_flags);
78027 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
78028 + const struct vfsmount *mnt);
78029 +__u32 gr_acl_handle_open(const struct dentry *dentry,
78030 + const struct vfsmount *mnt, int acc_mode);
78031 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
78032 + const struct dentry *p_dentry,
78033 + const struct vfsmount *p_mnt,
78034 + int open_flags, int acc_mode, const int imode);
78035 +void gr_handle_create(const struct dentry *dentry,
78036 + const struct vfsmount *mnt);
78037 +void gr_handle_proc_create(const struct dentry *dentry,
78038 + const struct inode *inode);
78039 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
78040 + const struct dentry *parent_dentry,
78041 + const struct vfsmount *parent_mnt,
78042 + const int mode);
78043 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
78044 + const struct dentry *parent_dentry,
78045 + const struct vfsmount *parent_mnt);
78046 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
78047 + const struct vfsmount *mnt);
78048 +void gr_handle_delete(const ino_t ino, const dev_t dev);
78049 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
78050 + const struct vfsmount *mnt);
78051 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
78052 + const struct dentry *parent_dentry,
78053 + const struct vfsmount *parent_mnt,
78054 + const struct filename *from);
78055 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
78056 + const struct dentry *parent_dentry,
78057 + const struct vfsmount *parent_mnt,
78058 + const struct dentry *old_dentry,
78059 + const struct vfsmount *old_mnt, const struct filename *to);
78060 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
78061 +int gr_acl_handle_rename(struct dentry *new_dentry,
78062 + struct dentry *parent_dentry,
78063 + const struct vfsmount *parent_mnt,
78064 + struct dentry *old_dentry,
78065 + struct inode *old_parent_inode,
78066 + struct vfsmount *old_mnt, const struct filename *newname);
78067 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
78068 + struct dentry *old_dentry,
78069 + struct dentry *new_dentry,
78070 + struct vfsmount *mnt, const __u8 replace);
78071 +__u32 gr_check_link(const struct dentry *new_dentry,
78072 + const struct dentry *parent_dentry,
78073 + const struct vfsmount *parent_mnt,
78074 + const struct dentry *old_dentry,
78075 + const struct vfsmount *old_mnt);
78076 +int gr_acl_handle_filldir(const struct file *file, const char *name,
78077 + const unsigned int namelen, const ino_t ino);
78078 +
78079 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
78080 + const struct vfsmount *mnt);
78081 +void gr_acl_handle_exit(void);
78082 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
78083 +int gr_acl_handle_procpidmem(const struct task_struct *task);
78084 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
78085 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
78086 +void gr_audit_ptrace(struct task_struct *task);
78087 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
78088 +void gr_put_exec_file(struct task_struct *task);
78089 +
78090 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
78091 +
78092 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
78093 +extern void gr_learn_resource(const struct task_struct *task, const int res,
78094 + const unsigned long wanted, const int gt);
78095 +#else
78096 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
78097 + const unsigned long wanted, const int gt)
78098 +{
78099 +}
78100 +#endif
78101 +
78102 +#ifdef CONFIG_GRKERNSEC_RESLOG
78103 +extern void gr_log_resource(const struct task_struct *task, const int res,
78104 + const unsigned long wanted, const int gt);
78105 +#else
78106 +static inline void gr_log_resource(const struct task_struct *task, const int res,
78107 + const unsigned long wanted, const int gt)
78108 +{
78109 +}
78110 +#endif
78111 +
78112 +#ifdef CONFIG_GRKERNSEC
78113 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
78114 +void gr_handle_vm86(void);
78115 +void gr_handle_mem_readwrite(u64 from, u64 to);
78116 +
78117 +void gr_log_badprocpid(const char *entry);
78118 +
78119 +extern int grsec_enable_dmesg;
78120 +extern int grsec_disable_privio;
78121 +
78122 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78123 +extern kgid_t grsec_proc_gid;
78124 +#endif
78125 +
78126 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78127 +extern int grsec_enable_chroot_findtask;
78128 +#endif
78129 +#ifdef CONFIG_GRKERNSEC_SETXID
78130 +extern int grsec_enable_setxid;
78131 +#endif
78132 +#endif
78133 +
78134 +#endif
78135 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
78136 new file mode 100644
78137 index 0000000..e7ffaaf
78138 --- /dev/null
78139 +++ b/include/linux/grsock.h
78140 @@ -0,0 +1,19 @@
78141 +#ifndef __GRSOCK_H
78142 +#define __GRSOCK_H
78143 +
78144 +extern void gr_attach_curr_ip(const struct sock *sk);
78145 +extern int gr_handle_sock_all(const int family, const int type,
78146 + const int protocol);
78147 +extern int gr_handle_sock_server(const struct sockaddr *sck);
78148 +extern int gr_handle_sock_server_other(const struct sock *sck);
78149 +extern int gr_handle_sock_client(const struct sockaddr *sck);
78150 +extern int gr_search_connect(struct socket * sock,
78151 + struct sockaddr_in * addr);
78152 +extern int gr_search_bind(struct socket * sock,
78153 + struct sockaddr_in * addr);
78154 +extern int gr_search_listen(struct socket * sock);
78155 +extern int gr_search_accept(struct socket * sock);
78156 +extern int gr_search_socket(const int domain, const int type,
78157 + const int protocol);
78158 +
78159 +#endif
78160 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
78161 index 7fb31da..08b5114 100644
78162 --- a/include/linux/highmem.h
78163 +++ b/include/linux/highmem.h
78164 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
78165 kunmap_atomic(kaddr);
78166 }
78167
78168 +static inline void sanitize_highpage(struct page *page)
78169 +{
78170 + void *kaddr;
78171 + unsigned long flags;
78172 +
78173 + local_irq_save(flags);
78174 + kaddr = kmap_atomic(page);
78175 + clear_page(kaddr);
78176 + kunmap_atomic(kaddr);
78177 + local_irq_restore(flags);
78178 +}
78179 +
78180 static inline void zero_user_segments(struct page *page,
78181 unsigned start1, unsigned end1,
78182 unsigned start2, unsigned end2)
78183 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
78184 index 1c7b89a..7dda400 100644
78185 --- a/include/linux/hwmon-sysfs.h
78186 +++ b/include/linux/hwmon-sysfs.h
78187 @@ -25,7 +25,8 @@
78188 struct sensor_device_attribute{
78189 struct device_attribute dev_attr;
78190 int index;
78191 -};
78192 +} __do_const;
78193 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
78194 #define to_sensor_dev_attr(_dev_attr) \
78195 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
78196
78197 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
78198 struct device_attribute dev_attr;
78199 u8 index;
78200 u8 nr;
78201 -};
78202 +} __do_const;
78203 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
78204 #define to_sensor_dev_attr_2(_dev_attr) \
78205 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
78206
78207 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
78208 index d9c8dbd3..def6e5a 100644
78209 --- a/include/linux/i2c.h
78210 +++ b/include/linux/i2c.h
78211 @@ -364,6 +364,7 @@ struct i2c_algorithm {
78212 /* To determine what the adapter supports */
78213 u32 (*functionality) (struct i2c_adapter *);
78214 };
78215 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
78216
78217 /**
78218 * struct i2c_bus_recovery_info - I2C bus recovery information
78219 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
78220 index d23c3c2..eb63c81 100644
78221 --- a/include/linux/i2o.h
78222 +++ b/include/linux/i2o.h
78223 @@ -565,7 +565,7 @@ struct i2o_controller {
78224 struct i2o_device *exec; /* Executive */
78225 #if BITS_PER_LONG == 64
78226 spinlock_t context_list_lock; /* lock for context_list */
78227 - atomic_t context_list_counter; /* needed for unique contexts */
78228 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
78229 struct list_head context_list; /* list of context id's
78230 and pointers */
78231 #endif
78232 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
78233 index aff7ad8..3942bbd 100644
78234 --- a/include/linux/if_pppox.h
78235 +++ b/include/linux/if_pppox.h
78236 @@ -76,7 +76,7 @@ struct pppox_proto {
78237 int (*ioctl)(struct socket *sock, unsigned int cmd,
78238 unsigned long arg);
78239 struct module *owner;
78240 -};
78241 +} __do_const;
78242
78243 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
78244 extern void unregister_pppox_proto(int proto_num);
78245 diff --git a/include/linux/init.h b/include/linux/init.h
78246 index 8e68a64..3f977a0 100644
78247 --- a/include/linux/init.h
78248 +++ b/include/linux/init.h
78249 @@ -37,9 +37,17 @@
78250 * section.
78251 */
78252
78253 +#define add_init_latent_entropy __latent_entropy
78254 +
78255 +#ifdef CONFIG_MEMORY_HOTPLUG
78256 +#define add_meminit_latent_entropy
78257 +#else
78258 +#define add_meminit_latent_entropy __latent_entropy
78259 +#endif
78260 +
78261 /* These are for everybody (although not all archs will actually
78262 discard it in modules) */
78263 -#define __init __section(.init.text) __cold notrace
78264 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
78265 #define __initdata __section(.init.data)
78266 #define __initconst __constsection(.init.rodata)
78267 #define __exitdata __section(.exit.data)
78268 @@ -100,7 +108,7 @@
78269 #define __cpuexitconst
78270
78271 /* Used for MEMORY_HOTPLUG */
78272 -#define __meminit __section(.meminit.text) __cold notrace
78273 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
78274 #define __meminitdata __section(.meminit.data)
78275 #define __meminitconst __constsection(.meminit.rodata)
78276 #define __memexit __section(.memexit.text) __exitused __cold notrace
78277 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
78278 index b0ed422..d79ea23 100644
78279 --- a/include/linux/init_task.h
78280 +++ b/include/linux/init_task.h
78281 @@ -154,6 +154,12 @@ extern struct task_group root_task_group;
78282
78283 #define INIT_TASK_COMM "swapper"
78284
78285 +#ifdef CONFIG_X86
78286 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
78287 +#else
78288 +#define INIT_TASK_THREAD_INFO
78289 +#endif
78290 +
78291 /*
78292 * INIT_TASK is used to set up the first task table, touch at
78293 * your own risk!. Base=0, limit=0x1fffff (=2MB)
78294 @@ -193,6 +199,7 @@ extern struct task_group root_task_group;
78295 RCU_POINTER_INITIALIZER(cred, &init_cred), \
78296 .comm = INIT_TASK_COMM, \
78297 .thread = INIT_THREAD, \
78298 + INIT_TASK_THREAD_INFO \
78299 .fs = &init_fs, \
78300 .files = &init_files, \
78301 .signal = &init_signals, \
78302 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
78303 index db43b58..5d5084b 100644
78304 --- a/include/linux/interrupt.h
78305 +++ b/include/linux/interrupt.h
78306 @@ -360,7 +360,7 @@ enum
78307 /* map softirq index to softirq name. update 'softirq_to_name' in
78308 * kernel/softirq.c when adding a new softirq.
78309 */
78310 -extern char *softirq_to_name[NR_SOFTIRQS];
78311 +extern const char * const softirq_to_name[NR_SOFTIRQS];
78312
78313 /* softirq mask and active fields moved to irq_cpustat_t in
78314 * asm/hardirq.h to get better cache usage. KAO
78315 @@ -368,8 +368,8 @@ extern char *softirq_to_name[NR_SOFTIRQS];
78316
78317 struct softirq_action
78318 {
78319 - void (*action)(struct softirq_action *);
78320 -};
78321 + void (*action)(void);
78322 +} __no_const;
78323
78324 asmlinkage void do_softirq(void);
78325 asmlinkage void __do_softirq(void);
78326 @@ -383,7 +383,7 @@ static inline void do_softirq_own_stack(void)
78327 }
78328 #endif
78329
78330 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
78331 +extern void open_softirq(int nr, void (*action)(void));
78332 extern void softirq_init(void);
78333 extern void __raise_softirq_irqoff(unsigned int nr);
78334
78335 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
78336 index a444c79..8c41ea9 100644
78337 --- a/include/linux/iommu.h
78338 +++ b/include/linux/iommu.h
78339 @@ -130,7 +130,7 @@ struct iommu_ops {
78340 u32 (*domain_get_windows)(struct iommu_domain *domain);
78341
78342 unsigned long pgsize_bitmap;
78343 -};
78344 +} __do_const;
78345
78346 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
78347 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
78348 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
78349 index 89b7c24..382af74 100644
78350 --- a/include/linux/ioport.h
78351 +++ b/include/linux/ioport.h
78352 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
78353 int adjust_resource(struct resource *res, resource_size_t start,
78354 resource_size_t size);
78355 resource_size_t resource_alignment(struct resource *res);
78356 -static inline resource_size_t resource_size(const struct resource *res)
78357 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
78358 {
78359 return res->end - res->start + 1;
78360 }
78361 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
78362 index f6c82de..de8619e 100644
78363 --- a/include/linux/ipc_namespace.h
78364 +++ b/include/linux/ipc_namespace.h
78365 @@ -70,7 +70,7 @@ struct ipc_namespace {
78366 struct user_namespace *user_ns;
78367
78368 unsigned int proc_inum;
78369 -};
78370 +} __randomize_layout;
78371
78372 extern struct ipc_namespace init_ipc_ns;
78373 extern atomic_t nr_ipc_ns;
78374 diff --git a/include/linux/irq.h b/include/linux/irq.h
78375 index 7dc1003..407327b 100644
78376 --- a/include/linux/irq.h
78377 +++ b/include/linux/irq.h
78378 @@ -338,7 +338,8 @@ struct irq_chip {
78379 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
78380
78381 unsigned long flags;
78382 -};
78383 +} __do_const;
78384 +typedef struct irq_chip __no_const irq_chip_no_const;
78385
78386 /*
78387 * irq_chip specific flags
78388 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
78389 index cac496b..ffa0567 100644
78390 --- a/include/linux/irqchip/arm-gic.h
78391 +++ b/include/linux/irqchip/arm-gic.h
78392 @@ -61,9 +61,11 @@
78393
78394 #ifndef __ASSEMBLY__
78395
78396 +#include <linux/irq.h>
78397 +
78398 struct device_node;
78399
78400 -extern struct irq_chip gic_arch_extn;
78401 +extern irq_chip_no_const gic_arch_extn;
78402
78403 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
78404 u32 offset, struct device_node *);
78405 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
78406 index d235e88..8ccbe74 100644
78407 --- a/include/linux/jiffies.h
78408 +++ b/include/linux/jiffies.h
78409 @@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
78410 /*
78411 * Convert various time units to each other:
78412 */
78413 -extern unsigned int jiffies_to_msecs(const unsigned long j);
78414 -extern unsigned int jiffies_to_usecs(const unsigned long j);
78415 -extern unsigned long msecs_to_jiffies(const unsigned int m);
78416 -extern unsigned long usecs_to_jiffies(const unsigned int u);
78417 -extern unsigned long timespec_to_jiffies(const struct timespec *value);
78418 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
78419 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
78420 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
78421 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
78422 +extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
78423 extern void jiffies_to_timespec(const unsigned long jiffies,
78424 struct timespec *value);
78425 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
78426 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
78427 extern void jiffies_to_timeval(const unsigned long jiffies,
78428 struct timeval *value);
78429
78430 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
78431 index 6883e19..e854fcb 100644
78432 --- a/include/linux/kallsyms.h
78433 +++ b/include/linux/kallsyms.h
78434 @@ -15,7 +15,8 @@
78435
78436 struct module;
78437
78438 -#ifdef CONFIG_KALLSYMS
78439 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
78440 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
78441 /* Lookup the address for a symbol. Returns 0 if not found. */
78442 unsigned long kallsyms_lookup_name(const char *name);
78443
78444 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
78445 /* Stupid that this does nothing, but I didn't create this mess. */
78446 #define __print_symbol(fmt, addr)
78447 #endif /*CONFIG_KALLSYMS*/
78448 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
78449 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
78450 +extern unsigned long kallsyms_lookup_name(const char *name);
78451 +extern void __print_symbol(const char *fmt, unsigned long address);
78452 +extern int sprint_backtrace(char *buffer, unsigned long address);
78453 +extern int sprint_symbol(char *buffer, unsigned long address);
78454 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
78455 +const char *kallsyms_lookup(unsigned long addr,
78456 + unsigned long *symbolsize,
78457 + unsigned long *offset,
78458 + char **modname, char *namebuf);
78459 +extern int kallsyms_lookup_size_offset(unsigned long addr,
78460 + unsigned long *symbolsize,
78461 + unsigned long *offset);
78462 +#endif
78463
78464 /* This macro allows us to keep printk typechecking */
78465 static __printf(1, 2)
78466 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
78467 index a74c3a8..28d3f21 100644
78468 --- a/include/linux/key-type.h
78469 +++ b/include/linux/key-type.h
78470 @@ -131,7 +131,7 @@ struct key_type {
78471 /* internal fields */
78472 struct list_head link; /* link in types list */
78473 struct lock_class_key lock_class; /* key->sem lock class */
78474 -};
78475 +} __do_const;
78476
78477 extern struct key_type key_type_keyring;
78478
78479 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
78480 index dfb4f2f..7927e62 100644
78481 --- a/include/linux/kgdb.h
78482 +++ b/include/linux/kgdb.h
78483 @@ -52,7 +52,7 @@ extern int kgdb_connected;
78484 extern int kgdb_io_module_registered;
78485
78486 extern atomic_t kgdb_setting_breakpoint;
78487 -extern atomic_t kgdb_cpu_doing_single_step;
78488 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
78489
78490 extern struct task_struct *kgdb_usethread;
78491 extern struct task_struct *kgdb_contthread;
78492 @@ -254,7 +254,7 @@ struct kgdb_arch {
78493 void (*correct_hw_break)(void);
78494
78495 void (*enable_nmi)(bool on);
78496 -};
78497 +} __do_const;
78498
78499 /**
78500 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
78501 @@ -279,7 +279,7 @@ struct kgdb_io {
78502 void (*pre_exception) (void);
78503 void (*post_exception) (void);
78504 int is_console;
78505 -};
78506 +} __do_const;
78507
78508 extern struct kgdb_arch arch_kgdb_ops;
78509
78510 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
78511 index 0555cc6..40116ce 100644
78512 --- a/include/linux/kmod.h
78513 +++ b/include/linux/kmod.h
78514 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
78515 * usually useless though. */
78516 extern __printf(2, 3)
78517 int __request_module(bool wait, const char *name, ...);
78518 +extern __printf(3, 4)
78519 +int ___request_module(bool wait, char *param_name, const char *name, ...);
78520 #define request_module(mod...) __request_module(true, mod)
78521 #define request_module_nowait(mod...) __request_module(false, mod)
78522 #define try_then_request_module(x, mod...) \
78523 @@ -57,6 +59,9 @@ struct subprocess_info {
78524 struct work_struct work;
78525 struct completion *complete;
78526 char *path;
78527 +#ifdef CONFIG_GRKERNSEC
78528 + char *origpath;
78529 +#endif
78530 char **argv;
78531 char **envp;
78532 int wait;
78533 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
78534 index e7ba650..0af3acb 100644
78535 --- a/include/linux/kobject.h
78536 +++ b/include/linux/kobject.h
78537 @@ -116,7 +116,7 @@ struct kobj_type {
78538 struct attribute **default_attrs;
78539 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
78540 const void *(*namespace)(struct kobject *kobj);
78541 -};
78542 +} __do_const;
78543
78544 struct kobj_uevent_env {
78545 char *envp[UEVENT_NUM_ENVP];
78546 @@ -139,6 +139,7 @@ struct kobj_attribute {
78547 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
78548 const char *buf, size_t count);
78549 };
78550 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
78551
78552 extern const struct sysfs_ops kobj_sysfs_ops;
78553
78554 @@ -166,7 +167,7 @@ struct kset {
78555 spinlock_t list_lock;
78556 struct kobject kobj;
78557 const struct kset_uevent_ops *uevent_ops;
78558 -};
78559 +} __randomize_layout;
78560
78561 extern void kset_init(struct kset *kset);
78562 extern int __must_check kset_register(struct kset *kset);
78563 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
78564 index df32d25..fb52e27 100644
78565 --- a/include/linux/kobject_ns.h
78566 +++ b/include/linux/kobject_ns.h
78567 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
78568 const void *(*netlink_ns)(struct sock *sk);
78569 const void *(*initial_ns)(void);
78570 void (*drop_ns)(void *);
78571 -};
78572 +} __do_const;
78573
78574 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
78575 int kobj_ns_type_registered(enum kobj_ns_type type);
78576 diff --git a/include/linux/kref.h b/include/linux/kref.h
78577 index 484604d..0f6c5b6 100644
78578 --- a/include/linux/kref.h
78579 +++ b/include/linux/kref.h
78580 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
78581 static inline int kref_sub(struct kref *kref, unsigned int count,
78582 void (*release)(struct kref *kref))
78583 {
78584 - WARN_ON(release == NULL);
78585 + BUG_ON(release == NULL);
78586
78587 if (atomic_sub_and_test((int) count, &kref->refcount)) {
78588 release(kref);
78589 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
78590 index 9523d2a..16c0424 100644
78591 --- a/include/linux/kvm_host.h
78592 +++ b/include/linux/kvm_host.h
78593 @@ -457,7 +457,7 @@ static inline void kvm_irqfd_exit(void)
78594 {
78595 }
78596 #endif
78597 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78598 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78599 struct module *module);
78600 void kvm_exit(void);
78601
78602 @@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
78603 struct kvm_guest_debug *dbg);
78604 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
78605
78606 -int kvm_arch_init(void *opaque);
78607 +int kvm_arch_init(const void *opaque);
78608 void kvm_arch_exit(void);
78609
78610 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
78611 diff --git a/include/linux/libata.h b/include/linux/libata.h
78612 index 9b50337..712d748 100644
78613 --- a/include/linux/libata.h
78614 +++ b/include/linux/libata.h
78615 @@ -973,7 +973,7 @@ struct ata_port_operations {
78616 * fields must be pointers.
78617 */
78618 const struct ata_port_operations *inherits;
78619 -};
78620 +} __do_const;
78621
78622 struct ata_port_info {
78623 unsigned long flags;
78624 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
78625 index d3e8ad2..a949f68 100644
78626 --- a/include/linux/linkage.h
78627 +++ b/include/linux/linkage.h
78628 @@ -31,6 +31,7 @@
78629 #endif
78630
78631 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
78632 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
78633 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
78634
78635 /*
78636 diff --git a/include/linux/list.h b/include/linux/list.h
78637 index ef95941..82db65a 100644
78638 --- a/include/linux/list.h
78639 +++ b/include/linux/list.h
78640 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
78641 extern void list_del(struct list_head *entry);
78642 #endif
78643
78644 +extern void __pax_list_add(struct list_head *new,
78645 + struct list_head *prev,
78646 + struct list_head *next);
78647 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
78648 +{
78649 + __pax_list_add(new, head, head->next);
78650 +}
78651 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
78652 +{
78653 + __pax_list_add(new, head->prev, head);
78654 +}
78655 +extern void pax_list_del(struct list_head *entry);
78656 +
78657 /**
78658 * list_replace - replace old entry by new one
78659 * @old : the element to be replaced
78660 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
78661 INIT_LIST_HEAD(entry);
78662 }
78663
78664 +extern void pax_list_del_init(struct list_head *entry);
78665 +
78666 /**
78667 * list_move - delete from one list and add as another's head
78668 * @list: the entry to move
78669 diff --git a/include/linux/math64.h b/include/linux/math64.h
78670 index c45c089..298841c 100644
78671 --- a/include/linux/math64.h
78672 +++ b/include/linux/math64.h
78673 @@ -15,7 +15,7 @@
78674 * This is commonly provided by 32bit archs to provide an optimized 64bit
78675 * divide.
78676 */
78677 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78678 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78679 {
78680 *remainder = dividend % divisor;
78681 return dividend / divisor;
78682 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
78683 /**
78684 * div64_u64 - unsigned 64bit divide with 64bit divisor
78685 */
78686 -static inline u64 div64_u64(u64 dividend, u64 divisor)
78687 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
78688 {
78689 return dividend / divisor;
78690 }
78691 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
78692 #define div64_ul(x, y) div_u64((x), (y))
78693
78694 #ifndef div_u64_rem
78695 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78696 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78697 {
78698 *remainder = do_div(dividend, divisor);
78699 return dividend;
78700 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
78701 #endif
78702
78703 #ifndef div64_u64
78704 -extern u64 div64_u64(u64 dividend, u64 divisor);
78705 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
78706 #endif
78707
78708 #ifndef div64_s64
78709 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
78710 * divide.
78711 */
78712 #ifndef div_u64
78713 -static inline u64 div_u64(u64 dividend, u32 divisor)
78714 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
78715 {
78716 u32 remainder;
78717 return div_u64_rem(dividend, divisor, &remainder);
78718 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
78719 index 9fe426b..8148be6 100644
78720 --- a/include/linux/mempolicy.h
78721 +++ b/include/linux/mempolicy.h
78722 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
78723 }
78724
78725 #define vma_policy(vma) ((vma)->vm_policy)
78726 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
78727 +{
78728 + vma->vm_policy = pol;
78729 +}
78730
78731 static inline void mpol_get(struct mempolicy *pol)
78732 {
78733 @@ -241,6 +245,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
78734 }
78735
78736 #define vma_policy(vma) NULL
78737 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
78738 +{
78739 +}
78740
78741 static inline int
78742 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
78743 diff --git a/include/linux/mm.h b/include/linux/mm.h
78744 index 3552717..658aae0 100644
78745 --- a/include/linux/mm.h
78746 +++ b/include/linux/mm.h
78747 @@ -117,6 +117,11 @@ extern unsigned int kobjsize(const void *objp);
78748 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
78749 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
78750 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
78751 +
78752 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
78753 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
78754 +#endif
78755 +
78756 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
78757
78758 #ifdef CONFIG_MEM_SOFT_DIRTY
78759 @@ -219,8 +224,8 @@ struct vm_operations_struct {
78760 /* called by access_process_vm when get_user_pages() fails, typically
78761 * for use by special VMAs that can switch between memory and hardware
78762 */
78763 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
78764 - void *buf, int len, int write);
78765 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
78766 + void *buf, size_t len, int write);
78767 #ifdef CONFIG_NUMA
78768 /*
78769 * set_policy() op must add a reference to any non-NULL @new mempolicy
78770 @@ -250,6 +255,7 @@ struct vm_operations_struct {
78771 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
78772 unsigned long size, pgoff_t pgoff);
78773 };
78774 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
78775
78776 struct mmu_gather;
78777 struct inode;
78778 @@ -1061,8 +1067,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
78779 unsigned long *pfn);
78780 int follow_phys(struct vm_area_struct *vma, unsigned long address,
78781 unsigned int flags, unsigned long *prot, resource_size_t *phys);
78782 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
78783 - void *buf, int len, int write);
78784 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
78785 + void *buf, size_t len, int write);
78786
78787 static inline void unmap_shared_mapping_range(struct address_space *mapping,
78788 loff_t const holebegin, loff_t const holelen)
78789 @@ -1101,9 +1107,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
78790 }
78791 #endif
78792
78793 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
78794 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
78795 - void *buf, int len, int write);
78796 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
78797 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
78798 + void *buf, size_t len, int write);
78799
78800 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
78801 unsigned long start, unsigned long nr_pages,
78802 @@ -1135,34 +1141,6 @@ int set_page_dirty(struct page *page);
78803 int set_page_dirty_lock(struct page *page);
78804 int clear_page_dirty_for_io(struct page *page);
78805
78806 -/* Is the vma a continuation of the stack vma above it? */
78807 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
78808 -{
78809 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
78810 -}
78811 -
78812 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
78813 - unsigned long addr)
78814 -{
78815 - return (vma->vm_flags & VM_GROWSDOWN) &&
78816 - (vma->vm_start == addr) &&
78817 - !vma_growsdown(vma->vm_prev, addr);
78818 -}
78819 -
78820 -/* Is the vma a continuation of the stack vma below it? */
78821 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
78822 -{
78823 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
78824 -}
78825 -
78826 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
78827 - unsigned long addr)
78828 -{
78829 - return (vma->vm_flags & VM_GROWSUP) &&
78830 - (vma->vm_end == addr) &&
78831 - !vma_growsup(vma->vm_next, addr);
78832 -}
78833 -
78834 extern pid_t
78835 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
78836
78837 @@ -1262,6 +1240,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
78838 }
78839 #endif
78840
78841 +#ifdef CONFIG_MMU
78842 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
78843 +#else
78844 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
78845 +{
78846 + return __pgprot(0);
78847 +}
78848 +#endif
78849 +
78850 int vma_wants_writenotify(struct vm_area_struct *vma);
78851
78852 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
78853 @@ -1280,8 +1267,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
78854 {
78855 return 0;
78856 }
78857 +
78858 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
78859 + unsigned long address)
78860 +{
78861 + return 0;
78862 +}
78863 #else
78864 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
78865 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
78866 #endif
78867
78868 #ifdef __PAGETABLE_PMD_FOLDED
78869 @@ -1290,8 +1284,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
78870 {
78871 return 0;
78872 }
78873 +
78874 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
78875 + unsigned long address)
78876 +{
78877 + return 0;
78878 +}
78879 #else
78880 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
78881 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
78882 #endif
78883
78884 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
78885 @@ -1309,11 +1310,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
78886 NULL: pud_offset(pgd, address);
78887 }
78888
78889 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
78890 +{
78891 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
78892 + NULL: pud_offset(pgd, address);
78893 +}
78894 +
78895 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
78896 {
78897 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
78898 NULL: pmd_offset(pud, address);
78899 }
78900 +
78901 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
78902 +{
78903 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
78904 + NULL: pmd_offset(pud, address);
78905 +}
78906 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
78907
78908 #if USE_SPLIT_PTE_PTLOCKS
78909 @@ -1691,7 +1704,7 @@ extern int install_special_mapping(struct mm_struct *mm,
78910 unsigned long addr, unsigned long len,
78911 unsigned long flags, struct page **pages);
78912
78913 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
78914 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
78915
78916 extern unsigned long mmap_region(struct file *file, unsigned long addr,
78917 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
78918 @@ -1699,6 +1712,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
78919 unsigned long len, unsigned long prot, unsigned long flags,
78920 unsigned long pgoff, unsigned long *populate);
78921 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
78922 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
78923
78924 #ifdef CONFIG_MMU
78925 extern int __mm_populate(unsigned long addr, unsigned long len,
78926 @@ -1727,10 +1741,11 @@ struct vm_unmapped_area_info {
78927 unsigned long high_limit;
78928 unsigned long align_mask;
78929 unsigned long align_offset;
78930 + unsigned long threadstack_offset;
78931 };
78932
78933 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
78934 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
78935 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
78936 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
78937
78938 /*
78939 * Search for an unmapped address range.
78940 @@ -1742,7 +1757,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
78941 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
78942 */
78943 static inline unsigned long
78944 -vm_unmapped_area(struct vm_unmapped_area_info *info)
78945 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
78946 {
78947 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
78948 return unmapped_area(info);
78949 @@ -1805,6 +1820,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
78950 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
78951 struct vm_area_struct **pprev);
78952
78953 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
78954 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
78955 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
78956 +
78957 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
78958 NULL if none. Assume start_addr < end_addr. */
78959 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
78960 @@ -1833,15 +1852,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
78961 return vma;
78962 }
78963
78964 -#ifdef CONFIG_MMU
78965 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
78966 -#else
78967 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
78968 -{
78969 - return __pgprot(0);
78970 -}
78971 -#endif
78972 -
78973 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
78974 unsigned long change_prot_numa(struct vm_area_struct *vma,
78975 unsigned long start, unsigned long end);
78976 @@ -1893,6 +1903,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
78977 static inline void vm_stat_account(struct mm_struct *mm,
78978 unsigned long flags, struct file *file, long pages)
78979 {
78980 +
78981 +#ifdef CONFIG_PAX_RANDMMAP
78982 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
78983 +#endif
78984 +
78985 mm->total_vm += pages;
78986 }
78987 #endif /* CONFIG_PROC_FS */
78988 @@ -1974,7 +1989,7 @@ extern int unpoison_memory(unsigned long pfn);
78989 extern int sysctl_memory_failure_early_kill;
78990 extern int sysctl_memory_failure_recovery;
78991 extern void shake_page(struct page *p, int access);
78992 -extern atomic_long_t num_poisoned_pages;
78993 +extern atomic_long_unchecked_t num_poisoned_pages;
78994 extern int soft_offline_page(struct page *page, int flags);
78995
78996 extern void dump_page(struct page *page);
78997 @@ -2011,5 +2026,11 @@ void __init setup_nr_node_ids(void);
78998 static inline void setup_nr_node_ids(void) {}
78999 #endif
79000
79001 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
79002 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
79003 +#else
79004 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
79005 +#endif
79006 +
79007 #endif /* __KERNEL__ */
79008 #endif /* _LINUX_MM_H */
79009 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
79010 index 290901a..e99b01c 100644
79011 --- a/include/linux/mm_types.h
79012 +++ b/include/linux/mm_types.h
79013 @@ -307,7 +307,9 @@ struct vm_area_struct {
79014 #ifdef CONFIG_NUMA
79015 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
79016 #endif
79017 -};
79018 +
79019 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
79020 +} __randomize_layout;
79021
79022 struct core_thread {
79023 struct task_struct *task;
79024 @@ -453,7 +455,25 @@ struct mm_struct {
79025 bool tlb_flush_pending;
79026 #endif
79027 struct uprobes_state uprobes_state;
79028 -};
79029 +
79030 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
79031 + unsigned long pax_flags;
79032 +#endif
79033 +
79034 +#ifdef CONFIG_PAX_DLRESOLVE
79035 + unsigned long call_dl_resolve;
79036 +#endif
79037 +
79038 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
79039 + unsigned long call_syscall;
79040 +#endif
79041 +
79042 +#ifdef CONFIG_PAX_ASLR
79043 + unsigned long delta_mmap; /* randomized offset */
79044 + unsigned long delta_stack; /* randomized offset */
79045 +#endif
79046 +
79047 +} __randomize_layout;
79048
79049 static inline void mm_init_cpumask(struct mm_struct *mm)
79050 {
79051 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
79052 index c5d5278..f0b68c8 100644
79053 --- a/include/linux/mmiotrace.h
79054 +++ b/include/linux/mmiotrace.h
79055 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
79056 /* Called from ioremap.c */
79057 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
79058 void __iomem *addr);
79059 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
79060 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
79061
79062 /* For anyone to insert markers. Remember trailing newline. */
79063 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
79064 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
79065 {
79066 }
79067
79068 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
79069 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
79070 {
79071 }
79072
79073 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
79074 index bd791e4..8617c34f 100644
79075 --- a/include/linux/mmzone.h
79076 +++ b/include/linux/mmzone.h
79077 @@ -396,7 +396,7 @@ struct zone {
79078 unsigned long flags; /* zone flags, see below */
79079
79080 /* Zone statistics */
79081 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79082 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79083
79084 /*
79085 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
79086 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
79087 index 45e9214..a7227d6 100644
79088 --- a/include/linux/mod_devicetable.h
79089 +++ b/include/linux/mod_devicetable.h
79090 @@ -13,7 +13,7 @@
79091 typedef unsigned long kernel_ulong_t;
79092 #endif
79093
79094 -#define PCI_ANY_ID (~0)
79095 +#define PCI_ANY_ID ((__u16)~0)
79096
79097 struct pci_device_id {
79098 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
79099 @@ -139,7 +139,7 @@ struct usb_device_id {
79100 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
79101 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
79102
79103 -#define HID_ANY_ID (~0)
79104 +#define HID_ANY_ID (~0U)
79105 #define HID_BUS_ANY 0xffff
79106 #define HID_GROUP_ANY 0x0000
79107
79108 @@ -467,7 +467,7 @@ struct dmi_system_id {
79109 const char *ident;
79110 struct dmi_strmatch matches[4];
79111 void *driver_data;
79112 -};
79113 +} __do_const;
79114 /*
79115 * struct dmi_device_id appears during expansion of
79116 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
79117 diff --git a/include/linux/module.h b/include/linux/module.h
79118 index 15cd6b1..f6e2e6a 100644
79119 --- a/include/linux/module.h
79120 +++ b/include/linux/module.h
79121 @@ -17,9 +17,11 @@
79122 #include <linux/moduleparam.h>
79123 #include <linux/tracepoint.h>
79124 #include <linux/export.h>
79125 +#include <linux/fs.h>
79126
79127 #include <linux/percpu.h>
79128 #include <asm/module.h>
79129 +#include <asm/pgtable.h>
79130
79131 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
79132 #define MODULE_SIG_STRING "~Module signature appended~\n"
79133 @@ -43,7 +45,7 @@ struct module_kobject {
79134 struct kobject *drivers_dir;
79135 struct module_param_attrs *mp;
79136 struct completion *kobj_completion;
79137 -};
79138 +} __randomize_layout;
79139
79140 struct module_attribute {
79141 struct attribute attr;
79142 @@ -55,12 +57,13 @@ struct module_attribute {
79143 int (*test)(struct module *);
79144 void (*free)(struct module *);
79145 };
79146 +typedef struct module_attribute __no_const module_attribute_no_const;
79147
79148 struct module_version_attribute {
79149 struct module_attribute mattr;
79150 const char *module_name;
79151 const char *version;
79152 -} __attribute__ ((__aligned__(sizeof(void *))));
79153 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
79154
79155 extern ssize_t __modver_version_show(struct module_attribute *,
79156 struct module_kobject *, char *);
79157 @@ -238,7 +241,7 @@ struct module
79158
79159 /* Sysfs stuff. */
79160 struct module_kobject mkobj;
79161 - struct module_attribute *modinfo_attrs;
79162 + module_attribute_no_const *modinfo_attrs;
79163 const char *version;
79164 const char *srcversion;
79165 struct kobject *holders_dir;
79166 @@ -287,19 +290,16 @@ struct module
79167 int (*init)(void);
79168
79169 /* If this is non-NULL, vfree after init() returns */
79170 - void *module_init;
79171 + void *module_init_rx, *module_init_rw;
79172
79173 /* Here is the actual code + data, vfree'd on unload. */
79174 - void *module_core;
79175 + void *module_core_rx, *module_core_rw;
79176
79177 /* Here are the sizes of the init and core sections */
79178 - unsigned int init_size, core_size;
79179 + unsigned int init_size_rw, core_size_rw;
79180
79181 /* The size of the executable code in each section. */
79182 - unsigned int init_text_size, core_text_size;
79183 -
79184 - /* Size of RO sections of the module (text+rodata) */
79185 - unsigned int init_ro_size, core_ro_size;
79186 + unsigned int init_size_rx, core_size_rx;
79187
79188 /* Arch-specific module values */
79189 struct mod_arch_specific arch;
79190 @@ -355,6 +355,10 @@ struct module
79191 #ifdef CONFIG_EVENT_TRACING
79192 struct ftrace_event_call **trace_events;
79193 unsigned int num_trace_events;
79194 + struct file_operations trace_id;
79195 + struct file_operations trace_enable;
79196 + struct file_operations trace_format;
79197 + struct file_operations trace_filter;
79198 #endif
79199 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
79200 unsigned int num_ftrace_callsites;
79201 @@ -378,7 +382,7 @@ struct module
79202 ctor_fn_t *ctors;
79203 unsigned int num_ctors;
79204 #endif
79205 -};
79206 +} __randomize_layout;
79207 #ifndef MODULE_ARCH_INIT
79208 #define MODULE_ARCH_INIT {}
79209 #endif
79210 @@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
79211 bool is_module_percpu_address(unsigned long addr);
79212 bool is_module_text_address(unsigned long addr);
79213
79214 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
79215 +{
79216 +
79217 +#ifdef CONFIG_PAX_KERNEXEC
79218 + if (ktla_ktva(addr) >= (unsigned long)start &&
79219 + ktla_ktva(addr) < (unsigned long)start + size)
79220 + return 1;
79221 +#endif
79222 +
79223 + return ((void *)addr >= start && (void *)addr < start + size);
79224 +}
79225 +
79226 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
79227 +{
79228 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
79229 +}
79230 +
79231 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
79232 +{
79233 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
79234 +}
79235 +
79236 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
79237 +{
79238 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
79239 +}
79240 +
79241 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
79242 +{
79243 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
79244 +}
79245 +
79246 static inline int within_module_core(unsigned long addr, const struct module *mod)
79247 {
79248 - return (unsigned long)mod->module_core <= addr &&
79249 - addr < (unsigned long)mod->module_core + mod->core_size;
79250 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
79251 }
79252
79253 static inline int within_module_init(unsigned long addr, const struct module *mod)
79254 {
79255 - return (unsigned long)mod->module_init <= addr &&
79256 - addr < (unsigned long)mod->module_init + mod->init_size;
79257 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
79258 }
79259
79260 /* Search for module by name: must hold module_mutex. */
79261 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
79262 index 560ca53..ef621ef 100644
79263 --- a/include/linux/moduleloader.h
79264 +++ b/include/linux/moduleloader.h
79265 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
79266 sections. Returns NULL on failure. */
79267 void *module_alloc(unsigned long size);
79268
79269 +#ifdef CONFIG_PAX_KERNEXEC
79270 +void *module_alloc_exec(unsigned long size);
79271 +#else
79272 +#define module_alloc_exec(x) module_alloc(x)
79273 +#endif
79274 +
79275 /* Free memory returned from module_alloc. */
79276 void module_free(struct module *mod, void *module_region);
79277
79278 +#ifdef CONFIG_PAX_KERNEXEC
79279 +void module_free_exec(struct module *mod, void *module_region);
79280 +#else
79281 +#define module_free_exec(x, y) module_free((x), (y))
79282 +#endif
79283 +
79284 /*
79285 * Apply the given relocation to the (simplified) ELF. Return -error
79286 * or 0.
79287 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
79288 unsigned int relsec,
79289 struct module *me)
79290 {
79291 +#ifdef CONFIG_MODULES
79292 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
79293 +#endif
79294 return -ENOEXEC;
79295 }
79296 #endif
79297 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
79298 unsigned int relsec,
79299 struct module *me)
79300 {
79301 +#ifdef CONFIG_MODULES
79302 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
79303 +#endif
79304 return -ENOEXEC;
79305 }
79306 #endif
79307 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
79308 index c3eb102..073c4a6 100644
79309 --- a/include/linux/moduleparam.h
79310 +++ b/include/linux/moduleparam.h
79311 @@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
79312 * @len is usually just sizeof(string).
79313 */
79314 #define module_param_string(name, string, len, perm) \
79315 - static const struct kparam_string __param_string_##name \
79316 + static const struct kparam_string __param_string_##name __used \
79317 = { len, string }; \
79318 __module_param_call(MODULE_PARAM_PREFIX, name, \
79319 &param_ops_string, \
79320 @@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
79321 */
79322 #define module_param_array_named(name, array, type, nump, perm) \
79323 param_check_##type(name, &(array)[0]); \
79324 - static const struct kparam_array __param_arr_##name \
79325 + static const struct kparam_array __param_arr_##name __used \
79326 = { .max = ARRAY_SIZE(array), .num = nump, \
79327 .ops = &param_ops_##type, \
79328 .elemsize = sizeof(array[0]), .elem = array }; \
79329 diff --git a/include/linux/mount.h b/include/linux/mount.h
79330 index 371d346..fba2819 100644
79331 --- a/include/linux/mount.h
79332 +++ b/include/linux/mount.h
79333 @@ -56,7 +56,7 @@ struct vfsmount {
79334 struct dentry *mnt_root; /* root of the mounted tree */
79335 struct super_block *mnt_sb; /* pointer to superblock */
79336 int mnt_flags;
79337 -};
79338 +} __randomize_layout;
79339
79340 struct file; /* forward dec */
79341
79342 diff --git a/include/linux/namei.h b/include/linux/namei.h
79343 index 492de72..1bddcd4 100644
79344 --- a/include/linux/namei.h
79345 +++ b/include/linux/namei.h
79346 @@ -19,7 +19,7 @@ struct nameidata {
79347 unsigned seq, m_seq;
79348 int last_type;
79349 unsigned depth;
79350 - char *saved_names[MAX_NESTED_LINKS + 1];
79351 + const char *saved_names[MAX_NESTED_LINKS + 1];
79352 };
79353
79354 /*
79355 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
79356
79357 extern void nd_jump_link(struct nameidata *nd, struct path *path);
79358
79359 -static inline void nd_set_link(struct nameidata *nd, char *path)
79360 +static inline void nd_set_link(struct nameidata *nd, const char *path)
79361 {
79362 nd->saved_names[nd->depth] = path;
79363 }
79364
79365 -static inline char *nd_get_link(struct nameidata *nd)
79366 +static inline const char *nd_get_link(const struct nameidata *nd)
79367 {
79368 return nd->saved_names[nd->depth];
79369 }
79370 diff --git a/include/linux/net.h b/include/linux/net.h
79371 index 69be3e6..0fb422d 100644
79372 --- a/include/linux/net.h
79373 +++ b/include/linux/net.h
79374 @@ -192,7 +192,7 @@ struct net_proto_family {
79375 int (*create)(struct net *net, struct socket *sock,
79376 int protocol, int kern);
79377 struct module *owner;
79378 -};
79379 +} __do_const;
79380
79381 struct iovec;
79382 struct kvec;
79383 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
79384 index ce2a1f5..cb9bc8c 100644
79385 --- a/include/linux/netdevice.h
79386 +++ b/include/linux/netdevice.h
79387 @@ -1129,6 +1129,7 @@ struct net_device_ops {
79388 struct net_device *dev,
79389 void *priv);
79390 };
79391 +typedef struct net_device_ops __no_const net_device_ops_no_const;
79392
79393 /*
79394 * The DEVICE structure.
79395 @@ -1211,7 +1212,7 @@ struct net_device {
79396 int iflink;
79397
79398 struct net_device_stats stats;
79399 - atomic_long_t rx_dropped; /* dropped packets by core network
79400 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
79401 * Do not use this in drivers.
79402 */
79403
79404 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
79405 index 2077489..a15e561 100644
79406 --- a/include/linux/netfilter.h
79407 +++ b/include/linux/netfilter.h
79408 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
79409 #endif
79410 /* Use the module struct to lock set/get code in place */
79411 struct module *owner;
79412 -};
79413 +} __do_const;
79414
79415 /* Function to register/unregister hook points. */
79416 int nf_register_hook(struct nf_hook_ops *reg);
79417 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
79418 index 28c7436..2d6156a 100644
79419 --- a/include/linux/netfilter/nfnetlink.h
79420 +++ b/include/linux/netfilter/nfnetlink.h
79421 @@ -19,7 +19,7 @@ struct nfnl_callback {
79422 const struct nlattr * const cda[]);
79423 const struct nla_policy *policy; /* netlink attribute policy */
79424 const u_int16_t attr_count; /* number of nlattr's */
79425 -};
79426 +} __do_const;
79427
79428 struct nfnetlink_subsystem {
79429 const char *name;
79430 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
79431 new file mode 100644
79432 index 0000000..33f4af8
79433 --- /dev/null
79434 +++ b/include/linux/netfilter/xt_gradm.h
79435 @@ -0,0 +1,9 @@
79436 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
79437 +#define _LINUX_NETFILTER_XT_GRADM_H 1
79438 +
79439 +struct xt_gradm_mtinfo {
79440 + __u16 flags;
79441 + __u16 invflags;
79442 +};
79443 +
79444 +#endif
79445 diff --git a/include/linux/nls.h b/include/linux/nls.h
79446 index 5dc635f..35f5e11 100644
79447 --- a/include/linux/nls.h
79448 +++ b/include/linux/nls.h
79449 @@ -31,7 +31,7 @@ struct nls_table {
79450 const unsigned char *charset2upper;
79451 struct module *owner;
79452 struct nls_table *next;
79453 -};
79454 +} __do_const;
79455
79456 /* this value hold the maximum octet of charset */
79457 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
79458 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
79459 index d14a4c3..a078786 100644
79460 --- a/include/linux/notifier.h
79461 +++ b/include/linux/notifier.h
79462 @@ -54,7 +54,8 @@ struct notifier_block {
79463 notifier_fn_t notifier_call;
79464 struct notifier_block __rcu *next;
79465 int priority;
79466 -};
79467 +} __do_const;
79468 +typedef struct notifier_block __no_const notifier_block_no_const;
79469
79470 struct atomic_notifier_head {
79471 spinlock_t lock;
79472 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
79473 index b2a0f15..4d7da32 100644
79474 --- a/include/linux/oprofile.h
79475 +++ b/include/linux/oprofile.h
79476 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
79477 int oprofilefs_create_ro_ulong(struct dentry * root,
79478 char const * name, ulong * val);
79479
79480 -/** Create a file for read-only access to an atomic_t. */
79481 +/** Create a file for read-only access to an atomic_unchecked_t. */
79482 int oprofilefs_create_ro_atomic(struct dentry * root,
79483 - char const * name, atomic_t * val);
79484 + char const * name, atomic_unchecked_t * val);
79485
79486 /** create a directory */
79487 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
79488 diff --git a/include/linux/padata.h b/include/linux/padata.h
79489 index 4386946..f50c615 100644
79490 --- a/include/linux/padata.h
79491 +++ b/include/linux/padata.h
79492 @@ -129,7 +129,7 @@ struct parallel_data {
79493 struct padata_serial_queue __percpu *squeue;
79494 atomic_t reorder_objects;
79495 atomic_t refcnt;
79496 - atomic_t seq_nr;
79497 + atomic_unchecked_t seq_nr;
79498 struct padata_cpumask cpumask;
79499 spinlock_t lock ____cacheline_aligned;
79500 unsigned int processed;
79501 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
79502 index a2e2f1d..8a391d2 100644
79503 --- a/include/linux/pci_hotplug.h
79504 +++ b/include/linux/pci_hotplug.h
79505 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
79506 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
79507 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
79508 int (*reset_slot) (struct hotplug_slot *slot, int probe);
79509 -};
79510 +} __do_const;
79511 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
79512
79513 /**
79514 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
79515 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
79516 index 2e069d1..27054b8 100644
79517 --- a/include/linux/perf_event.h
79518 +++ b/include/linux/perf_event.h
79519 @@ -327,8 +327,8 @@ struct perf_event {
79520
79521 enum perf_event_active_state state;
79522 unsigned int attach_state;
79523 - local64_t count;
79524 - atomic64_t child_count;
79525 + local64_t count; /* PaX: fix it one day */
79526 + atomic64_unchecked_t child_count;
79527
79528 /*
79529 * These are the total time in nanoseconds that the event
79530 @@ -379,8 +379,8 @@ struct perf_event {
79531 * These accumulate total time (in nanoseconds) that children
79532 * events have been enabled and running, respectively.
79533 */
79534 - atomic64_t child_total_time_enabled;
79535 - atomic64_t child_total_time_running;
79536 + atomic64_unchecked_t child_total_time_enabled;
79537 + atomic64_unchecked_t child_total_time_running;
79538
79539 /*
79540 * Protect attach/detach and child_list:
79541 @@ -707,7 +707,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
79542 entry->ip[entry->nr++] = ip;
79543 }
79544
79545 -extern int sysctl_perf_event_paranoid;
79546 +extern int sysctl_perf_event_legitimately_concerned;
79547 extern int sysctl_perf_event_mlock;
79548 extern int sysctl_perf_event_sample_rate;
79549 extern int sysctl_perf_cpu_time_max_percent;
79550 @@ -722,19 +722,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
79551 loff_t *ppos);
79552
79553
79554 +static inline bool perf_paranoid_any(void)
79555 +{
79556 + return sysctl_perf_event_legitimately_concerned > 2;
79557 +}
79558 +
79559 static inline bool perf_paranoid_tracepoint_raw(void)
79560 {
79561 - return sysctl_perf_event_paranoid > -1;
79562 + return sysctl_perf_event_legitimately_concerned > -1;
79563 }
79564
79565 static inline bool perf_paranoid_cpu(void)
79566 {
79567 - return sysctl_perf_event_paranoid > 0;
79568 + return sysctl_perf_event_legitimately_concerned > 0;
79569 }
79570
79571 static inline bool perf_paranoid_kernel(void)
79572 {
79573 - return sysctl_perf_event_paranoid > 1;
79574 + return sysctl_perf_event_legitimately_concerned > 1;
79575 }
79576
79577 extern void perf_event_init(void);
79578 @@ -850,7 +855,7 @@ struct perf_pmu_events_attr {
79579 struct device_attribute attr;
79580 u64 id;
79581 const char *event_str;
79582 -};
79583 +} __do_const;
79584
79585 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
79586 static struct perf_pmu_events_attr _var = { \
79587 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
79588 index 7246ef3..1539ea4 100644
79589 --- a/include/linux/pid_namespace.h
79590 +++ b/include/linux/pid_namespace.h
79591 @@ -43,7 +43,7 @@ struct pid_namespace {
79592 int hide_pid;
79593 int reboot; /* group exit code if this pidns was rebooted */
79594 unsigned int proc_inum;
79595 -};
79596 +} __randomize_layout;
79597
79598 extern struct pid_namespace init_pid_ns;
79599
79600 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
79601 index b8809fe..ae4ccd0 100644
79602 --- a/include/linux/pipe_fs_i.h
79603 +++ b/include/linux/pipe_fs_i.h
79604 @@ -47,10 +47,10 @@ struct pipe_inode_info {
79605 struct mutex mutex;
79606 wait_queue_head_t wait;
79607 unsigned int nrbufs, curbuf, buffers;
79608 - unsigned int readers;
79609 - unsigned int writers;
79610 - unsigned int files;
79611 - unsigned int waiting_writers;
79612 + atomic_t readers;
79613 + atomic_t writers;
79614 + atomic_t files;
79615 + atomic_t waiting_writers;
79616 unsigned int r_counter;
79617 unsigned int w_counter;
79618 struct page *tmp_page;
79619 diff --git a/include/linux/pm.h b/include/linux/pm.h
79620 index a224c7f..92d8a97 100644
79621 --- a/include/linux/pm.h
79622 +++ b/include/linux/pm.h
79623 @@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
79624 struct dev_pm_domain {
79625 struct dev_pm_ops ops;
79626 };
79627 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
79628
79629 /*
79630 * The PM_EVENT_ messages are also used by drivers implementing the legacy
79631 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
79632 index 7c1d252..c5c773e 100644
79633 --- a/include/linux/pm_domain.h
79634 +++ b/include/linux/pm_domain.h
79635 @@ -48,7 +48,7 @@ struct gpd_dev_ops {
79636
79637 struct gpd_cpu_data {
79638 unsigned int saved_exit_latency;
79639 - struct cpuidle_state *idle_state;
79640 + cpuidle_state_no_const *idle_state;
79641 };
79642
79643 struct generic_pm_domain {
79644 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
79645 index 6fa7cea..7bf6415 100644
79646 --- a/include/linux/pm_runtime.h
79647 +++ b/include/linux/pm_runtime.h
79648 @@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
79649
79650 static inline void pm_runtime_mark_last_busy(struct device *dev)
79651 {
79652 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
79653 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
79654 }
79655
79656 #else /* !CONFIG_PM_RUNTIME */
79657 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
79658 index 195aafc..49a7bc2 100644
79659 --- a/include/linux/pnp.h
79660 +++ b/include/linux/pnp.h
79661 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
79662 struct pnp_fixup {
79663 char id[7];
79664 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
79665 -};
79666 +} __do_const;
79667
79668 /* config parameters */
79669 #define PNP_CONFIG_NORMAL 0x0001
79670 diff --git a/include/linux/poison.h b/include/linux/poison.h
79671 index 2110a81..13a11bb 100644
79672 --- a/include/linux/poison.h
79673 +++ b/include/linux/poison.h
79674 @@ -19,8 +19,8 @@
79675 * under normal circumstances, used to verify that nobody uses
79676 * non-initialized list entries.
79677 */
79678 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
79679 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
79680 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
79681 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
79682
79683 /********** include/linux/timer.h **********/
79684 /*
79685 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
79686 index d8b187c3..9a9257a 100644
79687 --- a/include/linux/power/smartreflex.h
79688 +++ b/include/linux/power/smartreflex.h
79689 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
79690 int (*notify)(struct omap_sr *sr, u32 status);
79691 u8 notify_flags;
79692 u8 class_type;
79693 -};
79694 +} __do_const;
79695
79696 /**
79697 * struct omap_sr_nvalue_table - Smartreflex n-target value info
79698 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
79699 index 4ea1d37..80f4b33 100644
79700 --- a/include/linux/ppp-comp.h
79701 +++ b/include/linux/ppp-comp.h
79702 @@ -84,7 +84,7 @@ struct compressor {
79703 struct module *owner;
79704 /* Extra skb space needed by the compressor algorithm */
79705 unsigned int comp_extra;
79706 -};
79707 +} __do_const;
79708
79709 /*
79710 * The return value from decompress routine is the length of the
79711 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
79712 index a3d9dc8..8af9922 100644
79713 --- a/include/linux/preempt.h
79714 +++ b/include/linux/preempt.h
79715 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
79716 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
79717 #endif
79718
79719 +#define raw_preempt_count_add(val) __preempt_count_add(val)
79720 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
79721 +
79722 #define __preempt_count_inc() __preempt_count_add(1)
79723 #define __preempt_count_dec() __preempt_count_sub(1)
79724
79725 #define preempt_count_inc() preempt_count_add(1)
79726 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
79727 #define preempt_count_dec() preempt_count_sub(1)
79728 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
79729
79730 #ifdef CONFIG_PREEMPT_COUNT
79731
79732 @@ -41,6 +46,12 @@ do { \
79733 barrier(); \
79734 } while (0)
79735
79736 +#define raw_preempt_disable() \
79737 +do { \
79738 + raw_preempt_count_inc(); \
79739 + barrier(); \
79740 +} while (0)
79741 +
79742 #define sched_preempt_enable_no_resched() \
79743 do { \
79744 barrier(); \
79745 @@ -49,6 +60,12 @@ do { \
79746
79747 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
79748
79749 +#define raw_preempt_enable_no_resched() \
79750 +do { \
79751 + barrier(); \
79752 + raw_preempt_count_dec(); \
79753 +} while (0)
79754 +
79755 #ifdef CONFIG_PREEMPT
79756 #define preempt_enable() \
79757 do { \
79758 @@ -105,8 +122,10 @@ do { \
79759 * region.
79760 */
79761 #define preempt_disable() barrier()
79762 +#define raw_preempt_disable() barrier()
79763 #define sched_preempt_enable_no_resched() barrier()
79764 #define preempt_enable_no_resched() barrier()
79765 +#define raw_preempt_enable_no_resched() barrier()
79766 #define preempt_enable() barrier()
79767 #define preempt_check_resched() do { } while (0)
79768
79769 diff --git a/include/linux/printk.h b/include/linux/printk.h
79770 index 6949258..7c4730e 100644
79771 --- a/include/linux/printk.h
79772 +++ b/include/linux/printk.h
79773 @@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
79774 void early_printk(const char *s, ...) { }
79775 #endif
79776
79777 +extern int kptr_restrict;
79778 +
79779 #ifdef CONFIG_PRINTK
79780 asmlinkage __printf(5, 0)
79781 int vprintk_emit(int facility, int level,
79782 @@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
79783
79784 extern int printk_delay_msec;
79785 extern int dmesg_restrict;
79786 -extern int kptr_restrict;
79787
79788 extern void wake_up_klogd(void);
79789
79790 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
79791 index 608e60a..c26f864 100644
79792 --- a/include/linux/proc_fs.h
79793 +++ b/include/linux/proc_fs.h
79794 @@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
79795 return proc_create_data(name, mode, parent, proc_fops, NULL);
79796 }
79797
79798 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
79799 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
79800 +{
79801 +#ifdef CONFIG_GRKERNSEC_PROC_USER
79802 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
79803 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79804 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
79805 +#else
79806 + return proc_create_data(name, mode, parent, proc_fops, NULL);
79807 +#endif
79808 +}
79809 +
79810 +
79811 extern void proc_set_size(struct proc_dir_entry *, loff_t);
79812 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
79813 extern void *PDE_DATA(const struct inode *);
79814 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
79815 index 34a1e10..70f6bde 100644
79816 --- a/include/linux/proc_ns.h
79817 +++ b/include/linux/proc_ns.h
79818 @@ -14,7 +14,7 @@ struct proc_ns_operations {
79819 void (*put)(void *ns);
79820 int (*install)(struct nsproxy *nsproxy, void *ns);
79821 unsigned int (*inum)(void *ns);
79822 -};
79823 +} __do_const __randomize_layout;
79824
79825 struct proc_ns {
79826 void *ns;
79827 diff --git a/include/linux/quota.h b/include/linux/quota.h
79828 index cc7494a..1e27036 100644
79829 --- a/include/linux/quota.h
79830 +++ b/include/linux/quota.h
79831 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
79832
79833 extern bool qid_eq(struct kqid left, struct kqid right);
79834 extern bool qid_lt(struct kqid left, struct kqid right);
79835 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
79836 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
79837 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
79838 extern bool qid_valid(struct kqid qid);
79839
79840 diff --git a/include/linux/random.h b/include/linux/random.h
79841 index 4002b3d..d5ad855 100644
79842 --- a/include/linux/random.h
79843 +++ b/include/linux/random.h
79844 @@ -10,9 +10,19 @@
79845
79846
79847 extern void add_device_randomness(const void *, unsigned int);
79848 +
79849 +static inline void add_latent_entropy(void)
79850 +{
79851 +
79852 +#ifdef LATENT_ENTROPY_PLUGIN
79853 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
79854 +#endif
79855 +
79856 +}
79857 +
79858 extern void add_input_randomness(unsigned int type, unsigned int code,
79859 - unsigned int value);
79860 -extern void add_interrupt_randomness(int irq, int irq_flags);
79861 + unsigned int value) __latent_entropy;
79862 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
79863
79864 extern void get_random_bytes(void *buf, int nbytes);
79865 extern void get_random_bytes_arch(void *buf, int nbytes);
79866 @@ -23,10 +33,10 @@ extern int random_int_secret_init(void);
79867 extern const struct file_operations random_fops, urandom_fops;
79868 #endif
79869
79870 -unsigned int get_random_int(void);
79871 +unsigned int __intentional_overflow(-1) get_random_int(void);
79872 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
79873
79874 -u32 prandom_u32(void);
79875 +u32 prandom_u32(void) __intentional_overflow(-1);
79876 void prandom_bytes(void *buf, int nbytes);
79877 void prandom_seed(u32 seed);
79878 void prandom_reseed_late(void);
79879 @@ -38,6 +48,11 @@ struct rnd_state {
79880 u32 prandom_u32_state(struct rnd_state *state);
79881 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
79882
79883 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
79884 +{
79885 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
79886 +}
79887 +
79888 /*
79889 * Handle minimum values for seeds
79890 */
79891 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
79892 index fea49b5..2ac22bb 100644
79893 --- a/include/linux/rbtree_augmented.h
79894 +++ b/include/linux/rbtree_augmented.h
79895 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
79896 old->rbaugmented = rbcompute(old); \
79897 } \
79898 rbstatic const struct rb_augment_callbacks rbname = { \
79899 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
79900 + .propagate = rbname ## _propagate, \
79901 + .copy = rbname ## _copy, \
79902 + .rotate = rbname ## _rotate \
79903 };
79904
79905
79906 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
79907 index 45a0a9e..e83788e 100644
79908 --- a/include/linux/rculist.h
79909 +++ b/include/linux/rculist.h
79910 @@ -29,8 +29,8 @@
79911 */
79912 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
79913 {
79914 - ACCESS_ONCE(list->next) = list;
79915 - ACCESS_ONCE(list->prev) = list;
79916 + ACCESS_ONCE_RW(list->next) = list;
79917 + ACCESS_ONCE_RW(list->prev) = list;
79918 }
79919
79920 /*
79921 @@ -59,6 +59,9 @@ extern void __list_add_rcu(struct list_head *new,
79922 struct list_head *prev, struct list_head *next);
79923 #endif
79924
79925 +extern void __pax_list_add_rcu(struct list_head *new,
79926 + struct list_head *prev, struct list_head *next);
79927 +
79928 /**
79929 * list_add_rcu - add a new entry to rcu-protected list
79930 * @new: new entry to be added
79931 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
79932 __list_add_rcu(new, head, head->next);
79933 }
79934
79935 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
79936 +{
79937 + __pax_list_add_rcu(new, head, head->next);
79938 +}
79939 +
79940 /**
79941 * list_add_tail_rcu - add a new entry to rcu-protected list
79942 * @new: new entry to be added
79943 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
79944 __list_add_rcu(new, head->prev, head);
79945 }
79946
79947 +static inline void pax_list_add_tail_rcu(struct list_head *new,
79948 + struct list_head *head)
79949 +{
79950 + __pax_list_add_rcu(new, head->prev, head);
79951 +}
79952 +
79953 /**
79954 * list_del_rcu - deletes entry from list without re-initialization
79955 * @entry: the element to delete from the list.
79956 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
79957 entry->prev = LIST_POISON2;
79958 }
79959
79960 +extern void pax_list_del_rcu(struct list_head *entry);
79961 +
79962 /**
79963 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
79964 * @n: the element to delete from the hash list.
79965 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
79966 index 9e7db9e..7d4fd72 100644
79967 --- a/include/linux/reboot.h
79968 +++ b/include/linux/reboot.h
79969 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
79970 */
79971
79972 extern void migrate_to_reboot_cpu(void);
79973 -extern void machine_restart(char *cmd);
79974 -extern void machine_halt(void);
79975 -extern void machine_power_off(void);
79976 +extern void machine_restart(char *cmd) __noreturn;
79977 +extern void machine_halt(void) __noreturn;
79978 +extern void machine_power_off(void) __noreturn;
79979
79980 extern void machine_shutdown(void);
79981 struct pt_regs;
79982 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
79983 */
79984
79985 extern void kernel_restart_prepare(char *cmd);
79986 -extern void kernel_restart(char *cmd);
79987 -extern void kernel_halt(void);
79988 -extern void kernel_power_off(void);
79989 +extern void kernel_restart(char *cmd) __noreturn;
79990 +extern void kernel_halt(void) __noreturn;
79991 +extern void kernel_power_off(void) __noreturn;
79992
79993 extern int C_A_D; /* for sysctl */
79994 void ctrl_alt_del(void);
79995 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
79996 * Emergency restart, callable from an interrupt handler.
79997 */
79998
79999 -extern void emergency_restart(void);
80000 +extern void emergency_restart(void) __noreturn;
80001 #include <asm/emergency-restart.h>
80002
80003 #endif /* _LINUX_REBOOT_H */
80004 diff --git a/include/linux/regset.h b/include/linux/regset.h
80005 index 8e0c9fe..ac4d221 100644
80006 --- a/include/linux/regset.h
80007 +++ b/include/linux/regset.h
80008 @@ -161,7 +161,8 @@ struct user_regset {
80009 unsigned int align;
80010 unsigned int bias;
80011 unsigned int core_note_type;
80012 -};
80013 +} __do_const;
80014 +typedef struct user_regset __no_const user_regset_no_const;
80015
80016 /**
80017 * struct user_regset_view - available regsets
80018 diff --git a/include/linux/relay.h b/include/linux/relay.h
80019 index d7c8359..818daf5 100644
80020 --- a/include/linux/relay.h
80021 +++ b/include/linux/relay.h
80022 @@ -157,7 +157,7 @@ struct rchan_callbacks
80023 * The callback should return 0 if successful, negative if not.
80024 */
80025 int (*remove_buf_file)(struct dentry *dentry);
80026 -};
80027 +} __no_const;
80028
80029 /*
80030 * CONFIG_RELAY kernel API, kernel/relay.c
80031 diff --git a/include/linux/rio.h b/include/linux/rio.h
80032 index b71d573..2f940bd 100644
80033 --- a/include/linux/rio.h
80034 +++ b/include/linux/rio.h
80035 @@ -355,7 +355,7 @@ struct rio_ops {
80036 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
80037 u64 rstart, u32 size, u32 flags);
80038 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
80039 -};
80040 +} __no_const;
80041
80042 #define RIO_RESOURCE_MEM 0x00000100
80043 #define RIO_RESOURCE_DOORBELL 0x00000200
80044 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
80045 index 6dacb93..6174423 100644
80046 --- a/include/linux/rmap.h
80047 +++ b/include/linux/rmap.h
80048 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
80049 void anon_vma_init(void); /* create anon_vma_cachep */
80050 int anon_vma_prepare(struct vm_area_struct *);
80051 void unlink_anon_vmas(struct vm_area_struct *);
80052 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
80053 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
80054 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
80055 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
80056
80057 static inline void anon_vma_merge(struct vm_area_struct *vma,
80058 struct vm_area_struct *next)
80059 diff --git a/include/linux/sched.h b/include/linux/sched.h
80060 index 53f97eb..1d90705 100644
80061 --- a/include/linux/sched.h
80062 +++ b/include/linux/sched.h
80063 @@ -63,6 +63,7 @@ struct bio_list;
80064 struct fs_struct;
80065 struct perf_event_context;
80066 struct blk_plug;
80067 +struct linux_binprm;
80068
80069 /*
80070 * List of flags we want to share for kernel threads,
80071 @@ -304,7 +305,7 @@ extern char __sched_text_start[], __sched_text_end[];
80072 extern int in_sched_functions(unsigned long addr);
80073
80074 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
80075 -extern signed long schedule_timeout(signed long timeout);
80076 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
80077 extern signed long schedule_timeout_interruptible(signed long timeout);
80078 extern signed long schedule_timeout_killable(signed long timeout);
80079 extern signed long schedule_timeout_uninterruptible(signed long timeout);
80080 @@ -315,6 +316,19 @@ struct nsproxy;
80081 struct user_namespace;
80082
80083 #ifdef CONFIG_MMU
80084 +
80085 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
80086 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
80087 +#else
80088 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
80089 +{
80090 + return 0;
80091 +}
80092 +#endif
80093 +
80094 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
80095 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
80096 +
80097 extern void arch_pick_mmap_layout(struct mm_struct *mm);
80098 extern unsigned long
80099 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
80100 @@ -600,6 +614,17 @@ struct signal_struct {
80101 #ifdef CONFIG_TASKSTATS
80102 struct taskstats *stats;
80103 #endif
80104 +
80105 +#ifdef CONFIG_GRKERNSEC
80106 + u32 curr_ip;
80107 + u32 saved_ip;
80108 + u32 gr_saddr;
80109 + u32 gr_daddr;
80110 + u16 gr_sport;
80111 + u16 gr_dport;
80112 + u8 used_accept:1;
80113 +#endif
80114 +
80115 #ifdef CONFIG_AUDIT
80116 unsigned audit_tty;
80117 unsigned audit_tty_log_passwd;
80118 @@ -626,7 +651,7 @@ struct signal_struct {
80119 struct mutex cred_guard_mutex; /* guard against foreign influences on
80120 * credential calculations
80121 * (notably. ptrace) */
80122 -};
80123 +} __randomize_layout;
80124
80125 /*
80126 * Bits in flags field of signal_struct.
80127 @@ -680,6 +705,14 @@ struct user_struct {
80128 struct key *session_keyring; /* UID's default session keyring */
80129 #endif
80130
80131 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
80132 + unsigned char kernel_banned;
80133 +#endif
80134 +#ifdef CONFIG_GRKERNSEC_BRUTE
80135 + unsigned char suid_banned;
80136 + unsigned long suid_ban_expires;
80137 +#endif
80138 +
80139 /* Hash table maintenance information */
80140 struct hlist_node uidhash_node;
80141 kuid_t uid;
80142 @@ -687,7 +720,7 @@ struct user_struct {
80143 #ifdef CONFIG_PERF_EVENTS
80144 atomic_long_t locked_vm;
80145 #endif
80146 -};
80147 +} __randomize_layout;
80148
80149 extern int uids_sysfs_init(void);
80150
80151 @@ -1162,8 +1195,8 @@ struct task_struct {
80152 struct list_head thread_group;
80153
80154 struct completion *vfork_done; /* for vfork() */
80155 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
80156 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
80157 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
80158 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
80159
80160 cputime_t utime, stime, utimescaled, stimescaled;
80161 cputime_t gtime;
80162 @@ -1188,11 +1221,6 @@ struct task_struct {
80163 struct task_cputime cputime_expires;
80164 struct list_head cpu_timers[3];
80165
80166 -/* process credentials */
80167 - const struct cred __rcu *real_cred; /* objective and real subjective task
80168 - * credentials (COW) */
80169 - const struct cred __rcu *cred; /* effective (overridable) subjective task
80170 - * credentials (COW) */
80171 char comm[TASK_COMM_LEN]; /* executable name excluding path
80172 - access with [gs]et_task_comm (which lock
80173 it with task_lock())
80174 @@ -1209,6 +1237,10 @@ struct task_struct {
80175 #endif
80176 /* CPU-specific state of this task */
80177 struct thread_struct thread;
80178 +/* thread_info moved to task_struct */
80179 +#ifdef CONFIG_X86
80180 + struct thread_info tinfo;
80181 +#endif
80182 /* filesystem information */
80183 struct fs_struct *fs;
80184 /* open file information */
80185 @@ -1282,6 +1314,10 @@ struct task_struct {
80186 gfp_t lockdep_reclaim_gfp;
80187 #endif
80188
80189 +/* process credentials */
80190 + const struct cred __rcu *real_cred; /* objective and real subjective task
80191 + * credentials (COW) */
80192 +
80193 /* journalling filesystem info */
80194 void *journal_info;
80195
80196 @@ -1320,6 +1356,10 @@ struct task_struct {
80197 /* cg_list protected by css_set_lock and tsk->alloc_lock */
80198 struct list_head cg_list;
80199 #endif
80200 +
80201 + const struct cred __rcu *cred; /* effective (overridable) subjective task
80202 + * credentials (COW) */
80203 +
80204 #ifdef CONFIG_FUTEX
80205 struct robust_list_head __user *robust_list;
80206 #ifdef CONFIG_COMPAT
80207 @@ -1454,7 +1494,78 @@ struct task_struct {
80208 unsigned int sequential_io;
80209 unsigned int sequential_io_avg;
80210 #endif
80211 -};
80212 +
80213 +#ifdef CONFIG_GRKERNSEC
80214 + /* grsecurity */
80215 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80216 + u64 exec_id;
80217 +#endif
80218 +#ifdef CONFIG_GRKERNSEC_SETXID
80219 + const struct cred *delayed_cred;
80220 +#endif
80221 + struct dentry *gr_chroot_dentry;
80222 + struct acl_subject_label *acl;
80223 + struct acl_subject_label *tmpacl;
80224 + struct acl_role_label *role;
80225 + struct file *exec_file;
80226 + unsigned long brute_expires;
80227 + u16 acl_role_id;
80228 + u8 inherited;
80229 + /* is this the task that authenticated to the special role */
80230 + u8 acl_sp_role;
80231 + u8 is_writable;
80232 + u8 brute;
80233 + u8 gr_is_chrooted;
80234 +#endif
80235 +
80236 +} __randomize_layout;
80237 +
80238 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
80239 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
80240 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
80241 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
80242 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
80243 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
80244 +
80245 +#ifdef CONFIG_PAX_SOFTMODE
80246 +extern int pax_softmode;
80247 +#endif
80248 +
80249 +extern int pax_check_flags(unsigned long *);
80250 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
80251 +
80252 +/* if tsk != current then task_lock must be held on it */
80253 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80254 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
80255 +{
80256 + if (likely(tsk->mm))
80257 + return tsk->mm->pax_flags;
80258 + else
80259 + return 0UL;
80260 +}
80261 +
80262 +/* if tsk != current then task_lock must be held on it */
80263 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
80264 +{
80265 + if (likely(tsk->mm)) {
80266 + tsk->mm->pax_flags = flags;
80267 + return 0;
80268 + }
80269 + return -EINVAL;
80270 +}
80271 +#endif
80272 +
80273 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
80274 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
80275 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
80276 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
80277 +#endif
80278 +
80279 +struct path;
80280 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
80281 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
80282 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
80283 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
80284
80285 /* Future-safe accessor for struct task_struct's cpus_allowed. */
80286 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
80287 @@ -1531,7 +1642,7 @@ struct pid_namespace;
80288 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
80289 struct pid_namespace *ns);
80290
80291 -static inline pid_t task_pid_nr(struct task_struct *tsk)
80292 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
80293 {
80294 return tsk->pid;
80295 }
80296 @@ -1981,7 +2092,9 @@ void yield(void);
80297 extern struct exec_domain default_exec_domain;
80298
80299 union thread_union {
80300 +#ifndef CONFIG_X86
80301 struct thread_info thread_info;
80302 +#endif
80303 unsigned long stack[THREAD_SIZE/sizeof(long)];
80304 };
80305
80306 @@ -2014,6 +2127,7 @@ extern struct pid_namespace init_pid_ns;
80307 */
80308
80309 extern struct task_struct *find_task_by_vpid(pid_t nr);
80310 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
80311 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
80312 struct pid_namespace *ns);
80313
80314 @@ -2178,7 +2292,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
80315 extern void exit_itimers(struct signal_struct *);
80316 extern void flush_itimer_signals(void);
80317
80318 -extern void do_group_exit(int);
80319 +extern __noreturn void do_group_exit(int);
80320
80321 extern int allow_signal(int);
80322 extern int disallow_signal(int);
80323 @@ -2369,9 +2483,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
80324
80325 #endif
80326
80327 -static inline int object_is_on_stack(void *obj)
80328 +static inline int object_starts_on_stack(void *obj)
80329 {
80330 - void *stack = task_stack_page(current);
80331 + const void *stack = task_stack_page(current);
80332
80333 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
80334 }
80335 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
80336 index 41467f8..1e4253d 100644
80337 --- a/include/linux/sched/sysctl.h
80338 +++ b/include/linux/sched/sysctl.h
80339 @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
80340 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
80341
80342 extern int sysctl_max_map_count;
80343 +extern unsigned long sysctl_heap_stack_gap;
80344
80345 extern unsigned int sysctl_sched_latency;
80346 extern unsigned int sysctl_sched_min_granularity;
80347 diff --git a/include/linux/security.h b/include/linux/security.h
80348 index 5623a7f..b352409 100644
80349 --- a/include/linux/security.h
80350 +++ b/include/linux/security.h
80351 @@ -27,6 +27,7 @@
80352 #include <linux/slab.h>
80353 #include <linux/err.h>
80354 #include <linux/string.h>
80355 +#include <linux/grsecurity.h>
80356
80357 struct linux_binprm;
80358 struct cred;
80359 @@ -116,8 +117,6 @@ struct seq_file;
80360
80361 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
80362
80363 -void reset_security_ops(void);
80364 -
80365 #ifdef CONFIG_MMU
80366 extern unsigned long mmap_min_addr;
80367 extern unsigned long dac_mmap_min_addr;
80368 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
80369 index dc368b8..e895209 100644
80370 --- a/include/linux/semaphore.h
80371 +++ b/include/linux/semaphore.h
80372 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
80373 }
80374
80375 extern void down(struct semaphore *sem);
80376 -extern int __must_check down_interruptible(struct semaphore *sem);
80377 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
80378 extern int __must_check down_killable(struct semaphore *sem);
80379 extern int __must_check down_trylock(struct semaphore *sem);
80380 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
80381 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
80382 index 52e0097..09625ef 100644
80383 --- a/include/linux/seq_file.h
80384 +++ b/include/linux/seq_file.h
80385 @@ -27,6 +27,9 @@ struct seq_file {
80386 struct mutex lock;
80387 const struct seq_operations *op;
80388 int poll_event;
80389 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80390 + u64 exec_id;
80391 +#endif
80392 #ifdef CONFIG_USER_NS
80393 struct user_namespace *user_ns;
80394 #endif
80395 @@ -39,6 +42,7 @@ struct seq_operations {
80396 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
80397 int (*show) (struct seq_file *m, void *v);
80398 };
80399 +typedef struct seq_operations __no_const seq_operations_no_const;
80400
80401 #define SEQ_SKIP 1
80402
80403 diff --git a/include/linux/shm.h b/include/linux/shm.h
80404 index 429c199..4d42e38 100644
80405 --- a/include/linux/shm.h
80406 +++ b/include/linux/shm.h
80407 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
80408
80409 /* The task created the shm object. NULL if the task is dead. */
80410 struct task_struct *shm_creator;
80411 +#ifdef CONFIG_GRKERNSEC
80412 + time_t shm_createtime;
80413 + pid_t shm_lapid;
80414 +#endif
80415 };
80416
80417 /* shm_mode upper byte flags */
80418 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
80419 index 6f69b3f..71ac613 100644
80420 --- a/include/linux/skbuff.h
80421 +++ b/include/linux/skbuff.h
80422 @@ -643,7 +643,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
80423 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
80424 int node);
80425 struct sk_buff *build_skb(void *data, unsigned int frag_size);
80426 -static inline struct sk_buff *alloc_skb(unsigned int size,
80427 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
80428 gfp_t priority)
80429 {
80430 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
80431 @@ -750,7 +750,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
80432 */
80433 static inline int skb_queue_empty(const struct sk_buff_head *list)
80434 {
80435 - return list->next == (struct sk_buff *)list;
80436 + return list->next == (const struct sk_buff *)list;
80437 }
80438
80439 /**
80440 @@ -763,7 +763,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
80441 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
80442 const struct sk_buff *skb)
80443 {
80444 - return skb->next == (struct sk_buff *)list;
80445 + return skb->next == (const struct sk_buff *)list;
80446 }
80447
80448 /**
80449 @@ -776,7 +776,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
80450 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
80451 const struct sk_buff *skb)
80452 {
80453 - return skb->prev == (struct sk_buff *)list;
80454 + return skb->prev == (const struct sk_buff *)list;
80455 }
80456
80457 /**
80458 @@ -1686,7 +1686,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
80459 return skb->inner_transport_header - skb->inner_network_header;
80460 }
80461
80462 -static inline int skb_network_offset(const struct sk_buff *skb)
80463 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
80464 {
80465 return skb_network_header(skb) - skb->data;
80466 }
80467 @@ -1746,7 +1746,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
80468 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
80469 */
80470 #ifndef NET_SKB_PAD
80471 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
80472 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
80473 #endif
80474
80475 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
80476 @@ -2345,7 +2345,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
80477 int *err);
80478 unsigned int datagram_poll(struct file *file, struct socket *sock,
80479 struct poll_table_struct *wait);
80480 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
80481 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
80482 struct iovec *to, int size);
80483 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
80484 struct iovec *iov);
80485 @@ -2617,6 +2617,9 @@ static inline void nf_reset(struct sk_buff *skb)
80486 nf_bridge_put(skb->nf_bridge);
80487 skb->nf_bridge = NULL;
80488 #endif
80489 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
80490 + skb->nf_trace = 0;
80491 +#endif
80492 }
80493
80494 static inline void nf_reset_trace(struct sk_buff *skb)
80495 diff --git a/include/linux/slab.h b/include/linux/slab.h
80496 index 1e2f4fe..df49ca6 100644
80497 --- a/include/linux/slab.h
80498 +++ b/include/linux/slab.h
80499 @@ -14,15 +14,29 @@
80500 #include <linux/gfp.h>
80501 #include <linux/types.h>
80502 #include <linux/workqueue.h>
80503 -
80504 +#include <linux/err.h>
80505
80506 /*
80507 * Flags to pass to kmem_cache_create().
80508 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
80509 */
80510 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
80511 +
80512 +#ifdef CONFIG_PAX_USERCOPY_SLABS
80513 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
80514 +#else
80515 +#define SLAB_USERCOPY 0x00000000UL
80516 +#endif
80517 +
80518 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
80519 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
80520 +
80521 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
80522 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
80523 +#else
80524 +#define SLAB_NO_SANITIZE 0x00000000UL
80525 +#endif
80526 +
80527 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
80528 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
80529 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
80530 @@ -98,10 +112,13 @@
80531 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
80532 * Both make kfree a no-op.
80533 */
80534 -#define ZERO_SIZE_PTR ((void *)16)
80535 +#define ZERO_SIZE_PTR \
80536 +({ \
80537 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
80538 + (void *)(-MAX_ERRNO-1L); \
80539 +})
80540
80541 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
80542 - (unsigned long)ZERO_SIZE_PTR)
80543 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
80544
80545 #include <linux/kmemleak.h>
80546
80547 @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
80548 void kfree(const void *);
80549 void kzfree(const void *);
80550 size_t ksize(const void *);
80551 +const char *check_heap_object(const void *ptr, unsigned long n);
80552 +bool is_usercopy_object(const void *ptr);
80553
80554 /*
80555 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
80556 @@ -174,7 +193,7 @@ struct kmem_cache {
80557 unsigned int align; /* Alignment as calculated */
80558 unsigned long flags; /* Active flags on the slab */
80559 const char *name; /* Slab name for sysfs */
80560 - int refcount; /* Use counter */
80561 + atomic_t refcount; /* Use counter */
80562 void (*ctor)(void *); /* Called on object slot creation */
80563 struct list_head list; /* List of all slab caches on the system */
80564 };
80565 @@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
80566 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
80567 #endif
80568
80569 +#ifdef CONFIG_PAX_USERCOPY_SLABS
80570 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
80571 +#endif
80572 +
80573 /*
80574 * Figure out which kmalloc slab an allocation of a certain size
80575 * belongs to.
80576 @@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
80577 * 2 = 120 .. 192 bytes
80578 * n = 2^(n-1) .. 2^n -1
80579 */
80580 -static __always_inline int kmalloc_index(size_t size)
80581 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
80582 {
80583 if (!size)
80584 return 0;
80585 @@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
80586 }
80587 #endif /* !CONFIG_SLOB */
80588
80589 -void *__kmalloc(size_t size, gfp_t flags);
80590 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
80591 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
80592
80593 #ifdef CONFIG_NUMA
80594 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
80595 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
80596 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
80597 #else
80598 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
80599 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
80600 index 09bfffb..4fc80fb 100644
80601 --- a/include/linux/slab_def.h
80602 +++ b/include/linux/slab_def.h
80603 @@ -36,7 +36,7 @@ struct kmem_cache {
80604 /* 4) cache creation/removal */
80605 const char *name;
80606 struct list_head list;
80607 - int refcount;
80608 + atomic_t refcount;
80609 int object_size;
80610 int align;
80611
80612 @@ -52,10 +52,14 @@ struct kmem_cache {
80613 unsigned long node_allocs;
80614 unsigned long node_frees;
80615 unsigned long node_overflow;
80616 - atomic_t allochit;
80617 - atomic_t allocmiss;
80618 - atomic_t freehit;
80619 - atomic_t freemiss;
80620 + atomic_unchecked_t allochit;
80621 + atomic_unchecked_t allocmiss;
80622 + atomic_unchecked_t freehit;
80623 + atomic_unchecked_t freemiss;
80624 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
80625 + atomic_unchecked_t sanitized;
80626 + atomic_unchecked_t not_sanitized;
80627 +#endif
80628
80629 /*
80630 * If debugging is enabled, then the allocator can add additional
80631 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
80632 index f56bfa9..8378a26 100644
80633 --- a/include/linux/slub_def.h
80634 +++ b/include/linux/slub_def.h
80635 @@ -74,7 +74,7 @@ struct kmem_cache {
80636 struct kmem_cache_order_objects max;
80637 struct kmem_cache_order_objects min;
80638 gfp_t allocflags; /* gfp flags to use on each alloc */
80639 - int refcount; /* Refcount for slab cache destroy */
80640 + atomic_t refcount; /* Refcount for slab cache destroy */
80641 void (*ctor)(void *);
80642 int inuse; /* Offset to metadata */
80643 int align; /* Alignment */
80644 diff --git a/include/linux/smp.h b/include/linux/smp.h
80645 index 5da22ee..71d8a28 100644
80646 --- a/include/linux/smp.h
80647 +++ b/include/linux/smp.h
80648 @@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
80649 #endif
80650
80651 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
80652 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
80653 #define put_cpu() preempt_enable()
80654 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
80655
80656 /*
80657 * Callback to arch code if there's nosmp or maxcpus=0 on the
80658 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
80659 index 54f91d3..be2c379 100644
80660 --- a/include/linux/sock_diag.h
80661 +++ b/include/linux/sock_diag.h
80662 @@ -11,7 +11,7 @@ struct sock;
80663 struct sock_diag_handler {
80664 __u8 family;
80665 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
80666 -};
80667 +} __do_const;
80668
80669 int sock_diag_register(const struct sock_diag_handler *h);
80670 void sock_diag_unregister(const struct sock_diag_handler *h);
80671 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
80672 index 680f9a3..f13aeb0 100644
80673 --- a/include/linux/sonet.h
80674 +++ b/include/linux/sonet.h
80675 @@ -7,7 +7,7 @@
80676 #include <uapi/linux/sonet.h>
80677
80678 struct k_sonet_stats {
80679 -#define __HANDLE_ITEM(i) atomic_t i
80680 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
80681 __SONET_ITEMS
80682 #undef __HANDLE_ITEM
80683 };
80684 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
80685 index 07d8e53..dc934c9 100644
80686 --- a/include/linux/sunrpc/addr.h
80687 +++ b/include/linux/sunrpc/addr.h
80688 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
80689 {
80690 switch (sap->sa_family) {
80691 case AF_INET:
80692 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
80693 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
80694 case AF_INET6:
80695 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
80696 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
80697 }
80698 return 0;
80699 }
80700 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
80701 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
80702 const struct sockaddr *src)
80703 {
80704 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
80705 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
80706 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
80707
80708 dsin->sin_family = ssin->sin_family;
80709 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
80710 if (sa->sa_family != AF_INET6)
80711 return 0;
80712
80713 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
80714 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
80715 }
80716
80717 #endif /* _LINUX_SUNRPC_ADDR_H */
80718 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
80719 index 8af2804..c7414ef 100644
80720 --- a/include/linux/sunrpc/clnt.h
80721 +++ b/include/linux/sunrpc/clnt.h
80722 @@ -97,7 +97,7 @@ struct rpc_procinfo {
80723 unsigned int p_timer; /* Which RTT timer to use */
80724 u32 p_statidx; /* Which procedure to account */
80725 const char * p_name; /* name of procedure */
80726 -};
80727 +} __do_const;
80728
80729 #ifdef __KERNEL__
80730
80731 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
80732 index 6eecfc2..7ada79d 100644
80733 --- a/include/linux/sunrpc/svc.h
80734 +++ b/include/linux/sunrpc/svc.h
80735 @@ -410,7 +410,7 @@ struct svc_procedure {
80736 unsigned int pc_count; /* call count */
80737 unsigned int pc_cachetype; /* cache info (NFS) */
80738 unsigned int pc_xdrressize; /* maximum size of XDR reply */
80739 -};
80740 +} __do_const;
80741
80742 /*
80743 * Function prototypes.
80744 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
80745 index 0b8e3e6..33e0a01 100644
80746 --- a/include/linux/sunrpc/svc_rdma.h
80747 +++ b/include/linux/sunrpc/svc_rdma.h
80748 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
80749 extern unsigned int svcrdma_max_requests;
80750 extern unsigned int svcrdma_max_req_size;
80751
80752 -extern atomic_t rdma_stat_recv;
80753 -extern atomic_t rdma_stat_read;
80754 -extern atomic_t rdma_stat_write;
80755 -extern atomic_t rdma_stat_sq_starve;
80756 -extern atomic_t rdma_stat_rq_starve;
80757 -extern atomic_t rdma_stat_rq_poll;
80758 -extern atomic_t rdma_stat_rq_prod;
80759 -extern atomic_t rdma_stat_sq_poll;
80760 -extern atomic_t rdma_stat_sq_prod;
80761 +extern atomic_unchecked_t rdma_stat_recv;
80762 +extern atomic_unchecked_t rdma_stat_read;
80763 +extern atomic_unchecked_t rdma_stat_write;
80764 +extern atomic_unchecked_t rdma_stat_sq_starve;
80765 +extern atomic_unchecked_t rdma_stat_rq_starve;
80766 +extern atomic_unchecked_t rdma_stat_rq_poll;
80767 +extern atomic_unchecked_t rdma_stat_rq_prod;
80768 +extern atomic_unchecked_t rdma_stat_sq_poll;
80769 +extern atomic_unchecked_t rdma_stat_sq_prod;
80770
80771 #define RPCRDMA_VERSION 1
80772
80773 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
80774 index 8d71d65..f79586e 100644
80775 --- a/include/linux/sunrpc/svcauth.h
80776 +++ b/include/linux/sunrpc/svcauth.h
80777 @@ -120,7 +120,7 @@ struct auth_ops {
80778 int (*release)(struct svc_rqst *rq);
80779 void (*domain_release)(struct auth_domain *);
80780 int (*set_client)(struct svc_rqst *rq);
80781 -};
80782 +} __do_const;
80783
80784 #define SVC_GARBAGE 1
80785 #define SVC_SYSERR 2
80786 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
80787 index a5ffd32..0935dea 100644
80788 --- a/include/linux/swiotlb.h
80789 +++ b/include/linux/swiotlb.h
80790 @@ -60,7 +60,8 @@ extern void
80791
80792 extern void
80793 swiotlb_free_coherent(struct device *hwdev, size_t size,
80794 - void *vaddr, dma_addr_t dma_handle);
80795 + void *vaddr, dma_addr_t dma_handle,
80796 + struct dma_attrs *attrs);
80797
80798 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
80799 unsigned long offset, size_t size,
80800 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
80801 index 94273bb..c2e05fc 100644
80802 --- a/include/linux/syscalls.h
80803 +++ b/include/linux/syscalls.h
80804 @@ -97,8 +97,14 @@ struct sigaltstack;
80805 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
80806
80807 #define __SC_DECL(t, a) t a
80808 +#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))
80809 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
80810 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
80811 +#define __SC_LONG(t, a) __typeof( \
80812 + __builtin_choose_expr( \
80813 + sizeof(t) > sizeof(int), \
80814 + (t) 0, \
80815 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
80816 + )) a
80817 #define __SC_CAST(t, a) (t) a
80818 #define __SC_ARGS(t, a) a
80819 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
80820 @@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
80821 asmlinkage long sys_fsync(unsigned int fd);
80822 asmlinkage long sys_fdatasync(unsigned int fd);
80823 asmlinkage long sys_bdflush(int func, long data);
80824 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
80825 - char __user *type, unsigned long flags,
80826 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
80827 + const char __user *type, unsigned long flags,
80828 void __user *data);
80829 -asmlinkage long sys_umount(char __user *name, int flags);
80830 -asmlinkage long sys_oldumount(char __user *name);
80831 +asmlinkage long sys_umount(const char __user *name, int flags);
80832 +asmlinkage long sys_oldumount(const char __user *name);
80833 asmlinkage long sys_truncate(const char __user *path, long length);
80834 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
80835 asmlinkage long sys_stat(const char __user *filename,
80836 @@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
80837 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
80838 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
80839 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
80840 - struct sockaddr __user *, int);
80841 + struct sockaddr __user *, int) __intentional_overflow(0);
80842 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
80843 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
80844 unsigned int vlen, unsigned flags);
80845 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
80846 index 27b3b0b..e093dd9 100644
80847 --- a/include/linux/syscore_ops.h
80848 +++ b/include/linux/syscore_ops.h
80849 @@ -16,7 +16,7 @@ struct syscore_ops {
80850 int (*suspend)(void);
80851 void (*resume)(void);
80852 void (*shutdown)(void);
80853 -};
80854 +} __do_const;
80855
80856 extern void register_syscore_ops(struct syscore_ops *ops);
80857 extern void unregister_syscore_ops(struct syscore_ops *ops);
80858 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
80859 index 14a8ff2..fa95f3a 100644
80860 --- a/include/linux/sysctl.h
80861 +++ b/include/linux/sysctl.h
80862 @@ -34,13 +34,13 @@ struct ctl_table_root;
80863 struct ctl_table_header;
80864 struct ctl_dir;
80865
80866 -typedef struct ctl_table ctl_table;
80867 -
80868 typedef int proc_handler (struct ctl_table *ctl, int write,
80869 void __user *buffer, size_t *lenp, loff_t *ppos);
80870
80871 extern int proc_dostring(struct ctl_table *, int,
80872 void __user *, size_t *, loff_t *);
80873 +extern int proc_dostring_modpriv(struct ctl_table *, int,
80874 + void __user *, size_t *, loff_t *);
80875 extern int proc_dointvec(struct ctl_table *, int,
80876 void __user *, size_t *, loff_t *);
80877 extern int proc_dointvec_minmax(struct ctl_table *, int,
80878 @@ -115,7 +115,9 @@ struct ctl_table
80879 struct ctl_table_poll *poll;
80880 void *extra1;
80881 void *extra2;
80882 -};
80883 +} __do_const __randomize_layout;
80884 +typedef struct ctl_table __no_const ctl_table_no_const;
80885 +typedef struct ctl_table ctl_table;
80886
80887 struct ctl_node {
80888 struct rb_node node;
80889 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
80890 index 6695040..3d4192d 100644
80891 --- a/include/linux/sysfs.h
80892 +++ b/include/linux/sysfs.h
80893 @@ -33,7 +33,8 @@ struct attribute {
80894 struct lock_class_key *key;
80895 struct lock_class_key skey;
80896 #endif
80897 -};
80898 +} __do_const;
80899 +typedef struct attribute __no_const attribute_no_const;
80900
80901 /**
80902 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
80903 @@ -62,7 +63,8 @@ struct attribute_group {
80904 struct attribute *, int);
80905 struct attribute **attrs;
80906 struct bin_attribute **bin_attrs;
80907 -};
80908 +} __do_const;
80909 +typedef struct attribute_group __no_const attribute_group_no_const;
80910
80911 /**
80912 * Use these macros to make defining attributes easier. See include/linux/device.h
80913 @@ -126,7 +128,8 @@ struct bin_attribute {
80914 char *, loff_t, size_t);
80915 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
80916 struct vm_area_struct *vma);
80917 -};
80918 +} __do_const;
80919 +typedef struct bin_attribute __no_const bin_attribute_no_const;
80920
80921 /**
80922 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
80923 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
80924 index 387fa7d..3fcde6b 100644
80925 --- a/include/linux/sysrq.h
80926 +++ b/include/linux/sysrq.h
80927 @@ -16,6 +16,7 @@
80928
80929 #include <linux/errno.h>
80930 #include <linux/types.h>
80931 +#include <linux/compiler.h>
80932
80933 /* Possible values of bitmask for enabling sysrq functions */
80934 /* 0x0001 is reserved for enable everything */
80935 @@ -33,7 +34,7 @@ struct sysrq_key_op {
80936 char *help_msg;
80937 char *action_msg;
80938 int enable_mask;
80939 -};
80940 +} __do_const;
80941
80942 #ifdef CONFIG_MAGIC_SYSRQ
80943
80944 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
80945 index fddbe20..0312de8 100644
80946 --- a/include/linux/thread_info.h
80947 +++ b/include/linux/thread_info.h
80948 @@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
80949 #error "no set_restore_sigmask() provided and default one won't work"
80950 #endif
80951
80952 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
80953 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
80954 +{
80955 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
80956 + if (!__builtin_constant_p(n))
80957 +#endif
80958 + __check_object_size(ptr, n, to_user);
80959 +}
80960 +
80961 #endif /* __KERNEL__ */
80962
80963 #endif /* _LINUX_THREAD_INFO_H */
80964 diff --git a/include/linux/tty.h b/include/linux/tty.h
80965 index 97d660e..6356755 100644
80966 --- a/include/linux/tty.h
80967 +++ b/include/linux/tty.h
80968 @@ -196,7 +196,7 @@ struct tty_port {
80969 const struct tty_port_operations *ops; /* Port operations */
80970 spinlock_t lock; /* Lock protecting tty field */
80971 int blocked_open; /* Waiting to open */
80972 - int count; /* Usage count */
80973 + atomic_t count; /* Usage count */
80974 wait_queue_head_t open_wait; /* Open waiters */
80975 wait_queue_head_t close_wait; /* Close waiters */
80976 wait_queue_head_t delta_msr_wait; /* Modem status change */
80977 @@ -278,7 +278,7 @@ struct tty_struct {
80978 /* If the tty has a pending do_SAK, queue it here - akpm */
80979 struct work_struct SAK_work;
80980 struct tty_port *port;
80981 -};
80982 +} __randomize_layout;
80983
80984 /* Each of a tty's open files has private_data pointing to tty_file_private */
80985 struct tty_file_private {
80986 @@ -545,7 +545,7 @@ extern int tty_port_open(struct tty_port *port,
80987 struct tty_struct *tty, struct file *filp);
80988 static inline int tty_port_users(struct tty_port *port)
80989 {
80990 - return port->count + port->blocked_open;
80991 + return atomic_read(&port->count) + port->blocked_open;
80992 }
80993
80994 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
80995 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
80996 index 756a609..f61242d 100644
80997 --- a/include/linux/tty_driver.h
80998 +++ b/include/linux/tty_driver.h
80999 @@ -285,7 +285,7 @@ struct tty_operations {
81000 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
81001 #endif
81002 const struct file_operations *proc_fops;
81003 -};
81004 +} __do_const;
81005
81006 struct tty_driver {
81007 int magic; /* magic number for this structure */
81008 @@ -319,7 +319,7 @@ struct tty_driver {
81009
81010 const struct tty_operations *ops;
81011 struct list_head tty_drivers;
81012 -};
81013 +} __randomize_layout;
81014
81015 extern struct list_head tty_drivers;
81016
81017 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
81018 index f15c898..207b7d1 100644
81019 --- a/include/linux/tty_ldisc.h
81020 +++ b/include/linux/tty_ldisc.h
81021 @@ -211,7 +211,7 @@ struct tty_ldisc_ops {
81022
81023 struct module *owner;
81024
81025 - int refcount;
81026 + atomic_t refcount;
81027 };
81028
81029 struct tty_ldisc {
81030 diff --git a/include/linux/types.h b/include/linux/types.h
81031 index 4d118ba..c3ee9bf 100644
81032 --- a/include/linux/types.h
81033 +++ b/include/linux/types.h
81034 @@ -176,10 +176,26 @@ typedef struct {
81035 int counter;
81036 } atomic_t;
81037
81038 +#ifdef CONFIG_PAX_REFCOUNT
81039 +typedef struct {
81040 + int counter;
81041 +} atomic_unchecked_t;
81042 +#else
81043 +typedef atomic_t atomic_unchecked_t;
81044 +#endif
81045 +
81046 #ifdef CONFIG_64BIT
81047 typedef struct {
81048 long counter;
81049 } atomic64_t;
81050 +
81051 +#ifdef CONFIG_PAX_REFCOUNT
81052 +typedef struct {
81053 + long counter;
81054 +} atomic64_unchecked_t;
81055 +#else
81056 +typedef atomic64_t atomic64_unchecked_t;
81057 +#endif
81058 #endif
81059
81060 struct list_head {
81061 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
81062 index 9d8cf05..0ed74dd 100644
81063 --- a/include/linux/uaccess.h
81064 +++ b/include/linux/uaccess.h
81065 @@ -72,11 +72,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
81066 long ret; \
81067 mm_segment_t old_fs = get_fs(); \
81068 \
81069 - set_fs(KERNEL_DS); \
81070 pagefault_disable(); \
81071 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
81072 - pagefault_enable(); \
81073 + set_fs(KERNEL_DS); \
81074 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
81075 set_fs(old_fs); \
81076 + pagefault_enable(); \
81077 ret; \
81078 })
81079
81080 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
81081 index 8e522cbc..aa8572d 100644
81082 --- a/include/linux/uidgid.h
81083 +++ b/include/linux/uidgid.h
81084 @@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
81085
81086 #endif /* CONFIG_USER_NS */
81087
81088 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
81089 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
81090 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
81091 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
81092 +
81093 #endif /* _LINUX_UIDGID_H */
81094 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
81095 index 99c1b4d..562e6f3 100644
81096 --- a/include/linux/unaligned/access_ok.h
81097 +++ b/include/linux/unaligned/access_ok.h
81098 @@ -4,34 +4,34 @@
81099 #include <linux/kernel.h>
81100 #include <asm/byteorder.h>
81101
81102 -static inline u16 get_unaligned_le16(const void *p)
81103 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
81104 {
81105 - return le16_to_cpup((__le16 *)p);
81106 + return le16_to_cpup((const __le16 *)p);
81107 }
81108
81109 -static inline u32 get_unaligned_le32(const void *p)
81110 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
81111 {
81112 - return le32_to_cpup((__le32 *)p);
81113 + return le32_to_cpup((const __le32 *)p);
81114 }
81115
81116 -static inline u64 get_unaligned_le64(const void *p)
81117 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
81118 {
81119 - return le64_to_cpup((__le64 *)p);
81120 + return le64_to_cpup((const __le64 *)p);
81121 }
81122
81123 -static inline u16 get_unaligned_be16(const void *p)
81124 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
81125 {
81126 - return be16_to_cpup((__be16 *)p);
81127 + return be16_to_cpup((const __be16 *)p);
81128 }
81129
81130 -static inline u32 get_unaligned_be32(const void *p)
81131 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
81132 {
81133 - return be32_to_cpup((__be32 *)p);
81134 + return be32_to_cpup((const __be32 *)p);
81135 }
81136
81137 -static inline u64 get_unaligned_be64(const void *p)
81138 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
81139 {
81140 - return be64_to_cpup((__be64 *)p);
81141 + return be64_to_cpup((const __be64 *)p);
81142 }
81143
81144 static inline void put_unaligned_le16(u16 val, void *p)
81145 diff --git a/include/linux/usb.h b/include/linux/usb.h
81146 index 512ab16..f53e1bf 100644
81147 --- a/include/linux/usb.h
81148 +++ b/include/linux/usb.h
81149 @@ -563,7 +563,7 @@ struct usb_device {
81150 int maxchild;
81151
81152 u32 quirks;
81153 - atomic_t urbnum;
81154 + atomic_unchecked_t urbnum;
81155
81156 unsigned long active_duration;
81157
81158 @@ -1643,7 +1643,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
81159
81160 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
81161 __u8 request, __u8 requesttype, __u16 value, __u16 index,
81162 - void *data, __u16 size, int timeout);
81163 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
81164 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
81165 void *data, int len, int *actual_length, int timeout);
81166 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
81167 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
81168 index e452ba6..78f8e80 100644
81169 --- a/include/linux/usb/renesas_usbhs.h
81170 +++ b/include/linux/usb/renesas_usbhs.h
81171 @@ -39,7 +39,7 @@ enum {
81172 */
81173 struct renesas_usbhs_driver_callback {
81174 int (*notify_hotplug)(struct platform_device *pdev);
81175 -};
81176 +} __no_const;
81177
81178 /*
81179 * callback functions for platform
81180 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
81181 index 4836ba3..603f6ee 100644
81182 --- a/include/linux/user_namespace.h
81183 +++ b/include/linux/user_namespace.h
81184 @@ -33,7 +33,7 @@ struct user_namespace {
81185 struct key *persistent_keyring_register;
81186 struct rw_semaphore persistent_keyring_register_sem;
81187 #endif
81188 -};
81189 +} __randomize_layout;
81190
81191 extern struct user_namespace init_user_ns;
81192
81193 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
81194 index 239e277..22a5cf5 100644
81195 --- a/include/linux/utsname.h
81196 +++ b/include/linux/utsname.h
81197 @@ -24,7 +24,7 @@ struct uts_namespace {
81198 struct new_utsname name;
81199 struct user_namespace *user_ns;
81200 unsigned int proc_inum;
81201 -};
81202 +} __randomize_layout;
81203 extern struct uts_namespace init_uts_ns;
81204
81205 #ifdef CONFIG_UTS_NS
81206 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
81207 index 6f8fbcf..e2a0e61 100644
81208 --- a/include/linux/vermagic.h
81209 +++ b/include/linux/vermagic.h
81210 @@ -25,9 +25,41 @@
81211 #define MODULE_ARCH_VERMAGIC ""
81212 #endif
81213
81214 +#ifdef CONFIG_PAX_REFCOUNT
81215 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
81216 +#else
81217 +#define MODULE_PAX_REFCOUNT ""
81218 +#endif
81219 +
81220 +#ifdef CONSTIFY_PLUGIN
81221 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
81222 +#else
81223 +#define MODULE_CONSTIFY_PLUGIN ""
81224 +#endif
81225 +
81226 +#ifdef STACKLEAK_PLUGIN
81227 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
81228 +#else
81229 +#define MODULE_STACKLEAK_PLUGIN ""
81230 +#endif
81231 +
81232 +#ifdef RANDSTRUCT_PLUGIN
81233 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
81234 +#else
81235 +#define MODULE_RANDSTRUCT_PLUGIN
81236 +#endif
81237 +
81238 +#ifdef CONFIG_GRKERNSEC
81239 +#define MODULE_GRSEC "GRSEC "
81240 +#else
81241 +#define MODULE_GRSEC ""
81242 +#endif
81243 +
81244 #define VERMAGIC_STRING \
81245 UTS_RELEASE " " \
81246 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
81247 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
81248 - MODULE_ARCH_VERMAGIC
81249 + MODULE_ARCH_VERMAGIC \
81250 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
81251 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
81252
81253 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
81254 index 502073a..a7de024 100644
81255 --- a/include/linux/vga_switcheroo.h
81256 +++ b/include/linux/vga_switcheroo.h
81257 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
81258
81259 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
81260
81261 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
81262 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
81263 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
81264 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
81265 #else
81266
81267 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
81268 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
81269
81270 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
81271
81272 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
81273 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
81274 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
81275 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
81276
81277 #endif
81278 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
81279 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
81280 index 4b8a891..cb8df6e 100644
81281 --- a/include/linux/vmalloc.h
81282 +++ b/include/linux/vmalloc.h
81283 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
81284 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
81285 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
81286 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
81287 +
81288 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
81289 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
81290 +#endif
81291 +
81292 /* bits [20..32] reserved for arch specific ioremap internals */
81293
81294 /*
81295 @@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
81296
81297 /* for /dev/kmem */
81298 extern long vread(char *buf, char *addr, unsigned long count);
81299 -extern long vwrite(char *buf, char *addr, unsigned long count);
81300 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
81301
81302 /*
81303 * Internals. Dont't use..
81304 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
81305 index e4b9480..5a5f65a 100644
81306 --- a/include/linux/vmstat.h
81307 +++ b/include/linux/vmstat.h
81308 @@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
81309 /*
81310 * Zone based page accounting with per cpu differentials.
81311 */
81312 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81313 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81314
81315 static inline void zone_page_state_add(long x, struct zone *zone,
81316 enum zone_stat_item item)
81317 {
81318 - atomic_long_add(x, &zone->vm_stat[item]);
81319 - atomic_long_add(x, &vm_stat[item]);
81320 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
81321 + atomic_long_add_unchecked(x, &vm_stat[item]);
81322 }
81323
81324 -static inline unsigned long global_page_state(enum zone_stat_item item)
81325 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
81326 {
81327 - long x = atomic_long_read(&vm_stat[item]);
81328 + long x = atomic_long_read_unchecked(&vm_stat[item]);
81329 #ifdef CONFIG_SMP
81330 if (x < 0)
81331 x = 0;
81332 @@ -109,10 +109,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
81333 return x;
81334 }
81335
81336 -static inline unsigned long zone_page_state(struct zone *zone,
81337 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
81338 enum zone_stat_item item)
81339 {
81340 - long x = atomic_long_read(&zone->vm_stat[item]);
81341 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
81342 #ifdef CONFIG_SMP
81343 if (x < 0)
81344 x = 0;
81345 @@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
81346 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
81347 enum zone_stat_item item)
81348 {
81349 - long x = atomic_long_read(&zone->vm_stat[item]);
81350 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
81351
81352 #ifdef CONFIG_SMP
81353 int cpu;
81354 @@ -220,8 +220,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
81355
81356 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
81357 {
81358 - atomic_long_inc(&zone->vm_stat[item]);
81359 - atomic_long_inc(&vm_stat[item]);
81360 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
81361 + atomic_long_inc_unchecked(&vm_stat[item]);
81362 }
81363
81364 static inline void __inc_zone_page_state(struct page *page,
81365 @@ -232,8 +232,8 @@ static inline void __inc_zone_page_state(struct page *page,
81366
81367 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
81368 {
81369 - atomic_long_dec(&zone->vm_stat[item]);
81370 - atomic_long_dec(&vm_stat[item]);
81371 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
81372 + atomic_long_dec_unchecked(&vm_stat[item]);
81373 }
81374
81375 static inline void __dec_zone_page_state(struct page *page,
81376 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
81377 index 91b0a68..0e9adf6 100644
81378 --- a/include/linux/xattr.h
81379 +++ b/include/linux/xattr.h
81380 @@ -28,7 +28,7 @@ struct xattr_handler {
81381 size_t size, int handler_flags);
81382 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
81383 size_t size, int flags, int handler_flags);
81384 -};
81385 +} __do_const;
81386
81387 struct xattr {
81388 const char *name;
81389 @@ -37,6 +37,9 @@ struct xattr {
81390 };
81391
81392 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
81393 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
81394 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
81395 +#endif
81396 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
81397 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
81398 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
81399 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
81400 index 9c5a6b4..09c9438 100644
81401 --- a/include/linux/zlib.h
81402 +++ b/include/linux/zlib.h
81403 @@ -31,6 +31,7 @@
81404 #define _ZLIB_H
81405
81406 #include <linux/zconf.h>
81407 +#include <linux/compiler.h>
81408
81409 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
81410 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
81411 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
81412
81413 /* basic functions */
81414
81415 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
81416 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
81417 /*
81418 Returns the number of bytes that needs to be allocated for a per-
81419 stream workspace with the specified parameters. A pointer to this
81420 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
81421 index c768c9f..bdcaa5a 100644
81422 --- a/include/media/v4l2-dev.h
81423 +++ b/include/media/v4l2-dev.h
81424 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
81425 int (*mmap) (struct file *, struct vm_area_struct *);
81426 int (*open) (struct file *);
81427 int (*release) (struct file *);
81428 -};
81429 +} __do_const;
81430
81431 /*
81432 * Newer version of video_device, handled by videodev2.c
81433 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
81434 index c9b1593..a572459 100644
81435 --- a/include/media/v4l2-device.h
81436 +++ b/include/media/v4l2-device.h
81437 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
81438 this function returns 0. If the name ends with a digit (e.g. cx18),
81439 then the name will be set to cx18-0 since cx180 looks really odd. */
81440 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
81441 - atomic_t *instance);
81442 + atomic_unchecked_t *instance);
81443
81444 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
81445 Since the parent disappears this ensures that v4l2_dev doesn't have an
81446 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
81447 index 9a36d92..0aafe2a 100644
81448 --- a/include/net/9p/transport.h
81449 +++ b/include/net/9p/transport.h
81450 @@ -60,7 +60,7 @@ struct p9_trans_module {
81451 int (*cancel) (struct p9_client *, struct p9_req_t *req);
81452 int (*zc_request)(struct p9_client *, struct p9_req_t *,
81453 char *, char *, int , int, int, int);
81454 -};
81455 +} __do_const;
81456
81457 void v9fs_register_trans(struct p9_trans_module *m);
81458 void v9fs_unregister_trans(struct p9_trans_module *m);
81459 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
81460 index c853b16d..37fccb7 100644
81461 --- a/include/net/bluetooth/l2cap.h
81462 +++ b/include/net/bluetooth/l2cap.h
81463 @@ -557,7 +557,7 @@ struct l2cap_ops {
81464 long (*get_sndtimeo) (struct l2cap_chan *chan);
81465 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
81466 unsigned long len, int nb);
81467 -};
81468 +} __do_const;
81469
81470 struct l2cap_conn {
81471 struct hci_conn *hcon;
81472 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
81473 index f2ae33d..c457cf0 100644
81474 --- a/include/net/caif/cfctrl.h
81475 +++ b/include/net/caif/cfctrl.h
81476 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
81477 void (*radioset_rsp)(void);
81478 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
81479 struct cflayer *client_layer);
81480 -};
81481 +} __no_const;
81482
81483 /* Link Setup Parameters for CAIF-Links. */
81484 struct cfctrl_link_param {
81485 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
81486 struct cfctrl {
81487 struct cfsrvl serv;
81488 struct cfctrl_rsp res;
81489 - atomic_t req_seq_no;
81490 - atomic_t rsp_seq_no;
81491 + atomic_unchecked_t req_seq_no;
81492 + atomic_unchecked_t rsp_seq_no;
81493 struct list_head list;
81494 /* Protects from simultaneous access to first_req list */
81495 spinlock_t info_list_lock;
81496 diff --git a/include/net/flow.h b/include/net/flow.h
81497 index 65ce471..b7bbe9b 100644
81498 --- a/include/net/flow.h
81499 +++ b/include/net/flow.h
81500 @@ -222,6 +222,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
81501
81502 void flow_cache_flush(void);
81503 void flow_cache_flush_deferred(void);
81504 -extern atomic_t flow_cache_genid;
81505 +extern atomic_unchecked_t flow_cache_genid;
81506
81507 #endif
81508 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
81509 index 1b177ed..a24a138 100644
81510 --- a/include/net/genetlink.h
81511 +++ b/include/net/genetlink.h
81512 @@ -118,7 +118,7 @@ struct genl_ops {
81513 u8 cmd;
81514 u8 internal_flags;
81515 u8 flags;
81516 -};
81517 +} __do_const;
81518
81519 int __genl_register_family(struct genl_family *family);
81520
81521 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
81522 index 734d9b5..48a9a4b 100644
81523 --- a/include/net/gro_cells.h
81524 +++ b/include/net/gro_cells.h
81525 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
81526 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
81527
81528 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
81529 - atomic_long_inc(&dev->rx_dropped);
81530 + atomic_long_inc_unchecked(&dev->rx_dropped);
81531 kfree_skb(skb);
81532 return;
81533 }
81534 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
81535 index c55aeed..b3393f4 100644
81536 --- a/include/net/inet_connection_sock.h
81537 +++ b/include/net/inet_connection_sock.h
81538 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
81539 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
81540 int (*bind_conflict)(const struct sock *sk,
81541 const struct inet_bind_bucket *tb, bool relax);
81542 -};
81543 +} __do_const;
81544
81545 /** inet_connection_sock - INET connection oriented sock
81546 *
81547 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
81548 index f4e127a..c3d5e9c 100644
81549 --- a/include/net/inetpeer.h
81550 +++ b/include/net/inetpeer.h
81551 @@ -47,8 +47,8 @@ struct inet_peer {
81552 */
81553 union {
81554 struct {
81555 - atomic_t rid; /* Frag reception counter */
81556 - atomic_t ip_id_count; /* IP ID for the next packet */
81557 + atomic_unchecked_t rid; /* Frag reception counter */
81558 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
81559 };
81560 struct rcu_head rcu;
81561 struct inet_peer *gc_next;
81562 @@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
81563 /* can be called with or without local BH being disabled */
81564 static inline int inet_getid(struct inet_peer *p, int more)
81565 {
81566 - int old, new;
81567 + int id;
81568 more++;
81569 inet_peer_refcheck(p);
81570 - do {
81571 - old = atomic_read(&p->ip_id_count);
81572 - new = old + more;
81573 - if (!new)
81574 - new = 1;
81575 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
81576 - return new;
81577 + id = atomic_add_return_unchecked(more, &p->ip_id_count);
81578 + if (!id)
81579 + id = atomic_inc_return_unchecked(&p->ip_id_count);
81580 + return id;
81581 }
81582
81583 #endif /* _NET_INETPEER_H */
81584 diff --git a/include/net/ip.h b/include/net/ip.h
81585 index 5a25f36..2e73203 100644
81586 --- a/include/net/ip.h
81587 +++ b/include/net/ip.h
81588 @@ -219,7 +219,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
81589
81590 void inet_get_local_port_range(struct net *net, int *low, int *high);
81591
81592 -extern unsigned long *sysctl_local_reserved_ports;
81593 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
81594 static inline int inet_is_reserved_local_port(int port)
81595 {
81596 return test_bit(port, sysctl_local_reserved_ports);
81597 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
81598 index 9922093..a1755d6 100644
81599 --- a/include/net/ip_fib.h
81600 +++ b/include/net/ip_fib.h
81601 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
81602
81603 #define FIB_RES_SADDR(net, res) \
81604 ((FIB_RES_NH(res).nh_saddr_genid == \
81605 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
81606 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
81607 FIB_RES_NH(res).nh_saddr : \
81608 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
81609 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
81610 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
81611 index 5679d92..2e7a690 100644
81612 --- a/include/net/ip_vs.h
81613 +++ b/include/net/ip_vs.h
81614 @@ -558,7 +558,7 @@ struct ip_vs_conn {
81615 struct ip_vs_conn *control; /* Master control connection */
81616 atomic_t n_control; /* Number of controlled ones */
81617 struct ip_vs_dest *dest; /* real server */
81618 - atomic_t in_pkts; /* incoming packet counter */
81619 + atomic_unchecked_t in_pkts; /* incoming packet counter */
81620
81621 /* packet transmitter for different forwarding methods. If it
81622 mangles the packet, it must return NF_DROP or better NF_STOLEN,
81623 @@ -705,7 +705,7 @@ struct ip_vs_dest {
81624 __be16 port; /* port number of the server */
81625 union nf_inet_addr addr; /* IP address of the server */
81626 volatile unsigned int flags; /* dest status flags */
81627 - atomic_t conn_flags; /* flags to copy to conn */
81628 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
81629 atomic_t weight; /* server weight */
81630
81631 atomic_t refcnt; /* reference counter */
81632 @@ -960,11 +960,11 @@ struct netns_ipvs {
81633 /* ip_vs_lblc */
81634 int sysctl_lblc_expiration;
81635 struct ctl_table_header *lblc_ctl_header;
81636 - struct ctl_table *lblc_ctl_table;
81637 + ctl_table_no_const *lblc_ctl_table;
81638 /* ip_vs_lblcr */
81639 int sysctl_lblcr_expiration;
81640 struct ctl_table_header *lblcr_ctl_header;
81641 - struct ctl_table *lblcr_ctl_table;
81642 + ctl_table_no_const *lblcr_ctl_table;
81643 /* ip_vs_est */
81644 struct list_head est_list; /* estimator list */
81645 spinlock_t est_lock;
81646 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
81647 index 0224402..dafaf94a 100644
81648 --- a/include/net/irda/ircomm_tty.h
81649 +++ b/include/net/irda/ircomm_tty.h
81650 @@ -35,6 +35,7 @@
81651 #include <linux/termios.h>
81652 #include <linux/timer.h>
81653 #include <linux/tty.h> /* struct tty_struct */
81654 +#include <asm/local.h>
81655
81656 #include <net/irda/irias_object.h>
81657 #include <net/irda/ircomm_core.h>
81658 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
81659 index 714cc9a..ea05f3e 100644
81660 --- a/include/net/iucv/af_iucv.h
81661 +++ b/include/net/iucv/af_iucv.h
81662 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
81663 struct iucv_sock_list {
81664 struct hlist_head head;
81665 rwlock_t lock;
81666 - atomic_t autobind_name;
81667 + atomic_unchecked_t autobind_name;
81668 };
81669
81670 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
81671 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
81672 index f3be818..bf46196 100644
81673 --- a/include/net/llc_c_ac.h
81674 +++ b/include/net/llc_c_ac.h
81675 @@ -87,7 +87,7 @@
81676 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
81677 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
81678
81679 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
81680 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
81681
81682 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
81683 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
81684 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
81685 index 3948cf1..83b28c4 100644
81686 --- a/include/net/llc_c_ev.h
81687 +++ b/include/net/llc_c_ev.h
81688 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
81689 return (struct llc_conn_state_ev *)skb->cb;
81690 }
81691
81692 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
81693 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
81694 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
81695 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
81696
81697 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
81698 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
81699 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
81700 index 0e79cfb..f46db31 100644
81701 --- a/include/net/llc_c_st.h
81702 +++ b/include/net/llc_c_st.h
81703 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
81704 u8 next_state;
81705 llc_conn_ev_qfyr_t *ev_qualifiers;
81706 llc_conn_action_t *ev_actions;
81707 -};
81708 +} __do_const;
81709
81710 struct llc_conn_state {
81711 u8 current_state;
81712 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
81713 index a61b98c..aade1eb 100644
81714 --- a/include/net/llc_s_ac.h
81715 +++ b/include/net/llc_s_ac.h
81716 @@ -23,7 +23,7 @@
81717 #define SAP_ACT_TEST_IND 9
81718
81719 /* All action functions must look like this */
81720 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
81721 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
81722
81723 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
81724 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
81725 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
81726 index 567c681..cd73ac0 100644
81727 --- a/include/net/llc_s_st.h
81728 +++ b/include/net/llc_s_st.h
81729 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
81730 llc_sap_ev_t ev;
81731 u8 next_state;
81732 llc_sap_action_t *ev_actions;
81733 -};
81734 +} __do_const;
81735
81736 struct llc_sap_state {
81737 u8 curr_state;
81738 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
81739 index 7ceed99..d3ffaa2 100644
81740 --- a/include/net/mac80211.h
81741 +++ b/include/net/mac80211.h
81742 @@ -4407,7 +4407,7 @@ struct rate_control_ops {
81743 void (*add_sta_debugfs)(void *priv, void *priv_sta,
81744 struct dentry *dir);
81745 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
81746 -};
81747 +} __do_const;
81748
81749 static inline int rate_supported(struct ieee80211_sta *sta,
81750 enum ieee80211_band band,
81751 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
81752 index 536501a..74ad02bc 100644
81753 --- a/include/net/neighbour.h
81754 +++ b/include/net/neighbour.h
81755 @@ -123,7 +123,7 @@ struct neigh_ops {
81756 void (*error_report)(struct neighbour *, struct sk_buff *);
81757 int (*output)(struct neighbour *, struct sk_buff *);
81758 int (*connected_output)(struct neighbour *, struct sk_buff *);
81759 -};
81760 +} __do_const;
81761
81762 struct pneigh_entry {
81763 struct pneigh_entry *next;
81764 @@ -178,7 +178,7 @@ struct neigh_table {
81765 struct neigh_statistics __percpu *stats;
81766 struct neigh_hash_table __rcu *nht;
81767 struct pneigh_entry **phash_buckets;
81768 -};
81769 +} __randomize_layout;
81770
81771 #define NEIGH_PRIV_ALIGN sizeof(long long)
81772 #define NEIGH_ENTRY_SIZE(size) ALIGN((size), NEIGH_PRIV_ALIGN)
81773 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
81774 index da68c9a..c4a0720 100644
81775 --- a/include/net/net_namespace.h
81776 +++ b/include/net/net_namespace.h
81777 @@ -124,8 +124,8 @@ struct net {
81778 struct netns_ipvs *ipvs;
81779 #endif
81780 struct sock *diag_nlsk;
81781 - atomic_t fnhe_genid;
81782 -};
81783 + atomic_unchecked_t fnhe_genid;
81784 +} __randomize_layout;
81785
81786 /*
81787 * ifindex generation is per-net namespace, and loopback is
81788 @@ -281,7 +281,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
81789 #define __net_init __init
81790 #define __net_exit __exit_refok
81791 #define __net_initdata __initdata
81792 +#ifdef CONSTIFY_PLUGIN
81793 #define __net_initconst __initconst
81794 +#else
81795 +#define __net_initconst __initdata
81796 +#endif
81797 #endif
81798
81799 struct pernet_operations {
81800 @@ -291,7 +295,7 @@ struct pernet_operations {
81801 void (*exit_batch)(struct list_head *net_exit_list);
81802 int *id;
81803 size_t size;
81804 -};
81805 +} __do_const;
81806
81807 /*
81808 * Use these carefully. If you implement a network device and it
81809 @@ -339,23 +343,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
81810
81811 static inline int rt_genid_ipv4(struct net *net)
81812 {
81813 - return atomic_read(&net->ipv4.rt_genid);
81814 + return atomic_read_unchecked(&net->ipv4.rt_genid);
81815 }
81816
81817 static inline void rt_genid_bump_ipv4(struct net *net)
81818 {
81819 - atomic_inc(&net->ipv4.rt_genid);
81820 + atomic_inc_unchecked(&net->ipv4.rt_genid);
81821 }
81822
81823 #if IS_ENABLED(CONFIG_IPV6)
81824 static inline int rt_genid_ipv6(struct net *net)
81825 {
81826 - return atomic_read(&net->ipv6.rt_genid);
81827 + return atomic_read_unchecked(&net->ipv6.rt_genid);
81828 }
81829
81830 static inline void rt_genid_bump_ipv6(struct net *net)
81831 {
81832 - atomic_inc(&net->ipv6.rt_genid);
81833 + atomic_inc_unchecked(&net->ipv6.rt_genid);
81834 }
81835 #else
81836 static inline int rt_genid_ipv6(struct net *net)
81837 @@ -377,12 +381,12 @@ static inline void rt_genid_bump_all(struct net *net)
81838
81839 static inline int fnhe_genid(struct net *net)
81840 {
81841 - return atomic_read(&net->fnhe_genid);
81842 + return atomic_read_unchecked(&net->fnhe_genid);
81843 }
81844
81845 static inline void fnhe_genid_bump(struct net *net)
81846 {
81847 - atomic_inc(&net->fnhe_genid);
81848 + atomic_inc_unchecked(&net->fnhe_genid);
81849 }
81850
81851 #endif /* __NET_NET_NAMESPACE_H */
81852 diff --git a/include/net/netdma.h b/include/net/netdma.h
81853 index 8ba8ce2..99b7fff 100644
81854 --- a/include/net/netdma.h
81855 +++ b/include/net/netdma.h
81856 @@ -24,7 +24,7 @@
81857 #include <linux/dmaengine.h>
81858 #include <linux/skbuff.h>
81859
81860 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
81861 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
81862 struct sk_buff *skb, int offset, struct iovec *to,
81863 size_t len, struct dma_pinned_list *pinned_list);
81864
81865 diff --git a/include/net/netlink.h b/include/net/netlink.h
81866 index 2b47eaa..6d5bcc2 100644
81867 --- a/include/net/netlink.h
81868 +++ b/include/net/netlink.h
81869 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
81870 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
81871 {
81872 if (mark)
81873 - skb_trim(skb, (unsigned char *) mark - skb->data);
81874 + skb_trim(skb, (const unsigned char *) mark - skb->data);
81875 }
81876
81877 /**
81878 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
81879 index c9c0c53..53f24c3 100644
81880 --- a/include/net/netns/conntrack.h
81881 +++ b/include/net/netns/conntrack.h
81882 @@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
81883 struct nf_proto_net {
81884 #ifdef CONFIG_SYSCTL
81885 struct ctl_table_header *ctl_table_header;
81886 - struct ctl_table *ctl_table;
81887 + ctl_table_no_const *ctl_table;
81888 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
81889 struct ctl_table_header *ctl_compat_header;
81890 - struct ctl_table *ctl_compat_table;
81891 + ctl_table_no_const *ctl_compat_table;
81892 #endif
81893 #endif
81894 unsigned int users;
81895 @@ -58,7 +58,7 @@ struct nf_ip_net {
81896 struct nf_icmp_net icmpv6;
81897 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
81898 struct ctl_table_header *ctl_table_header;
81899 - struct ctl_table *ctl_table;
81900 + ctl_table_no_const *ctl_table;
81901 #endif
81902 };
81903
81904 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
81905 index ee520cb..9a0fd88 100644
81906 --- a/include/net/netns/ipv4.h
81907 +++ b/include/net/netns/ipv4.h
81908 @@ -72,7 +72,7 @@ struct netns_ipv4 {
81909
81910 kgid_t sysctl_ping_group_range[2];
81911
81912 - atomic_t dev_addr_genid;
81913 + atomic_unchecked_t dev_addr_genid;
81914
81915 #ifdef CONFIG_IP_MROUTE
81916 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
81917 @@ -82,6 +82,6 @@ struct netns_ipv4 {
81918 struct fib_rules_ops *mr_rules_ops;
81919 #endif
81920 #endif
81921 - atomic_t rt_genid;
81922 + atomic_unchecked_t rt_genid;
81923 };
81924 #endif
81925 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
81926 index 0fb2401..477d81c 100644
81927 --- a/include/net/netns/ipv6.h
81928 +++ b/include/net/netns/ipv6.h
81929 @@ -71,8 +71,8 @@ struct netns_ipv6 {
81930 struct fib_rules_ops *mr6_rules_ops;
81931 #endif
81932 #endif
81933 - atomic_t dev_addr_genid;
81934 - atomic_t rt_genid;
81935 + atomic_unchecked_t dev_addr_genid;
81936 + atomic_unchecked_t rt_genid;
81937 };
81938
81939 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
81940 diff --git a/include/net/ping.h b/include/net/ping.h
81941 index 90f4841..74446a8 100644
81942 --- a/include/net/ping.h
81943 +++ b/include/net/ping.h
81944 @@ -56,7 +56,7 @@ struct ping_iter_state {
81945 extern struct proto ping_prot;
81946 extern struct ping_table ping_table;
81947 #if IS_ENABLED(CONFIG_IPV6)
81948 -extern struct pingv6_ops pingv6_ops;
81949 +extern struct pingv6_ops *pingv6_ops;
81950 #endif
81951
81952 struct pingfakehdr {
81953 diff --git a/include/net/protocol.h b/include/net/protocol.h
81954 index fbf7676..a5e21c3 100644
81955 --- a/include/net/protocol.h
81956 +++ b/include/net/protocol.h
81957 @@ -44,7 +44,7 @@ struct net_protocol {
81958 void (*err_handler)(struct sk_buff *skb, u32 info);
81959 unsigned int no_policy:1,
81960 netns_ok:1;
81961 -};
81962 +} __do_const;
81963
81964 #if IS_ENABLED(CONFIG_IPV6)
81965 struct inet6_protocol {
81966 @@ -57,7 +57,7 @@ struct inet6_protocol {
81967 u8 type, u8 code, int offset,
81968 __be32 info);
81969 unsigned int flags; /* INET6_PROTO_xxx */
81970 -};
81971 +} __do_const;
81972
81973 #define INET6_PROTO_NOPOLICY 0x1
81974 #define INET6_PROTO_FINAL 0x2
81975 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
81976 index bb13a18..e734116 100644
81977 --- a/include/net/rtnetlink.h
81978 +++ b/include/net/rtnetlink.h
81979 @@ -79,7 +79,7 @@ struct rtnl_link_ops {
81980 const struct net_device *dev);
81981 unsigned int (*get_num_tx_queues)(void);
81982 unsigned int (*get_num_rx_queues)(void);
81983 -};
81984 +} __do_const;
81985
81986 int __rtnl_link_register(struct rtnl_link_ops *ops);
81987 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
81988 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
81989 index 6bd44fe..96f364e 100644
81990 --- a/include/net/sctp/checksum.h
81991 +++ b/include/net/sctp/checksum.h
81992 @@ -62,8 +62,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
81993 unsigned int offset)
81994 {
81995 struct sctphdr *sh = sctp_hdr(skb);
81996 - __le32 ret, old = sh->checksum;
81997 - const struct skb_checksum_ops ops = {
81998 + __le32 ret, old = sh->checksum;
81999 + static const struct skb_checksum_ops ops = {
82000 .update = sctp_csum_update,
82001 .combine = sctp_csum_combine,
82002 };
82003 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
82004 index 4ef75af..5aa073a 100644
82005 --- a/include/net/sctp/sm.h
82006 +++ b/include/net/sctp/sm.h
82007 @@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
82008 typedef struct {
82009 sctp_state_fn_t *fn;
82010 const char *name;
82011 -} sctp_sm_table_entry_t;
82012 +} __do_const sctp_sm_table_entry_t;
82013
82014 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
82015 * currently in use.
82016 @@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
82017 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
82018
82019 /* Extern declarations for major data structures. */
82020 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
82021 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
82022
82023
82024 /* Get the size of a DATA chunk payload. */
82025 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
82026 index 0a248b3..4dcbe5c 100644
82027 --- a/include/net/sctp/structs.h
82028 +++ b/include/net/sctp/structs.h
82029 @@ -508,7 +508,7 @@ struct sctp_pf {
82030 struct sctp_association *asoc);
82031 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
82032 struct sctp_af *af;
82033 -};
82034 +} __do_const;
82035
82036
82037 /* Structure to track chunk fragments that have been acked, but peer
82038 diff --git a/include/net/sock.h b/include/net/sock.h
82039 index 2ef3c3e..e02013e 100644
82040 --- a/include/net/sock.h
82041 +++ b/include/net/sock.h
82042 @@ -348,7 +348,7 @@ struct sock {
82043 unsigned int sk_napi_id;
82044 unsigned int sk_ll_usec;
82045 #endif
82046 - atomic_t sk_drops;
82047 + atomic_unchecked_t sk_drops;
82048 int sk_rcvbuf;
82049
82050 struct sk_filter __rcu *sk_filter;
82051 @@ -1209,7 +1209,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
82052 return ret >> PAGE_SHIFT;
82053 }
82054
82055 -static inline long
82056 +static inline long __intentional_overflow(-1)
82057 sk_memory_allocated(const struct sock *sk)
82058 {
82059 struct proto *prot = sk->sk_prot;
82060 @@ -1813,7 +1813,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
82061 }
82062
82063 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
82064 - char __user *from, char *to,
82065 + char __user *from, unsigned char *to,
82066 int copy, int offset)
82067 {
82068 if (skb->ip_summed == CHECKSUM_NONE) {
82069 @@ -2075,7 +2075,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
82070 }
82071 }
82072
82073 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
82074 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
82075
82076 /**
82077 * sk_page_frag - return an appropriate page_frag
82078 diff --git a/include/net/tcp.h b/include/net/tcp.h
82079 index 70e55d2..c5d8d53 100644
82080 --- a/include/net/tcp.h
82081 +++ b/include/net/tcp.h
82082 @@ -540,7 +540,7 @@ void tcp_retransmit_timer(struct sock *sk);
82083 void tcp_xmit_retransmit_queue(struct sock *);
82084 void tcp_simple_retransmit(struct sock *);
82085 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
82086 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
82087 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
82088
82089 void tcp_send_probe0(struct sock *);
82090 void tcp_send_partial(struct sock *);
82091 @@ -711,8 +711,8 @@ struct tcp_skb_cb {
82092 struct inet6_skb_parm h6;
82093 #endif
82094 } header; /* For incoming frames */
82095 - __u32 seq; /* Starting sequence number */
82096 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
82097 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
82098 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
82099 __u32 when; /* used to compute rtt's */
82100 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
82101
82102 @@ -726,7 +726,7 @@ struct tcp_skb_cb {
82103
82104 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
82105 /* 1 byte hole */
82106 - __u32 ack_seq; /* Sequence number ACK'd */
82107 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
82108 };
82109
82110 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
82111 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
82112 index 6b82fdf..14d74d2 100644
82113 --- a/include/net/xfrm.h
82114 +++ b/include/net/xfrm.h
82115 @@ -287,7 +287,6 @@ struct xfrm_dst;
82116 struct xfrm_policy_afinfo {
82117 unsigned short family;
82118 struct dst_ops *dst_ops;
82119 - void (*garbage_collect)(struct net *net);
82120 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
82121 const xfrm_address_t *saddr,
82122 const xfrm_address_t *daddr);
82123 @@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
82124 struct net_device *dev,
82125 const struct flowi *fl);
82126 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
82127 -};
82128 +} __do_const;
82129
82130 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
82131 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
82132 @@ -344,7 +343,7 @@ struct xfrm_state_afinfo {
82133 int (*transport_finish)(struct sk_buff *skb,
82134 int async);
82135 void (*local_error)(struct sk_buff *skb, u32 mtu);
82136 -};
82137 +} __do_const;
82138
82139 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
82140 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
82141 @@ -429,7 +428,7 @@ struct xfrm_mode {
82142 struct module *owner;
82143 unsigned int encap;
82144 int flags;
82145 -};
82146 +} __do_const;
82147
82148 /* Flags for xfrm_mode. */
82149 enum {
82150 @@ -526,7 +525,7 @@ struct xfrm_policy {
82151 struct timer_list timer;
82152
82153 struct flow_cache_object flo;
82154 - atomic_t genid;
82155 + atomic_unchecked_t genid;
82156 u32 priority;
82157 u32 index;
82158 struct xfrm_mark mark;
82159 @@ -1166,6 +1165,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
82160 }
82161
82162 void xfrm_garbage_collect(struct net *net);
82163 +void xfrm_garbage_collect_deferred(struct net *net);
82164
82165 #else
82166
82167 @@ -1204,6 +1204,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
82168 static inline void xfrm_garbage_collect(struct net *net)
82169 {
82170 }
82171 +static inline void xfrm_garbage_collect_deferred(struct net *net)
82172 +{
82173 +}
82174 #endif
82175
82176 static __inline__
82177 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
82178 index 1017e0b..227aa4d 100644
82179 --- a/include/rdma/iw_cm.h
82180 +++ b/include/rdma/iw_cm.h
82181 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
82182 int backlog);
82183
82184 int (*destroy_listen)(struct iw_cm_id *cm_id);
82185 -};
82186 +} __no_const;
82187
82188 /**
82189 * iw_create_cm_id - Create an IW CM identifier.
82190 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
82191 index 52beadf..598734c 100644
82192 --- a/include/scsi/libfc.h
82193 +++ b/include/scsi/libfc.h
82194 @@ -771,6 +771,7 @@ struct libfc_function_template {
82195 */
82196 void (*disc_stop_final) (struct fc_lport *);
82197 };
82198 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
82199
82200 /**
82201 * struct fc_disc - Discovery context
82202 @@ -875,7 +876,7 @@ struct fc_lport {
82203 struct fc_vport *vport;
82204
82205 /* Operational Information */
82206 - struct libfc_function_template tt;
82207 + libfc_function_template_no_const tt;
82208 u8 link_up;
82209 u8 qfull;
82210 enum fc_lport_state state;
82211 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
82212 index d65fbec..f80fef2 100644
82213 --- a/include/scsi/scsi_device.h
82214 +++ b/include/scsi/scsi_device.h
82215 @@ -180,9 +180,9 @@ struct scsi_device {
82216 unsigned int max_device_blocked; /* what device_blocked counts down from */
82217 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
82218
82219 - atomic_t iorequest_cnt;
82220 - atomic_t iodone_cnt;
82221 - atomic_t ioerr_cnt;
82222 + atomic_unchecked_t iorequest_cnt;
82223 + atomic_unchecked_t iodone_cnt;
82224 + atomic_unchecked_t ioerr_cnt;
82225
82226 struct device sdev_gendev,
82227 sdev_dev;
82228 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
82229 index b797e8f..8e2c3aa 100644
82230 --- a/include/scsi/scsi_transport_fc.h
82231 +++ b/include/scsi/scsi_transport_fc.h
82232 @@ -751,7 +751,8 @@ struct fc_function_template {
82233 unsigned long show_host_system_hostname:1;
82234
82235 unsigned long disable_target_scan:1;
82236 -};
82237 +} __do_const;
82238 +typedef struct fc_function_template __no_const fc_function_template_no_const;
82239
82240
82241 /**
82242 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
82243 index ae6c3b8..fd748ac 100644
82244 --- a/include/sound/compress_driver.h
82245 +++ b/include/sound/compress_driver.h
82246 @@ -128,7 +128,7 @@ struct snd_compr_ops {
82247 struct snd_compr_caps *caps);
82248 int (*get_codec_caps) (struct snd_compr_stream *stream,
82249 struct snd_compr_codec_caps *codec);
82250 -};
82251 +} __no_const;
82252
82253 /**
82254 * struct snd_compr: Compressed device
82255 diff --git a/include/sound/soc.h b/include/sound/soc.h
82256 index 1f741cb..8cefc08 100644
82257 --- a/include/sound/soc.h
82258 +++ b/include/sound/soc.h
82259 @@ -763,7 +763,7 @@ struct snd_soc_codec_driver {
82260 /* probe ordering - for components with runtime dependencies */
82261 int probe_order;
82262 int remove_order;
82263 -};
82264 +} __do_const;
82265
82266 /* SoC platform interface */
82267 struct snd_soc_platform_driver {
82268 @@ -809,7 +809,7 @@ struct snd_soc_platform_driver {
82269 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
82270 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
82271 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
82272 -};
82273 +} __do_const;
82274
82275 struct snd_soc_platform {
82276 const char *name;
82277 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
82278 index 321301c..2ae5cb0 100644
82279 --- a/include/target/target_core_base.h
82280 +++ b/include/target/target_core_base.h
82281 @@ -687,7 +687,7 @@ struct se_device {
82282 atomic_long_t write_bytes;
82283 /* Active commands on this virtual SE device */
82284 atomic_t simple_cmds;
82285 - atomic_t dev_ordered_id;
82286 + atomic_unchecked_t dev_ordered_id;
82287 atomic_t dev_ordered_sync;
82288 atomic_t dev_qf_count;
82289 int export_count;
82290 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
82291 new file mode 100644
82292 index 0000000..fb634b7
82293 --- /dev/null
82294 +++ b/include/trace/events/fs.h
82295 @@ -0,0 +1,53 @@
82296 +#undef TRACE_SYSTEM
82297 +#define TRACE_SYSTEM fs
82298 +
82299 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
82300 +#define _TRACE_FS_H
82301 +
82302 +#include <linux/fs.h>
82303 +#include <linux/tracepoint.h>
82304 +
82305 +TRACE_EVENT(do_sys_open,
82306 +
82307 + TP_PROTO(const char *filename, int flags, int mode),
82308 +
82309 + TP_ARGS(filename, flags, mode),
82310 +
82311 + TP_STRUCT__entry(
82312 + __string( filename, filename )
82313 + __field( int, flags )
82314 + __field( int, mode )
82315 + ),
82316 +
82317 + TP_fast_assign(
82318 + __assign_str(filename, filename);
82319 + __entry->flags = flags;
82320 + __entry->mode = mode;
82321 + ),
82322 +
82323 + TP_printk("\"%s\" %x %o",
82324 + __get_str(filename), __entry->flags, __entry->mode)
82325 +);
82326 +
82327 +TRACE_EVENT(open_exec,
82328 +
82329 + TP_PROTO(const char *filename),
82330 +
82331 + TP_ARGS(filename),
82332 +
82333 + TP_STRUCT__entry(
82334 + __string( filename, filename )
82335 + ),
82336 +
82337 + TP_fast_assign(
82338 + __assign_str(filename, filename);
82339 + ),
82340 +
82341 + TP_printk("\"%s\"",
82342 + __get_str(filename))
82343 +);
82344 +
82345 +#endif /* _TRACE_FS_H */
82346 +
82347 +/* This part must be outside protection */
82348 +#include <trace/define_trace.h>
82349 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
82350 index 1c09820..7f5ec79 100644
82351 --- a/include/trace/events/irq.h
82352 +++ b/include/trace/events/irq.h
82353 @@ -36,7 +36,7 @@ struct softirq_action;
82354 */
82355 TRACE_EVENT(irq_handler_entry,
82356
82357 - TP_PROTO(int irq, struct irqaction *action),
82358 + TP_PROTO(int irq, const struct irqaction *action),
82359
82360 TP_ARGS(irq, action),
82361
82362 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
82363 */
82364 TRACE_EVENT(irq_handler_exit,
82365
82366 - TP_PROTO(int irq, struct irqaction *action, int ret),
82367 + TP_PROTO(int irq, const struct irqaction *action, int ret),
82368
82369 TP_ARGS(irq, action, ret),
82370
82371 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
82372 index 7caf44c..23c6f27 100644
82373 --- a/include/uapi/linux/a.out.h
82374 +++ b/include/uapi/linux/a.out.h
82375 @@ -39,6 +39,14 @@ enum machine_type {
82376 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
82377 };
82378
82379 +/* Constants for the N_FLAGS field */
82380 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
82381 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
82382 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
82383 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
82384 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
82385 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
82386 +
82387 #if !defined (N_MAGIC)
82388 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
82389 #endif
82390 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
82391 index d876736..ccce5c0 100644
82392 --- a/include/uapi/linux/byteorder/little_endian.h
82393 +++ b/include/uapi/linux/byteorder/little_endian.h
82394 @@ -42,51 +42,51 @@
82395
82396 static inline __le64 __cpu_to_le64p(const __u64 *p)
82397 {
82398 - return (__force __le64)*p;
82399 + return (__force const __le64)*p;
82400 }
82401 -static inline __u64 __le64_to_cpup(const __le64 *p)
82402 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
82403 {
82404 - return (__force __u64)*p;
82405 + return (__force const __u64)*p;
82406 }
82407 static inline __le32 __cpu_to_le32p(const __u32 *p)
82408 {
82409 - return (__force __le32)*p;
82410 + return (__force const __le32)*p;
82411 }
82412 static inline __u32 __le32_to_cpup(const __le32 *p)
82413 {
82414 - return (__force __u32)*p;
82415 + return (__force const __u32)*p;
82416 }
82417 static inline __le16 __cpu_to_le16p(const __u16 *p)
82418 {
82419 - return (__force __le16)*p;
82420 + return (__force const __le16)*p;
82421 }
82422 static inline __u16 __le16_to_cpup(const __le16 *p)
82423 {
82424 - return (__force __u16)*p;
82425 + return (__force const __u16)*p;
82426 }
82427 static inline __be64 __cpu_to_be64p(const __u64 *p)
82428 {
82429 - return (__force __be64)__swab64p(p);
82430 + return (__force const __be64)__swab64p(p);
82431 }
82432 static inline __u64 __be64_to_cpup(const __be64 *p)
82433 {
82434 - return __swab64p((__u64 *)p);
82435 + return __swab64p((const __u64 *)p);
82436 }
82437 static inline __be32 __cpu_to_be32p(const __u32 *p)
82438 {
82439 - return (__force __be32)__swab32p(p);
82440 + return (__force const __be32)__swab32p(p);
82441 }
82442 -static inline __u32 __be32_to_cpup(const __be32 *p)
82443 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
82444 {
82445 - return __swab32p((__u32 *)p);
82446 + return __swab32p((const __u32 *)p);
82447 }
82448 static inline __be16 __cpu_to_be16p(const __u16 *p)
82449 {
82450 - return (__force __be16)__swab16p(p);
82451 + return (__force const __be16)__swab16p(p);
82452 }
82453 static inline __u16 __be16_to_cpup(const __be16 *p)
82454 {
82455 - return __swab16p((__u16 *)p);
82456 + return __swab16p((const __u16 *)p);
82457 }
82458 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
82459 #define __le64_to_cpus(x) do { (void)(x); } while (0)
82460 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
82461 index ef6103b..d4e65dd 100644
82462 --- a/include/uapi/linux/elf.h
82463 +++ b/include/uapi/linux/elf.h
82464 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
82465 #define PT_GNU_EH_FRAME 0x6474e550
82466
82467 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
82468 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
82469 +
82470 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
82471 +
82472 +/* Constants for the e_flags field */
82473 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
82474 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
82475 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
82476 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
82477 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
82478 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
82479
82480 /*
82481 * Extended Numbering
82482 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
82483 #define DT_DEBUG 21
82484 #define DT_TEXTREL 22
82485 #define DT_JMPREL 23
82486 +#define DT_FLAGS 30
82487 + #define DF_TEXTREL 0x00000004
82488 #define DT_ENCODING 32
82489 #define OLD_DT_LOOS 0x60000000
82490 #define DT_LOOS 0x6000000d
82491 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
82492 #define PF_W 0x2
82493 #define PF_X 0x1
82494
82495 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
82496 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
82497 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
82498 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
82499 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
82500 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
82501 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
82502 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
82503 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
82504 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
82505 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
82506 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
82507 +
82508 typedef struct elf32_phdr{
82509 Elf32_Word p_type;
82510 Elf32_Off p_offset;
82511 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
82512 #define EI_OSABI 7
82513 #define EI_PAD 8
82514
82515 +#define EI_PAX 14
82516 +
82517 #define ELFMAG0 0x7f /* EI_MAG */
82518 #define ELFMAG1 'E'
82519 #define ELFMAG2 'L'
82520 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
82521 index aa169c4..6a2771d 100644
82522 --- a/include/uapi/linux/personality.h
82523 +++ b/include/uapi/linux/personality.h
82524 @@ -30,6 +30,7 @@ enum {
82525 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
82526 ADDR_NO_RANDOMIZE | \
82527 ADDR_COMPAT_LAYOUT | \
82528 + ADDR_LIMIT_3GB | \
82529 MMAP_PAGE_ZERO)
82530
82531 /*
82532 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
82533 index 7530e74..e714828 100644
82534 --- a/include/uapi/linux/screen_info.h
82535 +++ b/include/uapi/linux/screen_info.h
82536 @@ -43,7 +43,8 @@ struct screen_info {
82537 __u16 pages; /* 0x32 */
82538 __u16 vesa_attributes; /* 0x34 */
82539 __u32 capabilities; /* 0x36 */
82540 - __u8 _reserved[6]; /* 0x3a */
82541 + __u16 vesapm_size; /* 0x3a */
82542 + __u8 _reserved[4]; /* 0x3c */
82543 } __attribute__((packed));
82544
82545 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
82546 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
82547 index 0e011eb..82681b1 100644
82548 --- a/include/uapi/linux/swab.h
82549 +++ b/include/uapi/linux/swab.h
82550 @@ -43,7 +43,7 @@
82551 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
82552 */
82553
82554 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
82555 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
82556 {
82557 #ifdef __HAVE_BUILTIN_BSWAP16__
82558 return __builtin_bswap16(val);
82559 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
82560 #endif
82561 }
82562
82563 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
82564 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
82565 {
82566 #ifdef __HAVE_BUILTIN_BSWAP32__
82567 return __builtin_bswap32(val);
82568 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
82569 #endif
82570 }
82571
82572 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
82573 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
82574 {
82575 #ifdef __HAVE_BUILTIN_BSWAP64__
82576 return __builtin_bswap64(val);
82577 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
82578 index 6d67213..552fdd9 100644
82579 --- a/include/uapi/linux/sysctl.h
82580 +++ b/include/uapi/linux/sysctl.h
82581 @@ -155,8 +155,6 @@ enum
82582 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
82583 };
82584
82585 -
82586 -
82587 /* CTL_VM names: */
82588 enum
82589 {
82590 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
82591 index 437f1b0..0eeb38d 100644
82592 --- a/include/uapi/linux/videodev2.h
82593 +++ b/include/uapi/linux/videodev2.h
82594 @@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
82595 union {
82596 __s32 value;
82597 __s64 value64;
82598 - char *string;
82599 + char __user *string;
82600 };
82601 } __attribute__ ((packed));
82602
82603 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
82604 index e4629b9..6958086 100644
82605 --- a/include/uapi/linux/xattr.h
82606 +++ b/include/uapi/linux/xattr.h
82607 @@ -63,5 +63,9 @@
82608 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
82609 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
82610
82611 +/* User namespace */
82612 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
82613 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
82614 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
82615
82616 #endif /* _UAPI_LINUX_XATTR_H */
82617 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
82618 index f9466fa..f4e2b81 100644
82619 --- a/include/video/udlfb.h
82620 +++ b/include/video/udlfb.h
82621 @@ -53,10 +53,10 @@ struct dlfb_data {
82622 u32 pseudo_palette[256];
82623 int blank_mode; /*one of FB_BLANK_ */
82624 /* blit-only rendering path metrics, exposed through sysfs */
82625 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
82626 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
82627 - atomic_t bytes_sent; /* to usb, after compression including overhead */
82628 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
82629 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
82630 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
82631 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
82632 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
82633 };
82634
82635 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
82636 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
82637 index 30f5362..8ed8ac9 100644
82638 --- a/include/video/uvesafb.h
82639 +++ b/include/video/uvesafb.h
82640 @@ -122,6 +122,7 @@ struct uvesafb_par {
82641 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
82642 u8 pmi_setpal; /* PMI for palette changes */
82643 u16 *pmi_base; /* protected mode interface location */
82644 + u8 *pmi_code; /* protected mode code location */
82645 void *pmi_start;
82646 void *pmi_pal;
82647 u8 *vbe_state_orig; /*
82648 diff --git a/init/Kconfig b/init/Kconfig
82649 index 4e5d96a..93cd8a1 100644
82650 --- a/init/Kconfig
82651 +++ b/init/Kconfig
82652 @@ -1079,6 +1079,7 @@ endif # CGROUPS
82653
82654 config CHECKPOINT_RESTORE
82655 bool "Checkpoint/restore support" if EXPERT
82656 + depends on !GRKERNSEC
82657 default n
82658 help
82659 Enables additional kernel features in a sake of checkpoint/restore.
82660 @@ -1550,7 +1551,7 @@ config SLUB_DEBUG
82661
82662 config COMPAT_BRK
82663 bool "Disable heap randomization"
82664 - default y
82665 + default n
82666 help
82667 Randomizing heap placement makes heap exploits harder, but it
82668 also breaks ancient binaries (including anything libc5 based).
82669 @@ -1838,7 +1839,7 @@ config INIT_ALL_POSSIBLE
82670 config STOP_MACHINE
82671 bool
82672 default y
82673 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
82674 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
82675 help
82676 Need stop_machine() primitive.
82677
82678 diff --git a/init/Makefile b/init/Makefile
82679 index 7bc47ee..6da2dc7 100644
82680 --- a/init/Makefile
82681 +++ b/init/Makefile
82682 @@ -2,6 +2,9 @@
82683 # Makefile for the linux kernel.
82684 #
82685
82686 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
82687 +asflags-y := $(GCC_PLUGINS_AFLAGS)
82688 +
82689 obj-y := main.o version.o mounts.o
82690 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
82691 obj-y += noinitramfs.o
82692 diff --git a/init/do_mounts.c b/init/do_mounts.c
82693 index 8e5addc..c96ea61 100644
82694 --- a/init/do_mounts.c
82695 +++ b/init/do_mounts.c
82696 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
82697 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
82698 {
82699 struct super_block *s;
82700 - int err = sys_mount(name, "/root", fs, flags, data);
82701 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
82702 if (err)
82703 return err;
82704
82705 - sys_chdir("/root");
82706 + sys_chdir((const char __force_user *)"/root");
82707 s = current->fs->pwd.dentry->d_sb;
82708 ROOT_DEV = s->s_dev;
82709 printk(KERN_INFO
82710 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
82711 va_start(args, fmt);
82712 vsprintf(buf, fmt, args);
82713 va_end(args);
82714 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
82715 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
82716 if (fd >= 0) {
82717 sys_ioctl(fd, FDEJECT, 0);
82718 sys_close(fd);
82719 }
82720 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
82721 - fd = sys_open("/dev/console", O_RDWR, 0);
82722 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
82723 if (fd >= 0) {
82724 sys_ioctl(fd, TCGETS, (long)&termios);
82725 termios.c_lflag &= ~ICANON;
82726 sys_ioctl(fd, TCSETSF, (long)&termios);
82727 - sys_read(fd, &c, 1);
82728 + sys_read(fd, (char __user *)&c, 1);
82729 termios.c_lflag |= ICANON;
82730 sys_ioctl(fd, TCSETSF, (long)&termios);
82731 sys_close(fd);
82732 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
82733 mount_root();
82734 out:
82735 devtmpfs_mount("dev");
82736 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
82737 - sys_chroot(".");
82738 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
82739 + sys_chroot((const char __force_user *)".");
82740 }
82741
82742 static bool is_tmpfs;
82743 diff --git a/init/do_mounts.h b/init/do_mounts.h
82744 index f5b978a..69dbfe8 100644
82745 --- a/init/do_mounts.h
82746 +++ b/init/do_mounts.h
82747 @@ -15,15 +15,15 @@ extern int root_mountflags;
82748
82749 static inline int create_dev(char *name, dev_t dev)
82750 {
82751 - sys_unlink(name);
82752 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
82753 + sys_unlink((char __force_user *)name);
82754 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
82755 }
82756
82757 #if BITS_PER_LONG == 32
82758 static inline u32 bstat(char *name)
82759 {
82760 struct stat64 stat;
82761 - if (sys_stat64(name, &stat) != 0)
82762 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
82763 return 0;
82764 if (!S_ISBLK(stat.st_mode))
82765 return 0;
82766 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
82767 static inline u32 bstat(char *name)
82768 {
82769 struct stat stat;
82770 - if (sys_newstat(name, &stat) != 0)
82771 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
82772 return 0;
82773 if (!S_ISBLK(stat.st_mode))
82774 return 0;
82775 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
82776 index 3e0878e..8a9d7a0 100644
82777 --- a/init/do_mounts_initrd.c
82778 +++ b/init/do_mounts_initrd.c
82779 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
82780 {
82781 sys_unshare(CLONE_FS | CLONE_FILES);
82782 /* stdin/stdout/stderr for /linuxrc */
82783 - sys_open("/dev/console", O_RDWR, 0);
82784 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
82785 sys_dup(0);
82786 sys_dup(0);
82787 /* move initrd over / and chdir/chroot in initrd root */
82788 - sys_chdir("/root");
82789 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
82790 - sys_chroot(".");
82791 + sys_chdir((const char __force_user *)"/root");
82792 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
82793 + sys_chroot((const char __force_user *)".");
82794 sys_setsid();
82795 return 0;
82796 }
82797 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
82798 create_dev("/dev/root.old", Root_RAM0);
82799 /* mount initrd on rootfs' /root */
82800 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
82801 - sys_mkdir("/old", 0700);
82802 - sys_chdir("/old");
82803 + sys_mkdir((const char __force_user *)"/old", 0700);
82804 + sys_chdir((const char __force_user *)"/old");
82805
82806 /* try loading default modules from initrd */
82807 load_default_modules();
82808 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
82809 current->flags &= ~PF_FREEZER_SKIP;
82810
82811 /* move initrd to rootfs' /old */
82812 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
82813 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
82814 /* switch root and cwd back to / of rootfs */
82815 - sys_chroot("..");
82816 + sys_chroot((const char __force_user *)"..");
82817
82818 if (new_decode_dev(real_root_dev) == Root_RAM0) {
82819 - sys_chdir("/old");
82820 + sys_chdir((const char __force_user *)"/old");
82821 return;
82822 }
82823
82824 - sys_chdir("/");
82825 + sys_chdir((const char __force_user *)"/");
82826 ROOT_DEV = new_decode_dev(real_root_dev);
82827 mount_root();
82828
82829 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
82830 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
82831 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
82832 if (!error)
82833 printk("okay\n");
82834 else {
82835 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
82836 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
82837 if (error == -ENOENT)
82838 printk("/initrd does not exist. Ignored.\n");
82839 else
82840 printk("failed\n");
82841 printk(KERN_NOTICE "Unmounting old root\n");
82842 - sys_umount("/old", MNT_DETACH);
82843 + sys_umount((char __force_user *)"/old", MNT_DETACH);
82844 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
82845 if (fd < 0) {
82846 error = fd;
82847 @@ -127,11 +127,11 @@ int __init initrd_load(void)
82848 * mounted in the normal path.
82849 */
82850 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
82851 - sys_unlink("/initrd.image");
82852 + sys_unlink((const char __force_user *)"/initrd.image");
82853 handle_initrd();
82854 return 1;
82855 }
82856 }
82857 - sys_unlink("/initrd.image");
82858 + sys_unlink((const char __force_user *)"/initrd.image");
82859 return 0;
82860 }
82861 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
82862 index 8cb6db5..d729f50 100644
82863 --- a/init/do_mounts_md.c
82864 +++ b/init/do_mounts_md.c
82865 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
82866 partitioned ? "_d" : "", minor,
82867 md_setup_args[ent].device_names);
82868
82869 - fd = sys_open(name, 0, 0);
82870 + fd = sys_open((char __force_user *)name, 0, 0);
82871 if (fd < 0) {
82872 printk(KERN_ERR "md: open failed - cannot start "
82873 "array %s\n", name);
82874 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
82875 * array without it
82876 */
82877 sys_close(fd);
82878 - fd = sys_open(name, 0, 0);
82879 + fd = sys_open((char __force_user *)name, 0, 0);
82880 sys_ioctl(fd, BLKRRPART, 0);
82881 }
82882 sys_close(fd);
82883 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
82884
82885 wait_for_device_probe();
82886
82887 - fd = sys_open("/dev/md0", 0, 0);
82888 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
82889 if (fd >= 0) {
82890 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
82891 sys_close(fd);
82892 diff --git a/init/init_task.c b/init/init_task.c
82893 index ba0a7f36..2bcf1d5 100644
82894 --- a/init/init_task.c
82895 +++ b/init/init_task.c
82896 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
82897 * Initial thread structure. Alignment of this is handled by a special
82898 * linker map entry.
82899 */
82900 +#ifdef CONFIG_X86
82901 +union thread_union init_thread_union __init_task_data;
82902 +#else
82903 union thread_union init_thread_union __init_task_data =
82904 { INIT_THREAD_INFO(init_task) };
82905 +#endif
82906 diff --git a/init/initramfs.c b/init/initramfs.c
82907 index a67ef9d..2d17ed9 100644
82908 --- a/init/initramfs.c
82909 +++ b/init/initramfs.c
82910 @@ -84,7 +84,7 @@ static void __init free_hash(void)
82911 }
82912 }
82913
82914 -static long __init do_utime(char *filename, time_t mtime)
82915 +static long __init do_utime(char __force_user *filename, time_t mtime)
82916 {
82917 struct timespec t[2];
82918
82919 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
82920 struct dir_entry *de, *tmp;
82921 list_for_each_entry_safe(de, tmp, &dir_list, list) {
82922 list_del(&de->list);
82923 - do_utime(de->name, de->mtime);
82924 + do_utime((char __force_user *)de->name, de->mtime);
82925 kfree(de->name);
82926 kfree(de);
82927 }
82928 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
82929 if (nlink >= 2) {
82930 char *old = find_link(major, minor, ino, mode, collected);
82931 if (old)
82932 - return (sys_link(old, collected) < 0) ? -1 : 1;
82933 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
82934 }
82935 return 0;
82936 }
82937 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
82938 {
82939 struct stat st;
82940
82941 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
82942 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
82943 if (S_ISDIR(st.st_mode))
82944 - sys_rmdir(path);
82945 + sys_rmdir((char __force_user *)path);
82946 else
82947 - sys_unlink(path);
82948 + sys_unlink((char __force_user *)path);
82949 }
82950 }
82951
82952 @@ -315,7 +315,7 @@ static int __init do_name(void)
82953 int openflags = O_WRONLY|O_CREAT;
82954 if (ml != 1)
82955 openflags |= O_TRUNC;
82956 - wfd = sys_open(collected, openflags, mode);
82957 + wfd = sys_open((char __force_user *)collected, openflags, mode);
82958
82959 if (wfd >= 0) {
82960 sys_fchown(wfd, uid, gid);
82961 @@ -327,17 +327,17 @@ static int __init do_name(void)
82962 }
82963 }
82964 } else if (S_ISDIR(mode)) {
82965 - sys_mkdir(collected, mode);
82966 - sys_chown(collected, uid, gid);
82967 - sys_chmod(collected, mode);
82968 + sys_mkdir((char __force_user *)collected, mode);
82969 + sys_chown((char __force_user *)collected, uid, gid);
82970 + sys_chmod((char __force_user *)collected, mode);
82971 dir_add(collected, mtime);
82972 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
82973 S_ISFIFO(mode) || S_ISSOCK(mode)) {
82974 if (maybe_link() == 0) {
82975 - sys_mknod(collected, mode, rdev);
82976 - sys_chown(collected, uid, gid);
82977 - sys_chmod(collected, mode);
82978 - do_utime(collected, mtime);
82979 + sys_mknod((char __force_user *)collected, mode, rdev);
82980 + sys_chown((char __force_user *)collected, uid, gid);
82981 + sys_chmod((char __force_user *)collected, mode);
82982 + do_utime((char __force_user *)collected, mtime);
82983 }
82984 }
82985 return 0;
82986 @@ -346,15 +346,15 @@ static int __init do_name(void)
82987 static int __init do_copy(void)
82988 {
82989 if (count >= body_len) {
82990 - sys_write(wfd, victim, body_len);
82991 + sys_write(wfd, (char __force_user *)victim, body_len);
82992 sys_close(wfd);
82993 - do_utime(vcollected, mtime);
82994 + do_utime((char __force_user *)vcollected, mtime);
82995 kfree(vcollected);
82996 eat(body_len);
82997 state = SkipIt;
82998 return 0;
82999 } else {
83000 - sys_write(wfd, victim, count);
83001 + sys_write(wfd, (char __force_user *)victim, count);
83002 body_len -= count;
83003 eat(count);
83004 return 1;
83005 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
83006 {
83007 collected[N_ALIGN(name_len) + body_len] = '\0';
83008 clean_path(collected, 0);
83009 - sys_symlink(collected + N_ALIGN(name_len), collected);
83010 - sys_lchown(collected, uid, gid);
83011 - do_utime(collected, mtime);
83012 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
83013 + sys_lchown((char __force_user *)collected, uid, gid);
83014 + do_utime((char __force_user *)collected, mtime);
83015 state = SkipIt;
83016 next_state = Reset;
83017 return 0;
83018 @@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
83019 {
83020 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
83021 if (err)
83022 - panic(err); /* Failed to decompress INTERNAL initramfs */
83023 + panic("%s", err); /* Failed to decompress INTERNAL initramfs */
83024 if (initrd_start) {
83025 #ifdef CONFIG_BLK_DEV_RAM
83026 int fd;
83027 diff --git a/init/main.c b/init/main.c
83028 index febc511..f0851763 100644
83029 --- a/init/main.c
83030 +++ b/init/main.c
83031 @@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
83032 extern void tc_init(void);
83033 #endif
83034
83035 +extern void grsecurity_init(void);
83036 +
83037 /*
83038 * Debug helper: via this flag we know that we are in 'early bootup code'
83039 * where only the boot processor is running with IRQ disabled. This means
83040 @@ -164,6 +166,75 @@ static int __init set_reset_devices(char *str)
83041
83042 __setup("reset_devices", set_reset_devices);
83043
83044 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
83045 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
83046 +static int __init setup_grsec_proc_gid(char *str)
83047 +{
83048 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
83049 + return 1;
83050 +}
83051 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
83052 +#endif
83053 +
83054 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
83055 +unsigned long pax_user_shadow_base __read_only;
83056 +EXPORT_SYMBOL(pax_user_shadow_base);
83057 +extern char pax_enter_kernel_user[];
83058 +extern char pax_exit_kernel_user[];
83059 +#endif
83060 +
83061 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
83062 +static int __init setup_pax_nouderef(char *str)
83063 +{
83064 +#ifdef CONFIG_X86_32
83065 + unsigned int cpu;
83066 + struct desc_struct *gdt;
83067 +
83068 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
83069 + gdt = get_cpu_gdt_table(cpu);
83070 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
83071 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
83072 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
83073 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
83074 + }
83075 + loadsegment(ds, __KERNEL_DS);
83076 + loadsegment(es, __KERNEL_DS);
83077 + loadsegment(ss, __KERNEL_DS);
83078 +#else
83079 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
83080 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
83081 + clone_pgd_mask = ~(pgdval_t)0UL;
83082 + pax_user_shadow_base = 0UL;
83083 + setup_clear_cpu_cap(X86_FEATURE_PCID);
83084 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
83085 +#endif
83086 +
83087 + return 0;
83088 +}
83089 +early_param("pax_nouderef", setup_pax_nouderef);
83090 +
83091 +#ifdef CONFIG_X86_64
83092 +static int __init setup_pax_weakuderef(char *str)
83093 +{
83094 + if (clone_pgd_mask != ~(pgdval_t)0UL)
83095 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
83096 + return 1;
83097 +}
83098 +__setup("pax_weakuderef", setup_pax_weakuderef);
83099 +#endif
83100 +#endif
83101 +
83102 +#ifdef CONFIG_PAX_SOFTMODE
83103 +int pax_softmode;
83104 +
83105 +static int __init setup_pax_softmode(char *str)
83106 +{
83107 + get_option(&str, &pax_softmode);
83108 + return 1;
83109 +}
83110 +__setup("pax_softmode=", setup_pax_softmode);
83111 +#endif
83112 +
83113 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
83114 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
83115 static const char *panic_later, *panic_param;
83116 @@ -691,25 +762,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
83117 {
83118 int count = preempt_count();
83119 int ret;
83120 - char msgbuf[64];
83121 + const char *msg1 = "", *msg2 = "";
83122
83123 if (initcall_debug)
83124 ret = do_one_initcall_debug(fn);
83125 else
83126 ret = fn();
83127
83128 - msgbuf[0] = 0;
83129 -
83130 if (preempt_count() != count) {
83131 - sprintf(msgbuf, "preemption imbalance ");
83132 + msg1 = " preemption imbalance";
83133 preempt_count_set(count);
83134 }
83135 if (irqs_disabled()) {
83136 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
83137 + msg2 = " disabled interrupts";
83138 local_irq_enable();
83139 }
83140 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
83141 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
83142
83143 + add_latent_entropy();
83144 return ret;
83145 }
83146
83147 @@ -816,8 +886,8 @@ static int run_init_process(const char *init_filename)
83148 {
83149 argv_init[0] = init_filename;
83150 return do_execve(init_filename,
83151 - (const char __user *const __user *)argv_init,
83152 - (const char __user *const __user *)envp_init);
83153 + (const char __user *const __force_user *)argv_init,
83154 + (const char __user *const __force_user *)envp_init);
83155 }
83156
83157 static int try_to_run_init_process(const char *init_filename)
83158 @@ -834,6 +904,10 @@ static int try_to_run_init_process(const char *init_filename)
83159 return ret;
83160 }
83161
83162 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
83163 +extern int gr_init_ran;
83164 +#endif
83165 +
83166 static noinline void __init kernel_init_freeable(void);
83167
83168 static int __ref kernel_init(void *unused)
83169 @@ -858,6 +932,11 @@ static int __ref kernel_init(void *unused)
83170 ramdisk_execute_command, ret);
83171 }
83172
83173 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
83174 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
83175 + gr_init_ran = 1;
83176 +#endif
83177 +
83178 /*
83179 * We try each of these until one succeeds.
83180 *
83181 @@ -913,7 +992,7 @@ static noinline void __init kernel_init_freeable(void)
83182 do_basic_setup();
83183
83184 /* Open the /dev/console on the rootfs, this should never fail */
83185 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
83186 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
83187 pr_err("Warning: unable to open an initial console.\n");
83188
83189 (void) sys_dup(0);
83190 @@ -926,11 +1005,13 @@ static noinline void __init kernel_init_freeable(void)
83191 if (!ramdisk_execute_command)
83192 ramdisk_execute_command = "/init";
83193
83194 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
83195 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
83196 ramdisk_execute_command = NULL;
83197 prepare_namespace();
83198 }
83199
83200 + grsecurity_init();
83201 +
83202 /*
83203 * Ok, we have completed the initial bootup, and
83204 * we're essentially up and running. Get rid of the
83205 diff --git a/ipc/compat.c b/ipc/compat.c
83206 index 892f658..e7c6320 100644
83207 --- a/ipc/compat.c
83208 +++ b/ipc/compat.c
83209 @@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
83210 COMPAT_SHMLBA);
83211 if (err < 0)
83212 return err;
83213 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
83214 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
83215 }
83216 case SHMDT:
83217 return sys_shmdt(compat_ptr(ptr));
83218 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
83219 index b0e99de..09f385c 100644
83220 --- a/ipc/ipc_sysctl.c
83221 +++ b/ipc/ipc_sysctl.c
83222 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
83223 static int proc_ipc_dointvec(ctl_table *table, int write,
83224 void __user *buffer, size_t *lenp, loff_t *ppos)
83225 {
83226 - struct ctl_table ipc_table;
83227 + ctl_table_no_const ipc_table;
83228
83229 memcpy(&ipc_table, table, sizeof(ipc_table));
83230 ipc_table.data = get_ipc(table);
83231 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
83232 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
83233 void __user *buffer, size_t *lenp, loff_t *ppos)
83234 {
83235 - struct ctl_table ipc_table;
83236 + ctl_table_no_const ipc_table;
83237
83238 memcpy(&ipc_table, table, sizeof(ipc_table));
83239 ipc_table.data = get_ipc(table);
83240 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
83241 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
83242 void __user *buffer, size_t *lenp, loff_t *ppos)
83243 {
83244 - struct ctl_table ipc_table;
83245 + ctl_table_no_const ipc_table;
83246 size_t lenp_bef = *lenp;
83247 int rc;
83248
83249 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
83250 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
83251 void __user *buffer, size_t *lenp, loff_t *ppos)
83252 {
83253 - struct ctl_table ipc_table;
83254 + ctl_table_no_const ipc_table;
83255 memcpy(&ipc_table, table, sizeof(ipc_table));
83256 ipc_table.data = get_ipc(table);
83257
83258 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
83259 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
83260 void __user *buffer, size_t *lenp, loff_t *ppos)
83261 {
83262 - struct ctl_table ipc_table;
83263 + ctl_table_no_const ipc_table;
83264 size_t lenp_bef = *lenp;
83265 int oldval;
83266 int rc;
83267 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
83268 index 383d638..943fdbb 100644
83269 --- a/ipc/mq_sysctl.c
83270 +++ b/ipc/mq_sysctl.c
83271 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
83272 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
83273 void __user *buffer, size_t *lenp, loff_t *ppos)
83274 {
83275 - struct ctl_table mq_table;
83276 + ctl_table_no_const mq_table;
83277 memcpy(&mq_table, table, sizeof(mq_table));
83278 mq_table.data = get_mq(table);
83279
83280 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
83281 index 95827ce..09e6d38 100644
83282 --- a/ipc/mqueue.c
83283 +++ b/ipc/mqueue.c
83284 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
83285 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
83286 info->attr.mq_msgsize);
83287
83288 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
83289 spin_lock(&mq_lock);
83290 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
83291 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
83292 diff --git a/ipc/msg.c b/ipc/msg.c
83293 index 558aa91..359e718 100644
83294 --- a/ipc/msg.c
83295 +++ b/ipc/msg.c
83296 @@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
83297 return security_msg_queue_associate(msq, msgflg);
83298 }
83299
83300 +static struct ipc_ops msg_ops = {
83301 + .getnew = newque,
83302 + .associate = msg_security,
83303 + .more_checks = NULL
83304 +};
83305 +
83306 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
83307 {
83308 struct ipc_namespace *ns;
83309 - struct ipc_ops msg_ops;
83310 struct ipc_params msg_params;
83311
83312 ns = current->nsproxy->ipc_ns;
83313
83314 - msg_ops.getnew = newque;
83315 - msg_ops.associate = msg_security;
83316 - msg_ops.more_checks = NULL;
83317 -
83318 msg_params.key = key;
83319 msg_params.flg = msgflg;
83320
83321 diff --git a/ipc/sem.c b/ipc/sem.c
83322 index db9d241..bc8427c 100644
83323 --- a/ipc/sem.c
83324 +++ b/ipc/sem.c
83325 @@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
83326 return 0;
83327 }
83328
83329 +static struct ipc_ops sem_ops = {
83330 + .getnew = newary,
83331 + .associate = sem_security,
83332 + .more_checks = sem_more_checks
83333 +};
83334 +
83335 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
83336 {
83337 struct ipc_namespace *ns;
83338 - struct ipc_ops sem_ops;
83339 struct ipc_params sem_params;
83340
83341 ns = current->nsproxy->ipc_ns;
83342 @@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
83343 if (nsems < 0 || nsems > ns->sc_semmsl)
83344 return -EINVAL;
83345
83346 - sem_ops.getnew = newary;
83347 - sem_ops.associate = sem_security;
83348 - sem_ops.more_checks = sem_more_checks;
83349 -
83350 sem_params.key = key;
83351 sem_params.flg = semflg;
83352 sem_params.u.nsems = nsems;
83353 diff --git a/ipc/shm.c b/ipc/shm.c
83354 index 7a51443..3a257d8 100644
83355 --- a/ipc/shm.c
83356 +++ b/ipc/shm.c
83357 @@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
83358 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
83359 #endif
83360
83361 +#ifdef CONFIG_GRKERNSEC
83362 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
83363 + const time_t shm_createtime, const kuid_t cuid,
83364 + const int shmid);
83365 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
83366 + const time_t shm_createtime);
83367 +#endif
83368 +
83369 void shm_init_ns(struct ipc_namespace *ns)
83370 {
83371 ns->shm_ctlmax = SHMMAX;
83372 @@ -554,6 +562,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
83373 shp->shm_lprid = 0;
83374 shp->shm_atim = shp->shm_dtim = 0;
83375 shp->shm_ctim = get_seconds();
83376 +#ifdef CONFIG_GRKERNSEC
83377 + {
83378 + struct timespec timeval;
83379 + do_posix_clock_monotonic_gettime(&timeval);
83380 +
83381 + shp->shm_createtime = timeval.tv_sec;
83382 + }
83383 +#endif
83384 shp->shm_segsz = size;
83385 shp->shm_nattch = 0;
83386 shp->shm_file = file;
83387 @@ -607,18 +623,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
83388 return 0;
83389 }
83390
83391 +static struct ipc_ops shm_ops = {
83392 + .getnew = newseg,
83393 + .associate = shm_security,
83394 + .more_checks = shm_more_checks
83395 +};
83396 +
83397 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
83398 {
83399 struct ipc_namespace *ns;
83400 - struct ipc_ops shm_ops;
83401 struct ipc_params shm_params;
83402
83403 ns = current->nsproxy->ipc_ns;
83404
83405 - shm_ops.getnew = newseg;
83406 - shm_ops.associate = shm_security;
83407 - shm_ops.more_checks = shm_more_checks;
83408 -
83409 shm_params.key = key;
83410 shm_params.flg = shmflg;
83411 shm_params.u.size = size;
83412 @@ -1089,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83413 f_mode = FMODE_READ | FMODE_WRITE;
83414 }
83415 if (shmflg & SHM_EXEC) {
83416 +
83417 +#ifdef CONFIG_PAX_MPROTECT
83418 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
83419 + goto out;
83420 +#endif
83421 +
83422 prot |= PROT_EXEC;
83423 acc_mode |= S_IXUGO;
83424 }
83425 @@ -1113,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83426 if (err)
83427 goto out_unlock;
83428
83429 +#ifdef CONFIG_GRKERNSEC
83430 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
83431 + shp->shm_perm.cuid, shmid) ||
83432 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
83433 + err = -EACCES;
83434 + goto out_unlock;
83435 + }
83436 +#endif
83437 +
83438 ipc_lock_object(&shp->shm_perm);
83439
83440 /* check if shm_destroy() is tearing down shp */
83441 @@ -1125,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83442 path = shp->shm_file->f_path;
83443 path_get(&path);
83444 shp->shm_nattch++;
83445 +#ifdef CONFIG_GRKERNSEC
83446 + shp->shm_lapid = current->pid;
83447 +#endif
83448 size = i_size_read(path.dentry->d_inode);
83449 ipc_unlock_object(&shp->shm_perm);
83450 rcu_read_unlock();
83451 diff --git a/ipc/util.c b/ipc/util.c
83452 index 3ae17a4..d67c32f 100644
83453 --- a/ipc/util.c
83454 +++ b/ipc/util.c
83455 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
83456 int (*show)(struct seq_file *, void *);
83457 };
83458
83459 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
83460 +
83461 static void ipc_memory_notifier(struct work_struct *work)
83462 {
83463 ipcns_notify(IPCNS_MEMCHANGED);
83464 @@ -558,6 +560,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
83465 granted_mode >>= 6;
83466 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
83467 granted_mode >>= 3;
83468 +
83469 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
83470 + return -1;
83471 +
83472 /* is there some bit set in requested_mode but not in granted_mode? */
83473 if ((requested_mode & ~granted_mode & 0007) &&
83474 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
83475 diff --git a/kernel/acct.c b/kernel/acct.c
83476 index 8d6e145..33e0b1e 100644
83477 --- a/kernel/acct.c
83478 +++ b/kernel/acct.c
83479 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
83480 */
83481 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
83482 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
83483 - file->f_op->write(file, (char *)&ac,
83484 + file->f_op->write(file, (char __force_user *)&ac,
83485 sizeof(acct_t), &file->f_pos);
83486 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
83487 set_fs(fs);
83488 diff --git a/kernel/audit.c b/kernel/audit.c
83489 index 906ae5a0..a7ad0b4 100644
83490 --- a/kernel/audit.c
83491 +++ b/kernel/audit.c
83492 @@ -117,7 +117,7 @@ u32 audit_sig_sid = 0;
83493 3) suppressed due to audit_rate_limit
83494 4) suppressed due to audit_backlog_limit
83495 */
83496 -static atomic_t audit_lost = ATOMIC_INIT(0);
83497 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
83498
83499 /* The netlink socket. */
83500 static struct sock *audit_sock;
83501 @@ -250,7 +250,7 @@ void audit_log_lost(const char *message)
83502 unsigned long now;
83503 int print;
83504
83505 - atomic_inc(&audit_lost);
83506 + atomic_inc_unchecked(&audit_lost);
83507
83508 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
83509
83510 @@ -269,7 +269,7 @@ void audit_log_lost(const char *message)
83511 printk(KERN_WARNING
83512 "audit: audit_lost=%d audit_rate_limit=%d "
83513 "audit_backlog_limit=%d\n",
83514 - atomic_read(&audit_lost),
83515 + atomic_read_unchecked(&audit_lost),
83516 audit_rate_limit,
83517 audit_backlog_limit);
83518 audit_panic(message);
83519 @@ -765,7 +765,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
83520 status_set.pid = audit_pid;
83521 status_set.rate_limit = audit_rate_limit;
83522 status_set.backlog_limit = audit_backlog_limit;
83523 - status_set.lost = atomic_read(&audit_lost);
83524 + status_set.lost = atomic_read_unchecked(&audit_lost);
83525 status_set.backlog = skb_queue_len(&audit_skb_queue);
83526 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
83527 &status_set, sizeof(status_set));
83528 @@ -1356,7 +1356,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
83529 int i, avail, new_len;
83530 unsigned char *ptr;
83531 struct sk_buff *skb;
83532 - static const unsigned char *hex = "0123456789ABCDEF";
83533 + static const unsigned char hex[] = "0123456789ABCDEF";
83534
83535 if (!ab)
83536 return;
83537 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
83538 index 90594c9..abbeed7 100644
83539 --- a/kernel/auditsc.c
83540 +++ b/kernel/auditsc.c
83541 @@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
83542 }
83543
83544 /* global counter which is incremented every time something logs in */
83545 -static atomic_t session_id = ATOMIC_INIT(0);
83546 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
83547
83548 static int audit_set_loginuid_perm(kuid_t loginuid)
83549 {
83550 @@ -2008,7 +2008,7 @@ int audit_set_loginuid(kuid_t loginuid)
83551
83552 /* are we setting or clearing? */
83553 if (uid_valid(loginuid))
83554 - sessionid = atomic_inc_return(&session_id);
83555 + sessionid = atomic_inc_return_unchecked(&session_id);
83556
83557 task->sessionid = sessionid;
83558 task->loginuid = loginuid;
83559 diff --git a/kernel/capability.c b/kernel/capability.c
83560 index 4e66bf9..cdccecf 100644
83561 --- a/kernel/capability.c
83562 +++ b/kernel/capability.c
83563 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
83564 * before modification is attempted and the application
83565 * fails.
83566 */
83567 + if (tocopy > ARRAY_SIZE(kdata))
83568 + return -EFAULT;
83569 +
83570 if (copy_to_user(dataptr, kdata, tocopy
83571 * sizeof(struct __user_cap_data_struct))) {
83572 return -EFAULT;
83573 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
83574 int ret;
83575
83576 rcu_read_lock();
83577 - ret = security_capable(__task_cred(t), ns, cap);
83578 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
83579 + gr_task_is_capable(t, __task_cred(t), cap);
83580 rcu_read_unlock();
83581
83582 - return (ret == 0);
83583 + return ret;
83584 }
83585
83586 /**
83587 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
83588 int ret;
83589
83590 rcu_read_lock();
83591 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
83592 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
83593 rcu_read_unlock();
83594
83595 - return (ret == 0);
83596 + return ret;
83597 }
83598
83599 /**
83600 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
83601 BUG();
83602 }
83603
83604 - if (security_capable(current_cred(), ns, cap) == 0) {
83605 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
83606 current->flags |= PF_SUPERPRIV;
83607 return true;
83608 }
83609 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
83610 }
83611 EXPORT_SYMBOL(ns_capable);
83612
83613 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
83614 +{
83615 + if (unlikely(!cap_valid(cap))) {
83616 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
83617 + BUG();
83618 + }
83619 +
83620 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
83621 + current->flags |= PF_SUPERPRIV;
83622 + return true;
83623 + }
83624 + return false;
83625 +}
83626 +EXPORT_SYMBOL(ns_capable_nolog);
83627 +
83628 /**
83629 * file_ns_capable - Determine if the file's opener had a capability in effect
83630 * @file: The file we want to check
83631 @@ -432,6 +451,12 @@ bool capable(int cap)
83632 }
83633 EXPORT_SYMBOL(capable);
83634
83635 +bool capable_nolog(int cap)
83636 +{
83637 + return ns_capable_nolog(&init_user_ns, cap);
83638 +}
83639 +EXPORT_SYMBOL(capable_nolog);
83640 +
83641 /**
83642 * inode_capable - Check superior capability over inode
83643 * @inode: The inode in question
83644 @@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
83645 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
83646 }
83647 EXPORT_SYMBOL(inode_capable);
83648 +
83649 +bool inode_capable_nolog(const struct inode *inode, int cap)
83650 +{
83651 + struct user_namespace *ns = current_user_ns();
83652 +
83653 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
83654 +}
83655 +EXPORT_SYMBOL(inode_capable_nolog);
83656 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
83657 index bc1dcab..f3a6b42 100644
83658 --- a/kernel/cgroup.c
83659 +++ b/kernel/cgroup.c
83660 @@ -5607,7 +5607,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
83661 struct css_set *cset = link->cset;
83662 struct task_struct *task;
83663 int count = 0;
83664 - seq_printf(seq, "css_set %p\n", cset);
83665 + seq_printf(seq, "css_set %pK\n", cset);
83666 list_for_each_entry(task, &cset->tasks, cg_list) {
83667 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
83668 seq_puts(seq, " ...\n");
83669 diff --git a/kernel/compat.c b/kernel/compat.c
83670 index 0a09e48..b46b3d78 100644
83671 --- a/kernel/compat.c
83672 +++ b/kernel/compat.c
83673 @@ -13,6 +13,7 @@
83674
83675 #include <linux/linkage.h>
83676 #include <linux/compat.h>
83677 +#include <linux/module.h>
83678 #include <linux/errno.h>
83679 #include <linux/time.h>
83680 #include <linux/signal.h>
83681 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
83682 mm_segment_t oldfs;
83683 long ret;
83684
83685 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
83686 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
83687 oldfs = get_fs();
83688 set_fs(KERNEL_DS);
83689 ret = hrtimer_nanosleep_restart(restart);
83690 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
83691 oldfs = get_fs();
83692 set_fs(KERNEL_DS);
83693 ret = hrtimer_nanosleep(&tu,
83694 - rmtp ? (struct timespec __user *)&rmt : NULL,
83695 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
83696 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
83697 set_fs(oldfs);
83698
83699 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
83700 mm_segment_t old_fs = get_fs();
83701
83702 set_fs(KERNEL_DS);
83703 - ret = sys_sigpending((old_sigset_t __user *) &s);
83704 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
83705 set_fs(old_fs);
83706 if (ret == 0)
83707 ret = put_user(s, set);
83708 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
83709 mm_segment_t old_fs = get_fs();
83710
83711 set_fs(KERNEL_DS);
83712 - ret = sys_old_getrlimit(resource, &r);
83713 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
83714 set_fs(old_fs);
83715
83716 if (!ret) {
83717 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
83718 set_fs (KERNEL_DS);
83719 ret = sys_wait4(pid,
83720 (stat_addr ?
83721 - (unsigned int __user *) &status : NULL),
83722 - options, (struct rusage __user *) &r);
83723 + (unsigned int __force_user *) &status : NULL),
83724 + options, (struct rusage __force_user *) &r);
83725 set_fs (old_fs);
83726
83727 if (ret > 0) {
83728 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
83729 memset(&info, 0, sizeof(info));
83730
83731 set_fs(KERNEL_DS);
83732 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
83733 - uru ? (struct rusage __user *)&ru : NULL);
83734 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
83735 + uru ? (struct rusage __force_user *)&ru : NULL);
83736 set_fs(old_fs);
83737
83738 if ((ret < 0) || (info.si_signo == 0))
83739 @@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
83740 oldfs = get_fs();
83741 set_fs(KERNEL_DS);
83742 err = sys_timer_settime(timer_id, flags,
83743 - (struct itimerspec __user *) &newts,
83744 - (struct itimerspec __user *) &oldts);
83745 + (struct itimerspec __force_user *) &newts,
83746 + (struct itimerspec __force_user *) &oldts);
83747 set_fs(oldfs);
83748 if (!err && old && put_compat_itimerspec(old, &oldts))
83749 return -EFAULT;
83750 @@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
83751 oldfs = get_fs();
83752 set_fs(KERNEL_DS);
83753 err = sys_timer_gettime(timer_id,
83754 - (struct itimerspec __user *) &ts);
83755 + (struct itimerspec __force_user *) &ts);
83756 set_fs(oldfs);
83757 if (!err && put_compat_itimerspec(setting, &ts))
83758 return -EFAULT;
83759 @@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
83760 oldfs = get_fs();
83761 set_fs(KERNEL_DS);
83762 err = sys_clock_settime(which_clock,
83763 - (struct timespec __user *) &ts);
83764 + (struct timespec __force_user *) &ts);
83765 set_fs(oldfs);
83766 return err;
83767 }
83768 @@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
83769 oldfs = get_fs();
83770 set_fs(KERNEL_DS);
83771 err = sys_clock_gettime(which_clock,
83772 - (struct timespec __user *) &ts);
83773 + (struct timespec __force_user *) &ts);
83774 set_fs(oldfs);
83775 if (!err && put_compat_timespec(&ts, tp))
83776 return -EFAULT;
83777 @@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
83778
83779 oldfs = get_fs();
83780 set_fs(KERNEL_DS);
83781 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
83782 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
83783 set_fs(oldfs);
83784
83785 err = compat_put_timex(utp, &txc);
83786 @@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
83787 oldfs = get_fs();
83788 set_fs(KERNEL_DS);
83789 err = sys_clock_getres(which_clock,
83790 - (struct timespec __user *) &ts);
83791 + (struct timespec __force_user *) &ts);
83792 set_fs(oldfs);
83793 if (!err && tp && put_compat_timespec(&ts, tp))
83794 return -EFAULT;
83795 @@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
83796 long err;
83797 mm_segment_t oldfs;
83798 struct timespec tu;
83799 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
83800 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
83801
83802 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
83803 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
83804 oldfs = get_fs();
83805 set_fs(KERNEL_DS);
83806 err = clock_nanosleep_restart(restart);
83807 @@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
83808 oldfs = get_fs();
83809 set_fs(KERNEL_DS);
83810 err = sys_clock_nanosleep(which_clock, flags,
83811 - (struct timespec __user *) &in,
83812 - (struct timespec __user *) &out);
83813 + (struct timespec __force_user *) &in,
83814 + (struct timespec __force_user *) &out);
83815 set_fs(oldfs);
83816
83817 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
83818 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
83819 mm_segment_t old_fs = get_fs();
83820
83821 set_fs(KERNEL_DS);
83822 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
83823 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
83824 set_fs(old_fs);
83825 if (put_compat_timespec(&t, interval))
83826 return -EFAULT;
83827 diff --git a/kernel/configs.c b/kernel/configs.c
83828 index c18b1f1..b9a0132 100644
83829 --- a/kernel/configs.c
83830 +++ b/kernel/configs.c
83831 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
83832 struct proc_dir_entry *entry;
83833
83834 /* create the current config file */
83835 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
83836 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
83837 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
83838 + &ikconfig_file_ops);
83839 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83840 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
83841 + &ikconfig_file_ops);
83842 +#endif
83843 +#else
83844 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
83845 &ikconfig_file_ops);
83846 +#endif
83847 +
83848 if (!entry)
83849 return -ENOMEM;
83850
83851 diff --git a/kernel/cred.c b/kernel/cred.c
83852 index e0573a4..3874e41 100644
83853 --- a/kernel/cred.c
83854 +++ b/kernel/cred.c
83855 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
83856 validate_creds(cred);
83857 alter_cred_subscribers(cred, -1);
83858 put_cred(cred);
83859 +
83860 +#ifdef CONFIG_GRKERNSEC_SETXID
83861 + cred = (struct cred *) tsk->delayed_cred;
83862 + if (cred != NULL) {
83863 + tsk->delayed_cred = NULL;
83864 + validate_creds(cred);
83865 + alter_cred_subscribers(cred, -1);
83866 + put_cred(cred);
83867 + }
83868 +#endif
83869 }
83870
83871 /**
83872 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
83873 * Always returns 0 thus allowing this function to be tail-called at the end
83874 * of, say, sys_setgid().
83875 */
83876 -int commit_creds(struct cred *new)
83877 +static int __commit_creds(struct cred *new)
83878 {
83879 struct task_struct *task = current;
83880 const struct cred *old = task->real_cred;
83881 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
83882
83883 get_cred(new); /* we will require a ref for the subj creds too */
83884
83885 + gr_set_role_label(task, new->uid, new->gid);
83886 +
83887 /* dumpability changes */
83888 if (!uid_eq(old->euid, new->euid) ||
83889 !gid_eq(old->egid, new->egid) ||
83890 @@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
83891 put_cred(old);
83892 return 0;
83893 }
83894 +#ifdef CONFIG_GRKERNSEC_SETXID
83895 +extern int set_user(struct cred *new);
83896 +
83897 +void gr_delayed_cred_worker(void)
83898 +{
83899 + const struct cred *new = current->delayed_cred;
83900 + struct cred *ncred;
83901 +
83902 + current->delayed_cred = NULL;
83903 +
83904 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
83905 + // from doing get_cred on it when queueing this
83906 + put_cred(new);
83907 + return;
83908 + } else if (new == NULL)
83909 + return;
83910 +
83911 + ncred = prepare_creds();
83912 + if (!ncred)
83913 + goto die;
83914 + // uids
83915 + ncred->uid = new->uid;
83916 + ncred->euid = new->euid;
83917 + ncred->suid = new->suid;
83918 + ncred->fsuid = new->fsuid;
83919 + // gids
83920 + ncred->gid = new->gid;
83921 + ncred->egid = new->egid;
83922 + ncred->sgid = new->sgid;
83923 + ncred->fsgid = new->fsgid;
83924 + // groups
83925 + if (set_groups(ncred, new->group_info) < 0) {
83926 + abort_creds(ncred);
83927 + goto die;
83928 + }
83929 + // caps
83930 + ncred->securebits = new->securebits;
83931 + ncred->cap_inheritable = new->cap_inheritable;
83932 + ncred->cap_permitted = new->cap_permitted;
83933 + ncred->cap_effective = new->cap_effective;
83934 + ncred->cap_bset = new->cap_bset;
83935 +
83936 + if (set_user(ncred)) {
83937 + abort_creds(ncred);
83938 + goto die;
83939 + }
83940 +
83941 + // from doing get_cred on it when queueing this
83942 + put_cred(new);
83943 +
83944 + __commit_creds(ncred);
83945 + return;
83946 +die:
83947 + // from doing get_cred on it when queueing this
83948 + put_cred(new);
83949 + do_group_exit(SIGKILL);
83950 +}
83951 +#endif
83952 +
83953 +int commit_creds(struct cred *new)
83954 +{
83955 +#ifdef CONFIG_GRKERNSEC_SETXID
83956 + int ret;
83957 + int schedule_it = 0;
83958 + struct task_struct *t;
83959 +
83960 + /* we won't get called with tasklist_lock held for writing
83961 + and interrupts disabled as the cred struct in that case is
83962 + init_cred
83963 + */
83964 + if (grsec_enable_setxid && !current_is_single_threaded() &&
83965 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
83966 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
83967 + schedule_it = 1;
83968 + }
83969 + ret = __commit_creds(new);
83970 + if (schedule_it) {
83971 + rcu_read_lock();
83972 + read_lock(&tasklist_lock);
83973 + for (t = next_thread(current); t != current;
83974 + t = next_thread(t)) {
83975 + if (t->delayed_cred == NULL) {
83976 + t->delayed_cred = get_cred(new);
83977 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
83978 + set_tsk_need_resched(t);
83979 + }
83980 + }
83981 + read_unlock(&tasklist_lock);
83982 + rcu_read_unlock();
83983 + }
83984 + return ret;
83985 +#else
83986 + return __commit_creds(new);
83987 +#endif
83988 +}
83989 +
83990 EXPORT_SYMBOL(commit_creds);
83991
83992 /**
83993 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
83994 index 7d2f35e..1bafcd0 100644
83995 --- a/kernel/debug/debug_core.c
83996 +++ b/kernel/debug/debug_core.c
83997 @@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
83998 */
83999 static atomic_t masters_in_kgdb;
84000 static atomic_t slaves_in_kgdb;
84001 -static atomic_t kgdb_break_tasklet_var;
84002 +static atomic_unchecked_t kgdb_break_tasklet_var;
84003 atomic_t kgdb_setting_breakpoint;
84004
84005 struct task_struct *kgdb_usethread;
84006 @@ -133,7 +133,7 @@ int kgdb_single_step;
84007 static pid_t kgdb_sstep_pid;
84008
84009 /* to keep track of the CPU which is doing the single stepping*/
84010 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
84011 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
84012
84013 /*
84014 * If you are debugging a problem where roundup (the collection of
84015 @@ -541,7 +541,7 @@ return_normal:
84016 * kernel will only try for the value of sstep_tries before
84017 * giving up and continuing on.
84018 */
84019 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
84020 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
84021 (kgdb_info[cpu].task &&
84022 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
84023 atomic_set(&kgdb_active, -1);
84024 @@ -639,8 +639,8 @@ cpu_master_loop:
84025 }
84026
84027 kgdb_restore:
84028 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
84029 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
84030 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
84031 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
84032 if (kgdb_info[sstep_cpu].task)
84033 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
84034 else
84035 @@ -916,18 +916,18 @@ static void kgdb_unregister_callbacks(void)
84036 static void kgdb_tasklet_bpt(unsigned long ing)
84037 {
84038 kgdb_breakpoint();
84039 - atomic_set(&kgdb_break_tasklet_var, 0);
84040 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
84041 }
84042
84043 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
84044
84045 void kgdb_schedule_breakpoint(void)
84046 {
84047 - if (atomic_read(&kgdb_break_tasklet_var) ||
84048 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
84049 atomic_read(&kgdb_active) != -1 ||
84050 atomic_read(&kgdb_setting_breakpoint))
84051 return;
84052 - atomic_inc(&kgdb_break_tasklet_var);
84053 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
84054 tasklet_schedule(&kgdb_tasklet_breakpoint);
84055 }
84056 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
84057 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
84058 index 0b097c8..11dd5c5 100644
84059 --- a/kernel/debug/kdb/kdb_main.c
84060 +++ b/kernel/debug/kdb/kdb_main.c
84061 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
84062 continue;
84063
84064 kdb_printf("%-20s%8u 0x%p ", mod->name,
84065 - mod->core_size, (void *)mod);
84066 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
84067 #ifdef CONFIG_MODULE_UNLOAD
84068 kdb_printf("%4ld ", module_refcount(mod));
84069 #endif
84070 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
84071 kdb_printf(" (Loading)");
84072 else
84073 kdb_printf(" (Live)");
84074 - kdb_printf(" 0x%p", mod->module_core);
84075 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
84076
84077 #ifdef CONFIG_MODULE_UNLOAD
84078 {
84079 diff --git a/kernel/events/core.c b/kernel/events/core.c
84080 index f574401..11b21f0 100644
84081 --- a/kernel/events/core.c
84082 +++ b/kernel/events/core.c
84083 @@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
84084 * 0 - disallow raw tracepoint access for unpriv
84085 * 1 - disallow cpu events for unpriv
84086 * 2 - disallow kernel profiling for unpriv
84087 + * 3 - disallow all unpriv perf event use
84088 */
84089 -int sysctl_perf_event_paranoid __read_mostly = 1;
84090 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84091 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
84092 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
84093 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
84094 +#else
84095 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
84096 +#endif
84097
84098 /* Minimum for 512 kiB + 1 user control page */
84099 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
84100 @@ -184,7 +191,7 @@ void update_perf_cpu_limits(void)
84101
84102 tmp *= sysctl_perf_cpu_time_max_percent;
84103 do_div(tmp, 100);
84104 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
84105 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
84106 }
84107
84108 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
84109 @@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
84110 update_perf_cpu_limits();
84111 }
84112
84113 -static atomic64_t perf_event_id;
84114 +static atomic64_unchecked_t perf_event_id;
84115
84116 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
84117 enum event_type_t event_type);
84118 @@ -2985,7 +2992,7 @@ static void __perf_event_read(void *info)
84119
84120 static inline u64 perf_event_count(struct perf_event *event)
84121 {
84122 - return local64_read(&event->count) + atomic64_read(&event->child_count);
84123 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
84124 }
84125
84126 static u64 perf_event_read(struct perf_event *event)
84127 @@ -3353,9 +3360,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
84128 mutex_lock(&event->child_mutex);
84129 total += perf_event_read(event);
84130 *enabled += event->total_time_enabled +
84131 - atomic64_read(&event->child_total_time_enabled);
84132 + atomic64_read_unchecked(&event->child_total_time_enabled);
84133 *running += event->total_time_running +
84134 - atomic64_read(&event->child_total_time_running);
84135 + atomic64_read_unchecked(&event->child_total_time_running);
84136
84137 list_for_each_entry(child, &event->child_list, child_list) {
84138 total += perf_event_read(child);
84139 @@ -3770,10 +3777,10 @@ void perf_event_update_userpage(struct perf_event *event)
84140 userpg->offset -= local64_read(&event->hw.prev_count);
84141
84142 userpg->time_enabled = enabled +
84143 - atomic64_read(&event->child_total_time_enabled);
84144 + atomic64_read_unchecked(&event->child_total_time_enabled);
84145
84146 userpg->time_running = running +
84147 - atomic64_read(&event->child_total_time_running);
84148 + atomic64_read_unchecked(&event->child_total_time_running);
84149
84150 arch_perf_update_userpage(userpg, now);
84151
84152 @@ -4324,7 +4331,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
84153
84154 /* Data. */
84155 sp = perf_user_stack_pointer(regs);
84156 - rem = __output_copy_user(handle, (void *) sp, dump_size);
84157 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
84158 dyn_size = dump_size - rem;
84159
84160 perf_output_skip(handle, rem);
84161 @@ -4415,11 +4422,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
84162 values[n++] = perf_event_count(event);
84163 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
84164 values[n++] = enabled +
84165 - atomic64_read(&event->child_total_time_enabled);
84166 + atomic64_read_unchecked(&event->child_total_time_enabled);
84167 }
84168 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
84169 values[n++] = running +
84170 - atomic64_read(&event->child_total_time_running);
84171 + atomic64_read_unchecked(&event->child_total_time_running);
84172 }
84173 if (read_format & PERF_FORMAT_ID)
84174 values[n++] = primary_event_id(event);
84175 @@ -6686,7 +6693,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
84176 event->parent = parent_event;
84177
84178 event->ns = get_pid_ns(task_active_pid_ns(current));
84179 - event->id = atomic64_inc_return(&perf_event_id);
84180 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
84181
84182 event->state = PERF_EVENT_STATE_INACTIVE;
84183
84184 @@ -6985,6 +6992,11 @@ SYSCALL_DEFINE5(perf_event_open,
84185 if (flags & ~PERF_FLAG_ALL)
84186 return -EINVAL;
84187
84188 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84189 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
84190 + return -EACCES;
84191 +#endif
84192 +
84193 err = perf_copy_attr(attr_uptr, &attr);
84194 if (err)
84195 return err;
84196 @@ -7316,10 +7328,10 @@ static void sync_child_event(struct perf_event *child_event,
84197 /*
84198 * Add back the child's count to the parent's count:
84199 */
84200 - atomic64_add(child_val, &parent_event->child_count);
84201 - atomic64_add(child_event->total_time_enabled,
84202 + atomic64_add_unchecked(child_val, &parent_event->child_count);
84203 + atomic64_add_unchecked(child_event->total_time_enabled,
84204 &parent_event->child_total_time_enabled);
84205 - atomic64_add(child_event->total_time_running,
84206 + atomic64_add_unchecked(child_event->total_time_running,
84207 &parent_event->child_total_time_running);
84208
84209 /*
84210 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
84211 index 569b2187..19940d9 100644
84212 --- a/kernel/events/internal.h
84213 +++ b/kernel/events/internal.h
84214 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
84215 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
84216 }
84217
84218 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
84219 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
84220 static inline unsigned long \
84221 func_name(struct perf_output_handle *handle, \
84222 - const void *buf, unsigned long len) \
84223 + const void user *buf, unsigned long len) \
84224 { \
84225 unsigned long size, written; \
84226 \
84227 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
84228 return 0;
84229 }
84230
84231 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
84232 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
84233
84234 static inline unsigned long
84235 memcpy_skip(void *dst, const void *src, unsigned long n)
84236 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
84237 return 0;
84238 }
84239
84240 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
84241 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
84242
84243 #ifndef arch_perf_out_copy_user
84244 #define arch_perf_out_copy_user arch_perf_out_copy_user
84245 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
84246 }
84247 #endif
84248
84249 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
84250 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
84251
84252 /* Callchain handling */
84253 extern struct perf_callchain_entry *
84254 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
84255 index 24b7d6c..40cf797 100644
84256 --- a/kernel/events/uprobes.c
84257 +++ b/kernel/events/uprobes.c
84258 @@ -1640,7 +1640,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
84259 {
84260 struct page *page;
84261 uprobe_opcode_t opcode;
84262 - int result;
84263 + long result;
84264
84265 pagefault_disable();
84266 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
84267 diff --git a/kernel/exit.c b/kernel/exit.c
84268 index a949819..a5f127d 100644
84269 --- a/kernel/exit.c
84270 +++ b/kernel/exit.c
84271 @@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
84272 struct task_struct *leader;
84273 int zap_leader;
84274 repeat:
84275 +#ifdef CONFIG_NET
84276 + gr_del_task_from_ip_table(p);
84277 +#endif
84278 +
84279 /* don't need to get the RCU readlock here - the process is dead and
84280 * can't be modifying its own credentials. But shut RCU-lockdep up */
84281 rcu_read_lock();
84282 @@ -329,7 +333,7 @@ int allow_signal(int sig)
84283 * know it'll be handled, so that they don't get converted to
84284 * SIGKILL or just silently dropped.
84285 */
84286 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
84287 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
84288 recalc_sigpending();
84289 spin_unlock_irq(&current->sighand->siglock);
84290 return 0;
84291 @@ -698,6 +702,8 @@ void do_exit(long code)
84292 struct task_struct *tsk = current;
84293 int group_dead;
84294
84295 + set_fs(USER_DS);
84296 +
84297 profile_task_exit(tsk);
84298
84299 WARN_ON(blk_needs_flush_plug(tsk));
84300 @@ -714,7 +720,6 @@ void do_exit(long code)
84301 * mm_release()->clear_child_tid() from writing to a user-controlled
84302 * kernel address.
84303 */
84304 - set_fs(USER_DS);
84305
84306 ptrace_event(PTRACE_EVENT_EXIT, code);
84307
84308 @@ -773,6 +778,9 @@ void do_exit(long code)
84309 tsk->exit_code = code;
84310 taskstats_exit(tsk, group_dead);
84311
84312 + gr_acl_handle_psacct(tsk, code);
84313 + gr_acl_handle_exit();
84314 +
84315 exit_mm(tsk);
84316
84317 if (group_dead)
84318 @@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
84319 * Take down every thread in the group. This is called by fatal signals
84320 * as well as by sys_exit_group (below).
84321 */
84322 -void
84323 +__noreturn void
84324 do_group_exit(int exit_code)
84325 {
84326 struct signal_struct *sig = current->signal;
84327 diff --git a/kernel/fork.c b/kernel/fork.c
84328 index dfa736c..d170f9b 100644
84329 --- a/kernel/fork.c
84330 +++ b/kernel/fork.c
84331 @@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
84332 *stackend = STACK_END_MAGIC; /* for overflow detection */
84333
84334 #ifdef CONFIG_CC_STACKPROTECTOR
84335 - tsk->stack_canary = get_random_int();
84336 + tsk->stack_canary = pax_get_random_long();
84337 #endif
84338
84339 /*
84340 @@ -345,12 +345,80 @@ free_tsk:
84341 }
84342
84343 #ifdef CONFIG_MMU
84344 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84345 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
84346 +{
84347 + struct vm_area_struct *tmp;
84348 + unsigned long charge;
84349 + struct file *file;
84350 + int retval;
84351 +
84352 + charge = 0;
84353 + if (mpnt->vm_flags & VM_ACCOUNT) {
84354 + unsigned long len = vma_pages(mpnt);
84355 +
84356 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
84357 + goto fail_nomem;
84358 + charge = len;
84359 + }
84360 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
84361 + if (!tmp)
84362 + goto fail_nomem;
84363 + *tmp = *mpnt;
84364 + tmp->vm_mm = mm;
84365 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
84366 + retval = vma_dup_policy(mpnt, tmp);
84367 + if (retval)
84368 + goto fail_nomem_policy;
84369 + if (anon_vma_fork(tmp, mpnt))
84370 + goto fail_nomem_anon_vma_fork;
84371 + tmp->vm_flags &= ~VM_LOCKED;
84372 + tmp->vm_next = tmp->vm_prev = NULL;
84373 + tmp->vm_mirror = NULL;
84374 + file = tmp->vm_file;
84375 + if (file) {
84376 + struct inode *inode = file_inode(file);
84377 + struct address_space *mapping = file->f_mapping;
84378 +
84379 + get_file(file);
84380 + if (tmp->vm_flags & VM_DENYWRITE)
84381 + atomic_dec(&inode->i_writecount);
84382 + mutex_lock(&mapping->i_mmap_mutex);
84383 + if (tmp->vm_flags & VM_SHARED)
84384 + mapping->i_mmap_writable++;
84385 + flush_dcache_mmap_lock(mapping);
84386 + /* insert tmp into the share list, just after mpnt */
84387 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
84388 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
84389 + else
84390 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
84391 + flush_dcache_mmap_unlock(mapping);
84392 + mutex_unlock(&mapping->i_mmap_mutex);
84393 + }
84394 +
84395 + /*
84396 + * Clear hugetlb-related page reserves for children. This only
84397 + * affects MAP_PRIVATE mappings. Faults generated by the child
84398 + * are not guaranteed to succeed, even if read-only
84399 + */
84400 + if (is_vm_hugetlb_page(tmp))
84401 + reset_vma_resv_huge_pages(tmp);
84402 +
84403 + return tmp;
84404 +
84405 +fail_nomem_anon_vma_fork:
84406 + mpol_put(vma_policy(tmp));
84407 +fail_nomem_policy:
84408 + kmem_cache_free(vm_area_cachep, tmp);
84409 +fail_nomem:
84410 + vm_unacct_memory(charge);
84411 + return NULL;
84412 +}
84413 +
84414 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84415 {
84416 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
84417 struct rb_node **rb_link, *rb_parent;
84418 int retval;
84419 - unsigned long charge;
84420
84421 uprobe_start_dup_mmap();
84422 down_write(&oldmm->mmap_sem);
84423 @@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84424
84425 prev = NULL;
84426 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
84427 - struct file *file;
84428 -
84429 if (mpnt->vm_flags & VM_DONTCOPY) {
84430 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
84431 -vma_pages(mpnt));
84432 continue;
84433 }
84434 - charge = 0;
84435 - if (mpnt->vm_flags & VM_ACCOUNT) {
84436 - unsigned long len = vma_pages(mpnt);
84437 -
84438 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
84439 - goto fail_nomem;
84440 - charge = len;
84441 - }
84442 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
84443 - if (!tmp)
84444 - goto fail_nomem;
84445 - *tmp = *mpnt;
84446 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
84447 - retval = vma_dup_policy(mpnt, tmp);
84448 - if (retval)
84449 - goto fail_nomem_policy;
84450 - tmp->vm_mm = mm;
84451 - if (anon_vma_fork(tmp, mpnt))
84452 - goto fail_nomem_anon_vma_fork;
84453 - tmp->vm_flags &= ~VM_LOCKED;
84454 - tmp->vm_next = tmp->vm_prev = NULL;
84455 - file = tmp->vm_file;
84456 - if (file) {
84457 - struct inode *inode = file_inode(file);
84458 - struct address_space *mapping = file->f_mapping;
84459 -
84460 - get_file(file);
84461 - if (tmp->vm_flags & VM_DENYWRITE)
84462 - atomic_dec(&inode->i_writecount);
84463 - mutex_lock(&mapping->i_mmap_mutex);
84464 - if (tmp->vm_flags & VM_SHARED)
84465 - mapping->i_mmap_writable++;
84466 - flush_dcache_mmap_lock(mapping);
84467 - /* insert tmp into the share list, just after mpnt */
84468 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
84469 - vma_nonlinear_insert(tmp,
84470 - &mapping->i_mmap_nonlinear);
84471 - else
84472 - vma_interval_tree_insert_after(tmp, mpnt,
84473 - &mapping->i_mmap);
84474 - flush_dcache_mmap_unlock(mapping);
84475 - mutex_unlock(&mapping->i_mmap_mutex);
84476 + tmp = dup_vma(mm, oldmm, mpnt);
84477 + if (!tmp) {
84478 + retval = -ENOMEM;
84479 + goto out;
84480 }
84481
84482 /*
84483 @@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84484 if (retval)
84485 goto out;
84486 }
84487 +
84488 +#ifdef CONFIG_PAX_SEGMEXEC
84489 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
84490 + struct vm_area_struct *mpnt_m;
84491 +
84492 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
84493 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
84494 +
84495 + if (!mpnt->vm_mirror)
84496 + continue;
84497 +
84498 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
84499 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
84500 + mpnt->vm_mirror = mpnt_m;
84501 + } else {
84502 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
84503 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
84504 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
84505 + mpnt->vm_mirror->vm_mirror = mpnt;
84506 + }
84507 + }
84508 + BUG_ON(mpnt_m);
84509 + }
84510 +#endif
84511 +
84512 /* a new mm has just been created */
84513 arch_dup_mmap(oldmm, mm);
84514 retval = 0;
84515 @@ -468,14 +521,6 @@ out:
84516 up_write(&oldmm->mmap_sem);
84517 uprobe_end_dup_mmap();
84518 return retval;
84519 -fail_nomem_anon_vma_fork:
84520 - mpol_put(vma_policy(tmp));
84521 -fail_nomem_policy:
84522 - kmem_cache_free(vm_area_cachep, tmp);
84523 -fail_nomem:
84524 - retval = -ENOMEM;
84525 - vm_unacct_memory(charge);
84526 - goto out;
84527 }
84528
84529 static inline int mm_alloc_pgd(struct mm_struct *mm)
84530 @@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
84531 return ERR_PTR(err);
84532
84533 mm = get_task_mm(task);
84534 - if (mm && mm != current->mm &&
84535 - !ptrace_may_access(task, mode)) {
84536 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
84537 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
84538 mmput(mm);
84539 mm = ERR_PTR(-EACCES);
84540 }
84541 @@ -909,13 +954,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
84542 spin_unlock(&fs->lock);
84543 return -EAGAIN;
84544 }
84545 - fs->users++;
84546 + atomic_inc(&fs->users);
84547 spin_unlock(&fs->lock);
84548 return 0;
84549 }
84550 tsk->fs = copy_fs_struct(fs);
84551 if (!tsk->fs)
84552 return -ENOMEM;
84553 + /* Carry through gr_chroot_dentry and is_chrooted instead
84554 + of recomputing it here. Already copied when the task struct
84555 + is duplicated. This allows pivot_root to not be treated as
84556 + a chroot
84557 + */
84558 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
84559 +
84560 return 0;
84561 }
84562
84563 @@ -1126,7 +1178,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
84564 * parts of the process environment (as per the clone
84565 * flags). The actual kick-off is left to the caller.
84566 */
84567 -static struct task_struct *copy_process(unsigned long clone_flags,
84568 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
84569 unsigned long stack_start,
84570 unsigned long stack_size,
84571 int __user *child_tidptr,
84572 @@ -1198,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
84573 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
84574 #endif
84575 retval = -EAGAIN;
84576 +
84577 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
84578 +
84579 if (atomic_read(&p->real_cred->user->processes) >=
84580 task_rlimit(p, RLIMIT_NPROC)) {
84581 if (p->real_cred->user != INIT_USER &&
84582 @@ -1446,6 +1501,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
84583 goto bad_fork_free_pid;
84584 }
84585
84586 + /* synchronizes with gr_set_acls()
84587 + we need to call this past the point of no return for fork()
84588 + */
84589 + gr_copy_label(p);
84590 +
84591 if (likely(p->pid)) {
84592 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
84593
84594 @@ -1532,6 +1592,8 @@ bad_fork_cleanup_count:
84595 bad_fork_free:
84596 free_task(p);
84597 fork_out:
84598 + gr_log_forkfail(retval);
84599 +
84600 return ERR_PTR(retval);
84601 }
84602
84603 @@ -1593,6 +1655,7 @@ long do_fork(unsigned long clone_flags,
84604
84605 p = copy_process(clone_flags, stack_start, stack_size,
84606 child_tidptr, NULL, trace);
84607 + add_latent_entropy();
84608 /*
84609 * Do this prior waking up the new thread - the thread pointer
84610 * might get invalid after that point, if the thread exits quickly.
84611 @@ -1607,6 +1670,8 @@ long do_fork(unsigned long clone_flags,
84612 if (clone_flags & CLONE_PARENT_SETTID)
84613 put_user(nr, parent_tidptr);
84614
84615 + gr_handle_brute_check();
84616 +
84617 if (clone_flags & CLONE_VFORK) {
84618 p->vfork_done = &vfork;
84619 init_completion(&vfork);
84620 @@ -1723,7 +1788,7 @@ void __init proc_caches_init(void)
84621 mm_cachep = kmem_cache_create("mm_struct",
84622 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
84623 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
84624 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
84625 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
84626 mmap_init();
84627 nsproxy_cache_init();
84628 }
84629 @@ -1763,7 +1828,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
84630 return 0;
84631
84632 /* don't need lock here; in the worst case we'll do useless copy */
84633 - if (fs->users == 1)
84634 + if (atomic_read(&fs->users) == 1)
84635 return 0;
84636
84637 *new_fsp = copy_fs_struct(fs);
84638 @@ -1870,7 +1935,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
84639 fs = current->fs;
84640 spin_lock(&fs->lock);
84641 current->fs = new_fs;
84642 - if (--fs->users)
84643 + gr_set_chroot_entries(current, &current->fs->root);
84644 + if (atomic_dec_return(&fs->users))
84645 new_fs = NULL;
84646 else
84647 new_fs = fs;
84648 diff --git a/kernel/futex.c b/kernel/futex.c
84649 index f6ff019..ac53307 100644
84650 --- a/kernel/futex.c
84651 +++ b/kernel/futex.c
84652 @@ -54,6 +54,7 @@
84653 #include <linux/mount.h>
84654 #include <linux/pagemap.h>
84655 #include <linux/syscalls.h>
84656 +#include <linux/ptrace.h>
84657 #include <linux/signal.h>
84658 #include <linux/export.h>
84659 #include <linux/magic.h>
84660 @@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
84661 struct page *page, *page_head;
84662 int err, ro = 0;
84663
84664 +#ifdef CONFIG_PAX_SEGMEXEC
84665 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
84666 + return -EFAULT;
84667 +#endif
84668 +
84669 /*
84670 * The futex address must be "naturally" aligned.
84671 */
84672 @@ -442,7 +448,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
84673
84674 static int get_futex_value_locked(u32 *dest, u32 __user *from)
84675 {
84676 - int ret;
84677 + unsigned long ret;
84678
84679 pagefault_disable();
84680 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
84681 @@ -2735,6 +2741,7 @@ static int __init futex_init(void)
84682 {
84683 u32 curval;
84684 int i;
84685 + mm_segment_t oldfs;
84686
84687 /*
84688 * This will fail and we want it. Some arch implementations do
84689 @@ -2746,8 +2753,11 @@ static int __init futex_init(void)
84690 * implementation, the non-functional ones will return
84691 * -ENOSYS.
84692 */
84693 + oldfs = get_fs();
84694 + set_fs(USER_DS);
84695 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
84696 futex_cmpxchg_enabled = 1;
84697 + set_fs(oldfs);
84698
84699 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
84700 plist_head_init(&futex_queues[i].chain);
84701 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
84702 index f9f44fd..29885e4 100644
84703 --- a/kernel/futex_compat.c
84704 +++ b/kernel/futex_compat.c
84705 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
84706 return 0;
84707 }
84708
84709 -static void __user *futex_uaddr(struct robust_list __user *entry,
84710 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
84711 compat_long_t futex_offset)
84712 {
84713 compat_uptr_t base = ptr_to_compat(entry);
84714 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
84715 index f45b75b..bfac6d5 100644
84716 --- a/kernel/gcov/base.c
84717 +++ b/kernel/gcov/base.c
84718 @@ -108,11 +108,6 @@ void gcov_enable_events(void)
84719 }
84720
84721 #ifdef CONFIG_MODULES
84722 -static inline int within(void *addr, void *start, unsigned long size)
84723 -{
84724 - return ((addr >= start) && (addr < start + size));
84725 -}
84726 -
84727 /* Update list and generate events when modules are unloaded. */
84728 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
84729 void *data)
84730 @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
84731
84732 /* Remove entries located in module from linked list. */
84733 while ((info = gcov_info_next(info))) {
84734 - if (within(info, mod->module_core, mod->core_size)) {
84735 + if (within_module_core_rw((unsigned long)info, mod)) {
84736 gcov_info_unlink(prev, info);
84737 if (gcov_events_enabled)
84738 gcov_event(GCOV_REMOVE, info);
84739 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
84740 index 383319b..56ebb13 100644
84741 --- a/kernel/hrtimer.c
84742 +++ b/kernel/hrtimer.c
84743 @@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
84744 local_irq_restore(flags);
84745 }
84746
84747 -static void run_hrtimer_softirq(struct softirq_action *h)
84748 +static __latent_entropy void run_hrtimer_softirq(void)
84749 {
84750 hrtimer_peek_ahead_timers();
84751 }
84752 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
84753 index 55fcce6..0e4cf34 100644
84754 --- a/kernel/irq_work.c
84755 +++ b/kernel/irq_work.c
84756 @@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
84757 return NOTIFY_OK;
84758 }
84759
84760 -static struct notifier_block cpu_notify;
84761 +static struct notifier_block cpu_notify = {
84762 + .notifier_call = irq_work_cpu_notify,
84763 + .priority = 0,
84764 +};
84765
84766 static __init int irq_work_init_cpu_notifier(void)
84767 {
84768 - cpu_notify.notifier_call = irq_work_cpu_notify;
84769 - cpu_notify.priority = 0;
84770 register_cpu_notifier(&cpu_notify);
84771 return 0;
84772 }
84773 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
84774 index 9019f15..9a3c42e 100644
84775 --- a/kernel/jump_label.c
84776 +++ b/kernel/jump_label.c
84777 @@ -14,6 +14,7 @@
84778 #include <linux/err.h>
84779 #include <linux/static_key.h>
84780 #include <linux/jump_label_ratelimit.h>
84781 +#include <linux/mm.h>
84782
84783 #ifdef HAVE_JUMP_LABEL
84784
84785 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
84786
84787 size = (((unsigned long)stop - (unsigned long)start)
84788 / sizeof(struct jump_entry));
84789 + pax_open_kernel();
84790 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
84791 + pax_close_kernel();
84792 }
84793
84794 static void jump_label_update(struct static_key *key, int enable);
84795 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
84796 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
84797 struct jump_entry *iter;
84798
84799 + pax_open_kernel();
84800 for (iter = iter_start; iter < iter_stop; iter++) {
84801 if (within_module_init(iter->code, mod))
84802 iter->code = 0;
84803 }
84804 + pax_close_kernel();
84805 }
84806
84807 static int
84808 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
84809 index 3127ad5..159d880 100644
84810 --- a/kernel/kallsyms.c
84811 +++ b/kernel/kallsyms.c
84812 @@ -11,6 +11,9 @@
84813 * Changed the compression method from stem compression to "table lookup"
84814 * compression (see scripts/kallsyms.c for a more complete description)
84815 */
84816 +#ifdef CONFIG_GRKERNSEC_HIDESYM
84817 +#define __INCLUDED_BY_HIDESYM 1
84818 +#endif
84819 #include <linux/kallsyms.h>
84820 #include <linux/module.h>
84821 #include <linux/init.h>
84822 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
84823
84824 static inline int is_kernel_inittext(unsigned long addr)
84825 {
84826 + if (system_state != SYSTEM_BOOTING)
84827 + return 0;
84828 +
84829 if (addr >= (unsigned long)_sinittext
84830 && addr <= (unsigned long)_einittext)
84831 return 1;
84832 return 0;
84833 }
84834
84835 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84836 +#ifdef CONFIG_MODULES
84837 +static inline int is_module_text(unsigned long addr)
84838 +{
84839 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
84840 + return 1;
84841 +
84842 + addr = ktla_ktva(addr);
84843 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
84844 +}
84845 +#else
84846 +static inline int is_module_text(unsigned long addr)
84847 +{
84848 + return 0;
84849 +}
84850 +#endif
84851 +#endif
84852 +
84853 static inline int is_kernel_text(unsigned long addr)
84854 {
84855 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
84856 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
84857
84858 static inline int is_kernel(unsigned long addr)
84859 {
84860 +
84861 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84862 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
84863 + return 1;
84864 +
84865 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
84866 +#else
84867 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
84868 +#endif
84869 +
84870 return 1;
84871 return in_gate_area_no_mm(addr);
84872 }
84873
84874 static int is_ksym_addr(unsigned long addr)
84875 {
84876 +
84877 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84878 + if (is_module_text(addr))
84879 + return 0;
84880 +#endif
84881 +
84882 if (all_var)
84883 return is_kernel(addr);
84884
84885 @@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
84886
84887 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
84888 {
84889 - iter->name[0] = '\0';
84890 iter->nameoff = get_symbol_offset(new_pos);
84891 iter->pos = new_pos;
84892 }
84893 @@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
84894 {
84895 struct kallsym_iter *iter = m->private;
84896
84897 +#ifdef CONFIG_GRKERNSEC_HIDESYM
84898 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
84899 + return 0;
84900 +#endif
84901 +
84902 /* Some debugging symbols have no name. Ignore them. */
84903 if (!iter->name[0])
84904 return 0;
84905 @@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
84906 */
84907 type = iter->exported ? toupper(iter->type) :
84908 tolower(iter->type);
84909 +
84910 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
84911 type, iter->name, iter->module_name);
84912 } else
84913 @@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
84914 struct kallsym_iter *iter;
84915 int ret;
84916
84917 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
84918 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
84919 if (!iter)
84920 return -ENOMEM;
84921 reset_iter(iter, 0);
84922 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
84923 index e30ac0f..3528cac 100644
84924 --- a/kernel/kcmp.c
84925 +++ b/kernel/kcmp.c
84926 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
84927 struct task_struct *task1, *task2;
84928 int ret;
84929
84930 +#ifdef CONFIG_GRKERNSEC
84931 + return -ENOSYS;
84932 +#endif
84933 +
84934 rcu_read_lock();
84935
84936 /*
84937 diff --git a/kernel/kexec.c b/kernel/kexec.c
84938 index 9c97016..df438f8 100644
84939 --- a/kernel/kexec.c
84940 +++ b/kernel/kexec.c
84941 @@ -1044,7 +1044,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
84942 unsigned long flags)
84943 {
84944 struct compat_kexec_segment in;
84945 - struct kexec_segment out, __user *ksegments;
84946 + struct kexec_segment out;
84947 + struct kexec_segment __user *ksegments;
84948 unsigned long i, result;
84949
84950 /* Don't allow clients that don't understand the native
84951 diff --git a/kernel/kmod.c b/kernel/kmod.c
84952 index b086006..655e2aa 100644
84953 --- a/kernel/kmod.c
84954 +++ b/kernel/kmod.c
84955 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
84956 kfree(info->argv);
84957 }
84958
84959 -static int call_modprobe(char *module_name, int wait)
84960 +static int call_modprobe(char *module_name, char *module_param, int wait)
84961 {
84962 struct subprocess_info *info;
84963 static char *envp[] = {
84964 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
84965 NULL
84966 };
84967
84968 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
84969 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
84970 if (!argv)
84971 goto out;
84972
84973 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
84974 argv[1] = "-q";
84975 argv[2] = "--";
84976 argv[3] = module_name; /* check free_modprobe_argv() */
84977 - argv[4] = NULL;
84978 + argv[4] = module_param;
84979 + argv[5] = NULL;
84980
84981 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
84982 NULL, free_modprobe_argv, NULL);
84983 @@ -129,9 +130,8 @@ out:
84984 * If module auto-loading support is disabled then this function
84985 * becomes a no-operation.
84986 */
84987 -int __request_module(bool wait, const char *fmt, ...)
84988 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
84989 {
84990 - va_list args;
84991 char module_name[MODULE_NAME_LEN];
84992 unsigned int max_modprobes;
84993 int ret;
84994 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
84995 if (!modprobe_path[0])
84996 return 0;
84997
84998 - va_start(args, fmt);
84999 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
85000 - va_end(args);
85001 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
85002 if (ret >= MODULE_NAME_LEN)
85003 return -ENAMETOOLONG;
85004
85005 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
85006 if (ret)
85007 return ret;
85008
85009 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85010 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
85011 + /* hack to workaround consolekit/udisks stupidity */
85012 + read_lock(&tasklist_lock);
85013 + if (!strcmp(current->comm, "mount") &&
85014 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
85015 + read_unlock(&tasklist_lock);
85016 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
85017 + return -EPERM;
85018 + }
85019 + read_unlock(&tasklist_lock);
85020 + }
85021 +#endif
85022 +
85023 /* If modprobe needs a service that is in a module, we get a recursive
85024 * loop. Limit the number of running kmod threads to max_threads/2 or
85025 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
85026 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
85027
85028 trace_module_request(module_name, wait, _RET_IP_);
85029
85030 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
85031 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
85032
85033 atomic_dec(&kmod_concurrent);
85034 return ret;
85035 }
85036 +
85037 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
85038 +{
85039 + va_list args;
85040 + int ret;
85041 +
85042 + va_start(args, fmt);
85043 + ret = ____request_module(wait, module_param, fmt, args);
85044 + va_end(args);
85045 +
85046 + return ret;
85047 +}
85048 +
85049 +int __request_module(bool wait, const char *fmt, ...)
85050 +{
85051 + va_list args;
85052 + int ret;
85053 +
85054 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85055 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
85056 + char module_param[MODULE_NAME_LEN];
85057 +
85058 + memset(module_param, 0, sizeof(module_param));
85059 +
85060 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
85061 +
85062 + va_start(args, fmt);
85063 + ret = ____request_module(wait, module_param, fmt, args);
85064 + va_end(args);
85065 +
85066 + return ret;
85067 + }
85068 +#endif
85069 +
85070 + va_start(args, fmt);
85071 + ret = ____request_module(wait, NULL, fmt, args);
85072 + va_end(args);
85073 +
85074 + return ret;
85075 +}
85076 +
85077 EXPORT_SYMBOL(__request_module);
85078 #endif /* CONFIG_MODULES */
85079
85080 @@ -218,6 +271,19 @@ static int ____call_usermodehelper(void *data)
85081 */
85082 set_user_nice(current, 0);
85083
85084 +#ifdef CONFIG_GRKERNSEC
85085 + /* this is race-free as far as userland is concerned as we copied
85086 + out the path to be used prior to this point and are now operating
85087 + on that copy
85088 + */
85089 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
85090 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7)) || strstr(sub_info->path, "..")) {
85091 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
85092 + retval = -EPERM;
85093 + goto fail;
85094 + }
85095 +#endif
85096 +
85097 retval = -ENOMEM;
85098 new = prepare_kernel_cred(current);
85099 if (!new)
85100 @@ -240,8 +306,8 @@ static int ____call_usermodehelper(void *data)
85101 commit_creds(new);
85102
85103 retval = do_execve(sub_info->path,
85104 - (const char __user *const __user *)sub_info->argv,
85105 - (const char __user *const __user *)sub_info->envp);
85106 + (const char __user *const __force_user *)sub_info->argv,
85107 + (const char __user *const __force_user *)sub_info->envp);
85108 if (!retval)
85109 return 0;
85110
85111 @@ -260,6 +326,10 @@ static int call_helper(void *data)
85112
85113 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
85114 {
85115 +#ifdef CONFIG_GRKERNSEC
85116 + kfree(info->path);
85117 + info->path = info->origpath;
85118 +#endif
85119 if (info->cleanup)
85120 (*info->cleanup)(info);
85121 kfree(info);
85122 @@ -303,7 +373,7 @@ static int wait_for_helper(void *data)
85123 *
85124 * Thus the __user pointer cast is valid here.
85125 */
85126 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
85127 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
85128
85129 /*
85130 * If ret is 0, either ____call_usermodehelper failed and the
85131 @@ -542,7 +612,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
85132 goto out;
85133
85134 INIT_WORK(&sub_info->work, __call_usermodehelper);
85135 +#ifdef CONFIG_GRKERNSEC
85136 + sub_info->origpath = path;
85137 + sub_info->path = kstrdup(path, gfp_mask);
85138 +#else
85139 sub_info->path = path;
85140 +#endif
85141 sub_info->argv = argv;
85142 sub_info->envp = envp;
85143
85144 @@ -650,7 +725,7 @@ EXPORT_SYMBOL(call_usermodehelper);
85145 static int proc_cap_handler(struct ctl_table *table, int write,
85146 void __user *buffer, size_t *lenp, loff_t *ppos)
85147 {
85148 - struct ctl_table t;
85149 + ctl_table_no_const t;
85150 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
85151 kernel_cap_t new_cap;
85152 int err, i;
85153 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
85154 index ceeadfc..11c18b6 100644
85155 --- a/kernel/kprobes.c
85156 +++ b/kernel/kprobes.c
85157 @@ -31,6 +31,9 @@
85158 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
85159 * <prasanna@in.ibm.com> added function-return probes.
85160 */
85161 +#ifdef CONFIG_GRKERNSEC_HIDESYM
85162 +#define __INCLUDED_BY_HIDESYM 1
85163 +#endif
85164 #include <linux/kprobes.h>
85165 #include <linux/hash.h>
85166 #include <linux/init.h>
85167 @@ -135,12 +138,12 @@ enum kprobe_slot_state {
85168
85169 static void *alloc_insn_page(void)
85170 {
85171 - return module_alloc(PAGE_SIZE);
85172 + return module_alloc_exec(PAGE_SIZE);
85173 }
85174
85175 static void free_insn_page(void *page)
85176 {
85177 - module_free(NULL, page);
85178 + module_free_exec(NULL, page);
85179 }
85180
85181 struct kprobe_insn_cache kprobe_insn_slots = {
85182 @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
85183 kprobe_type = "k";
85184
85185 if (sym)
85186 - seq_printf(pi, "%p %s %s+0x%x %s ",
85187 + seq_printf(pi, "%pK %s %s+0x%x %s ",
85188 p->addr, kprobe_type, sym, offset,
85189 (modname ? modname : " "));
85190 else
85191 - seq_printf(pi, "%p %s %p ",
85192 + seq_printf(pi, "%pK %s %pK ",
85193 p->addr, kprobe_type, p->addr);
85194
85195 if (!pp)
85196 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
85197 index 9659d38..bffd520 100644
85198 --- a/kernel/ksysfs.c
85199 +++ b/kernel/ksysfs.c
85200 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
85201 {
85202 if (count+1 > UEVENT_HELPER_PATH_LEN)
85203 return -ENOENT;
85204 + if (!capable(CAP_SYS_ADMIN))
85205 + return -EPERM;
85206 memcpy(uevent_helper, buf, count);
85207 uevent_helper[count] = '\0';
85208 if (count && uevent_helper[count-1] == '\n')
85209 @@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
85210 return count;
85211 }
85212
85213 -static struct bin_attribute notes_attr = {
85214 +static bin_attribute_no_const notes_attr __read_only = {
85215 .attr = {
85216 .name = "notes",
85217 .mode = S_IRUGO,
85218 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
85219 index 576ba75..7c256e4 100644
85220 --- a/kernel/locking/lockdep.c
85221 +++ b/kernel/locking/lockdep.c
85222 @@ -596,6 +596,10 @@ static int static_obj(void *obj)
85223 end = (unsigned long) &_end,
85224 addr = (unsigned long) obj;
85225
85226 +#ifdef CONFIG_PAX_KERNEXEC
85227 + start = ktla_ktva(start);
85228 +#endif
85229 +
85230 /*
85231 * static variable?
85232 */
85233 @@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
85234 if (!static_obj(lock->key)) {
85235 debug_locks_off();
85236 printk("INFO: trying to register non-static key.\n");
85237 + printk("lock:%pS key:%pS.\n", lock, lock->key);
85238 printk("the code is fine but needs lockdep annotation.\n");
85239 printk("turning off the locking correctness validator.\n");
85240 dump_stack();
85241 @@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
85242 if (!class)
85243 return 0;
85244 }
85245 - atomic_inc((atomic_t *)&class->ops);
85246 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
85247 if (very_verbose(class)) {
85248 printk("\nacquire class [%p] %s", class->key, class->name);
85249 if (class->name_version > 1)
85250 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
85251 index ef43ac4..2720dfa 100644
85252 --- a/kernel/locking/lockdep_proc.c
85253 +++ b/kernel/locking/lockdep_proc.c
85254 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
85255 return 0;
85256 }
85257
85258 - seq_printf(m, "%p", class->key);
85259 + seq_printf(m, "%pK", class->key);
85260 #ifdef CONFIG_DEBUG_LOCKDEP
85261 seq_printf(m, " OPS:%8ld", class->ops);
85262 #endif
85263 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
85264
85265 list_for_each_entry(entry, &class->locks_after, entry) {
85266 if (entry->distance == 1) {
85267 - seq_printf(m, " -> [%p] ", entry->class->key);
85268 + seq_printf(m, " -> [%pK] ", entry->class->key);
85269 print_name(m, entry->class);
85270 seq_puts(m, "\n");
85271 }
85272 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
85273 if (!class->key)
85274 continue;
85275
85276 - seq_printf(m, "[%p] ", class->key);
85277 + seq_printf(m, "[%pK] ", class->key);
85278 print_name(m, class);
85279 seq_puts(m, "\n");
85280 }
85281 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
85282 if (!i)
85283 seq_line(m, '-', 40-namelen, namelen);
85284
85285 - snprintf(ip, sizeof(ip), "[<%p>]",
85286 + snprintf(ip, sizeof(ip), "[<%pK>]",
85287 (void *)class->contention_point[i]);
85288 seq_printf(m, "%40s %14lu %29s %pS\n",
85289 name, stats->contention_point[i],
85290 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
85291 if (!i)
85292 seq_line(m, '-', 40-namelen, namelen);
85293
85294 - snprintf(ip, sizeof(ip), "[<%p>]",
85295 + snprintf(ip, sizeof(ip), "[<%pK>]",
85296 (void *)class->contending_point[i]);
85297 seq_printf(m, "%40s %14lu %29s %pS\n",
85298 name, stats->contending_point[i],
85299 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
85300 index 7e3443f..b2a1e6b 100644
85301 --- a/kernel/locking/mutex-debug.c
85302 +++ b/kernel/locking/mutex-debug.c
85303 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
85304 }
85305
85306 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85307 - struct thread_info *ti)
85308 + struct task_struct *task)
85309 {
85310 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
85311
85312 /* Mark the current thread as blocked on the lock: */
85313 - ti->task->blocked_on = waiter;
85314 + task->blocked_on = waiter;
85315 }
85316
85317 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85318 - struct thread_info *ti)
85319 + struct task_struct *task)
85320 {
85321 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
85322 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
85323 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
85324 - ti->task->blocked_on = NULL;
85325 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
85326 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
85327 + task->blocked_on = NULL;
85328
85329 list_del_init(&waiter->list);
85330 waiter->task = NULL;
85331 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
85332 index 0799fd3..d06ae3b 100644
85333 --- a/kernel/locking/mutex-debug.h
85334 +++ b/kernel/locking/mutex-debug.h
85335 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
85336 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
85337 extern void debug_mutex_add_waiter(struct mutex *lock,
85338 struct mutex_waiter *waiter,
85339 - struct thread_info *ti);
85340 + struct task_struct *task);
85341 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85342 - struct thread_info *ti);
85343 + struct task_struct *task);
85344 extern void debug_mutex_unlock(struct mutex *lock);
85345 extern void debug_mutex_init(struct mutex *lock, const char *name,
85346 struct lock_class_key *key);
85347 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
85348 index 4dd6e4c..df52693 100644
85349 --- a/kernel/locking/mutex.c
85350 +++ b/kernel/locking/mutex.c
85351 @@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
85352 node->locked = 1;
85353 return;
85354 }
85355 - ACCESS_ONCE(prev->next) = node;
85356 + ACCESS_ONCE_RW(prev->next) = node;
85357 smp_wmb();
85358 /* Wait until the lock holder passes the lock down */
85359 while (!ACCESS_ONCE(node->locked))
85360 @@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
85361 while (!(next = ACCESS_ONCE(node->next)))
85362 arch_mutex_cpu_relax();
85363 }
85364 - ACCESS_ONCE(next->locked) = 1;
85365 + ACCESS_ONCE_RW(next->locked) = 1;
85366 smp_wmb();
85367 }
85368
85369 @@ -520,7 +520,7 @@ slowpath:
85370 goto skip_wait;
85371
85372 debug_mutex_lock_common(lock, &waiter);
85373 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
85374 + debug_mutex_add_waiter(lock, &waiter, task);
85375
85376 /* add waiting tasks to the end of the waitqueue (FIFO): */
85377 list_add_tail(&waiter.list, &lock->wait_list);
85378 @@ -564,7 +564,7 @@ slowpath:
85379 schedule_preempt_disabled();
85380 spin_lock_mutex(&lock->wait_lock, flags);
85381 }
85382 - mutex_remove_waiter(lock, &waiter, current_thread_info());
85383 + mutex_remove_waiter(lock, &waiter, task);
85384 /* set it to 0 if there are no waiters left: */
85385 if (likely(list_empty(&lock->wait_list)))
85386 atomic_set(&lock->count, 0);
85387 @@ -601,7 +601,7 @@ skip_wait:
85388 return 0;
85389
85390 err:
85391 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
85392 + mutex_remove_waiter(lock, &waiter, task);
85393 spin_unlock_mutex(&lock->wait_lock, flags);
85394 debug_mutex_free_waiter(&waiter);
85395 mutex_release(&lock->dep_map, 1, ip);
85396 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
85397 index 1d96dd0..994ff19 100644
85398 --- a/kernel/locking/rtmutex-tester.c
85399 +++ b/kernel/locking/rtmutex-tester.c
85400 @@ -22,7 +22,7 @@
85401 #define MAX_RT_TEST_MUTEXES 8
85402
85403 static spinlock_t rttest_lock;
85404 -static atomic_t rttest_event;
85405 +static atomic_unchecked_t rttest_event;
85406
85407 struct test_thread_data {
85408 int opcode;
85409 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85410
85411 case RTTEST_LOCKCONT:
85412 td->mutexes[td->opdata] = 1;
85413 - td->event = atomic_add_return(1, &rttest_event);
85414 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85415 return 0;
85416
85417 case RTTEST_RESET:
85418 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85419 return 0;
85420
85421 case RTTEST_RESETEVENT:
85422 - atomic_set(&rttest_event, 0);
85423 + atomic_set_unchecked(&rttest_event, 0);
85424 return 0;
85425
85426 default:
85427 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85428 return ret;
85429
85430 td->mutexes[id] = 1;
85431 - td->event = atomic_add_return(1, &rttest_event);
85432 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85433 rt_mutex_lock(&mutexes[id]);
85434 - td->event = atomic_add_return(1, &rttest_event);
85435 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85436 td->mutexes[id] = 4;
85437 return 0;
85438
85439 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85440 return ret;
85441
85442 td->mutexes[id] = 1;
85443 - td->event = atomic_add_return(1, &rttest_event);
85444 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85445 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
85446 - td->event = atomic_add_return(1, &rttest_event);
85447 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85448 td->mutexes[id] = ret ? 0 : 4;
85449 return ret ? -EINTR : 0;
85450
85451 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85452 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
85453 return ret;
85454
85455 - td->event = atomic_add_return(1, &rttest_event);
85456 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85457 rt_mutex_unlock(&mutexes[id]);
85458 - td->event = atomic_add_return(1, &rttest_event);
85459 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85460 td->mutexes[id] = 0;
85461 return 0;
85462
85463 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85464 break;
85465
85466 td->mutexes[dat] = 2;
85467 - td->event = atomic_add_return(1, &rttest_event);
85468 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85469 break;
85470
85471 default:
85472 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85473 return;
85474
85475 td->mutexes[dat] = 3;
85476 - td->event = atomic_add_return(1, &rttest_event);
85477 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85478 break;
85479
85480 case RTTEST_LOCKNOWAIT:
85481 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85482 return;
85483
85484 td->mutexes[dat] = 1;
85485 - td->event = atomic_add_return(1, &rttest_event);
85486 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85487 return;
85488
85489 default:
85490 diff --git a/kernel/module.c b/kernel/module.c
85491 index f5a3b1e..1f5578b 100644
85492 --- a/kernel/module.c
85493 +++ b/kernel/module.c
85494 @@ -61,6 +61,7 @@
85495 #include <linux/pfn.h>
85496 #include <linux/bsearch.h>
85497 #include <linux/fips.h>
85498 +#include <linux/grsecurity.h>
85499 #include <uapi/linux/module.h>
85500 #include "module-internal.h"
85501
85502 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
85503
85504 /* Bounds of module allocation, for speeding __module_address.
85505 * Protected by module_mutex. */
85506 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
85507 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
85508 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
85509
85510 int register_module_notifier(struct notifier_block * nb)
85511 {
85512 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
85513 return true;
85514
85515 list_for_each_entry_rcu(mod, &modules, list) {
85516 - struct symsearch arr[] = {
85517 + struct symsearch modarr[] = {
85518 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
85519 NOT_GPL_ONLY, false },
85520 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
85521 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
85522 if (mod->state == MODULE_STATE_UNFORMED)
85523 continue;
85524
85525 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
85526 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
85527 return true;
85528 }
85529 return false;
85530 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
85531 if (!pcpusec->sh_size)
85532 return 0;
85533
85534 - if (align > PAGE_SIZE) {
85535 + if (align-1 >= PAGE_SIZE) {
85536 pr_warn("%s: per-cpu alignment %li > %li\n",
85537 mod->name, align, PAGE_SIZE);
85538 align = PAGE_SIZE;
85539 @@ -1064,7 +1066,7 @@ struct module_attribute module_uevent =
85540 static ssize_t show_coresize(struct module_attribute *mattr,
85541 struct module_kobject *mk, char *buffer)
85542 {
85543 - return sprintf(buffer, "%u\n", mk->mod->core_size);
85544 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
85545 }
85546
85547 static struct module_attribute modinfo_coresize =
85548 @@ -1073,7 +1075,7 @@ static struct module_attribute modinfo_coresize =
85549 static ssize_t show_initsize(struct module_attribute *mattr,
85550 struct module_kobject *mk, char *buffer)
85551 {
85552 - return sprintf(buffer, "%u\n", mk->mod->init_size);
85553 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
85554 }
85555
85556 static struct module_attribute modinfo_initsize =
85557 @@ -1286,7 +1288,7 @@ resolve_symbol_wait(struct module *mod,
85558 */
85559 #ifdef CONFIG_SYSFS
85560
85561 -#ifdef CONFIG_KALLSYMS
85562 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
85563 static inline bool sect_empty(const Elf_Shdr *sect)
85564 {
85565 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
85566 @@ -1426,7 +1428,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
85567 {
85568 unsigned int notes, loaded, i;
85569 struct module_notes_attrs *notes_attrs;
85570 - struct bin_attribute *nattr;
85571 + bin_attribute_no_const *nattr;
85572
85573 /* failed to create section attributes, so can't create notes */
85574 if (!mod->sect_attrs)
85575 @@ -1538,7 +1540,7 @@ static void del_usage_links(struct module *mod)
85576 static int module_add_modinfo_attrs(struct module *mod)
85577 {
85578 struct module_attribute *attr;
85579 - struct module_attribute *temp_attr;
85580 + module_attribute_no_const *temp_attr;
85581 int error = 0;
85582 int i;
85583
85584 @@ -1759,21 +1761,21 @@ static void set_section_ro_nx(void *base,
85585
85586 static void unset_module_core_ro_nx(struct module *mod)
85587 {
85588 - set_page_attributes(mod->module_core + mod->core_text_size,
85589 - mod->module_core + mod->core_size,
85590 + set_page_attributes(mod->module_core_rw,
85591 + mod->module_core_rw + mod->core_size_rw,
85592 set_memory_x);
85593 - set_page_attributes(mod->module_core,
85594 - mod->module_core + mod->core_ro_size,
85595 + set_page_attributes(mod->module_core_rx,
85596 + mod->module_core_rx + mod->core_size_rx,
85597 set_memory_rw);
85598 }
85599
85600 static void unset_module_init_ro_nx(struct module *mod)
85601 {
85602 - set_page_attributes(mod->module_init + mod->init_text_size,
85603 - mod->module_init + mod->init_size,
85604 + set_page_attributes(mod->module_init_rw,
85605 + mod->module_init_rw + mod->init_size_rw,
85606 set_memory_x);
85607 - set_page_attributes(mod->module_init,
85608 - mod->module_init + mod->init_ro_size,
85609 + set_page_attributes(mod->module_init_rx,
85610 + mod->module_init_rx + mod->init_size_rx,
85611 set_memory_rw);
85612 }
85613
85614 @@ -1786,14 +1788,14 @@ void set_all_modules_text_rw(void)
85615 list_for_each_entry_rcu(mod, &modules, list) {
85616 if (mod->state == MODULE_STATE_UNFORMED)
85617 continue;
85618 - if ((mod->module_core) && (mod->core_text_size)) {
85619 - set_page_attributes(mod->module_core,
85620 - mod->module_core + mod->core_text_size,
85621 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
85622 + set_page_attributes(mod->module_core_rx,
85623 + mod->module_core_rx + mod->core_size_rx,
85624 set_memory_rw);
85625 }
85626 - if ((mod->module_init) && (mod->init_text_size)) {
85627 - set_page_attributes(mod->module_init,
85628 - mod->module_init + mod->init_text_size,
85629 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
85630 + set_page_attributes(mod->module_init_rx,
85631 + mod->module_init_rx + mod->init_size_rx,
85632 set_memory_rw);
85633 }
85634 }
85635 @@ -1809,14 +1811,14 @@ void set_all_modules_text_ro(void)
85636 list_for_each_entry_rcu(mod, &modules, list) {
85637 if (mod->state == MODULE_STATE_UNFORMED)
85638 continue;
85639 - if ((mod->module_core) && (mod->core_text_size)) {
85640 - set_page_attributes(mod->module_core,
85641 - mod->module_core + mod->core_text_size,
85642 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
85643 + set_page_attributes(mod->module_core_rx,
85644 + mod->module_core_rx + mod->core_size_rx,
85645 set_memory_ro);
85646 }
85647 - if ((mod->module_init) && (mod->init_text_size)) {
85648 - set_page_attributes(mod->module_init,
85649 - mod->module_init + mod->init_text_size,
85650 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
85651 + set_page_attributes(mod->module_init_rx,
85652 + mod->module_init_rx + mod->init_size_rx,
85653 set_memory_ro);
85654 }
85655 }
85656 @@ -1867,16 +1869,19 @@ static void free_module(struct module *mod)
85657
85658 /* This may be NULL, but that's OK */
85659 unset_module_init_ro_nx(mod);
85660 - module_free(mod, mod->module_init);
85661 + module_free(mod, mod->module_init_rw);
85662 + module_free_exec(mod, mod->module_init_rx);
85663 kfree(mod->args);
85664 percpu_modfree(mod);
85665
85666 /* Free lock-classes: */
85667 - lockdep_free_key_range(mod->module_core, mod->core_size);
85668 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
85669 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
85670
85671 /* Finally, free the core (containing the module structure) */
85672 unset_module_core_ro_nx(mod);
85673 - module_free(mod, mod->module_core);
85674 + module_free_exec(mod, mod->module_core_rx);
85675 + module_free(mod, mod->module_core_rw);
85676
85677 #ifdef CONFIG_MPU
85678 update_protections(current->mm);
85679 @@ -1945,9 +1950,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85680 int ret = 0;
85681 const struct kernel_symbol *ksym;
85682
85683 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85684 + int is_fs_load = 0;
85685 + int register_filesystem_found = 0;
85686 + char *p;
85687 +
85688 + p = strstr(mod->args, "grsec_modharden_fs");
85689 + if (p) {
85690 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
85691 + /* copy \0 as well */
85692 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
85693 + is_fs_load = 1;
85694 + }
85695 +#endif
85696 +
85697 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
85698 const char *name = info->strtab + sym[i].st_name;
85699
85700 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85701 + /* it's a real shame this will never get ripped and copied
85702 + upstream! ;(
85703 + */
85704 + if (is_fs_load && !strcmp(name, "register_filesystem"))
85705 + register_filesystem_found = 1;
85706 +#endif
85707 +
85708 switch (sym[i].st_shndx) {
85709 case SHN_COMMON:
85710 /* We compiled with -fno-common. These are not
85711 @@ -1968,7 +1995,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85712 ksym = resolve_symbol_wait(mod, info, name);
85713 /* Ok if resolved. */
85714 if (ksym && !IS_ERR(ksym)) {
85715 + pax_open_kernel();
85716 sym[i].st_value = ksym->value;
85717 + pax_close_kernel();
85718 break;
85719 }
85720
85721 @@ -1987,11 +2016,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85722 secbase = (unsigned long)mod_percpu(mod);
85723 else
85724 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
85725 + pax_open_kernel();
85726 sym[i].st_value += secbase;
85727 + pax_close_kernel();
85728 break;
85729 }
85730 }
85731
85732 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85733 + if (is_fs_load && !register_filesystem_found) {
85734 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
85735 + ret = -EPERM;
85736 + }
85737 +#endif
85738 +
85739 return ret;
85740 }
85741
85742 @@ -2075,22 +2113,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
85743 || s->sh_entsize != ~0UL
85744 || strstarts(sname, ".init"))
85745 continue;
85746 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
85747 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
85748 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
85749 + else
85750 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
85751 pr_debug("\t%s\n", sname);
85752 }
85753 - switch (m) {
85754 - case 0: /* executable */
85755 - mod->core_size = debug_align(mod->core_size);
85756 - mod->core_text_size = mod->core_size;
85757 - break;
85758 - case 1: /* RO: text and ro-data */
85759 - mod->core_size = debug_align(mod->core_size);
85760 - mod->core_ro_size = mod->core_size;
85761 - break;
85762 - case 3: /* whole core */
85763 - mod->core_size = debug_align(mod->core_size);
85764 - break;
85765 - }
85766 }
85767
85768 pr_debug("Init section allocation order:\n");
85769 @@ -2104,23 +2132,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
85770 || s->sh_entsize != ~0UL
85771 || !strstarts(sname, ".init"))
85772 continue;
85773 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
85774 - | INIT_OFFSET_MASK);
85775 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
85776 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
85777 + else
85778 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
85779 + s->sh_entsize |= INIT_OFFSET_MASK;
85780 pr_debug("\t%s\n", sname);
85781 }
85782 - switch (m) {
85783 - case 0: /* executable */
85784 - mod->init_size = debug_align(mod->init_size);
85785 - mod->init_text_size = mod->init_size;
85786 - break;
85787 - case 1: /* RO: text and ro-data */
85788 - mod->init_size = debug_align(mod->init_size);
85789 - mod->init_ro_size = mod->init_size;
85790 - break;
85791 - case 3: /* whole init */
85792 - mod->init_size = debug_align(mod->init_size);
85793 - break;
85794 - }
85795 }
85796 }
85797
85798 @@ -2293,7 +2311,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
85799
85800 /* Put symbol section at end of init part of module. */
85801 symsect->sh_flags |= SHF_ALLOC;
85802 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
85803 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
85804 info->index.sym) | INIT_OFFSET_MASK;
85805 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
85806
85807 @@ -2310,13 +2328,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
85808 }
85809
85810 /* Append room for core symbols at end of core part. */
85811 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
85812 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
85813 - mod->core_size += strtab_size;
85814 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
85815 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
85816 + mod->core_size_rx += strtab_size;
85817
85818 /* Put string table section at end of init part of module. */
85819 strsect->sh_flags |= SHF_ALLOC;
85820 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
85821 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
85822 info->index.str) | INIT_OFFSET_MASK;
85823 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
85824 }
85825 @@ -2334,12 +2352,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
85826 /* Make sure we get permanent strtab: don't use info->strtab. */
85827 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
85828
85829 + pax_open_kernel();
85830 +
85831 /* Set types up while we still have access to sections. */
85832 for (i = 0; i < mod->num_symtab; i++)
85833 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
85834
85835 - mod->core_symtab = dst = mod->module_core + info->symoffs;
85836 - mod->core_strtab = s = mod->module_core + info->stroffs;
85837 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
85838 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
85839 src = mod->symtab;
85840 for (ndst = i = 0; i < mod->num_symtab; i++) {
85841 if (i == 0 ||
85842 @@ -2351,6 +2371,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
85843 }
85844 }
85845 mod->core_num_syms = ndst;
85846 +
85847 + pax_close_kernel();
85848 }
85849 #else
85850 static inline void layout_symtab(struct module *mod, struct load_info *info)
85851 @@ -2384,17 +2406,33 @@ void * __weak module_alloc(unsigned long size)
85852 return vmalloc_exec(size);
85853 }
85854
85855 -static void *module_alloc_update_bounds(unsigned long size)
85856 +static void *module_alloc_update_bounds_rw(unsigned long size)
85857 {
85858 void *ret = module_alloc(size);
85859
85860 if (ret) {
85861 mutex_lock(&module_mutex);
85862 /* Update module bounds. */
85863 - if ((unsigned long)ret < module_addr_min)
85864 - module_addr_min = (unsigned long)ret;
85865 - if ((unsigned long)ret + size > module_addr_max)
85866 - module_addr_max = (unsigned long)ret + size;
85867 + if ((unsigned long)ret < module_addr_min_rw)
85868 + module_addr_min_rw = (unsigned long)ret;
85869 + if ((unsigned long)ret + size > module_addr_max_rw)
85870 + module_addr_max_rw = (unsigned long)ret + size;
85871 + mutex_unlock(&module_mutex);
85872 + }
85873 + return ret;
85874 +}
85875 +
85876 +static void *module_alloc_update_bounds_rx(unsigned long size)
85877 +{
85878 + void *ret = module_alloc_exec(size);
85879 +
85880 + if (ret) {
85881 + mutex_lock(&module_mutex);
85882 + /* Update module bounds. */
85883 + if ((unsigned long)ret < module_addr_min_rx)
85884 + module_addr_min_rx = (unsigned long)ret;
85885 + if ((unsigned long)ret + size > module_addr_max_rx)
85886 + module_addr_max_rx = (unsigned long)ret + size;
85887 mutex_unlock(&module_mutex);
85888 }
85889 return ret;
85890 @@ -2667,8 +2705,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
85891 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
85892 {
85893 const char *modmagic = get_modinfo(info, "vermagic");
85894 + const char *license = get_modinfo(info, "license");
85895 int err;
85896
85897 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
85898 + if (!license || !license_is_gpl_compatible(license))
85899 + return -ENOEXEC;
85900 +#endif
85901 +
85902 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
85903 modmagic = NULL;
85904
85905 @@ -2693,7 +2737,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
85906 }
85907
85908 /* Set up license info based on the info section */
85909 - set_license(mod, get_modinfo(info, "license"));
85910 + set_license(mod, license);
85911
85912 return 0;
85913 }
85914 @@ -2787,7 +2831,7 @@ static int move_module(struct module *mod, struct load_info *info)
85915 void *ptr;
85916
85917 /* Do the allocs. */
85918 - ptr = module_alloc_update_bounds(mod->core_size);
85919 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
85920 /*
85921 * The pointer to this block is stored in the module structure
85922 * which is inside the block. Just mark it as not being a
85923 @@ -2797,11 +2841,11 @@ static int move_module(struct module *mod, struct load_info *info)
85924 if (!ptr)
85925 return -ENOMEM;
85926
85927 - memset(ptr, 0, mod->core_size);
85928 - mod->module_core = ptr;
85929 + memset(ptr, 0, mod->core_size_rw);
85930 + mod->module_core_rw = ptr;
85931
85932 - if (mod->init_size) {
85933 - ptr = module_alloc_update_bounds(mod->init_size);
85934 + if (mod->init_size_rw) {
85935 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
85936 /*
85937 * The pointer to this block is stored in the module structure
85938 * which is inside the block. This block doesn't need to be
85939 @@ -2810,13 +2854,45 @@ static int move_module(struct module *mod, struct load_info *info)
85940 */
85941 kmemleak_ignore(ptr);
85942 if (!ptr) {
85943 - module_free(mod, mod->module_core);
85944 + module_free(mod, mod->module_core_rw);
85945 return -ENOMEM;
85946 }
85947 - memset(ptr, 0, mod->init_size);
85948 - mod->module_init = ptr;
85949 + memset(ptr, 0, mod->init_size_rw);
85950 + mod->module_init_rw = ptr;
85951 } else
85952 - mod->module_init = NULL;
85953 + mod->module_init_rw = NULL;
85954 +
85955 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
85956 + kmemleak_not_leak(ptr);
85957 + if (!ptr) {
85958 + if (mod->module_init_rw)
85959 + module_free(mod, mod->module_init_rw);
85960 + module_free(mod, mod->module_core_rw);
85961 + return -ENOMEM;
85962 + }
85963 +
85964 + pax_open_kernel();
85965 + memset(ptr, 0, mod->core_size_rx);
85966 + pax_close_kernel();
85967 + mod->module_core_rx = ptr;
85968 +
85969 + if (mod->init_size_rx) {
85970 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
85971 + kmemleak_ignore(ptr);
85972 + if (!ptr && mod->init_size_rx) {
85973 + module_free_exec(mod, mod->module_core_rx);
85974 + if (mod->module_init_rw)
85975 + module_free(mod, mod->module_init_rw);
85976 + module_free(mod, mod->module_core_rw);
85977 + return -ENOMEM;
85978 + }
85979 +
85980 + pax_open_kernel();
85981 + memset(ptr, 0, mod->init_size_rx);
85982 + pax_close_kernel();
85983 + mod->module_init_rx = ptr;
85984 + } else
85985 + mod->module_init_rx = NULL;
85986
85987 /* Transfer each section which specifies SHF_ALLOC */
85988 pr_debug("final section addresses:\n");
85989 @@ -2827,16 +2903,45 @@ static int move_module(struct module *mod, struct load_info *info)
85990 if (!(shdr->sh_flags & SHF_ALLOC))
85991 continue;
85992
85993 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
85994 - dest = mod->module_init
85995 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
85996 - else
85997 - dest = mod->module_core + shdr->sh_entsize;
85998 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
85999 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
86000 + dest = mod->module_init_rw
86001 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
86002 + else
86003 + dest = mod->module_init_rx
86004 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
86005 + } else {
86006 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
86007 + dest = mod->module_core_rw + shdr->sh_entsize;
86008 + else
86009 + dest = mod->module_core_rx + shdr->sh_entsize;
86010 + }
86011 +
86012 + if (shdr->sh_type != SHT_NOBITS) {
86013 +
86014 +#ifdef CONFIG_PAX_KERNEXEC
86015 +#ifdef CONFIG_X86_64
86016 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
86017 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
86018 +#endif
86019 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
86020 + pax_open_kernel();
86021 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
86022 + pax_close_kernel();
86023 + } else
86024 +#endif
86025
86026 - if (shdr->sh_type != SHT_NOBITS)
86027 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
86028 + }
86029 /* Update sh_addr to point to copy in image. */
86030 - shdr->sh_addr = (unsigned long)dest;
86031 +
86032 +#ifdef CONFIG_PAX_KERNEXEC
86033 + if (shdr->sh_flags & SHF_EXECINSTR)
86034 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
86035 + else
86036 +#endif
86037 +
86038 + shdr->sh_addr = (unsigned long)dest;
86039 pr_debug("\t0x%lx %s\n",
86040 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
86041 }
86042 @@ -2893,12 +2998,12 @@ static void flush_module_icache(const struct module *mod)
86043 * Do it before processing of module parameters, so the module
86044 * can provide parameter accessor functions of its own.
86045 */
86046 - if (mod->module_init)
86047 - flush_icache_range((unsigned long)mod->module_init,
86048 - (unsigned long)mod->module_init
86049 - + mod->init_size);
86050 - flush_icache_range((unsigned long)mod->module_core,
86051 - (unsigned long)mod->module_core + mod->core_size);
86052 + if (mod->module_init_rx)
86053 + flush_icache_range((unsigned long)mod->module_init_rx,
86054 + (unsigned long)mod->module_init_rx
86055 + + mod->init_size_rx);
86056 + flush_icache_range((unsigned long)mod->module_core_rx,
86057 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
86058
86059 set_fs(old_fs);
86060 }
86061 @@ -2955,8 +3060,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
86062 static void module_deallocate(struct module *mod, struct load_info *info)
86063 {
86064 percpu_modfree(mod);
86065 - module_free(mod, mod->module_init);
86066 - module_free(mod, mod->module_core);
86067 + module_free_exec(mod, mod->module_init_rx);
86068 + module_free_exec(mod, mod->module_core_rx);
86069 + module_free(mod, mod->module_init_rw);
86070 + module_free(mod, mod->module_core_rw);
86071 }
86072
86073 int __weak module_finalize(const Elf_Ehdr *hdr,
86074 @@ -2969,7 +3076,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
86075 static int post_relocation(struct module *mod, const struct load_info *info)
86076 {
86077 /* Sort exception table now relocations are done. */
86078 + pax_open_kernel();
86079 sort_extable(mod->extable, mod->extable + mod->num_exentries);
86080 + pax_close_kernel();
86081
86082 /* Copy relocated percpu area over. */
86083 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
86084 @@ -3023,16 +3132,16 @@ static int do_init_module(struct module *mod)
86085 MODULE_STATE_COMING, mod);
86086
86087 /* Set RO and NX regions for core */
86088 - set_section_ro_nx(mod->module_core,
86089 - mod->core_text_size,
86090 - mod->core_ro_size,
86091 - mod->core_size);
86092 + set_section_ro_nx(mod->module_core_rx,
86093 + mod->core_size_rx,
86094 + mod->core_size_rx,
86095 + mod->core_size_rx);
86096
86097 /* Set RO and NX regions for init */
86098 - set_section_ro_nx(mod->module_init,
86099 - mod->init_text_size,
86100 - mod->init_ro_size,
86101 - mod->init_size);
86102 + set_section_ro_nx(mod->module_init_rx,
86103 + mod->init_size_rx,
86104 + mod->init_size_rx,
86105 + mod->init_size_rx);
86106
86107 do_mod_ctors(mod);
86108 /* Start the module */
86109 @@ -3093,11 +3202,12 @@ static int do_init_module(struct module *mod)
86110 mod->strtab = mod->core_strtab;
86111 #endif
86112 unset_module_init_ro_nx(mod);
86113 - module_free(mod, mod->module_init);
86114 - mod->module_init = NULL;
86115 - mod->init_size = 0;
86116 - mod->init_ro_size = 0;
86117 - mod->init_text_size = 0;
86118 + module_free(mod, mod->module_init_rw);
86119 + module_free_exec(mod, mod->module_init_rx);
86120 + mod->module_init_rw = NULL;
86121 + mod->module_init_rx = NULL;
86122 + mod->init_size_rw = 0;
86123 + mod->init_size_rx = 0;
86124 mutex_unlock(&module_mutex);
86125 wake_up_all(&module_wq);
86126
86127 @@ -3240,9 +3350,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
86128 if (err)
86129 goto free_unload;
86130
86131 + /* Now copy in args */
86132 + mod->args = strndup_user(uargs, ~0UL >> 1);
86133 + if (IS_ERR(mod->args)) {
86134 + err = PTR_ERR(mod->args);
86135 + goto free_unload;
86136 + }
86137 +
86138 /* Set up MODINFO_ATTR fields */
86139 setup_modinfo(mod, info);
86140
86141 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86142 + {
86143 + char *p, *p2;
86144 +
86145 + if (strstr(mod->args, "grsec_modharden_netdev")) {
86146 + 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);
86147 + err = -EPERM;
86148 + goto free_modinfo;
86149 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
86150 + p += sizeof("grsec_modharden_normal") - 1;
86151 + p2 = strstr(p, "_");
86152 + if (p2) {
86153 + *p2 = '\0';
86154 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
86155 + *p2 = '_';
86156 + }
86157 + err = -EPERM;
86158 + goto free_modinfo;
86159 + }
86160 + }
86161 +#endif
86162 +
86163 /* Fix up syms, so that st_value is a pointer to location. */
86164 err = simplify_symbols(mod, info);
86165 if (err < 0)
86166 @@ -3258,13 +3397,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
86167
86168 flush_module_icache(mod);
86169
86170 - /* Now copy in args */
86171 - mod->args = strndup_user(uargs, ~0UL >> 1);
86172 - if (IS_ERR(mod->args)) {
86173 - err = PTR_ERR(mod->args);
86174 - goto free_arch_cleanup;
86175 - }
86176 -
86177 dynamic_debug_setup(info->debug, info->num_debug);
86178
86179 /* Finally it's fully formed, ready to start executing. */
86180 @@ -3299,11 +3431,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
86181 ddebug_cleanup:
86182 dynamic_debug_remove(info->debug);
86183 synchronize_sched();
86184 - kfree(mod->args);
86185 - free_arch_cleanup:
86186 module_arch_cleanup(mod);
86187 free_modinfo:
86188 free_modinfo(mod);
86189 + kfree(mod->args);
86190 free_unload:
86191 module_unload_free(mod);
86192 unlink_mod:
86193 @@ -3386,10 +3517,16 @@ static const char *get_ksymbol(struct module *mod,
86194 unsigned long nextval;
86195
86196 /* At worse, next value is at end of module */
86197 - if (within_module_init(addr, mod))
86198 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
86199 + if (within_module_init_rx(addr, mod))
86200 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
86201 + else if (within_module_init_rw(addr, mod))
86202 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
86203 + else if (within_module_core_rx(addr, mod))
86204 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
86205 + else if (within_module_core_rw(addr, mod))
86206 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
86207 else
86208 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
86209 + return NULL;
86210
86211 /* Scan for closest preceding symbol, and next symbol. (ELF
86212 starts real symbols at 1). */
86213 @@ -3640,7 +3777,7 @@ static int m_show(struct seq_file *m, void *p)
86214 return 0;
86215
86216 seq_printf(m, "%s %u",
86217 - mod->name, mod->init_size + mod->core_size);
86218 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
86219 print_unload_info(m, mod);
86220
86221 /* Informative for users. */
86222 @@ -3649,7 +3786,7 @@ static int m_show(struct seq_file *m, void *p)
86223 mod->state == MODULE_STATE_COMING ? "Loading":
86224 "Live");
86225 /* Used by oprofile and other similar tools. */
86226 - seq_printf(m, " 0x%pK", mod->module_core);
86227 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
86228
86229 /* Taints info */
86230 if (mod->taints)
86231 @@ -3685,7 +3822,17 @@ static const struct file_operations proc_modules_operations = {
86232
86233 static int __init proc_modules_init(void)
86234 {
86235 +#ifndef CONFIG_GRKERNSEC_HIDESYM
86236 +#ifdef CONFIG_GRKERNSEC_PROC_USER
86237 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
86238 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
86239 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
86240 +#else
86241 proc_create("modules", 0, NULL, &proc_modules_operations);
86242 +#endif
86243 +#else
86244 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
86245 +#endif
86246 return 0;
86247 }
86248 module_init(proc_modules_init);
86249 @@ -3746,14 +3893,14 @@ struct module *__module_address(unsigned long addr)
86250 {
86251 struct module *mod;
86252
86253 - if (addr < module_addr_min || addr > module_addr_max)
86254 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
86255 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
86256 return NULL;
86257
86258 list_for_each_entry_rcu(mod, &modules, list) {
86259 if (mod->state == MODULE_STATE_UNFORMED)
86260 continue;
86261 - if (within_module_core(addr, mod)
86262 - || within_module_init(addr, mod))
86263 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
86264 return mod;
86265 }
86266 return NULL;
86267 @@ -3788,11 +3935,20 @@ bool is_module_text_address(unsigned long addr)
86268 */
86269 struct module *__module_text_address(unsigned long addr)
86270 {
86271 - struct module *mod = __module_address(addr);
86272 + struct module *mod;
86273 +
86274 +#ifdef CONFIG_X86_32
86275 + addr = ktla_ktva(addr);
86276 +#endif
86277 +
86278 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
86279 + return NULL;
86280 +
86281 + mod = __module_address(addr);
86282 +
86283 if (mod) {
86284 /* Make sure it's within the text section. */
86285 - if (!within(addr, mod->module_init, mod->init_text_size)
86286 - && !within(addr, mod->module_core, mod->core_text_size))
86287 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
86288 mod = NULL;
86289 }
86290 return mod;
86291 diff --git a/kernel/notifier.c b/kernel/notifier.c
86292 index 2d5cc4c..d9ea600 100644
86293 --- a/kernel/notifier.c
86294 +++ b/kernel/notifier.c
86295 @@ -5,6 +5,7 @@
86296 #include <linux/rcupdate.h>
86297 #include <linux/vmalloc.h>
86298 #include <linux/reboot.h>
86299 +#include <linux/mm.h>
86300
86301 /*
86302 * Notifier list for kernel code which wants to be called
86303 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
86304 while ((*nl) != NULL) {
86305 if (n->priority > (*nl)->priority)
86306 break;
86307 - nl = &((*nl)->next);
86308 + nl = (struct notifier_block **)&((*nl)->next);
86309 }
86310 - n->next = *nl;
86311 + pax_open_kernel();
86312 + *(const void **)&n->next = *nl;
86313 rcu_assign_pointer(*nl, n);
86314 + pax_close_kernel();
86315 return 0;
86316 }
86317
86318 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
86319 return 0;
86320 if (n->priority > (*nl)->priority)
86321 break;
86322 - nl = &((*nl)->next);
86323 + nl = (struct notifier_block **)&((*nl)->next);
86324 }
86325 - n->next = *nl;
86326 + pax_open_kernel();
86327 + *(const void **)&n->next = *nl;
86328 rcu_assign_pointer(*nl, n);
86329 + pax_close_kernel();
86330 return 0;
86331 }
86332
86333 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
86334 {
86335 while ((*nl) != NULL) {
86336 if ((*nl) == n) {
86337 + pax_open_kernel();
86338 rcu_assign_pointer(*nl, n->next);
86339 + pax_close_kernel();
86340 return 0;
86341 }
86342 - nl = &((*nl)->next);
86343 + nl = (struct notifier_block **)&((*nl)->next);
86344 }
86345 return -ENOENT;
86346 }
86347 diff --git a/kernel/padata.c b/kernel/padata.c
86348 index 2abd25d..02c4faa 100644
86349 --- a/kernel/padata.c
86350 +++ b/kernel/padata.c
86351 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
86352 * seq_nr mod. number of cpus in use.
86353 */
86354
86355 - seq_nr = atomic_inc_return(&pd->seq_nr);
86356 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
86357 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
86358
86359 return padata_index_to_cpu(pd, cpu_index);
86360 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
86361 padata_init_pqueues(pd);
86362 padata_init_squeues(pd);
86363 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
86364 - atomic_set(&pd->seq_nr, -1);
86365 + atomic_set_unchecked(&pd->seq_nr, -1);
86366 atomic_set(&pd->reorder_objects, 0);
86367 atomic_set(&pd->refcnt, 0);
86368 pd->pinst = pinst;
86369 diff --git a/kernel/panic.c b/kernel/panic.c
86370 index c00b4ce..a846117 100644
86371 --- a/kernel/panic.c
86372 +++ b/kernel/panic.c
86373 @@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
86374 disable_trace_on_warning();
86375
86376 pr_warn("------------[ cut here ]------------\n");
86377 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
86378 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
86379 raw_smp_processor_id(), current->pid, file, line, caller);
86380
86381 if (args)
86382 @@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
86383 */
86384 void __stack_chk_fail(void)
86385 {
86386 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
86387 + dump_stack();
86388 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
86389 __builtin_return_address(0));
86390 }
86391 EXPORT_SYMBOL(__stack_chk_fail);
86392 diff --git a/kernel/pid.c b/kernel/pid.c
86393 index 9b9a266..c20ef80 100644
86394 --- a/kernel/pid.c
86395 +++ b/kernel/pid.c
86396 @@ -33,6 +33,7 @@
86397 #include <linux/rculist.h>
86398 #include <linux/bootmem.h>
86399 #include <linux/hash.h>
86400 +#include <linux/security.h>
86401 #include <linux/pid_namespace.h>
86402 #include <linux/init_task.h>
86403 #include <linux/syscalls.h>
86404 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
86405
86406 int pid_max = PID_MAX_DEFAULT;
86407
86408 -#define RESERVED_PIDS 300
86409 +#define RESERVED_PIDS 500
86410
86411 int pid_max_min = RESERVED_PIDS + 1;
86412 int pid_max_max = PID_MAX_LIMIT;
86413 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
86414 */
86415 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
86416 {
86417 + struct task_struct *task;
86418 +
86419 rcu_lockdep_assert(rcu_read_lock_held(),
86420 "find_task_by_pid_ns() needs rcu_read_lock()"
86421 " protection");
86422 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
86423 +
86424 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
86425 +
86426 + if (gr_pid_is_chrooted(task))
86427 + return NULL;
86428 +
86429 + return task;
86430 }
86431
86432 struct task_struct *find_task_by_vpid(pid_t vnr)
86433 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
86434 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
86435 }
86436
86437 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
86438 +{
86439 + rcu_lockdep_assert(rcu_read_lock_held(),
86440 + "find_task_by_pid_ns() needs rcu_read_lock()"
86441 + " protection");
86442 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
86443 +}
86444 +
86445 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
86446 {
86447 struct pid *pid;
86448 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
86449 index 06c62de..b08cc6c 100644
86450 --- a/kernel/pid_namespace.c
86451 +++ b/kernel/pid_namespace.c
86452 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
86453 void __user *buffer, size_t *lenp, loff_t *ppos)
86454 {
86455 struct pid_namespace *pid_ns = task_active_pid_ns(current);
86456 - struct ctl_table tmp = *table;
86457 + ctl_table_no_const tmp = *table;
86458
86459 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
86460 return -EPERM;
86461 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
86462 index c7f31aa..2b44977 100644
86463 --- a/kernel/posix-cpu-timers.c
86464 +++ b/kernel/posix-cpu-timers.c
86465 @@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
86466
86467 static __init int init_posix_cpu_timers(void)
86468 {
86469 - struct k_clock process = {
86470 + static struct k_clock process = {
86471 .clock_getres = process_cpu_clock_getres,
86472 .clock_get = process_cpu_clock_get,
86473 .timer_create = process_cpu_timer_create,
86474 .nsleep = process_cpu_nsleep,
86475 .nsleep_restart = process_cpu_nsleep_restart,
86476 };
86477 - struct k_clock thread = {
86478 + static struct k_clock thread = {
86479 .clock_getres = thread_cpu_clock_getres,
86480 .clock_get = thread_cpu_clock_get,
86481 .timer_create = thread_cpu_timer_create,
86482 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
86483 index 424c2d4..679242f 100644
86484 --- a/kernel/posix-timers.c
86485 +++ b/kernel/posix-timers.c
86486 @@ -43,6 +43,7 @@
86487 #include <linux/hash.h>
86488 #include <linux/posix-clock.h>
86489 #include <linux/posix-timers.h>
86490 +#include <linux/grsecurity.h>
86491 #include <linux/syscalls.h>
86492 #include <linux/wait.h>
86493 #include <linux/workqueue.h>
86494 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
86495 * which we beg off on and pass to do_sys_settimeofday().
86496 */
86497
86498 -static struct k_clock posix_clocks[MAX_CLOCKS];
86499 +static struct k_clock *posix_clocks[MAX_CLOCKS];
86500
86501 /*
86502 * These ones are defined below.
86503 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
86504 */
86505 static __init int init_posix_timers(void)
86506 {
86507 - struct k_clock clock_realtime = {
86508 + static struct k_clock clock_realtime = {
86509 .clock_getres = hrtimer_get_res,
86510 .clock_get = posix_clock_realtime_get,
86511 .clock_set = posix_clock_realtime_set,
86512 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
86513 .timer_get = common_timer_get,
86514 .timer_del = common_timer_del,
86515 };
86516 - struct k_clock clock_monotonic = {
86517 + static struct k_clock clock_monotonic = {
86518 .clock_getres = hrtimer_get_res,
86519 .clock_get = posix_ktime_get_ts,
86520 .nsleep = common_nsleep,
86521 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
86522 .timer_get = common_timer_get,
86523 .timer_del = common_timer_del,
86524 };
86525 - struct k_clock clock_monotonic_raw = {
86526 + static struct k_clock clock_monotonic_raw = {
86527 .clock_getres = hrtimer_get_res,
86528 .clock_get = posix_get_monotonic_raw,
86529 };
86530 - struct k_clock clock_realtime_coarse = {
86531 + static struct k_clock clock_realtime_coarse = {
86532 .clock_getres = posix_get_coarse_res,
86533 .clock_get = posix_get_realtime_coarse,
86534 };
86535 - struct k_clock clock_monotonic_coarse = {
86536 + static struct k_clock clock_monotonic_coarse = {
86537 .clock_getres = posix_get_coarse_res,
86538 .clock_get = posix_get_monotonic_coarse,
86539 };
86540 - struct k_clock clock_tai = {
86541 + static struct k_clock clock_tai = {
86542 .clock_getres = hrtimer_get_res,
86543 .clock_get = posix_get_tai,
86544 .nsleep = common_nsleep,
86545 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
86546 .timer_get = common_timer_get,
86547 .timer_del = common_timer_del,
86548 };
86549 - struct k_clock clock_boottime = {
86550 + static struct k_clock clock_boottime = {
86551 .clock_getres = hrtimer_get_res,
86552 .clock_get = posix_get_boottime,
86553 .nsleep = common_nsleep,
86554 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
86555 return;
86556 }
86557
86558 - posix_clocks[clock_id] = *new_clock;
86559 + posix_clocks[clock_id] = new_clock;
86560 }
86561 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
86562
86563 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
86564 return (id & CLOCKFD_MASK) == CLOCKFD ?
86565 &clock_posix_dynamic : &clock_posix_cpu;
86566
86567 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
86568 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
86569 return NULL;
86570 - return &posix_clocks[id];
86571 + return posix_clocks[id];
86572 }
86573
86574 static int common_timer_create(struct k_itimer *new_timer)
86575 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
86576 struct k_clock *kc = clockid_to_kclock(which_clock);
86577 struct k_itimer *new_timer;
86578 int error, new_timer_id;
86579 - sigevent_t event;
86580 + sigevent_t event = { };
86581 int it_id_set = IT_ID_NOT_SET;
86582
86583 if (!kc)
86584 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
86585 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
86586 return -EFAULT;
86587
86588 + /* only the CLOCK_REALTIME clock can be set, all other clocks
86589 + have their clock_set fptr set to a nosettime dummy function
86590 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
86591 + call common_clock_set, which calls do_sys_settimeofday, which
86592 + we hook
86593 + */
86594 +
86595 return kc->clock_set(which_clock, &new_tp);
86596 }
86597
86598 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
86599 index 2fac9cc..56fef29 100644
86600 --- a/kernel/power/Kconfig
86601 +++ b/kernel/power/Kconfig
86602 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
86603 config HIBERNATION
86604 bool "Hibernation (aka 'suspend to disk')"
86605 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
86606 + depends on !GRKERNSEC_KMEM
86607 + depends on !PAX_MEMORY_SANITIZE
86608 select HIBERNATE_CALLBACKS
86609 select LZO_COMPRESS
86610 select LZO_DECOMPRESS
86611 diff --git a/kernel/power/process.c b/kernel/power/process.c
86612 index 06ec886..9dba35e 100644
86613 --- a/kernel/power/process.c
86614 +++ b/kernel/power/process.c
86615 @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
86616 unsigned int elapsed_msecs;
86617 bool wakeup = false;
86618 int sleep_usecs = USEC_PER_MSEC;
86619 + bool timedout = false;
86620
86621 do_gettimeofday(&start);
86622
86623 @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
86624
86625 while (true) {
86626 todo = 0;
86627 + if (time_after(jiffies, end_time))
86628 + timedout = true;
86629 read_lock(&tasklist_lock);
86630 do_each_thread(g, p) {
86631 if (p == current || !freeze_task(p))
86632 continue;
86633
86634 - if (!freezer_should_skip(p))
86635 + if (!freezer_should_skip(p)) {
86636 todo++;
86637 + if (timedout) {
86638 + printk(KERN_ERR "Task refusing to freeze:\n");
86639 + sched_show_task(p);
86640 + }
86641 + }
86642 } while_each_thread(g, p);
86643 read_unlock(&tasklist_lock);
86644
86645 @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
86646 todo += wq_busy;
86647 }
86648
86649 - if (!todo || time_after(jiffies, end_time))
86650 + if (!todo || timedout)
86651 break;
86652
86653 if (pm_wakeup_pending()) {
86654 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
86655 index be7c86b..c741464 100644
86656 --- a/kernel/printk/printk.c
86657 +++ b/kernel/printk/printk.c
86658 @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
86659 if (from_file && type != SYSLOG_ACTION_OPEN)
86660 return 0;
86661
86662 +#ifdef CONFIG_GRKERNSEC_DMESG
86663 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
86664 + return -EPERM;
86665 +#endif
86666 +
86667 if (syslog_action_restricted(type)) {
86668 if (capable(CAP_SYSLOG))
86669 return 0;
86670 diff --git a/kernel/profile.c b/kernel/profile.c
86671 index 6631e1e..310c266 100644
86672 --- a/kernel/profile.c
86673 +++ b/kernel/profile.c
86674 @@ -37,7 +37,7 @@ struct profile_hit {
86675 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
86676 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
86677
86678 -static atomic_t *prof_buffer;
86679 +static atomic_unchecked_t *prof_buffer;
86680 static unsigned long prof_len, prof_shift;
86681
86682 int prof_on __read_mostly;
86683 @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
86684 hits[i].pc = 0;
86685 continue;
86686 }
86687 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
86688 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
86689 hits[i].hits = hits[i].pc = 0;
86690 }
86691 }
86692 @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
86693 * Add the current hit(s) and flush the write-queue out
86694 * to the global buffer:
86695 */
86696 - atomic_add(nr_hits, &prof_buffer[pc]);
86697 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
86698 for (i = 0; i < NR_PROFILE_HIT; ++i) {
86699 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
86700 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
86701 hits[i].pc = hits[i].hits = 0;
86702 }
86703 out:
86704 @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
86705 {
86706 unsigned long pc;
86707 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
86708 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
86709 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
86710 }
86711 #endif /* !CONFIG_SMP */
86712
86713 @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
86714 return -EFAULT;
86715 buf++; p++; count--; read++;
86716 }
86717 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
86718 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
86719 if (copy_to_user(buf, (void *)pnt, count))
86720 return -EFAULT;
86721 read += count;
86722 @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
86723 }
86724 #endif
86725 profile_discard_flip_buffers();
86726 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
86727 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
86728 return count;
86729 }
86730
86731 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
86732 index 1f4bcb3..99cf7ab 100644
86733 --- a/kernel/ptrace.c
86734 +++ b/kernel/ptrace.c
86735 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
86736 if (seize)
86737 flags |= PT_SEIZED;
86738 rcu_read_lock();
86739 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
86740 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
86741 flags |= PT_PTRACE_CAP;
86742 rcu_read_unlock();
86743 task->ptrace = flags;
86744 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
86745 break;
86746 return -EIO;
86747 }
86748 - if (copy_to_user(dst, buf, retval))
86749 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
86750 return -EFAULT;
86751 copied += retval;
86752 src += retval;
86753 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
86754 bool seized = child->ptrace & PT_SEIZED;
86755 int ret = -EIO;
86756 siginfo_t siginfo, *si;
86757 - void __user *datavp = (void __user *) data;
86758 + void __user *datavp = (__force void __user *) data;
86759 unsigned long __user *datalp = datavp;
86760 unsigned long flags;
86761
86762 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
86763 goto out;
86764 }
86765
86766 + if (gr_handle_ptrace(child, request)) {
86767 + ret = -EPERM;
86768 + goto out_put_task_struct;
86769 + }
86770 +
86771 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
86772 ret = ptrace_attach(child, request, addr, data);
86773 /*
86774 * Some architectures need to do book-keeping after
86775 * a ptrace attach.
86776 */
86777 - if (!ret)
86778 + if (!ret) {
86779 arch_ptrace_attach(child);
86780 + gr_audit_ptrace(child);
86781 + }
86782 goto out_put_task_struct;
86783 }
86784
86785 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
86786 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
86787 if (copied != sizeof(tmp))
86788 return -EIO;
86789 - return put_user(tmp, (unsigned long __user *)data);
86790 + return put_user(tmp, (__force unsigned long __user *)data);
86791 }
86792
86793 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
86794 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
86795 }
86796
86797 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
86798 - compat_long_t addr, compat_long_t data)
86799 + compat_ulong_t addr, compat_ulong_t data)
86800 {
86801 struct task_struct *child;
86802 long ret;
86803 @@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
86804 goto out;
86805 }
86806
86807 + if (gr_handle_ptrace(child, request)) {
86808 + ret = -EPERM;
86809 + goto out_put_task_struct;
86810 + }
86811 +
86812 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
86813 ret = ptrace_attach(child, request, addr, data);
86814 /*
86815 * Some architectures need to do book-keeping after
86816 * a ptrace attach.
86817 */
86818 - if (!ret)
86819 + if (!ret) {
86820 arch_ptrace_attach(child);
86821 + gr_audit_ptrace(child);
86822 + }
86823 goto out_put_task_struct;
86824 }
86825
86826 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
86827 index 01d5ccb..cdcbee6 100644
86828 --- a/kernel/rcu/srcu.c
86829 +++ b/kernel/rcu/srcu.c
86830 @@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
86831
86832 idx = ACCESS_ONCE(sp->completed) & 0x1;
86833 preempt_disable();
86834 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
86835 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
86836 smp_mb(); /* B */ /* Avoid leaking the critical section. */
86837 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
86838 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
86839 preempt_enable();
86840 return idx;
86841 }
86842 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
86843 index 1254f31..16258dc 100644
86844 --- a/kernel/rcu/tiny.c
86845 +++ b/kernel/rcu/tiny.c
86846 @@ -46,7 +46,7 @@
86847 /* Forward declarations for tiny_plugin.h. */
86848 struct rcu_ctrlblk;
86849 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
86850 -static void rcu_process_callbacks(struct softirq_action *unused);
86851 +static void rcu_process_callbacks(void);
86852 static void __call_rcu(struct rcu_head *head,
86853 void (*func)(struct rcu_head *rcu),
86854 struct rcu_ctrlblk *rcp);
86855 @@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
86856 false));
86857 }
86858
86859 -static void rcu_process_callbacks(struct softirq_action *unused)
86860 +static __latent_entropy void rcu_process_callbacks(void)
86861 {
86862 __rcu_process_callbacks(&rcu_sched_ctrlblk);
86863 __rcu_process_callbacks(&rcu_bh_ctrlblk);
86864 diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
86865 index 3929cd4..421624d 100644
86866 --- a/kernel/rcu/torture.c
86867 +++ b/kernel/rcu/torture.c
86868 @@ -176,12 +176,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
86869 { 0 };
86870 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
86871 { 0 };
86872 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
86873 -static atomic_t n_rcu_torture_alloc;
86874 -static atomic_t n_rcu_torture_alloc_fail;
86875 -static atomic_t n_rcu_torture_free;
86876 -static atomic_t n_rcu_torture_mberror;
86877 -static atomic_t n_rcu_torture_error;
86878 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
86879 +static atomic_unchecked_t n_rcu_torture_alloc;
86880 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
86881 +static atomic_unchecked_t n_rcu_torture_free;
86882 +static atomic_unchecked_t n_rcu_torture_mberror;
86883 +static atomic_unchecked_t n_rcu_torture_error;
86884 static long n_rcu_torture_barrier_error;
86885 static long n_rcu_torture_boost_ktrerror;
86886 static long n_rcu_torture_boost_rterror;
86887 @@ -299,11 +299,11 @@ rcu_torture_alloc(void)
86888
86889 spin_lock_bh(&rcu_torture_lock);
86890 if (list_empty(&rcu_torture_freelist)) {
86891 - atomic_inc(&n_rcu_torture_alloc_fail);
86892 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
86893 spin_unlock_bh(&rcu_torture_lock);
86894 return NULL;
86895 }
86896 - atomic_inc(&n_rcu_torture_alloc);
86897 + atomic_inc_unchecked(&n_rcu_torture_alloc);
86898 p = rcu_torture_freelist.next;
86899 list_del_init(p);
86900 spin_unlock_bh(&rcu_torture_lock);
86901 @@ -316,7 +316,7 @@ rcu_torture_alloc(void)
86902 static void
86903 rcu_torture_free(struct rcu_torture *p)
86904 {
86905 - atomic_inc(&n_rcu_torture_free);
86906 + atomic_inc_unchecked(&n_rcu_torture_free);
86907 spin_lock_bh(&rcu_torture_lock);
86908 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
86909 spin_unlock_bh(&rcu_torture_lock);
86910 @@ -437,7 +437,7 @@ rcu_torture_cb(struct rcu_head *p)
86911 i = rp->rtort_pipe_count;
86912 if (i > RCU_TORTURE_PIPE_LEN)
86913 i = RCU_TORTURE_PIPE_LEN;
86914 - atomic_inc(&rcu_torture_wcount[i]);
86915 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
86916 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
86917 rp->rtort_mbtest = 0;
86918 rcu_torture_free(rp);
86919 @@ -827,7 +827,7 @@ rcu_torture_writer(void *arg)
86920 i = old_rp->rtort_pipe_count;
86921 if (i > RCU_TORTURE_PIPE_LEN)
86922 i = RCU_TORTURE_PIPE_LEN;
86923 - atomic_inc(&rcu_torture_wcount[i]);
86924 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
86925 old_rp->rtort_pipe_count++;
86926 if (gp_normal == gp_exp)
86927 exp = !!(rcu_random(&rand) & 0x80);
86928 @@ -845,7 +845,7 @@ rcu_torture_writer(void *arg)
86929 i = rp->rtort_pipe_count;
86930 if (i > RCU_TORTURE_PIPE_LEN)
86931 i = RCU_TORTURE_PIPE_LEN;
86932 - atomic_inc(&rcu_torture_wcount[i]);
86933 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
86934 if (++rp->rtort_pipe_count >=
86935 RCU_TORTURE_PIPE_LEN) {
86936 rp->rtort_mbtest = 0;
86937 @@ -944,7 +944,7 @@ static void rcu_torture_timer(unsigned long unused)
86938 return;
86939 }
86940 if (p->rtort_mbtest == 0)
86941 - atomic_inc(&n_rcu_torture_mberror);
86942 + atomic_inc_unchecked(&n_rcu_torture_mberror);
86943 spin_lock(&rand_lock);
86944 cur_ops->read_delay(&rand);
86945 n_rcu_torture_timers++;
86946 @@ -1014,7 +1014,7 @@ rcu_torture_reader(void *arg)
86947 continue;
86948 }
86949 if (p->rtort_mbtest == 0)
86950 - atomic_inc(&n_rcu_torture_mberror);
86951 + atomic_inc_unchecked(&n_rcu_torture_mberror);
86952 cur_ops->read_delay(&rand);
86953 preempt_disable();
86954 pipe_count = p->rtort_pipe_count;
86955 @@ -1077,11 +1077,11 @@ rcu_torture_printk(char *page)
86956 rcu_torture_current,
86957 rcu_torture_current_version,
86958 list_empty(&rcu_torture_freelist),
86959 - atomic_read(&n_rcu_torture_alloc),
86960 - atomic_read(&n_rcu_torture_alloc_fail),
86961 - atomic_read(&n_rcu_torture_free));
86962 + atomic_read_unchecked(&n_rcu_torture_alloc),
86963 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
86964 + atomic_read_unchecked(&n_rcu_torture_free));
86965 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
86966 - atomic_read(&n_rcu_torture_mberror),
86967 + atomic_read_unchecked(&n_rcu_torture_mberror),
86968 n_rcu_torture_boost_ktrerror,
86969 n_rcu_torture_boost_rterror);
86970 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
86971 @@ -1100,14 +1100,14 @@ rcu_torture_printk(char *page)
86972 n_barrier_attempts,
86973 n_rcu_torture_barrier_error);
86974 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
86975 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
86976 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
86977 n_rcu_torture_barrier_error != 0 ||
86978 n_rcu_torture_boost_ktrerror != 0 ||
86979 n_rcu_torture_boost_rterror != 0 ||
86980 n_rcu_torture_boost_failure != 0 ||
86981 i > 1) {
86982 cnt += sprintf(&page[cnt], "!!! ");
86983 - atomic_inc(&n_rcu_torture_error);
86984 + atomic_inc_unchecked(&n_rcu_torture_error);
86985 WARN_ON_ONCE(1);
86986 }
86987 cnt += sprintf(&page[cnt], "Reader Pipe: ");
86988 @@ -1121,7 +1121,7 @@ rcu_torture_printk(char *page)
86989 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
86990 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
86991 cnt += sprintf(&page[cnt], " %d",
86992 - atomic_read(&rcu_torture_wcount[i]));
86993 + atomic_read_unchecked(&rcu_torture_wcount[i]));
86994 }
86995 cnt += sprintf(&page[cnt], "\n");
86996 if (cur_ops->stats)
86997 @@ -1836,7 +1836,7 @@ rcu_torture_cleanup(void)
86998
86999 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
87000
87001 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
87002 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
87003 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
87004 else if (n_online_successes != n_online_attempts ||
87005 n_offline_successes != n_offline_attempts)
87006 @@ -1958,18 +1958,18 @@ rcu_torture_init(void)
87007
87008 rcu_torture_current = NULL;
87009 rcu_torture_current_version = 0;
87010 - atomic_set(&n_rcu_torture_alloc, 0);
87011 - atomic_set(&n_rcu_torture_alloc_fail, 0);
87012 - atomic_set(&n_rcu_torture_free, 0);
87013 - atomic_set(&n_rcu_torture_mberror, 0);
87014 - atomic_set(&n_rcu_torture_error, 0);
87015 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
87016 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
87017 + atomic_set_unchecked(&n_rcu_torture_free, 0);
87018 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
87019 + atomic_set_unchecked(&n_rcu_torture_error, 0);
87020 n_rcu_torture_barrier_error = 0;
87021 n_rcu_torture_boost_ktrerror = 0;
87022 n_rcu_torture_boost_rterror = 0;
87023 n_rcu_torture_boost_failure = 0;
87024 n_rcu_torture_boosts = 0;
87025 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
87026 - atomic_set(&rcu_torture_wcount[i], 0);
87027 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
87028 for_each_possible_cpu(cpu) {
87029 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
87030 per_cpu(rcu_torture_count, cpu)[i] = 0;
87031 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
87032 index dd08198..5ccccbe 100644
87033 --- a/kernel/rcu/tree.c
87034 +++ b/kernel/rcu/tree.c
87035 @@ -383,9 +383,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
87036 rcu_prepare_for_idle(smp_processor_id());
87037 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
87038 smp_mb__before_atomic_inc(); /* See above. */
87039 - atomic_inc(&rdtp->dynticks);
87040 + atomic_inc_unchecked(&rdtp->dynticks);
87041 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
87042 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
87043 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
87044
87045 /*
87046 * It is illegal to enter an extended quiescent state while
87047 @@ -502,10 +502,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
87048 int user)
87049 {
87050 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
87051 - atomic_inc(&rdtp->dynticks);
87052 + atomic_inc_unchecked(&rdtp->dynticks);
87053 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
87054 smp_mb__after_atomic_inc(); /* See above. */
87055 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
87056 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
87057 rcu_cleanup_after_idle(smp_processor_id());
87058 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
87059 if (!user && !is_idle_task(current)) {
87060 @@ -625,14 +625,14 @@ void rcu_nmi_enter(void)
87061 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
87062
87063 if (rdtp->dynticks_nmi_nesting == 0 &&
87064 - (atomic_read(&rdtp->dynticks) & 0x1))
87065 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
87066 return;
87067 rdtp->dynticks_nmi_nesting++;
87068 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
87069 - atomic_inc(&rdtp->dynticks);
87070 + atomic_inc_unchecked(&rdtp->dynticks);
87071 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
87072 smp_mb__after_atomic_inc(); /* See above. */
87073 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
87074 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
87075 }
87076
87077 /**
87078 @@ -651,9 +651,9 @@ void rcu_nmi_exit(void)
87079 return;
87080 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
87081 smp_mb__before_atomic_inc(); /* See above. */
87082 - atomic_inc(&rdtp->dynticks);
87083 + atomic_inc_unchecked(&rdtp->dynticks);
87084 smp_mb__after_atomic_inc(); /* Force delay to next write. */
87085 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
87086 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
87087 }
87088
87089 /**
87090 @@ -666,7 +666,7 @@ void rcu_nmi_exit(void)
87091 */
87092 bool notrace __rcu_is_watching(void)
87093 {
87094 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
87095 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
87096 }
87097
87098 /**
87099 @@ -749,7 +749,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
87100 static int dyntick_save_progress_counter(struct rcu_data *rdp,
87101 bool *isidle, unsigned long *maxj)
87102 {
87103 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
87104 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
87105 rcu_sysidle_check_cpu(rdp, isidle, maxj);
87106 return (rdp->dynticks_snap & 0x1) == 0;
87107 }
87108 @@ -766,7 +766,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
87109 unsigned int curr;
87110 unsigned int snap;
87111
87112 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
87113 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
87114 snap = (unsigned int)rdp->dynticks_snap;
87115
87116 /*
87117 @@ -1412,9 +1412,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
87118 rdp = this_cpu_ptr(rsp->rda);
87119 rcu_preempt_check_blocked_tasks(rnp);
87120 rnp->qsmask = rnp->qsmaskinit;
87121 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
87122 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
87123 WARN_ON_ONCE(rnp->completed != rsp->completed);
87124 - ACCESS_ONCE(rnp->completed) = rsp->completed;
87125 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
87126 if (rnp == rdp->mynode)
87127 __note_gp_changes(rsp, rnp, rdp);
87128 rcu_preempt_boost_start_gp(rnp);
87129 @@ -1505,7 +1505,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
87130 */
87131 rcu_for_each_node_breadth_first(rsp, rnp) {
87132 raw_spin_lock_irq(&rnp->lock);
87133 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
87134 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
87135 rdp = this_cpu_ptr(rsp->rda);
87136 if (rnp == rdp->mynode)
87137 __note_gp_changes(rsp, rnp, rdp);
87138 @@ -1865,7 +1865,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
87139 rsp->qlen += rdp->qlen;
87140 rdp->n_cbs_orphaned += rdp->qlen;
87141 rdp->qlen_lazy = 0;
87142 - ACCESS_ONCE(rdp->qlen) = 0;
87143 + ACCESS_ONCE_RW(rdp->qlen) = 0;
87144 }
87145
87146 /*
87147 @@ -2111,7 +2111,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
87148 }
87149 smp_mb(); /* List handling before counting for rcu_barrier(). */
87150 rdp->qlen_lazy -= count_lazy;
87151 - ACCESS_ONCE(rdp->qlen) -= count;
87152 + ACCESS_ONCE_RW(rdp->qlen) -= count;
87153 rdp->n_cbs_invoked += count;
87154
87155 /* Reinstate batch limit if we have worked down the excess. */
87156 @@ -2308,7 +2308,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
87157 /*
87158 * Do RCU core processing for the current CPU.
87159 */
87160 -static void rcu_process_callbacks(struct softirq_action *unused)
87161 +static void rcu_process_callbacks(void)
87162 {
87163 struct rcu_state *rsp;
87164
87165 @@ -2415,7 +2415,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
87166 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
87167 if (debug_rcu_head_queue(head)) {
87168 /* Probable double call_rcu(), so leak the callback. */
87169 - ACCESS_ONCE(head->func) = rcu_leak_callback;
87170 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
87171 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
87172 return;
87173 }
87174 @@ -2443,7 +2443,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
87175 local_irq_restore(flags);
87176 return;
87177 }
87178 - ACCESS_ONCE(rdp->qlen)++;
87179 + ACCESS_ONCE_RW(rdp->qlen)++;
87180 if (lazy)
87181 rdp->qlen_lazy++;
87182 else
87183 @@ -2652,11 +2652,11 @@ void synchronize_sched_expedited(void)
87184 * counter wrap on a 32-bit system. Quite a few more CPUs would of
87185 * course be required on a 64-bit system.
87186 */
87187 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
87188 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
87189 (ulong)atomic_long_read(&rsp->expedited_done) +
87190 ULONG_MAX / 8)) {
87191 synchronize_sched();
87192 - atomic_long_inc(&rsp->expedited_wrap);
87193 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
87194 return;
87195 }
87196
87197 @@ -2664,7 +2664,7 @@ void synchronize_sched_expedited(void)
87198 * Take a ticket. Note that atomic_inc_return() implies a
87199 * full memory barrier.
87200 */
87201 - snap = atomic_long_inc_return(&rsp->expedited_start);
87202 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
87203 firstsnap = snap;
87204 get_online_cpus();
87205 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
87206 @@ -2677,14 +2677,14 @@ void synchronize_sched_expedited(void)
87207 synchronize_sched_expedited_cpu_stop,
87208 NULL) == -EAGAIN) {
87209 put_online_cpus();
87210 - atomic_long_inc(&rsp->expedited_tryfail);
87211 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
87212
87213 /* Check to see if someone else did our work for us. */
87214 s = atomic_long_read(&rsp->expedited_done);
87215 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
87216 /* ensure test happens before caller kfree */
87217 smp_mb__before_atomic_inc(); /* ^^^ */
87218 - atomic_long_inc(&rsp->expedited_workdone1);
87219 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
87220 return;
87221 }
87222
87223 @@ -2693,7 +2693,7 @@ void synchronize_sched_expedited(void)
87224 udelay(trycount * num_online_cpus());
87225 } else {
87226 wait_rcu_gp(call_rcu_sched);
87227 - atomic_long_inc(&rsp->expedited_normal);
87228 + atomic_long_inc_unchecked(&rsp->expedited_normal);
87229 return;
87230 }
87231
87232 @@ -2702,7 +2702,7 @@ void synchronize_sched_expedited(void)
87233 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
87234 /* ensure test happens before caller kfree */
87235 smp_mb__before_atomic_inc(); /* ^^^ */
87236 - atomic_long_inc(&rsp->expedited_workdone2);
87237 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
87238 return;
87239 }
87240
87241 @@ -2714,10 +2714,10 @@ void synchronize_sched_expedited(void)
87242 * period works for us.
87243 */
87244 get_online_cpus();
87245 - snap = atomic_long_read(&rsp->expedited_start);
87246 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
87247 smp_mb(); /* ensure read is before try_stop_cpus(). */
87248 }
87249 - atomic_long_inc(&rsp->expedited_stoppedcpus);
87250 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
87251
87252 /*
87253 * Everyone up to our most recent fetch is covered by our grace
87254 @@ -2726,16 +2726,16 @@ void synchronize_sched_expedited(void)
87255 * than we did already did their update.
87256 */
87257 do {
87258 - atomic_long_inc(&rsp->expedited_done_tries);
87259 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
87260 s = atomic_long_read(&rsp->expedited_done);
87261 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
87262 /* ensure test happens before caller kfree */
87263 smp_mb__before_atomic_inc(); /* ^^^ */
87264 - atomic_long_inc(&rsp->expedited_done_lost);
87265 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
87266 break;
87267 }
87268 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
87269 - atomic_long_inc(&rsp->expedited_done_exit);
87270 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
87271
87272 put_online_cpus();
87273 }
87274 @@ -2931,7 +2931,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
87275 * ACCESS_ONCE() to prevent the compiler from speculating
87276 * the increment to precede the early-exit check.
87277 */
87278 - ACCESS_ONCE(rsp->n_barrier_done)++;
87279 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
87280 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
87281 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
87282 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
87283 @@ -2981,7 +2981,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
87284
87285 /* Increment ->n_barrier_done to prevent duplicate work. */
87286 smp_mb(); /* Keep increment after above mechanism. */
87287 - ACCESS_ONCE(rsp->n_barrier_done)++;
87288 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
87289 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
87290 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
87291 smp_mb(); /* Keep increment before caller's subsequent code. */
87292 @@ -3026,10 +3026,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
87293 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
87294 init_callback_list(rdp);
87295 rdp->qlen_lazy = 0;
87296 - ACCESS_ONCE(rdp->qlen) = 0;
87297 + ACCESS_ONCE_RW(rdp->qlen) = 0;
87298 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
87299 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
87300 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
87301 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
87302 rdp->cpu = cpu;
87303 rdp->rsp = rsp;
87304 rcu_boot_init_nocb_percpu_data(rdp);
87305 @@ -3063,8 +3063,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
87306 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
87307 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
87308 rcu_sysidle_init_percpu_data(rdp->dynticks);
87309 - atomic_set(&rdp->dynticks->dynticks,
87310 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
87311 + atomic_set_unchecked(&rdp->dynticks->dynticks,
87312 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
87313 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
87314
87315 /* Add CPU to rcu_node bitmasks. */
87316 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
87317 index 52be957..365ded3 100644
87318 --- a/kernel/rcu/tree.h
87319 +++ b/kernel/rcu/tree.h
87320 @@ -87,11 +87,11 @@ struct rcu_dynticks {
87321 long long dynticks_nesting; /* Track irq/process nesting level. */
87322 /* Process level is worth LLONG_MAX/2. */
87323 int dynticks_nmi_nesting; /* Track NMI nesting level. */
87324 - atomic_t dynticks; /* Even value for idle, else odd. */
87325 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
87326 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
87327 long long dynticks_idle_nesting;
87328 /* irq/process nesting level from idle. */
87329 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
87330 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
87331 /* "Idle" excludes userspace execution. */
87332 unsigned long dynticks_idle_jiffies;
87333 /* End of last non-NMI non-idle period. */
87334 @@ -429,17 +429,17 @@ struct rcu_state {
87335 /* _rcu_barrier(). */
87336 /* End of fields guarded by barrier_mutex. */
87337
87338 - atomic_long_t expedited_start; /* Starting ticket. */
87339 - atomic_long_t expedited_done; /* Done ticket. */
87340 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
87341 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
87342 - atomic_long_t expedited_workdone1; /* # done by others #1. */
87343 - atomic_long_t expedited_workdone2; /* # done by others #2. */
87344 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
87345 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
87346 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
87347 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
87348 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
87349 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
87350 + atomic_long_t expedited_done; /* Done ticket. */
87351 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
87352 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
87353 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
87354 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
87355 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
87356 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
87357 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
87358 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
87359 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
87360
87361 unsigned long jiffies_force_qs; /* Time at which to invoke */
87362 /* force_quiescent_state(). */
87363 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
87364 index 08a7652..3598c7e 100644
87365 --- a/kernel/rcu/tree_plugin.h
87366 +++ b/kernel/rcu/tree_plugin.h
87367 @@ -749,7 +749,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
87368 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
87369 {
87370 return !rcu_preempted_readers_exp(rnp) &&
87371 - ACCESS_ONCE(rnp->expmask) == 0;
87372 + ACCESS_ONCE_RW(rnp->expmask) == 0;
87373 }
87374
87375 /*
87376 @@ -905,7 +905,7 @@ void synchronize_rcu_expedited(void)
87377
87378 /* Clean up and exit. */
87379 smp_mb(); /* ensure expedited GP seen before counter increment. */
87380 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
87381 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
87382 unlock_mb_ret:
87383 mutex_unlock(&sync_rcu_preempt_exp_mutex);
87384 mb_ret:
87385 @@ -1479,7 +1479,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
87386 free_cpumask_var(cm);
87387 }
87388
87389 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
87390 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
87391 .store = &rcu_cpu_kthread_task,
87392 .thread_should_run = rcu_cpu_kthread_should_run,
87393 .thread_fn = rcu_cpu_kthread,
87394 @@ -1946,7 +1946,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
87395 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
87396 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
87397 cpu, ticks_value, ticks_title,
87398 - atomic_read(&rdtp->dynticks) & 0xfff,
87399 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
87400 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
87401 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
87402 fast_no_hz);
87403 @@ -2109,7 +2109,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
87404
87405 /* Enqueue the callback on the nocb list and update counts. */
87406 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
87407 - ACCESS_ONCE(*old_rhpp) = rhp;
87408 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
87409 atomic_long_add(rhcount, &rdp->nocb_q_count);
87410 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
87411
87412 @@ -2272,12 +2272,12 @@ static int rcu_nocb_kthread(void *arg)
87413 * Extract queued callbacks, update counts, and wait
87414 * for a grace period to elapse.
87415 */
87416 - ACCESS_ONCE(rdp->nocb_head) = NULL;
87417 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
87418 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
87419 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
87420 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
87421 - ACCESS_ONCE(rdp->nocb_p_count) += c;
87422 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
87423 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
87424 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
87425 rcu_nocb_wait_gp(rdp);
87426
87427 /* Each pass through the following loop invokes a callback. */
87428 @@ -2303,8 +2303,8 @@ static int rcu_nocb_kthread(void *arg)
87429 list = next;
87430 }
87431 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
87432 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
87433 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
87434 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
87435 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
87436 rdp->n_nocbs_invoked += c;
87437 }
87438 return 0;
87439 @@ -2331,7 +2331,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
87440 t = kthread_run(rcu_nocb_kthread, rdp,
87441 "rcuo%c/%d", rsp->abbr, cpu);
87442 BUG_ON(IS_ERR(t));
87443 - ACCESS_ONCE(rdp->nocb_kthread) = t;
87444 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
87445 }
87446 }
87447
87448 @@ -2457,11 +2457,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
87449
87450 /* Record start of fully idle period. */
87451 j = jiffies;
87452 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
87453 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
87454 smp_mb__before_atomic_inc();
87455 - atomic_inc(&rdtp->dynticks_idle);
87456 + atomic_inc_unchecked(&rdtp->dynticks_idle);
87457 smp_mb__after_atomic_inc();
87458 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
87459 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
87460 }
87461
87462 /*
87463 @@ -2526,9 +2526,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
87464
87465 /* Record end of idle period. */
87466 smp_mb__before_atomic_inc();
87467 - atomic_inc(&rdtp->dynticks_idle);
87468 + atomic_inc_unchecked(&rdtp->dynticks_idle);
87469 smp_mb__after_atomic_inc();
87470 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
87471 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
87472
87473 /*
87474 * If we are the timekeeping CPU, we are permitted to be non-idle
87475 @@ -2569,7 +2569,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
87476 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
87477
87478 /* Pick up current idle and NMI-nesting counter and check. */
87479 - cur = atomic_read(&rdtp->dynticks_idle);
87480 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
87481 if (cur & 0x1) {
87482 *isidle = false; /* We are not idle! */
87483 return;
87484 @@ -2632,7 +2632,7 @@ static void rcu_sysidle(unsigned long j)
87485 case RCU_SYSIDLE_NOT:
87486
87487 /* First time all are idle, so note a short idle period. */
87488 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
87489 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
87490 break;
87491
87492 case RCU_SYSIDLE_SHORT:
87493 @@ -2669,7 +2669,7 @@ static void rcu_sysidle(unsigned long j)
87494 static void rcu_sysidle_cancel(void)
87495 {
87496 smp_mb();
87497 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
87498 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
87499 }
87500
87501 /*
87502 @@ -2717,7 +2717,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
87503 smp_mb(); /* grace period precedes setting inuse. */
87504
87505 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
87506 - ACCESS_ONCE(rshp->inuse) = 0;
87507 + ACCESS_ONCE_RW(rshp->inuse) = 0;
87508 }
87509
87510 /*
87511 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
87512 index 3596797..f78391c 100644
87513 --- a/kernel/rcu/tree_trace.c
87514 +++ b/kernel/rcu/tree_trace.c
87515 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
87516 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
87517 rdp->passed_quiesce, rdp->qs_pending);
87518 seq_printf(m, " dt=%d/%llx/%d df=%lu",
87519 - atomic_read(&rdp->dynticks->dynticks),
87520 + atomic_read_unchecked(&rdp->dynticks->dynticks),
87521 rdp->dynticks->dynticks_nesting,
87522 rdp->dynticks->dynticks_nmi_nesting,
87523 rdp->dynticks_fqs);
87524 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
87525 struct rcu_state *rsp = (struct rcu_state *)m->private;
87526
87527 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",
87528 - atomic_long_read(&rsp->expedited_start),
87529 + atomic_long_read_unchecked(&rsp->expedited_start),
87530 atomic_long_read(&rsp->expedited_done),
87531 - atomic_long_read(&rsp->expedited_wrap),
87532 - atomic_long_read(&rsp->expedited_tryfail),
87533 - atomic_long_read(&rsp->expedited_workdone1),
87534 - atomic_long_read(&rsp->expedited_workdone2),
87535 - atomic_long_read(&rsp->expedited_normal),
87536 - atomic_long_read(&rsp->expedited_stoppedcpus),
87537 - atomic_long_read(&rsp->expedited_done_tries),
87538 - atomic_long_read(&rsp->expedited_done_lost),
87539 - atomic_long_read(&rsp->expedited_done_exit));
87540 + atomic_long_read_unchecked(&rsp->expedited_wrap),
87541 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
87542 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
87543 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
87544 + atomic_long_read_unchecked(&rsp->expedited_normal),
87545 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
87546 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
87547 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
87548 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
87549 return 0;
87550 }
87551
87552 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
87553 index 6cb3dff..dc5710f 100644
87554 --- a/kernel/rcu/update.c
87555 +++ b/kernel/rcu/update.c
87556 @@ -318,10 +318,10 @@ int rcu_jiffies_till_stall_check(void)
87557 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
87558 */
87559 if (till_stall_check < 3) {
87560 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
87561 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
87562 till_stall_check = 3;
87563 } else if (till_stall_check > 300) {
87564 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
87565 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
87566 till_stall_check = 300;
87567 }
87568 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
87569 diff --git a/kernel/resource.c b/kernel/resource.c
87570 index 3f285dc..5755f62 100644
87571 --- a/kernel/resource.c
87572 +++ b/kernel/resource.c
87573 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
87574
87575 static int __init ioresources_init(void)
87576 {
87577 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
87578 +#ifdef CONFIG_GRKERNSEC_PROC_USER
87579 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
87580 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
87581 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87582 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
87583 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
87584 +#endif
87585 +#else
87586 proc_create("ioports", 0, NULL, &proc_ioports_operations);
87587 proc_create("iomem", 0, NULL, &proc_iomem_operations);
87588 +#endif
87589 return 0;
87590 }
87591 __initcall(ioresources_init);
87592 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
87593 index 4a07353..66b5291 100644
87594 --- a/kernel/sched/auto_group.c
87595 +++ b/kernel/sched/auto_group.c
87596 @@ -11,7 +11,7 @@
87597
87598 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
87599 static struct autogroup autogroup_default;
87600 -static atomic_t autogroup_seq_nr;
87601 +static atomic_unchecked_t autogroup_seq_nr;
87602
87603 void __init autogroup_init(struct task_struct *init_task)
87604 {
87605 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
87606
87607 kref_init(&ag->kref);
87608 init_rwsem(&ag->lock);
87609 - ag->id = atomic_inc_return(&autogroup_seq_nr);
87610 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
87611 ag->tg = tg;
87612 #ifdef CONFIG_RT_GROUP_SCHED
87613 /*
87614 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
87615 index a63f4dc..349bbb0 100644
87616 --- a/kernel/sched/completion.c
87617 +++ b/kernel/sched/completion.c
87618 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
87619 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
87620 * or number of jiffies left till timeout) if completed.
87621 */
87622 -long __sched
87623 +long __sched __intentional_overflow(-1)
87624 wait_for_completion_interruptible_timeout(struct completion *x,
87625 unsigned long timeout)
87626 {
87627 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
87628 *
87629 * Return: -ERESTARTSYS if interrupted, 0 if completed.
87630 */
87631 -int __sched wait_for_completion_killable(struct completion *x)
87632 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
87633 {
87634 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
87635 if (t == -ERESTARTSYS)
87636 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
87637 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
87638 * or number of jiffies left till timeout) if completed.
87639 */
87640 -long __sched
87641 +long __sched __intentional_overflow(-1)
87642 wait_for_completion_killable_timeout(struct completion *x,
87643 unsigned long timeout)
87644 {
87645 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
87646 index a88f4a4..9d57ac9 100644
87647 --- a/kernel/sched/core.c
87648 +++ b/kernel/sched/core.c
87649 @@ -2871,6 +2871,8 @@ int can_nice(const struct task_struct *p, const int nice)
87650 /* convert nice value [19,-20] to rlimit style value [1,40] */
87651 int nice_rlim = 20 - nice;
87652
87653 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
87654 +
87655 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
87656 capable(CAP_SYS_NICE));
87657 }
87658 @@ -2904,7 +2906,8 @@ SYSCALL_DEFINE1(nice, int, increment)
87659 if (nice > 19)
87660 nice = 19;
87661
87662 - if (increment < 0 && !can_nice(current, nice))
87663 + if (increment < 0 && (!can_nice(current, nice) ||
87664 + gr_handle_chroot_nice()))
87665 return -EPERM;
87666
87667 retval = security_task_setnice(current, nice);
87668 @@ -3066,6 +3069,7 @@ recheck:
87669 unsigned long rlim_rtprio =
87670 task_rlimit(p, RLIMIT_RTPRIO);
87671
87672 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
87673 /* can't set/change the rt policy */
87674 if (policy != p->policy && !rlim_rtprio)
87675 return -EPERM;
87676 @@ -4232,7 +4236,7 @@ static void migrate_tasks(unsigned int dead_cpu)
87677
87678 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
87679
87680 -static struct ctl_table sd_ctl_dir[] = {
87681 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
87682 {
87683 .procname = "sched_domain",
87684 .mode = 0555,
87685 @@ -4249,17 +4253,17 @@ static struct ctl_table sd_ctl_root[] = {
87686 {}
87687 };
87688
87689 -static struct ctl_table *sd_alloc_ctl_entry(int n)
87690 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
87691 {
87692 - struct ctl_table *entry =
87693 + ctl_table_no_const *entry =
87694 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
87695
87696 return entry;
87697 }
87698
87699 -static void sd_free_ctl_entry(struct ctl_table **tablep)
87700 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
87701 {
87702 - struct ctl_table *entry;
87703 + ctl_table_no_const *entry;
87704
87705 /*
87706 * In the intermediate directories, both the child directory and
87707 @@ -4267,22 +4271,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
87708 * will always be set. In the lowest directory the names are
87709 * static strings and all have proc handlers.
87710 */
87711 - for (entry = *tablep; entry->mode; entry++) {
87712 - if (entry->child)
87713 - sd_free_ctl_entry(&entry->child);
87714 + for (entry = tablep; entry->mode; entry++) {
87715 + if (entry->child) {
87716 + sd_free_ctl_entry(entry->child);
87717 + pax_open_kernel();
87718 + entry->child = NULL;
87719 + pax_close_kernel();
87720 + }
87721 if (entry->proc_handler == NULL)
87722 kfree(entry->procname);
87723 }
87724
87725 - kfree(*tablep);
87726 - *tablep = NULL;
87727 + kfree(tablep);
87728 }
87729
87730 static int min_load_idx = 0;
87731 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
87732
87733 static void
87734 -set_table_entry(struct ctl_table *entry,
87735 +set_table_entry(ctl_table_no_const *entry,
87736 const char *procname, void *data, int maxlen,
87737 umode_t mode, proc_handler *proc_handler,
87738 bool load_idx)
87739 @@ -4302,7 +4309,7 @@ set_table_entry(struct ctl_table *entry,
87740 static struct ctl_table *
87741 sd_alloc_ctl_domain_table(struct sched_domain *sd)
87742 {
87743 - struct ctl_table *table = sd_alloc_ctl_entry(13);
87744 + ctl_table_no_const *table = sd_alloc_ctl_entry(13);
87745
87746 if (table == NULL)
87747 return NULL;
87748 @@ -4337,9 +4344,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
87749 return table;
87750 }
87751
87752 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
87753 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
87754 {
87755 - struct ctl_table *entry, *table;
87756 + ctl_table_no_const *entry, *table;
87757 struct sched_domain *sd;
87758 int domain_num = 0, i;
87759 char buf[32];
87760 @@ -4366,11 +4373,13 @@ static struct ctl_table_header *sd_sysctl_header;
87761 static void register_sched_domain_sysctl(void)
87762 {
87763 int i, cpu_num = num_possible_cpus();
87764 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
87765 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
87766 char buf[32];
87767
87768 WARN_ON(sd_ctl_dir[0].child);
87769 + pax_open_kernel();
87770 sd_ctl_dir[0].child = entry;
87771 + pax_close_kernel();
87772
87773 if (entry == NULL)
87774 return;
87775 @@ -4393,8 +4402,12 @@ static void unregister_sched_domain_sysctl(void)
87776 if (sd_sysctl_header)
87777 unregister_sysctl_table(sd_sysctl_header);
87778 sd_sysctl_header = NULL;
87779 - if (sd_ctl_dir[0].child)
87780 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
87781 + if (sd_ctl_dir[0].child) {
87782 + sd_free_ctl_entry(sd_ctl_dir[0].child);
87783 + pax_open_kernel();
87784 + sd_ctl_dir[0].child = NULL;
87785 + pax_close_kernel();
87786 + }
87787 }
87788 #else
87789 static void register_sched_domain_sysctl(void)
87790 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
87791 index e64b079..a46bd34 100644
87792 --- a/kernel/sched/fair.c
87793 +++ b/kernel/sched/fair.c
87794 @@ -1652,7 +1652,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
87795
87796 static void reset_ptenuma_scan(struct task_struct *p)
87797 {
87798 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
87799 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
87800 p->mm->numa_scan_offset = 0;
87801 }
87802
87803 @@ -6863,7 +6863,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
87804 * run_rebalance_domains is triggered when needed from the scheduler tick.
87805 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
87806 */
87807 -static void run_rebalance_domains(struct softirq_action *h)
87808 +static __latent_entropy void run_rebalance_domains(void)
87809 {
87810 int this_cpu = smp_processor_id();
87811 struct rq *this_rq = cpu_rq(this_cpu);
87812 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
87813 index 88c85b2..a1dec86 100644
87814 --- a/kernel/sched/sched.h
87815 +++ b/kernel/sched/sched.h
87816 @@ -1035,7 +1035,7 @@ struct sched_class {
87817 #ifdef CONFIG_FAIR_GROUP_SCHED
87818 void (*task_move_group) (struct task_struct *p, int on_rq);
87819 #endif
87820 -};
87821 +} __do_const;
87822
87823 #define sched_class_highest (&stop_sched_class)
87824 #define for_each_class(class) \
87825 diff --git a/kernel/signal.c b/kernel/signal.c
87826 index 940b30e..7fd6041 100644
87827 --- a/kernel/signal.c
87828 +++ b/kernel/signal.c
87829 @@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
87830
87831 int print_fatal_signals __read_mostly;
87832
87833 -static void __user *sig_handler(struct task_struct *t, int sig)
87834 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
87835 {
87836 return t->sighand->action[sig - 1].sa.sa_handler;
87837 }
87838
87839 -static int sig_handler_ignored(void __user *handler, int sig)
87840 +static int sig_handler_ignored(__sighandler_t handler, int sig)
87841 {
87842 /* Is it explicitly or implicitly ignored? */
87843 return handler == SIG_IGN ||
87844 @@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
87845
87846 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
87847 {
87848 - void __user *handler;
87849 + __sighandler_t handler;
87850
87851 handler = sig_handler(t, sig);
87852
87853 @@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
87854 atomic_inc(&user->sigpending);
87855 rcu_read_unlock();
87856
87857 + if (!override_rlimit)
87858 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
87859 +
87860 if (override_rlimit ||
87861 atomic_read(&user->sigpending) <=
87862 task_rlimit(t, RLIMIT_SIGPENDING)) {
87863 @@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
87864
87865 int unhandled_signal(struct task_struct *tsk, int sig)
87866 {
87867 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
87868 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
87869 if (is_global_init(tsk))
87870 return 1;
87871 if (handler != SIG_IGN && handler != SIG_DFL)
87872 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
87873 }
87874 }
87875
87876 + /* allow glibc communication via tgkill to other threads in our
87877 + thread group */
87878 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
87879 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
87880 + && gr_handle_signal(t, sig))
87881 + return -EPERM;
87882 +
87883 return security_task_kill(t, info, sig, 0);
87884 }
87885
87886 @@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
87887 return send_signal(sig, info, p, 1);
87888 }
87889
87890 -static int
87891 +int
87892 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
87893 {
87894 return send_signal(sig, info, t, 0);
87895 @@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
87896 unsigned long int flags;
87897 int ret, blocked, ignored;
87898 struct k_sigaction *action;
87899 + int is_unhandled = 0;
87900
87901 spin_lock_irqsave(&t->sighand->siglock, flags);
87902 action = &t->sighand->action[sig-1];
87903 @@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
87904 }
87905 if (action->sa.sa_handler == SIG_DFL)
87906 t->signal->flags &= ~SIGNAL_UNKILLABLE;
87907 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
87908 + is_unhandled = 1;
87909 ret = specific_send_sig_info(sig, info, t);
87910 spin_unlock_irqrestore(&t->sighand->siglock, flags);
87911
87912 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
87913 + normal operation */
87914 + if (is_unhandled) {
87915 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
87916 + gr_handle_crash(t, sig);
87917 + }
87918 +
87919 return ret;
87920 }
87921
87922 @@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
87923 ret = check_kill_permission(sig, info, p);
87924 rcu_read_unlock();
87925
87926 - if (!ret && sig)
87927 + if (!ret && sig) {
87928 ret = do_send_sig_info(sig, info, p, true);
87929 + if (!ret)
87930 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
87931 + }
87932
87933 return ret;
87934 }
87935 @@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
87936 int error = -ESRCH;
87937
87938 rcu_read_lock();
87939 - p = find_task_by_vpid(pid);
87940 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
87941 + /* allow glibc communication via tgkill to other threads in our
87942 + thread group */
87943 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
87944 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
87945 + p = find_task_by_vpid_unrestricted(pid);
87946 + else
87947 +#endif
87948 + p = find_task_by_vpid(pid);
87949 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
87950 error = check_kill_permission(sig, info, p);
87951 /*
87952 @@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
87953 }
87954 seg = get_fs();
87955 set_fs(KERNEL_DS);
87956 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
87957 - (stack_t __force __user *) &uoss,
87958 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
87959 + (stack_t __force_user *) &uoss,
87960 compat_user_stack_pointer());
87961 set_fs(seg);
87962 if (ret >= 0 && uoss_ptr) {
87963 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
87964 index eb89e18..a4e6792 100644
87965 --- a/kernel/smpboot.c
87966 +++ b/kernel/smpboot.c
87967 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
87968 }
87969 smpboot_unpark_thread(plug_thread, cpu);
87970 }
87971 - list_add(&plug_thread->list, &hotplug_threads);
87972 + pax_list_add(&plug_thread->list, &hotplug_threads);
87973 out:
87974 mutex_unlock(&smpboot_threads_lock);
87975 return ret;
87976 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
87977 {
87978 get_online_cpus();
87979 mutex_lock(&smpboot_threads_lock);
87980 - list_del(&plug_thread->list);
87981 + pax_list_del(&plug_thread->list);
87982 smpboot_destroy_threads(plug_thread);
87983 mutex_unlock(&smpboot_threads_lock);
87984 put_online_cpus();
87985 diff --git a/kernel/softirq.c b/kernel/softirq.c
87986 index 11025cc..bc0e4dc 100644
87987 --- a/kernel/softirq.c
87988 +++ b/kernel/softirq.c
87989 @@ -50,11 +50,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
87990 EXPORT_SYMBOL(irq_stat);
87991 #endif
87992
87993 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
87994 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
87995
87996 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
87997
87998 -char *softirq_to_name[NR_SOFTIRQS] = {
87999 +const char * const softirq_to_name[NR_SOFTIRQS] = {
88000 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
88001 "TASKLET", "SCHED", "HRTIMER", "RCU"
88002 };
88003 @@ -250,7 +250,7 @@ restart:
88004 kstat_incr_softirqs_this_cpu(vec_nr);
88005
88006 trace_softirq_entry(vec_nr);
88007 - h->action(h);
88008 + h->action();
88009 trace_softirq_exit(vec_nr);
88010 if (unlikely(prev_count != preempt_count())) {
88011 printk(KERN_ERR "huh, entered softirq %u %s %p"
88012 @@ -419,7 +419,7 @@ void __raise_softirq_irqoff(unsigned int nr)
88013 or_softirq_pending(1UL << nr);
88014 }
88015
88016 -void open_softirq(int nr, void (*action)(struct softirq_action *))
88017 +void __init open_softirq(int nr, void (*action)(void))
88018 {
88019 softirq_vec[nr].action = action;
88020 }
88021 @@ -475,7 +475,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
88022
88023 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
88024
88025 -static void tasklet_action(struct softirq_action *a)
88026 +static __latent_entropy void tasklet_action(void)
88027 {
88028 struct tasklet_struct *list;
88029
88030 @@ -510,7 +510,7 @@ static void tasklet_action(struct softirq_action *a)
88031 }
88032 }
88033
88034 -static void tasklet_hi_action(struct softirq_action *a)
88035 +static __latent_entropy void tasklet_hi_action(void)
88036 {
88037 struct tasklet_struct *list;
88038
88039 @@ -740,7 +740,7 @@ static struct notifier_block cpu_nfb = {
88040 .notifier_call = cpu_callback
88041 };
88042
88043 -static struct smp_hotplug_thread softirq_threads = {
88044 +static struct smp_hotplug_thread softirq_threads __read_only = {
88045 .store = &ksoftirqd,
88046 .thread_should_run = ksoftirqd_should_run,
88047 .thread_fn = run_ksoftirqd,
88048 diff --git a/kernel/sys.c b/kernel/sys.c
88049 index c723113..46bf922 100644
88050 --- a/kernel/sys.c
88051 +++ b/kernel/sys.c
88052 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
88053 error = -EACCES;
88054 goto out;
88055 }
88056 +
88057 + if (gr_handle_chroot_setpriority(p, niceval)) {
88058 + error = -EACCES;
88059 + goto out;
88060 + }
88061 +
88062 no_nice = security_task_setnice(p, niceval);
88063 if (no_nice) {
88064 error = no_nice;
88065 @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
88066 goto error;
88067 }
88068
88069 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
88070 + goto error;
88071 +
88072 if (rgid != (gid_t) -1 ||
88073 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
88074 new->sgid = new->egid;
88075 @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
88076 old = current_cred();
88077
88078 retval = -EPERM;
88079 +
88080 + if (gr_check_group_change(kgid, kgid, kgid))
88081 + goto error;
88082 +
88083 if (ns_capable(old->user_ns, CAP_SETGID))
88084 new->gid = new->egid = new->sgid = new->fsgid = kgid;
88085 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
88086 @@ -403,7 +416,7 @@ error:
88087 /*
88088 * change the user struct in a credentials set to match the new UID
88089 */
88090 -static int set_user(struct cred *new)
88091 +int set_user(struct cred *new)
88092 {
88093 struct user_struct *new_user;
88094
88095 @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
88096 goto error;
88097 }
88098
88099 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
88100 + goto error;
88101 +
88102 if (!uid_eq(new->uid, old->uid)) {
88103 retval = set_user(new);
88104 if (retval < 0)
88105 @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
88106 old = current_cred();
88107
88108 retval = -EPERM;
88109 +
88110 + if (gr_check_crash_uid(kuid))
88111 + goto error;
88112 + if (gr_check_user_change(kuid, kuid, kuid))
88113 + goto error;
88114 +
88115 if (ns_capable(old->user_ns, CAP_SETUID)) {
88116 new->suid = new->uid = kuid;
88117 if (!uid_eq(kuid, old->uid)) {
88118 @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
88119 goto error;
88120 }
88121
88122 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
88123 + goto error;
88124 +
88125 if (ruid != (uid_t) -1) {
88126 new->uid = kruid;
88127 if (!uid_eq(kruid, old->uid)) {
88128 @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
88129 goto error;
88130 }
88131
88132 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
88133 + goto error;
88134 +
88135 if (rgid != (gid_t) -1)
88136 new->gid = krgid;
88137 if (egid != (gid_t) -1)
88138 @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
88139 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
88140 ns_capable(old->user_ns, CAP_SETUID)) {
88141 if (!uid_eq(kuid, old->fsuid)) {
88142 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
88143 + goto error;
88144 +
88145 new->fsuid = kuid;
88146 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
88147 goto change_okay;
88148 }
88149 }
88150
88151 +error:
88152 abort_creds(new);
88153 return old_fsuid;
88154
88155 @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
88156 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
88157 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
88158 ns_capable(old->user_ns, CAP_SETGID)) {
88159 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
88160 + goto error;
88161 +
88162 if (!gid_eq(kgid, old->fsgid)) {
88163 new->fsgid = kgid;
88164 goto change_okay;
88165 }
88166 }
88167
88168 +error:
88169 abort_creds(new);
88170 return old_fsgid;
88171
88172 @@ -1168,19 +1204,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
88173 return -EFAULT;
88174
88175 down_read(&uts_sem);
88176 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
88177 + error = __copy_to_user(name->sysname, &utsname()->sysname,
88178 __OLD_UTS_LEN);
88179 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
88180 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
88181 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
88182 __OLD_UTS_LEN);
88183 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
88184 - error |= __copy_to_user(&name->release, &utsname()->release,
88185 + error |= __copy_to_user(name->release, &utsname()->release,
88186 __OLD_UTS_LEN);
88187 error |= __put_user(0, name->release + __OLD_UTS_LEN);
88188 - error |= __copy_to_user(&name->version, &utsname()->version,
88189 + error |= __copy_to_user(name->version, &utsname()->version,
88190 __OLD_UTS_LEN);
88191 error |= __put_user(0, name->version + __OLD_UTS_LEN);
88192 - error |= __copy_to_user(&name->machine, &utsname()->machine,
88193 + error |= __copy_to_user(name->machine, &utsname()->machine,
88194 __OLD_UTS_LEN);
88195 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
88196 up_read(&uts_sem);
88197 @@ -1382,6 +1418,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
88198 */
88199 new_rlim->rlim_cur = 1;
88200 }
88201 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
88202 + is changed to a lower value. Since tasks can be created by the same
88203 + user in between this limit change and an execve by this task, force
88204 + a recheck only for this task by setting PF_NPROC_EXCEEDED
88205 + */
88206 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
88207 + tsk->flags |= PF_NPROC_EXCEEDED;
88208 }
88209 if (!retval) {
88210 if (old_rlim)
88211 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
88212 index 34a6047..5665aa7 100644
88213 --- a/kernel/sysctl.c
88214 +++ b/kernel/sysctl.c
88215 @@ -93,7 +93,6 @@
88216
88217
88218 #if defined(CONFIG_SYSCTL)
88219 -
88220 /* External variables not in a header file. */
88221 extern int sysctl_overcommit_memory;
88222 extern int sysctl_overcommit_ratio;
88223 @@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
88224
88225 /* Constants used for minimum and maximum */
88226 #ifdef CONFIG_LOCKUP_DETECTOR
88227 -static int sixty = 60;
88228 +static int sixty __read_only = 60;
88229 #endif
88230
88231 -static int zero;
88232 -static int __maybe_unused one = 1;
88233 -static int __maybe_unused two = 2;
88234 -static int __maybe_unused three = 3;
88235 -static unsigned long one_ul = 1;
88236 -static int one_hundred = 100;
88237 +static int neg_one __read_only = -1;
88238 +static int zero __read_only = 0;
88239 +static int __maybe_unused one __read_only = 1;
88240 +static int __maybe_unused two __read_only = 2;
88241 +static int __maybe_unused three __read_only = 3;
88242 +static unsigned long one_ul __read_only = 1;
88243 +static int one_hundred __read_only = 100;
88244 #ifdef CONFIG_PRINTK
88245 -static int ten_thousand = 10000;
88246 +static int ten_thousand __read_only = 10000;
88247 #endif
88248
88249 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
88250 @@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
88251 void __user *buffer, size_t *lenp, loff_t *ppos);
88252 #endif
88253
88254 -#ifdef CONFIG_PRINTK
88255 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88256 void __user *buffer, size_t *lenp, loff_t *ppos);
88257 -#endif
88258
88259 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
88260 void __user *buffer, size_t *lenp, loff_t *ppos);
88261 @@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
88262
88263 #endif
88264
88265 +extern struct ctl_table grsecurity_table[];
88266 +
88267 static struct ctl_table kern_table[];
88268 static struct ctl_table vm_table[];
88269 static struct ctl_table fs_table[];
88270 @@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
88271 int sysctl_legacy_va_layout;
88272 #endif
88273
88274 +#ifdef CONFIG_PAX_SOFTMODE
88275 +static ctl_table pax_table[] = {
88276 + {
88277 + .procname = "softmode",
88278 + .data = &pax_softmode,
88279 + .maxlen = sizeof(unsigned int),
88280 + .mode = 0600,
88281 + .proc_handler = &proc_dointvec,
88282 + },
88283 +
88284 + { }
88285 +};
88286 +#endif
88287 +
88288 /* The default sysctl tables: */
88289
88290 static struct ctl_table sysctl_base_table[] = {
88291 @@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
88292 #endif
88293
88294 static struct ctl_table kern_table[] = {
88295 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
88296 + {
88297 + .procname = "grsecurity",
88298 + .mode = 0500,
88299 + .child = grsecurity_table,
88300 + },
88301 +#endif
88302 +
88303 +#ifdef CONFIG_PAX_SOFTMODE
88304 + {
88305 + .procname = "pax",
88306 + .mode = 0500,
88307 + .child = pax_table,
88308 + },
88309 +#endif
88310 +
88311 {
88312 .procname = "sched_child_runs_first",
88313 .data = &sysctl_sched_child_runs_first,
88314 @@ -620,7 +650,7 @@ static struct ctl_table kern_table[] = {
88315 .data = &modprobe_path,
88316 .maxlen = KMOD_PATH_LEN,
88317 .mode = 0644,
88318 - .proc_handler = proc_dostring,
88319 + .proc_handler = proc_dostring_modpriv,
88320 },
88321 {
88322 .procname = "modules_disabled",
88323 @@ -787,16 +817,20 @@ static struct ctl_table kern_table[] = {
88324 .extra1 = &zero,
88325 .extra2 = &one,
88326 },
88327 +#endif
88328 {
88329 .procname = "kptr_restrict",
88330 .data = &kptr_restrict,
88331 .maxlen = sizeof(int),
88332 .mode = 0644,
88333 .proc_handler = proc_dointvec_minmax_sysadmin,
88334 +#ifdef CONFIG_GRKERNSEC_HIDESYM
88335 + .extra1 = &two,
88336 +#else
88337 .extra1 = &zero,
88338 +#endif
88339 .extra2 = &two,
88340 },
88341 -#endif
88342 {
88343 .procname = "ngroups_max",
88344 .data = &ngroups_max,
88345 @@ -1039,10 +1073,17 @@ static struct ctl_table kern_table[] = {
88346 */
88347 {
88348 .procname = "perf_event_paranoid",
88349 - .data = &sysctl_perf_event_paranoid,
88350 - .maxlen = sizeof(sysctl_perf_event_paranoid),
88351 + .data = &sysctl_perf_event_legitimately_concerned,
88352 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
88353 .mode = 0644,
88354 - .proc_handler = proc_dointvec,
88355 + /* go ahead, be a hero */
88356 + .proc_handler = proc_dointvec_minmax_sysadmin,
88357 + .extra1 = &neg_one,
88358 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88359 + .extra2 = &three,
88360 +#else
88361 + .extra2 = &two,
88362 +#endif
88363 },
88364 {
88365 .procname = "perf_event_mlock_kb",
88366 @@ -1306,6 +1347,13 @@ static struct ctl_table vm_table[] = {
88367 .proc_handler = proc_dointvec_minmax,
88368 .extra1 = &zero,
88369 },
88370 + {
88371 + .procname = "heap_stack_gap",
88372 + .data = &sysctl_heap_stack_gap,
88373 + .maxlen = sizeof(sysctl_heap_stack_gap),
88374 + .mode = 0644,
88375 + .proc_handler = proc_doulongvec_minmax,
88376 + },
88377 #else
88378 {
88379 .procname = "nr_trim_pages",
88380 @@ -1770,6 +1818,16 @@ int proc_dostring(struct ctl_table *table, int write,
88381 buffer, lenp, ppos);
88382 }
88383
88384 +int proc_dostring_modpriv(struct ctl_table *table, int write,
88385 + void __user *buffer, size_t *lenp, loff_t *ppos)
88386 +{
88387 + if (write && !capable(CAP_SYS_MODULE))
88388 + return -EPERM;
88389 +
88390 + return _proc_do_string(table->data, table->maxlen, write,
88391 + buffer, lenp, ppos);
88392 +}
88393 +
88394 static size_t proc_skip_spaces(char **buf)
88395 {
88396 size_t ret;
88397 @@ -1875,6 +1933,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
88398 len = strlen(tmp);
88399 if (len > *size)
88400 len = *size;
88401 + if (len > sizeof(tmp))
88402 + len = sizeof(tmp);
88403 if (copy_to_user(*buf, tmp, len))
88404 return -EFAULT;
88405 *size -= len;
88406 @@ -2039,7 +2099,7 @@ int proc_dointvec(struct ctl_table *table, int write,
88407 static int proc_taint(struct ctl_table *table, int write,
88408 void __user *buffer, size_t *lenp, loff_t *ppos)
88409 {
88410 - struct ctl_table t;
88411 + ctl_table_no_const t;
88412 unsigned long tmptaint = get_taint();
88413 int err;
88414
88415 @@ -2067,7 +2127,6 @@ static int proc_taint(struct ctl_table *table, int write,
88416 return err;
88417 }
88418
88419 -#ifdef CONFIG_PRINTK
88420 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88421 void __user *buffer, size_t *lenp, loff_t *ppos)
88422 {
88423 @@ -2076,7 +2135,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88424
88425 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
88426 }
88427 -#endif
88428
88429 struct do_proc_dointvec_minmax_conv_param {
88430 int *min;
88431 @@ -2623,6 +2681,12 @@ int proc_dostring(struct ctl_table *table, int write,
88432 return -ENOSYS;
88433 }
88434
88435 +int proc_dostring_modpriv(struct ctl_table *table, int write,
88436 + void __user *buffer, size_t *lenp, loff_t *ppos)
88437 +{
88438 + return -ENOSYS;
88439 +}
88440 +
88441 int proc_dointvec(struct ctl_table *table, int write,
88442 void __user *buffer, size_t *lenp, loff_t *ppos)
88443 {
88444 @@ -2679,5 +2743,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
88445 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
88446 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
88447 EXPORT_SYMBOL(proc_dostring);
88448 +EXPORT_SYMBOL(proc_dostring_modpriv);
88449 EXPORT_SYMBOL(proc_doulongvec_minmax);
88450 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
88451 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
88452 index 13d2f7c..c93d0b0 100644
88453 --- a/kernel/taskstats.c
88454 +++ b/kernel/taskstats.c
88455 @@ -28,9 +28,12 @@
88456 #include <linux/fs.h>
88457 #include <linux/file.h>
88458 #include <linux/pid_namespace.h>
88459 +#include <linux/grsecurity.h>
88460 #include <net/genetlink.h>
88461 #include <linux/atomic.h>
88462
88463 +extern int gr_is_taskstats_denied(int pid);
88464 +
88465 /*
88466 * Maximum length of a cpumask that can be specified in
88467 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
88468 @@ -576,6 +579,9 @@ err:
88469
88470 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
88471 {
88472 + if (gr_is_taskstats_denied(current->pid))
88473 + return -EACCES;
88474 +
88475 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
88476 return cmd_attr_register_cpumask(info);
88477 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
88478 diff --git a/kernel/time.c b/kernel/time.c
88479 index 7c7964c..2a0d412 100644
88480 --- a/kernel/time.c
88481 +++ b/kernel/time.c
88482 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
88483 return error;
88484
88485 if (tz) {
88486 + /* we log in do_settimeofday called below, so don't log twice
88487 + */
88488 + if (!tv)
88489 + gr_log_timechange();
88490 +
88491 sys_tz = *tz;
88492 update_vsyscall_tz();
88493 if (firsttime) {
88494 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
88495 index 88c9c65..7497ebc 100644
88496 --- a/kernel/time/alarmtimer.c
88497 +++ b/kernel/time/alarmtimer.c
88498 @@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
88499 struct platform_device *pdev;
88500 int error = 0;
88501 int i;
88502 - struct k_clock alarm_clock = {
88503 + static struct k_clock alarm_clock = {
88504 .clock_getres = alarm_clock_getres,
88505 .clock_get = alarm_clock_get,
88506 .timer_create = alarm_timer_create,
88507 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
88508 index 87b4f00..b7f77a7 100644
88509 --- a/kernel/time/timekeeping.c
88510 +++ b/kernel/time/timekeeping.c
88511 @@ -15,6 +15,7 @@
88512 #include <linux/init.h>
88513 #include <linux/mm.h>
88514 #include <linux/sched.h>
88515 +#include <linux/grsecurity.h>
88516 #include <linux/syscore_ops.h>
88517 #include <linux/clocksource.h>
88518 #include <linux/jiffies.h>
88519 @@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
88520 if (!timespec_valid_strict(tv))
88521 return -EINVAL;
88522
88523 + gr_log_timechange();
88524 +
88525 raw_spin_lock_irqsave(&timekeeper_lock, flags);
88526 write_seqcount_begin(&timekeeper_seq);
88527
88528 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
88529 index 61ed862..3b52c65 100644
88530 --- a/kernel/time/timer_list.c
88531 +++ b/kernel/time/timer_list.c
88532 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
88533
88534 static void print_name_offset(struct seq_file *m, void *sym)
88535 {
88536 +#ifdef CONFIG_GRKERNSEC_HIDESYM
88537 + SEQ_printf(m, "<%p>", NULL);
88538 +#else
88539 char symname[KSYM_NAME_LEN];
88540
88541 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
88542 SEQ_printf(m, "<%pK>", sym);
88543 else
88544 SEQ_printf(m, "%s", symname);
88545 +#endif
88546 }
88547
88548 static void
88549 @@ -119,7 +123,11 @@ next_one:
88550 static void
88551 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
88552 {
88553 +#ifdef CONFIG_GRKERNSEC_HIDESYM
88554 + SEQ_printf(m, " .base: %p\n", NULL);
88555 +#else
88556 SEQ_printf(m, " .base: %pK\n", base);
88557 +#endif
88558 SEQ_printf(m, " .index: %d\n",
88559 base->index);
88560 SEQ_printf(m, " .resolution: %Lu nsecs\n",
88561 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
88562 {
88563 struct proc_dir_entry *pe;
88564
88565 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
88566 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
88567 +#else
88568 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
88569 +#endif
88570 if (!pe)
88571 return -ENOMEM;
88572 return 0;
88573 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
88574 index 1fb08f2..ca4bb1e 100644
88575 --- a/kernel/time/timer_stats.c
88576 +++ b/kernel/time/timer_stats.c
88577 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
88578 static unsigned long nr_entries;
88579 static struct entry entries[MAX_ENTRIES];
88580
88581 -static atomic_t overflow_count;
88582 +static atomic_unchecked_t overflow_count;
88583
88584 /*
88585 * The entries are in a hash-table, for fast lookup:
88586 @@ -140,7 +140,7 @@ static void reset_entries(void)
88587 nr_entries = 0;
88588 memset(entries, 0, sizeof(entries));
88589 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
88590 - atomic_set(&overflow_count, 0);
88591 + atomic_set_unchecked(&overflow_count, 0);
88592 }
88593
88594 static struct entry *alloc_entry(void)
88595 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
88596 if (likely(entry))
88597 entry->count++;
88598 else
88599 - atomic_inc(&overflow_count);
88600 + atomic_inc_unchecked(&overflow_count);
88601
88602 out_unlock:
88603 raw_spin_unlock_irqrestore(lock, flags);
88604 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
88605
88606 static void print_name_offset(struct seq_file *m, unsigned long addr)
88607 {
88608 +#ifdef CONFIG_GRKERNSEC_HIDESYM
88609 + seq_printf(m, "<%p>", NULL);
88610 +#else
88611 char symname[KSYM_NAME_LEN];
88612
88613 if (lookup_symbol_name(addr, symname) < 0)
88614 - seq_printf(m, "<%p>", (void *)addr);
88615 + seq_printf(m, "<%pK>", (void *)addr);
88616 else
88617 seq_printf(m, "%s", symname);
88618 +#endif
88619 }
88620
88621 static int tstats_show(struct seq_file *m, void *v)
88622 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
88623
88624 seq_puts(m, "Timer Stats Version: v0.3\n");
88625 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
88626 - if (atomic_read(&overflow_count))
88627 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
88628 + if (atomic_read_unchecked(&overflow_count))
88629 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
88630 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
88631
88632 for (i = 0; i < nr_entries; i++) {
88633 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
88634 {
88635 struct proc_dir_entry *pe;
88636
88637 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
88638 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
88639 +#else
88640 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
88641 +#endif
88642 if (!pe)
88643 return -ENOMEM;
88644 return 0;
88645 diff --git a/kernel/timer.c b/kernel/timer.c
88646 index accfd24..e00f0c0 100644
88647 --- a/kernel/timer.c
88648 +++ b/kernel/timer.c
88649 @@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
88650 /*
88651 * This function runs timers and the timer-tq in bottom half context.
88652 */
88653 -static void run_timer_softirq(struct softirq_action *h)
88654 +static __latent_entropy void run_timer_softirq(void)
88655 {
88656 struct tvec_base *base = __this_cpu_read(tvec_bases);
88657
88658 @@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
88659 *
88660 * In all cases the return value is guaranteed to be non-negative.
88661 */
88662 -signed long __sched schedule_timeout(signed long timeout)
88663 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
88664 {
88665 struct timer_list timer;
88666 unsigned long expire;
88667 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
88668 index f785aef..59f1b18 100644
88669 --- a/kernel/trace/blktrace.c
88670 +++ b/kernel/trace/blktrace.c
88671 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
88672 struct blk_trace *bt = filp->private_data;
88673 char buf[16];
88674
88675 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
88676 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
88677
88678 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
88679 }
88680 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
88681 return 1;
88682
88683 bt = buf->chan->private_data;
88684 - atomic_inc(&bt->dropped);
88685 + atomic_inc_unchecked(&bt->dropped);
88686 return 0;
88687 }
88688
88689 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
88690
88691 bt->dir = dir;
88692 bt->dev = dev;
88693 - atomic_set(&bt->dropped, 0);
88694 + atomic_set_unchecked(&bt->dropped, 0);
88695 INIT_LIST_HEAD(&bt->running_list);
88696
88697 ret = -EIO;
88698 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
88699 index 72a0f81..0bbfd090 100644
88700 --- a/kernel/trace/ftrace.c
88701 +++ b/kernel/trace/ftrace.c
88702 @@ -1944,12 +1944,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
88703 if (unlikely(ftrace_disabled))
88704 return 0;
88705
88706 + ret = ftrace_arch_code_modify_prepare();
88707 + FTRACE_WARN_ON(ret);
88708 + if (ret)
88709 + return 0;
88710 +
88711 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
88712 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
88713 if (ret) {
88714 ftrace_bug(ret, ip);
88715 - return 0;
88716 }
88717 - return 1;
88718 + return ret ? 0 : 1;
88719 }
88720
88721 /*
88722 @@ -4119,8 +4124,10 @@ static int ftrace_process_locs(struct module *mod,
88723 if (!count)
88724 return 0;
88725
88726 + pax_open_kernel();
88727 sort(start, count, sizeof(*start),
88728 ftrace_cmp_ips, ftrace_swap_ips);
88729 + pax_close_kernel();
88730
88731 start_pg = ftrace_allocate_pages(count);
88732 if (!start_pg)
88733 @@ -4851,8 +4858,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
88734 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
88735
88736 static int ftrace_graph_active;
88737 -static struct notifier_block ftrace_suspend_notifier;
88738 -
88739 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
88740 {
88741 return 0;
88742 @@ -5003,6 +5008,10 @@ static struct ftrace_ops fgraph_ops __read_mostly = {
88743 FTRACE_OPS_FL_RECURSION_SAFE,
88744 };
88745
88746 +static struct notifier_block ftrace_suspend_notifier = {
88747 + .notifier_call = ftrace_suspend_notifier_call
88748 +};
88749 +
88750 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
88751 trace_func_graph_ent_t entryfunc)
88752 {
88753 @@ -5016,7 +5025,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
88754 goto out;
88755 }
88756
88757 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
88758 register_pm_notifier(&ftrace_suspend_notifier);
88759
88760 ftrace_graph_active++;
88761 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
88762 index cc2f66f..05edd54 100644
88763 --- a/kernel/trace/ring_buffer.c
88764 +++ b/kernel/trace/ring_buffer.c
88765 @@ -352,9 +352,9 @@ struct buffer_data_page {
88766 */
88767 struct buffer_page {
88768 struct list_head list; /* list of buffer pages */
88769 - local_t write; /* index for next write */
88770 + local_unchecked_t write; /* index for next write */
88771 unsigned read; /* index for next read */
88772 - local_t entries; /* entries on this page */
88773 + local_unchecked_t entries; /* entries on this page */
88774 unsigned long real_end; /* real end of data */
88775 struct buffer_data_page *page; /* Actual data page */
88776 };
88777 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
88778 unsigned long last_overrun;
88779 local_t entries_bytes;
88780 local_t entries;
88781 - local_t overrun;
88782 - local_t commit_overrun;
88783 + local_unchecked_t overrun;
88784 + local_unchecked_t commit_overrun;
88785 local_t dropped_events;
88786 local_t committing;
88787 local_t commits;
88788 @@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
88789 *
88790 * We add a counter to the write field to denote this.
88791 */
88792 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
88793 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
88794 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
88795 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
88796
88797 /*
88798 * Just make sure we have seen our old_write and synchronize
88799 @@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
88800 * cmpxchg to only update if an interrupt did not already
88801 * do it for us. If the cmpxchg fails, we don't care.
88802 */
88803 - (void)local_cmpxchg(&next_page->write, old_write, val);
88804 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
88805 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
88806 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
88807
88808 /*
88809 * No need to worry about races with clearing out the commit.
88810 @@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
88811
88812 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
88813 {
88814 - return local_read(&bpage->entries) & RB_WRITE_MASK;
88815 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
88816 }
88817
88818 static inline unsigned long rb_page_write(struct buffer_page *bpage)
88819 {
88820 - return local_read(&bpage->write) & RB_WRITE_MASK;
88821 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
88822 }
88823
88824 static int
88825 @@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
88826 * bytes consumed in ring buffer from here.
88827 * Increment overrun to account for the lost events.
88828 */
88829 - local_add(page_entries, &cpu_buffer->overrun);
88830 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
88831 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
88832 }
88833
88834 @@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
88835 * it is our responsibility to update
88836 * the counters.
88837 */
88838 - local_add(entries, &cpu_buffer->overrun);
88839 + local_add_unchecked(entries, &cpu_buffer->overrun);
88840 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
88841
88842 /*
88843 @@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
88844 if (tail == BUF_PAGE_SIZE)
88845 tail_page->real_end = 0;
88846
88847 - local_sub(length, &tail_page->write);
88848 + local_sub_unchecked(length, &tail_page->write);
88849 return;
88850 }
88851
88852 @@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
88853 rb_event_set_padding(event);
88854
88855 /* Set the write back to the previous setting */
88856 - local_sub(length, &tail_page->write);
88857 + local_sub_unchecked(length, &tail_page->write);
88858 return;
88859 }
88860
88861 @@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
88862
88863 /* Set write to end of buffer */
88864 length = (tail + length) - BUF_PAGE_SIZE;
88865 - local_sub(length, &tail_page->write);
88866 + local_sub_unchecked(length, &tail_page->write);
88867 }
88868
88869 /*
88870 @@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
88871 * about it.
88872 */
88873 if (unlikely(next_page == commit_page)) {
88874 - local_inc(&cpu_buffer->commit_overrun);
88875 + local_inc_unchecked(&cpu_buffer->commit_overrun);
88876 goto out_reset;
88877 }
88878
88879 @@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
88880 cpu_buffer->tail_page) &&
88881 (cpu_buffer->commit_page ==
88882 cpu_buffer->reader_page))) {
88883 - local_inc(&cpu_buffer->commit_overrun);
88884 + local_inc_unchecked(&cpu_buffer->commit_overrun);
88885 goto out_reset;
88886 }
88887 }
88888 @@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
88889 length += RB_LEN_TIME_EXTEND;
88890
88891 tail_page = cpu_buffer->tail_page;
88892 - write = local_add_return(length, &tail_page->write);
88893 + write = local_add_return_unchecked(length, &tail_page->write);
88894
88895 /* set write to only the index of the write */
88896 write &= RB_WRITE_MASK;
88897 @@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
88898 kmemcheck_annotate_bitfield(event, bitfield);
88899 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
88900
88901 - local_inc(&tail_page->entries);
88902 + local_inc_unchecked(&tail_page->entries);
88903
88904 /*
88905 * If this is the first commit on the page, then update
88906 @@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
88907
88908 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
88909 unsigned long write_mask =
88910 - local_read(&bpage->write) & ~RB_WRITE_MASK;
88911 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
88912 unsigned long event_length = rb_event_length(event);
88913 /*
88914 * This is on the tail page. It is possible that
88915 @@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
88916 */
88917 old_index += write_mask;
88918 new_index += write_mask;
88919 - index = local_cmpxchg(&bpage->write, old_index, new_index);
88920 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
88921 if (index == old_index) {
88922 /* update counters */
88923 local_sub(event_length, &cpu_buffer->entries_bytes);
88924 @@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
88925
88926 /* Do the likely case first */
88927 if (likely(bpage->page == (void *)addr)) {
88928 - local_dec(&bpage->entries);
88929 + local_dec_unchecked(&bpage->entries);
88930 return;
88931 }
88932
88933 @@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
88934 start = bpage;
88935 do {
88936 if (bpage->page == (void *)addr) {
88937 - local_dec(&bpage->entries);
88938 + local_dec_unchecked(&bpage->entries);
88939 return;
88940 }
88941 rb_inc_page(cpu_buffer, &bpage);
88942 @@ -3139,7 +3139,7 @@ static inline unsigned long
88943 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
88944 {
88945 return local_read(&cpu_buffer->entries) -
88946 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
88947 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
88948 }
88949
88950 /**
88951 @@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
88952 return 0;
88953
88954 cpu_buffer = buffer->buffers[cpu];
88955 - ret = local_read(&cpu_buffer->overrun);
88956 + ret = local_read_unchecked(&cpu_buffer->overrun);
88957
88958 return ret;
88959 }
88960 @@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
88961 return 0;
88962
88963 cpu_buffer = buffer->buffers[cpu];
88964 - ret = local_read(&cpu_buffer->commit_overrun);
88965 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
88966
88967 return ret;
88968 }
88969 @@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
88970 /* if you care about this being correct, lock the buffer */
88971 for_each_buffer_cpu(buffer, cpu) {
88972 cpu_buffer = buffer->buffers[cpu];
88973 - overruns += local_read(&cpu_buffer->overrun);
88974 + overruns += local_read_unchecked(&cpu_buffer->overrun);
88975 }
88976
88977 return overruns;
88978 @@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
88979 /*
88980 * Reset the reader page to size zero.
88981 */
88982 - local_set(&cpu_buffer->reader_page->write, 0);
88983 - local_set(&cpu_buffer->reader_page->entries, 0);
88984 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
88985 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
88986 local_set(&cpu_buffer->reader_page->page->commit, 0);
88987 cpu_buffer->reader_page->real_end = 0;
88988
88989 @@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
88990 * want to compare with the last_overrun.
88991 */
88992 smp_mb();
88993 - overwrite = local_read(&(cpu_buffer->overrun));
88994 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
88995
88996 /*
88997 * Here's the tricky part.
88998 @@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
88999
89000 cpu_buffer->head_page
89001 = list_entry(cpu_buffer->pages, struct buffer_page, list);
89002 - local_set(&cpu_buffer->head_page->write, 0);
89003 - local_set(&cpu_buffer->head_page->entries, 0);
89004 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
89005 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
89006 local_set(&cpu_buffer->head_page->page->commit, 0);
89007
89008 cpu_buffer->head_page->read = 0;
89009 @@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
89010
89011 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
89012 INIT_LIST_HEAD(&cpu_buffer->new_pages);
89013 - local_set(&cpu_buffer->reader_page->write, 0);
89014 - local_set(&cpu_buffer->reader_page->entries, 0);
89015 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
89016 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
89017 local_set(&cpu_buffer->reader_page->page->commit, 0);
89018 cpu_buffer->reader_page->read = 0;
89019
89020 local_set(&cpu_buffer->entries_bytes, 0);
89021 - local_set(&cpu_buffer->overrun, 0);
89022 - local_set(&cpu_buffer->commit_overrun, 0);
89023 + local_set_unchecked(&cpu_buffer->overrun, 0);
89024 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
89025 local_set(&cpu_buffer->dropped_events, 0);
89026 local_set(&cpu_buffer->entries, 0);
89027 local_set(&cpu_buffer->committing, 0);
89028 @@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
89029 rb_init_page(bpage);
89030 bpage = reader->page;
89031 reader->page = *data_page;
89032 - local_set(&reader->write, 0);
89033 - local_set(&reader->entries, 0);
89034 + local_set_unchecked(&reader->write, 0);
89035 + local_set_unchecked(&reader->entries, 0);
89036 reader->read = 0;
89037 *data_page = bpage;
89038
89039 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
89040 index 9d20cd9..221d816 100644
89041 --- a/kernel/trace/trace.c
89042 +++ b/kernel/trace/trace.c
89043 @@ -3346,7 +3346,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
89044 return 0;
89045 }
89046
89047 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
89048 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
89049 {
89050 /* do nothing if flag is already set */
89051 if (!!(trace_flags & mask) == !!enabled)
89052 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
89053 index ea189e0..a5b48c4 100644
89054 --- a/kernel/trace/trace.h
89055 +++ b/kernel/trace/trace.h
89056 @@ -1040,7 +1040,7 @@ extern const char *__stop___tracepoint_str[];
89057 void trace_printk_init_buffers(void);
89058 void trace_printk_start_comm(void);
89059 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
89060 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
89061 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
89062
89063 /*
89064 * Normal trace_printk() and friends allocates special buffers
89065 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
89066 index 26dc348..8708ca7 100644
89067 --- a/kernel/trace/trace_clock.c
89068 +++ b/kernel/trace/trace_clock.c
89069 @@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
89070 return now;
89071 }
89072
89073 -static atomic64_t trace_counter;
89074 +static atomic64_unchecked_t trace_counter;
89075
89076 /*
89077 * trace_clock_counter(): simply an atomic counter.
89078 @@ -132,5 +132,5 @@ static atomic64_t trace_counter;
89079 */
89080 u64 notrace trace_clock_counter(void)
89081 {
89082 - return atomic64_add_return(1, &trace_counter);
89083 + return atomic64_inc_return_unchecked(&trace_counter);
89084 }
89085 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
89086 index a11800a..3dafde5 100644
89087 --- a/kernel/trace/trace_events.c
89088 +++ b/kernel/trace/trace_events.c
89089 @@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
89090 return 0;
89091 }
89092
89093 -struct ftrace_module_file_ops;
89094 static void __add_event_to_tracers(struct ftrace_event_call *call);
89095
89096 /* Add an additional event_call dynamically */
89097 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
89098 index 0abd9b8..6a663a2 100644
89099 --- a/kernel/trace/trace_mmiotrace.c
89100 +++ b/kernel/trace/trace_mmiotrace.c
89101 @@ -24,7 +24,7 @@ struct header_iter {
89102 static struct trace_array *mmio_trace_array;
89103 static bool overrun_detected;
89104 static unsigned long prev_overruns;
89105 -static atomic_t dropped_count;
89106 +static atomic_unchecked_t dropped_count;
89107
89108 static void mmio_reset_data(struct trace_array *tr)
89109 {
89110 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
89111
89112 static unsigned long count_overruns(struct trace_iterator *iter)
89113 {
89114 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
89115 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
89116 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
89117
89118 if (over > prev_overruns)
89119 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
89120 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
89121 sizeof(*entry), 0, pc);
89122 if (!event) {
89123 - atomic_inc(&dropped_count);
89124 + atomic_inc_unchecked(&dropped_count);
89125 return;
89126 }
89127 entry = ring_buffer_event_data(event);
89128 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
89129 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
89130 sizeof(*entry), 0, pc);
89131 if (!event) {
89132 - atomic_inc(&dropped_count);
89133 + atomic_inc_unchecked(&dropped_count);
89134 return;
89135 }
89136 entry = ring_buffer_event_data(event);
89137 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
89138 index ed32284..884d6c3 100644
89139 --- a/kernel/trace/trace_output.c
89140 +++ b/kernel/trace/trace_output.c
89141 @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
89142
89143 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
89144 if (!IS_ERR(p)) {
89145 - p = mangle_path(s->buffer + s->len, p, "\n");
89146 + p = mangle_path(s->buffer + s->len, p, "\n\\");
89147 if (p) {
89148 s->len = p - s->buffer;
89149 return 1;
89150 @@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
89151 goto out;
89152 }
89153
89154 + pax_open_kernel();
89155 if (event->funcs->trace == NULL)
89156 - event->funcs->trace = trace_nop_print;
89157 + *(void **)&event->funcs->trace = trace_nop_print;
89158 if (event->funcs->raw == NULL)
89159 - event->funcs->raw = trace_nop_print;
89160 + *(void **)&event->funcs->raw = trace_nop_print;
89161 if (event->funcs->hex == NULL)
89162 - event->funcs->hex = trace_nop_print;
89163 + *(void **)&event->funcs->hex = trace_nop_print;
89164 if (event->funcs->binary == NULL)
89165 - event->funcs->binary = trace_nop_print;
89166 + *(void **)&event->funcs->binary = trace_nop_print;
89167 + pax_close_kernel();
89168
89169 key = event->type & (EVENT_HASHSIZE - 1);
89170
89171 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
89172 index b20428c..4845a10 100644
89173 --- a/kernel/trace/trace_stack.c
89174 +++ b/kernel/trace/trace_stack.c
89175 @@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
89176 return;
89177
89178 /* we do not handle interrupt stacks yet */
89179 - if (!object_is_on_stack(stack))
89180 + if (!object_starts_on_stack(stack))
89181 return;
89182
89183 local_irq_save(flags);
89184 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
89185 index 240fb62..583473e 100644
89186 --- a/kernel/user_namespace.c
89187 +++ b/kernel/user_namespace.c
89188 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
89189 !kgid_has_mapping(parent_ns, group))
89190 return -EPERM;
89191
89192 +#ifdef CONFIG_GRKERNSEC
89193 + /*
89194 + * This doesn't really inspire confidence:
89195 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
89196 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
89197 + * Increases kernel attack surface in areas developers
89198 + * previously cared little about ("low importance due
89199 + * to requiring "root" capability")
89200 + * To be removed when this code receives *proper* review
89201 + */
89202 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
89203 + !capable(CAP_SETGID))
89204 + return -EPERM;
89205 +#endif
89206 +
89207 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
89208 if (!ns)
89209 return -ENOMEM;
89210 @@ -866,7 +881,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
89211 if (atomic_read(&current->mm->mm_users) > 1)
89212 return -EINVAL;
89213
89214 - if (current->fs->users != 1)
89215 + if (atomic_read(&current->fs->users) != 1)
89216 return -EINVAL;
89217
89218 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
89219 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
89220 index 4f69f9a..7c6f8f8 100644
89221 --- a/kernel/utsname_sysctl.c
89222 +++ b/kernel/utsname_sysctl.c
89223 @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
89224 static int proc_do_uts_string(ctl_table *table, int write,
89225 void __user *buffer, size_t *lenp, loff_t *ppos)
89226 {
89227 - struct ctl_table uts_table;
89228 + ctl_table_no_const uts_table;
89229 int r;
89230 memcpy(&uts_table, table, sizeof(uts_table));
89231 uts_table.data = get_uts(table, write);
89232 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
89233 index 4431610..4265616 100644
89234 --- a/kernel/watchdog.c
89235 +++ b/kernel/watchdog.c
89236 @@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
89237 static void watchdog_nmi_disable(unsigned int cpu) { return; }
89238 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
89239
89240 -static struct smp_hotplug_thread watchdog_threads = {
89241 +static struct smp_hotplug_thread watchdog_threads __read_only = {
89242 .store = &softlockup_watchdog,
89243 .thread_should_run = watchdog_should_run,
89244 .thread_fn = watchdog,
89245 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
89246 index b010eac..e4bda78 100644
89247 --- a/kernel/workqueue.c
89248 +++ b/kernel/workqueue.c
89249 @@ -4671,7 +4671,7 @@ static void rebind_workers(struct worker_pool *pool)
89250 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
89251 worker_flags |= WORKER_REBOUND;
89252 worker_flags &= ~WORKER_UNBOUND;
89253 - ACCESS_ONCE(worker->flags) = worker_flags;
89254 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
89255 }
89256
89257 spin_unlock_irq(&pool->lock);
89258 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
89259 index db25707..8b16430 100644
89260 --- a/lib/Kconfig.debug
89261 +++ b/lib/Kconfig.debug
89262 @@ -845,7 +845,7 @@ config DEBUG_MUTEXES
89263
89264 config DEBUG_WW_MUTEX_SLOWPATH
89265 bool "Wait/wound mutex debugging: Slowpath testing"
89266 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89267 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89268 select DEBUG_LOCK_ALLOC
89269 select DEBUG_SPINLOCK
89270 select DEBUG_MUTEXES
89271 @@ -858,7 +858,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
89272
89273 config DEBUG_LOCK_ALLOC
89274 bool "Lock debugging: detect incorrect freeing of live locks"
89275 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89276 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89277 select DEBUG_SPINLOCK
89278 select DEBUG_MUTEXES
89279 select LOCKDEP
89280 @@ -872,7 +872,7 @@ config DEBUG_LOCK_ALLOC
89281
89282 config PROVE_LOCKING
89283 bool "Lock debugging: prove locking correctness"
89284 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89285 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89286 select LOCKDEP
89287 select DEBUG_SPINLOCK
89288 select DEBUG_MUTEXES
89289 @@ -923,7 +923,7 @@ config LOCKDEP
89290
89291 config LOCK_STAT
89292 bool "Lock usage statistics"
89293 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89294 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89295 select LOCKDEP
89296 select DEBUG_SPINLOCK
89297 select DEBUG_MUTEXES
89298 @@ -1385,6 +1385,7 @@ config LATENCYTOP
89299 depends on DEBUG_KERNEL
89300 depends on STACKTRACE_SUPPORT
89301 depends on PROC_FS
89302 + depends on !GRKERNSEC_HIDESYM
89303 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
89304 select KALLSYMS
89305 select KALLSYMS_ALL
89306 @@ -1401,7 +1402,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
89307 config DEBUG_STRICT_USER_COPY_CHECKS
89308 bool "Strict user copy size checks"
89309 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
89310 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
89311 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
89312 help
89313 Enabling this option turns a certain set of sanity checks for user
89314 copy operations into compile time failures.
89315 @@ -1520,7 +1521,7 @@ endmenu # runtime tests
89316
89317 config PROVIDE_OHCI1394_DMA_INIT
89318 bool "Remote debugging over FireWire early on boot"
89319 - depends on PCI && X86
89320 + depends on PCI && X86 && !GRKERNSEC
89321 help
89322 If you want to debug problems which hang or crash the kernel early
89323 on boot and the crashing machine has a FireWire port, you can use
89324 @@ -1549,7 +1550,7 @@ config PROVIDE_OHCI1394_DMA_INIT
89325
89326 config FIREWIRE_OHCI_REMOTE_DMA
89327 bool "Remote debugging over FireWire with firewire-ohci"
89328 - depends on FIREWIRE_OHCI
89329 + depends on FIREWIRE_OHCI && !GRKERNSEC
89330 help
89331 This option lets you use the FireWire bus for remote debugging
89332 with help of the firewire-ohci driver. It enables unfiltered
89333 diff --git a/lib/Makefile b/lib/Makefile
89334 index a459c31..3320e82 100644
89335 --- a/lib/Makefile
89336 +++ b/lib/Makefile
89337 @@ -49,7 +49,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
89338 obj-$(CONFIG_BTREE) += btree.o
89339 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
89340 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
89341 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
89342 +obj-y += list_debug.o
89343 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
89344
89345 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
89346 diff --git a/lib/bitmap.c b/lib/bitmap.c
89347 index 06f7e4f..f3cf2b0 100644
89348 --- a/lib/bitmap.c
89349 +++ b/lib/bitmap.c
89350 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
89351 {
89352 int c, old_c, totaldigits, ndigits, nchunks, nbits;
89353 u32 chunk;
89354 - const char __user __force *ubuf = (const char __user __force *)buf;
89355 + const char __user *ubuf = (const char __force_user *)buf;
89356
89357 bitmap_zero(maskp, nmaskbits);
89358
89359 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
89360 {
89361 if (!access_ok(VERIFY_READ, ubuf, ulen))
89362 return -EFAULT;
89363 - return __bitmap_parse((const char __force *)ubuf,
89364 + return __bitmap_parse((const char __force_kernel *)ubuf,
89365 ulen, 1, maskp, nmaskbits);
89366
89367 }
89368 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
89369 {
89370 unsigned a, b;
89371 int c, old_c, totaldigits;
89372 - const char __user __force *ubuf = (const char __user __force *)buf;
89373 + const char __user *ubuf = (const char __force_user *)buf;
89374 int exp_digit, in_range;
89375
89376 totaldigits = c = 0;
89377 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
89378 {
89379 if (!access_ok(VERIFY_READ, ubuf, ulen))
89380 return -EFAULT;
89381 - return __bitmap_parselist((const char __force *)ubuf,
89382 + return __bitmap_parselist((const char __force_kernel *)ubuf,
89383 ulen, 1, maskp, nmaskbits);
89384 }
89385 EXPORT_SYMBOL(bitmap_parselist_user);
89386 diff --git a/lib/bug.c b/lib/bug.c
89387 index 1686034..a9c00c8 100644
89388 --- a/lib/bug.c
89389 +++ b/lib/bug.c
89390 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
89391 return BUG_TRAP_TYPE_NONE;
89392
89393 bug = find_bug(bugaddr);
89394 + if (!bug)
89395 + return BUG_TRAP_TYPE_NONE;
89396
89397 file = NULL;
89398 line = 0;
89399 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
89400 index e0731c3..ad66444 100644
89401 --- a/lib/debugobjects.c
89402 +++ b/lib/debugobjects.c
89403 @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
89404 if (limit > 4)
89405 return;
89406
89407 - is_on_stack = object_is_on_stack(addr);
89408 + is_on_stack = object_starts_on_stack(addr);
89409 if (is_on_stack == onstack)
89410 return;
89411
89412 diff --git a/lib/devres.c b/lib/devres.c
89413 index 8235331..5881053 100644
89414 --- a/lib/devres.c
89415 +++ b/lib/devres.c
89416 @@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
89417 void devm_iounmap(struct device *dev, void __iomem *addr)
89418 {
89419 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
89420 - (void *)addr));
89421 + (void __force *)addr));
89422 iounmap(addr);
89423 }
89424 EXPORT_SYMBOL(devm_iounmap);
89425 @@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
89426 {
89427 ioport_unmap(addr);
89428 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
89429 - devm_ioport_map_match, (void *)addr));
89430 + devm_ioport_map_match, (void __force *)addr));
89431 }
89432 EXPORT_SYMBOL(devm_ioport_unmap);
89433 #endif /* CONFIG_HAS_IOPORT */
89434 diff --git a/lib/div64.c b/lib/div64.c
89435 index 4382ad7..08aa558 100644
89436 --- a/lib/div64.c
89437 +++ b/lib/div64.c
89438 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
89439 EXPORT_SYMBOL(__div64_32);
89440
89441 #ifndef div_s64_rem
89442 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
89443 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
89444 {
89445 u64 quotient;
89446
89447 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
89448 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
89449 */
89450 #ifndef div64_u64
89451 -u64 div64_u64(u64 dividend, u64 divisor)
89452 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
89453 {
89454 u32 high = divisor >> 32;
89455 u64 quot;
89456 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
89457 index d87a17a..ac0d79a 100644
89458 --- a/lib/dma-debug.c
89459 +++ b/lib/dma-debug.c
89460 @@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
89461
89462 void dma_debug_add_bus(struct bus_type *bus)
89463 {
89464 - struct notifier_block *nb;
89465 + notifier_block_no_const *nb;
89466
89467 if (global_disable)
89468 return;
89469 @@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
89470
89471 static void check_for_stack(struct device *dev, void *addr)
89472 {
89473 - if (object_is_on_stack(addr))
89474 + if (object_starts_on_stack(addr))
89475 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
89476 "stack [addr=%p]\n", addr);
89477 }
89478 diff --git a/lib/inflate.c b/lib/inflate.c
89479 index 013a761..c28f3fc 100644
89480 --- a/lib/inflate.c
89481 +++ b/lib/inflate.c
89482 @@ -269,7 +269,7 @@ static void free(void *where)
89483 malloc_ptr = free_mem_ptr;
89484 }
89485 #else
89486 -#define malloc(a) kmalloc(a, GFP_KERNEL)
89487 +#define malloc(a) kmalloc((a), GFP_KERNEL)
89488 #define free(a) kfree(a)
89489 #endif
89490
89491 diff --git a/lib/ioremap.c b/lib/ioremap.c
89492 index 0c9216c..863bd89 100644
89493 --- a/lib/ioremap.c
89494 +++ b/lib/ioremap.c
89495 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
89496 unsigned long next;
89497
89498 phys_addr -= addr;
89499 - pmd = pmd_alloc(&init_mm, pud, addr);
89500 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
89501 if (!pmd)
89502 return -ENOMEM;
89503 do {
89504 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
89505 unsigned long next;
89506
89507 phys_addr -= addr;
89508 - pud = pud_alloc(&init_mm, pgd, addr);
89509 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
89510 if (!pud)
89511 return -ENOMEM;
89512 do {
89513 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
89514 index bd2bea9..6b3c95e 100644
89515 --- a/lib/is_single_threaded.c
89516 +++ b/lib/is_single_threaded.c
89517 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
89518 struct task_struct *p, *t;
89519 bool ret;
89520
89521 + if (!mm)
89522 + return true;
89523 +
89524 if (atomic_read(&task->signal->live) != 1)
89525 return false;
89526
89527 diff --git a/lib/kobject.c b/lib/kobject.c
89528 index 5b4b888..c2950f7 100644
89529 --- a/lib/kobject.c
89530 +++ b/lib/kobject.c
89531 @@ -957,9 +957,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
89532
89533
89534 static DEFINE_SPINLOCK(kobj_ns_type_lock);
89535 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
89536 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
89537
89538 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
89539 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
89540 {
89541 enum kobj_ns_type type = ops->type;
89542 int error;
89543 diff --git a/lib/list_debug.c b/lib/list_debug.c
89544 index c24c2f7..f0296f4 100644
89545 --- a/lib/list_debug.c
89546 +++ b/lib/list_debug.c
89547 @@ -11,7 +11,9 @@
89548 #include <linux/bug.h>
89549 #include <linux/kernel.h>
89550 #include <linux/rculist.h>
89551 +#include <linux/mm.h>
89552
89553 +#ifdef CONFIG_DEBUG_LIST
89554 /*
89555 * Insert a new entry between two known consecutive entries.
89556 *
89557 @@ -19,21 +21,40 @@
89558 * the prev/next entries already!
89559 */
89560
89561 +static bool __list_add_debug(struct list_head *new,
89562 + struct list_head *prev,
89563 + struct list_head *next)
89564 +{
89565 + if (unlikely(next->prev != prev)) {
89566 + printk(KERN_ERR "list_add corruption. next->prev should be "
89567 + "prev (%p), but was %p. (next=%p).\n",
89568 + prev, next->prev, next);
89569 + BUG();
89570 + return false;
89571 + }
89572 + if (unlikely(prev->next != next)) {
89573 + printk(KERN_ERR "list_add corruption. prev->next should be "
89574 + "next (%p), but was %p. (prev=%p).\n",
89575 + next, prev->next, prev);
89576 + BUG();
89577 + return false;
89578 + }
89579 + if (unlikely(new == prev || new == next)) {
89580 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
89581 + new, prev, next);
89582 + BUG();
89583 + return false;
89584 + }
89585 + return true;
89586 +}
89587 +
89588 void __list_add(struct list_head *new,
89589 - struct list_head *prev,
89590 - struct list_head *next)
89591 + struct list_head *prev,
89592 + struct list_head *next)
89593 {
89594 - WARN(next->prev != prev,
89595 - "list_add corruption. next->prev should be "
89596 - "prev (%p), but was %p. (next=%p).\n",
89597 - prev, next->prev, next);
89598 - WARN(prev->next != next,
89599 - "list_add corruption. prev->next should be "
89600 - "next (%p), but was %p. (prev=%p).\n",
89601 - next, prev->next, prev);
89602 - WARN(new == prev || new == next,
89603 - "list_add double add: new=%p, prev=%p, next=%p.\n",
89604 - new, prev, next);
89605 + if (!__list_add_debug(new, prev, next))
89606 + return;
89607 +
89608 next->prev = new;
89609 new->next = next;
89610 new->prev = prev;
89611 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
89612 }
89613 EXPORT_SYMBOL(__list_add);
89614
89615 -void __list_del_entry(struct list_head *entry)
89616 +static bool __list_del_entry_debug(struct list_head *entry)
89617 {
89618 struct list_head *prev, *next;
89619
89620 prev = entry->prev;
89621 next = entry->next;
89622
89623 - if (WARN(next == LIST_POISON1,
89624 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
89625 - entry, LIST_POISON1) ||
89626 - WARN(prev == LIST_POISON2,
89627 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
89628 - entry, LIST_POISON2) ||
89629 - WARN(prev->next != entry,
89630 - "list_del corruption. prev->next should be %p, "
89631 - "but was %p\n", entry, prev->next) ||
89632 - WARN(next->prev != entry,
89633 - "list_del corruption. next->prev should be %p, "
89634 - "but was %p\n", entry, next->prev))
89635 + if (unlikely(next == LIST_POISON1)) {
89636 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
89637 + entry, LIST_POISON1);
89638 + BUG();
89639 + return false;
89640 + }
89641 + if (unlikely(prev == LIST_POISON2)) {
89642 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
89643 + entry, LIST_POISON2);
89644 + BUG();
89645 + return false;
89646 + }
89647 + if (unlikely(entry->prev->next != entry)) {
89648 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
89649 + "but was %p\n", entry, prev->next);
89650 + BUG();
89651 + return false;
89652 + }
89653 + if (unlikely(entry->next->prev != entry)) {
89654 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
89655 + "but was %p\n", entry, next->prev);
89656 + BUG();
89657 + return false;
89658 + }
89659 + return true;
89660 +}
89661 +
89662 +void __list_del_entry(struct list_head *entry)
89663 +{
89664 + if (!__list_del_entry_debug(entry))
89665 return;
89666
89667 - __list_del(prev, next);
89668 + __list_del(entry->prev, entry->next);
89669 }
89670 EXPORT_SYMBOL(__list_del_entry);
89671
89672 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
89673 void __list_add_rcu(struct list_head *new,
89674 struct list_head *prev, struct list_head *next)
89675 {
89676 - WARN(next->prev != prev,
89677 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
89678 - prev, next->prev, next);
89679 - WARN(prev->next != next,
89680 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
89681 - next, prev->next, prev);
89682 + if (!__list_add_debug(new, prev, next))
89683 + return;
89684 +
89685 new->next = next;
89686 new->prev = prev;
89687 rcu_assign_pointer(list_next_rcu(prev), new);
89688 next->prev = new;
89689 }
89690 EXPORT_SYMBOL(__list_add_rcu);
89691 +#endif
89692 +
89693 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
89694 +{
89695 +#ifdef CONFIG_DEBUG_LIST
89696 + if (!__list_add_debug(new, prev, next))
89697 + return;
89698 +#endif
89699 +
89700 + pax_open_kernel();
89701 + next->prev = new;
89702 + new->next = next;
89703 + new->prev = prev;
89704 + prev->next = new;
89705 + pax_close_kernel();
89706 +}
89707 +EXPORT_SYMBOL(__pax_list_add);
89708 +
89709 +void pax_list_del(struct list_head *entry)
89710 +{
89711 +#ifdef CONFIG_DEBUG_LIST
89712 + if (!__list_del_entry_debug(entry))
89713 + return;
89714 +#endif
89715 +
89716 + pax_open_kernel();
89717 + __list_del(entry->prev, entry->next);
89718 + entry->next = LIST_POISON1;
89719 + entry->prev = LIST_POISON2;
89720 + pax_close_kernel();
89721 +}
89722 +EXPORT_SYMBOL(pax_list_del);
89723 +
89724 +void pax_list_del_init(struct list_head *entry)
89725 +{
89726 + pax_open_kernel();
89727 + __list_del(entry->prev, entry->next);
89728 + INIT_LIST_HEAD(entry);
89729 + pax_close_kernel();
89730 +}
89731 +EXPORT_SYMBOL(pax_list_del_init);
89732 +
89733 +void __pax_list_add_rcu(struct list_head *new,
89734 + struct list_head *prev, struct list_head *next)
89735 +{
89736 +#ifdef CONFIG_DEBUG_LIST
89737 + if (!__list_add_debug(new, prev, next))
89738 + return;
89739 +#endif
89740 +
89741 + pax_open_kernel();
89742 + new->next = next;
89743 + new->prev = prev;
89744 + rcu_assign_pointer(list_next_rcu(prev), new);
89745 + next->prev = new;
89746 + pax_close_kernel();
89747 +}
89748 +EXPORT_SYMBOL(__pax_list_add_rcu);
89749 +
89750 +void pax_list_del_rcu(struct list_head *entry)
89751 +{
89752 +#ifdef CONFIG_DEBUG_LIST
89753 + if (!__list_del_entry_debug(entry))
89754 + return;
89755 +#endif
89756 +
89757 + pax_open_kernel();
89758 + __list_del(entry->prev, entry->next);
89759 + entry->next = LIST_POISON1;
89760 + entry->prev = LIST_POISON2;
89761 + pax_close_kernel();
89762 +}
89763 +EXPORT_SYMBOL(pax_list_del_rcu);
89764 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
89765 index 1a53d49..ace934c 100644
89766 --- a/lib/percpu-refcount.c
89767 +++ b/lib/percpu-refcount.c
89768 @@ -29,7 +29,7 @@
89769 * can't hit 0 before we've added up all the percpu refs.
89770 */
89771
89772 -#define PCPU_COUNT_BIAS (1U << 31)
89773 +#define PCPU_COUNT_BIAS (1U << 30)
89774
89775 /**
89776 * percpu_ref_init - initialize a percpu refcount
89777 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
89778 index 7811ed3..f80ca19 100644
89779 --- a/lib/radix-tree.c
89780 +++ b/lib/radix-tree.c
89781 @@ -93,7 +93,7 @@ struct radix_tree_preload {
89782 int nr;
89783 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
89784 };
89785 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
89786 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
89787
89788 static inline void *ptr_to_indirect(void *ptr)
89789 {
89790 diff --git a/lib/rbtree.c b/lib/rbtree.c
89791 index 65f4eff..2cfa167 100644
89792 --- a/lib/rbtree.c
89793 +++ b/lib/rbtree.c
89794 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
89795 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
89796
89797 static const struct rb_augment_callbacks dummy_callbacks = {
89798 - dummy_propagate, dummy_copy, dummy_rotate
89799 + .propagate = dummy_propagate,
89800 + .copy = dummy_copy,
89801 + .rotate = dummy_rotate
89802 };
89803
89804 void rb_insert_color(struct rb_node *node, struct rb_root *root)
89805 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
89806 index bb2b201..46abaf9 100644
89807 --- a/lib/strncpy_from_user.c
89808 +++ b/lib/strncpy_from_user.c
89809 @@ -21,7 +21,7 @@
89810 */
89811 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
89812 {
89813 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89814 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89815 long res = 0;
89816
89817 /*
89818 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
89819 index a28df52..3d55877 100644
89820 --- a/lib/strnlen_user.c
89821 +++ b/lib/strnlen_user.c
89822 @@ -26,7 +26,7 @@
89823 */
89824 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
89825 {
89826 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89827 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89828 long align, res = 0;
89829 unsigned long c;
89830
89831 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
89832 index e4399fa..5e8b214 100644
89833 --- a/lib/swiotlb.c
89834 +++ b/lib/swiotlb.c
89835 @@ -668,7 +668,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
89836
89837 void
89838 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
89839 - dma_addr_t dev_addr)
89840 + dma_addr_t dev_addr, struct dma_attrs *attrs)
89841 {
89842 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
89843
89844 diff --git a/lib/usercopy.c b/lib/usercopy.c
89845 index 4f5b1dd..7cab418 100644
89846 --- a/lib/usercopy.c
89847 +++ b/lib/usercopy.c
89848 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
89849 WARN(1, "Buffer overflow detected!\n");
89850 }
89851 EXPORT_SYMBOL(copy_from_user_overflow);
89852 +
89853 +void copy_to_user_overflow(void)
89854 +{
89855 + WARN(1, "Buffer overflow detected!\n");
89856 +}
89857 +EXPORT_SYMBOL(copy_to_user_overflow);
89858 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
89859 index 10909c5..653e1b8 100644
89860 --- a/lib/vsprintf.c
89861 +++ b/lib/vsprintf.c
89862 @@ -16,6 +16,9 @@
89863 * - scnprintf and vscnprintf
89864 */
89865
89866 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89867 +#define __INCLUDED_BY_HIDESYM 1
89868 +#endif
89869 #include <stdarg.h>
89870 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
89871 #include <linux/types.h>
89872 @@ -1155,7 +1158,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
89873 return number(buf, end, *(const netdev_features_t *)addr, spec);
89874 }
89875
89876 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89877 +int kptr_restrict __read_mostly = 2;
89878 +#else
89879 int kptr_restrict __read_mostly;
89880 +#endif
89881
89882 /*
89883 * Show a '%p' thing. A kernel extension is that the '%p' is followed
89884 @@ -1168,6 +1175,7 @@ int kptr_restrict __read_mostly;
89885 * - 'f' For simple symbolic function names without offset
89886 * - 'S' For symbolic direct pointers with offset
89887 * - 's' For symbolic direct pointers without offset
89888 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
89889 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
89890 * - 'B' For backtraced symbolic direct pointers with offset
89891 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
89892 @@ -1234,12 +1242,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
89893
89894 if (!ptr && *fmt != 'K') {
89895 /*
89896 - * Print (null) with the same width as a pointer so it makes
89897 + * Print (nil) with the same width as a pointer so it makes
89898 * tabular output look nice.
89899 */
89900 if (spec.field_width == -1)
89901 spec.field_width = default_width;
89902 - return string(buf, end, "(null)", spec);
89903 + return string(buf, end, "(nil)", spec);
89904 }
89905
89906 switch (*fmt) {
89907 @@ -1249,6 +1257,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
89908 /* Fallthrough */
89909 case 'S':
89910 case 's':
89911 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89912 + break;
89913 +#else
89914 + return symbol_string(buf, end, ptr, spec, fmt);
89915 +#endif
89916 + case 'A':
89917 case 'B':
89918 return symbol_string(buf, end, ptr, spec, fmt);
89919 case 'R':
89920 @@ -1304,6 +1318,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
89921 va_end(va);
89922 return buf;
89923 }
89924 + case 'P':
89925 + break;
89926 case 'K':
89927 /*
89928 * %pK cannot be used in IRQ context because its test
89929 @@ -1365,6 +1381,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
89930 ((const struct file *)ptr)->f_path.dentry,
89931 spec, fmt);
89932 }
89933 +
89934 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89935 + /* 'P' = approved pointers to copy to userland,
89936 + as in the /proc/kallsyms case, as we make it display nothing
89937 + for non-root users, and the real contents for root users
89938 + Also ignore 'K' pointers, since we force their NULLing for non-root users
89939 + above
89940 + */
89941 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
89942 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
89943 + dump_stack();
89944 + ptr = NULL;
89945 + }
89946 +#endif
89947 +
89948 spec.flags |= SMALL;
89949 if (spec.field_width == -1) {
89950 spec.field_width = default_width;
89951 @@ -2086,11 +2117,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
89952 typeof(type) value; \
89953 if (sizeof(type) == 8) { \
89954 args = PTR_ALIGN(args, sizeof(u32)); \
89955 - *(u32 *)&value = *(u32 *)args; \
89956 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
89957 + *(u32 *)&value = *(const u32 *)args; \
89958 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
89959 } else { \
89960 args = PTR_ALIGN(args, sizeof(type)); \
89961 - value = *(typeof(type) *)args; \
89962 + value = *(const typeof(type) *)args; \
89963 } \
89964 args += sizeof(type); \
89965 value; \
89966 @@ -2153,7 +2184,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
89967 case FORMAT_TYPE_STR: {
89968 const char *str_arg = args;
89969 args += strlen(str_arg) + 1;
89970 - str = string(str, end, (char *)str_arg, spec);
89971 + str = string(str, end, str_arg, spec);
89972 break;
89973 }
89974
89975 diff --git a/localversion-grsec b/localversion-grsec
89976 new file mode 100644
89977 index 0000000..7cd6065
89978 --- /dev/null
89979 +++ b/localversion-grsec
89980 @@ -0,0 +1 @@
89981 +-grsec
89982 diff --git a/mm/Kconfig b/mm/Kconfig
89983 index 723bbe0..ea624b1 100644
89984 --- a/mm/Kconfig
89985 +++ b/mm/Kconfig
89986 @@ -326,10 +326,11 @@ config KSM
89987 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
89988
89989 config DEFAULT_MMAP_MIN_ADDR
89990 - int "Low address space to protect from user allocation"
89991 + int "Low address space to protect from user allocation"
89992 depends on MMU
89993 - default 4096
89994 - help
89995 + default 32768 if ALPHA || ARM || PARISC || SPARC32
89996 + default 65536
89997 + help
89998 This is the portion of low virtual memory which should be protected
89999 from userspace allocation. Keeping a user from writing to low pages
90000 can help reduce the impact of kernel NULL pointer bugs.
90001 @@ -360,7 +361,7 @@ config MEMORY_FAILURE
90002
90003 config HWPOISON_INJECT
90004 tristate "HWPoison pages injector"
90005 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
90006 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
90007 select PROC_PAGE_MONITOR
90008
90009 config NOMMU_INITIAL_TRIM_EXCESS
90010 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
90011 index ce682f7..1fb54f9 100644
90012 --- a/mm/backing-dev.c
90013 +++ b/mm/backing-dev.c
90014 @@ -12,7 +12,7 @@
90015 #include <linux/device.h>
90016 #include <trace/events/writeback.h>
90017
90018 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
90019 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
90020
90021 struct backing_dev_info default_backing_dev_info = {
90022 .name = "default",
90023 @@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
90024 return err;
90025
90026 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
90027 - atomic_long_inc_return(&bdi_seq));
90028 + atomic_long_inc_return_unchecked(&bdi_seq));
90029 if (err) {
90030 bdi_destroy(bdi);
90031 return err;
90032 diff --git a/mm/filemap.c b/mm/filemap.c
90033 index b7749a9..50d1123 100644
90034 --- a/mm/filemap.c
90035 +++ b/mm/filemap.c
90036 @@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
90037 struct address_space *mapping = file->f_mapping;
90038
90039 if (!mapping->a_ops->readpage)
90040 - return -ENOEXEC;
90041 + return -ENODEV;
90042 file_accessed(file);
90043 vma->vm_ops = &generic_file_vm_ops;
90044 return 0;
90045 @@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
90046
90047 while (bytes) {
90048 char __user *buf = iov->iov_base + base;
90049 - int copy = min(bytes, iov->iov_len - base);
90050 + size_t copy = min(bytes, iov->iov_len - base);
90051
90052 base = 0;
90053 left = __copy_from_user_inatomic(vaddr, buf, copy);
90054 @@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
90055 BUG_ON(!in_atomic());
90056 kaddr = kmap_atomic(page);
90057 if (likely(i->nr_segs == 1)) {
90058 - int left;
90059 + size_t left;
90060 char __user *buf = i->iov->iov_base + i->iov_offset;
90061 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
90062 copied = bytes - left;
90063 @@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
90064
90065 kaddr = kmap(page);
90066 if (likely(i->nr_segs == 1)) {
90067 - int left;
90068 + size_t left;
90069 char __user *buf = i->iov->iov_base + i->iov_offset;
90070 left = __copy_from_user(kaddr + offset, buf, bytes);
90071 copied = bytes - left;
90072 @@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
90073 * zero-length segments (without overruning the iovec).
90074 */
90075 while (bytes || unlikely(i->count && !iov->iov_len)) {
90076 - int copy;
90077 + size_t copy;
90078
90079 copy = min(bytes, iov->iov_len - base);
90080 BUG_ON(!i->count || i->count < copy);
90081 @@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
90082 *pos = i_size_read(inode);
90083
90084 if (limit != RLIM_INFINITY) {
90085 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
90086 if (*pos >= limit) {
90087 send_sig(SIGXFSZ, current, 0);
90088 return -EFBIG;
90089 diff --git a/mm/fremap.c b/mm/fremap.c
90090 index bbc4d66..117b798 100644
90091 --- a/mm/fremap.c
90092 +++ b/mm/fremap.c
90093 @@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
90094 retry:
90095 vma = find_vma(mm, start);
90096
90097 +#ifdef CONFIG_PAX_SEGMEXEC
90098 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
90099 + goto out;
90100 +#endif
90101 +
90102 /*
90103 * Make sure the vma is shared, that it supports prefaulting,
90104 * and that the remapped range is valid and fully within
90105 diff --git a/mm/highmem.c b/mm/highmem.c
90106 index b32b70c..e512eb0 100644
90107 --- a/mm/highmem.c
90108 +++ b/mm/highmem.c
90109 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
90110 * So no dangers, even with speculative execution.
90111 */
90112 page = pte_page(pkmap_page_table[i]);
90113 + pax_open_kernel();
90114 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
90115 -
90116 + pax_close_kernel();
90117 set_page_address(page, NULL);
90118 need_flush = 1;
90119 }
90120 @@ -198,9 +199,11 @@ start:
90121 }
90122 }
90123 vaddr = PKMAP_ADDR(last_pkmap_nr);
90124 +
90125 + pax_open_kernel();
90126 set_pte_at(&init_mm, vaddr,
90127 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
90128 -
90129 + pax_close_kernel();
90130 pkmap_count[last_pkmap_nr] = 1;
90131 set_page_address(page, (void *)vaddr);
90132
90133 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
90134 index dee6cf4..52b94f7 100644
90135 --- a/mm/hugetlb.c
90136 +++ b/mm/hugetlb.c
90137 @@ -2077,15 +2077,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
90138 struct hstate *h = &default_hstate;
90139 unsigned long tmp;
90140 int ret;
90141 + ctl_table_no_const hugetlb_table;
90142
90143 tmp = h->max_huge_pages;
90144
90145 if (write && h->order >= MAX_ORDER)
90146 return -EINVAL;
90147
90148 - table->data = &tmp;
90149 - table->maxlen = sizeof(unsigned long);
90150 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
90151 + hugetlb_table = *table;
90152 + hugetlb_table.data = &tmp;
90153 + hugetlb_table.maxlen = sizeof(unsigned long);
90154 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
90155 if (ret)
90156 goto out;
90157
90158 @@ -2130,15 +2132,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
90159 struct hstate *h = &default_hstate;
90160 unsigned long tmp;
90161 int ret;
90162 + ctl_table_no_const hugetlb_table;
90163
90164 tmp = h->nr_overcommit_huge_pages;
90165
90166 if (write && h->order >= MAX_ORDER)
90167 return -EINVAL;
90168
90169 - table->data = &tmp;
90170 - table->maxlen = sizeof(unsigned long);
90171 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
90172 + hugetlb_table = *table;
90173 + hugetlb_table.data = &tmp;
90174 + hugetlb_table.maxlen = sizeof(unsigned long);
90175 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
90176 if (ret)
90177 goto out;
90178
90179 @@ -2596,6 +2600,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
90180 return 1;
90181 }
90182
90183 +#ifdef CONFIG_PAX_SEGMEXEC
90184 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
90185 +{
90186 + struct mm_struct *mm = vma->vm_mm;
90187 + struct vm_area_struct *vma_m;
90188 + unsigned long address_m;
90189 + pte_t *ptep_m;
90190 +
90191 + vma_m = pax_find_mirror_vma(vma);
90192 + if (!vma_m)
90193 + return;
90194 +
90195 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90196 + address_m = address + SEGMEXEC_TASK_SIZE;
90197 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
90198 + get_page(page_m);
90199 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
90200 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
90201 +}
90202 +#endif
90203 +
90204 /*
90205 * Hugetlb_cow() should be called with page lock of the original hugepage held.
90206 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
90207 @@ -2712,6 +2737,11 @@ retry_avoidcopy:
90208 make_huge_pte(vma, new_page, 1));
90209 page_remove_rmap(old_page);
90210 hugepage_add_new_anon_rmap(new_page, vma, address);
90211 +
90212 +#ifdef CONFIG_PAX_SEGMEXEC
90213 + pax_mirror_huge_pte(vma, address, new_page);
90214 +#endif
90215 +
90216 /* Make the old page be freed below */
90217 new_page = old_page;
90218 }
90219 @@ -2876,6 +2906,10 @@ retry:
90220 && (vma->vm_flags & VM_SHARED)));
90221 set_huge_pte_at(mm, address, ptep, new_pte);
90222
90223 +#ifdef CONFIG_PAX_SEGMEXEC
90224 + pax_mirror_huge_pte(vma, address, page);
90225 +#endif
90226 +
90227 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
90228 /* Optimization, do the COW without a second fault */
90229 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
90230 @@ -2906,6 +2940,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90231 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
90232 struct hstate *h = hstate_vma(vma);
90233
90234 +#ifdef CONFIG_PAX_SEGMEXEC
90235 + struct vm_area_struct *vma_m;
90236 +#endif
90237 +
90238 address &= huge_page_mask(h);
90239
90240 ptep = huge_pte_offset(mm, address);
90241 @@ -2919,6 +2957,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90242 VM_FAULT_SET_HINDEX(hstate_index(h));
90243 }
90244
90245 +#ifdef CONFIG_PAX_SEGMEXEC
90246 + vma_m = pax_find_mirror_vma(vma);
90247 + if (vma_m) {
90248 + unsigned long address_m;
90249 +
90250 + if (vma->vm_start > vma_m->vm_start) {
90251 + address_m = address;
90252 + address -= SEGMEXEC_TASK_SIZE;
90253 + vma = vma_m;
90254 + h = hstate_vma(vma);
90255 + } else
90256 + address_m = address + SEGMEXEC_TASK_SIZE;
90257 +
90258 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
90259 + return VM_FAULT_OOM;
90260 + address_m &= HPAGE_MASK;
90261 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
90262 + }
90263 +#endif
90264 +
90265 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
90266 if (!ptep)
90267 return VM_FAULT_OOM;
90268 diff --git a/mm/internal.h b/mm/internal.h
90269 index 684f7aa..9eb9edc 100644
90270 --- a/mm/internal.h
90271 +++ b/mm/internal.h
90272 @@ -97,6 +97,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
90273 * in mm/page_alloc.c
90274 */
90275 extern void __free_pages_bootmem(struct page *page, unsigned int order);
90276 +extern void free_compound_page(struct page *page);
90277 extern void prep_compound_page(struct page *page, unsigned long order);
90278 #ifdef CONFIG_MEMORY_FAILURE
90279 extern bool is_free_buddy_page(struct page *page);
90280 @@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
90281
90282 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
90283 unsigned long, unsigned long,
90284 - unsigned long, unsigned long);
90285 + unsigned long, unsigned long) __intentional_overflow(-1);
90286
90287 extern void set_pageblock_order(void);
90288 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
90289 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
90290 index 31f01c5..7015178 100644
90291 --- a/mm/kmemleak.c
90292 +++ b/mm/kmemleak.c
90293 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
90294
90295 for (i = 0; i < object->trace_len; i++) {
90296 void *ptr = (void *)object->trace[i];
90297 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
90298 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
90299 }
90300 }
90301
90302 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
90303 return -ENOMEM;
90304 }
90305
90306 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
90307 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
90308 &kmemleak_fops);
90309 if (!dentry)
90310 pr_warning("Failed to create the debugfs kmemleak file\n");
90311 diff --git a/mm/maccess.c b/mm/maccess.c
90312 index d53adf9..03a24bf 100644
90313 --- a/mm/maccess.c
90314 +++ b/mm/maccess.c
90315 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
90316 set_fs(KERNEL_DS);
90317 pagefault_disable();
90318 ret = __copy_from_user_inatomic(dst,
90319 - (__force const void __user *)src, size);
90320 + (const void __force_user *)src, size);
90321 pagefault_enable();
90322 set_fs(old_fs);
90323
90324 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
90325
90326 set_fs(KERNEL_DS);
90327 pagefault_disable();
90328 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
90329 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
90330 pagefault_enable();
90331 set_fs(old_fs);
90332
90333 diff --git a/mm/madvise.c b/mm/madvise.c
90334 index 539eeb9..e24a987 100644
90335 --- a/mm/madvise.c
90336 +++ b/mm/madvise.c
90337 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
90338 pgoff_t pgoff;
90339 unsigned long new_flags = vma->vm_flags;
90340
90341 +#ifdef CONFIG_PAX_SEGMEXEC
90342 + struct vm_area_struct *vma_m;
90343 +#endif
90344 +
90345 switch (behavior) {
90346 case MADV_NORMAL:
90347 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
90348 @@ -126,6 +130,13 @@ success:
90349 /*
90350 * vm_flags is protected by the mmap_sem held in write mode.
90351 */
90352 +
90353 +#ifdef CONFIG_PAX_SEGMEXEC
90354 + vma_m = pax_find_mirror_vma(vma);
90355 + if (vma_m)
90356 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
90357 +#endif
90358 +
90359 vma->vm_flags = new_flags;
90360
90361 out:
90362 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
90363 struct vm_area_struct **prev,
90364 unsigned long start, unsigned long end)
90365 {
90366 +
90367 +#ifdef CONFIG_PAX_SEGMEXEC
90368 + struct vm_area_struct *vma_m;
90369 +#endif
90370 +
90371 *prev = vma;
90372 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
90373 return -EINVAL;
90374 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
90375 zap_page_range(vma, start, end - start, &details);
90376 } else
90377 zap_page_range(vma, start, end - start, NULL);
90378 +
90379 +#ifdef CONFIG_PAX_SEGMEXEC
90380 + vma_m = pax_find_mirror_vma(vma);
90381 + if (vma_m) {
90382 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
90383 + struct zap_details details = {
90384 + .nonlinear_vma = vma_m,
90385 + .last_index = ULONG_MAX,
90386 + };
90387 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
90388 + } else
90389 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
90390 + }
90391 +#endif
90392 +
90393 return 0;
90394 }
90395
90396 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
90397 if (end < start)
90398 return error;
90399
90400 +#ifdef CONFIG_PAX_SEGMEXEC
90401 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
90402 + if (end > SEGMEXEC_TASK_SIZE)
90403 + return error;
90404 + } else
90405 +#endif
90406 +
90407 + if (end > TASK_SIZE)
90408 + return error;
90409 +
90410 error = 0;
90411 if (end == start)
90412 return error;
90413 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
90414 index fabe550..f31b51c 100644
90415 --- a/mm/memory-failure.c
90416 +++ b/mm/memory-failure.c
90417 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
90418
90419 int sysctl_memory_failure_recovery __read_mostly = 1;
90420
90421 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
90422 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
90423
90424 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
90425
90426 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
90427 pfn, t->comm, t->pid);
90428 si.si_signo = SIGBUS;
90429 si.si_errno = 0;
90430 - si.si_addr = (void *)addr;
90431 + si.si_addr = (void __user *)addr;
90432 #ifdef __ARCH_SI_TRAPNO
90433 si.si_trapno = trapno;
90434 #endif
90435 @@ -762,7 +762,7 @@ static struct page_state {
90436 unsigned long res;
90437 char *msg;
90438 int (*action)(struct page *p, unsigned long pfn);
90439 -} error_states[] = {
90440 +} __do_const error_states[] = {
90441 { reserved, reserved, "reserved kernel", me_kernel },
90442 /*
90443 * free pages are specially detected outside this table:
90444 @@ -1063,7 +1063,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90445 nr_pages = 1 << compound_order(hpage);
90446 else /* normal page or thp */
90447 nr_pages = 1;
90448 - atomic_long_add(nr_pages, &num_poisoned_pages);
90449 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
90450
90451 /*
90452 * We need/can do nothing about count=0 pages.
90453 @@ -1093,7 +1093,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90454 if (!PageHWPoison(hpage)
90455 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
90456 || (p != hpage && TestSetPageHWPoison(hpage))) {
90457 - atomic_long_sub(nr_pages, &num_poisoned_pages);
90458 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90459 return 0;
90460 }
90461 set_page_hwpoison_huge_page(hpage);
90462 @@ -1162,7 +1162,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90463 }
90464 if (hwpoison_filter(p)) {
90465 if (TestClearPageHWPoison(p))
90466 - atomic_long_sub(nr_pages, &num_poisoned_pages);
90467 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90468 unlock_page(hpage);
90469 put_page(hpage);
90470 return 0;
90471 @@ -1380,7 +1380,7 @@ int unpoison_memory(unsigned long pfn)
90472 return 0;
90473 }
90474 if (TestClearPageHWPoison(p))
90475 - atomic_long_dec(&num_poisoned_pages);
90476 + atomic_long_dec_unchecked(&num_poisoned_pages);
90477 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
90478 return 0;
90479 }
90480 @@ -1394,7 +1394,7 @@ int unpoison_memory(unsigned long pfn)
90481 */
90482 if (TestClearPageHWPoison(page)) {
90483 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
90484 - atomic_long_sub(nr_pages, &num_poisoned_pages);
90485 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90486 freeit = 1;
90487 if (PageHuge(page))
90488 clear_page_hwpoison_huge_page(page);
90489 @@ -1519,11 +1519,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
90490 if (PageHuge(page)) {
90491 set_page_hwpoison_huge_page(hpage);
90492 dequeue_hwpoisoned_huge_page(hpage);
90493 - atomic_long_add(1 << compound_order(hpage),
90494 + atomic_long_add_unchecked(1 << compound_order(hpage),
90495 &num_poisoned_pages);
90496 } else {
90497 SetPageHWPoison(page);
90498 - atomic_long_inc(&num_poisoned_pages);
90499 + atomic_long_inc_unchecked(&num_poisoned_pages);
90500 }
90501 }
90502 return ret;
90503 @@ -1562,7 +1562,7 @@ static int __soft_offline_page(struct page *page, int flags)
90504 put_page(page);
90505 pr_info("soft_offline: %#lx: invalidated\n", pfn);
90506 SetPageHWPoison(page);
90507 - atomic_long_inc(&num_poisoned_pages);
90508 + atomic_long_inc_unchecked(&num_poisoned_pages);
90509 return 0;
90510 }
90511
90512 @@ -1607,7 +1607,7 @@ static int __soft_offline_page(struct page *page, int flags)
90513 if (!is_free_buddy_page(page))
90514 pr_info("soft offline: %#lx: page leaked\n",
90515 pfn);
90516 - atomic_long_inc(&num_poisoned_pages);
90517 + atomic_long_inc_unchecked(&num_poisoned_pages);
90518 }
90519 } else {
90520 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
90521 @@ -1681,11 +1681,11 @@ int soft_offline_page(struct page *page, int flags)
90522 if (PageHuge(page)) {
90523 set_page_hwpoison_huge_page(hpage);
90524 dequeue_hwpoisoned_huge_page(hpage);
90525 - atomic_long_add(1 << compound_order(hpage),
90526 + atomic_long_add_unchecked(1 << compound_order(hpage),
90527 &num_poisoned_pages);
90528 } else {
90529 SetPageHWPoison(page);
90530 - atomic_long_inc(&num_poisoned_pages);
90531 + atomic_long_inc_unchecked(&num_poisoned_pages);
90532 }
90533 }
90534 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
90535 diff --git a/mm/memory.c b/mm/memory.c
90536 index 6768ce9..4c41d69 100644
90537 --- a/mm/memory.c
90538 +++ b/mm/memory.c
90539 @@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
90540 free_pte_range(tlb, pmd, addr);
90541 } while (pmd++, addr = next, addr != end);
90542
90543 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
90544 start &= PUD_MASK;
90545 if (start < floor)
90546 return;
90547 @@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
90548 pmd = pmd_offset(pud, start);
90549 pud_clear(pud);
90550 pmd_free_tlb(tlb, pmd, start);
90551 +#endif
90552 +
90553 }
90554
90555 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90556 @@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90557 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
90558 } while (pud++, addr = next, addr != end);
90559
90560 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
90561 start &= PGDIR_MASK;
90562 if (start < floor)
90563 return;
90564 @@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90565 pud = pud_offset(pgd, start);
90566 pgd_clear(pgd);
90567 pud_free_tlb(tlb, pud, start);
90568 +#endif
90569 +
90570 }
90571
90572 /*
90573 @@ -1635,12 +1641,6 @@ no_page_table:
90574 return page;
90575 }
90576
90577 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
90578 -{
90579 - return stack_guard_page_start(vma, addr) ||
90580 - stack_guard_page_end(vma, addr+PAGE_SIZE);
90581 -}
90582 -
90583 /**
90584 * __get_user_pages() - pin user pages in memory
90585 * @tsk: task_struct of target task
90586 @@ -1727,10 +1727,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90587
90588 i = 0;
90589
90590 - do {
90591 + while (nr_pages) {
90592 struct vm_area_struct *vma;
90593
90594 - vma = find_extend_vma(mm, start);
90595 + vma = find_vma(mm, start);
90596 if (!vma && in_gate_area(mm, start)) {
90597 unsigned long pg = start & PAGE_MASK;
90598 pgd_t *pgd;
90599 @@ -1779,7 +1779,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90600 goto next_page;
90601 }
90602
90603 - if (!vma ||
90604 + if (!vma || start < vma->vm_start ||
90605 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
90606 !(vm_flags & vma->vm_flags))
90607 return i ? : -EFAULT;
90608 @@ -1808,11 +1808,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90609 int ret;
90610 unsigned int fault_flags = 0;
90611
90612 - /* For mlock, just skip the stack guard page. */
90613 - if (foll_flags & FOLL_MLOCK) {
90614 - if (stack_guard_page(vma, start))
90615 - goto next_page;
90616 - }
90617 if (foll_flags & FOLL_WRITE)
90618 fault_flags |= FAULT_FLAG_WRITE;
90619 if (nonblocking)
90620 @@ -1892,7 +1887,7 @@ next_page:
90621 start += page_increm * PAGE_SIZE;
90622 nr_pages -= page_increm;
90623 } while (nr_pages && start < vma->vm_end);
90624 - } while (nr_pages);
90625 + }
90626 return i;
90627 }
90628 EXPORT_SYMBOL(__get_user_pages);
90629 @@ -2099,6 +2094,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
90630 page_add_file_rmap(page);
90631 set_pte_at(mm, addr, pte, mk_pte(page, prot));
90632
90633 +#ifdef CONFIG_PAX_SEGMEXEC
90634 + pax_mirror_file_pte(vma, addr, page, ptl);
90635 +#endif
90636 +
90637 retval = 0;
90638 pte_unmap_unlock(pte, ptl);
90639 return retval;
90640 @@ -2143,9 +2142,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
90641 if (!page_count(page))
90642 return -EINVAL;
90643 if (!(vma->vm_flags & VM_MIXEDMAP)) {
90644 +
90645 +#ifdef CONFIG_PAX_SEGMEXEC
90646 + struct vm_area_struct *vma_m;
90647 +#endif
90648 +
90649 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
90650 BUG_ON(vma->vm_flags & VM_PFNMAP);
90651 vma->vm_flags |= VM_MIXEDMAP;
90652 +
90653 +#ifdef CONFIG_PAX_SEGMEXEC
90654 + vma_m = pax_find_mirror_vma(vma);
90655 + if (vma_m)
90656 + vma_m->vm_flags |= VM_MIXEDMAP;
90657 +#endif
90658 +
90659 }
90660 return insert_page(vma, addr, page, vma->vm_page_prot);
90661 }
90662 @@ -2228,6 +2239,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
90663 unsigned long pfn)
90664 {
90665 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
90666 + BUG_ON(vma->vm_mirror);
90667
90668 if (addr < vma->vm_start || addr >= vma->vm_end)
90669 return -EFAULT;
90670 @@ -2475,7 +2487,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
90671
90672 BUG_ON(pud_huge(*pud));
90673
90674 - pmd = pmd_alloc(mm, pud, addr);
90675 + pmd = (mm == &init_mm) ?
90676 + pmd_alloc_kernel(mm, pud, addr) :
90677 + pmd_alloc(mm, pud, addr);
90678 if (!pmd)
90679 return -ENOMEM;
90680 do {
90681 @@ -2495,7 +2509,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
90682 unsigned long next;
90683 int err;
90684
90685 - pud = pud_alloc(mm, pgd, addr);
90686 + pud = (mm == &init_mm) ?
90687 + pud_alloc_kernel(mm, pgd, addr) :
90688 + pud_alloc(mm, pgd, addr);
90689 if (!pud)
90690 return -ENOMEM;
90691 do {
90692 @@ -2583,6 +2599,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
90693 copy_user_highpage(dst, src, va, vma);
90694 }
90695
90696 +#ifdef CONFIG_PAX_SEGMEXEC
90697 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
90698 +{
90699 + struct mm_struct *mm = vma->vm_mm;
90700 + spinlock_t *ptl;
90701 + pte_t *pte, entry;
90702 +
90703 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
90704 + entry = *pte;
90705 + if (!pte_present(entry)) {
90706 + if (!pte_none(entry)) {
90707 + BUG_ON(pte_file(entry));
90708 + free_swap_and_cache(pte_to_swp_entry(entry));
90709 + pte_clear_not_present_full(mm, address, pte, 0);
90710 + }
90711 + } else {
90712 + struct page *page;
90713 +
90714 + flush_cache_page(vma, address, pte_pfn(entry));
90715 + entry = ptep_clear_flush(vma, address, pte);
90716 + BUG_ON(pte_dirty(entry));
90717 + page = vm_normal_page(vma, address, entry);
90718 + if (page) {
90719 + update_hiwater_rss(mm);
90720 + if (PageAnon(page))
90721 + dec_mm_counter_fast(mm, MM_ANONPAGES);
90722 + else
90723 + dec_mm_counter_fast(mm, MM_FILEPAGES);
90724 + page_remove_rmap(page);
90725 + page_cache_release(page);
90726 + }
90727 + }
90728 + pte_unmap_unlock(pte, ptl);
90729 +}
90730 +
90731 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
90732 + *
90733 + * the ptl of the lower mapped page is held on entry and is not released on exit
90734 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
90735 + */
90736 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
90737 +{
90738 + struct mm_struct *mm = vma->vm_mm;
90739 + unsigned long address_m;
90740 + spinlock_t *ptl_m;
90741 + struct vm_area_struct *vma_m;
90742 + pmd_t *pmd_m;
90743 + pte_t *pte_m, entry_m;
90744 +
90745 + BUG_ON(!page_m || !PageAnon(page_m));
90746 +
90747 + vma_m = pax_find_mirror_vma(vma);
90748 + if (!vma_m)
90749 + return;
90750 +
90751 + BUG_ON(!PageLocked(page_m));
90752 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90753 + address_m = address + SEGMEXEC_TASK_SIZE;
90754 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90755 + pte_m = pte_offset_map(pmd_m, address_m);
90756 + ptl_m = pte_lockptr(mm, pmd_m);
90757 + if (ptl != ptl_m) {
90758 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90759 + if (!pte_none(*pte_m))
90760 + goto out;
90761 + }
90762 +
90763 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
90764 + page_cache_get(page_m);
90765 + page_add_anon_rmap(page_m, vma_m, address_m);
90766 + inc_mm_counter_fast(mm, MM_ANONPAGES);
90767 + set_pte_at(mm, address_m, pte_m, entry_m);
90768 + update_mmu_cache(vma_m, address_m, pte_m);
90769 +out:
90770 + if (ptl != ptl_m)
90771 + spin_unlock(ptl_m);
90772 + pte_unmap(pte_m);
90773 + unlock_page(page_m);
90774 +}
90775 +
90776 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
90777 +{
90778 + struct mm_struct *mm = vma->vm_mm;
90779 + unsigned long address_m;
90780 + spinlock_t *ptl_m;
90781 + struct vm_area_struct *vma_m;
90782 + pmd_t *pmd_m;
90783 + pte_t *pte_m, entry_m;
90784 +
90785 + BUG_ON(!page_m || PageAnon(page_m));
90786 +
90787 + vma_m = pax_find_mirror_vma(vma);
90788 + if (!vma_m)
90789 + return;
90790 +
90791 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90792 + address_m = address + SEGMEXEC_TASK_SIZE;
90793 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90794 + pte_m = pte_offset_map(pmd_m, address_m);
90795 + ptl_m = pte_lockptr(mm, pmd_m);
90796 + if (ptl != ptl_m) {
90797 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90798 + if (!pte_none(*pte_m))
90799 + goto out;
90800 + }
90801 +
90802 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
90803 + page_cache_get(page_m);
90804 + page_add_file_rmap(page_m);
90805 + inc_mm_counter_fast(mm, MM_FILEPAGES);
90806 + set_pte_at(mm, address_m, pte_m, entry_m);
90807 + update_mmu_cache(vma_m, address_m, pte_m);
90808 +out:
90809 + if (ptl != ptl_m)
90810 + spin_unlock(ptl_m);
90811 + pte_unmap(pte_m);
90812 +}
90813 +
90814 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
90815 +{
90816 + struct mm_struct *mm = vma->vm_mm;
90817 + unsigned long address_m;
90818 + spinlock_t *ptl_m;
90819 + struct vm_area_struct *vma_m;
90820 + pmd_t *pmd_m;
90821 + pte_t *pte_m, entry_m;
90822 +
90823 + vma_m = pax_find_mirror_vma(vma);
90824 + if (!vma_m)
90825 + return;
90826 +
90827 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90828 + address_m = address + SEGMEXEC_TASK_SIZE;
90829 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90830 + pte_m = pte_offset_map(pmd_m, address_m);
90831 + ptl_m = pte_lockptr(mm, pmd_m);
90832 + if (ptl != ptl_m) {
90833 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90834 + if (!pte_none(*pte_m))
90835 + goto out;
90836 + }
90837 +
90838 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
90839 + set_pte_at(mm, address_m, pte_m, entry_m);
90840 +out:
90841 + if (ptl != ptl_m)
90842 + spin_unlock(ptl_m);
90843 + pte_unmap(pte_m);
90844 +}
90845 +
90846 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
90847 +{
90848 + struct page *page_m;
90849 + pte_t entry;
90850 +
90851 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
90852 + goto out;
90853 +
90854 + entry = *pte;
90855 + page_m = vm_normal_page(vma, address, entry);
90856 + if (!page_m)
90857 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
90858 + else if (PageAnon(page_m)) {
90859 + if (pax_find_mirror_vma(vma)) {
90860 + pte_unmap_unlock(pte, ptl);
90861 + lock_page(page_m);
90862 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
90863 + if (pte_same(entry, *pte))
90864 + pax_mirror_anon_pte(vma, address, page_m, ptl);
90865 + else
90866 + unlock_page(page_m);
90867 + }
90868 + } else
90869 + pax_mirror_file_pte(vma, address, page_m, ptl);
90870 +
90871 +out:
90872 + pte_unmap_unlock(pte, ptl);
90873 +}
90874 +#endif
90875 +
90876 /*
90877 * This routine handles present pages, when users try to write
90878 * to a shared page. It is done by copying the page to a new address
90879 @@ -2807,6 +3003,12 @@ gotten:
90880 */
90881 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
90882 if (likely(pte_same(*page_table, orig_pte))) {
90883 +
90884 +#ifdef CONFIG_PAX_SEGMEXEC
90885 + if (pax_find_mirror_vma(vma))
90886 + BUG_ON(!trylock_page(new_page));
90887 +#endif
90888 +
90889 if (old_page) {
90890 if (!PageAnon(old_page)) {
90891 dec_mm_counter_fast(mm, MM_FILEPAGES);
90892 @@ -2858,6 +3060,10 @@ gotten:
90893 page_remove_rmap(old_page);
90894 }
90895
90896 +#ifdef CONFIG_PAX_SEGMEXEC
90897 + pax_mirror_anon_pte(vma, address, new_page, ptl);
90898 +#endif
90899 +
90900 /* Free the old page.. */
90901 new_page = old_page;
90902 ret |= VM_FAULT_WRITE;
90903 @@ -3135,6 +3341,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
90904 swap_free(entry);
90905 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
90906 try_to_free_swap(page);
90907 +
90908 +#ifdef CONFIG_PAX_SEGMEXEC
90909 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
90910 +#endif
90911 +
90912 unlock_page(page);
90913 if (page != swapcache) {
90914 /*
90915 @@ -3158,6 +3369,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
90916
90917 /* No need to invalidate - it was non-present before */
90918 update_mmu_cache(vma, address, page_table);
90919 +
90920 +#ifdef CONFIG_PAX_SEGMEXEC
90921 + pax_mirror_anon_pte(vma, address, page, ptl);
90922 +#endif
90923 +
90924 unlock:
90925 pte_unmap_unlock(page_table, ptl);
90926 out:
90927 @@ -3177,40 +3393,6 @@ out_release:
90928 }
90929
90930 /*
90931 - * This is like a special single-page "expand_{down|up}wards()",
90932 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
90933 - * doesn't hit another vma.
90934 - */
90935 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
90936 -{
90937 - address &= PAGE_MASK;
90938 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
90939 - struct vm_area_struct *prev = vma->vm_prev;
90940 -
90941 - /*
90942 - * Is there a mapping abutting this one below?
90943 - *
90944 - * That's only ok if it's the same stack mapping
90945 - * that has gotten split..
90946 - */
90947 - if (prev && prev->vm_end == address)
90948 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
90949 -
90950 - expand_downwards(vma, address - PAGE_SIZE);
90951 - }
90952 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
90953 - struct vm_area_struct *next = vma->vm_next;
90954 -
90955 - /* As VM_GROWSDOWN but s/below/above/ */
90956 - if (next && next->vm_start == address + PAGE_SIZE)
90957 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
90958 -
90959 - expand_upwards(vma, address + PAGE_SIZE);
90960 - }
90961 - return 0;
90962 -}
90963 -
90964 -/*
90965 * We enter with non-exclusive mmap_sem (to exclude vma changes,
90966 * but allow concurrent faults), and pte mapped but not yet locked.
90967 * We return with mmap_sem still held, but pte unmapped and unlocked.
90968 @@ -3219,27 +3401,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
90969 unsigned long address, pte_t *page_table, pmd_t *pmd,
90970 unsigned int flags)
90971 {
90972 - struct page *page;
90973 + struct page *page = NULL;
90974 spinlock_t *ptl;
90975 pte_t entry;
90976
90977 - pte_unmap(page_table);
90978 -
90979 - /* Check if we need to add a guard page to the stack */
90980 - if (check_stack_guard_page(vma, address) < 0)
90981 - return VM_FAULT_SIGBUS;
90982 -
90983 - /* Use the zero-page for reads */
90984 if (!(flags & FAULT_FLAG_WRITE)) {
90985 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
90986 vma->vm_page_prot));
90987 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
90988 + ptl = pte_lockptr(mm, pmd);
90989 + spin_lock(ptl);
90990 if (!pte_none(*page_table))
90991 goto unlock;
90992 goto setpte;
90993 }
90994
90995 /* Allocate our own private page. */
90996 + pte_unmap(page_table);
90997 +
90998 if (unlikely(anon_vma_prepare(vma)))
90999 goto oom;
91000 page = alloc_zeroed_user_highpage_movable(vma, address);
91001 @@ -3263,6 +3441,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
91002 if (!pte_none(*page_table))
91003 goto release;
91004
91005 +#ifdef CONFIG_PAX_SEGMEXEC
91006 + if (pax_find_mirror_vma(vma))
91007 + BUG_ON(!trylock_page(page));
91008 +#endif
91009 +
91010 inc_mm_counter_fast(mm, MM_ANONPAGES);
91011 page_add_new_anon_rmap(page, vma, address);
91012 setpte:
91013 @@ -3270,6 +3453,12 @@ setpte:
91014
91015 /* No need to invalidate - it was non-present before */
91016 update_mmu_cache(vma, address, page_table);
91017 +
91018 +#ifdef CONFIG_PAX_SEGMEXEC
91019 + if (page)
91020 + pax_mirror_anon_pte(vma, address, page, ptl);
91021 +#endif
91022 +
91023 unlock:
91024 pte_unmap_unlock(page_table, ptl);
91025 return 0;
91026 @@ -3413,6 +3602,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91027 */
91028 /* Only go through if we didn't race with anybody else... */
91029 if (likely(pte_same(*page_table, orig_pte))) {
91030 +
91031 +#ifdef CONFIG_PAX_SEGMEXEC
91032 + if (anon && pax_find_mirror_vma(vma))
91033 + BUG_ON(!trylock_page(page));
91034 +#endif
91035 +
91036 flush_icache_page(vma, page);
91037 entry = mk_pte(page, vma->vm_page_prot);
91038 if (flags & FAULT_FLAG_WRITE)
91039 @@ -3434,6 +3629,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91040
91041 /* no need to invalidate: a not-present page won't be cached */
91042 update_mmu_cache(vma, address, page_table);
91043 +
91044 +#ifdef CONFIG_PAX_SEGMEXEC
91045 + if (anon)
91046 + pax_mirror_anon_pte(vma, address, page, ptl);
91047 + else
91048 + pax_mirror_file_pte(vma, address, page, ptl);
91049 +#endif
91050 +
91051 } else {
91052 if (cow_page)
91053 mem_cgroup_uncharge_page(cow_page);
91054 @@ -3681,6 +3884,12 @@ static int handle_pte_fault(struct mm_struct *mm,
91055 if (flags & FAULT_FLAG_WRITE)
91056 flush_tlb_fix_spurious_fault(vma, address);
91057 }
91058 +
91059 +#ifdef CONFIG_PAX_SEGMEXEC
91060 + pax_mirror_pte(vma, address, pte, pmd, ptl);
91061 + return 0;
91062 +#endif
91063 +
91064 unlock:
91065 pte_unmap_unlock(pte, ptl);
91066 return 0;
91067 @@ -3697,9 +3906,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91068 pmd_t *pmd;
91069 pte_t *pte;
91070
91071 +#ifdef CONFIG_PAX_SEGMEXEC
91072 + struct vm_area_struct *vma_m;
91073 +#endif
91074 +
91075 if (unlikely(is_vm_hugetlb_page(vma)))
91076 return hugetlb_fault(mm, vma, address, flags);
91077
91078 +#ifdef CONFIG_PAX_SEGMEXEC
91079 + vma_m = pax_find_mirror_vma(vma);
91080 + if (vma_m) {
91081 + unsigned long address_m;
91082 + pgd_t *pgd_m;
91083 + pud_t *pud_m;
91084 + pmd_t *pmd_m;
91085 +
91086 + if (vma->vm_start > vma_m->vm_start) {
91087 + address_m = address;
91088 + address -= SEGMEXEC_TASK_SIZE;
91089 + vma = vma_m;
91090 + } else
91091 + address_m = address + SEGMEXEC_TASK_SIZE;
91092 +
91093 + pgd_m = pgd_offset(mm, address_m);
91094 + pud_m = pud_alloc(mm, pgd_m, address_m);
91095 + if (!pud_m)
91096 + return VM_FAULT_OOM;
91097 + pmd_m = pmd_alloc(mm, pud_m, address_m);
91098 + if (!pmd_m)
91099 + return VM_FAULT_OOM;
91100 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
91101 + return VM_FAULT_OOM;
91102 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
91103 + }
91104 +#endif
91105 +
91106 retry:
91107 pgd = pgd_offset(mm, address);
91108 pud = pud_alloc(mm, pgd, address);
91109 @@ -3838,6 +4079,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
91110 spin_unlock(&mm->page_table_lock);
91111 return 0;
91112 }
91113 +
91114 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
91115 +{
91116 + pud_t *new = pud_alloc_one(mm, address);
91117 + if (!new)
91118 + return -ENOMEM;
91119 +
91120 + smp_wmb(); /* See comment in __pte_alloc */
91121 +
91122 + spin_lock(&mm->page_table_lock);
91123 + if (pgd_present(*pgd)) /* Another has populated it */
91124 + pud_free(mm, new);
91125 + else
91126 + pgd_populate_kernel(mm, pgd, new);
91127 + spin_unlock(&mm->page_table_lock);
91128 + return 0;
91129 +}
91130 #endif /* __PAGETABLE_PUD_FOLDED */
91131
91132 #ifndef __PAGETABLE_PMD_FOLDED
91133 @@ -3868,6 +4126,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
91134 spin_unlock(&mm->page_table_lock);
91135 return 0;
91136 }
91137 +
91138 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
91139 +{
91140 + pmd_t *new = pmd_alloc_one(mm, address);
91141 + if (!new)
91142 + return -ENOMEM;
91143 +
91144 + smp_wmb(); /* See comment in __pte_alloc */
91145 +
91146 + spin_lock(&mm->page_table_lock);
91147 +#ifndef __ARCH_HAS_4LEVEL_HACK
91148 + if (pud_present(*pud)) /* Another has populated it */
91149 + pmd_free(mm, new);
91150 + else
91151 + pud_populate_kernel(mm, pud, new);
91152 +#else
91153 + if (pgd_present(*pud)) /* Another has populated it */
91154 + pmd_free(mm, new);
91155 + else
91156 + pgd_populate_kernel(mm, pud, new);
91157 +#endif /* __ARCH_HAS_4LEVEL_HACK */
91158 + spin_unlock(&mm->page_table_lock);
91159 + return 0;
91160 +}
91161 #endif /* __PAGETABLE_PMD_FOLDED */
91162
91163 #if !defined(__HAVE_ARCH_GATE_AREA)
91164 @@ -3881,7 +4163,7 @@ static int __init gate_vma_init(void)
91165 gate_vma.vm_start = FIXADDR_USER_START;
91166 gate_vma.vm_end = FIXADDR_USER_END;
91167 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
91168 - gate_vma.vm_page_prot = __P101;
91169 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
91170
91171 return 0;
91172 }
91173 @@ -4015,8 +4297,8 @@ out:
91174 return ret;
91175 }
91176
91177 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
91178 - void *buf, int len, int write)
91179 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
91180 + void *buf, size_t len, int write)
91181 {
91182 resource_size_t phys_addr;
91183 unsigned long prot = 0;
91184 @@ -4042,8 +4324,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
91185 * Access another process' address space as given in mm. If non-NULL, use the
91186 * given task for page fault accounting.
91187 */
91188 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91189 - unsigned long addr, void *buf, int len, int write)
91190 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91191 + unsigned long addr, void *buf, size_t len, int write)
91192 {
91193 struct vm_area_struct *vma;
91194 void *old_buf = buf;
91195 @@ -4051,7 +4333,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91196 down_read(&mm->mmap_sem);
91197 /* ignore errors, just check how much was successfully transferred */
91198 while (len) {
91199 - int bytes, ret, offset;
91200 + ssize_t bytes, ret, offset;
91201 void *maddr;
91202 struct page *page = NULL;
91203
91204 @@ -4110,8 +4392,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91205 *
91206 * The caller must hold a reference on @mm.
91207 */
91208 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
91209 - void *buf, int len, int write)
91210 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
91211 + void *buf, size_t len, int write)
91212 {
91213 return __access_remote_vm(NULL, mm, addr, buf, len, write);
91214 }
91215 @@ -4121,11 +4403,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
91216 * Source/target buffer must be kernel space,
91217 * Do not walk the page table directly, use get_user_pages
91218 */
91219 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
91220 - void *buf, int len, int write)
91221 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
91222 + void *buf, size_t len, int write)
91223 {
91224 struct mm_struct *mm;
91225 - int ret;
91226 + ssize_t ret;
91227
91228 mm = get_task_mm(tsk);
91229 if (!mm)
91230 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
91231 index 0cd2c4d..9558c83 100644
91232 --- a/mm/mempolicy.c
91233 +++ b/mm/mempolicy.c
91234 @@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
91235 unsigned long vmstart;
91236 unsigned long vmend;
91237
91238 +#ifdef CONFIG_PAX_SEGMEXEC
91239 + struct vm_area_struct *vma_m;
91240 +#endif
91241 +
91242 vma = find_vma(mm, start);
91243 if (!vma || vma->vm_start > start)
91244 return -EFAULT;
91245 @@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
91246 err = vma_replace_policy(vma, new_pol);
91247 if (err)
91248 goto out;
91249 +
91250 +#ifdef CONFIG_PAX_SEGMEXEC
91251 + vma_m = pax_find_mirror_vma(vma);
91252 + if (vma_m) {
91253 + err = vma_replace_policy(vma_m, new_pol);
91254 + if (err)
91255 + goto out;
91256 + }
91257 +#endif
91258 +
91259 }
91260
91261 out:
91262 @@ -1255,6 +1269,17 @@ static long do_mbind(unsigned long start, unsigned long len,
91263
91264 if (end < start)
91265 return -EINVAL;
91266 +
91267 +#ifdef CONFIG_PAX_SEGMEXEC
91268 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
91269 + if (end > SEGMEXEC_TASK_SIZE)
91270 + return -EINVAL;
91271 + } else
91272 +#endif
91273 +
91274 + if (end > TASK_SIZE)
91275 + return -EINVAL;
91276 +
91277 if (end == start)
91278 return 0;
91279
91280 @@ -1483,8 +1508,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
91281 */
91282 tcred = __task_cred(task);
91283 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
91284 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
91285 - !capable(CAP_SYS_NICE)) {
91286 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
91287 rcu_read_unlock();
91288 err = -EPERM;
91289 goto out_put;
91290 @@ -1515,6 +1539,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
91291 goto out;
91292 }
91293
91294 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
91295 + if (mm != current->mm &&
91296 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
91297 + mmput(mm);
91298 + err = -EPERM;
91299 + goto out;
91300 + }
91301 +#endif
91302 +
91303 err = do_migrate_pages(mm, old, new,
91304 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
91305
91306 diff --git a/mm/migrate.c b/mm/migrate.c
91307 index 9194375..75c81e2 100644
91308 --- a/mm/migrate.c
91309 +++ b/mm/migrate.c
91310 @@ -1464,8 +1464,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
91311 */
91312 tcred = __task_cred(task);
91313 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
91314 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
91315 - !capable(CAP_SYS_NICE)) {
91316 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
91317 rcu_read_unlock();
91318 err = -EPERM;
91319 goto out;
91320 diff --git a/mm/mlock.c b/mm/mlock.c
91321 index 192e6ee..b044449 100644
91322 --- a/mm/mlock.c
91323 +++ b/mm/mlock.c
91324 @@ -14,6 +14,7 @@
91325 #include <linux/pagevec.h>
91326 #include <linux/mempolicy.h>
91327 #include <linux/syscalls.h>
91328 +#include <linux/security.h>
91329 #include <linux/sched.h>
91330 #include <linux/export.h>
91331 #include <linux/rmap.h>
91332 @@ -588,7 +589,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
91333 {
91334 unsigned long nstart, end, tmp;
91335 struct vm_area_struct * vma, * prev;
91336 - int error;
91337 + int error = 0;
91338
91339 VM_BUG_ON(start & ~PAGE_MASK);
91340 VM_BUG_ON(len != PAGE_ALIGN(len));
91341 @@ -597,6 +598,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
91342 return -EINVAL;
91343 if (end == start)
91344 return 0;
91345 + if (end > TASK_SIZE)
91346 + return -EINVAL;
91347 +
91348 vma = find_vma(current->mm, start);
91349 if (!vma || vma->vm_start > start)
91350 return -ENOMEM;
91351 @@ -608,6 +612,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
91352 for (nstart = start ; ; ) {
91353 vm_flags_t newflags;
91354
91355 +#ifdef CONFIG_PAX_SEGMEXEC
91356 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
91357 + break;
91358 +#endif
91359 +
91360 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
91361
91362 newflags = vma->vm_flags & ~VM_LOCKED;
91363 @@ -720,6 +729,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
91364 lock_limit >>= PAGE_SHIFT;
91365
91366 /* check against resource limits */
91367 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
91368 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
91369 error = do_mlock(start, len, 1);
91370 up_write(&current->mm->mmap_sem);
91371 @@ -754,6 +764,11 @@ static int do_mlockall(int flags)
91372 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
91373 vm_flags_t newflags;
91374
91375 +#ifdef CONFIG_PAX_SEGMEXEC
91376 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
91377 + break;
91378 +#endif
91379 +
91380 newflags = vma->vm_flags & ~VM_LOCKED;
91381 if (flags & MCL_CURRENT)
91382 newflags |= VM_LOCKED;
91383 @@ -787,6 +802,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
91384 lock_limit >>= PAGE_SHIFT;
91385
91386 ret = -ENOMEM;
91387 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
91388 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
91389 capable(CAP_IPC_LOCK))
91390 ret = do_mlockall(flags);
91391 diff --git a/mm/mmap.c b/mm/mmap.c
91392 index 834b2d7..650d1b9 100644
91393 --- a/mm/mmap.c
91394 +++ b/mm/mmap.c
91395 @@ -36,6 +36,7 @@
91396 #include <linux/sched/sysctl.h>
91397 #include <linux/notifier.h>
91398 #include <linux/memory.h>
91399 +#include <linux/random.h>
91400
91401 #include <asm/uaccess.h>
91402 #include <asm/cacheflush.h>
91403 @@ -52,6 +53,16 @@
91404 #define arch_rebalance_pgtables(addr, len) (addr)
91405 #endif
91406
91407 +static inline void verify_mm_writelocked(struct mm_struct *mm)
91408 +{
91409 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
91410 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
91411 + up_read(&mm->mmap_sem);
91412 + BUG();
91413 + }
91414 +#endif
91415 +}
91416 +
91417 static void unmap_region(struct mm_struct *mm,
91418 struct vm_area_struct *vma, struct vm_area_struct *prev,
91419 unsigned long start, unsigned long end);
91420 @@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
91421 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
91422 *
91423 */
91424 -pgprot_t protection_map[16] = {
91425 +pgprot_t protection_map[16] __read_only = {
91426 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
91427 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
91428 };
91429
91430 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
91431 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
91432 {
91433 - return __pgprot(pgprot_val(protection_map[vm_flags &
91434 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
91435 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
91436 pgprot_val(arch_vm_get_page_prot(vm_flags)));
91437 +
91438 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91439 + if (!(__supported_pte_mask & _PAGE_NX) &&
91440 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
91441 + (vm_flags & (VM_READ | VM_WRITE)))
91442 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
91443 +#endif
91444 +
91445 + return prot;
91446 }
91447 EXPORT_SYMBOL(vm_get_page_prot);
91448
91449 @@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
91450 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
91451 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
91452 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
91453 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
91454 /*
91455 * Make sure vm_committed_as in one cacheline and not cacheline shared with
91456 * other variables. It can be updated by several CPUs frequently.
91457 @@ -245,6 +266,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
91458 struct vm_area_struct *next = vma->vm_next;
91459
91460 might_sleep();
91461 + BUG_ON(vma->vm_mirror);
91462 if (vma->vm_ops && vma->vm_ops->close)
91463 vma->vm_ops->close(vma);
91464 if (vma->vm_file)
91465 @@ -289,6 +311,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
91466 * not page aligned -Ram Gupta
91467 */
91468 rlim = rlimit(RLIMIT_DATA);
91469 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
91470 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
91471 (mm->end_data - mm->start_data) > rlim)
91472 goto out;
91473 @@ -893,7 +916,15 @@ again: remove_next = 1 + (end > next->vm_end);
91474 static inline int is_mergeable_vma(struct vm_area_struct *vma,
91475 struct file *file, unsigned long vm_flags)
91476 {
91477 - if (vma->vm_flags ^ vm_flags)
91478 + /*
91479 + * VM_SOFTDIRTY should not prevent from VMA merging, if we
91480 + * match the flags but dirty bit -- the caller should mark
91481 + * merged VMA as dirty. If dirty bit won't be excluded from
91482 + * comparison, we increase pressue on the memory system forcing
91483 + * the kernel to generate new VMAs when old one could be
91484 + * extended instead.
91485 + */
91486 + if ((vma->vm_flags ^ vm_flags) & ~VM_SOFTDIRTY)
91487 return 0;
91488 if (vma->vm_file != file)
91489 return 0;
91490 @@ -931,6 +962,12 @@ static int
91491 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
91492 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
91493 {
91494 +
91495 +#ifdef CONFIG_PAX_SEGMEXEC
91496 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
91497 + return 0;
91498 +#endif
91499 +
91500 if (is_mergeable_vma(vma, file, vm_flags) &&
91501 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
91502 if (vma->vm_pgoff == vm_pgoff)
91503 @@ -950,6 +987,12 @@ static int
91504 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
91505 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
91506 {
91507 +
91508 +#ifdef CONFIG_PAX_SEGMEXEC
91509 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
91510 + return 0;
91511 +#endif
91512 +
91513 if (is_mergeable_vma(vma, file, vm_flags) &&
91514 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
91515 pgoff_t vm_pglen;
91516 @@ -992,13 +1035,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
91517 struct vm_area_struct *vma_merge(struct mm_struct *mm,
91518 struct vm_area_struct *prev, unsigned long addr,
91519 unsigned long end, unsigned long vm_flags,
91520 - struct anon_vma *anon_vma, struct file *file,
91521 + struct anon_vma *anon_vma, struct file *file,
91522 pgoff_t pgoff, struct mempolicy *policy)
91523 {
91524 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
91525 struct vm_area_struct *area, *next;
91526 int err;
91527
91528 +#ifdef CONFIG_PAX_SEGMEXEC
91529 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
91530 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
91531 +
91532 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
91533 +#endif
91534 +
91535 /*
91536 * We later require that vma->vm_flags == vm_flags,
91537 * so this tests vma->vm_flags & VM_SPECIAL, too.
91538 @@ -1014,6 +1064,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91539 if (next && next->vm_end == end) /* cases 6, 7, 8 */
91540 next = next->vm_next;
91541
91542 +#ifdef CONFIG_PAX_SEGMEXEC
91543 + if (prev)
91544 + prev_m = pax_find_mirror_vma(prev);
91545 + if (area)
91546 + area_m = pax_find_mirror_vma(area);
91547 + if (next)
91548 + next_m = pax_find_mirror_vma(next);
91549 +#endif
91550 +
91551 /*
91552 * Can it merge with the predecessor?
91553 */
91554 @@ -1033,9 +1092,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91555 /* cases 1, 6 */
91556 err = vma_adjust(prev, prev->vm_start,
91557 next->vm_end, prev->vm_pgoff, NULL);
91558 - } else /* cases 2, 5, 7 */
91559 +
91560 +#ifdef CONFIG_PAX_SEGMEXEC
91561 + if (!err && prev_m)
91562 + err = vma_adjust(prev_m, prev_m->vm_start,
91563 + next_m->vm_end, prev_m->vm_pgoff, NULL);
91564 +#endif
91565 +
91566 + } else { /* cases 2, 5, 7 */
91567 err = vma_adjust(prev, prev->vm_start,
91568 end, prev->vm_pgoff, NULL);
91569 +
91570 +#ifdef CONFIG_PAX_SEGMEXEC
91571 + if (!err && prev_m)
91572 + err = vma_adjust(prev_m, prev_m->vm_start,
91573 + end_m, prev_m->vm_pgoff, NULL);
91574 +#endif
91575 +
91576 + }
91577 if (err)
91578 return NULL;
91579 khugepaged_enter_vma_merge(prev);
91580 @@ -1049,12 +1123,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91581 mpol_equal(policy, vma_policy(next)) &&
91582 can_vma_merge_before(next, vm_flags,
91583 anon_vma, file, pgoff+pglen)) {
91584 - if (prev && addr < prev->vm_end) /* case 4 */
91585 + if (prev && addr < prev->vm_end) { /* case 4 */
91586 err = vma_adjust(prev, prev->vm_start,
91587 addr, prev->vm_pgoff, NULL);
91588 - else /* cases 3, 8 */
91589 +
91590 +#ifdef CONFIG_PAX_SEGMEXEC
91591 + if (!err && prev_m)
91592 + err = vma_adjust(prev_m, prev_m->vm_start,
91593 + addr_m, prev_m->vm_pgoff, NULL);
91594 +#endif
91595 +
91596 + } else { /* cases 3, 8 */
91597 err = vma_adjust(area, addr, next->vm_end,
91598 next->vm_pgoff - pglen, NULL);
91599 +
91600 +#ifdef CONFIG_PAX_SEGMEXEC
91601 + if (!err && area_m)
91602 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
91603 + next_m->vm_pgoff - pglen, NULL);
91604 +#endif
91605 +
91606 + }
91607 if (err)
91608 return NULL;
91609 khugepaged_enter_vma_merge(area);
91610 @@ -1082,7 +1171,7 @@ static int anon_vma_compatible(struct vm_area_struct *a, struct vm_area_struct *
91611 return a->vm_end == b->vm_start &&
91612 mpol_equal(vma_policy(a), vma_policy(b)) &&
91613 a->vm_file == b->vm_file &&
91614 - !((a->vm_flags ^ b->vm_flags) & ~(VM_READ|VM_WRITE|VM_EXEC)) &&
91615 + !((a->vm_flags ^ b->vm_flags) & ~(VM_READ|VM_WRITE|VM_EXEC|VM_SOFTDIRTY)) &&
91616 b->vm_pgoff == a->vm_pgoff + ((b->vm_start - a->vm_start) >> PAGE_SHIFT);
91617 }
91618
91619 @@ -1163,8 +1252,10 @@ none:
91620 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
91621 struct file *file, long pages)
91622 {
91623 - const unsigned long stack_flags
91624 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
91625 +
91626 +#ifdef CONFIG_PAX_RANDMMAP
91627 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
91628 +#endif
91629
91630 mm->total_vm += pages;
91631
91632 @@ -1172,7 +1263,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
91633 mm->shared_vm += pages;
91634 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
91635 mm->exec_vm += pages;
91636 - } else if (flags & stack_flags)
91637 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
91638 mm->stack_vm += pages;
91639 }
91640 #endif /* CONFIG_PROC_FS */
91641 @@ -1210,7 +1301,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91642 * (the exception is when the underlying filesystem is noexec
91643 * mounted, in which case we dont add PROT_EXEC.)
91644 */
91645 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
91646 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
91647 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
91648 prot |= PROT_EXEC;
91649
91650 @@ -1236,7 +1327,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91651 /* Obtain the address to map to. we verify (or select) it and ensure
91652 * that it represents a valid section of the address space.
91653 */
91654 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
91655 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
91656 if (addr & ~PAGE_MASK)
91657 return addr;
91658
91659 @@ -1247,6 +1338,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91660 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
91661 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
91662
91663 +#ifdef CONFIG_PAX_MPROTECT
91664 + if (mm->pax_flags & MF_PAX_MPROTECT) {
91665 +
91666 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
91667 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
91668 + mm->binfmt->handle_mmap)
91669 + mm->binfmt->handle_mmap(file);
91670 +#endif
91671 +
91672 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
91673 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
91674 + gr_log_rwxmmap(file);
91675 +
91676 +#ifdef CONFIG_PAX_EMUPLT
91677 + vm_flags &= ~VM_EXEC;
91678 +#else
91679 + return -EPERM;
91680 +#endif
91681 +
91682 + }
91683 +
91684 + if (!(vm_flags & VM_EXEC))
91685 + vm_flags &= ~VM_MAYEXEC;
91686 +#else
91687 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
91688 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
91689 +#endif
91690 + else
91691 + vm_flags &= ~VM_MAYWRITE;
91692 + }
91693 +#endif
91694 +
91695 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91696 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
91697 + vm_flags &= ~VM_PAGEEXEC;
91698 +#endif
91699 +
91700 if (flags & MAP_LOCKED)
91701 if (!can_do_mlock())
91702 return -EPERM;
91703 @@ -1258,6 +1386,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91704 locked += mm->locked_vm;
91705 lock_limit = rlimit(RLIMIT_MEMLOCK);
91706 lock_limit >>= PAGE_SHIFT;
91707 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
91708 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
91709 return -EAGAIN;
91710 }
91711 @@ -1342,6 +1471,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91712 vm_flags |= VM_NORESERVE;
91713 }
91714
91715 + if (!gr_acl_handle_mmap(file, prot))
91716 + return -EACCES;
91717 +
91718 addr = mmap_region(file, addr, len, vm_flags, pgoff);
91719 if (!IS_ERR_VALUE(addr) &&
91720 ((vm_flags & VM_LOCKED) ||
91721 @@ -1435,7 +1567,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
91722 vm_flags_t vm_flags = vma->vm_flags;
91723
91724 /* If it was private or non-writable, the write bit is already clear */
91725 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
91726 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
91727 return 0;
91728
91729 /* The backer wishes to know when pages are first written to? */
91730 @@ -1481,7 +1613,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
91731 struct rb_node **rb_link, *rb_parent;
91732 unsigned long charged = 0;
91733
91734 +#ifdef CONFIG_PAX_SEGMEXEC
91735 + struct vm_area_struct *vma_m = NULL;
91736 +#endif
91737 +
91738 + /*
91739 + * mm->mmap_sem is required to protect against another thread
91740 + * changing the mappings in case we sleep.
91741 + */
91742 + verify_mm_writelocked(mm);
91743 +
91744 /* Check against address space limit. */
91745 +
91746 +#ifdef CONFIG_PAX_RANDMMAP
91747 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
91748 +#endif
91749 +
91750 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
91751 unsigned long nr_pages;
91752
91753 @@ -1500,11 +1647,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
91754
91755 /* Clear old maps */
91756 error = -ENOMEM;
91757 -munmap_back:
91758 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
91759 if (do_munmap(mm, addr, len))
91760 return -ENOMEM;
91761 - goto munmap_back;
91762 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
91763 }
91764
91765 /*
91766 @@ -1535,6 +1681,16 @@ munmap_back:
91767 goto unacct_error;
91768 }
91769
91770 +#ifdef CONFIG_PAX_SEGMEXEC
91771 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
91772 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
91773 + if (!vma_m) {
91774 + error = -ENOMEM;
91775 + goto free_vma;
91776 + }
91777 + }
91778 +#endif
91779 +
91780 vma->vm_mm = mm;
91781 vma->vm_start = addr;
91782 vma->vm_end = addr + len;
91783 @@ -1554,6 +1710,13 @@ munmap_back:
91784 if (error)
91785 goto unmap_and_free_vma;
91786
91787 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91788 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
91789 + vma->vm_flags |= VM_PAGEEXEC;
91790 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
91791 + }
91792 +#endif
91793 +
91794 /* Can addr have changed??
91795 *
91796 * Answer: Yes, several device drivers can do it in their
91797 @@ -1587,6 +1750,12 @@ munmap_back:
91798 }
91799
91800 vma_link(mm, vma, prev, rb_link, rb_parent);
91801 +
91802 +#ifdef CONFIG_PAX_SEGMEXEC
91803 + if (vma_m)
91804 + BUG_ON(pax_mirror_vma(vma_m, vma));
91805 +#endif
91806 +
91807 /* Once vma denies write, undo our temporary denial count */
91808 if (vm_flags & VM_DENYWRITE)
91809 allow_write_access(file);
91810 @@ -1595,6 +1764,7 @@ out:
91811 perf_event_mmap(vma);
91812
91813 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
91814 + track_exec_limit(mm, addr, addr + len, vm_flags);
91815 if (vm_flags & VM_LOCKED) {
91816 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
91817 vma == get_gate_vma(current->mm)))
91818 @@ -1627,6 +1797,12 @@ unmap_and_free_vma:
91819 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
91820 charged = 0;
91821 free_vma:
91822 +
91823 +#ifdef CONFIG_PAX_SEGMEXEC
91824 + if (vma_m)
91825 + kmem_cache_free(vm_area_cachep, vma_m);
91826 +#endif
91827 +
91828 kmem_cache_free(vm_area_cachep, vma);
91829 unacct_error:
91830 if (charged)
91831 @@ -1634,7 +1810,63 @@ unacct_error:
91832 return error;
91833 }
91834
91835 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
91836 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
91837 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
91838 +{
91839 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
91840 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
91841 +
91842 + return 0;
91843 +}
91844 +#endif
91845 +
91846 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
91847 +{
91848 + if (!vma) {
91849 +#ifdef CONFIG_STACK_GROWSUP
91850 + if (addr > sysctl_heap_stack_gap)
91851 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
91852 + else
91853 + vma = find_vma(current->mm, 0);
91854 + if (vma && (vma->vm_flags & VM_GROWSUP))
91855 + return false;
91856 +#endif
91857 + return true;
91858 + }
91859 +
91860 + if (addr + len > vma->vm_start)
91861 + return false;
91862 +
91863 + if (vma->vm_flags & VM_GROWSDOWN)
91864 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
91865 +#ifdef CONFIG_STACK_GROWSUP
91866 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
91867 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
91868 +#endif
91869 + else if (offset)
91870 + return offset <= vma->vm_start - addr - len;
91871 +
91872 + return true;
91873 +}
91874 +
91875 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
91876 +{
91877 + if (vma->vm_start < len)
91878 + return -ENOMEM;
91879 +
91880 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
91881 + if (offset <= vma->vm_start - len)
91882 + return vma->vm_start - len - offset;
91883 + else
91884 + return -ENOMEM;
91885 + }
91886 +
91887 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
91888 + return vma->vm_start - len - sysctl_heap_stack_gap;
91889 + return -ENOMEM;
91890 +}
91891 +
91892 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
91893 {
91894 /*
91895 * We implement the search by looking for an rbtree node that
91896 @@ -1682,11 +1914,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
91897 }
91898 }
91899
91900 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
91901 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
91902 check_current:
91903 /* Check if current node has a suitable gap */
91904 if (gap_start > high_limit)
91905 return -ENOMEM;
91906 +
91907 + if (gap_end - gap_start > info->threadstack_offset)
91908 + gap_start += info->threadstack_offset;
91909 + else
91910 + gap_start = gap_end;
91911 +
91912 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
91913 + if (gap_end - gap_start > sysctl_heap_stack_gap)
91914 + gap_start += sysctl_heap_stack_gap;
91915 + else
91916 + gap_start = gap_end;
91917 + }
91918 + if (vma->vm_flags & VM_GROWSDOWN) {
91919 + if (gap_end - gap_start > sysctl_heap_stack_gap)
91920 + gap_end -= sysctl_heap_stack_gap;
91921 + else
91922 + gap_end = gap_start;
91923 + }
91924 if (gap_end >= low_limit && gap_end - gap_start >= length)
91925 goto found;
91926
91927 @@ -1736,7 +1986,7 @@ found:
91928 return gap_start;
91929 }
91930
91931 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
91932 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
91933 {
91934 struct mm_struct *mm = current->mm;
91935 struct vm_area_struct *vma;
91936 @@ -1790,6 +2040,24 @@ check_current:
91937 gap_end = vma->vm_start;
91938 if (gap_end < low_limit)
91939 return -ENOMEM;
91940 +
91941 + if (gap_end - gap_start > info->threadstack_offset)
91942 + gap_end -= info->threadstack_offset;
91943 + else
91944 + gap_end = gap_start;
91945 +
91946 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
91947 + if (gap_end - gap_start > sysctl_heap_stack_gap)
91948 + gap_start += sysctl_heap_stack_gap;
91949 + else
91950 + gap_start = gap_end;
91951 + }
91952 + if (vma->vm_flags & VM_GROWSDOWN) {
91953 + if (gap_end - gap_start > sysctl_heap_stack_gap)
91954 + gap_end -= sysctl_heap_stack_gap;
91955 + else
91956 + gap_end = gap_start;
91957 + }
91958 if (gap_start <= high_limit && gap_end - gap_start >= length)
91959 goto found;
91960
91961 @@ -1853,6 +2121,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
91962 struct mm_struct *mm = current->mm;
91963 struct vm_area_struct *vma;
91964 struct vm_unmapped_area_info info;
91965 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
91966
91967 if (len > TASK_SIZE - mmap_min_addr)
91968 return -ENOMEM;
91969 @@ -1860,11 +2129,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
91970 if (flags & MAP_FIXED)
91971 return addr;
91972
91973 +#ifdef CONFIG_PAX_RANDMMAP
91974 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
91975 +#endif
91976 +
91977 if (addr) {
91978 addr = PAGE_ALIGN(addr);
91979 vma = find_vma(mm, addr);
91980 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
91981 - (!vma || addr + len <= vma->vm_start))
91982 + check_heap_stack_gap(vma, addr, len, offset))
91983 return addr;
91984 }
91985
91986 @@ -1873,6 +2146,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
91987 info.low_limit = mm->mmap_base;
91988 info.high_limit = TASK_SIZE;
91989 info.align_mask = 0;
91990 + info.threadstack_offset = offset;
91991 return vm_unmapped_area(&info);
91992 }
91993 #endif
91994 @@ -1891,6 +2165,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
91995 struct mm_struct *mm = current->mm;
91996 unsigned long addr = addr0;
91997 struct vm_unmapped_area_info info;
91998 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
91999
92000 /* requested length too big for entire address space */
92001 if (len > TASK_SIZE - mmap_min_addr)
92002 @@ -1899,12 +2174,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92003 if (flags & MAP_FIXED)
92004 return addr;
92005
92006 +#ifdef CONFIG_PAX_RANDMMAP
92007 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
92008 +#endif
92009 +
92010 /* requesting a specific address */
92011 if (addr) {
92012 addr = PAGE_ALIGN(addr);
92013 vma = find_vma(mm, addr);
92014 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
92015 - (!vma || addr + len <= vma->vm_start))
92016 + check_heap_stack_gap(vma, addr, len, offset))
92017 return addr;
92018 }
92019
92020 @@ -1913,6 +2192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92021 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
92022 info.high_limit = mm->mmap_base;
92023 info.align_mask = 0;
92024 + info.threadstack_offset = offset;
92025 addr = vm_unmapped_area(&info);
92026
92027 /*
92028 @@ -1925,6 +2205,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92029 VM_BUG_ON(addr != -ENOMEM);
92030 info.flags = 0;
92031 info.low_limit = TASK_UNMAPPED_BASE;
92032 +
92033 +#ifdef CONFIG_PAX_RANDMMAP
92034 + if (mm->pax_flags & MF_PAX_RANDMMAP)
92035 + info.low_limit += mm->delta_mmap;
92036 +#endif
92037 +
92038 info.high_limit = TASK_SIZE;
92039 addr = vm_unmapped_area(&info);
92040 }
92041 @@ -2026,6 +2312,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
92042 return vma;
92043 }
92044
92045 +#ifdef CONFIG_PAX_SEGMEXEC
92046 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
92047 +{
92048 + struct vm_area_struct *vma_m;
92049 +
92050 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
92051 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
92052 + BUG_ON(vma->vm_mirror);
92053 + return NULL;
92054 + }
92055 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
92056 + vma_m = vma->vm_mirror;
92057 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
92058 + BUG_ON(vma->vm_file != vma_m->vm_file);
92059 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
92060 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
92061 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
92062 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
92063 + return vma_m;
92064 +}
92065 +#endif
92066 +
92067 /*
92068 * Verify that the stack growth is acceptable and
92069 * update accounting. This is shared with both the
92070 @@ -2042,6 +2350,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92071 return -ENOMEM;
92072
92073 /* Stack limit test */
92074 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
92075 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
92076 return -ENOMEM;
92077
92078 @@ -2052,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92079 locked = mm->locked_vm + grow;
92080 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
92081 limit >>= PAGE_SHIFT;
92082 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
92083 if (locked > limit && !capable(CAP_IPC_LOCK))
92084 return -ENOMEM;
92085 }
92086 @@ -2081,37 +2391,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92087 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
92088 * vma is the last one with address > vma->vm_end. Have to extend vma.
92089 */
92090 +#ifndef CONFIG_IA64
92091 +static
92092 +#endif
92093 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
92094 {
92095 int error;
92096 + bool locknext;
92097
92098 if (!(vma->vm_flags & VM_GROWSUP))
92099 return -EFAULT;
92100
92101 + /* Also guard against wrapping around to address 0. */
92102 + if (address < PAGE_ALIGN(address+1))
92103 + address = PAGE_ALIGN(address+1);
92104 + else
92105 + return -ENOMEM;
92106 +
92107 /*
92108 * We must make sure the anon_vma is allocated
92109 * so that the anon_vma locking is not a noop.
92110 */
92111 if (unlikely(anon_vma_prepare(vma)))
92112 return -ENOMEM;
92113 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
92114 + if (locknext && anon_vma_prepare(vma->vm_next))
92115 + return -ENOMEM;
92116 vma_lock_anon_vma(vma);
92117 + if (locknext)
92118 + vma_lock_anon_vma(vma->vm_next);
92119
92120 /*
92121 * vma->vm_start/vm_end cannot change under us because the caller
92122 * is required to hold the mmap_sem in read mode. We need the
92123 - * anon_vma lock to serialize against concurrent expand_stacks.
92124 - * Also guard against wrapping around to address 0.
92125 + * anon_vma locks to serialize against concurrent expand_stacks
92126 + * and expand_upwards.
92127 */
92128 - if (address < PAGE_ALIGN(address+4))
92129 - address = PAGE_ALIGN(address+4);
92130 - else {
92131 - vma_unlock_anon_vma(vma);
92132 - return -ENOMEM;
92133 - }
92134 error = 0;
92135
92136 /* Somebody else might have raced and expanded it already */
92137 - if (address > vma->vm_end) {
92138 + 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)
92139 + error = -ENOMEM;
92140 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
92141 unsigned long size, grow;
92142
92143 size = address - vma->vm_start;
92144 @@ -2146,6 +2467,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
92145 }
92146 }
92147 }
92148 + if (locknext)
92149 + vma_unlock_anon_vma(vma->vm_next);
92150 vma_unlock_anon_vma(vma);
92151 khugepaged_enter_vma_merge(vma);
92152 validate_mm(vma->vm_mm);
92153 @@ -2160,6 +2483,8 @@ int expand_downwards(struct vm_area_struct *vma,
92154 unsigned long address)
92155 {
92156 int error;
92157 + bool lockprev = false;
92158 + struct vm_area_struct *prev;
92159
92160 /*
92161 * We must make sure the anon_vma is allocated
92162 @@ -2173,6 +2498,15 @@ int expand_downwards(struct vm_area_struct *vma,
92163 if (error)
92164 return error;
92165
92166 + prev = vma->vm_prev;
92167 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
92168 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
92169 +#endif
92170 + if (lockprev && anon_vma_prepare(prev))
92171 + return -ENOMEM;
92172 + if (lockprev)
92173 + vma_lock_anon_vma(prev);
92174 +
92175 vma_lock_anon_vma(vma);
92176
92177 /*
92178 @@ -2182,9 +2516,17 @@ int expand_downwards(struct vm_area_struct *vma,
92179 */
92180
92181 /* Somebody else might have raced and expanded it already */
92182 - if (address < vma->vm_start) {
92183 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
92184 + error = -ENOMEM;
92185 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
92186 unsigned long size, grow;
92187
92188 +#ifdef CONFIG_PAX_SEGMEXEC
92189 + struct vm_area_struct *vma_m;
92190 +
92191 + vma_m = pax_find_mirror_vma(vma);
92192 +#endif
92193 +
92194 size = vma->vm_end - address;
92195 grow = (vma->vm_start - address) >> PAGE_SHIFT;
92196
92197 @@ -2209,13 +2551,27 @@ int expand_downwards(struct vm_area_struct *vma,
92198 vma->vm_pgoff -= grow;
92199 anon_vma_interval_tree_post_update_vma(vma);
92200 vma_gap_update(vma);
92201 +
92202 +#ifdef CONFIG_PAX_SEGMEXEC
92203 + if (vma_m) {
92204 + anon_vma_interval_tree_pre_update_vma(vma_m);
92205 + vma_m->vm_start -= grow << PAGE_SHIFT;
92206 + vma_m->vm_pgoff -= grow;
92207 + anon_vma_interval_tree_post_update_vma(vma_m);
92208 + vma_gap_update(vma_m);
92209 + }
92210 +#endif
92211 +
92212 spin_unlock(&vma->vm_mm->page_table_lock);
92213
92214 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
92215 perf_event_mmap(vma);
92216 }
92217 }
92218 }
92219 vma_unlock_anon_vma(vma);
92220 + if (lockprev)
92221 + vma_unlock_anon_vma(prev);
92222 khugepaged_enter_vma_merge(vma);
92223 validate_mm(vma->vm_mm);
92224 return error;
92225 @@ -2313,6 +2669,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
92226 do {
92227 long nrpages = vma_pages(vma);
92228
92229 +#ifdef CONFIG_PAX_SEGMEXEC
92230 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
92231 + vma = remove_vma(vma);
92232 + continue;
92233 + }
92234 +#endif
92235 +
92236 if (vma->vm_flags & VM_ACCOUNT)
92237 nr_accounted += nrpages;
92238 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
92239 @@ -2357,6 +2720,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
92240 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
92241 vma->vm_prev = NULL;
92242 do {
92243 +
92244 +#ifdef CONFIG_PAX_SEGMEXEC
92245 + if (vma->vm_mirror) {
92246 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
92247 + vma->vm_mirror->vm_mirror = NULL;
92248 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
92249 + vma->vm_mirror = NULL;
92250 + }
92251 +#endif
92252 +
92253 vma_rb_erase(vma, &mm->mm_rb);
92254 mm->map_count--;
92255 tail_vma = vma;
92256 @@ -2382,14 +2755,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92257 struct vm_area_struct *new;
92258 int err = -ENOMEM;
92259
92260 +#ifdef CONFIG_PAX_SEGMEXEC
92261 + struct vm_area_struct *vma_m, *new_m = NULL;
92262 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
92263 +#endif
92264 +
92265 if (is_vm_hugetlb_page(vma) && (addr &
92266 ~(huge_page_mask(hstate_vma(vma)))))
92267 return -EINVAL;
92268
92269 +#ifdef CONFIG_PAX_SEGMEXEC
92270 + vma_m = pax_find_mirror_vma(vma);
92271 +#endif
92272 +
92273 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
92274 if (!new)
92275 goto out_err;
92276
92277 +#ifdef CONFIG_PAX_SEGMEXEC
92278 + if (vma_m) {
92279 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
92280 + if (!new_m) {
92281 + kmem_cache_free(vm_area_cachep, new);
92282 + goto out_err;
92283 + }
92284 + }
92285 +#endif
92286 +
92287 /* most fields are the same, copy all, and then fixup */
92288 *new = *vma;
92289
92290 @@ -2402,6 +2794,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92291 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
92292 }
92293
92294 +#ifdef CONFIG_PAX_SEGMEXEC
92295 + if (vma_m) {
92296 + *new_m = *vma_m;
92297 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
92298 + new_m->vm_mirror = new;
92299 + new->vm_mirror = new_m;
92300 +
92301 + if (new_below)
92302 + new_m->vm_end = addr_m;
92303 + else {
92304 + new_m->vm_start = addr_m;
92305 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
92306 + }
92307 + }
92308 +#endif
92309 +
92310 err = vma_dup_policy(vma, new);
92311 if (err)
92312 goto out_free_vma;
92313 @@ -2421,6 +2829,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92314 else
92315 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
92316
92317 +#ifdef CONFIG_PAX_SEGMEXEC
92318 + if (!err && vma_m) {
92319 + struct mempolicy *pol = vma_policy(new);
92320 +
92321 + if (anon_vma_clone(new_m, vma_m))
92322 + goto out_free_mpol;
92323 +
92324 + mpol_get(pol);
92325 + set_vma_policy(new_m, pol);
92326 +
92327 + if (new_m->vm_file)
92328 + get_file(new_m->vm_file);
92329 +
92330 + if (new_m->vm_ops && new_m->vm_ops->open)
92331 + new_m->vm_ops->open(new_m);
92332 +
92333 + if (new_below)
92334 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
92335 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
92336 + else
92337 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
92338 +
92339 + if (err) {
92340 + if (new_m->vm_ops && new_m->vm_ops->close)
92341 + new_m->vm_ops->close(new_m);
92342 + if (new_m->vm_file)
92343 + fput(new_m->vm_file);
92344 + mpol_put(pol);
92345 + }
92346 + }
92347 +#endif
92348 +
92349 /* Success. */
92350 if (!err)
92351 return 0;
92352 @@ -2430,10 +2870,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92353 new->vm_ops->close(new);
92354 if (new->vm_file)
92355 fput(new->vm_file);
92356 - unlink_anon_vmas(new);
92357 out_free_mpol:
92358 mpol_put(vma_policy(new));
92359 out_free_vma:
92360 +
92361 +#ifdef CONFIG_PAX_SEGMEXEC
92362 + if (new_m) {
92363 + unlink_anon_vmas(new_m);
92364 + kmem_cache_free(vm_area_cachep, new_m);
92365 + }
92366 +#endif
92367 +
92368 + unlink_anon_vmas(new);
92369 kmem_cache_free(vm_area_cachep, new);
92370 out_err:
92371 return err;
92372 @@ -2446,6 +2894,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92373 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
92374 unsigned long addr, int new_below)
92375 {
92376 +
92377 +#ifdef CONFIG_PAX_SEGMEXEC
92378 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92379 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
92380 + if (mm->map_count >= sysctl_max_map_count-1)
92381 + return -ENOMEM;
92382 + } else
92383 +#endif
92384 +
92385 if (mm->map_count >= sysctl_max_map_count)
92386 return -ENOMEM;
92387
92388 @@ -2457,11 +2914,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
92389 * work. This now handles partial unmappings.
92390 * Jeremy Fitzhardinge <jeremy@goop.org>
92391 */
92392 +#ifdef CONFIG_PAX_SEGMEXEC
92393 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92394 {
92395 + int ret = __do_munmap(mm, start, len);
92396 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
92397 + return ret;
92398 +
92399 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
92400 +}
92401 +
92402 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92403 +#else
92404 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92405 +#endif
92406 +{
92407 unsigned long end;
92408 struct vm_area_struct *vma, *prev, *last;
92409
92410 + /*
92411 + * mm->mmap_sem is required to protect against another thread
92412 + * changing the mappings in case we sleep.
92413 + */
92414 + verify_mm_writelocked(mm);
92415 +
92416 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
92417 return -EINVAL;
92418
92419 @@ -2536,6 +3012,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92420 /* Fix up all other VM information */
92421 remove_vma_list(mm, vma);
92422
92423 + track_exec_limit(mm, start, end, 0UL);
92424 +
92425 return 0;
92426 }
92427
92428 @@ -2544,6 +3022,13 @@ int vm_munmap(unsigned long start, size_t len)
92429 int ret;
92430 struct mm_struct *mm = current->mm;
92431
92432 +
92433 +#ifdef CONFIG_PAX_SEGMEXEC
92434 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
92435 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
92436 + return -EINVAL;
92437 +#endif
92438 +
92439 down_write(&mm->mmap_sem);
92440 ret = do_munmap(mm, start, len);
92441 up_write(&mm->mmap_sem);
92442 @@ -2557,16 +3042,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
92443 return vm_munmap(addr, len);
92444 }
92445
92446 -static inline void verify_mm_writelocked(struct mm_struct *mm)
92447 -{
92448 -#ifdef CONFIG_DEBUG_VM
92449 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
92450 - WARN_ON(1);
92451 - up_read(&mm->mmap_sem);
92452 - }
92453 -#endif
92454 -}
92455 -
92456 /*
92457 * this is really a simplified "do_mmap". it only handles
92458 * anonymous maps. eventually we may be able to do some
92459 @@ -2580,6 +3055,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92460 struct rb_node ** rb_link, * rb_parent;
92461 pgoff_t pgoff = addr >> PAGE_SHIFT;
92462 int error;
92463 + unsigned long charged;
92464
92465 len = PAGE_ALIGN(len);
92466 if (!len)
92467 @@ -2587,16 +3063,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92468
92469 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
92470
92471 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
92472 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
92473 + flags &= ~VM_EXEC;
92474 +
92475 +#ifdef CONFIG_PAX_MPROTECT
92476 + if (mm->pax_flags & MF_PAX_MPROTECT)
92477 + flags &= ~VM_MAYEXEC;
92478 +#endif
92479 +
92480 + }
92481 +#endif
92482 +
92483 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
92484 if (error & ~PAGE_MASK)
92485 return error;
92486
92487 + charged = len >> PAGE_SHIFT;
92488 +
92489 /*
92490 * mlock MCL_FUTURE?
92491 */
92492 if (mm->def_flags & VM_LOCKED) {
92493 unsigned long locked, lock_limit;
92494 - locked = len >> PAGE_SHIFT;
92495 + locked = charged;
92496 locked += mm->locked_vm;
92497 lock_limit = rlimit(RLIMIT_MEMLOCK);
92498 lock_limit >>= PAGE_SHIFT;
92499 @@ -2613,21 +3103,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92500 /*
92501 * Clear old maps. this also does some error checking for us
92502 */
92503 - munmap_back:
92504 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
92505 if (do_munmap(mm, addr, len))
92506 return -ENOMEM;
92507 - goto munmap_back;
92508 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
92509 }
92510
92511 /* Check against address space limits *after* clearing old maps... */
92512 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
92513 + if (!may_expand_vm(mm, charged))
92514 return -ENOMEM;
92515
92516 if (mm->map_count > sysctl_max_map_count)
92517 return -ENOMEM;
92518
92519 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
92520 + if (security_vm_enough_memory_mm(mm, charged))
92521 return -ENOMEM;
92522
92523 /* Can we just expand an old private anonymous mapping? */
92524 @@ -2641,7 +3130,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92525 */
92526 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92527 if (!vma) {
92528 - vm_unacct_memory(len >> PAGE_SHIFT);
92529 + vm_unacct_memory(charged);
92530 return -ENOMEM;
92531 }
92532
92533 @@ -2655,10 +3144,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92534 vma_link(mm, vma, prev, rb_link, rb_parent);
92535 out:
92536 perf_event_mmap(vma);
92537 - mm->total_vm += len >> PAGE_SHIFT;
92538 + mm->total_vm += charged;
92539 if (flags & VM_LOCKED)
92540 - mm->locked_vm += (len >> PAGE_SHIFT);
92541 + mm->locked_vm += charged;
92542 vma->vm_flags |= VM_SOFTDIRTY;
92543 + track_exec_limit(mm, addr, addr + len, flags);
92544 return addr;
92545 }
92546
92547 @@ -2720,6 +3210,7 @@ void exit_mmap(struct mm_struct *mm)
92548 while (vma) {
92549 if (vma->vm_flags & VM_ACCOUNT)
92550 nr_accounted += vma_pages(vma);
92551 + vma->vm_mirror = NULL;
92552 vma = remove_vma(vma);
92553 }
92554 vm_unacct_memory(nr_accounted);
92555 @@ -2737,6 +3228,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
92556 struct vm_area_struct *prev;
92557 struct rb_node **rb_link, *rb_parent;
92558
92559 +#ifdef CONFIG_PAX_SEGMEXEC
92560 + struct vm_area_struct *vma_m = NULL;
92561 +#endif
92562 +
92563 + if (security_mmap_addr(vma->vm_start))
92564 + return -EPERM;
92565 +
92566 /*
92567 * The vm_pgoff of a purely anonymous vma should be irrelevant
92568 * until its first write fault, when page's anon_vma and index
92569 @@ -2760,7 +3258,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
92570 security_vm_enough_memory_mm(mm, vma_pages(vma)))
92571 return -ENOMEM;
92572
92573 +#ifdef CONFIG_PAX_SEGMEXEC
92574 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
92575 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92576 + if (!vma_m)
92577 + return -ENOMEM;
92578 + }
92579 +#endif
92580 +
92581 vma_link(mm, vma, prev, rb_link, rb_parent);
92582 +
92583 +#ifdef CONFIG_PAX_SEGMEXEC
92584 + if (vma_m)
92585 + BUG_ON(pax_mirror_vma(vma_m, vma));
92586 +#endif
92587 +
92588 return 0;
92589 }
92590
92591 @@ -2779,6 +3291,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
92592 struct rb_node **rb_link, *rb_parent;
92593 bool faulted_in_anon_vma = true;
92594
92595 + BUG_ON(vma->vm_mirror);
92596 +
92597 /*
92598 * If anonymous vma has not yet been faulted, update new pgoff
92599 * to match new location, to increase its chance of merging.
92600 @@ -2843,6 +3357,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
92601 return NULL;
92602 }
92603
92604 +#ifdef CONFIG_PAX_SEGMEXEC
92605 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
92606 +{
92607 + struct vm_area_struct *prev_m;
92608 + struct rb_node **rb_link_m, *rb_parent_m;
92609 + struct mempolicy *pol_m;
92610 +
92611 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
92612 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
92613 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
92614 + *vma_m = *vma;
92615 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
92616 + if (anon_vma_clone(vma_m, vma))
92617 + return -ENOMEM;
92618 + pol_m = vma_policy(vma_m);
92619 + mpol_get(pol_m);
92620 + set_vma_policy(vma_m, pol_m);
92621 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
92622 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
92623 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
92624 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
92625 + if (vma_m->vm_file)
92626 + get_file(vma_m->vm_file);
92627 + if (vma_m->vm_ops && vma_m->vm_ops->open)
92628 + vma_m->vm_ops->open(vma_m);
92629 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
92630 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
92631 + vma_m->vm_mirror = vma;
92632 + vma->vm_mirror = vma_m;
92633 + return 0;
92634 +}
92635 +#endif
92636 +
92637 /*
92638 * Return true if the calling process may expand its vm space by the passed
92639 * number of pages
92640 @@ -2854,6 +3401,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
92641
92642 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
92643
92644 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
92645 if (cur + npages > lim)
92646 return 0;
92647 return 1;
92648 @@ -2924,6 +3472,22 @@ int install_special_mapping(struct mm_struct *mm,
92649 vma->vm_start = addr;
92650 vma->vm_end = addr + len;
92651
92652 +#ifdef CONFIG_PAX_MPROTECT
92653 + if (mm->pax_flags & MF_PAX_MPROTECT) {
92654 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
92655 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
92656 + return -EPERM;
92657 + if (!(vm_flags & VM_EXEC))
92658 + vm_flags &= ~VM_MAYEXEC;
92659 +#else
92660 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
92661 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
92662 +#endif
92663 + else
92664 + vm_flags &= ~VM_MAYWRITE;
92665 + }
92666 +#endif
92667 +
92668 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
92669 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
92670
92671 diff --git a/mm/mprotect.c b/mm/mprotect.c
92672 index bb53a65..249c052 100644
92673 --- a/mm/mprotect.c
92674 +++ b/mm/mprotect.c
92675 @@ -23,10 +23,18 @@
92676 #include <linux/mmu_notifier.h>
92677 #include <linux/migrate.h>
92678 #include <linux/perf_event.h>
92679 +#include <linux/sched/sysctl.h>
92680 +
92681 +#ifdef CONFIG_PAX_MPROTECT
92682 +#include <linux/elf.h>
92683 +#include <linux/binfmts.h>
92684 +#endif
92685 +
92686 #include <asm/uaccess.h>
92687 #include <asm/pgtable.h>
92688 #include <asm/cacheflush.h>
92689 #include <asm/tlbflush.h>
92690 +#include <asm/mmu_context.h>
92691
92692 #ifndef pgprot_modify
92693 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
92694 @@ -222,6 +230,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
92695 return pages;
92696 }
92697
92698 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
92699 +/* called while holding the mmap semaphor for writing except stack expansion */
92700 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
92701 +{
92702 + unsigned long oldlimit, newlimit = 0UL;
92703 +
92704 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
92705 + return;
92706 +
92707 + spin_lock(&mm->page_table_lock);
92708 + oldlimit = mm->context.user_cs_limit;
92709 + if ((prot & VM_EXEC) && oldlimit < end)
92710 + /* USER_CS limit moved up */
92711 + newlimit = end;
92712 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
92713 + /* USER_CS limit moved down */
92714 + newlimit = start;
92715 +
92716 + if (newlimit) {
92717 + mm->context.user_cs_limit = newlimit;
92718 +
92719 +#ifdef CONFIG_SMP
92720 + wmb();
92721 + cpus_clear(mm->context.cpu_user_cs_mask);
92722 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
92723 +#endif
92724 +
92725 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
92726 + }
92727 + spin_unlock(&mm->page_table_lock);
92728 + if (newlimit == end) {
92729 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
92730 +
92731 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
92732 + if (is_vm_hugetlb_page(vma))
92733 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
92734 + else
92735 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
92736 + }
92737 +}
92738 +#endif
92739 +
92740 int
92741 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92742 unsigned long start, unsigned long end, unsigned long newflags)
92743 @@ -234,11 +284,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92744 int error;
92745 int dirty_accountable = 0;
92746
92747 +#ifdef CONFIG_PAX_SEGMEXEC
92748 + struct vm_area_struct *vma_m = NULL;
92749 + unsigned long start_m, end_m;
92750 +
92751 + start_m = start + SEGMEXEC_TASK_SIZE;
92752 + end_m = end + SEGMEXEC_TASK_SIZE;
92753 +#endif
92754 +
92755 if (newflags == oldflags) {
92756 *pprev = vma;
92757 return 0;
92758 }
92759
92760 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
92761 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
92762 +
92763 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
92764 + return -ENOMEM;
92765 +
92766 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
92767 + return -ENOMEM;
92768 + }
92769 +
92770 /*
92771 * If we make a private mapping writable we increase our commit;
92772 * but (without finer accounting) cannot reduce our commit if we
92773 @@ -255,6 +323,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92774 }
92775 }
92776
92777 +#ifdef CONFIG_PAX_SEGMEXEC
92778 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
92779 + if (start != vma->vm_start) {
92780 + error = split_vma(mm, vma, start, 1);
92781 + if (error)
92782 + goto fail;
92783 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
92784 + *pprev = (*pprev)->vm_next;
92785 + }
92786 +
92787 + if (end != vma->vm_end) {
92788 + error = split_vma(mm, vma, end, 0);
92789 + if (error)
92790 + goto fail;
92791 + }
92792 +
92793 + if (pax_find_mirror_vma(vma)) {
92794 + error = __do_munmap(mm, start_m, end_m - start_m);
92795 + if (error)
92796 + goto fail;
92797 + } else {
92798 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92799 + if (!vma_m) {
92800 + error = -ENOMEM;
92801 + goto fail;
92802 + }
92803 + vma->vm_flags = newflags;
92804 + error = pax_mirror_vma(vma_m, vma);
92805 + if (error) {
92806 + vma->vm_flags = oldflags;
92807 + goto fail;
92808 + }
92809 + }
92810 + }
92811 +#endif
92812 +
92813 /*
92814 * First try to merge with previous and/or next vma.
92815 */
92816 @@ -285,9 +389,21 @@ success:
92817 * vm_flags and vm_page_prot are protected by the mmap_sem
92818 * held in write mode.
92819 */
92820 +
92821 +#ifdef CONFIG_PAX_SEGMEXEC
92822 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
92823 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
92824 +#endif
92825 +
92826 vma->vm_flags = newflags;
92827 +
92828 +#ifdef CONFIG_PAX_MPROTECT
92829 + if (mm->binfmt && mm->binfmt->handle_mprotect)
92830 + mm->binfmt->handle_mprotect(vma, newflags);
92831 +#endif
92832 +
92833 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
92834 - vm_get_page_prot(newflags));
92835 + vm_get_page_prot(vma->vm_flags));
92836
92837 if (vma_wants_writenotify(vma)) {
92838 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
92839 @@ -326,6 +442,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92840 end = start + len;
92841 if (end <= start)
92842 return -ENOMEM;
92843 +
92844 +#ifdef CONFIG_PAX_SEGMEXEC
92845 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92846 + if (end > SEGMEXEC_TASK_SIZE)
92847 + return -EINVAL;
92848 + } else
92849 +#endif
92850 +
92851 + if (end > TASK_SIZE)
92852 + return -EINVAL;
92853 +
92854 if (!arch_validate_prot(prot))
92855 return -EINVAL;
92856
92857 @@ -333,7 +460,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92858 /*
92859 * Does the application expect PROT_READ to imply PROT_EXEC:
92860 */
92861 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
92862 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
92863 prot |= PROT_EXEC;
92864
92865 vm_flags = calc_vm_prot_bits(prot);
92866 @@ -365,6 +492,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92867 if (start > vma->vm_start)
92868 prev = vma;
92869
92870 +#ifdef CONFIG_PAX_MPROTECT
92871 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
92872 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
92873 +#endif
92874 +
92875 for (nstart = start ; ; ) {
92876 unsigned long newflags;
92877
92878 @@ -375,6 +507,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92879
92880 /* newflags >> 4 shift VM_MAY% in place of VM_% */
92881 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
92882 + if (prot & (PROT_WRITE | PROT_EXEC))
92883 + gr_log_rwxmprotect(vma);
92884 +
92885 + error = -EACCES;
92886 + goto out;
92887 + }
92888 +
92889 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
92890 error = -EACCES;
92891 goto out;
92892 }
92893 @@ -389,6 +529,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92894 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
92895 if (error)
92896 goto out;
92897 +
92898 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
92899 +
92900 nstart = tmp;
92901
92902 if (nstart < prev->vm_end)
92903 diff --git a/mm/mremap.c b/mm/mremap.c
92904 index 0843feb..4f5b2e6 100644
92905 --- a/mm/mremap.c
92906 +++ b/mm/mremap.c
92907 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
92908 continue;
92909 pte = ptep_get_and_clear(mm, old_addr, old_pte);
92910 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
92911 +
92912 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
92913 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
92914 + pte = pte_exprotect(pte);
92915 +#endif
92916 +
92917 pte = move_soft_dirty_pte(pte);
92918 set_pte_at(mm, new_addr, new_pte, pte);
92919 }
92920 @@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
92921 if (is_vm_hugetlb_page(vma))
92922 goto Einval;
92923
92924 +#ifdef CONFIG_PAX_SEGMEXEC
92925 + if (pax_find_mirror_vma(vma))
92926 + goto Einval;
92927 +#endif
92928 +
92929 /* We can't remap across vm area boundaries */
92930 if (old_len > vma->vm_end - addr)
92931 goto Efault;
92932 @@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
92933 unsigned long ret = -EINVAL;
92934 unsigned long charged = 0;
92935 unsigned long map_flags;
92936 + unsigned long pax_task_size = TASK_SIZE;
92937
92938 if (new_addr & ~PAGE_MASK)
92939 goto out;
92940
92941 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
92942 +#ifdef CONFIG_PAX_SEGMEXEC
92943 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
92944 + pax_task_size = SEGMEXEC_TASK_SIZE;
92945 +#endif
92946 +
92947 + pax_task_size -= PAGE_SIZE;
92948 +
92949 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
92950 goto out;
92951
92952 /* Check if the location we're moving into overlaps the
92953 * old location at all, and fail if it does.
92954 */
92955 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
92956 - goto out;
92957 -
92958 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
92959 + if (addr + old_len > new_addr && new_addr + new_len > addr)
92960 goto out;
92961
92962 ret = do_munmap(mm, new_addr, new_len);
92963 @@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
92964 unsigned long ret = -EINVAL;
92965 unsigned long charged = 0;
92966 bool locked = false;
92967 + unsigned long pax_task_size = TASK_SIZE;
92968
92969 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
92970 return ret;
92971 @@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
92972 if (!new_len)
92973 return ret;
92974
92975 +#ifdef CONFIG_PAX_SEGMEXEC
92976 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
92977 + pax_task_size = SEGMEXEC_TASK_SIZE;
92978 +#endif
92979 +
92980 + pax_task_size -= PAGE_SIZE;
92981 +
92982 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
92983 + old_len > pax_task_size || addr > pax_task_size-old_len)
92984 + return ret;
92985 +
92986 down_write(&current->mm->mmap_sem);
92987
92988 if (flags & MREMAP_FIXED) {
92989 @@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
92990 new_addr = addr;
92991 }
92992 ret = addr;
92993 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
92994 goto out;
92995 }
92996 }
92997 @@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
92998 goto out;
92999 }
93000
93001 + map_flags = vma->vm_flags;
93002 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
93003 + if (!(ret & ~PAGE_MASK)) {
93004 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
93005 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
93006 + }
93007 }
93008 out:
93009 if (ret & ~PAGE_MASK)
93010 diff --git a/mm/nommu.c b/mm/nommu.c
93011 index fec093a..8162f74 100644
93012 --- a/mm/nommu.c
93013 +++ b/mm/nommu.c
93014 @@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
93015 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
93016 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93017 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93018 -int heap_stack_gap = 0;
93019
93020 atomic_long_t mmap_pages_allocated;
93021
93022 @@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
93023 EXPORT_SYMBOL(find_vma);
93024
93025 /*
93026 - * find a VMA
93027 - * - we don't extend stack VMAs under NOMMU conditions
93028 - */
93029 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
93030 -{
93031 - return find_vma(mm, addr);
93032 -}
93033 -
93034 -/*
93035 * expand a stack to a given address
93036 * - not supported under NOMMU conditions
93037 */
93038 @@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93039
93040 /* most fields are the same, copy all, and then fixup */
93041 *new = *vma;
93042 + INIT_LIST_HEAD(&new->anon_vma_chain);
93043 *region = *vma->vm_region;
93044 new->vm_region = region;
93045
93046 @@ -1992,8 +1983,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
93047 }
93048 EXPORT_SYMBOL(generic_file_remap_pages);
93049
93050 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93051 - unsigned long addr, void *buf, int len, int write)
93052 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93053 + unsigned long addr, void *buf, size_t len, int write)
93054 {
93055 struct vm_area_struct *vma;
93056
93057 @@ -2034,8 +2025,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93058 *
93059 * The caller must hold a reference on @mm.
93060 */
93061 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93062 - void *buf, int len, int write)
93063 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93064 + void *buf, size_t len, int write)
93065 {
93066 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93067 }
93068 @@ -2044,7 +2035,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93069 * Access another process' address space.
93070 * - source/target buffer must be kernel space
93071 */
93072 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
93073 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
93074 {
93075 struct mm_struct *mm;
93076
93077 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
93078 index 6380758..4064aec 100644
93079 --- a/mm/page-writeback.c
93080 +++ b/mm/page-writeback.c
93081 @@ -690,7 +690,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
93082 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
93083 * - the bdi dirty thresh drops quickly due to change of JBOD workload
93084 */
93085 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
93086 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
93087 unsigned long thresh,
93088 unsigned long bg_thresh,
93089 unsigned long dirty,
93090 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
93091 index 5248fe0..0f693aa 100644
93092 --- a/mm/page_alloc.c
93093 +++ b/mm/page_alloc.c
93094 @@ -61,6 +61,7 @@
93095 #include <linux/page-debug-flags.h>
93096 #include <linux/hugetlb.h>
93097 #include <linux/sched/rt.h>
93098 +#include <linux/random.h>
93099
93100 #include <asm/sections.h>
93101 #include <asm/tlbflush.h>
93102 @@ -354,7 +355,7 @@ out:
93103 * This usage means that zero-order pages may not be compound.
93104 */
93105
93106 -static void free_compound_page(struct page *page)
93107 +void free_compound_page(struct page *page)
93108 {
93109 __free_pages_ok(page, compound_order(page));
93110 }
93111 @@ -712,6 +713,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
93112 int i;
93113 int bad = 0;
93114
93115 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93116 + unsigned long index = 1UL << order;
93117 +#endif
93118 +
93119 trace_mm_page_free(page, order);
93120 kmemcheck_free_shadow(page, order);
93121
93122 @@ -728,6 +733,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
93123 debug_check_no_obj_freed(page_address(page),
93124 PAGE_SIZE << order);
93125 }
93126 +
93127 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93128 + for (; index; --index)
93129 + sanitize_highpage(page + index - 1);
93130 +#endif
93131 +
93132 arch_free_page(page, order);
93133 kernel_map_pages(page, 1 << order, 0);
93134
93135 @@ -750,6 +761,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
93136 local_irq_restore(flags);
93137 }
93138
93139 +#ifdef CONFIG_PAX_LATENT_ENTROPY
93140 +bool __meminitdata extra_latent_entropy;
93141 +
93142 +static int __init setup_pax_extra_latent_entropy(char *str)
93143 +{
93144 + extra_latent_entropy = true;
93145 + return 0;
93146 +}
93147 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
93148 +
93149 +volatile u64 latent_entropy __latent_entropy;
93150 +EXPORT_SYMBOL(latent_entropy);
93151 +#endif
93152 +
93153 void __init __free_pages_bootmem(struct page *page, unsigned int order)
93154 {
93155 unsigned int nr_pages = 1 << order;
93156 @@ -765,6 +790,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
93157 __ClearPageReserved(p);
93158 set_page_count(p, 0);
93159
93160 +#ifdef CONFIG_PAX_LATENT_ENTROPY
93161 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
93162 + u64 hash = 0;
93163 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
93164 + const u64 *data = lowmem_page_address(page);
93165 +
93166 + for (index = 0; index < end; index++)
93167 + hash ^= hash + data[index];
93168 + latent_entropy ^= hash;
93169 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
93170 + }
93171 +#endif
93172 +
93173 page_zone(page)->managed_pages += nr_pages;
93174 set_page_refcounted(page);
93175 __free_pages(page, order);
93176 @@ -870,8 +908,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
93177 arch_alloc_page(page, order);
93178 kernel_map_pages(page, 1 << order, 1);
93179
93180 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
93181 if (gfp_flags & __GFP_ZERO)
93182 prep_zero_page(page, order, gfp_flags);
93183 +#endif
93184
93185 if (order && (gfp_flags & __GFP_COMP))
93186 prep_compound_page(page, order);
93187 diff --git a/mm/page_io.c b/mm/page_io.c
93188 index 8c79a47..a689e0d 100644
93189 --- a/mm/page_io.c
93190 +++ b/mm/page_io.c
93191 @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
93192 struct file *swap_file = sis->swap_file;
93193 struct address_space *mapping = swap_file->f_mapping;
93194 struct iovec iov = {
93195 - .iov_base = kmap(page),
93196 + .iov_base = (void __force_user *)kmap(page),
93197 .iov_len = PAGE_SIZE,
93198 };
93199
93200 diff --git a/mm/percpu.c b/mm/percpu.c
93201 index 0d10def..6dc822d 100644
93202 --- a/mm/percpu.c
93203 +++ b/mm/percpu.c
93204 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
93205 static unsigned int pcpu_high_unit_cpu __read_mostly;
93206
93207 /* the address of the first chunk which starts with the kernel static area */
93208 -void *pcpu_base_addr __read_mostly;
93209 +void *pcpu_base_addr __read_only;
93210 EXPORT_SYMBOL_GPL(pcpu_base_addr);
93211
93212 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
93213 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
93214 index fd26d04..0cea1b0 100644
93215 --- a/mm/process_vm_access.c
93216 +++ b/mm/process_vm_access.c
93217 @@ -13,6 +13,7 @@
93218 #include <linux/uio.h>
93219 #include <linux/sched.h>
93220 #include <linux/highmem.h>
93221 +#include <linux/security.h>
93222 #include <linux/ptrace.h>
93223 #include <linux/slab.h>
93224 #include <linux/syscalls.h>
93225 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
93226 size_t iov_l_curr_offset = 0;
93227 ssize_t iov_len;
93228
93229 + return -ENOSYS; // PaX: until properly audited
93230 +
93231 /*
93232 * Work out how many pages of struct pages we're going to need
93233 * when eventually calling get_user_pages
93234 */
93235 for (i = 0; i < riovcnt; i++) {
93236 iov_len = rvec[i].iov_len;
93237 - if (iov_len > 0) {
93238 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
93239 - + iov_len)
93240 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
93241 - / PAGE_SIZE + 1;
93242 - nr_pages = max(nr_pages, nr_pages_iov);
93243 - }
93244 + if (iov_len <= 0)
93245 + continue;
93246 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
93247 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
93248 + nr_pages = max(nr_pages, nr_pages_iov);
93249 }
93250
93251 if (nr_pages == 0)
93252 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
93253 goto free_proc_pages;
93254 }
93255
93256 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
93257 + rc = -EPERM;
93258 + goto put_task_struct;
93259 + }
93260 +
93261 mm = mm_access(task, PTRACE_MODE_ATTACH);
93262 if (!mm || IS_ERR(mm)) {
93263 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
93264 diff --git a/mm/rmap.c b/mm/rmap.c
93265 index 068522d..f539f21 100644
93266 --- a/mm/rmap.c
93267 +++ b/mm/rmap.c
93268 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93269 struct anon_vma *anon_vma = vma->anon_vma;
93270 struct anon_vma_chain *avc;
93271
93272 +#ifdef CONFIG_PAX_SEGMEXEC
93273 + struct anon_vma_chain *avc_m = NULL;
93274 +#endif
93275 +
93276 might_sleep();
93277 if (unlikely(!anon_vma)) {
93278 struct mm_struct *mm = vma->vm_mm;
93279 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93280 if (!avc)
93281 goto out_enomem;
93282
93283 +#ifdef CONFIG_PAX_SEGMEXEC
93284 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
93285 + if (!avc_m)
93286 + goto out_enomem_free_avc;
93287 +#endif
93288 +
93289 anon_vma = find_mergeable_anon_vma(vma);
93290 allocated = NULL;
93291 if (!anon_vma) {
93292 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93293 /* page_table_lock to protect against threads */
93294 spin_lock(&mm->page_table_lock);
93295 if (likely(!vma->anon_vma)) {
93296 +
93297 +#ifdef CONFIG_PAX_SEGMEXEC
93298 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
93299 +
93300 + if (vma_m) {
93301 + BUG_ON(vma_m->anon_vma);
93302 + vma_m->anon_vma = anon_vma;
93303 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
93304 + avc_m = NULL;
93305 + }
93306 +#endif
93307 +
93308 vma->anon_vma = anon_vma;
93309 anon_vma_chain_link(vma, avc, anon_vma);
93310 allocated = NULL;
93311 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93312
93313 if (unlikely(allocated))
93314 put_anon_vma(allocated);
93315 +
93316 +#ifdef CONFIG_PAX_SEGMEXEC
93317 + if (unlikely(avc_m))
93318 + anon_vma_chain_free(avc_m);
93319 +#endif
93320 +
93321 if (unlikely(avc))
93322 anon_vma_chain_free(avc);
93323 }
93324 return 0;
93325
93326 out_enomem_free_avc:
93327 +
93328 +#ifdef CONFIG_PAX_SEGMEXEC
93329 + if (avc_m)
93330 + anon_vma_chain_free(avc_m);
93331 +#endif
93332 +
93333 anon_vma_chain_free(avc);
93334 out_enomem:
93335 return -ENOMEM;
93336 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
93337 * Attach the anon_vmas from src to dst.
93338 * Returns 0 on success, -ENOMEM on failure.
93339 */
93340 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
93341 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
93342 {
93343 struct anon_vma_chain *avc, *pavc;
93344 struct anon_vma *root = NULL;
93345 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
93346 * the corresponding VMA in the parent process is attached to.
93347 * Returns 0 on success, non-zero on failure.
93348 */
93349 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
93350 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
93351 {
93352 struct anon_vma_chain *avc;
93353 struct anon_vma *anon_vma;
93354 @@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
93355 void __init anon_vma_init(void)
93356 {
93357 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
93358 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
93359 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
93360 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
93361 + anon_vma_ctor);
93362 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
93363 + SLAB_PANIC|SLAB_NO_SANITIZE);
93364 }
93365
93366 /*
93367 diff --git a/mm/shmem.c b/mm/shmem.c
93368 index 902a148..58f9d59 100644
93369 --- a/mm/shmem.c
93370 +++ b/mm/shmem.c
93371 @@ -33,7 +33,7 @@
93372 #include <linux/swap.h>
93373 #include <linux/aio.h>
93374
93375 -static struct vfsmount *shm_mnt;
93376 +struct vfsmount *shm_mnt;
93377
93378 #ifdef CONFIG_SHMEM
93379 /*
93380 @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
93381 #define BOGO_DIRENT_SIZE 20
93382
93383 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
93384 -#define SHORT_SYMLINK_LEN 128
93385 +#define SHORT_SYMLINK_LEN 64
93386
93387 /*
93388 * shmem_fallocate and shmem_writepage communicate via inode->i_private
93389 @@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
93390 static int shmem_xattr_validate(const char *name)
93391 {
93392 struct { const char *prefix; size_t len; } arr[] = {
93393 +
93394 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
93395 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
93396 +#endif
93397 +
93398 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
93399 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
93400 };
93401 @@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
93402 if (err)
93403 return err;
93404
93405 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
93406 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
93407 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
93408 + return -EOPNOTSUPP;
93409 + if (size > 8)
93410 + return -EINVAL;
93411 + }
93412 +#endif
93413 +
93414 return simple_xattr_set(&info->xattrs, name, value, size, flags);
93415 }
93416
93417 @@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
93418 int err = -ENOMEM;
93419
93420 /* Round up to L1_CACHE_BYTES to resist false sharing */
93421 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
93422 - L1_CACHE_BYTES), GFP_KERNEL);
93423 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
93424 if (!sbinfo)
93425 return -ENOMEM;
93426
93427 diff --git a/mm/slab.c b/mm/slab.c
93428 index eb043bf..d82f5a8 100644
93429 --- a/mm/slab.c
93430 +++ b/mm/slab.c
93431 @@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
93432 if ((x)->max_freeable < i) \
93433 (x)->max_freeable = i; \
93434 } while (0)
93435 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
93436 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
93437 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
93438 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
93439 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
93440 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
93441 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
93442 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
93443 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
93444 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
93445 #else
93446 #define STATS_INC_ACTIVE(x) do { } while (0)
93447 #define STATS_DEC_ACTIVE(x) do { } while (0)
93448 @@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
93449 #define STATS_INC_ALLOCMISS(x) do { } while (0)
93450 #define STATS_INC_FREEHIT(x) do { } while (0)
93451 #define STATS_INC_FREEMISS(x) do { } while (0)
93452 +#define STATS_INC_SANITIZED(x) do { } while (0)
93453 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
93454 #endif
93455
93456 #if DEBUG
93457 @@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
93458 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
93459 */
93460 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
93461 - const struct page *page, void *obj)
93462 + const struct page *page, const void *obj)
93463 {
93464 u32 offset = (obj - page->s_mem);
93465 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
93466 @@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
93467 */
93468
93469 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
93470 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
93471 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
93472
93473 if (INDEX_AC != INDEX_NODE)
93474 kmalloc_caches[INDEX_NODE] =
93475 create_kmalloc_cache("kmalloc-node",
93476 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
93477 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
93478
93479 slab_early_init = 0;
93480
93481 @@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
93482 struct array_cache *ac = cpu_cache_get(cachep);
93483
93484 check_irq_off();
93485 +
93486 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93487 + if (pax_sanitize_slab) {
93488 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
93489 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
93490 +
93491 + if (cachep->ctor)
93492 + cachep->ctor(objp);
93493 +
93494 + STATS_INC_SANITIZED(cachep);
93495 + } else
93496 + STATS_INC_NOT_SANITIZED(cachep);
93497 + }
93498 +#endif
93499 +
93500 kmemleak_free_recursive(objp, cachep->flags);
93501 objp = cache_free_debugcheck(cachep, objp, caller);
93502
93503 @@ -3656,6 +3675,7 @@ void kfree(const void *objp)
93504
93505 if (unlikely(ZERO_OR_NULL_PTR(objp)))
93506 return;
93507 + VM_BUG_ON(!virt_addr_valid(objp));
93508 local_irq_save(flags);
93509 kfree_debugcheck(objp);
93510 c = virt_to_cache(objp);
93511 @@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
93512 }
93513 /* cpu stats */
93514 {
93515 - unsigned long allochit = atomic_read(&cachep->allochit);
93516 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
93517 - unsigned long freehit = atomic_read(&cachep->freehit);
93518 - unsigned long freemiss = atomic_read(&cachep->freemiss);
93519 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
93520 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
93521 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
93522 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
93523
93524 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
93525 allochit, allocmiss, freehit, freemiss);
93526 }
93527 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93528 + {
93529 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
93530 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
93531 +
93532 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
93533 + }
93534 +#endif
93535 #endif
93536 }
93537
93538 @@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
93539 static int __init slab_proc_init(void)
93540 {
93541 #ifdef CONFIG_DEBUG_SLAB_LEAK
93542 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
93543 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
93544 #endif
93545 return 0;
93546 }
93547 module_init(slab_proc_init);
93548 #endif
93549
93550 +bool is_usercopy_object(const void *ptr)
93551 +{
93552 + struct page *page;
93553 + struct kmem_cache *cachep;
93554 +
93555 + if (ZERO_OR_NULL_PTR(ptr))
93556 + return false;
93557 +
93558 + if (!slab_is_available())
93559 + return false;
93560 +
93561 + if (!virt_addr_valid(ptr))
93562 + return false;
93563 +
93564 + page = virt_to_head_page(ptr);
93565 +
93566 + if (!PageSlab(page))
93567 + return false;
93568 +
93569 + cachep = page->slab_cache;
93570 + return cachep->flags & SLAB_USERCOPY;
93571 +}
93572 +
93573 +#ifdef CONFIG_PAX_USERCOPY
93574 +const char *check_heap_object(const void *ptr, unsigned long n)
93575 +{
93576 + struct page *page;
93577 + struct kmem_cache *cachep;
93578 + unsigned int objnr;
93579 + unsigned long offset;
93580 +
93581 + if (ZERO_OR_NULL_PTR(ptr))
93582 + return "<null>";
93583 +
93584 + if (!virt_addr_valid(ptr))
93585 + return NULL;
93586 +
93587 + page = virt_to_head_page(ptr);
93588 +
93589 + if (!PageSlab(page))
93590 + return NULL;
93591 +
93592 + cachep = page->slab_cache;
93593 + if (!(cachep->flags & SLAB_USERCOPY))
93594 + return cachep->name;
93595 +
93596 + objnr = obj_to_index(cachep, page, ptr);
93597 + BUG_ON(objnr >= cachep->num);
93598 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
93599 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
93600 + return NULL;
93601 +
93602 + return cachep->name;
93603 +}
93604 +#endif
93605 +
93606 /**
93607 * ksize - get the actual amount of memory allocated for a given object
93608 * @objp: Pointer to the object
93609 diff --git a/mm/slab.h b/mm/slab.h
93610 index 0859c42..2f7b737 100644
93611 --- a/mm/slab.h
93612 +++ b/mm/slab.h
93613 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
93614 /* The slab cache that manages slab cache information */
93615 extern struct kmem_cache *kmem_cache;
93616
93617 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93618 +#ifdef CONFIG_X86_64
93619 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
93620 +#else
93621 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
93622 +#endif
93623 +extern bool pax_sanitize_slab;
93624 +#endif
93625 +
93626 unsigned long calculate_alignment(unsigned long flags,
93627 unsigned long align, unsigned long size);
93628
93629 @@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
93630
93631 /* Legal flag mask for kmem_cache_create(), for various configurations */
93632 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
93633 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
93634 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
93635 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
93636
93637 #if defined(CONFIG_DEBUG_SLAB)
93638 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
93639 @@ -233,6 +243,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
93640 return s;
93641
93642 page = virt_to_head_page(x);
93643 +
93644 + BUG_ON(!PageSlab(page));
93645 +
93646 cachep = page->slab_cache;
93647 if (slab_equal_or_root(cachep, s))
93648 return cachep;
93649 diff --git a/mm/slab_common.c b/mm/slab_common.c
93650 index 0b7bb39..334c328 100644
93651 --- a/mm/slab_common.c
93652 +++ b/mm/slab_common.c
93653 @@ -23,11 +23,22 @@
93654
93655 #include "slab.h"
93656
93657 -enum slab_state slab_state;
93658 +enum slab_state slab_state __read_only;
93659 LIST_HEAD(slab_caches);
93660 DEFINE_MUTEX(slab_mutex);
93661 struct kmem_cache *kmem_cache;
93662
93663 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93664 +bool pax_sanitize_slab __read_only = true;
93665 +static int __init pax_sanitize_slab_setup(char *str)
93666 +{
93667 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
93668 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
93669 + return 1;
93670 +}
93671 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
93672 +#endif
93673 +
93674 #ifdef CONFIG_DEBUG_VM
93675 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
93676 size_t size)
93677 @@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
93678
93679 err = __kmem_cache_create(s, flags);
93680 if (!err) {
93681 - s->refcount = 1;
93682 + atomic_set(&s->refcount, 1);
93683 list_add(&s->list, &slab_caches);
93684 memcg_cache_list_add(memcg, s);
93685 } else {
93686 @@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
93687
93688 get_online_cpus();
93689 mutex_lock(&slab_mutex);
93690 - s->refcount--;
93691 - if (!s->refcount) {
93692 + if (atomic_dec_and_test(&s->refcount)) {
93693 list_del(&s->list);
93694
93695 if (!__kmem_cache_shutdown(s)) {
93696 @@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
93697 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
93698 name, size, err);
93699
93700 - s->refcount = -1; /* Exempt from merging for now */
93701 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
93702 }
93703
93704 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
93705 @@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
93706
93707 create_boot_cache(s, name, size, flags);
93708 list_add(&s->list, &slab_caches);
93709 - s->refcount = 1;
93710 + atomic_set(&s->refcount, 1);
93711 return s;
93712 }
93713
93714 @@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
93715 EXPORT_SYMBOL(kmalloc_dma_caches);
93716 #endif
93717
93718 +#ifdef CONFIG_PAX_USERCOPY_SLABS
93719 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
93720 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
93721 +#endif
93722 +
93723 /*
93724 * Conversion table for small slabs sizes / 8 to the index in the
93725 * kmalloc array. This is necessary for slabs < 192 since we have non power
93726 @@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
93727 return kmalloc_dma_caches[index];
93728
93729 #endif
93730 +
93731 +#ifdef CONFIG_PAX_USERCOPY_SLABS
93732 + if (unlikely((flags & GFP_USERCOPY)))
93733 + return kmalloc_usercopy_caches[index];
93734 +
93735 +#endif
93736 +
93737 return kmalloc_caches[index];
93738 }
93739
93740 @@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
93741 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
93742 if (!kmalloc_caches[i]) {
93743 kmalloc_caches[i] = create_kmalloc_cache(NULL,
93744 - 1 << i, flags);
93745 + 1 << i, SLAB_USERCOPY | flags);
93746 }
93747
93748 /*
93749 @@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
93750 * earlier power of two caches
93751 */
93752 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
93753 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
93754 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
93755
93756 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
93757 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
93758 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
93759 }
93760
93761 /* Kmalloc array is now usable */
93762 @@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
93763 }
93764 }
93765 #endif
93766 +
93767 +#ifdef CONFIG_PAX_USERCOPY_SLABS
93768 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
93769 + struct kmem_cache *s = kmalloc_caches[i];
93770 +
93771 + if (s) {
93772 + int size = kmalloc_size(i);
93773 + char *n = kasprintf(GFP_NOWAIT,
93774 + "usercopy-kmalloc-%d", size);
93775 +
93776 + BUG_ON(!n);
93777 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
93778 + size, SLAB_USERCOPY | flags);
93779 + }
93780 + }
93781 +#endif
93782 +
93783 }
93784 #endif /* !CONFIG_SLOB */
93785
93786 @@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
93787 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
93788 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
93789 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
93790 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93791 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
93792 +#endif
93793 #endif
93794 seq_putc(m, '\n');
93795 }
93796 diff --git a/mm/slob.c b/mm/slob.c
93797 index 4bf8809..98a6914 100644
93798 --- a/mm/slob.c
93799 +++ b/mm/slob.c
93800 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
93801 /*
93802 * Return the size of a slob block.
93803 */
93804 -static slobidx_t slob_units(slob_t *s)
93805 +static slobidx_t slob_units(const slob_t *s)
93806 {
93807 if (s->units > 0)
93808 return s->units;
93809 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
93810 /*
93811 * Return the next free slob block pointer after this one.
93812 */
93813 -static slob_t *slob_next(slob_t *s)
93814 +static slob_t *slob_next(const slob_t *s)
93815 {
93816 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
93817 slobidx_t next;
93818 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
93819 /*
93820 * Returns true if s is the last free block in its page.
93821 */
93822 -static int slob_last(slob_t *s)
93823 +static int slob_last(const slob_t *s)
93824 {
93825 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
93826 }
93827
93828 -static void *slob_new_pages(gfp_t gfp, int order, int node)
93829 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
93830 {
93831 - void *page;
93832 + struct page *page;
93833
93834 #ifdef CONFIG_NUMA
93835 if (node != NUMA_NO_NODE)
93836 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
93837 if (!page)
93838 return NULL;
93839
93840 - return page_address(page);
93841 + __SetPageSlab(page);
93842 + return page;
93843 }
93844
93845 -static void slob_free_pages(void *b, int order)
93846 +static void slob_free_pages(struct page *sp, int order)
93847 {
93848 if (current->reclaim_state)
93849 current->reclaim_state->reclaimed_slab += 1 << order;
93850 - free_pages((unsigned long)b, order);
93851 + __ClearPageSlab(sp);
93852 + page_mapcount_reset(sp);
93853 + sp->private = 0;
93854 + __free_pages(sp, order);
93855 }
93856
93857 /*
93858 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
93859
93860 /* Not enough space: must allocate a new page */
93861 if (!b) {
93862 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
93863 - if (!b)
93864 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
93865 + if (!sp)
93866 return NULL;
93867 - sp = virt_to_page(b);
93868 - __SetPageSlab(sp);
93869 + b = page_address(sp);
93870
93871 spin_lock_irqsave(&slob_lock, flags);
93872 sp->units = SLOB_UNITS(PAGE_SIZE);
93873 sp->freelist = b;
93874 + sp->private = 0;
93875 INIT_LIST_HEAD(&sp->list);
93876 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
93877 set_slob_page_free(sp, slob_list);
93878 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
93879 if (slob_page_free(sp))
93880 clear_slob_page_free(sp);
93881 spin_unlock_irqrestore(&slob_lock, flags);
93882 - __ClearPageSlab(sp);
93883 - page_mapcount_reset(sp);
93884 - slob_free_pages(b, 0);
93885 + slob_free_pages(sp, 0);
93886 return;
93887 }
93888
93889 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93890 + if (pax_sanitize_slab)
93891 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
93892 +#endif
93893 +
93894 if (!slob_page_free(sp)) {
93895 /* This slob page is about to become partially free. Easy! */
93896 sp->units = units;
93897 @@ -424,11 +431,10 @@ out:
93898 */
93899
93900 static __always_inline void *
93901 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
93902 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
93903 {
93904 - unsigned int *m;
93905 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
93906 - void *ret;
93907 + slob_t *m;
93908 + void *ret = NULL;
93909
93910 gfp &= gfp_allowed_mask;
93911
93912 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
93913
93914 if (!m)
93915 return NULL;
93916 - *m = size;
93917 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
93918 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
93919 + m[0].units = size;
93920 + m[1].units = align;
93921 ret = (void *)m + align;
93922
93923 trace_kmalloc_node(caller, ret,
93924 size, size + align, gfp, node);
93925 } else {
93926 unsigned int order = get_order(size);
93927 + struct page *page;
93928
93929 if (likely(order))
93930 gfp |= __GFP_COMP;
93931 - ret = slob_new_pages(gfp, order, node);
93932 + page = slob_new_pages(gfp, order, node);
93933 + if (page) {
93934 + ret = page_address(page);
93935 + page->private = size;
93936 + }
93937
93938 trace_kmalloc_node(caller, ret,
93939 size, PAGE_SIZE << order, gfp, node);
93940 }
93941
93942 - kmemleak_alloc(ret, size, 1, gfp);
93943 + return ret;
93944 +}
93945 +
93946 +static __always_inline void *
93947 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
93948 +{
93949 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
93950 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
93951 +
93952 + if (!ZERO_OR_NULL_PTR(ret))
93953 + kmemleak_alloc(ret, size, 1, gfp);
93954 return ret;
93955 }
93956
93957 @@ -493,34 +517,112 @@ void kfree(const void *block)
93958 return;
93959 kmemleak_free(block);
93960
93961 + VM_BUG_ON(!virt_addr_valid(block));
93962 sp = virt_to_page(block);
93963 - if (PageSlab(sp)) {
93964 + VM_BUG_ON(!PageSlab(sp));
93965 + if (!sp->private) {
93966 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
93967 - unsigned int *m = (unsigned int *)(block - align);
93968 - slob_free(m, *m + align);
93969 - } else
93970 + slob_t *m = (slob_t *)(block - align);
93971 + slob_free(m, m[0].units + align);
93972 + } else {
93973 + __ClearPageSlab(sp);
93974 + page_mapcount_reset(sp);
93975 + sp->private = 0;
93976 __free_pages(sp, compound_order(sp));
93977 + }
93978 }
93979 EXPORT_SYMBOL(kfree);
93980
93981 +bool is_usercopy_object(const void *ptr)
93982 +{
93983 + if (!slab_is_available())
93984 + return false;
93985 +
93986 + // PAX: TODO
93987 +
93988 + return false;
93989 +}
93990 +
93991 +#ifdef CONFIG_PAX_USERCOPY
93992 +const char *check_heap_object(const void *ptr, unsigned long n)
93993 +{
93994 + struct page *page;
93995 + const slob_t *free;
93996 + const void *base;
93997 + unsigned long flags;
93998 +
93999 + if (ZERO_OR_NULL_PTR(ptr))
94000 + return "<null>";
94001 +
94002 + if (!virt_addr_valid(ptr))
94003 + return NULL;
94004 +
94005 + page = virt_to_head_page(ptr);
94006 + if (!PageSlab(page))
94007 + return NULL;
94008 +
94009 + if (page->private) {
94010 + base = page;
94011 + if (base <= ptr && n <= page->private - (ptr - base))
94012 + return NULL;
94013 + return "<slob>";
94014 + }
94015 +
94016 + /* some tricky double walking to find the chunk */
94017 + spin_lock_irqsave(&slob_lock, flags);
94018 + base = (void *)((unsigned long)ptr & PAGE_MASK);
94019 + free = page->freelist;
94020 +
94021 + while (!slob_last(free) && (void *)free <= ptr) {
94022 + base = free + slob_units(free);
94023 + free = slob_next(free);
94024 + }
94025 +
94026 + while (base < (void *)free) {
94027 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
94028 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
94029 + int offset;
94030 +
94031 + if (ptr < base + align)
94032 + break;
94033 +
94034 + offset = ptr - base - align;
94035 + if (offset >= m) {
94036 + base += size;
94037 + continue;
94038 + }
94039 +
94040 + if (n > m - offset)
94041 + break;
94042 +
94043 + spin_unlock_irqrestore(&slob_lock, flags);
94044 + return NULL;
94045 + }
94046 +
94047 + spin_unlock_irqrestore(&slob_lock, flags);
94048 + return "<slob>";
94049 +}
94050 +#endif
94051 +
94052 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
94053 size_t ksize(const void *block)
94054 {
94055 struct page *sp;
94056 int align;
94057 - unsigned int *m;
94058 + slob_t *m;
94059
94060 BUG_ON(!block);
94061 if (unlikely(block == ZERO_SIZE_PTR))
94062 return 0;
94063
94064 sp = virt_to_page(block);
94065 - if (unlikely(!PageSlab(sp)))
94066 - return PAGE_SIZE << compound_order(sp);
94067 + VM_BUG_ON(!PageSlab(sp));
94068 + if (sp->private)
94069 + return sp->private;
94070
94071 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94072 - m = (unsigned int *)(block - align);
94073 - return SLOB_UNITS(*m) * SLOB_UNIT;
94074 + m = (slob_t *)(block - align);
94075 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
94076 }
94077 EXPORT_SYMBOL(ksize);
94078
94079 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
94080
94081 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
94082 {
94083 - void *b;
94084 + void *b = NULL;
94085
94086 flags &= gfp_allowed_mask;
94087
94088 lockdep_trace_alloc(flags);
94089
94090 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94091 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
94092 +#else
94093 if (c->size < PAGE_SIZE) {
94094 b = slob_alloc(c->size, flags, c->align, node);
94095 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
94096 SLOB_UNITS(c->size) * SLOB_UNIT,
94097 flags, node);
94098 } else {
94099 - b = slob_new_pages(flags, get_order(c->size), node);
94100 + struct page *sp;
94101 +
94102 + sp = slob_new_pages(flags, get_order(c->size), node);
94103 + if (sp) {
94104 + b = page_address(sp);
94105 + sp->private = c->size;
94106 + }
94107 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
94108 PAGE_SIZE << get_order(c->size),
94109 flags, node);
94110 }
94111 +#endif
94112
94113 if (b && c->ctor)
94114 c->ctor(b);
94115 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
94116
94117 static void __kmem_cache_free(void *b, int size)
94118 {
94119 - if (size < PAGE_SIZE)
94120 + struct page *sp;
94121 +
94122 + sp = virt_to_page(b);
94123 + BUG_ON(!PageSlab(sp));
94124 + if (!sp->private)
94125 slob_free(b, size);
94126 else
94127 - slob_free_pages(b, get_order(size));
94128 + slob_free_pages(sp, get_order(size));
94129 }
94130
94131 static void kmem_rcu_free(struct rcu_head *head)
94132 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
94133
94134 void kmem_cache_free(struct kmem_cache *c, void *b)
94135 {
94136 + int size = c->size;
94137 +
94138 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94139 + if (size + c->align < PAGE_SIZE) {
94140 + size += c->align;
94141 + b -= c->align;
94142 + }
94143 +#endif
94144 +
94145 kmemleak_free_recursive(b, c->flags);
94146 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
94147 struct slob_rcu *slob_rcu;
94148 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
94149 - slob_rcu->size = c->size;
94150 + slob_rcu = b + (size - sizeof(struct slob_rcu));
94151 + slob_rcu->size = size;
94152 call_rcu(&slob_rcu->head, kmem_rcu_free);
94153 } else {
94154 - __kmem_cache_free(b, c->size);
94155 + __kmem_cache_free(b, size);
94156 }
94157
94158 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94159 + trace_kfree(_RET_IP_, b);
94160 +#else
94161 trace_kmem_cache_free(_RET_IP_, b);
94162 +#endif
94163 +
94164 }
94165 EXPORT_SYMBOL(kmem_cache_free);
94166
94167 diff --git a/mm/slub.c b/mm/slub.c
94168 index 545a170..a086226 100644
94169 --- a/mm/slub.c
94170 +++ b/mm/slub.c
94171 @@ -207,7 +207,7 @@ struct track {
94172
94173 enum track_item { TRACK_ALLOC, TRACK_FREE };
94174
94175 -#ifdef CONFIG_SYSFS
94176 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94177 static int sysfs_slab_add(struct kmem_cache *);
94178 static int sysfs_slab_alias(struct kmem_cache *, const char *);
94179 static void sysfs_slab_remove(struct kmem_cache *);
94180 @@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
94181 if (!t->addr)
94182 return;
94183
94184 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
94185 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
94186 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
94187 #ifdef CONFIG_STACKTRACE
94188 {
94189 @@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
94190
94191 slab_free_hook(s, x);
94192
94193 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94194 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
94195 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
94196 + if (s->ctor)
94197 + s->ctor(x);
94198 + }
94199 +#endif
94200 +
94201 redo:
94202 /*
94203 * Determine the currently cpus per cpu slab.
94204 @@ -2710,7 +2718,7 @@ static int slub_min_objects;
94205 * Merge control. If this is set then no merging of slab caches will occur.
94206 * (Could be removed. This was introduced to pacify the merge skeptics.)
94207 */
94208 -static int slub_nomerge;
94209 +static int slub_nomerge = 1;
94210
94211 /*
94212 * Calculate the order of allocation given an slab object size.
94213 @@ -2987,6 +2995,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
94214 s->inuse = size;
94215
94216 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
94217 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94218 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
94219 +#endif
94220 s->ctor)) {
94221 /*
94222 * Relocate free pointer after the object if it is not
94223 @@ -3332,6 +3343,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
94224 EXPORT_SYMBOL(__kmalloc_node);
94225 #endif
94226
94227 +bool is_usercopy_object(const void *ptr)
94228 +{
94229 + struct page *page;
94230 + struct kmem_cache *s;
94231 +
94232 + if (ZERO_OR_NULL_PTR(ptr))
94233 + return false;
94234 +
94235 + if (!slab_is_available())
94236 + return false;
94237 +
94238 + if (!virt_addr_valid(ptr))
94239 + return false;
94240 +
94241 + page = virt_to_head_page(ptr);
94242 +
94243 + if (!PageSlab(page))
94244 + return false;
94245 +
94246 + s = page->slab_cache;
94247 + return s->flags & SLAB_USERCOPY;
94248 +}
94249 +
94250 +#ifdef CONFIG_PAX_USERCOPY
94251 +const char *check_heap_object(const void *ptr, unsigned long n)
94252 +{
94253 + struct page *page;
94254 + struct kmem_cache *s;
94255 + unsigned long offset;
94256 +
94257 + if (ZERO_OR_NULL_PTR(ptr))
94258 + return "<null>";
94259 +
94260 + if (!virt_addr_valid(ptr))
94261 + return NULL;
94262 +
94263 + page = virt_to_head_page(ptr);
94264 +
94265 + if (!PageSlab(page))
94266 + return NULL;
94267 +
94268 + s = page->slab_cache;
94269 + if (!(s->flags & SLAB_USERCOPY))
94270 + return s->name;
94271 +
94272 + offset = (ptr - page_address(page)) % s->size;
94273 + if (offset <= s->object_size && n <= s->object_size - offset)
94274 + return NULL;
94275 +
94276 + return s->name;
94277 +}
94278 +#endif
94279 +
94280 size_t ksize(const void *object)
94281 {
94282 struct page *page;
94283 @@ -3360,6 +3424,7 @@ void kfree(const void *x)
94284 if (unlikely(ZERO_OR_NULL_PTR(x)))
94285 return;
94286
94287 + VM_BUG_ON(!virt_addr_valid(x));
94288 page = virt_to_head_page(x);
94289 if (unlikely(!PageSlab(page))) {
94290 BUG_ON(!PageCompound(page));
94291 @@ -3665,7 +3730,7 @@ static int slab_unmergeable(struct kmem_cache *s)
94292 /*
94293 * We may have set a slab to be unmergeable during bootstrap.
94294 */
94295 - if (s->refcount < 0)
94296 + if (atomic_read(&s->refcount) < 0)
94297 return 1;
94298
94299 return 0;
94300 @@ -3723,7 +3788,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94301
94302 s = find_mergeable(memcg, size, align, flags, name, ctor);
94303 if (s) {
94304 - s->refcount++;
94305 + atomic_inc(&s->refcount);
94306 /*
94307 * Adjust the object sizes so that we clear
94308 * the complete object on kzalloc.
94309 @@ -3732,7 +3797,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94310 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
94311
94312 if (sysfs_slab_alias(s, name)) {
94313 - s->refcount--;
94314 + atomic_dec(&s->refcount);
94315 s = NULL;
94316 }
94317 }
94318 @@ -3852,7 +3917,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
94319 }
94320 #endif
94321
94322 -#ifdef CONFIG_SYSFS
94323 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94324 static int count_inuse(struct page *page)
94325 {
94326 return page->inuse;
94327 @@ -4241,12 +4306,12 @@ static void resiliency_test(void)
94328 validate_slab_cache(kmalloc_caches[9]);
94329 }
94330 #else
94331 -#ifdef CONFIG_SYSFS
94332 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94333 static void resiliency_test(void) {};
94334 #endif
94335 #endif
94336
94337 -#ifdef CONFIG_SYSFS
94338 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94339 enum slab_stat_type {
94340 SL_ALL, /* All slabs */
94341 SL_PARTIAL, /* Only partially allocated slabs */
94342 @@ -4486,7 +4551,7 @@ SLAB_ATTR_RO(ctor);
94343
94344 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
94345 {
94346 - return sprintf(buf, "%d\n", s->refcount - 1);
94347 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
94348 }
94349 SLAB_ATTR_RO(aliases);
94350
94351 @@ -4574,6 +4639,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
94352 SLAB_ATTR_RO(cache_dma);
94353 #endif
94354
94355 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94356 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
94357 +{
94358 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
94359 +}
94360 +SLAB_ATTR_RO(usercopy);
94361 +#endif
94362 +
94363 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
94364 {
94365 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
94366 @@ -4908,6 +4981,9 @@ static struct attribute *slab_attrs[] = {
94367 #ifdef CONFIG_ZONE_DMA
94368 &cache_dma_attr.attr,
94369 #endif
94370 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94371 + &usercopy_attr.attr,
94372 +#endif
94373 #ifdef CONFIG_NUMA
94374 &remote_node_defrag_ratio_attr.attr,
94375 #endif
94376 @@ -5140,6 +5216,7 @@ static char *create_unique_id(struct kmem_cache *s)
94377 return name;
94378 }
94379
94380 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94381 static int sysfs_slab_add(struct kmem_cache *s)
94382 {
94383 int err;
94384 @@ -5163,7 +5240,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
94385 }
94386
94387 s->kobj.kset = slab_kset;
94388 - err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
94389 + err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
94390 if (err) {
94391 kobject_put(&s->kobj);
94392 return err;
94393 @@ -5197,6 +5274,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
94394 kobject_del(&s->kobj);
94395 kobject_put(&s->kobj);
94396 }
94397 +#endif
94398
94399 /*
94400 * Need to buffer aliases during bootup until sysfs becomes
94401 @@ -5210,6 +5288,7 @@ struct saved_alias {
94402
94403 static struct saved_alias *alias_list;
94404
94405 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94406 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
94407 {
94408 struct saved_alias *al;
94409 @@ -5232,6 +5311,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
94410 alias_list = al;
94411 return 0;
94412 }
94413 +#endif
94414
94415 static int __init slab_sysfs_init(void)
94416 {
94417 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
94418 index 27eeab3..7c3f7f2 100644
94419 --- a/mm/sparse-vmemmap.c
94420 +++ b/mm/sparse-vmemmap.c
94421 @@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
94422 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
94423 if (!p)
94424 return NULL;
94425 - pud_populate(&init_mm, pud, p);
94426 + pud_populate_kernel(&init_mm, pud, p);
94427 }
94428 return pud;
94429 }
94430 @@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
94431 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
94432 if (!p)
94433 return NULL;
94434 - pgd_populate(&init_mm, pgd, p);
94435 + pgd_populate_kernel(&init_mm, pgd, p);
94436 }
94437 return pgd;
94438 }
94439 diff --git a/mm/sparse.c b/mm/sparse.c
94440 index 8cc7be0..d0f7d7a 100644
94441 --- a/mm/sparse.c
94442 +++ b/mm/sparse.c
94443 @@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
94444
94445 for (i = 0; i < PAGES_PER_SECTION; i++) {
94446 if (PageHWPoison(&memmap[i])) {
94447 - atomic_long_sub(1, &num_poisoned_pages);
94448 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
94449 ClearPageHWPoison(&memmap[i]);
94450 }
94451 }
94452 diff --git a/mm/swap.c b/mm/swap.c
94453 index 84b26aa..ce39899 100644
94454 --- a/mm/swap.c
94455 +++ b/mm/swap.c
94456 @@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
94457
94458 __page_cache_release(page);
94459 dtor = get_compound_page_dtor(page);
94460 + if (!PageHuge(page))
94461 + BUG_ON(dtor != free_compound_page);
94462 (*dtor)(page);
94463 }
94464
94465 diff --git a/mm/swapfile.c b/mm/swapfile.c
94466 index 612a7c9..66b0f5a 100644
94467 --- a/mm/swapfile.c
94468 +++ b/mm/swapfile.c
94469 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
94470
94471 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
94472 /* Activity counter to indicate that a swapon or swapoff has occurred */
94473 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
94474 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
94475
94476 static inline unsigned char swap_count(unsigned char ent)
94477 {
94478 @@ -1949,7 +1949,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
94479 }
94480 filp_close(swap_file, NULL);
94481 err = 0;
94482 - atomic_inc(&proc_poll_event);
94483 + atomic_inc_unchecked(&proc_poll_event);
94484 wake_up_interruptible(&proc_poll_wait);
94485
94486 out_dput:
94487 @@ -1966,8 +1966,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
94488
94489 poll_wait(file, &proc_poll_wait, wait);
94490
94491 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
94492 - seq->poll_event = atomic_read(&proc_poll_event);
94493 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
94494 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
94495 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
94496 }
94497
94498 @@ -2065,7 +2065,7 @@ static int swaps_open(struct inode *inode, struct file *file)
94499 return ret;
94500
94501 seq = file->private_data;
94502 - seq->poll_event = atomic_read(&proc_poll_event);
94503 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
94504 return 0;
94505 }
94506
94507 @@ -2524,7 +2524,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
94508 (frontswap_map) ? "FS" : "");
94509
94510 mutex_unlock(&swapon_mutex);
94511 - atomic_inc(&proc_poll_event);
94512 + atomic_inc_unchecked(&proc_poll_event);
94513 wake_up_interruptible(&proc_poll_wait);
94514
94515 if (S_ISREG(inode->i_mode))
94516 diff --git a/mm/util.c b/mm/util.c
94517 index 808f375..e4764b5 100644
94518 --- a/mm/util.c
94519 +++ b/mm/util.c
94520 @@ -297,6 +297,12 @@ done:
94521 void arch_pick_mmap_layout(struct mm_struct *mm)
94522 {
94523 mm->mmap_base = TASK_UNMAPPED_BASE;
94524 +
94525 +#ifdef CONFIG_PAX_RANDMMAP
94526 + if (mm->pax_flags & MF_PAX_RANDMMAP)
94527 + mm->mmap_base += mm->delta_mmap;
94528 +#endif
94529 +
94530 mm->get_unmapped_area = arch_get_unmapped_area;
94531 }
94532 #endif
94533 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
94534 index 0fdf968..d6686e8 100644
94535 --- a/mm/vmalloc.c
94536 +++ b/mm/vmalloc.c
94537 @@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
94538
94539 pte = pte_offset_kernel(pmd, addr);
94540 do {
94541 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
94542 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
94543 +
94544 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94545 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
94546 + BUG_ON(!pte_exec(*pte));
94547 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
94548 + continue;
94549 + }
94550 +#endif
94551 +
94552 + {
94553 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
94554 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
94555 + }
94556 } while (pte++, addr += PAGE_SIZE, addr != end);
94557 }
94558
94559 @@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
94560 pte = pte_alloc_kernel(pmd, addr);
94561 if (!pte)
94562 return -ENOMEM;
94563 +
94564 + pax_open_kernel();
94565 do {
94566 struct page *page = pages[*nr];
94567
94568 - if (WARN_ON(!pte_none(*pte)))
94569 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94570 + if (pgprot_val(prot) & _PAGE_NX)
94571 +#endif
94572 +
94573 + if (!pte_none(*pte)) {
94574 + pax_close_kernel();
94575 + WARN_ON(1);
94576 return -EBUSY;
94577 - if (WARN_ON(!page))
94578 + }
94579 + if (!page) {
94580 + pax_close_kernel();
94581 + WARN_ON(1);
94582 return -ENOMEM;
94583 + }
94584 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
94585 (*nr)++;
94586 } while (pte++, addr += PAGE_SIZE, addr != end);
94587 + pax_close_kernel();
94588 return 0;
94589 }
94590
94591 @@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
94592 pmd_t *pmd;
94593 unsigned long next;
94594
94595 - pmd = pmd_alloc(&init_mm, pud, addr);
94596 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94597 if (!pmd)
94598 return -ENOMEM;
94599 do {
94600 @@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
94601 pud_t *pud;
94602 unsigned long next;
94603
94604 - pud = pud_alloc(&init_mm, pgd, addr);
94605 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
94606 if (!pud)
94607 return -ENOMEM;
94608 do {
94609 @@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
94610 if (addr >= MODULES_VADDR && addr < MODULES_END)
94611 return 1;
94612 #endif
94613 +
94614 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94615 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
94616 + return 1;
94617 +#endif
94618 +
94619 return is_vmalloc_addr(x);
94620 }
94621
94622 @@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
94623
94624 if (!pgd_none(*pgd)) {
94625 pud_t *pud = pud_offset(pgd, addr);
94626 +#ifdef CONFIG_X86
94627 + if (!pud_large(*pud))
94628 +#endif
94629 if (!pud_none(*pud)) {
94630 pmd_t *pmd = pmd_offset(pud, addr);
94631 +#ifdef CONFIG_X86
94632 + if (!pmd_large(*pmd))
94633 +#endif
94634 if (!pmd_none(*pmd)) {
94635 pte_t *ptep, pte;
94636
94637 @@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
94638 struct vm_struct *area;
94639
94640 BUG_ON(in_interrupt());
94641 +
94642 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94643 + if (flags & VM_KERNEXEC) {
94644 + if (start != VMALLOC_START || end != VMALLOC_END)
94645 + return NULL;
94646 + start = (unsigned long)MODULES_EXEC_VADDR;
94647 + end = (unsigned long)MODULES_EXEC_END;
94648 + }
94649 +#endif
94650 +
94651 if (flags & VM_IOREMAP)
94652 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
94653
94654 @@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
94655 if (count > totalram_pages)
94656 return NULL;
94657
94658 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94659 + if (!(pgprot_val(prot) & _PAGE_NX))
94660 + flags |= VM_KERNEXEC;
94661 +#endif
94662 +
94663 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
94664 __builtin_return_address(0));
94665 if (!area)
94666 @@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
94667 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
94668 goto fail;
94669
94670 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94671 + if (!(pgprot_val(prot) & _PAGE_NX))
94672 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
94673 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
94674 + else
94675 +#endif
94676 +
94677 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
94678 start, end, node, gfp_mask, caller);
94679 if (!area)
94680 @@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
94681 * For tight control over page level allocator and protection flags
94682 * use __vmalloc() instead.
94683 */
94684 -
94685 void *vmalloc_exec(unsigned long size)
94686 {
94687 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
94688 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
94689 NUMA_NO_NODE, __builtin_return_address(0));
94690 }
94691
94692 @@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
94693 {
94694 struct vm_struct *area;
94695
94696 + BUG_ON(vma->vm_mirror);
94697 +
94698 size = PAGE_ALIGN(size);
94699
94700 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
94701 @@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
94702 v->addr, v->addr + v->size, v->size);
94703
94704 if (v->caller)
94705 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94706 + seq_printf(m, " %pK", v->caller);
94707 +#else
94708 seq_printf(m, " %pS", v->caller);
94709 +#endif
94710
94711 if (v->nr_pages)
94712 seq_printf(m, " pages=%d", v->nr_pages);
94713 diff --git a/mm/vmstat.c b/mm/vmstat.c
94714 index 7249614..2639fc7 100644
94715 --- a/mm/vmstat.c
94716 +++ b/mm/vmstat.c
94717 @@ -20,6 +20,7 @@
94718 #include <linux/writeback.h>
94719 #include <linux/compaction.h>
94720 #include <linux/mm_inline.h>
94721 +#include <linux/grsecurity.h>
94722
94723 #include "internal.h"
94724
94725 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
94726 *
94727 * vm_stat contains the global counters
94728 */
94729 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
94730 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
94731 EXPORT_SYMBOL(vm_stat);
94732
94733 #ifdef CONFIG_SMP
94734 @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
94735
94736 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
94737 if (diff[i])
94738 - atomic_long_add(diff[i], &vm_stat[i]);
94739 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
94740 }
94741
94742 /*
94743 @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
94744 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
94745 if (v) {
94746
94747 - atomic_long_add(v, &zone->vm_stat[i]);
94748 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94749 global_diff[i] += v;
94750 #ifdef CONFIG_NUMA
94751 /* 3 seconds idle till flush */
94752 @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
94753
94754 v = p->vm_stat_diff[i];
94755 p->vm_stat_diff[i] = 0;
94756 - atomic_long_add(v, &zone->vm_stat[i]);
94757 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94758 global_diff[i] += v;
94759 }
94760 }
94761 @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
94762 if (pset->vm_stat_diff[i]) {
94763 int v = pset->vm_stat_diff[i];
94764 pset->vm_stat_diff[i] = 0;
94765 - atomic_long_add(v, &zone->vm_stat[i]);
94766 - atomic_long_add(v, &vm_stat[i]);
94767 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94768 + atomic_long_add_unchecked(v, &vm_stat[i]);
94769 }
94770 }
94771 #endif
94772 @@ -1148,10 +1149,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
94773 stat_items_size += sizeof(struct vm_event_state);
94774 #endif
94775
94776 - v = kmalloc(stat_items_size, GFP_KERNEL);
94777 + v = kzalloc(stat_items_size, GFP_KERNEL);
94778 m->private = v;
94779 if (!v)
94780 return ERR_PTR(-ENOMEM);
94781 +
94782 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94783 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
94784 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
94785 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
94786 + && !in_group_p(grsec_proc_gid)
94787 +#endif
94788 + )
94789 + return (unsigned long *)m->private + *pos;
94790 +#endif
94791 +#endif
94792 +
94793 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
94794 v[i] = global_page_state(i);
94795 v += NR_VM_ZONE_STAT_ITEMS;
94796 @@ -1300,10 +1313,16 @@ static int __init setup_vmstat(void)
94797 put_online_cpus();
94798 #endif
94799 #ifdef CONFIG_PROC_FS
94800 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
94801 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
94802 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
94803 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
94804 + {
94805 + mode_t gr_mode = S_IRUGO;
94806 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94807 + gr_mode = S_IRUSR;
94808 +#endif
94809 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
94810 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
94811 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
94812 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
94813 + }
94814 #endif
94815 return 0;
94816 }
94817 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
94818 index b3d17d1..e8e4cdd 100644
94819 --- a/net/8021q/vlan.c
94820 +++ b/net/8021q/vlan.c
94821 @@ -472,7 +472,7 @@ out:
94822 return NOTIFY_DONE;
94823 }
94824
94825 -static struct notifier_block vlan_notifier_block __read_mostly = {
94826 +static struct notifier_block vlan_notifier_block = {
94827 .notifier_call = vlan_device_event,
94828 };
94829
94830 @@ -547,8 +547,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
94831 err = -EPERM;
94832 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
94833 break;
94834 - if ((args.u.name_type >= 0) &&
94835 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
94836 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
94837 struct vlan_net *vn;
94838
94839 vn = net_generic(net, vlan_net_id);
94840 diff --git a/net/9p/client.c b/net/9p/client.c
94841 index ee8fd6b..0469d50 100644
94842 --- a/net/9p/client.c
94843 +++ b/net/9p/client.c
94844 @@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
94845 len - inline_len);
94846 } else {
94847 err = copy_from_user(ename + inline_len,
94848 - uidata, len - inline_len);
94849 + (char __force_user *)uidata, len - inline_len);
94850 if (err) {
94851 err = -EFAULT;
94852 goto out_err;
94853 @@ -1563,7 +1563,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
94854 kernel_buf = 1;
94855 indata = data;
94856 } else
94857 - indata = (__force char *)udata;
94858 + indata = (__force_kernel char *)udata;
94859 /*
94860 * response header len is 11
94861 * PDU Header(7) + IO Size (4)
94862 @@ -1638,7 +1638,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
94863 kernel_buf = 1;
94864 odata = data;
94865 } else
94866 - odata = (char *)udata;
94867 + odata = (char __force_kernel *)udata;
94868 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
94869 P9_ZC_HDR_SZ, kernel_buf, "dqd",
94870 fid->fid, offset, rsize);
94871 diff --git a/net/9p/mod.c b/net/9p/mod.c
94872 index 6ab36ae..6f1841b 100644
94873 --- a/net/9p/mod.c
94874 +++ b/net/9p/mod.c
94875 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
94876 void v9fs_register_trans(struct p9_trans_module *m)
94877 {
94878 spin_lock(&v9fs_trans_lock);
94879 - list_add_tail(&m->list, &v9fs_trans_list);
94880 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
94881 spin_unlock(&v9fs_trans_lock);
94882 }
94883 EXPORT_SYMBOL(v9fs_register_trans);
94884 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
94885 void v9fs_unregister_trans(struct p9_trans_module *m)
94886 {
94887 spin_lock(&v9fs_trans_lock);
94888 - list_del_init(&m->list);
94889 + pax_list_del_init((struct list_head *)&m->list);
94890 spin_unlock(&v9fs_trans_lock);
94891 }
94892 EXPORT_SYMBOL(v9fs_unregister_trans);
94893 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
94894 index 9321a77..ed2f256 100644
94895 --- a/net/9p/trans_fd.c
94896 +++ b/net/9p/trans_fd.c
94897 @@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
94898 oldfs = get_fs();
94899 set_fs(get_ds());
94900 /* The cast to a user pointer is valid due to the set_fs() */
94901 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
94902 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
94903 set_fs(oldfs);
94904
94905 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
94906 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
94907 index 876fbe8..8bbea9f 100644
94908 --- a/net/atm/atm_misc.c
94909 +++ b/net/atm/atm_misc.c
94910 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
94911 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
94912 return 1;
94913 atm_return(vcc, truesize);
94914 - atomic_inc(&vcc->stats->rx_drop);
94915 + atomic_inc_unchecked(&vcc->stats->rx_drop);
94916 return 0;
94917 }
94918 EXPORT_SYMBOL(atm_charge);
94919 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
94920 }
94921 }
94922 atm_return(vcc, guess);
94923 - atomic_inc(&vcc->stats->rx_drop);
94924 + atomic_inc_unchecked(&vcc->stats->rx_drop);
94925 return NULL;
94926 }
94927 EXPORT_SYMBOL(atm_alloc_charge);
94928 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
94929
94930 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
94931 {
94932 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
94933 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
94934 __SONET_ITEMS
94935 #undef __HANDLE_ITEM
94936 }
94937 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
94938
94939 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
94940 {
94941 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
94942 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
94943 __SONET_ITEMS
94944 #undef __HANDLE_ITEM
94945 }
94946 diff --git a/net/atm/lec.c b/net/atm/lec.c
94947 index f23916b..dd4d26b 100644
94948 --- a/net/atm/lec.c
94949 +++ b/net/atm/lec.c
94950 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
94951 }
94952
94953 static struct lane2_ops lane2_ops = {
94954 - lane2_resolve, /* resolve, spec 3.1.3 */
94955 - lane2_associate_req, /* associate_req, spec 3.1.4 */
94956 - NULL /* associate indicator, spec 3.1.5 */
94957 + .resolve = lane2_resolve,
94958 + .associate_req = lane2_associate_req,
94959 + .associate_indicator = NULL
94960 };
94961
94962 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
94963 diff --git a/net/atm/lec.h b/net/atm/lec.h
94964 index 4149db1..f2ab682 100644
94965 --- a/net/atm/lec.h
94966 +++ b/net/atm/lec.h
94967 @@ -48,7 +48,7 @@ struct lane2_ops {
94968 const u8 *tlvs, u32 sizeoftlvs);
94969 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
94970 const u8 *tlvs, u32 sizeoftlvs);
94971 -};
94972 +} __no_const;
94973
94974 /*
94975 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
94976 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
94977 index d1b2d9a..d549f7f 100644
94978 --- a/net/atm/mpoa_caches.c
94979 +++ b/net/atm/mpoa_caches.c
94980 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
94981
94982
94983 static struct in_cache_ops ingress_ops = {
94984 - in_cache_add_entry, /* add_entry */
94985 - in_cache_get, /* get */
94986 - in_cache_get_with_mask, /* get_with_mask */
94987 - in_cache_get_by_vcc, /* get_by_vcc */
94988 - in_cache_put, /* put */
94989 - in_cache_remove_entry, /* remove_entry */
94990 - cache_hit, /* cache_hit */
94991 - clear_count_and_expired, /* clear_count */
94992 - check_resolving_entries, /* check_resolving */
94993 - refresh_entries, /* refresh */
94994 - in_destroy_cache /* destroy_cache */
94995 + .add_entry = in_cache_add_entry,
94996 + .get = in_cache_get,
94997 + .get_with_mask = in_cache_get_with_mask,
94998 + .get_by_vcc = in_cache_get_by_vcc,
94999 + .put = in_cache_put,
95000 + .remove_entry = in_cache_remove_entry,
95001 + .cache_hit = cache_hit,
95002 + .clear_count = clear_count_and_expired,
95003 + .check_resolving = check_resolving_entries,
95004 + .refresh = refresh_entries,
95005 + .destroy_cache = in_destroy_cache
95006 };
95007
95008 static struct eg_cache_ops egress_ops = {
95009 - eg_cache_add_entry, /* add_entry */
95010 - eg_cache_get_by_cache_id, /* get_by_cache_id */
95011 - eg_cache_get_by_tag, /* get_by_tag */
95012 - eg_cache_get_by_vcc, /* get_by_vcc */
95013 - eg_cache_get_by_src_ip, /* get_by_src_ip */
95014 - eg_cache_put, /* put */
95015 - eg_cache_remove_entry, /* remove_entry */
95016 - update_eg_cache_entry, /* update */
95017 - clear_expired, /* clear_expired */
95018 - eg_destroy_cache /* destroy_cache */
95019 + .add_entry = eg_cache_add_entry,
95020 + .get_by_cache_id = eg_cache_get_by_cache_id,
95021 + .get_by_tag = eg_cache_get_by_tag,
95022 + .get_by_vcc = eg_cache_get_by_vcc,
95023 + .get_by_src_ip = eg_cache_get_by_src_ip,
95024 + .put = eg_cache_put,
95025 + .remove_entry = eg_cache_remove_entry,
95026 + .update = update_eg_cache_entry,
95027 + .clear_expired = clear_expired,
95028 + .destroy_cache = eg_destroy_cache
95029 };
95030
95031
95032 diff --git a/net/atm/proc.c b/net/atm/proc.c
95033 index bbb6461..cf04016 100644
95034 --- a/net/atm/proc.c
95035 +++ b/net/atm/proc.c
95036 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
95037 const struct k_atm_aal_stats *stats)
95038 {
95039 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
95040 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
95041 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
95042 - atomic_read(&stats->rx_drop));
95043 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
95044 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
95045 + atomic_read_unchecked(&stats->rx_drop));
95046 }
95047
95048 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
95049 diff --git a/net/atm/resources.c b/net/atm/resources.c
95050 index 0447d5d..3cf4728 100644
95051 --- a/net/atm/resources.c
95052 +++ b/net/atm/resources.c
95053 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
95054 static void copy_aal_stats(struct k_atm_aal_stats *from,
95055 struct atm_aal_stats *to)
95056 {
95057 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
95058 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
95059 __AAL_STAT_ITEMS
95060 #undef __HANDLE_ITEM
95061 }
95062 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
95063 static void subtract_aal_stats(struct k_atm_aal_stats *from,
95064 struct atm_aal_stats *to)
95065 {
95066 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
95067 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
95068 __AAL_STAT_ITEMS
95069 #undef __HANDLE_ITEM
95070 }
95071 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
95072 index 919a5ce..cc6b444 100644
95073 --- a/net/ax25/sysctl_net_ax25.c
95074 +++ b/net/ax25/sysctl_net_ax25.c
95075 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
95076 {
95077 char path[sizeof("net/ax25/") + IFNAMSIZ];
95078 int k;
95079 - struct ctl_table *table;
95080 + ctl_table_no_const *table;
95081
95082 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
95083 if (!table)
95084 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
95085 index b9c8a6e..ed0f711 100644
95086 --- a/net/batman-adv/bat_iv_ogm.c
95087 +++ b/net/batman-adv/bat_iv_ogm.c
95088 @@ -297,7 +297,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
95089
95090 /* randomize initial seqno to avoid collision */
95091 get_random_bytes(&random_seqno, sizeof(random_seqno));
95092 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
95093 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
95094
95095 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
95096 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
95097 @@ -884,9 +884,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
95098 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
95099
95100 /* change sequence number to network order */
95101 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
95102 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
95103 batadv_ogm_packet->seqno = htonl(seqno);
95104 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
95105 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
95106
95107 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
95108 batadv_iv_ogm_queue_add(bat_priv, hard_iface->bat_iv.ogm_buff,
95109 @@ -1251,7 +1251,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
95110 return;
95111
95112 /* could be changed by schedule_own_packet() */
95113 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
95114 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
95115
95116 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
95117 has_directlink_flag = 1;
95118 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
95119 index 6ddb614..ca7e886 100644
95120 --- a/net/batman-adv/fragmentation.c
95121 +++ b/net/batman-adv/fragmentation.c
95122 @@ -447,7 +447,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
95123 frag_header.packet_type = BATADV_UNICAST_FRAG;
95124 frag_header.version = BATADV_COMPAT_VERSION;
95125 frag_header.ttl = BATADV_TTL;
95126 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
95127 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
95128 frag_header.reserved = 0;
95129 frag_header.no = 0;
95130 frag_header.total_size = htons(skb->len);
95131 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
95132 index a8f99d1..11797ef 100644
95133 --- a/net/batman-adv/soft-interface.c
95134 +++ b/net/batman-adv/soft-interface.c
95135 @@ -278,7 +278,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
95136 primary_if->net_dev->dev_addr, ETH_ALEN);
95137
95138 /* set broadcast sequence number */
95139 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
95140 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
95141 bcast_packet->seqno = htonl(seqno);
95142
95143 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
95144 @@ -688,7 +688,7 @@ static int batadv_softif_init_late(struct net_device *dev)
95145 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
95146
95147 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
95148 - atomic_set(&bat_priv->bcast_seqno, 1);
95149 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
95150 atomic_set(&bat_priv->tt.vn, 0);
95151 atomic_set(&bat_priv->tt.local_changes, 0);
95152 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
95153 @@ -700,7 +700,7 @@ static int batadv_softif_init_late(struct net_device *dev)
95154
95155 /* randomize initial seqno to avoid collision */
95156 get_random_bytes(&random_seqno, sizeof(random_seqno));
95157 - atomic_set(&bat_priv->frag_seqno, random_seqno);
95158 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
95159
95160 bat_priv->primary_if = NULL;
95161 bat_priv->num_ifaces = 0;
95162 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
95163 index 91dd369..9c25750 100644
95164 --- a/net/batman-adv/types.h
95165 +++ b/net/batman-adv/types.h
95166 @@ -56,7 +56,7 @@
95167 struct batadv_hard_iface_bat_iv {
95168 unsigned char *ogm_buff;
95169 int ogm_buff_len;
95170 - atomic_t ogm_seqno;
95171 + atomic_unchecked_t ogm_seqno;
95172 };
95173
95174 /**
95175 @@ -673,7 +673,7 @@ struct batadv_priv {
95176 atomic_t bonding;
95177 atomic_t fragmentation;
95178 atomic_t packet_size_max;
95179 - atomic_t frag_seqno;
95180 + atomic_unchecked_t frag_seqno;
95181 #ifdef CONFIG_BATMAN_ADV_BLA
95182 atomic_t bridge_loop_avoidance;
95183 #endif
95184 @@ -687,7 +687,7 @@ struct batadv_priv {
95185 #ifdef CONFIG_BATMAN_ADV_DEBUG
95186 atomic_t log_level;
95187 #endif
95188 - atomic_t bcast_seqno;
95189 + atomic_unchecked_t bcast_seqno;
95190 atomic_t bcast_queue_left;
95191 atomic_t batman_queue_left;
95192 char num_ifaces;
95193 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
95194 index 7552f9e..074ce29 100644
95195 --- a/net/bluetooth/hci_sock.c
95196 +++ b/net/bluetooth/hci_sock.c
95197 @@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
95198 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
95199 }
95200
95201 - len = min_t(unsigned int, len, sizeof(uf));
95202 + len = min((size_t)len, sizeof(uf));
95203 if (copy_from_user(&uf, optval, len)) {
95204 err = -EFAULT;
95205 break;
95206 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
95207 index 4af3821..f2ba46c 100644
95208 --- a/net/bluetooth/l2cap_core.c
95209 +++ b/net/bluetooth/l2cap_core.c
95210 @@ -3500,8 +3500,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
95211 break;
95212
95213 case L2CAP_CONF_RFC:
95214 - if (olen == sizeof(rfc))
95215 - memcpy(&rfc, (void *)val, olen);
95216 + if (olen != sizeof(rfc))
95217 + break;
95218 +
95219 + memcpy(&rfc, (void *)val, olen);
95220
95221 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
95222 rfc.mode != chan->mode)
95223 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
95224 index 7cc24d2..e83f531 100644
95225 --- a/net/bluetooth/l2cap_sock.c
95226 +++ b/net/bluetooth/l2cap_sock.c
95227 @@ -545,7 +545,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
95228 struct sock *sk = sock->sk;
95229 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
95230 struct l2cap_options opts;
95231 - int len, err = 0;
95232 + int err = 0;
95233 + size_t len = optlen;
95234 u32 opt;
95235
95236 BT_DBG("sk %p", sk);
95237 @@ -567,7 +568,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
95238 opts.max_tx = chan->max_tx;
95239 opts.txwin_size = chan->tx_win;
95240
95241 - len = min_t(unsigned int, sizeof(opts), optlen);
95242 + len = min(sizeof(opts), len);
95243 if (copy_from_user((char *) &opts, optval, len)) {
95244 err = -EFAULT;
95245 break;
95246 @@ -647,7 +648,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95247 struct bt_security sec;
95248 struct bt_power pwr;
95249 struct l2cap_conn *conn;
95250 - int len, err = 0;
95251 + int err = 0;
95252 + size_t len = optlen;
95253 u32 opt;
95254
95255 BT_DBG("sk %p", sk);
95256 @@ -670,7 +672,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95257
95258 sec.level = BT_SECURITY_LOW;
95259
95260 - len = min_t(unsigned int, sizeof(sec), optlen);
95261 + len = min(sizeof(sec), len);
95262 if (copy_from_user((char *) &sec, optval, len)) {
95263 err = -EFAULT;
95264 break;
95265 @@ -770,7 +772,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95266
95267 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
95268
95269 - len = min_t(unsigned int, sizeof(pwr), optlen);
95270 + len = min(sizeof(pwr), len);
95271 if (copy_from_user((char *) &pwr, optval, len)) {
95272 err = -EFAULT;
95273 break;
95274 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
95275 index 3c2d3e4..884855a 100644
95276 --- a/net/bluetooth/rfcomm/sock.c
95277 +++ b/net/bluetooth/rfcomm/sock.c
95278 @@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
95279 struct sock *sk = sock->sk;
95280 struct bt_security sec;
95281 int err = 0;
95282 - size_t len;
95283 + size_t len = optlen;
95284 u32 opt;
95285
95286 BT_DBG("sk %p", sk);
95287 @@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
95288
95289 sec.level = BT_SECURITY_LOW;
95290
95291 - len = min_t(unsigned int, sizeof(sec), optlen);
95292 + len = min(sizeof(sec), len);
95293 if (copy_from_user((char *) &sec, optval, len)) {
95294 err = -EFAULT;
95295 break;
95296 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
95297 index 84fcf9f..e389b27 100644
95298 --- a/net/bluetooth/rfcomm/tty.c
95299 +++ b/net/bluetooth/rfcomm/tty.c
95300 @@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
95301 BT_DBG("tty %p id %d", tty, tty->index);
95302
95303 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
95304 - dev->channel, dev->port.count);
95305 + dev->channel, atomic_read(&dev->port.count));
95306
95307 err = tty_port_open(&dev->port, tty, filp);
95308 if (err)
95309 @@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
95310 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
95311
95312 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
95313 - dev->port.count);
95314 + atomic_read(&dev->port.count));
95315
95316 tty_port_close(&dev->port, tty, filp);
95317 }
95318 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
95319 index ac78024..161a80c 100644
95320 --- a/net/bridge/netfilter/ebtables.c
95321 +++ b/net/bridge/netfilter/ebtables.c
95322 @@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
95323 tmp.valid_hooks = t->table->valid_hooks;
95324 }
95325 mutex_unlock(&ebt_mutex);
95326 - if (copy_to_user(user, &tmp, *len) != 0){
95327 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
95328 BUGPRINT("c2u Didn't work\n");
95329 ret = -EFAULT;
95330 break;
95331 @@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
95332 goto out;
95333 tmp.valid_hooks = t->valid_hooks;
95334
95335 - if (copy_to_user(user, &tmp, *len) != 0) {
95336 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
95337 ret = -EFAULT;
95338 break;
95339 }
95340 @@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
95341 tmp.entries_size = t->table->entries_size;
95342 tmp.valid_hooks = t->table->valid_hooks;
95343
95344 - if (copy_to_user(user, &tmp, *len) != 0) {
95345 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
95346 ret = -EFAULT;
95347 break;
95348 }
95349 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
95350 index 0f45522..dab651f 100644
95351 --- a/net/caif/cfctrl.c
95352 +++ b/net/caif/cfctrl.c
95353 @@ -10,6 +10,7 @@
95354 #include <linux/spinlock.h>
95355 #include <linux/slab.h>
95356 #include <linux/pkt_sched.h>
95357 +#include <linux/sched.h>
95358 #include <net/caif/caif_layer.h>
95359 #include <net/caif/cfpkt.h>
95360 #include <net/caif/cfctrl.h>
95361 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
95362 memset(&dev_info, 0, sizeof(dev_info));
95363 dev_info.id = 0xff;
95364 cfsrvl_init(&this->serv, 0, &dev_info, false);
95365 - atomic_set(&this->req_seq_no, 1);
95366 - atomic_set(&this->rsp_seq_no, 1);
95367 + atomic_set_unchecked(&this->req_seq_no, 1);
95368 + atomic_set_unchecked(&this->rsp_seq_no, 1);
95369 this->serv.layer.receive = cfctrl_recv;
95370 sprintf(this->serv.layer.name, "ctrl");
95371 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
95372 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
95373 struct cfctrl_request_info *req)
95374 {
95375 spin_lock_bh(&ctrl->info_list_lock);
95376 - atomic_inc(&ctrl->req_seq_no);
95377 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
95378 + atomic_inc_unchecked(&ctrl->req_seq_no);
95379 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
95380 list_add_tail(&req->list, &ctrl->list);
95381 spin_unlock_bh(&ctrl->info_list_lock);
95382 }
95383 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
95384 if (p != first)
95385 pr_warn("Requests are not received in order\n");
95386
95387 - atomic_set(&ctrl->rsp_seq_no,
95388 + atomic_set_unchecked(&ctrl->rsp_seq_no,
95389 p->sequence_no);
95390 list_del(&p->list);
95391 goto out;
95392 diff --git a/net/can/af_can.c b/net/can/af_can.c
95393 index d249874..99e197b 100644
95394 --- a/net/can/af_can.c
95395 +++ b/net/can/af_can.c
95396 @@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
95397 };
95398
95399 /* notifier block for netdevice event */
95400 -static struct notifier_block can_netdev_notifier __read_mostly = {
95401 +static struct notifier_block can_netdev_notifier = {
95402 .notifier_call = can_notifier,
95403 };
95404
95405 diff --git a/net/can/gw.c b/net/can/gw.c
95406 index 3f9b0f3..fc6d4fa 100644
95407 --- a/net/can/gw.c
95408 +++ b/net/can/gw.c
95409 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
95410 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
95411
95412 static HLIST_HEAD(cgw_list);
95413 -static struct notifier_block notifier;
95414
95415 static struct kmem_cache *cgw_cache __read_mostly;
95416
95417 @@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
95418 return err;
95419 }
95420
95421 +static struct notifier_block notifier = {
95422 + .notifier_call = cgw_notifier
95423 +};
95424 +
95425 static __init int cgw_module_init(void)
95426 {
95427 /* sanitize given module parameter */
95428 @@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
95429 return -ENOMEM;
95430
95431 /* set notifier */
95432 - notifier.notifier_call = cgw_notifier;
95433 register_netdevice_notifier(&notifier);
95434
95435 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
95436 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
95437 index 4a5df7b..9ad1f1d 100644
95438 --- a/net/ceph/messenger.c
95439 +++ b/net/ceph/messenger.c
95440 @@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
95441 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
95442
95443 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
95444 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
95445 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
95446
95447 static struct page *zero_page; /* used in certain error cases */
95448
95449 @@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
95450 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
95451 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
95452
95453 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
95454 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
95455 s = addr_str[i];
95456
95457 switch (ss->ss_family) {
95458 diff --git a/net/compat.c b/net/compat.c
95459 index dd32e34..0529c9c 100644
95460 --- a/net/compat.c
95461 +++ b/net/compat.c
95462 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
95463 return -EFAULT;
95464 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
95465 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
95466 - kmsg->msg_name = compat_ptr(tmp1);
95467 - kmsg->msg_iov = compat_ptr(tmp2);
95468 - kmsg->msg_control = compat_ptr(tmp3);
95469 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
95470 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
95471 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
95472 return 0;
95473 }
95474
95475 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95476
95477 if (kern_msg->msg_namelen) {
95478 if (mode == VERIFY_READ) {
95479 - int err = move_addr_to_kernel(kern_msg->msg_name,
95480 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
95481 kern_msg->msg_namelen,
95482 kern_address);
95483 if (err < 0)
95484 @@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95485 kern_msg->msg_name = NULL;
95486
95487 tot_len = iov_from_user_compat_to_kern(kern_iov,
95488 - (struct compat_iovec __user *)kern_msg->msg_iov,
95489 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
95490 kern_msg->msg_iovlen);
95491 if (tot_len >= 0)
95492 kern_msg->msg_iov = kern_iov;
95493 @@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95494
95495 #define CMSG_COMPAT_FIRSTHDR(msg) \
95496 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
95497 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
95498 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
95499 (struct compat_cmsghdr __user *)NULL)
95500
95501 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
95502 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
95503 (ucmlen) <= (unsigned long) \
95504 ((mhdr)->msg_controllen - \
95505 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
95506 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
95507
95508 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
95509 struct compat_cmsghdr __user *cmsg, int cmsg_len)
95510 {
95511 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
95512 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
95513 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
95514 msg->msg_controllen)
95515 return NULL;
95516 return (struct compat_cmsghdr __user *)ptr;
95517 @@ -222,7 +222,7 @@ Efault:
95518
95519 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
95520 {
95521 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
95522 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
95523 struct compat_cmsghdr cmhdr;
95524 struct compat_timeval ctv;
95525 struct compat_timespec cts[3];
95526 @@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
95527
95528 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
95529 {
95530 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
95531 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
95532 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
95533 int fdnum = scm->fp->count;
95534 struct file **fp = scm->fp->fp;
95535 @@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
95536 return -EFAULT;
95537 old_fs = get_fs();
95538 set_fs(KERNEL_DS);
95539 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
95540 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
95541 set_fs(old_fs);
95542
95543 return err;
95544 @@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
95545 len = sizeof(ktime);
95546 old_fs = get_fs();
95547 set_fs(KERNEL_DS);
95548 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
95549 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
95550 set_fs(old_fs);
95551
95552 if (!err) {
95553 @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95554 case MCAST_JOIN_GROUP:
95555 case MCAST_LEAVE_GROUP:
95556 {
95557 - struct compat_group_req __user *gr32 = (void *)optval;
95558 + struct compat_group_req __user *gr32 = (void __user *)optval;
95559 struct group_req __user *kgr =
95560 compat_alloc_user_space(sizeof(struct group_req));
95561 u32 interface;
95562 @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95563 case MCAST_BLOCK_SOURCE:
95564 case MCAST_UNBLOCK_SOURCE:
95565 {
95566 - struct compat_group_source_req __user *gsr32 = (void *)optval;
95567 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
95568 struct group_source_req __user *kgsr = compat_alloc_user_space(
95569 sizeof(struct group_source_req));
95570 u32 interface;
95571 @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95572 }
95573 case MCAST_MSFILTER:
95574 {
95575 - struct compat_group_filter __user *gf32 = (void *)optval;
95576 + struct compat_group_filter __user *gf32 = (void __user *)optval;
95577 struct group_filter __user *kgf;
95578 u32 interface, fmode, numsrc;
95579
95580 @@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
95581 char __user *optval, int __user *optlen,
95582 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
95583 {
95584 - struct compat_group_filter __user *gf32 = (void *)optval;
95585 + struct compat_group_filter __user *gf32 = (void __user *)optval;
95586 struct group_filter __user *kgf;
95587 int __user *koptlen;
95588 u32 interface, fmode, numsrc;
95589 @@ -783,7 +783,7 @@ asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
95590 if (COMPAT_USE_64BIT_TIME)
95591 return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
95592 flags | MSG_CMSG_COMPAT,
95593 - (struct timespec *) timeout);
95594 + (struct timespec __force_kernel *) timeout);
95595
95596 if (timeout == NULL)
95597 return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
95598 @@ -808,7 +808,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
95599
95600 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
95601 return -EINVAL;
95602 - if (copy_from_user(a, args, nas[call]))
95603 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
95604 return -EFAULT;
95605 a0 = a[0];
95606 a1 = a[1];
95607 diff --git a/net/core/datagram.c b/net/core/datagram.c
95608 index a16ed7b..eb44d17 100644
95609 --- a/net/core/datagram.c
95610 +++ b/net/core/datagram.c
95611 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
95612 }
95613
95614 kfree_skb(skb);
95615 - atomic_inc(&sk->sk_drops);
95616 + atomic_inc_unchecked(&sk->sk_drops);
95617 sk_mem_reclaim_partial(sk);
95618
95619 return err;
95620 diff --git a/net/core/dev.c b/net/core/dev.c
95621 index 0ce469e..dfb53d2 100644
95622 --- a/net/core/dev.c
95623 +++ b/net/core/dev.c
95624 @@ -1684,14 +1684,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
95625 {
95626 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
95627 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
95628 - atomic_long_inc(&dev->rx_dropped);
95629 + atomic_long_inc_unchecked(&dev->rx_dropped);
95630 kfree_skb(skb);
95631 return NET_RX_DROP;
95632 }
95633 }
95634
95635 if (unlikely(!is_skb_forwardable(dev, skb))) {
95636 - atomic_long_inc(&dev->rx_dropped);
95637 + atomic_long_inc_unchecked(&dev->rx_dropped);
95638 kfree_skb(skb);
95639 return NET_RX_DROP;
95640 }
95641 @@ -2434,7 +2434,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
95642
95643 struct dev_gso_cb {
95644 void (*destructor)(struct sk_buff *skb);
95645 -};
95646 +} __no_const;
95647
95648 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
95649
95650 @@ -3222,7 +3222,7 @@ enqueue:
95651
95652 local_irq_restore(flags);
95653
95654 - atomic_long_inc(&skb->dev->rx_dropped);
95655 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
95656 kfree_skb(skb);
95657 return NET_RX_DROP;
95658 }
95659 @@ -3294,7 +3294,7 @@ int netif_rx_ni(struct sk_buff *skb)
95660 }
95661 EXPORT_SYMBOL(netif_rx_ni);
95662
95663 -static void net_tx_action(struct softirq_action *h)
95664 +static __latent_entropy void net_tx_action(void)
95665 {
95666 struct softnet_data *sd = &__get_cpu_var(softnet_data);
95667
95668 @@ -3628,7 +3628,7 @@ ncls:
95669 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
95670 } else {
95671 drop:
95672 - atomic_long_inc(&skb->dev->rx_dropped);
95673 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
95674 kfree_skb(skb);
95675 /* Jamal, now you will not able to escape explaining
95676 * me how you were going to use this. :-)
95677 @@ -4288,7 +4288,7 @@ void netif_napi_del(struct napi_struct *napi)
95678 }
95679 EXPORT_SYMBOL(netif_napi_del);
95680
95681 -static void net_rx_action(struct softirq_action *h)
95682 +static __latent_entropy void net_rx_action(void)
95683 {
95684 struct softnet_data *sd = &__get_cpu_var(softnet_data);
95685 unsigned long time_limit = jiffies + 2;
95686 @@ -6177,7 +6177,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
95687 } else {
95688 netdev_stats_to_stats64(storage, &dev->stats);
95689 }
95690 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
95691 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
95692 return storage;
95693 }
95694 EXPORT_SYMBOL(dev_get_stats);
95695 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
95696 index 5b7d0e1..cb960fc 100644
95697 --- a/net/core/dev_ioctl.c
95698 +++ b/net/core/dev_ioctl.c
95699 @@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
95700 if (no_module && capable(CAP_NET_ADMIN))
95701 no_module = request_module("netdev-%s", name);
95702 if (no_module && capable(CAP_SYS_MODULE)) {
95703 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
95704 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
95705 +#else
95706 if (!request_module("%s", name))
95707 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
95708 name);
95709 +#endif
95710 }
95711 }
95712 EXPORT_SYMBOL(dev_load);
95713 diff --git a/net/core/filter.c b/net/core/filter.c
95714 index ad30d62..c2757df 100644
95715 --- a/net/core/filter.c
95716 +++ b/net/core/filter.c
95717 @@ -679,7 +679,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
95718 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
95719 if (!fp)
95720 return -ENOMEM;
95721 - memcpy(fp->insns, fprog->filter, fsize);
95722 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
95723
95724 atomic_set(&fp->refcnt, 1);
95725 fp->len = fprog->len;
95726 diff --git a/net/core/flow.c b/net/core/flow.c
95727 index dfa602c..3103d88 100644
95728 --- a/net/core/flow.c
95729 +++ b/net/core/flow.c
95730 @@ -61,7 +61,7 @@ struct flow_cache {
95731 struct timer_list rnd_timer;
95732 };
95733
95734 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
95735 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
95736 EXPORT_SYMBOL(flow_cache_genid);
95737 static struct flow_cache flow_cache_global;
95738 static struct kmem_cache *flow_cachep __read_mostly;
95739 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
95740
95741 static int flow_entry_valid(struct flow_cache_entry *fle)
95742 {
95743 - if (atomic_read(&flow_cache_genid) != fle->genid)
95744 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
95745 return 0;
95746 if (fle->object && !fle->object->ops->check(fle->object))
95747 return 0;
95748 @@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
95749 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
95750 fcp->hash_count++;
95751 }
95752 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
95753 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
95754 flo = fle->object;
95755 if (!flo)
95756 goto ret_object;
95757 @@ -279,7 +279,7 @@ nocache:
95758 }
95759 flo = resolver(net, key, family, dir, flo, ctx);
95760 if (fle) {
95761 - fle->genid = atomic_read(&flow_cache_genid);
95762 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
95763 if (!IS_ERR(flo))
95764 fle->object = flo;
95765 else
95766 diff --git a/net/core/iovec.c b/net/core/iovec.c
95767 index b618694..192bbba 100644
95768 --- a/net/core/iovec.c
95769 +++ b/net/core/iovec.c
95770 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
95771 if (m->msg_namelen) {
95772 if (mode == VERIFY_READ) {
95773 void __user *namep;
95774 - namep = (void __user __force *) m->msg_name;
95775 + namep = (void __force_user *) m->msg_name;
95776 err = move_addr_to_kernel(namep, m->msg_namelen,
95777 address);
95778 if (err < 0)
95779 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
95780 }
95781
95782 size = m->msg_iovlen * sizeof(struct iovec);
95783 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
95784 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
95785 return -EFAULT;
95786
95787 m->msg_iov = iov;
95788 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
95789 index 932c6d7..7c7aa10 100644
95790 --- a/net/core/neighbour.c
95791 +++ b/net/core/neighbour.c
95792 @@ -2775,7 +2775,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
95793 void __user *buffer, size_t *lenp, loff_t *ppos)
95794 {
95795 int size, ret;
95796 - struct ctl_table tmp = *ctl;
95797 + ctl_table_no_const tmp = *ctl;
95798
95799 tmp.extra1 = &zero;
95800 tmp.extra2 = &unres_qlen_max;
95801 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
95802 index 2bf8329..7960607 100644
95803 --- a/net/core/net-procfs.c
95804 +++ b/net/core/net-procfs.c
95805 @@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
95806 else
95807 seq_printf(seq, "%04x", ntohs(pt->type));
95808
95809 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95810 + seq_printf(seq, " %-8s %pf\n",
95811 + pt->dev ? pt->dev->name : "", NULL);
95812 +#else
95813 seq_printf(seq, " %-8s %pf\n",
95814 pt->dev ? pt->dev->name : "", pt->func);
95815 +#endif
95816 }
95817
95818 return 0;
95819 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
95820 index f3edf96..3cd8b40 100644
95821 --- a/net/core/net-sysfs.c
95822 +++ b/net/core/net-sysfs.c
95823 @@ -1358,7 +1358,7 @@ void netdev_class_remove_file_ns(struct class_attribute *class_attr,
95824 }
95825 EXPORT_SYMBOL(netdev_class_remove_file_ns);
95826
95827 -int netdev_kobject_init(void)
95828 +int __init netdev_kobject_init(void)
95829 {
95830 kobj_ns_type_register(&net_ns_type_operations);
95831 return class_register(&net_class);
95832 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
95833 index 81d3a9a..a0bd7a8 100644
95834 --- a/net/core/net_namespace.c
95835 +++ b/net/core/net_namespace.c
95836 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
95837 int error;
95838 LIST_HEAD(net_exit_list);
95839
95840 - list_add_tail(&ops->list, list);
95841 + pax_list_add_tail((struct list_head *)&ops->list, list);
95842 if (ops->init || (ops->id && ops->size)) {
95843 for_each_net(net) {
95844 error = ops_init(ops, net);
95845 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
95846
95847 out_undo:
95848 /* If I have an error cleanup all namespaces I initialized */
95849 - list_del(&ops->list);
95850 + pax_list_del((struct list_head *)&ops->list);
95851 ops_exit_list(ops, &net_exit_list);
95852 ops_free_list(ops, &net_exit_list);
95853 return error;
95854 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
95855 struct net *net;
95856 LIST_HEAD(net_exit_list);
95857
95858 - list_del(&ops->list);
95859 + pax_list_del((struct list_head *)&ops->list);
95860 for_each_net(net)
95861 list_add_tail(&net->exit_list, &net_exit_list);
95862 ops_exit_list(ops, &net_exit_list);
95863 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
95864 mutex_lock(&net_mutex);
95865 error = register_pernet_operations(&pernet_list, ops);
95866 if (!error && (first_device == &pernet_list))
95867 - first_device = &ops->list;
95868 + first_device = (struct list_head *)&ops->list;
95869 mutex_unlock(&net_mutex);
95870 return error;
95871 }
95872 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
95873 index 19fe9c7..b6bb620 100644
95874 --- a/net/core/netpoll.c
95875 +++ b/net/core/netpoll.c
95876 @@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
95877 struct udphdr *udph;
95878 struct iphdr *iph;
95879 struct ethhdr *eth;
95880 - static atomic_t ip_ident;
95881 + static atomic_unchecked_t ip_ident;
95882 struct ipv6hdr *ip6h;
95883
95884 udp_len = len + sizeof(*udph);
95885 @@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
95886 put_unaligned(0x45, (unsigned char *)iph);
95887 iph->tos = 0;
95888 put_unaligned(htons(ip_len), &(iph->tot_len));
95889 - iph->id = htons(atomic_inc_return(&ip_ident));
95890 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
95891 iph->frag_off = 0;
95892 iph->ttl = 64;
95893 iph->protocol = IPPROTO_UDP;
95894 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
95895 index cf67144..12bf94c 100644
95896 --- a/net/core/rtnetlink.c
95897 +++ b/net/core/rtnetlink.c
95898 @@ -58,7 +58,7 @@ struct rtnl_link {
95899 rtnl_doit_func doit;
95900 rtnl_dumpit_func dumpit;
95901 rtnl_calcit_func calcit;
95902 -};
95903 +} __no_const;
95904
95905 static DEFINE_MUTEX(rtnl_mutex);
95906
95907 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
95908 if (rtnl_link_ops_get(ops->kind))
95909 return -EEXIST;
95910
95911 - if (!ops->dellink)
95912 - ops->dellink = unregister_netdevice_queue;
95913 + if (!ops->dellink) {
95914 + pax_open_kernel();
95915 + *(void **)&ops->dellink = unregister_netdevice_queue;
95916 + pax_close_kernel();
95917 + }
95918
95919 - list_add_tail(&ops->list, &link_ops);
95920 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
95921 return 0;
95922 }
95923 EXPORT_SYMBOL_GPL(__rtnl_link_register);
95924 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
95925 for_each_net(net) {
95926 __rtnl_kill_links(net, ops);
95927 }
95928 - list_del(&ops->list);
95929 + pax_list_del((struct list_head *)&ops->list);
95930 }
95931 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
95932
95933 diff --git a/net/core/scm.c b/net/core/scm.c
95934 index b442e7e..6f5b5a2 100644
95935 --- a/net/core/scm.c
95936 +++ b/net/core/scm.c
95937 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
95938 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
95939 {
95940 struct cmsghdr __user *cm
95941 - = (__force struct cmsghdr __user *)msg->msg_control;
95942 + = (struct cmsghdr __force_user *)msg->msg_control;
95943 struct cmsghdr cmhdr;
95944 int cmlen = CMSG_LEN(len);
95945 int err;
95946 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
95947 err = -EFAULT;
95948 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
95949 goto out;
95950 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
95951 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
95952 goto out;
95953 cmlen = CMSG_SPACE(len);
95954 if (msg->msg_controllen < cmlen)
95955 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
95956 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
95957 {
95958 struct cmsghdr __user *cm
95959 - = (__force struct cmsghdr __user*)msg->msg_control;
95960 + = (struct cmsghdr __force_user *)msg->msg_control;
95961
95962 int fdmax = 0;
95963 int fdnum = scm->fp->count;
95964 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
95965 if (fdnum < fdmax)
95966 fdmax = fdnum;
95967
95968 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
95969 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
95970 i++, cmfptr++)
95971 {
95972 struct socket *sock;
95973 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
95974 index 06e72d3..19dfa7b 100644
95975 --- a/net/core/skbuff.c
95976 +++ b/net/core/skbuff.c
95977 @@ -2034,7 +2034,7 @@ EXPORT_SYMBOL(__skb_checksum);
95978 __wsum skb_checksum(const struct sk_buff *skb, int offset,
95979 int len, __wsum csum)
95980 {
95981 - const struct skb_checksum_ops ops = {
95982 + static const struct skb_checksum_ops ops = {
95983 .update = csum_partial_ext,
95984 .combine = csum_block_add_ext,
95985 };
95986 @@ -3147,13 +3147,15 @@ void __init skb_init(void)
95987 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
95988 sizeof(struct sk_buff),
95989 0,
95990 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
95991 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
95992 + SLAB_NO_SANITIZE,
95993 NULL);
95994 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
95995 (2*sizeof(struct sk_buff)) +
95996 sizeof(atomic_t),
95997 0,
95998 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
95999 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
96000 + SLAB_NO_SANITIZE,
96001 NULL);
96002 }
96003
96004 diff --git a/net/core/sock.c b/net/core/sock.c
96005 index 5393b4b..997c88b 100644
96006 --- a/net/core/sock.c
96007 +++ b/net/core/sock.c
96008 @@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96009 struct sk_buff_head *list = &sk->sk_receive_queue;
96010
96011 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
96012 - atomic_inc(&sk->sk_drops);
96013 + atomic_inc_unchecked(&sk->sk_drops);
96014 trace_sock_rcvqueue_full(sk, skb);
96015 return -ENOMEM;
96016 }
96017 @@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96018 return err;
96019
96020 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
96021 - atomic_inc(&sk->sk_drops);
96022 + atomic_inc_unchecked(&sk->sk_drops);
96023 return -ENOBUFS;
96024 }
96025
96026 @@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96027 skb_dst_force(skb);
96028
96029 spin_lock_irqsave(&list->lock, flags);
96030 - skb->dropcount = atomic_read(&sk->sk_drops);
96031 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
96032 __skb_queue_tail(list, skb);
96033 spin_unlock_irqrestore(&list->lock, flags);
96034
96035 @@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
96036 skb->dev = NULL;
96037
96038 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
96039 - atomic_inc(&sk->sk_drops);
96040 + atomic_inc_unchecked(&sk->sk_drops);
96041 goto discard_and_relse;
96042 }
96043 if (nested)
96044 @@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
96045 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
96046 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
96047 bh_unlock_sock(sk);
96048 - atomic_inc(&sk->sk_drops);
96049 + atomic_inc_unchecked(&sk->sk_drops);
96050 goto discard_and_relse;
96051 }
96052
96053 @@ -950,12 +950,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96054 struct timeval tm;
96055 } v;
96056
96057 - int lv = sizeof(int);
96058 - int len;
96059 + unsigned int lv = sizeof(int);
96060 + unsigned int len;
96061
96062 if (get_user(len, optlen))
96063 return -EFAULT;
96064 - if (len < 0)
96065 + if (len > INT_MAX)
96066 return -EINVAL;
96067
96068 memset(&v, 0, sizeof(v));
96069 @@ -1107,11 +1107,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96070
96071 case SO_PEERNAME:
96072 {
96073 - char address[128];
96074 + char address[_K_SS_MAXSIZE];
96075
96076 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
96077 return -ENOTCONN;
96078 - if (lv < len)
96079 + if (lv < len || sizeof address < len)
96080 return -EINVAL;
96081 if (copy_to_user(optval, address, len))
96082 return -EFAULT;
96083 @@ -1188,7 +1188,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96084
96085 if (len > lv)
96086 len = lv;
96087 - if (copy_to_user(optval, &v, len))
96088 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
96089 return -EFAULT;
96090 lenout:
96091 if (put_user(len, optlen))
96092 @@ -2351,7 +2351,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
96093 */
96094 smp_wmb();
96095 atomic_set(&sk->sk_refcnt, 1);
96096 - atomic_set(&sk->sk_drops, 0);
96097 + atomic_set_unchecked(&sk->sk_drops, 0);
96098 }
96099 EXPORT_SYMBOL(sock_init_data);
96100
96101 @@ -2476,6 +2476,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
96102 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
96103 int level, int type)
96104 {
96105 + struct sock_extended_err ee;
96106 struct sock_exterr_skb *serr;
96107 struct sk_buff *skb, *skb2;
96108 int copied, err;
96109 @@ -2497,7 +2498,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
96110 sock_recv_timestamp(msg, sk, skb);
96111
96112 serr = SKB_EXT_ERR(skb);
96113 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
96114 + ee = serr->ee;
96115 + put_cmsg(msg, level, type, sizeof ee, &ee);
96116
96117 msg->msg_flags |= MSG_ERRQUEUE;
96118 err = copied;
96119 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
96120 index a0e9cf6..ef7f9ed 100644
96121 --- a/net/core/sock_diag.c
96122 +++ b/net/core/sock_diag.c
96123 @@ -9,26 +9,33 @@
96124 #include <linux/inet_diag.h>
96125 #include <linux/sock_diag.h>
96126
96127 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
96128 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
96129 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
96130 static DEFINE_MUTEX(sock_diag_table_mutex);
96131
96132 int sock_diag_check_cookie(void *sk, __u32 *cookie)
96133 {
96134 +#ifndef CONFIG_GRKERNSEC_HIDESYM
96135 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
96136 cookie[1] != INET_DIAG_NOCOOKIE) &&
96137 ((u32)(unsigned long)sk != cookie[0] ||
96138 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
96139 return -ESTALE;
96140 else
96141 +#endif
96142 return 0;
96143 }
96144 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
96145
96146 void sock_diag_save_cookie(void *sk, __u32 *cookie)
96147 {
96148 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96149 + cookie[0] = 0;
96150 + cookie[1] = 0;
96151 +#else
96152 cookie[0] = (u32)(unsigned long)sk;
96153 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
96154 +#endif
96155 }
96156 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
96157
96158 @@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
96159 mutex_lock(&sock_diag_table_mutex);
96160 if (sock_diag_handlers[hndl->family])
96161 err = -EBUSY;
96162 - else
96163 + else {
96164 + pax_open_kernel();
96165 sock_diag_handlers[hndl->family] = hndl;
96166 + pax_close_kernel();
96167 + }
96168 mutex_unlock(&sock_diag_table_mutex);
96169
96170 return err;
96171 @@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
96172
96173 mutex_lock(&sock_diag_table_mutex);
96174 BUG_ON(sock_diag_handlers[family] != hnld);
96175 + pax_open_kernel();
96176 sock_diag_handlers[family] = NULL;
96177 + pax_close_kernel();
96178 mutex_unlock(&sock_diag_table_mutex);
96179 }
96180 EXPORT_SYMBOL_GPL(sock_diag_unregister);
96181 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
96182 index cca4441..5e616de 100644
96183 --- a/net/core/sysctl_net_core.c
96184 +++ b/net/core/sysctl_net_core.c
96185 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
96186 {
96187 unsigned int orig_size, size;
96188 int ret, i;
96189 - struct ctl_table tmp = {
96190 + ctl_table_no_const tmp = {
96191 .data = &size,
96192 .maxlen = sizeof(size),
96193 .mode = table->mode
96194 @@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
96195 void __user *buffer, size_t *lenp, loff_t *ppos)
96196 {
96197 char id[IFNAMSIZ];
96198 - struct ctl_table tbl = {
96199 + ctl_table_no_const tbl = {
96200 .data = id,
96201 .maxlen = IFNAMSIZ,
96202 };
96203 @@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
96204
96205 static __net_init int sysctl_core_net_init(struct net *net)
96206 {
96207 - struct ctl_table *tbl;
96208 + ctl_table_no_const *tbl = NULL;
96209
96210 net->core.sysctl_somaxconn = SOMAXCONN;
96211
96212 - tbl = netns_core_table;
96213 if (!net_eq(net, &init_net)) {
96214 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
96215 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
96216 if (tbl == NULL)
96217 goto err_dup;
96218
96219 @@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
96220 if (net->user_ns != &init_user_ns) {
96221 tbl[0].procname = NULL;
96222 }
96223 - }
96224 -
96225 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
96226 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
96227 + } else
96228 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
96229 if (net->core.sysctl_hdr == NULL)
96230 goto err_reg;
96231
96232 return 0;
96233
96234 err_reg:
96235 - if (tbl != netns_core_table)
96236 - kfree(tbl);
96237 + kfree(tbl);
96238 err_dup:
96239 return -ENOMEM;
96240 }
96241 @@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
96242 kfree(tbl);
96243 }
96244
96245 -static __net_initdata struct pernet_operations sysctl_core_ops = {
96246 +static __net_initconst struct pernet_operations sysctl_core_ops = {
96247 .init = sysctl_core_net_init,
96248 .exit = sysctl_core_net_exit,
96249 };
96250 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
96251 index dd4d506..fb2fb87 100644
96252 --- a/net/decnet/af_decnet.c
96253 +++ b/net/decnet/af_decnet.c
96254 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
96255 .sysctl_rmem = sysctl_decnet_rmem,
96256 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
96257 .obj_size = sizeof(struct dn_sock),
96258 + .slab_flags = SLAB_USERCOPY,
96259 };
96260
96261 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
96262 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
96263 index dd0dfb2..fdbc764 100644
96264 --- a/net/decnet/dn_dev.c
96265 +++ b/net/decnet/dn_dev.c
96266 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
96267 .extra1 = &min_t3,
96268 .extra2 = &max_t3
96269 },
96270 - {0}
96271 + { }
96272 },
96273 };
96274
96275 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
96276 index 5325b54..a0d4d69 100644
96277 --- a/net/decnet/sysctl_net_decnet.c
96278 +++ b/net/decnet/sysctl_net_decnet.c
96279 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
96280
96281 if (len > *lenp) len = *lenp;
96282
96283 - if (copy_to_user(buffer, addr, len))
96284 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
96285 return -EFAULT;
96286
96287 *lenp = len;
96288 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
96289
96290 if (len > *lenp) len = *lenp;
96291
96292 - if (copy_to_user(buffer, devname, len))
96293 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
96294 return -EFAULT;
96295
96296 *lenp = len;
96297 diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
96298 index 1865fdf..581a595 100644
96299 --- a/net/ieee802154/dgram.c
96300 +++ b/net/ieee802154/dgram.c
96301 @@ -315,8 +315,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
96302 if (saddr) {
96303 saddr->family = AF_IEEE802154;
96304 saddr->addr = mac_cb(skb)->sa;
96305 + }
96306 + if (addr_len)
96307 *addr_len = sizeof(*saddr);
96308 - }
96309
96310 if (flags & MSG_TRUNC)
96311 copied = skb->len;
96312 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
96313 index 70011e0..454ca6a 100644
96314 --- a/net/ipv4/af_inet.c
96315 +++ b/net/ipv4/af_inet.c
96316 @@ -1683,13 +1683,9 @@ static int __init inet_init(void)
96317
96318 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
96319
96320 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
96321 - if (!sysctl_local_reserved_ports)
96322 - goto out;
96323 -
96324 rc = proto_register(&tcp_prot, 1);
96325 if (rc)
96326 - goto out_free_reserved_ports;
96327 + goto out;
96328
96329 rc = proto_register(&udp_prot, 1);
96330 if (rc)
96331 @@ -1796,8 +1792,6 @@ out_unregister_udp_proto:
96332 proto_unregister(&udp_prot);
96333 out_unregister_tcp_proto:
96334 proto_unregister(&tcp_prot);
96335 -out_free_reserved_ports:
96336 - kfree(sysctl_local_reserved_ports);
96337 goto out;
96338 }
96339
96340 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
96341 index a1b5bcb..62ec5c6 100644
96342 --- a/net/ipv4/devinet.c
96343 +++ b/net/ipv4/devinet.c
96344 @@ -1533,7 +1533,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
96345 idx = 0;
96346 head = &net->dev_index_head[h];
96347 rcu_read_lock();
96348 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
96349 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
96350 net->dev_base_seq;
96351 hlist_for_each_entry_rcu(dev, head, index_hlist) {
96352 if (idx < s_idx)
96353 @@ -1844,7 +1844,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
96354 idx = 0;
96355 head = &net->dev_index_head[h];
96356 rcu_read_lock();
96357 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
96358 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
96359 net->dev_base_seq;
96360 hlist_for_each_entry_rcu(dev, head, index_hlist) {
96361 if (idx < s_idx)
96362 @@ -2069,7 +2069,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
96363 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
96364 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
96365
96366 -static struct devinet_sysctl_table {
96367 +static const struct devinet_sysctl_table {
96368 struct ctl_table_header *sysctl_header;
96369 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
96370 } devinet_sysctl = {
96371 @@ -2191,7 +2191,7 @@ static __net_init int devinet_init_net(struct net *net)
96372 int err;
96373 struct ipv4_devconf *all, *dflt;
96374 #ifdef CONFIG_SYSCTL
96375 - struct ctl_table *tbl = ctl_forward_entry;
96376 + ctl_table_no_const *tbl = NULL;
96377 struct ctl_table_header *forw_hdr;
96378 #endif
96379
96380 @@ -2209,7 +2209,7 @@ static __net_init int devinet_init_net(struct net *net)
96381 goto err_alloc_dflt;
96382
96383 #ifdef CONFIG_SYSCTL
96384 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
96385 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
96386 if (tbl == NULL)
96387 goto err_alloc_ctl;
96388
96389 @@ -2229,7 +2229,10 @@ static __net_init int devinet_init_net(struct net *net)
96390 goto err_reg_dflt;
96391
96392 err = -ENOMEM;
96393 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
96394 + if (!net_eq(net, &init_net))
96395 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
96396 + else
96397 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
96398 if (forw_hdr == NULL)
96399 goto err_reg_ctl;
96400 net->ipv4.forw_hdr = forw_hdr;
96401 @@ -2245,8 +2248,7 @@ err_reg_ctl:
96402 err_reg_dflt:
96403 __devinet_sysctl_unregister(all);
96404 err_reg_all:
96405 - if (tbl != ctl_forward_entry)
96406 - kfree(tbl);
96407 + kfree(tbl);
96408 err_alloc_ctl:
96409 #endif
96410 if (dflt != &ipv4_devconf_dflt)
96411 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
96412 index d846304..d0622bb 100644
96413 --- a/net/ipv4/fib_frontend.c
96414 +++ b/net/ipv4/fib_frontend.c
96415 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
96416 #ifdef CONFIG_IP_ROUTE_MULTIPATH
96417 fib_sync_up(dev);
96418 #endif
96419 - atomic_inc(&net->ipv4.dev_addr_genid);
96420 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96421 rt_cache_flush(dev_net(dev));
96422 break;
96423 case NETDEV_DOWN:
96424 fib_del_ifaddr(ifa, NULL);
96425 - atomic_inc(&net->ipv4.dev_addr_genid);
96426 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96427 if (ifa->ifa_dev->ifa_list == NULL) {
96428 /* Last address was deleted from this interface.
96429 * Disable IP.
96430 @@ -1056,7 +1056,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
96431 #ifdef CONFIG_IP_ROUTE_MULTIPATH
96432 fib_sync_up(dev);
96433 #endif
96434 - atomic_inc(&net->ipv4.dev_addr_genid);
96435 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96436 rt_cache_flush(net);
96437 break;
96438 case NETDEV_DOWN:
96439 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
96440 index e63f47a..e5c531d 100644
96441 --- a/net/ipv4/fib_semantics.c
96442 +++ b/net/ipv4/fib_semantics.c
96443 @@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
96444 nh->nh_saddr = inet_select_addr(nh->nh_dev,
96445 nh->nh_gw,
96446 nh->nh_parent->fib_scope);
96447 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
96448 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
96449
96450 return nh->nh_saddr;
96451 }
96452 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
96453 index fc0e649..febfa65 100644
96454 --- a/net/ipv4/inet_connection_sock.c
96455 +++ b/net/ipv4/inet_connection_sock.c
96456 @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
96457 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
96458 #endif
96459
96460 -unsigned long *sysctl_local_reserved_ports;
96461 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
96462 EXPORT_SYMBOL(sysctl_local_reserved_ports);
96463
96464 void inet_get_local_port_range(struct net *net, int *low, int *high)
96465 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
96466 index 8b9cf27..0d8d592 100644
96467 --- a/net/ipv4/inet_hashtables.c
96468 +++ b/net/ipv4/inet_hashtables.c
96469 @@ -18,6 +18,7 @@
96470 #include <linux/sched.h>
96471 #include <linux/slab.h>
96472 #include <linux/wait.h>
96473 +#include <linux/security.h>
96474
96475 #include <net/inet_connection_sock.h>
96476 #include <net/inet_hashtables.h>
96477 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
96478 return inet_ehashfn(net, laddr, lport, faddr, fport);
96479 }
96480
96481 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
96482 +
96483 /*
96484 * Allocate and initialize a new local port bind bucket.
96485 * The bindhash mutex for snum's hash chain must be held here.
96486 @@ -554,6 +557,8 @@ ok:
96487 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
96488 spin_unlock(&head->lock);
96489
96490 + gr_update_task_in_ip_table(current, inet_sk(sk));
96491 +
96492 if (tw) {
96493 inet_twsk_deschedule(tw, death_row);
96494 while (twrefcnt) {
96495 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
96496 index 33d5537..da337a4 100644
96497 --- a/net/ipv4/inetpeer.c
96498 +++ b/net/ipv4/inetpeer.c
96499 @@ -503,8 +503,8 @@ relookup:
96500 if (p) {
96501 p->daddr = *daddr;
96502 atomic_set(&p->refcnt, 1);
96503 - atomic_set(&p->rid, 0);
96504 - atomic_set(&p->ip_id_count,
96505 + atomic_set_unchecked(&p->rid, 0);
96506 + atomic_set_unchecked(&p->ip_id_count,
96507 (daddr->family == AF_INET) ?
96508 secure_ip_id(daddr->addr.a4) :
96509 secure_ipv6_id(daddr->addr.a6));
96510 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
96511 index 2481993..2d9a7a7 100644
96512 --- a/net/ipv4/ip_fragment.c
96513 +++ b/net/ipv4/ip_fragment.c
96514 @@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
96515 return 0;
96516
96517 start = qp->rid;
96518 - end = atomic_inc_return(&peer->rid);
96519 + end = atomic_inc_return_unchecked(&peer->rid);
96520 qp->rid = end;
96521
96522 rc = qp->q.fragments && (end - start) > max;
96523 @@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
96524
96525 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96526 {
96527 - struct ctl_table *table;
96528 + ctl_table_no_const *table = NULL;
96529 struct ctl_table_header *hdr;
96530
96531 - table = ip4_frags_ns_ctl_table;
96532 if (!net_eq(net, &init_net)) {
96533 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
96534 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
96535 if (table == NULL)
96536 goto err_alloc;
96537
96538 @@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96539 /* Don't export sysctls to unprivileged users */
96540 if (net->user_ns != &init_user_ns)
96541 table[0].procname = NULL;
96542 - }
96543 + hdr = register_net_sysctl(net, "net/ipv4", table);
96544 + } else
96545 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
96546
96547 - hdr = register_net_sysctl(net, "net/ipv4", table);
96548 if (hdr == NULL)
96549 goto err_reg;
96550
96551 @@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96552 return 0;
96553
96554 err_reg:
96555 - if (!net_eq(net, &init_net))
96556 - kfree(table);
96557 + kfree(table);
96558 err_alloc:
96559 return -ENOMEM;
96560 }
96561 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
96562 index e560ef3..218c5c5 100644
96563 --- a/net/ipv4/ip_gre.c
96564 +++ b/net/ipv4/ip_gre.c
96565 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
96566 module_param(log_ecn_error, bool, 0644);
96567 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
96568
96569 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
96570 +static struct rtnl_link_ops ipgre_link_ops;
96571 static int ipgre_tunnel_init(struct net_device *dev);
96572
96573 static int ipgre_net_id __read_mostly;
96574 @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
96575 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
96576 };
96577
96578 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
96579 +static struct rtnl_link_ops ipgre_link_ops = {
96580 .kind = "gre",
96581 .maxtype = IFLA_GRE_MAX,
96582 .policy = ipgre_policy,
96583 @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
96584 .fill_info = ipgre_fill_info,
96585 };
96586
96587 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
96588 +static struct rtnl_link_ops ipgre_tap_ops = {
96589 .kind = "gretap",
96590 .maxtype = IFLA_GRE_MAX,
96591 .policy = ipgre_policy,
96592 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
96593 index ddf32a6..3fdeea9 100644
96594 --- a/net/ipv4/ip_sockglue.c
96595 +++ b/net/ipv4/ip_sockglue.c
96596 @@ -1172,7 +1172,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
96597 len = min_t(unsigned int, len, opt->optlen);
96598 if (put_user(len, optlen))
96599 return -EFAULT;
96600 - if (copy_to_user(optval, opt->__data, len))
96601 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
96602 + copy_to_user(optval, opt->__data, len))
96603 return -EFAULT;
96604 return 0;
96605 }
96606 @@ -1303,7 +1304,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
96607 if (sk->sk_type != SOCK_STREAM)
96608 return -ENOPROTOOPT;
96609
96610 - msg.msg_control = optval;
96611 + msg.msg_control = (void __force_kernel *)optval;
96612 msg.msg_controllen = len;
96613 msg.msg_flags = flags;
96614
96615 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
96616 index 52b802a..b725179 100644
96617 --- a/net/ipv4/ip_vti.c
96618 +++ b/net/ipv4/ip_vti.c
96619 @@ -44,7 +44,7 @@
96620 #include <net/net_namespace.h>
96621 #include <net/netns/generic.h>
96622
96623 -static struct rtnl_link_ops vti_link_ops __read_mostly;
96624 +static struct rtnl_link_ops vti_link_ops;
96625
96626 static int vti_net_id __read_mostly;
96627 static int vti_tunnel_init(struct net_device *dev);
96628 @@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
96629 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
96630 };
96631
96632 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
96633 +static struct rtnl_link_ops vti_link_ops = {
96634 .kind = "vti",
96635 .maxtype = IFLA_VTI_MAX,
96636 .policy = vti_policy,
96637 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
96638 index efa1138..20dbba0 100644
96639 --- a/net/ipv4/ipconfig.c
96640 +++ b/net/ipv4/ipconfig.c
96641 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
96642
96643 mm_segment_t oldfs = get_fs();
96644 set_fs(get_ds());
96645 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
96646 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
96647 set_fs(oldfs);
96648 return res;
96649 }
96650 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
96651
96652 mm_segment_t oldfs = get_fs();
96653 set_fs(get_ds());
96654 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
96655 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
96656 set_fs(oldfs);
96657 return res;
96658 }
96659 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
96660
96661 mm_segment_t oldfs = get_fs();
96662 set_fs(get_ds());
96663 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
96664 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
96665 set_fs(oldfs);
96666 return res;
96667 }
96668 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
96669 index fe3e9f7..4956990 100644
96670 --- a/net/ipv4/ipip.c
96671 +++ b/net/ipv4/ipip.c
96672 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
96673 static int ipip_net_id __read_mostly;
96674
96675 static int ipip_tunnel_init(struct net_device *dev);
96676 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
96677 +static struct rtnl_link_ops ipip_link_ops;
96678
96679 static int ipip_err(struct sk_buff *skb, u32 info)
96680 {
96681 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
96682 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
96683 };
96684
96685 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
96686 +static struct rtnl_link_ops ipip_link_ops = {
96687 .kind = "ipip",
96688 .maxtype = IFLA_IPTUN_MAX,
96689 .policy = ipip_policy,
96690 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
96691 index 59da7cd..e318de1 100644
96692 --- a/net/ipv4/netfilter/arp_tables.c
96693 +++ b/net/ipv4/netfilter/arp_tables.c
96694 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
96695 #endif
96696
96697 static int get_info(struct net *net, void __user *user,
96698 - const int *len, int compat)
96699 + int len, int compat)
96700 {
96701 char name[XT_TABLE_MAXNAMELEN];
96702 struct xt_table *t;
96703 int ret;
96704
96705 - if (*len != sizeof(struct arpt_getinfo)) {
96706 - duprintf("length %u != %Zu\n", *len,
96707 + if (len != sizeof(struct arpt_getinfo)) {
96708 + duprintf("length %u != %Zu\n", len,
96709 sizeof(struct arpt_getinfo));
96710 return -EINVAL;
96711 }
96712 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
96713 info.size = private->size;
96714 strcpy(info.name, name);
96715
96716 - if (copy_to_user(user, &info, *len) != 0)
96717 + if (copy_to_user(user, &info, len) != 0)
96718 ret = -EFAULT;
96719 else
96720 ret = 0;
96721 @@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
96722
96723 switch (cmd) {
96724 case ARPT_SO_GET_INFO:
96725 - ret = get_info(sock_net(sk), user, len, 1);
96726 + ret = get_info(sock_net(sk), user, *len, 1);
96727 break;
96728 case ARPT_SO_GET_ENTRIES:
96729 ret = compat_get_entries(sock_net(sk), user, len);
96730 @@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
96731
96732 switch (cmd) {
96733 case ARPT_SO_GET_INFO:
96734 - ret = get_info(sock_net(sk), user, len, 0);
96735 + ret = get_info(sock_net(sk), user, *len, 0);
96736 break;
96737
96738 case ARPT_SO_GET_ENTRIES:
96739 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
96740 index 718dfbd..cef4152 100644
96741 --- a/net/ipv4/netfilter/ip_tables.c
96742 +++ b/net/ipv4/netfilter/ip_tables.c
96743 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
96744 #endif
96745
96746 static int get_info(struct net *net, void __user *user,
96747 - const int *len, int compat)
96748 + int len, int compat)
96749 {
96750 char name[XT_TABLE_MAXNAMELEN];
96751 struct xt_table *t;
96752 int ret;
96753
96754 - if (*len != sizeof(struct ipt_getinfo)) {
96755 - duprintf("length %u != %zu\n", *len,
96756 + if (len != sizeof(struct ipt_getinfo)) {
96757 + duprintf("length %u != %zu\n", len,
96758 sizeof(struct ipt_getinfo));
96759 return -EINVAL;
96760 }
96761 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
96762 info.size = private->size;
96763 strcpy(info.name, name);
96764
96765 - if (copy_to_user(user, &info, *len) != 0)
96766 + if (copy_to_user(user, &info, len) != 0)
96767 ret = -EFAULT;
96768 else
96769 ret = 0;
96770 @@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96771
96772 switch (cmd) {
96773 case IPT_SO_GET_INFO:
96774 - ret = get_info(sock_net(sk), user, len, 1);
96775 + ret = get_info(sock_net(sk), user, *len, 1);
96776 break;
96777 case IPT_SO_GET_ENTRIES:
96778 ret = compat_get_entries(sock_net(sk), user, len);
96779 @@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96780
96781 switch (cmd) {
96782 case IPT_SO_GET_INFO:
96783 - ret = get_info(sock_net(sk), user, len, 0);
96784 + ret = get_info(sock_net(sk), user, *len, 0);
96785 break;
96786
96787 case IPT_SO_GET_ENTRIES:
96788 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
96789 index 242e7f4..a084e95 100644
96790 --- a/net/ipv4/ping.c
96791 +++ b/net/ipv4/ping.c
96792 @@ -55,7 +55,7 @@
96793
96794
96795 struct ping_table ping_table;
96796 -struct pingv6_ops pingv6_ops;
96797 +struct pingv6_ops *pingv6_ops;
96798 EXPORT_SYMBOL_GPL(pingv6_ops);
96799
96800 static u16 ping_port_rover;
96801 @@ -334,7 +334,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
96802 return -ENODEV;
96803 }
96804 }
96805 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
96806 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
96807 scoped);
96808 rcu_read_unlock();
96809
96810 @@ -542,7 +542,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
96811 }
96812 #if IS_ENABLED(CONFIG_IPV6)
96813 } else if (skb->protocol == htons(ETH_P_IPV6)) {
96814 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
96815 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
96816 #endif
96817 }
96818
96819 @@ -560,7 +560,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
96820 info, (u8 *)icmph);
96821 #if IS_ENABLED(CONFIG_IPV6)
96822 } else if (family == AF_INET6) {
96823 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
96824 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
96825 info, (u8 *)icmph);
96826 #endif
96827 }
96828 @@ -830,6 +830,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96829 {
96830 struct inet_sock *isk = inet_sk(sk);
96831 int family = sk->sk_family;
96832 + struct sockaddr_in *sin;
96833 + struct sockaddr_in6 *sin6;
96834 struct sk_buff *skb;
96835 int copied, err;
96836
96837 @@ -839,12 +841,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96838 if (flags & MSG_OOB)
96839 goto out;
96840
96841 + if (addr_len) {
96842 + if (family == AF_INET)
96843 + *addr_len = sizeof(*sin);
96844 + else if (family == AF_INET6 && addr_len)
96845 + *addr_len = sizeof(*sin6);
96846 + }
96847 +
96848 if (flags & MSG_ERRQUEUE) {
96849 if (family == AF_INET) {
96850 return ip_recv_error(sk, msg, len, addr_len);
96851 #if IS_ENABLED(CONFIG_IPV6)
96852 } else if (family == AF_INET6) {
96853 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
96854 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
96855 addr_len);
96856 #endif
96857 }
96858 @@ -876,7 +885,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96859 sin->sin_port = 0 /* skb->h.uh->source */;
96860 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
96861 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
96862 - *addr_len = sizeof(*sin);
96863 }
96864
96865 if (isk->cmsg_flags)
96866 @@ -899,11 +907,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96867 sin6->sin6_scope_id =
96868 ipv6_iface_scope_id(&sin6->sin6_addr,
96869 IP6CB(skb)->iif);
96870 - *addr_len = sizeof(*sin6);
96871 }
96872
96873 if (inet6_sk(sk)->rxopt.all)
96874 - pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
96875 + pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
96876 #endif
96877 } else {
96878 BUG();
96879 @@ -1093,7 +1100,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
96880 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
96881 0, sock_i_ino(sp),
96882 atomic_read(&sp->sk_refcnt), sp,
96883 - atomic_read(&sp->sk_drops));
96884 + atomic_read_unchecked(&sp->sk_drops));
96885 }
96886
96887 static int ping_v4_seq_show(struct seq_file *seq, void *v)
96888 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
96889 index 23c3e5b..cdb8b36 100644
96890 --- a/net/ipv4/raw.c
96891 +++ b/net/ipv4/raw.c
96892 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
96893 int raw_rcv(struct sock *sk, struct sk_buff *skb)
96894 {
96895 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
96896 - atomic_inc(&sk->sk_drops);
96897 + atomic_inc_unchecked(&sk->sk_drops);
96898 kfree_skb(skb);
96899 return NET_RX_DROP;
96900 }
96901 @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96902 if (flags & MSG_OOB)
96903 goto out;
96904
96905 + if (addr_len)
96906 + *addr_len = sizeof(*sin);
96907 +
96908 if (flags & MSG_ERRQUEUE) {
96909 err = ip_recv_error(sk, msg, len, addr_len);
96910 goto out;
96911 @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96912 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
96913 sin->sin_port = 0;
96914 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
96915 - *addr_len = sizeof(*sin);
96916 }
96917 if (inet->cmsg_flags)
96918 ip_cmsg_recv(msg, skb);
96919 @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
96920
96921 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
96922 {
96923 + struct icmp_filter filter;
96924 +
96925 if (optlen > sizeof(struct icmp_filter))
96926 optlen = sizeof(struct icmp_filter);
96927 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
96928 + if (copy_from_user(&filter, optval, optlen))
96929 return -EFAULT;
96930 + raw_sk(sk)->filter = filter;
96931 return 0;
96932 }
96933
96934 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
96935 {
96936 int len, ret = -EFAULT;
96937 + struct icmp_filter filter;
96938
96939 if (get_user(len, optlen))
96940 goto out;
96941 @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
96942 if (len > sizeof(struct icmp_filter))
96943 len = sizeof(struct icmp_filter);
96944 ret = -EFAULT;
96945 - if (put_user(len, optlen) ||
96946 - copy_to_user(optval, &raw_sk(sk)->filter, len))
96947 + filter = raw_sk(sk)->filter;
96948 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
96949 goto out;
96950 ret = 0;
96951 out: return ret;
96952 @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
96953 0, 0L, 0,
96954 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
96955 0, sock_i_ino(sp),
96956 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
96957 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
96958 }
96959
96960 static int raw_seq_show(struct seq_file *seq, void *v)
96961 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
96962 index f8da282..133a1c7 100644
96963 --- a/net/ipv4/route.c
96964 +++ b/net/ipv4/route.c
96965 @@ -2621,34 +2621,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
96966 .maxlen = sizeof(int),
96967 .mode = 0200,
96968 .proc_handler = ipv4_sysctl_rtcache_flush,
96969 + .extra1 = &init_net,
96970 },
96971 { },
96972 };
96973
96974 static __net_init int sysctl_route_net_init(struct net *net)
96975 {
96976 - struct ctl_table *tbl;
96977 + ctl_table_no_const *tbl = NULL;
96978
96979 - tbl = ipv4_route_flush_table;
96980 if (!net_eq(net, &init_net)) {
96981 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
96982 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
96983 if (tbl == NULL)
96984 goto err_dup;
96985
96986 /* Don't export sysctls to unprivileged users */
96987 if (net->user_ns != &init_user_ns)
96988 tbl[0].procname = NULL;
96989 - }
96990 - tbl[0].extra1 = net;
96991 + tbl[0].extra1 = net;
96992 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
96993 + } else
96994 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
96995
96996 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
96997 if (net->ipv4.route_hdr == NULL)
96998 goto err_reg;
96999 return 0;
97000
97001 err_reg:
97002 - if (tbl != ipv4_route_flush_table)
97003 - kfree(tbl);
97004 + kfree(tbl);
97005 err_dup:
97006 return -ENOMEM;
97007 }
97008 @@ -2671,8 +2671,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
97009
97010 static __net_init int rt_genid_init(struct net *net)
97011 {
97012 - atomic_set(&net->ipv4.rt_genid, 0);
97013 - atomic_set(&net->fnhe_genid, 0);
97014 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
97015 + atomic_set_unchecked(&net->fnhe_genid, 0);
97016 get_random_bytes(&net->ipv4.dev_addr_genid,
97017 sizeof(net->ipv4.dev_addr_genid));
97018 return 0;
97019 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
97020 index 3d69ec8..57207b4 100644
97021 --- a/net/ipv4/sysctl_net_ipv4.c
97022 +++ b/net/ipv4/sysctl_net_ipv4.c
97023 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
97024 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
97025 int ret;
97026 int range[2];
97027 - struct ctl_table tmp = {
97028 + ctl_table_no_const tmp = {
97029 .data = &range,
97030 .maxlen = sizeof(range),
97031 .mode = table->mode,
97032 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
97033 int ret;
97034 gid_t urange[2];
97035 kgid_t low, high;
97036 - struct ctl_table tmp = {
97037 + ctl_table_no_const tmp = {
97038 .data = &urange,
97039 .maxlen = sizeof(urange),
97040 .mode = table->mode,
97041 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
97042 void __user *buffer, size_t *lenp, loff_t *ppos)
97043 {
97044 char val[TCP_CA_NAME_MAX];
97045 - struct ctl_table tbl = {
97046 + ctl_table_no_const tbl = {
97047 .data = val,
97048 .maxlen = TCP_CA_NAME_MAX,
97049 };
97050 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
97051 void __user *buffer, size_t *lenp,
97052 loff_t *ppos)
97053 {
97054 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
97055 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
97056 int ret;
97057
97058 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
97059 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
97060 void __user *buffer, size_t *lenp,
97061 loff_t *ppos)
97062 {
97063 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
97064 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
97065 int ret;
97066
97067 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
97068 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
97069 void __user *buffer, size_t *lenp,
97070 loff_t *ppos)
97071 {
97072 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
97073 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
97074 struct tcp_fastopen_context *ctxt;
97075 int ret;
97076 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
97077 @@ -445,7 +445,7 @@ static struct ctl_table ipv4_table[] = {
97078 },
97079 {
97080 .procname = "ip_local_reserved_ports",
97081 - .data = NULL, /* initialized in sysctl_ipv4_init */
97082 + .data = sysctl_local_reserved_ports,
97083 .maxlen = 65536,
97084 .mode = 0644,
97085 .proc_handler = proc_do_large_bitmap,
97086 @@ -827,13 +827,12 @@ static struct ctl_table ipv4_net_table[] = {
97087
97088 static __net_init int ipv4_sysctl_init_net(struct net *net)
97089 {
97090 - struct ctl_table *table;
97091 + ctl_table_no_const *table = NULL;
97092
97093 - table = ipv4_net_table;
97094 if (!net_eq(net, &init_net)) {
97095 int i;
97096
97097 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
97098 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
97099 if (table == NULL)
97100 goto err_alloc;
97101
97102 @@ -856,15 +855,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
97103 net->ipv4.sysctl_local_ports.range[0] = 32768;
97104 net->ipv4.sysctl_local_ports.range[1] = 61000;
97105
97106 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
97107 + if (!net_eq(net, &init_net))
97108 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
97109 + else
97110 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
97111 if (net->ipv4.ipv4_hdr == NULL)
97112 goto err_reg;
97113
97114 return 0;
97115
97116 err_reg:
97117 - if (!net_eq(net, &init_net))
97118 - kfree(table);
97119 + kfree(table);
97120 err_alloc:
97121 return -ENOMEM;
97122 }
97123 @@ -886,16 +887,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
97124 static __init int sysctl_ipv4_init(void)
97125 {
97126 struct ctl_table_header *hdr;
97127 - struct ctl_table *i;
97128 -
97129 - for (i = ipv4_table; i->procname; i++) {
97130 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
97131 - i->data = sysctl_local_reserved_ports;
97132 - break;
97133 - }
97134 - }
97135 - if (!i->procname)
97136 - return -EINVAL;
97137
97138 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
97139 if (hdr == NULL)
97140 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
97141 index c53b7f3..a89aadd 100644
97142 --- a/net/ipv4/tcp_input.c
97143 +++ b/net/ipv4/tcp_input.c
97144 @@ -759,7 +759,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
97145 * without any lock. We want to make sure compiler wont store
97146 * intermediate values in this location.
97147 */
97148 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
97149 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
97150 sk->sk_max_pacing_rate);
97151 }
97152
97153 @@ -4482,7 +4482,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
97154 * simplifies code)
97155 */
97156 static void
97157 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
97158 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
97159 struct sk_buff *head, struct sk_buff *tail,
97160 u32 start, u32 end)
97161 {
97162 @@ -5559,6 +5559,7 @@ discard:
97163 tcp_paws_reject(&tp->rx_opt, 0))
97164 goto discard_and_undo;
97165
97166 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
97167 if (th->syn) {
97168 /* We see SYN without ACK. It is attempt of
97169 * simultaneous connect with crossed SYNs.
97170 @@ -5609,6 +5610,7 @@ discard:
97171 goto discard;
97172 #endif
97173 }
97174 +#endif
97175 /* "fifth, if neither of the SYN or RST bits is set then
97176 * drop the segment and return."
97177 */
97178 @@ -5655,7 +5657,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
97179 goto discard;
97180
97181 if (th->syn) {
97182 - if (th->fin)
97183 + if (th->fin || th->urg || th->psh)
97184 goto discard;
97185 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
97186 return 1;
97187 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
97188 index 0672139..cacc17d 100644
97189 --- a/net/ipv4/tcp_ipv4.c
97190 +++ b/net/ipv4/tcp_ipv4.c
97191 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
97192 EXPORT_SYMBOL(sysctl_tcp_low_latency);
97193
97194
97195 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97196 +extern int grsec_enable_blackhole;
97197 +#endif
97198 +
97199 #ifdef CONFIG_TCP_MD5SIG
97200 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
97201 __be32 daddr, __be32 saddr, const struct tcphdr *th);
97202 @@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
97203 return 0;
97204
97205 reset:
97206 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97207 + if (!grsec_enable_blackhole)
97208 +#endif
97209 tcp_v4_send_reset(rsk, skb);
97210 discard:
97211 kfree_skb(skb);
97212 @@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
97213 TCP_SKB_CB(skb)->sacked = 0;
97214
97215 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
97216 - if (!sk)
97217 + if (!sk) {
97218 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97219 + ret = 1;
97220 +#endif
97221 goto no_tcp_socket;
97222 -
97223 + }
97224 process:
97225 - if (sk->sk_state == TCP_TIME_WAIT)
97226 + if (sk->sk_state == TCP_TIME_WAIT) {
97227 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97228 + ret = 2;
97229 +#endif
97230 goto do_time_wait;
97231 + }
97232
97233 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
97234 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
97235 @@ -2034,6 +2048,10 @@ csum_error:
97236 bad_packet:
97237 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
97238 } else {
97239 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97240 + if (!grsec_enable_blackhole || (ret == 1 &&
97241 + (skb->dev->flags & IFF_LOOPBACK)))
97242 +#endif
97243 tcp_v4_send_reset(NULL, skb);
97244 }
97245
97246 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
97247 index 97b6841..0893357 100644
97248 --- a/net/ipv4/tcp_minisocks.c
97249 +++ b/net/ipv4/tcp_minisocks.c
97250 @@ -27,6 +27,10 @@
97251 #include <net/inet_common.h>
97252 #include <net/xfrm.h>
97253
97254 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97255 +extern int grsec_enable_blackhole;
97256 +#endif
97257 +
97258 int sysctl_tcp_syncookies __read_mostly = 1;
97259 EXPORT_SYMBOL(sysctl_tcp_syncookies);
97260
97261 @@ -708,7 +712,10 @@ embryonic_reset:
97262 * avoid becoming vulnerable to outside attack aiming at
97263 * resetting legit local connections.
97264 */
97265 - req->rsk_ops->send_reset(sk, skb);
97266 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97267 + if (!grsec_enable_blackhole)
97268 +#endif
97269 + req->rsk_ops->send_reset(sk, skb);
97270 } else if (fastopen) { /* received a valid RST pkt */
97271 reqsk_fastopen_remove(sk, req, true);
97272 tcp_reset(sk);
97273 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
97274 index 8b97d71..9d7ccf5 100644
97275 --- a/net/ipv4/tcp_probe.c
97276 +++ b/net/ipv4/tcp_probe.c
97277 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
97278 if (cnt + width >= len)
97279 break;
97280
97281 - if (copy_to_user(buf + cnt, tbuf, width))
97282 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
97283 return -EFAULT;
97284 cnt += width;
97285 }
97286 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
97287 index 64f0354..a81b39d 100644
97288 --- a/net/ipv4/tcp_timer.c
97289 +++ b/net/ipv4/tcp_timer.c
97290 @@ -22,6 +22,10 @@
97291 #include <linux/gfp.h>
97292 #include <net/tcp.h>
97293
97294 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97295 +extern int grsec_lastack_retries;
97296 +#endif
97297 +
97298 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
97299 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
97300 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
97301 @@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
97302 }
97303 }
97304
97305 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97306 + if ((sk->sk_state == TCP_LAST_ACK) &&
97307 + (grsec_lastack_retries > 0) &&
97308 + (grsec_lastack_retries < retry_until))
97309 + retry_until = grsec_lastack_retries;
97310 +#endif
97311 +
97312 if (retransmits_timed_out(sk, retry_until,
97313 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
97314 /* Has it gone just too far? */
97315 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
97316 index a7e4729..2758946 100644
97317 --- a/net/ipv4/udp.c
97318 +++ b/net/ipv4/udp.c
97319 @@ -87,6 +87,7 @@
97320 #include <linux/types.h>
97321 #include <linux/fcntl.h>
97322 #include <linux/module.h>
97323 +#include <linux/security.h>
97324 #include <linux/socket.h>
97325 #include <linux/sockios.h>
97326 #include <linux/igmp.h>
97327 @@ -113,6 +114,10 @@
97328 #include <net/busy_poll.h>
97329 #include "udp_impl.h"
97330
97331 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97332 +extern int grsec_enable_blackhole;
97333 +#endif
97334 +
97335 struct udp_table udp_table __read_mostly;
97336 EXPORT_SYMBOL(udp_table);
97337
97338 @@ -615,6 +620,9 @@ found:
97339 return s;
97340 }
97341
97342 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
97343 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
97344 +
97345 /*
97346 * This routine is called by the ICMP module when it gets some
97347 * sort of error condition. If err < 0 then the socket should
97348 @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97349 dport = usin->sin_port;
97350 if (dport == 0)
97351 return -EINVAL;
97352 +
97353 + err = gr_search_udp_sendmsg(sk, usin);
97354 + if (err)
97355 + return err;
97356 } else {
97357 if (sk->sk_state != TCP_ESTABLISHED)
97358 return -EDESTADDRREQ;
97359 +
97360 + err = gr_search_udp_sendmsg(sk, NULL);
97361 + if (err)
97362 + return err;
97363 +
97364 daddr = inet->inet_daddr;
97365 dport = inet->inet_dport;
97366 /* Open fast path for connected socket.
97367 @@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
97368 IS_UDPLITE(sk));
97369 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
97370 IS_UDPLITE(sk));
97371 - atomic_inc(&sk->sk_drops);
97372 + atomic_inc_unchecked(&sk->sk_drops);
97373 __skb_unlink(skb, rcvq);
97374 __skb_queue_tail(&list_kill, skb);
97375 }
97376 @@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97377 int is_udplite = IS_UDPLITE(sk);
97378 bool slow;
97379
97380 + /*
97381 + * Check any passed addresses
97382 + */
97383 + if (addr_len)
97384 + *addr_len = sizeof(*sin);
97385 +
97386 if (flags & MSG_ERRQUEUE)
97387 return ip_recv_error(sk, msg, len, addr_len);
97388
97389 @@ -1243,6 +1266,10 @@ try_again:
97390 if (!skb)
97391 goto out;
97392
97393 + err = gr_search_udp_recvmsg(sk, skb);
97394 + if (err)
97395 + goto out_free;
97396 +
97397 ulen = skb->len - sizeof(struct udphdr);
97398 copied = len;
97399 if (copied > ulen)
97400 @@ -1276,7 +1303,7 @@ try_again:
97401 if (unlikely(err)) {
97402 trace_kfree_skb(skb, udp_recvmsg);
97403 if (!peeked) {
97404 - atomic_inc(&sk->sk_drops);
97405 + atomic_inc_unchecked(&sk->sk_drops);
97406 UDP_INC_STATS_USER(sock_net(sk),
97407 UDP_MIB_INERRORS, is_udplite);
97408 }
97409 @@ -1295,7 +1322,6 @@ try_again:
97410 sin->sin_port = udp_hdr(skb)->source;
97411 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
97412 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
97413 - *addr_len = sizeof(*sin);
97414 }
97415 if (inet->cmsg_flags)
97416 ip_cmsg_recv(msg, skb);
97417 @@ -1566,7 +1592,7 @@ csum_error:
97418 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
97419 drop:
97420 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
97421 - atomic_inc(&sk->sk_drops);
97422 + atomic_inc_unchecked(&sk->sk_drops);
97423 kfree_skb(skb);
97424 return -1;
97425 }
97426 @@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
97427 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
97428
97429 if (!skb1) {
97430 - atomic_inc(&sk->sk_drops);
97431 + atomic_inc_unchecked(&sk->sk_drops);
97432 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
97433 IS_UDPLITE(sk));
97434 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
97435 @@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
97436 goto csum_error;
97437
97438 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
97439 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97440 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
97441 +#endif
97442 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
97443
97444 /*
97445 @@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
97446 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
97447 0, sock_i_ino(sp),
97448 atomic_read(&sp->sk_refcnt), sp,
97449 - atomic_read(&sp->sk_drops));
97450 + atomic_read_unchecked(&sp->sk_drops));
97451 }
97452
97453 int udp4_seq_show(struct seq_file *seq, void *v)
97454 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
97455 index e1a6393..f634ce5 100644
97456 --- a/net/ipv4/xfrm4_policy.c
97457 +++ b/net/ipv4/xfrm4_policy.c
97458 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
97459 fl4->flowi4_tos = iph->tos;
97460 }
97461
97462 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
97463 +static int xfrm4_garbage_collect(struct dst_ops *ops)
97464 {
97465 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
97466
97467 - xfrm4_policy_afinfo.garbage_collect(net);
97468 + xfrm_garbage_collect_deferred(net);
97469 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
97470 }
97471
97472 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
97473
97474 static int __net_init xfrm4_net_init(struct net *net)
97475 {
97476 - struct ctl_table *table;
97477 + ctl_table_no_const *table = NULL;
97478 struct ctl_table_header *hdr;
97479
97480 - table = xfrm4_policy_table;
97481 if (!net_eq(net, &init_net)) {
97482 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
97483 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
97484 if (!table)
97485 goto err_alloc;
97486
97487 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
97488 - }
97489 -
97490 - hdr = register_net_sysctl(net, "net/ipv4", table);
97491 + hdr = register_net_sysctl(net, "net/ipv4", table);
97492 + } else
97493 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
97494 if (!hdr)
97495 goto err_reg;
97496
97497 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
97498 return 0;
97499
97500 err_reg:
97501 - if (!net_eq(net, &init_net))
97502 - kfree(table);
97503 + kfree(table);
97504 err_alloc:
97505 return -ENOMEM;
97506 }
97507 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
97508 index 4b6b720..272c0c5 100644
97509 --- a/net/ipv6/addrconf.c
97510 +++ b/net/ipv6/addrconf.c
97511 @@ -589,7 +589,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
97512 idx = 0;
97513 head = &net->dev_index_head[h];
97514 rcu_read_lock();
97515 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
97516 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
97517 net->dev_base_seq;
97518 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97519 if (idx < s_idx)
97520 @@ -2334,7 +2334,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
97521 p.iph.ihl = 5;
97522 p.iph.protocol = IPPROTO_IPV6;
97523 p.iph.ttl = 64;
97524 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
97525 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
97526
97527 if (ops->ndo_do_ioctl) {
97528 mm_segment_t oldfs = get_fs();
97529 @@ -3962,7 +3962,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
97530 s_ip_idx = ip_idx = cb->args[2];
97531
97532 rcu_read_lock();
97533 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
97534 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
97535 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
97536 idx = 0;
97537 head = &net->dev_index_head[h];
97538 @@ -4569,7 +4569,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
97539 dst_free(&ifp->rt->dst);
97540 break;
97541 }
97542 - atomic_inc(&net->ipv6.dev_addr_genid);
97543 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
97544 rt_genid_bump_ipv6(net);
97545 }
97546
97547 @@ -4590,7 +4590,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
97548 int *valp = ctl->data;
97549 int val = *valp;
97550 loff_t pos = *ppos;
97551 - struct ctl_table lctl;
97552 + ctl_table_no_const lctl;
97553 int ret;
97554
97555 /*
97556 @@ -4675,7 +4675,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
97557 int *valp = ctl->data;
97558 int val = *valp;
97559 loff_t pos = *ppos;
97560 - struct ctl_table lctl;
97561 + ctl_table_no_const lctl;
97562 int ret;
97563
97564 /*
97565 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
97566 index 4fbdb70..f6411f2 100644
97567 --- a/net/ipv6/af_inet6.c
97568 +++ b/net/ipv6/af_inet6.c
97569 @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
97570
97571 net->ipv6.sysctl.bindv6only = 0;
97572 net->ipv6.sysctl.icmpv6_time = 1*HZ;
97573 - atomic_set(&net->ipv6.rt_genid, 0);
97574 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
97575
97576 err = ipv6_init_mibs(net);
97577 if (err)
97578 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
97579 index 93b1aa3..e902855 100644
97580 --- a/net/ipv6/datagram.c
97581 +++ b/net/ipv6/datagram.c
97582 @@ -906,5 +906,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
97583 0,
97584 sock_i_ino(sp),
97585 atomic_read(&sp->sk_refcnt), sp,
97586 - atomic_read(&sp->sk_drops));
97587 + atomic_read_unchecked(&sp->sk_drops));
97588 }
97589 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
97590 index eef8d94..cfa1852 100644
97591 --- a/net/ipv6/icmp.c
97592 +++ b/net/ipv6/icmp.c
97593 @@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
97594
97595 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
97596 {
97597 - struct ctl_table *table;
97598 + ctl_table_no_const *table;
97599
97600 table = kmemdup(ipv6_icmp_table_template,
97601 sizeof(ipv6_icmp_table_template),
97602 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
97603 index 8acb286..840dd06 100644
97604 --- a/net/ipv6/ip6_gre.c
97605 +++ b/net/ipv6/ip6_gre.c
97606 @@ -74,7 +74,7 @@ struct ip6gre_net {
97607 struct net_device *fb_tunnel_dev;
97608 };
97609
97610 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
97611 +static struct rtnl_link_ops ip6gre_link_ops;
97612 static int ip6gre_tunnel_init(struct net_device *dev);
97613 static void ip6gre_tunnel_setup(struct net_device *dev);
97614 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
97615 @@ -1294,7 +1294,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
97616 }
97617
97618
97619 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
97620 +static struct inet6_protocol ip6gre_protocol = {
97621 .handler = ip6gre_rcv,
97622 .err_handler = ip6gre_err,
97623 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
97624 @@ -1637,7 +1637,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
97625 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
97626 };
97627
97628 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
97629 +static struct rtnl_link_ops ip6gre_link_ops = {
97630 .kind = "ip6gre",
97631 .maxtype = IFLA_GRE_MAX,
97632 .policy = ip6gre_policy,
97633 @@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
97634 .fill_info = ip6gre_fill_info,
97635 };
97636
97637 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
97638 +static struct rtnl_link_ops ip6gre_tap_ops = {
97639 .kind = "ip6gretap",
97640 .maxtype = IFLA_GRE_MAX,
97641 .policy = ip6gre_policy,
97642 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
97643 index 7881965..9cf62c4 100644
97644 --- a/net/ipv6/ip6_tunnel.c
97645 +++ b/net/ipv6/ip6_tunnel.c
97646 @@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
97647
97648 static int ip6_tnl_dev_init(struct net_device *dev);
97649 static void ip6_tnl_dev_setup(struct net_device *dev);
97650 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
97651 +static struct rtnl_link_ops ip6_link_ops;
97652
97653 static int ip6_tnl_net_id __read_mostly;
97654 struct ip6_tnl_net {
97655 @@ -1717,7 +1717,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
97656 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
97657 };
97658
97659 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
97660 +static struct rtnl_link_ops ip6_link_ops = {
97661 .kind = "ip6tnl",
97662 .maxtype = IFLA_IPTUN_MAX,
97663 .policy = ip6_tnl_policy,
97664 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
97665 index 7b42d5e..1eff693 100644
97666 --- a/net/ipv6/ip6_vti.c
97667 +++ b/net/ipv6/ip6_vti.c
97668 @@ -63,7 +63,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
97669
97670 static int vti6_dev_init(struct net_device *dev);
97671 static void vti6_dev_setup(struct net_device *dev);
97672 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
97673 +static struct rtnl_link_ops vti6_link_ops;
97674
97675 static int vti6_net_id __read_mostly;
97676 struct vti6_net {
97677 @@ -902,7 +902,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
97678 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
97679 };
97680
97681 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
97682 +static struct rtnl_link_ops vti6_link_ops = {
97683 .kind = "vti6",
97684 .maxtype = IFLA_VTI_MAX,
97685 .policy = vti6_policy,
97686 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
97687 index 1c6ce31..299e566 100644
97688 --- a/net/ipv6/ipv6_sockglue.c
97689 +++ b/net/ipv6/ipv6_sockglue.c
97690 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
97691 if (sk->sk_type != SOCK_STREAM)
97692 return -ENOPROTOOPT;
97693
97694 - msg.msg_control = optval;
97695 + msg.msg_control = (void __force_kernel *)optval;
97696 msg.msg_controllen = len;
97697 msg.msg_flags = flags;
97698
97699 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
97700 index 710238f..0fd1816 100644
97701 --- a/net/ipv6/netfilter/ip6_tables.c
97702 +++ b/net/ipv6/netfilter/ip6_tables.c
97703 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
97704 #endif
97705
97706 static int get_info(struct net *net, void __user *user,
97707 - const int *len, int compat)
97708 + int len, int compat)
97709 {
97710 char name[XT_TABLE_MAXNAMELEN];
97711 struct xt_table *t;
97712 int ret;
97713
97714 - if (*len != sizeof(struct ip6t_getinfo)) {
97715 - duprintf("length %u != %zu\n", *len,
97716 + if (len != sizeof(struct ip6t_getinfo)) {
97717 + duprintf("length %u != %zu\n", len,
97718 sizeof(struct ip6t_getinfo));
97719 return -EINVAL;
97720 }
97721 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
97722 info.size = private->size;
97723 strcpy(info.name, name);
97724
97725 - if (copy_to_user(user, &info, *len) != 0)
97726 + if (copy_to_user(user, &info, len) != 0)
97727 ret = -EFAULT;
97728 else
97729 ret = 0;
97730 @@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97731
97732 switch (cmd) {
97733 case IP6T_SO_GET_INFO:
97734 - ret = get_info(sock_net(sk), user, len, 1);
97735 + ret = get_info(sock_net(sk), user, *len, 1);
97736 break;
97737 case IP6T_SO_GET_ENTRIES:
97738 ret = compat_get_entries(sock_net(sk), user, len);
97739 @@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97740
97741 switch (cmd) {
97742 case IP6T_SO_GET_INFO:
97743 - ret = get_info(sock_net(sk), user, len, 0);
97744 + ret = get_info(sock_net(sk), user, *len, 0);
97745 break;
97746
97747 case IP6T_SO_GET_ENTRIES:
97748 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
97749 index 767ab8d..c5ec70a 100644
97750 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
97751 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
97752 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
97753
97754 static int nf_ct_frag6_sysctl_register(struct net *net)
97755 {
97756 - struct ctl_table *table;
97757 + ctl_table_no_const *table = NULL;
97758 struct ctl_table_header *hdr;
97759
97760 - table = nf_ct_frag6_sysctl_table;
97761 if (!net_eq(net, &init_net)) {
97762 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
97763 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
97764 GFP_KERNEL);
97765 if (table == NULL)
97766 goto err_alloc;
97767 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
97768 table[0].data = &net->nf_frag.frags.timeout;
97769 table[1].data = &net->nf_frag.frags.low_thresh;
97770 table[2].data = &net->nf_frag.frags.high_thresh;
97771 - }
97772 -
97773 - hdr = register_net_sysctl(net, "net/netfilter", table);
97774 + hdr = register_net_sysctl(net, "net/netfilter", table);
97775 + } else
97776 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
97777 if (hdr == NULL)
97778 goto err_reg;
97779
97780 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
97781 return 0;
97782
97783 err_reg:
97784 - if (!net_eq(net, &init_net))
97785 - kfree(table);
97786 + kfree(table);
97787 err_alloc:
97788 return -ENOMEM;
97789 }
97790 diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
97791 index 827f795..7e28e82 100644
97792 --- a/net/ipv6/output_core.c
97793 +++ b/net/ipv6/output_core.c
97794 @@ -9,8 +9,8 @@
97795
97796 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
97797 {
97798 - static atomic_t ipv6_fragmentation_id;
97799 - int old, new;
97800 + static atomic_unchecked_t ipv6_fragmentation_id;
97801 + int id;
97802
97803 #if IS_ENABLED(CONFIG_IPV6)
97804 if (rt && !(rt->dst.flags & DST_NOPEER)) {
97805 @@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
97806 }
97807 }
97808 #endif
97809 - do {
97810 - old = atomic_read(&ipv6_fragmentation_id);
97811 - new = old + 1;
97812 - if (!new)
97813 - new = 1;
97814 - } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
97815 - fhdr->identification = htonl(new);
97816 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
97817 + if (!id)
97818 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
97819 + fhdr->identification = htonl(id);
97820 }
97821 EXPORT_SYMBOL(ipv6_select_ident);
97822
97823 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
97824 index a83243c..a1ca589 100644
97825 --- a/net/ipv6/ping.c
97826 +++ b/net/ipv6/ping.c
97827 @@ -246,6 +246,22 @@ static struct pernet_operations ping_v6_net_ops = {
97828 };
97829 #endif
97830
97831 +static struct pingv6_ops real_pingv6_ops = {
97832 + .ipv6_recv_error = ipv6_recv_error,
97833 + .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
97834 + .icmpv6_err_convert = icmpv6_err_convert,
97835 + .ipv6_icmp_error = ipv6_icmp_error,
97836 + .ipv6_chk_addr = ipv6_chk_addr,
97837 +};
97838 +
97839 +static struct pingv6_ops dummy_pingv6_ops = {
97840 + .ipv6_recv_error = dummy_ipv6_recv_error,
97841 + .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
97842 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
97843 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
97844 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
97845 +};
97846 +
97847 int __init pingv6_init(void)
97848 {
97849 #ifdef CONFIG_PROC_FS
97850 @@ -253,11 +269,7 @@ int __init pingv6_init(void)
97851 if (ret)
97852 return ret;
97853 #endif
97854 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
97855 - pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
97856 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
97857 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
97858 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
97859 + pingv6_ops = &real_pingv6_ops;
97860 return inet6_register_protosw(&pingv6_protosw);
97861 }
97862
97863 @@ -266,11 +278,7 @@ int __init pingv6_init(void)
97864 */
97865 void pingv6_exit(void)
97866 {
97867 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
97868 - pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
97869 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
97870 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
97871 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
97872 + pingv6_ops = &dummy_pingv6_ops;
97873 #ifdef CONFIG_PROC_FS
97874 unregister_pernet_subsys(&ping_v6_net_ops);
97875 #endif
97876 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
97877 index b6bb87e..06cc9ed 100644
97878 --- a/net/ipv6/raw.c
97879 +++ b/net/ipv6/raw.c
97880 @@ -384,7 +384,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
97881 {
97882 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
97883 skb_checksum_complete(skb)) {
97884 - atomic_inc(&sk->sk_drops);
97885 + atomic_inc_unchecked(&sk->sk_drops);
97886 kfree_skb(skb);
97887 return NET_RX_DROP;
97888 }
97889 @@ -412,7 +412,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
97890 struct raw6_sock *rp = raw6_sk(sk);
97891
97892 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
97893 - atomic_inc(&sk->sk_drops);
97894 + atomic_inc_unchecked(&sk->sk_drops);
97895 kfree_skb(skb);
97896 return NET_RX_DROP;
97897 }
97898 @@ -436,7 +436,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
97899
97900 if (inet->hdrincl) {
97901 if (skb_checksum_complete(skb)) {
97902 - atomic_inc(&sk->sk_drops);
97903 + atomic_inc_unchecked(&sk->sk_drops);
97904 kfree_skb(skb);
97905 return NET_RX_DROP;
97906 }
97907 @@ -465,6 +465,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
97908 if (flags & MSG_OOB)
97909 return -EOPNOTSUPP;
97910
97911 + if (addr_len)
97912 + *addr_len=sizeof(*sin6);
97913 +
97914 if (flags & MSG_ERRQUEUE)
97915 return ipv6_recv_error(sk, msg, len, addr_len);
97916
97917 @@ -503,7 +506,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
97918 sin6->sin6_flowinfo = 0;
97919 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
97920 IP6CB(skb)->iif);
97921 - *addr_len = sizeof(*sin6);
97922 }
97923
97924 sock_recv_ts_and_drops(msg, sk, skb);
97925 @@ -606,7 +608,7 @@ out:
97926 return err;
97927 }
97928
97929 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
97930 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
97931 struct flowi6 *fl6, struct dst_entry **dstp,
97932 unsigned int flags)
97933 {
97934 @@ -918,12 +920,15 @@ do_confirm:
97935 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
97936 char __user *optval, int optlen)
97937 {
97938 + struct icmp6_filter filter;
97939 +
97940 switch (optname) {
97941 case ICMPV6_FILTER:
97942 if (optlen > sizeof(struct icmp6_filter))
97943 optlen = sizeof(struct icmp6_filter);
97944 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
97945 + if (copy_from_user(&filter, optval, optlen))
97946 return -EFAULT;
97947 + raw6_sk(sk)->filter = filter;
97948 return 0;
97949 default:
97950 return -ENOPROTOOPT;
97951 @@ -936,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
97952 char __user *optval, int __user *optlen)
97953 {
97954 int len;
97955 + struct icmp6_filter filter;
97956
97957 switch (optname) {
97958 case ICMPV6_FILTER:
97959 @@ -947,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
97960 len = sizeof(struct icmp6_filter);
97961 if (put_user(len, optlen))
97962 return -EFAULT;
97963 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
97964 + filter = raw6_sk(sk)->filter;
97965 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
97966 return -EFAULT;
97967 return 0;
97968 default:
97969 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
97970 index cc85a9b..526a133 100644
97971 --- a/net/ipv6/reassembly.c
97972 +++ b/net/ipv6/reassembly.c
97973 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
97974
97975 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
97976 {
97977 - struct ctl_table *table;
97978 + ctl_table_no_const *table = NULL;
97979 struct ctl_table_header *hdr;
97980
97981 - table = ip6_frags_ns_ctl_table;
97982 if (!net_eq(net, &init_net)) {
97983 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
97984 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
97985 if (table == NULL)
97986 goto err_alloc;
97987
97988 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
97989 /* Don't export sysctls to unprivileged users */
97990 if (net->user_ns != &init_user_ns)
97991 table[0].procname = NULL;
97992 - }
97993 + hdr = register_net_sysctl(net, "net/ipv6", table);
97994 + } else
97995 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
97996
97997 - hdr = register_net_sysctl(net, "net/ipv6", table);
97998 if (hdr == NULL)
97999 goto err_reg;
98000
98001 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
98002 return 0;
98003
98004 err_reg:
98005 - if (!net_eq(net, &init_net))
98006 - kfree(table);
98007 + kfree(table);
98008 err_alloc:
98009 return -ENOMEM;
98010 }
98011 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
98012 index 4b4944c..4580b91 100644
98013 --- a/net/ipv6/route.c
98014 +++ b/net/ipv6/route.c
98015 @@ -2954,7 +2954,7 @@ struct ctl_table ipv6_route_table_template[] = {
98016
98017 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
98018 {
98019 - struct ctl_table *table;
98020 + ctl_table_no_const *table;
98021
98022 table = kmemdup(ipv6_route_table_template,
98023 sizeof(ipv6_route_table_template),
98024 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
98025 index d3005b3..b36df4a 100644
98026 --- a/net/ipv6/sit.c
98027 +++ b/net/ipv6/sit.c
98028 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
98029 static void ipip6_dev_free(struct net_device *dev);
98030 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
98031 __be32 *v4dst);
98032 -static struct rtnl_link_ops sit_link_ops __read_mostly;
98033 +static struct rtnl_link_ops sit_link_ops;
98034
98035 static int sit_net_id __read_mostly;
98036 struct sit_net {
98037 @@ -1664,7 +1664,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
98038 unregister_netdevice_queue(dev, head);
98039 }
98040
98041 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
98042 +static struct rtnl_link_ops sit_link_ops = {
98043 .kind = "sit",
98044 .maxtype = IFLA_IPTUN_MAX,
98045 .policy = ipip6_policy,
98046 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
98047 index 107b2f1..72741a9 100644
98048 --- a/net/ipv6/sysctl_net_ipv6.c
98049 +++ b/net/ipv6/sysctl_net_ipv6.c
98050 @@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
98051
98052 static int __net_init ipv6_sysctl_net_init(struct net *net)
98053 {
98054 - struct ctl_table *ipv6_table;
98055 + ctl_table_no_const *ipv6_table;
98056 struct ctl_table *ipv6_route_table;
98057 struct ctl_table *ipv6_icmp_table;
98058 int err;
98059 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
98060 index f67033b..6f974fc 100644
98061 --- a/net/ipv6/tcp_ipv6.c
98062 +++ b/net/ipv6/tcp_ipv6.c
98063 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
98064 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
98065 }
98066
98067 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98068 +extern int grsec_enable_blackhole;
98069 +#endif
98070 +
98071 static void tcp_v6_hash(struct sock *sk)
98072 {
98073 if (sk->sk_state != TCP_CLOSE) {
98074 @@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
98075 return 0;
98076
98077 reset:
98078 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98079 + if (!grsec_enable_blackhole)
98080 +#endif
98081 tcp_v6_send_reset(sk, skb);
98082 discard:
98083 if (opt_skb)
98084 @@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
98085 TCP_SKB_CB(skb)->sacked = 0;
98086
98087 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
98088 - if (!sk)
98089 + if (!sk) {
98090 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98091 + ret = 1;
98092 +#endif
98093 goto no_tcp_socket;
98094 + }
98095
98096 process:
98097 - if (sk->sk_state == TCP_TIME_WAIT)
98098 + if (sk->sk_state == TCP_TIME_WAIT) {
98099 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98100 + ret = 2;
98101 +#endif
98102 goto do_time_wait;
98103 + }
98104
98105 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
98106 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
98107 @@ -1536,6 +1551,10 @@ csum_error:
98108 bad_packet:
98109 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
98110 } else {
98111 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98112 + if (!grsec_enable_blackhole || (ret == 1 &&
98113 + (skb->dev->flags & IFF_LOOPBACK)))
98114 +#endif
98115 tcp_v6_send_reset(NULL, skb);
98116 }
98117
98118 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
98119 index 089c741..cfee117 100644
98120 --- a/net/ipv6/udp.c
98121 +++ b/net/ipv6/udp.c
98122 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
98123 udp_ipv6_hash_secret + net_hash_mix(net));
98124 }
98125
98126 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98127 +extern int grsec_enable_blackhole;
98128 +#endif
98129 +
98130 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
98131 {
98132 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
98133 @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
98134 int is_udp4;
98135 bool slow;
98136
98137 + if (addr_len)
98138 + *addr_len = sizeof(struct sockaddr_in6);
98139 +
98140 if (flags & MSG_ERRQUEUE)
98141 return ipv6_recv_error(sk, msg, len, addr_len);
98142
98143 @@ -435,7 +442,7 @@ try_again:
98144 if (unlikely(err)) {
98145 trace_kfree_skb(skb, udpv6_recvmsg);
98146 if (!peeked) {
98147 - atomic_inc(&sk->sk_drops);
98148 + atomic_inc_unchecked(&sk->sk_drops);
98149 if (is_udp4)
98150 UDP_INC_STATS_USER(sock_net(sk),
98151 UDP_MIB_INERRORS,
98152 @@ -477,7 +484,7 @@ try_again:
98153 ipv6_iface_scope_id(&sin6->sin6_addr,
98154 IP6CB(skb)->iif);
98155 }
98156 - *addr_len = sizeof(*sin6);
98157 +
98158 }
98159 if (is_udp4) {
98160 if (inet->cmsg_flags)
98161 @@ -685,7 +692,7 @@ csum_error:
98162 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
98163 drop:
98164 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
98165 - atomic_inc(&sk->sk_drops);
98166 + atomic_inc_unchecked(&sk->sk_drops);
98167 kfree_skb(skb);
98168 return -1;
98169 }
98170 @@ -742,7 +749,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
98171 if (likely(skb1 == NULL))
98172 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
98173 if (!skb1) {
98174 - atomic_inc(&sk->sk_drops);
98175 + atomic_inc_unchecked(&sk->sk_drops);
98176 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
98177 IS_UDPLITE(sk));
98178 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98179 @@ -881,6 +888,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
98180 goto csum_error;
98181
98182 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
98183 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98184 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
98185 +#endif
98186 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
98187
98188 kfree_skb(skb);
98189 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
98190 index 5f8e128..865d38e 100644
98191 --- a/net/ipv6/xfrm6_policy.c
98192 +++ b/net/ipv6/xfrm6_policy.c
98193 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
98194 }
98195 }
98196
98197 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
98198 +static int xfrm6_garbage_collect(struct dst_ops *ops)
98199 {
98200 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
98201
98202 - xfrm6_policy_afinfo.garbage_collect(net);
98203 + xfrm_garbage_collect_deferred(net);
98204 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
98205 }
98206
98207 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
98208
98209 static int __net_init xfrm6_net_init(struct net *net)
98210 {
98211 - struct ctl_table *table;
98212 + ctl_table_no_const *table = NULL;
98213 struct ctl_table_header *hdr;
98214
98215 - table = xfrm6_policy_table;
98216 if (!net_eq(net, &init_net)) {
98217 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
98218 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
98219 if (!table)
98220 goto err_alloc;
98221
98222 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
98223 - }
98224 + hdr = register_net_sysctl(net, "net/ipv6", table);
98225 + } else
98226 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
98227
98228 - hdr = register_net_sysctl(net, "net/ipv6", table);
98229 if (!hdr)
98230 goto err_reg;
98231
98232 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
98233 return 0;
98234
98235 err_reg:
98236 - if (!net_eq(net, &init_net))
98237 - kfree(table);
98238 + kfree(table);
98239 err_alloc:
98240 return -ENOMEM;
98241 }
98242 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
98243 index 41ac7938..75e3bb1 100644
98244 --- a/net/irda/ircomm/ircomm_tty.c
98245 +++ b/net/irda/ircomm/ircomm_tty.c
98246 @@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98247 add_wait_queue(&port->open_wait, &wait);
98248
98249 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
98250 - __FILE__, __LINE__, tty->driver->name, port->count);
98251 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98252
98253 spin_lock_irqsave(&port->lock, flags);
98254 if (!tty_hung_up_p(filp))
98255 - port->count--;
98256 + atomic_dec(&port->count);
98257 port->blocked_open++;
98258 spin_unlock_irqrestore(&port->lock, flags);
98259
98260 @@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98261 }
98262
98263 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
98264 - __FILE__, __LINE__, tty->driver->name, port->count);
98265 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98266
98267 schedule();
98268 }
98269 @@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98270
98271 spin_lock_irqsave(&port->lock, flags);
98272 if (!tty_hung_up_p(filp))
98273 - port->count++;
98274 + atomic_inc(&port->count);
98275 port->blocked_open--;
98276 spin_unlock_irqrestore(&port->lock, flags);
98277
98278 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
98279 - __FILE__, __LINE__, tty->driver->name, port->count);
98280 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98281
98282 if (!retval)
98283 port->flags |= ASYNC_NORMAL_ACTIVE;
98284 @@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
98285
98286 /* ++ is not atomic, so this should be protected - Jean II */
98287 spin_lock_irqsave(&self->port.lock, flags);
98288 - self->port.count++;
98289 + atomic_inc(&self->port.count);
98290 spin_unlock_irqrestore(&self->port.lock, flags);
98291 tty_port_tty_set(&self->port, tty);
98292
98293 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
98294 - self->line, self->port.count);
98295 + self->line, atomic_read(&self->port.count));
98296
98297 /* Not really used by us, but lets do it anyway */
98298 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
98299 @@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
98300 tty_kref_put(port->tty);
98301 }
98302 port->tty = NULL;
98303 - port->count = 0;
98304 + atomic_set(&port->count, 0);
98305 spin_unlock_irqrestore(&port->lock, flags);
98306
98307 wake_up_interruptible(&port->open_wait);
98308 @@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
98309 seq_putc(m, '\n');
98310
98311 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
98312 - seq_printf(m, "Open count: %d\n", self->port.count);
98313 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
98314 seq_printf(m, "Max data size: %d\n", self->max_data_size);
98315 seq_printf(m, "Max header size: %d\n", self->max_header_size);
98316
98317 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
98318 index c4b7218..3e83259 100644
98319 --- a/net/iucv/af_iucv.c
98320 +++ b/net/iucv/af_iucv.c
98321 @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
98322
98323 write_lock_bh(&iucv_sk_list.lock);
98324
98325 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
98326 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
98327 while (__iucv_get_sock_by_name(name)) {
98328 sprintf(name, "%08x",
98329 - atomic_inc_return(&iucv_sk_list.autobind_name));
98330 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
98331 }
98332
98333 write_unlock_bh(&iucv_sk_list.lock);
98334 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
98335 index cd5b8ec..f205e6b 100644
98336 --- a/net/iucv/iucv.c
98337 +++ b/net/iucv/iucv.c
98338 @@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
98339 return NOTIFY_OK;
98340 }
98341
98342 -static struct notifier_block __refdata iucv_cpu_notifier = {
98343 +static struct notifier_block iucv_cpu_notifier = {
98344 .notifier_call = iucv_cpu_notify,
98345 };
98346
98347 diff --git a/net/key/af_key.c b/net/key/af_key.c
98348 index 545f047..9757a9d 100644
98349 --- a/net/key/af_key.c
98350 +++ b/net/key/af_key.c
98351 @@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
98352 static u32 get_acqseq(void)
98353 {
98354 u32 res;
98355 - static atomic_t acqseq;
98356 + static atomic_unchecked_t acqseq;
98357
98358 do {
98359 - res = atomic_inc_return(&acqseq);
98360 + res = atomic_inc_return_unchecked(&acqseq);
98361 } while (!res);
98362 return res;
98363 }
98364 diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
98365 index da1a1ce..571db8d 100644
98366 --- a/net/l2tp/l2tp_ip.c
98367 +++ b/net/l2tp/l2tp_ip.c
98368 @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
98369 if (flags & MSG_OOB)
98370 goto out;
98371
98372 + if (addr_len)
98373 + *addr_len = sizeof(*sin);
98374 +
98375 skb = skb_recv_datagram(sk, flags, noblock, &err);
98376 if (!skb)
98377 goto out;
98378 @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
98379 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98380 sin->sin_port = 0;
98381 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98382 - *addr_len = sizeof(*sin);
98383 }
98384 if (inet->cmsg_flags)
98385 ip_cmsg_recv(msg, skb);
98386 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
98387 index 364ce0c..3ebb5a4 100644
98388 --- a/net/mac80211/cfg.c
98389 +++ b/net/mac80211/cfg.c
98390 @@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
98391 ret = ieee80211_vif_use_channel(sdata, chandef,
98392 IEEE80211_CHANCTX_EXCLUSIVE);
98393 }
98394 - } else if (local->open_count == local->monitors) {
98395 + } else if (local_read(&local->open_count) == local->monitors) {
98396 local->_oper_chandef = *chandef;
98397 ieee80211_hw_config(local, 0);
98398 }
98399 @@ -3308,7 +3308,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
98400 else
98401 local->probe_req_reg--;
98402
98403 - if (!local->open_count)
98404 + if (!local_read(&local->open_count))
98405 break;
98406
98407 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
98408 @@ -3771,8 +3771,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
98409 if (chanctx_conf) {
98410 *chandef = chanctx_conf->def;
98411 ret = 0;
98412 - } else if (local->open_count > 0 &&
98413 - local->open_count == local->monitors &&
98414 + } else if (local_read(&local->open_count) > 0 &&
98415 + local_read(&local->open_count) == local->monitors &&
98416 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
98417 if (local->use_chanctx)
98418 *chandef = local->monitor_chandef;
98419 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
98420 index 4aea4e7..9e698d1 100644
98421 --- a/net/mac80211/ieee80211_i.h
98422 +++ b/net/mac80211/ieee80211_i.h
98423 @@ -28,6 +28,7 @@
98424 #include <net/ieee80211_radiotap.h>
98425 #include <net/cfg80211.h>
98426 #include <net/mac80211.h>
98427 +#include <asm/local.h>
98428 #include "key.h"
98429 #include "sta_info.h"
98430 #include "debug.h"
98431 @@ -961,7 +962,7 @@ struct ieee80211_local {
98432 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
98433 spinlock_t queue_stop_reason_lock;
98434
98435 - int open_count;
98436 + local_t open_count;
98437 int monitors, cooked_mntrs;
98438 /* number of interfaces with corresponding FIF_ flags */
98439 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
98440 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
98441 index a075791..1d0027f 100644
98442 --- a/net/mac80211/iface.c
98443 +++ b/net/mac80211/iface.c
98444 @@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98445 break;
98446 }
98447
98448 - if (local->open_count == 0) {
98449 + if (local_read(&local->open_count) == 0) {
98450 res = drv_start(local);
98451 if (res)
98452 goto err_del_bss;
98453 @@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98454 res = drv_add_interface(local, sdata);
98455 if (res)
98456 goto err_stop;
98457 - } else if (local->monitors == 0 && local->open_count == 0) {
98458 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
98459 res = ieee80211_add_virtual_monitor(local);
98460 if (res)
98461 goto err_stop;
98462 @@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98463 atomic_inc(&local->iff_promiscs);
98464
98465 if (coming_up)
98466 - local->open_count++;
98467 + local_inc(&local->open_count);
98468
98469 if (hw_reconf_flags)
98470 ieee80211_hw_config(local, hw_reconf_flags);
98471 @@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98472 err_del_interface:
98473 drv_remove_interface(local, sdata);
98474 err_stop:
98475 - if (!local->open_count)
98476 + if (!local_read(&local->open_count))
98477 drv_stop(local);
98478 err_del_bss:
98479 sdata->bss = NULL;
98480 @@ -856,7 +856,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98481 }
98482
98483 if (going_down)
98484 - local->open_count--;
98485 + local_dec(&local->open_count);
98486
98487 switch (sdata->vif.type) {
98488 case NL80211_IFTYPE_AP_VLAN:
98489 @@ -923,7 +923,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98490 }
98491 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
98492
98493 - if (local->open_count == 0)
98494 + if (local_read(&local->open_count) == 0)
98495 ieee80211_clear_tx_pending(local);
98496
98497 /*
98498 @@ -963,7 +963,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98499
98500 ieee80211_recalc_ps(local, -1);
98501
98502 - if (local->open_count == 0) {
98503 + if (local_read(&local->open_count) == 0) {
98504 ieee80211_stop_device(local);
98505
98506 /* no reconfiguring after stop! */
98507 @@ -974,7 +974,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98508 ieee80211_configure_filter(local);
98509 ieee80211_hw_config(local, hw_reconf_flags);
98510
98511 - if (local->monitors == local->open_count)
98512 + if (local->monitors == local_read(&local->open_count))
98513 ieee80211_add_virtual_monitor(local);
98514 }
98515
98516 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
98517 index 7d1c3ac..b62dd29 100644
98518 --- a/net/mac80211/main.c
98519 +++ b/net/mac80211/main.c
98520 @@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
98521 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
98522 IEEE80211_CONF_CHANGE_POWER);
98523
98524 - if (changed && local->open_count) {
98525 + if (changed && local_read(&local->open_count)) {
98526 ret = drv_config(local, changed);
98527 /*
98528 * Goal:
98529 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
98530 index 3401262..d5cd68d 100644
98531 --- a/net/mac80211/pm.c
98532 +++ b/net/mac80211/pm.c
98533 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98534 struct ieee80211_sub_if_data *sdata;
98535 struct sta_info *sta;
98536
98537 - if (!local->open_count)
98538 + if (!local_read(&local->open_count))
98539 goto suspend;
98540
98541 ieee80211_scan_cancel(local);
98542 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98543 cancel_work_sync(&local->dynamic_ps_enable_work);
98544 del_timer_sync(&local->dynamic_ps_timer);
98545
98546 - local->wowlan = wowlan && local->open_count;
98547 + local->wowlan = wowlan && local_read(&local->open_count);
98548 if (local->wowlan) {
98549 int err = drv_suspend(local, wowlan);
98550 if (err < 0) {
98551 @@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98552 WARN_ON(!list_empty(&local->chanctx_list));
98553
98554 /* stop hardware - this must stop RX */
98555 - if (local->open_count)
98556 + if (local_read(&local->open_count))
98557 ieee80211_stop_device(local);
98558
98559 suspend:
98560 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
98561 index 22b223f..ab70070 100644
98562 --- a/net/mac80211/rate.c
98563 +++ b/net/mac80211/rate.c
98564 @@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
98565
98566 ASSERT_RTNL();
98567
98568 - if (local->open_count)
98569 + if (local_read(&local->open_count))
98570 return -EBUSY;
98571
98572 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
98573 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
98574 index 6ff1346..936ca9a 100644
98575 --- a/net/mac80211/rc80211_pid_debugfs.c
98576 +++ b/net/mac80211/rc80211_pid_debugfs.c
98577 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
98578
98579 spin_unlock_irqrestore(&events->lock, status);
98580
98581 - if (copy_to_user(buf, pb, p))
98582 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
98583 return -EFAULT;
98584
98585 return p;
98586 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
98587 index 9f9b9bd..d6fcf59 100644
98588 --- a/net/mac80211/util.c
98589 +++ b/net/mac80211/util.c
98590 @@ -1474,7 +1474,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
98591 }
98592 #endif
98593 /* everything else happens only if HW was up & running */
98594 - if (!local->open_count)
98595 + if (!local_read(&local->open_count))
98596 goto wake_up;
98597
98598 /*
98599 @@ -1699,7 +1699,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
98600 local->in_reconfig = false;
98601 barrier();
98602
98603 - if (local->monitors == local->open_count && local->monitors > 0)
98604 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
98605 ieee80211_add_virtual_monitor(local);
98606
98607 /*
98608 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
98609 index c3398cd..98ad3b4 100644
98610 --- a/net/netfilter/Kconfig
98611 +++ b/net/netfilter/Kconfig
98612 @@ -1002,6 +1002,16 @@ config NETFILTER_XT_MATCH_ESP
98613
98614 To compile it as a module, choose M here. If unsure, say N.
98615
98616 +config NETFILTER_XT_MATCH_GRADM
98617 + tristate '"gradm" match support'
98618 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
98619 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
98620 + ---help---
98621 + The gradm match allows to match on grsecurity RBAC being enabled.
98622 + It is useful when iptables rules are applied early on bootup to
98623 + prevent connections to the machine (except from a trusted host)
98624 + while the RBAC system is disabled.
98625 +
98626 config NETFILTER_XT_MATCH_HASHLIMIT
98627 tristate '"hashlimit" match support'
98628 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
98629 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
98630 index 394483b..ed51f2d 100644
98631 --- a/net/netfilter/Makefile
98632 +++ b/net/netfilter/Makefile
98633 @@ -130,6 +130,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
98634 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
98635 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
98636 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
98637 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
98638 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
98639 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
98640 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
98641 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
98642 index bac7e01..1d7a31a 100644
98643 --- a/net/netfilter/ipset/ip_set_core.c
98644 +++ b/net/netfilter/ipset/ip_set_core.c
98645 @@ -1950,7 +1950,7 @@ done:
98646 return ret;
98647 }
98648
98649 -static struct nf_sockopt_ops so_set __read_mostly = {
98650 +static struct nf_sockopt_ops so_set = {
98651 .pf = PF_INET,
98652 .get_optmin = SO_IP_SET,
98653 .get_optmax = SO_IP_SET + 1,
98654 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
98655 index 4c8e5c0..5a79b4d 100644
98656 --- a/net/netfilter/ipvs/ip_vs_conn.c
98657 +++ b/net/netfilter/ipvs/ip_vs_conn.c
98658 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
98659 /* Increase the refcnt counter of the dest */
98660 ip_vs_dest_hold(dest);
98661
98662 - conn_flags = atomic_read(&dest->conn_flags);
98663 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
98664 if (cp->protocol != IPPROTO_UDP)
98665 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
98666 flags = cp->flags;
98667 @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
98668
98669 cp->control = NULL;
98670 atomic_set(&cp->n_control, 0);
98671 - atomic_set(&cp->in_pkts, 0);
98672 + atomic_set_unchecked(&cp->in_pkts, 0);
98673
98674 cp->packet_xmit = NULL;
98675 cp->app = NULL;
98676 @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
98677
98678 /* Don't drop the entry if its number of incoming packets is not
98679 located in [0, 8] */
98680 - i = atomic_read(&cp->in_pkts);
98681 + i = atomic_read_unchecked(&cp->in_pkts);
98682 if (i > 8 || i < 0) return 0;
98683
98684 if (!todrop_rate[i]) return 0;
98685 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
98686 index 4f26ee4..6a9d7c3 100644
98687 --- a/net/netfilter/ipvs/ip_vs_core.c
98688 +++ b/net/netfilter/ipvs/ip_vs_core.c
98689 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
98690 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
98691 /* do not touch skb anymore */
98692
98693 - atomic_inc(&cp->in_pkts);
98694 + atomic_inc_unchecked(&cp->in_pkts);
98695 ip_vs_conn_put(cp);
98696 return ret;
98697 }
98698 @@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
98699 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
98700 pkts = sysctl_sync_threshold(ipvs);
98701 else
98702 - pkts = atomic_add_return(1, &cp->in_pkts);
98703 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98704
98705 if (ipvs->sync_state & IP_VS_STATE_MASTER)
98706 ip_vs_sync_conn(net, cp, pkts);
98707 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
98708 index 35be035..dad174b 100644
98709 --- a/net/netfilter/ipvs/ip_vs_ctl.c
98710 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
98711 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
98712 */
98713 ip_vs_rs_hash(ipvs, dest);
98714 }
98715 - atomic_set(&dest->conn_flags, conn_flags);
98716 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
98717
98718 /* bind the service */
98719 old_svc = rcu_dereference_protected(dest->svc, 1);
98720 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
98721 * align with netns init in ip_vs_control_net_init()
98722 */
98723
98724 -static struct ctl_table vs_vars[] = {
98725 +static ctl_table_no_const vs_vars[] __read_only = {
98726 {
98727 .procname = "amemthresh",
98728 .maxlen = sizeof(int),
98729 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
98730 " %-7s %-6d %-10d %-10d\n",
98731 &dest->addr.in6,
98732 ntohs(dest->port),
98733 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
98734 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
98735 atomic_read(&dest->weight),
98736 atomic_read(&dest->activeconns),
98737 atomic_read(&dest->inactconns));
98738 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
98739 "%-7s %-6d %-10d %-10d\n",
98740 ntohl(dest->addr.ip),
98741 ntohs(dest->port),
98742 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
98743 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
98744 atomic_read(&dest->weight),
98745 atomic_read(&dest->activeconns),
98746 atomic_read(&dest->inactconns));
98747 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
98748
98749 entry.addr = dest->addr.ip;
98750 entry.port = dest->port;
98751 - entry.conn_flags = atomic_read(&dest->conn_flags);
98752 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
98753 entry.weight = atomic_read(&dest->weight);
98754 entry.u_threshold = dest->u_threshold;
98755 entry.l_threshold = dest->l_threshold;
98756 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
98757 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
98758 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
98759 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
98760 - (atomic_read(&dest->conn_flags) &
98761 + (atomic_read_unchecked(&dest->conn_flags) &
98762 IP_VS_CONN_F_FWD_MASK)) ||
98763 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
98764 atomic_read(&dest->weight)) ||
98765 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
98766 {
98767 int idx;
98768 struct netns_ipvs *ipvs = net_ipvs(net);
98769 - struct ctl_table *tbl;
98770 + ctl_table_no_const *tbl;
98771
98772 atomic_set(&ipvs->dropentry, 0);
98773 spin_lock_init(&ipvs->dropentry_lock);
98774 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
98775 index ca056a3..9cf01ef 100644
98776 --- a/net/netfilter/ipvs/ip_vs_lblc.c
98777 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
98778 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
98779 * IPVS LBLC sysctl table
98780 */
98781 #ifdef CONFIG_SYSCTL
98782 -static struct ctl_table vs_vars_table[] = {
98783 +static ctl_table_no_const vs_vars_table[] __read_only = {
98784 {
98785 .procname = "lblc_expiration",
98786 .data = NULL,
98787 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
98788 index 3f21a2f..a112e85 100644
98789 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
98790 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
98791 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
98792 * IPVS LBLCR sysctl table
98793 */
98794
98795 -static struct ctl_table vs_vars_table[] = {
98796 +static ctl_table_no_const vs_vars_table[] __read_only = {
98797 {
98798 .procname = "lblcr_expiration",
98799 .data = NULL,
98800 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
98801 index f63c238..1b87f8a 100644
98802 --- a/net/netfilter/ipvs/ip_vs_sync.c
98803 +++ b/net/netfilter/ipvs/ip_vs_sync.c
98804 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
98805 cp = cp->control;
98806 if (cp) {
98807 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
98808 - pkts = atomic_add_return(1, &cp->in_pkts);
98809 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98810 else
98811 pkts = sysctl_sync_threshold(ipvs);
98812 ip_vs_sync_conn(net, cp->control, pkts);
98813 @@ -771,7 +771,7 @@ control:
98814 if (!cp)
98815 return;
98816 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
98817 - pkts = atomic_add_return(1, &cp->in_pkts);
98818 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98819 else
98820 pkts = sysctl_sync_threshold(ipvs);
98821 goto sloop;
98822 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
98823
98824 if (opt)
98825 memcpy(&cp->in_seq, opt, sizeof(*opt));
98826 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
98827 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
98828 cp->state = state;
98829 cp->old_state = cp->state;
98830 /*
98831 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
98832 index c47444e..b0961c6 100644
98833 --- a/net/netfilter/ipvs/ip_vs_xmit.c
98834 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
98835 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
98836 else
98837 rc = NF_ACCEPT;
98838 /* do not touch skb anymore */
98839 - atomic_inc(&cp->in_pkts);
98840 + atomic_inc_unchecked(&cp->in_pkts);
98841 goto out;
98842 }
98843
98844 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
98845 else
98846 rc = NF_ACCEPT;
98847 /* do not touch skb anymore */
98848 - atomic_inc(&cp->in_pkts);
98849 + atomic_inc_unchecked(&cp->in_pkts);
98850 goto out;
98851 }
98852
98853 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
98854 index a4b5e2a..13b1de3 100644
98855 --- a/net/netfilter/nf_conntrack_acct.c
98856 +++ b/net/netfilter/nf_conntrack_acct.c
98857 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
98858 #ifdef CONFIG_SYSCTL
98859 static int nf_conntrack_acct_init_sysctl(struct net *net)
98860 {
98861 - struct ctl_table *table;
98862 + ctl_table_no_const *table;
98863
98864 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
98865 GFP_KERNEL);
98866 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
98867 index 43549eb..0bbeace 100644
98868 --- a/net/netfilter/nf_conntrack_core.c
98869 +++ b/net/netfilter/nf_conntrack_core.c
98870 @@ -1605,6 +1605,10 @@ void nf_conntrack_init_end(void)
98871 #define DYING_NULLS_VAL ((1<<30)+1)
98872 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
98873
98874 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98875 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
98876 +#endif
98877 +
98878 int nf_conntrack_init_net(struct net *net)
98879 {
98880 int ret;
98881 @@ -1619,7 +1623,11 @@ int nf_conntrack_init_net(struct net *net)
98882 goto err_stat;
98883 }
98884
98885 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98886 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
98887 +#else
98888 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
98889 +#endif
98890 if (!net->ct.slabname) {
98891 ret = -ENOMEM;
98892 goto err_slabname;
98893 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
98894 index 1df1761..ce8b88a 100644
98895 --- a/net/netfilter/nf_conntrack_ecache.c
98896 +++ b/net/netfilter/nf_conntrack_ecache.c
98897 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
98898 #ifdef CONFIG_SYSCTL
98899 static int nf_conntrack_event_init_sysctl(struct net *net)
98900 {
98901 - struct ctl_table *table;
98902 + ctl_table_no_const *table;
98903
98904 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
98905 GFP_KERNEL);
98906 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
98907 index 974a2a4..52cc6ff 100644
98908 --- a/net/netfilter/nf_conntrack_helper.c
98909 +++ b/net/netfilter/nf_conntrack_helper.c
98910 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
98911
98912 static int nf_conntrack_helper_init_sysctl(struct net *net)
98913 {
98914 - struct ctl_table *table;
98915 + ctl_table_no_const *table;
98916
98917 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
98918 GFP_KERNEL);
98919 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
98920 index ce30041..3861b5d 100644
98921 --- a/net/netfilter/nf_conntrack_proto.c
98922 +++ b/net/netfilter/nf_conntrack_proto.c
98923 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
98924
98925 static void
98926 nf_ct_unregister_sysctl(struct ctl_table_header **header,
98927 - struct ctl_table **table,
98928 + ctl_table_no_const **table,
98929 unsigned int users)
98930 {
98931 if (users > 0)
98932 diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
98933 index a99b6c3..cb372f9 100644
98934 --- a/net/netfilter/nf_conntrack_proto_dccp.c
98935 +++ b/net/netfilter/nf_conntrack_proto_dccp.c
98936 @@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
98937 const char *msg;
98938 u_int8_t state;
98939
98940 - dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
98941 + dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
98942 BUG_ON(dh == NULL);
98943
98944 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
98945 @@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
98946 out_invalid:
98947 if (LOG_INVALID(net, IPPROTO_DCCP))
98948 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
98949 - NULL, msg);
98950 + NULL, "%s", msg);
98951 return false;
98952 }
98953
98954 @@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
98955 u_int8_t type, old_state, new_state;
98956 enum ct_dccp_roles role;
98957
98958 - dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
98959 + dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
98960 BUG_ON(dh == NULL);
98961 type = dh->dccph_type;
98962
98963 @@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
98964 unsigned int cscov;
98965 const char *msg;
98966
98967 - dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
98968 + dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
98969 if (dh == NULL) {
98970 msg = "nf_ct_dccp: short packet ";
98971 goto out_invalid;
98972 @@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
98973
98974 out_invalid:
98975 if (LOG_INVALID(net, IPPROTO_DCCP))
98976 - nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
98977 + nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
98978 return -NF_ACCEPT;
98979 }
98980
98981 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
98982 index f641751..d3c5b51 100644
98983 --- a/net/netfilter/nf_conntrack_standalone.c
98984 +++ b/net/netfilter/nf_conntrack_standalone.c
98985 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
98986
98987 static int nf_conntrack_standalone_init_sysctl(struct net *net)
98988 {
98989 - struct ctl_table *table;
98990 + ctl_table_no_const *table;
98991
98992 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
98993 GFP_KERNEL);
98994 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
98995 index 7a394df..bd91a8a 100644
98996 --- a/net/netfilter/nf_conntrack_timestamp.c
98997 +++ b/net/netfilter/nf_conntrack_timestamp.c
98998 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
98999 #ifdef CONFIG_SYSCTL
99000 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
99001 {
99002 - struct ctl_table *table;
99003 + ctl_table_no_const *table;
99004
99005 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
99006 GFP_KERNEL);
99007 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
99008 index 85296d4..8becdec 100644
99009 --- a/net/netfilter/nf_log.c
99010 +++ b/net/netfilter/nf_log.c
99011 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
99012
99013 #ifdef CONFIG_SYSCTL
99014 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
99015 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
99016 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
99017
99018 static int nf_log_proc_dostring(struct ctl_table *table, int write,
99019 void __user *buffer, size_t *lenp, loff_t *ppos)
99020 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
99021 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
99022 mutex_unlock(&nf_log_mutex);
99023 } else {
99024 + ctl_table_no_const nf_log_table = *table;
99025 +
99026 mutex_lock(&nf_log_mutex);
99027 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
99028 lockdep_is_held(&nf_log_mutex));
99029 if (!logger)
99030 - table->data = "NONE";
99031 + nf_log_table.data = "NONE";
99032 else
99033 - table->data = logger->name;
99034 - r = proc_dostring(table, write, buffer, lenp, ppos);
99035 + nf_log_table.data = logger->name;
99036 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
99037 mutex_unlock(&nf_log_mutex);
99038 }
99039
99040 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
99041 index f042ae5..30ea486 100644
99042 --- a/net/netfilter/nf_sockopt.c
99043 +++ b/net/netfilter/nf_sockopt.c
99044 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
99045 }
99046 }
99047
99048 - list_add(&reg->list, &nf_sockopts);
99049 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
99050 out:
99051 mutex_unlock(&nf_sockopt_mutex);
99052 return ret;
99053 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
99054 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
99055 {
99056 mutex_lock(&nf_sockopt_mutex);
99057 - list_del(&reg->list);
99058 + pax_list_del((struct list_head *)&reg->list);
99059 mutex_unlock(&nf_sockopt_mutex);
99060 }
99061 EXPORT_SYMBOL(nf_unregister_sockopt);
99062 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
99063 index a155d19..726b0f2 100644
99064 --- a/net/netfilter/nfnetlink_log.c
99065 +++ b/net/netfilter/nfnetlink_log.c
99066 @@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
99067 struct nfnl_log_net {
99068 spinlock_t instances_lock;
99069 struct hlist_head instance_table[INSTANCE_BUCKETS];
99070 - atomic_t global_seq;
99071 + atomic_unchecked_t global_seq;
99072 };
99073
99074 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
99075 @@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
99076 /* global sequence number */
99077 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
99078 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
99079 - htonl(atomic_inc_return(&log->global_seq))))
99080 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
99081 goto nla_put_failure;
99082
99083 if (data_len) {
99084 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
99085 index da0c1f4..f79737a 100644
99086 --- a/net/netfilter/nft_compat.c
99087 +++ b/net/netfilter/nft_compat.c
99088 @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
99089 /* We want to reuse existing compat_to_user */
99090 old_fs = get_fs();
99091 set_fs(KERNEL_DS);
99092 - t->compat_to_user(out, in);
99093 + t->compat_to_user((void __force_user *)out, in);
99094 set_fs(old_fs);
99095 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
99096 kfree(out);
99097 @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
99098 /* We want to reuse existing compat_to_user */
99099 old_fs = get_fs();
99100 set_fs(KERNEL_DS);
99101 - m->compat_to_user(out, in);
99102 + m->compat_to_user((void __force_user *)out, in);
99103 set_fs(old_fs);
99104 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
99105 kfree(out);
99106 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
99107 new file mode 100644
99108 index 0000000..c566332
99109 --- /dev/null
99110 +++ b/net/netfilter/xt_gradm.c
99111 @@ -0,0 +1,51 @@
99112 +/*
99113 + * gradm match for netfilter
99114 + * Copyright © Zbigniew Krzystolik, 2010
99115 + *
99116 + * This program is free software; you can redistribute it and/or modify
99117 + * it under the terms of the GNU General Public License; either version
99118 + * 2 or 3 as published by the Free Software Foundation.
99119 + */
99120 +#include <linux/module.h>
99121 +#include <linux/moduleparam.h>
99122 +#include <linux/skbuff.h>
99123 +#include <linux/netfilter/x_tables.h>
99124 +#include <linux/grsecurity.h>
99125 +#include <linux/netfilter/xt_gradm.h>
99126 +
99127 +static bool
99128 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
99129 +{
99130 + const struct xt_gradm_mtinfo *info = par->matchinfo;
99131 + bool retval = false;
99132 + if (gr_acl_is_enabled())
99133 + retval = true;
99134 + return retval ^ info->invflags;
99135 +}
99136 +
99137 +static struct xt_match gradm_mt_reg __read_mostly = {
99138 + .name = "gradm",
99139 + .revision = 0,
99140 + .family = NFPROTO_UNSPEC,
99141 + .match = gradm_mt,
99142 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
99143 + .me = THIS_MODULE,
99144 +};
99145 +
99146 +static int __init gradm_mt_init(void)
99147 +{
99148 + return xt_register_match(&gradm_mt_reg);
99149 +}
99150 +
99151 +static void __exit gradm_mt_exit(void)
99152 +{
99153 + xt_unregister_match(&gradm_mt_reg);
99154 +}
99155 +
99156 +module_init(gradm_mt_init);
99157 +module_exit(gradm_mt_exit);
99158 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
99159 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
99160 +MODULE_LICENSE("GPL");
99161 +MODULE_ALIAS("ipt_gradm");
99162 +MODULE_ALIAS("ip6t_gradm");
99163 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
99164 index 4fe4fb4..87a89e5 100644
99165 --- a/net/netfilter/xt_statistic.c
99166 +++ b/net/netfilter/xt_statistic.c
99167 @@ -19,7 +19,7 @@
99168 #include <linux/module.h>
99169
99170 struct xt_statistic_priv {
99171 - atomic_t count;
99172 + atomic_unchecked_t count;
99173 } ____cacheline_aligned_in_smp;
99174
99175 MODULE_LICENSE("GPL");
99176 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
99177 break;
99178 case XT_STATISTIC_MODE_NTH:
99179 do {
99180 - oval = atomic_read(&info->master->count);
99181 + oval = atomic_read_unchecked(&info->master->count);
99182 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
99183 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
99184 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
99185 if (nval == 0)
99186 ret = !ret;
99187 break;
99188 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
99189 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
99190 if (info->master == NULL)
99191 return -ENOMEM;
99192 - atomic_set(&info->master->count, info->u.nth.count);
99193 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
99194
99195 return 0;
99196 }
99197 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
99198 index bca50b9..8f8a85e 100644
99199 --- a/net/netlink/af_netlink.c
99200 +++ b/net/netlink/af_netlink.c
99201 @@ -249,7 +249,7 @@ static void netlink_overrun(struct sock *sk)
99202 sk->sk_error_report(sk);
99203 }
99204 }
99205 - atomic_inc(&sk->sk_drops);
99206 + atomic_inc_unchecked(&sk->sk_drops);
99207 }
99208
99209 static void netlink_rcv_wake(struct sock *sk)
99210 @@ -2940,7 +2940,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
99211 sk_wmem_alloc_get(s),
99212 nlk->cb_running,
99213 atomic_read(&s->sk_refcnt),
99214 - atomic_read(&s->sk_drops),
99215 + atomic_read_unchecked(&s->sk_drops),
99216 sock_i_ino(s)
99217 );
99218
99219 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
99220 index 53c19a3..b0ac04a 100644
99221 --- a/net/netrom/af_netrom.c
99222 +++ b/net/netrom/af_netrom.c
99223 @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
99224 *uaddr_len = sizeof(struct full_sockaddr_ax25);
99225 } else {
99226 sax->fsa_ax25.sax25_family = AF_NETROM;
99227 - sax->fsa_ax25.sax25_ndigis = 0;
99228 sax->fsa_ax25.sax25_call = nr->source_addr;
99229 *uaddr_len = sizeof(struct sockaddr_ax25);
99230 }
99231 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
99232 index 88cfbc1..05d73f5 100644
99233 --- a/net/packet/af_packet.c
99234 +++ b/net/packet/af_packet.c
99235 @@ -1720,7 +1720,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
99236
99237 spin_lock(&sk->sk_receive_queue.lock);
99238 po->stats.stats1.tp_packets++;
99239 - skb->dropcount = atomic_read(&sk->sk_drops);
99240 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
99241 __skb_queue_tail(&sk->sk_receive_queue, skb);
99242 spin_unlock(&sk->sk_receive_queue.lock);
99243 sk->sk_data_ready(sk, skb->len);
99244 @@ -1729,7 +1729,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
99245 drop_n_acct:
99246 spin_lock(&sk->sk_receive_queue.lock);
99247 po->stats.stats1.tp_drops++;
99248 - atomic_inc(&sk->sk_drops);
99249 + atomic_inc_unchecked(&sk->sk_drops);
99250 spin_unlock(&sk->sk_receive_queue.lock);
99251
99252 drop_n_restore:
99253 @@ -3275,7 +3275,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
99254 case PACKET_HDRLEN:
99255 if (len > sizeof(int))
99256 len = sizeof(int);
99257 - if (copy_from_user(&val, optval, len))
99258 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
99259 return -EFAULT;
99260 switch (val) {
99261 case TPACKET_V1:
99262 @@ -3318,7 +3318,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
99263 len = lv;
99264 if (put_user(len, optlen))
99265 return -EFAULT;
99266 - if (copy_to_user(optval, data, len))
99267 + if (len > sizeof(st) || copy_to_user(optval, data, len))
99268 return -EFAULT;
99269 return 0;
99270 }
99271 diff --git a/net/phonet/datagram.c b/net/phonet/datagram.c
99272 index 38946b2..12c30f3 100644
99273 --- a/net/phonet/datagram.c
99274 +++ b/net/phonet/datagram.c
99275 @@ -139,6 +139,9 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
99276 MSG_CMSG_COMPAT))
99277 goto out_nofree;
99278
99279 + if (addr_len)
99280 + *addr_len = sizeof(sa);
99281 +
99282 skb = skb_recv_datagram(sk, flags, noblock, &rval);
99283 if (skb == NULL)
99284 goto out_nofree;
99285 @@ -159,10 +162,8 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
99286
99287 rval = (flags & MSG_TRUNC) ? skb->len : copylen;
99288
99289 - if (msg->msg_name != NULL) {
99290 - memcpy(msg->msg_name, &sa, sizeof(sa));
99291 - *addr_len = sizeof(sa);
99292 - }
99293 + if (msg->msg_name != NULL)
99294 + memcpy(msg->msg_name, &sa, sizeof(struct sockaddr_pn));
99295
99296 out:
99297 skb_free_datagram(sk, skb);
99298 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
99299 index e774117..900b8b7 100644
99300 --- a/net/phonet/pep.c
99301 +++ b/net/phonet/pep.c
99302 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
99303
99304 case PNS_PEP_CTRL_REQ:
99305 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
99306 - atomic_inc(&sk->sk_drops);
99307 + atomic_inc_unchecked(&sk->sk_drops);
99308 break;
99309 }
99310 __skb_pull(skb, 4);
99311 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
99312 }
99313
99314 if (pn->rx_credits == 0) {
99315 - atomic_inc(&sk->sk_drops);
99316 + atomic_inc_unchecked(&sk->sk_drops);
99317 err = -ENOBUFS;
99318 break;
99319 }
99320 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
99321 }
99322
99323 if (pn->rx_credits == 0) {
99324 - atomic_inc(&sk->sk_drops);
99325 + atomic_inc_unchecked(&sk->sk_drops);
99326 err = NET_RX_DROP;
99327 break;
99328 }
99329 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
99330 index 008214a..bb68240 100644
99331 --- a/net/phonet/socket.c
99332 +++ b/net/phonet/socket.c
99333 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
99334 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
99335 sock_i_ino(sk),
99336 atomic_read(&sk->sk_refcnt), sk,
99337 - atomic_read(&sk->sk_drops));
99338 + atomic_read_unchecked(&sk->sk_drops));
99339 }
99340 seq_pad(seq, '\n');
99341 return 0;
99342 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
99343 index c02a8c4..3c5b600 100644
99344 --- a/net/phonet/sysctl.c
99345 +++ b/net/phonet/sysctl.c
99346 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
99347 {
99348 int ret;
99349 int range[2] = {local_port_range[0], local_port_range[1]};
99350 - struct ctl_table tmp = {
99351 + ctl_table_no_const tmp = {
99352 .data = &range,
99353 .maxlen = sizeof(range),
99354 .mode = table->mode,
99355 diff --git a/net/rds/cong.c b/net/rds/cong.c
99356 index e5b65ac..f3b6fb7 100644
99357 --- a/net/rds/cong.c
99358 +++ b/net/rds/cong.c
99359 @@ -78,7 +78,7 @@
99360 * finds that the saved generation number is smaller than the global generation
99361 * number, it wakes up the process.
99362 */
99363 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
99364 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
99365
99366 /*
99367 * Congestion monitoring
99368 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
99369 rdsdebug("waking map %p for %pI4\n",
99370 map, &map->m_addr);
99371 rds_stats_inc(s_cong_update_received);
99372 - atomic_inc(&rds_cong_generation);
99373 + atomic_inc_unchecked(&rds_cong_generation);
99374 if (waitqueue_active(&map->m_waitq))
99375 wake_up(&map->m_waitq);
99376 if (waitqueue_active(&rds_poll_waitq))
99377 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
99378
99379 int rds_cong_updated_since(unsigned long *recent)
99380 {
99381 - unsigned long gen = atomic_read(&rds_cong_generation);
99382 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
99383
99384 if (likely(*recent == gen))
99385 return 0;
99386 diff --git a/net/rds/ib.h b/net/rds/ib.h
99387 index 7280ab8..e04f4ea 100644
99388 --- a/net/rds/ib.h
99389 +++ b/net/rds/ib.h
99390 @@ -128,7 +128,7 @@ struct rds_ib_connection {
99391 /* sending acks */
99392 unsigned long i_ack_flags;
99393 #ifdef KERNEL_HAS_ATOMIC64
99394 - atomic64_t i_ack_next; /* next ACK to send */
99395 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
99396 #else
99397 spinlock_t i_ack_lock; /* protect i_ack_next */
99398 u64 i_ack_next; /* next ACK to send */
99399 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
99400 index 31b74f5..dc1fbfa 100644
99401 --- a/net/rds/ib_cm.c
99402 +++ b/net/rds/ib_cm.c
99403 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
99404 /* Clear the ACK state */
99405 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
99406 #ifdef KERNEL_HAS_ATOMIC64
99407 - atomic64_set(&ic->i_ack_next, 0);
99408 + atomic64_set_unchecked(&ic->i_ack_next, 0);
99409 #else
99410 ic->i_ack_next = 0;
99411 #endif
99412 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
99413 index b7ebe23..b6352f6 100644
99414 --- a/net/rds/ib_recv.c
99415 +++ b/net/rds/ib_recv.c
99416 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
99417 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
99418 int ack_required)
99419 {
99420 - atomic64_set(&ic->i_ack_next, seq);
99421 + atomic64_set_unchecked(&ic->i_ack_next, seq);
99422 if (ack_required) {
99423 smp_mb__before_clear_bit();
99424 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
99425 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
99426 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
99427 smp_mb__after_clear_bit();
99428
99429 - return atomic64_read(&ic->i_ack_next);
99430 + return atomic64_read_unchecked(&ic->i_ack_next);
99431 }
99432 #endif
99433
99434 diff --git a/net/rds/iw.h b/net/rds/iw.h
99435 index 04ce3b1..48119a6 100644
99436 --- a/net/rds/iw.h
99437 +++ b/net/rds/iw.h
99438 @@ -134,7 +134,7 @@ struct rds_iw_connection {
99439 /* sending acks */
99440 unsigned long i_ack_flags;
99441 #ifdef KERNEL_HAS_ATOMIC64
99442 - atomic64_t i_ack_next; /* next ACK to send */
99443 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
99444 #else
99445 spinlock_t i_ack_lock; /* protect i_ack_next */
99446 u64 i_ack_next; /* next ACK to send */
99447 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
99448 index a91e1db..cf3053f 100644
99449 --- a/net/rds/iw_cm.c
99450 +++ b/net/rds/iw_cm.c
99451 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
99452 /* Clear the ACK state */
99453 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
99454 #ifdef KERNEL_HAS_ATOMIC64
99455 - atomic64_set(&ic->i_ack_next, 0);
99456 + atomic64_set_unchecked(&ic->i_ack_next, 0);
99457 #else
99458 ic->i_ack_next = 0;
99459 #endif
99460 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
99461 index 4503335..db566b4 100644
99462 --- a/net/rds/iw_recv.c
99463 +++ b/net/rds/iw_recv.c
99464 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
99465 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
99466 int ack_required)
99467 {
99468 - atomic64_set(&ic->i_ack_next, seq);
99469 + atomic64_set_unchecked(&ic->i_ack_next, seq);
99470 if (ack_required) {
99471 smp_mb__before_clear_bit();
99472 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
99473 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
99474 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
99475 smp_mb__after_clear_bit();
99476
99477 - return atomic64_read(&ic->i_ack_next);
99478 + return atomic64_read_unchecked(&ic->i_ack_next);
99479 }
99480 #endif
99481
99482 diff --git a/net/rds/rds.h b/net/rds/rds.h
99483 index 48f8ffc..0ef3eec 100644
99484 --- a/net/rds/rds.h
99485 +++ b/net/rds/rds.h
99486 @@ -449,7 +449,7 @@ struct rds_transport {
99487 void (*sync_mr)(void *trans_private, int direction);
99488 void (*free_mr)(void *trans_private, int invalidate);
99489 void (*flush_mrs)(void);
99490 -};
99491 +} __do_const;
99492
99493 struct rds_sock {
99494 struct sock rs_sk;
99495 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
99496 index edac9ef..16bcb98 100644
99497 --- a/net/rds/tcp.c
99498 +++ b/net/rds/tcp.c
99499 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
99500 int val = 1;
99501
99502 set_fs(KERNEL_DS);
99503 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
99504 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
99505 sizeof(val));
99506 set_fs(oldfs);
99507 }
99508 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
99509 index 81cf5a4..b5826ff 100644
99510 --- a/net/rds/tcp_send.c
99511 +++ b/net/rds/tcp_send.c
99512 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
99513
99514 oldfs = get_fs();
99515 set_fs(KERNEL_DS);
99516 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
99517 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
99518 sizeof(val));
99519 set_fs(oldfs);
99520 }
99521 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
99522 index e61aa60..f07cc89 100644
99523 --- a/net/rxrpc/af_rxrpc.c
99524 +++ b/net/rxrpc/af_rxrpc.c
99525 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
99526 __be32 rxrpc_epoch;
99527
99528 /* current debugging ID */
99529 -atomic_t rxrpc_debug_id;
99530 +atomic_unchecked_t rxrpc_debug_id;
99531
99532 /* count of skbs currently in use */
99533 atomic_t rxrpc_n_skbs;
99534 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
99535 index e4d9cbc..b229649 100644
99536 --- a/net/rxrpc/ar-ack.c
99537 +++ b/net/rxrpc/ar-ack.c
99538 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
99539
99540 _enter("{%d,%d,%d,%d},",
99541 call->acks_hard, call->acks_unacked,
99542 - atomic_read(&call->sequence),
99543 + atomic_read_unchecked(&call->sequence),
99544 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
99545
99546 stop = 0;
99547 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
99548
99549 /* each Tx packet has a new serial number */
99550 sp->hdr.serial =
99551 - htonl(atomic_inc_return(&call->conn->serial));
99552 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
99553
99554 hdr = (struct rxrpc_header *) txb->head;
99555 hdr->serial = sp->hdr.serial;
99556 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
99557 */
99558 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
99559 {
99560 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
99561 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
99562 }
99563
99564 /*
99565 @@ -629,7 +629,7 @@ process_further:
99566
99567 latest = ntohl(sp->hdr.serial);
99568 hard = ntohl(ack.firstPacket);
99569 - tx = atomic_read(&call->sequence);
99570 + tx = atomic_read_unchecked(&call->sequence);
99571
99572 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
99573 latest,
99574 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
99575 goto maybe_reschedule;
99576
99577 send_ACK_with_skew:
99578 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
99579 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
99580 ntohl(ack.serial));
99581 send_ACK:
99582 mtu = call->conn->trans->peer->if_mtu;
99583 @@ -1173,7 +1173,7 @@ send_ACK:
99584 ackinfo.rxMTU = htonl(5692);
99585 ackinfo.jumbo_max = htonl(4);
99586
99587 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
99588 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
99589 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
99590 ntohl(hdr.serial),
99591 ntohs(ack.maxSkew),
99592 @@ -1191,7 +1191,7 @@ send_ACK:
99593 send_message:
99594 _debug("send message");
99595
99596 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
99597 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
99598 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
99599 send_message_2:
99600
99601 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
99602 index a3bbb36..3341fb9 100644
99603 --- a/net/rxrpc/ar-call.c
99604 +++ b/net/rxrpc/ar-call.c
99605 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
99606 spin_lock_init(&call->lock);
99607 rwlock_init(&call->state_lock);
99608 atomic_set(&call->usage, 1);
99609 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
99610 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99611 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
99612
99613 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
99614 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
99615 index 4106ca9..a338d7a 100644
99616 --- a/net/rxrpc/ar-connection.c
99617 +++ b/net/rxrpc/ar-connection.c
99618 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
99619 rwlock_init(&conn->lock);
99620 spin_lock_init(&conn->state_lock);
99621 atomic_set(&conn->usage, 1);
99622 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
99623 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99624 conn->avail_calls = RXRPC_MAXCALLS;
99625 conn->size_align = 4;
99626 conn->header_size = sizeof(struct rxrpc_header);
99627 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
99628 index e7ed43a..6afa140 100644
99629 --- a/net/rxrpc/ar-connevent.c
99630 +++ b/net/rxrpc/ar-connevent.c
99631 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
99632
99633 len = iov[0].iov_len + iov[1].iov_len;
99634
99635 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
99636 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
99637 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
99638
99639 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
99640 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
99641 index 529572f..c758ca7 100644
99642 --- a/net/rxrpc/ar-input.c
99643 +++ b/net/rxrpc/ar-input.c
99644 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
99645 /* track the latest serial number on this connection for ACK packet
99646 * information */
99647 serial = ntohl(sp->hdr.serial);
99648 - hi_serial = atomic_read(&call->conn->hi_serial);
99649 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
99650 while (serial > hi_serial)
99651 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
99652 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
99653 serial);
99654
99655 /* request ACK generation for any ACK or DATA packet that requests
99656 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
99657 index 5f43675..ca07817 100644
99658 --- a/net/rxrpc/ar-internal.h
99659 +++ b/net/rxrpc/ar-internal.h
99660 @@ -272,8 +272,8 @@ struct rxrpc_connection {
99661 int error; /* error code for local abort */
99662 int debug_id; /* debug ID for printks */
99663 unsigned int call_counter; /* call ID counter */
99664 - atomic_t serial; /* packet serial number counter */
99665 - atomic_t hi_serial; /* highest serial number received */
99666 + atomic_unchecked_t serial; /* packet serial number counter */
99667 + atomic_unchecked_t hi_serial; /* highest serial number received */
99668 u8 avail_calls; /* number of calls available */
99669 u8 size_align; /* data size alignment (for security) */
99670 u8 header_size; /* rxrpc + security header size */
99671 @@ -346,7 +346,7 @@ struct rxrpc_call {
99672 spinlock_t lock;
99673 rwlock_t state_lock; /* lock for state transition */
99674 atomic_t usage;
99675 - atomic_t sequence; /* Tx data packet sequence counter */
99676 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
99677 u32 abort_code; /* local/remote abort code */
99678 enum { /* current state of call */
99679 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
99680 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
99681 */
99682 extern atomic_t rxrpc_n_skbs;
99683 extern __be32 rxrpc_epoch;
99684 -extern atomic_t rxrpc_debug_id;
99685 +extern atomic_unchecked_t rxrpc_debug_id;
99686 extern struct workqueue_struct *rxrpc_workqueue;
99687
99688 /*
99689 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
99690 index 87f7135..74d3703 100644
99691 --- a/net/rxrpc/ar-local.c
99692 +++ b/net/rxrpc/ar-local.c
99693 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
99694 spin_lock_init(&local->lock);
99695 rwlock_init(&local->services_lock);
99696 atomic_set(&local->usage, 1);
99697 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
99698 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99699 memcpy(&local->srx, srx, sizeof(*srx));
99700 }
99701
99702 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
99703 index e1ac183..b43e10e 100644
99704 --- a/net/rxrpc/ar-output.c
99705 +++ b/net/rxrpc/ar-output.c
99706 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
99707 sp->hdr.cid = call->cid;
99708 sp->hdr.callNumber = call->call_id;
99709 sp->hdr.seq =
99710 - htonl(atomic_inc_return(&call->sequence));
99711 + htonl(atomic_inc_return_unchecked(&call->sequence));
99712 sp->hdr.serial =
99713 - htonl(atomic_inc_return(&conn->serial));
99714 + htonl(atomic_inc_return_unchecked(&conn->serial));
99715 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
99716 sp->hdr.userStatus = 0;
99717 sp->hdr.securityIndex = conn->security_ix;
99718 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
99719 index bebaa43..2644591 100644
99720 --- a/net/rxrpc/ar-peer.c
99721 +++ b/net/rxrpc/ar-peer.c
99722 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
99723 INIT_LIST_HEAD(&peer->error_targets);
99724 spin_lock_init(&peer->lock);
99725 atomic_set(&peer->usage, 1);
99726 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
99727 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99728 memcpy(&peer->srx, srx, sizeof(*srx));
99729
99730 rxrpc_assess_MTU_size(peer);
99731 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
99732 index 38047f7..9f48511 100644
99733 --- a/net/rxrpc/ar-proc.c
99734 +++ b/net/rxrpc/ar-proc.c
99735 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
99736 atomic_read(&conn->usage),
99737 rxrpc_conn_states[conn->state],
99738 key_serial(conn->key),
99739 - atomic_read(&conn->serial),
99740 - atomic_read(&conn->hi_serial));
99741 + atomic_read_unchecked(&conn->serial),
99742 + atomic_read_unchecked(&conn->hi_serial));
99743
99744 return 0;
99745 }
99746 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
99747 index 92df566..87ec1bf 100644
99748 --- a/net/rxrpc/ar-transport.c
99749 +++ b/net/rxrpc/ar-transport.c
99750 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
99751 spin_lock_init(&trans->client_lock);
99752 rwlock_init(&trans->conn_lock);
99753 atomic_set(&trans->usage, 1);
99754 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
99755 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99756
99757 if (peer->srx.transport.family == AF_INET) {
99758 switch (peer->srx.transport_type) {
99759 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
99760 index f226709..0e735a8 100644
99761 --- a/net/rxrpc/rxkad.c
99762 +++ b/net/rxrpc/rxkad.c
99763 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
99764
99765 len = iov[0].iov_len + iov[1].iov_len;
99766
99767 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
99768 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
99769 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
99770
99771 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
99772 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
99773
99774 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
99775
99776 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
99777 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
99778 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
99779
99780 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
99781 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
99782 index 7567e6f..299382b 100644
99783 --- a/net/sctp/ipv6.c
99784 +++ b/net/sctp/ipv6.c
99785 @@ -964,7 +964,7 @@ static const struct inet6_protocol sctpv6_protocol = {
99786 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
99787 };
99788
99789 -static struct sctp_af sctp_af_inet6 = {
99790 +static struct sctp_af sctp_af_inet6 __read_only = {
99791 .sa_family = AF_INET6,
99792 .sctp_xmit = sctp_v6_xmit,
99793 .setsockopt = ipv6_setsockopt,
99794 @@ -996,7 +996,7 @@ static struct sctp_af sctp_af_inet6 = {
99795 #endif
99796 };
99797
99798 -static struct sctp_pf sctp_pf_inet6 = {
99799 +static struct sctp_pf sctp_pf_inet6 __read_only = {
99800 .event_msgname = sctp_inet6_event_msgname,
99801 .skb_msgname = sctp_inet6_skb_msgname,
99802 .af_supported = sctp_inet6_af_supported,
99803 @@ -1021,7 +1021,7 @@ void sctp_v6_pf_init(void)
99804
99805 void sctp_v6_pf_exit(void)
99806 {
99807 - list_del(&sctp_af_inet6.list);
99808 + pax_list_del(&sctp_af_inet6.list);
99809 }
99810
99811 /* Initialize IPv6 support and register with socket layer. */
99812 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
99813 index 5e17092..19be1d4 100644
99814 --- a/net/sctp/protocol.c
99815 +++ b/net/sctp/protocol.c
99816 @@ -832,8 +832,10 @@ int sctp_register_af(struct sctp_af *af)
99817 return 0;
99818 }
99819
99820 + pax_open_kernel();
99821 INIT_LIST_HEAD(&af->list);
99822 - list_add_tail(&af->list, &sctp_address_families);
99823 + pax_close_kernel();
99824 + pax_list_add_tail(&af->list, &sctp_address_families);
99825 return 1;
99826 }
99827
99828 @@ -963,7 +965,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
99829
99830 static struct sctp_af sctp_af_inet;
99831
99832 -static struct sctp_pf sctp_pf_inet = {
99833 +static struct sctp_pf sctp_pf_inet __read_only = {
99834 .event_msgname = sctp_inet_event_msgname,
99835 .skb_msgname = sctp_inet_skb_msgname,
99836 .af_supported = sctp_inet_af_supported,
99837 @@ -1034,7 +1036,7 @@ static const struct net_protocol sctp_protocol = {
99838 };
99839
99840 /* IPv4 address related functions. */
99841 -static struct sctp_af sctp_af_inet = {
99842 +static struct sctp_af sctp_af_inet __read_only = {
99843 .sa_family = AF_INET,
99844 .sctp_xmit = sctp_v4_xmit,
99845 .setsockopt = ip_setsockopt,
99846 @@ -1119,7 +1121,7 @@ static void sctp_v4_pf_init(void)
99847
99848 static void sctp_v4_pf_exit(void)
99849 {
99850 - list_del(&sctp_af_inet.list);
99851 + pax_list_del(&sctp_af_inet.list);
99852 }
99853
99854 static int sctp_v4_protosw_init(void)
99855 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
99856 index 1a6eef3..17e898f 100644
99857 --- a/net/sctp/sm_sideeffect.c
99858 +++ b/net/sctp/sm_sideeffect.c
99859 @@ -440,7 +440,7 @@ static void sctp_generate_sack_event(unsigned long data)
99860 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
99861 }
99862
99863 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
99864 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
99865 NULL,
99866 sctp_generate_t1_cookie_event,
99867 sctp_generate_t1_init_event,
99868 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
99869 index 42b709c..e7d09ac 100644
99870 --- a/net/sctp/socket.c
99871 +++ b/net/sctp/socket.c
99872 @@ -2153,11 +2153,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
99873 {
99874 struct sctp_association *asoc;
99875 struct sctp_ulpevent *event;
99876 + struct sctp_event_subscribe subscribe;
99877
99878 if (optlen > sizeof(struct sctp_event_subscribe))
99879 return -EINVAL;
99880 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
99881 + if (copy_from_user(&subscribe, optval, optlen))
99882 return -EFAULT;
99883 + sctp_sk(sk)->subscribe = subscribe;
99884
99885 /*
99886 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
99887 @@ -4229,13 +4231,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
99888 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
99889 int __user *optlen)
99890 {
99891 + struct sctp_event_subscribe subscribe;
99892 +
99893 if (len <= 0)
99894 return -EINVAL;
99895 if (len > sizeof(struct sctp_event_subscribe))
99896 len = sizeof(struct sctp_event_subscribe);
99897 if (put_user(len, optlen))
99898 return -EFAULT;
99899 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
99900 + subscribe = sctp_sk(sk)->subscribe;
99901 + if (copy_to_user(optval, &subscribe, len))
99902 return -EFAULT;
99903 return 0;
99904 }
99905 @@ -4253,6 +4258,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
99906 */
99907 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
99908 {
99909 + __u32 autoclose;
99910 +
99911 /* Applicable to UDP-style socket only */
99912 if (sctp_style(sk, TCP))
99913 return -EOPNOTSUPP;
99914 @@ -4261,7 +4268,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
99915 len = sizeof(int);
99916 if (put_user(len, optlen))
99917 return -EFAULT;
99918 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
99919 + autoclose = sctp_sk(sk)->autoclose;
99920 + if (copy_to_user(optval, &autoclose, sizeof(int)))
99921 return -EFAULT;
99922 return 0;
99923 }
99924 @@ -4633,12 +4641,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
99925 */
99926 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
99927 {
99928 + struct sctp_initmsg initmsg;
99929 +
99930 if (len < sizeof(struct sctp_initmsg))
99931 return -EINVAL;
99932 len = sizeof(struct sctp_initmsg);
99933 if (put_user(len, optlen))
99934 return -EFAULT;
99935 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
99936 + initmsg = sctp_sk(sk)->initmsg;
99937 + if (copy_to_user(optval, &initmsg, len))
99938 return -EFAULT;
99939 return 0;
99940 }
99941 @@ -4679,6 +4690,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
99942 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
99943 if (space_left < addrlen)
99944 return -ENOMEM;
99945 + if (addrlen > sizeof(temp) || addrlen < 0)
99946 + return -EFAULT;
99947 if (copy_to_user(to, &temp, addrlen))
99948 return -EFAULT;
99949 to += addrlen;
99950 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
99951 index b0565af..d135e6e 100644
99952 --- a/net/sctp/sysctl.c
99953 +++ b/net/sctp/sysctl.c
99954 @@ -305,7 +305,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
99955 {
99956 struct net *net = current->nsproxy->net_ns;
99957 char tmp[8];
99958 - struct ctl_table tbl;
99959 + ctl_table_no_const tbl;
99960 int ret;
99961 int changed = 0;
99962 char *none = "none";
99963 @@ -352,7 +352,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
99964 {
99965 struct net *net = current->nsproxy->net_ns;
99966 int new_value;
99967 - struct ctl_table tbl;
99968 + ctl_table_no_const tbl;
99969 unsigned int min = *(unsigned int *) ctl->extra1;
99970 unsigned int max = *(unsigned int *) ctl->extra2;
99971 int ret;
99972 @@ -379,7 +379,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
99973 {
99974 struct net *net = current->nsproxy->net_ns;
99975 int new_value;
99976 - struct ctl_table tbl;
99977 + ctl_table_no_const tbl;
99978 unsigned int min = *(unsigned int *) ctl->extra1;
99979 unsigned int max = *(unsigned int *) ctl->extra2;
99980 int ret;
99981 @@ -402,7 +402,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
99982
99983 int sctp_sysctl_net_register(struct net *net)
99984 {
99985 - struct ctl_table *table;
99986 + ctl_table_no_const *table;
99987 int i;
99988
99989 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
99990 diff --git a/net/socket.c b/net/socket.c
99991 index e83c416..1094d88 100644
99992 --- a/net/socket.c
99993 +++ b/net/socket.c
99994 @@ -88,6 +88,7 @@
99995 #include <linux/magic.h>
99996 #include <linux/slab.h>
99997 #include <linux/xattr.h>
99998 +#include <linux/in.h>
99999
100000 #include <asm/uaccess.h>
100001 #include <asm/unistd.h>
100002 @@ -111,6 +112,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
100003 unsigned int sysctl_net_busy_poll __read_mostly;
100004 #endif
100005
100006 +#include <linux/grsock.h>
100007 +
100008 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
100009 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
100010 unsigned long nr_segs, loff_t pos);
100011 @@ -162,7 +165,7 @@ static const struct file_operations socket_file_ops = {
100012 */
100013
100014 static DEFINE_SPINLOCK(net_family_lock);
100015 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
100016 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
100017
100018 /*
100019 * Statistics counters of the socket lists
100020 @@ -328,7 +331,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
100021 &sockfs_dentry_operations, SOCKFS_MAGIC);
100022 }
100023
100024 -static struct vfsmount *sock_mnt __read_mostly;
100025 +struct vfsmount *sock_mnt __read_mostly;
100026
100027 static struct file_system_type sock_fs_type = {
100028 .name = "sockfs",
100029 @@ -1255,6 +1258,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
100030 return -EAFNOSUPPORT;
100031 if (type < 0 || type >= SOCK_MAX)
100032 return -EINVAL;
100033 + if (protocol < 0)
100034 + return -EINVAL;
100035
100036 /* Compatibility.
100037
100038 @@ -1275,6 +1280,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
100039 if (err)
100040 return err;
100041
100042 + if(!kern && !gr_search_socket(family, type, protocol)) {
100043 + if (rcu_access_pointer(net_families[family]) == NULL)
100044 + return -EAFNOSUPPORT;
100045 + else
100046 + return -EACCES;
100047 + }
100048 +
100049 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
100050 + if (rcu_access_pointer(net_families[family]) == NULL)
100051 + return -EAFNOSUPPORT;
100052 + else
100053 + return -EACCES;
100054 + }
100055 +
100056 /*
100057 * Allocate the socket and allow the family to set things up. if
100058 * the protocol is 0, the family is instructed to select an appropriate
100059 @@ -1513,6 +1532,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
100060 if (sock) {
100061 err = move_addr_to_kernel(umyaddr, addrlen, &address);
100062 if (err >= 0) {
100063 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
100064 + err = -EACCES;
100065 + goto error;
100066 + }
100067 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
100068 + if (err)
100069 + goto error;
100070 +
100071 err = security_socket_bind(sock,
100072 (struct sockaddr *)&address,
100073 addrlen);
100074 @@ -1521,6 +1548,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
100075 (struct sockaddr *)
100076 &address, addrlen);
100077 }
100078 +error:
100079 fput_light(sock->file, fput_needed);
100080 }
100081 return err;
100082 @@ -1544,10 +1572,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
100083 if ((unsigned int)backlog > somaxconn)
100084 backlog = somaxconn;
100085
100086 + if (gr_handle_sock_server_other(sock->sk)) {
100087 + err = -EPERM;
100088 + goto error;
100089 + }
100090 +
100091 + err = gr_search_listen(sock);
100092 + if (err)
100093 + goto error;
100094 +
100095 err = security_socket_listen(sock, backlog);
100096 if (!err)
100097 err = sock->ops->listen(sock, backlog);
100098
100099 +error:
100100 fput_light(sock->file, fput_needed);
100101 }
100102 return err;
100103 @@ -1591,6 +1629,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
100104 newsock->type = sock->type;
100105 newsock->ops = sock->ops;
100106
100107 + if (gr_handle_sock_server_other(sock->sk)) {
100108 + err = -EPERM;
100109 + sock_release(newsock);
100110 + goto out_put;
100111 + }
100112 +
100113 + err = gr_search_accept(sock);
100114 + if (err) {
100115 + sock_release(newsock);
100116 + goto out_put;
100117 + }
100118 +
100119 /*
100120 * We don't need try_module_get here, as the listening socket (sock)
100121 * has the protocol module (sock->ops->owner) held.
100122 @@ -1636,6 +1686,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
100123 fd_install(newfd, newfile);
100124 err = newfd;
100125
100126 + gr_attach_curr_ip(newsock->sk);
100127 +
100128 out_put:
100129 fput_light(sock->file, fput_needed);
100130 out:
100131 @@ -1668,6 +1720,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
100132 int, addrlen)
100133 {
100134 struct socket *sock;
100135 + struct sockaddr *sck;
100136 struct sockaddr_storage address;
100137 int err, fput_needed;
100138
100139 @@ -1678,6 +1731,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
100140 if (err < 0)
100141 goto out_put;
100142
100143 + sck = (struct sockaddr *)&address;
100144 +
100145 + if (gr_handle_sock_client(sck)) {
100146 + err = -EACCES;
100147 + goto out_put;
100148 + }
100149 +
100150 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
100151 + if (err)
100152 + goto out_put;
100153 +
100154 err =
100155 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
100156 if (err)
100157 @@ -1759,6 +1823,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
100158 * the protocol.
100159 */
100160
100161 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
100162 +
100163 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
100164 unsigned int, flags, struct sockaddr __user *, addr,
100165 int, addr_len)
100166 @@ -2047,7 +2113,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
100167 * checking falls down on this.
100168 */
100169 if (copy_from_user(ctl_buf,
100170 - (void __user __force *)msg_sys->msg_control,
100171 + (void __force_user *)msg_sys->msg_control,
100172 ctl_len))
100173 goto out_freectl;
100174 msg_sys->msg_control = ctl_buf;
100175 @@ -2227,7 +2293,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
100176 /* Save the user-mode address (verify_iovec will change the
100177 * kernel msghdr to use the kernel address space)
100178 */
100179 - uaddr = (__force void __user *)msg_sys->msg_name;
100180 + uaddr = (void __force_user *)msg_sys->msg_name;
100181 uaddr_len = COMPAT_NAMELEN(msg);
100182 if (MSG_CMSG_COMPAT & flags)
100183 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
100184 @@ -2871,7 +2937,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
100185 ifr = compat_alloc_user_space(buf_size);
100186 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
100187
100188 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
100189 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
100190 return -EFAULT;
100191
100192 if (put_user(convert_in ? rxnfc : compat_ptr(data),
100193 @@ -2985,14 +3051,14 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
100194 old_fs = get_fs();
100195 set_fs(KERNEL_DS);
100196 err = dev_ioctl(net, cmd,
100197 - (struct ifreq __user __force *) &kifr);
100198 + (struct ifreq __force_user *) &kifr);
100199 set_fs(old_fs);
100200
100201 return err;
100202 case SIOCBONDSLAVEINFOQUERY:
100203 case SIOCBONDINFOQUERY:
100204 uifr = compat_alloc_user_space(sizeof(*uifr));
100205 - if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
100206 + if (copy_in_user(uifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
100207 return -EFAULT;
100208
100209 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
100210 @@ -3094,7 +3160,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
100211
100212 old_fs = get_fs();
100213 set_fs(KERNEL_DS);
100214 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
100215 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
100216 set_fs(old_fs);
100217
100218 if (cmd == SIOCGIFMAP && !err) {
100219 @@ -3199,7 +3265,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
100220 ret |= get_user(rtdev, &(ur4->rt_dev));
100221 if (rtdev) {
100222 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
100223 - r4.rt_dev = (char __user __force *)devname;
100224 + r4.rt_dev = (char __force_user *)devname;
100225 devname[15] = 0;
100226 } else
100227 r4.rt_dev = NULL;
100228 @@ -3425,8 +3491,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
100229 int __user *uoptlen;
100230 int err;
100231
100232 - uoptval = (char __user __force *) optval;
100233 - uoptlen = (int __user __force *) optlen;
100234 + uoptval = (char __force_user *) optval;
100235 + uoptlen = (int __force_user *) optlen;
100236
100237 set_fs(KERNEL_DS);
100238 if (level == SOL_SOCKET)
100239 @@ -3446,7 +3512,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
100240 char __user *uoptval;
100241 int err;
100242
100243 - uoptval = (char __user __force *) optval;
100244 + uoptval = (char __force_user *) optval;
100245
100246 set_fs(KERNEL_DS);
100247 if (level == SOL_SOCKET)
100248 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
100249 index 008cdad..6f17474 100644
100250 --- a/net/sunrpc/auth_gss/svcauth_gss.c
100251 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
100252 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
100253 uint64_t *handle)
100254 {
100255 struct rsc rsci, *rscp = NULL;
100256 - static atomic64_t ctxhctr;
100257 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
100258 long long ctxh;
100259 struct gss_api_mech *gm = NULL;
100260 time_t expiry;
100261 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
100262 status = -ENOMEM;
100263 /* the handle needs to be just a unique id,
100264 * use a static counter */
100265 - ctxh = atomic64_inc_return(&ctxhctr);
100266 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
100267
100268 /* make a copy for the caller */
100269 *handle = ctxh;
100270 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
100271 index f09b7db..393c39e 100644
100272 --- a/net/sunrpc/clnt.c
100273 +++ b/net/sunrpc/clnt.c
100274 @@ -1415,7 +1415,9 @@ call_start(struct rpc_task *task)
100275 (RPC_IS_ASYNC(task) ? "async" : "sync"));
100276
100277 /* Increment call count */
100278 - task->tk_msg.rpc_proc->p_count++;
100279 + pax_open_kernel();
100280 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
100281 + pax_close_kernel();
100282 clnt->cl_stats->rpccnt++;
100283 task->tk_action = call_reserve;
100284 }
100285 @@ -1529,9 +1531,13 @@ call_refreshresult(struct rpc_task *task)
100286 task->tk_action = call_refresh;
100287 switch (status) {
100288 case 0:
100289 - if (rpcauth_uptodatecred(task))
100290 + if (rpcauth_uptodatecred(task)) {
100291 task->tk_action = call_allocate;
100292 - return;
100293 + return;
100294 + }
100295 + /* Use rate-limiting and a max number of retries if refresh
100296 + * had status 0 but failed to update the cred.
100297 + */
100298 case -ETIMEDOUT:
100299 rpc_delay(task, 3*HZ);
100300 case -EAGAIN:
100301 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
100302 index ff3cc4b..7612a9e 100644
100303 --- a/net/sunrpc/sched.c
100304 +++ b/net/sunrpc/sched.c
100305 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
100306 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
100307 static void rpc_task_set_debuginfo(struct rpc_task *task)
100308 {
100309 - static atomic_t rpc_pid;
100310 + static atomic_unchecked_t rpc_pid;
100311
100312 - task->tk_pid = atomic_inc_return(&rpc_pid);
100313 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
100314 }
100315 #else
100316 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
100317 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
100318 index e7fbe36..8052603 100644
100319 --- a/net/sunrpc/svc.c
100320 +++ b/net/sunrpc/svc.c
100321 @@ -1158,7 +1158,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
100322 svc_putnl(resv, RPC_SUCCESS);
100323
100324 /* Bump per-procedure stats counter */
100325 - procp->pc_count++;
100326 + pax_open_kernel();
100327 + (*(unsigned int *)&procp->pc_count)++;
100328 + pax_close_kernel();
100329
100330 /* Initialize storage for argp and resp */
100331 memset(rqstp->rq_argp, 0, procp->pc_argsize);
100332 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
100333 index 621ca7b..59421dd 100644
100334 --- a/net/sunrpc/svcauth_unix.c
100335 +++ b/net/sunrpc/svcauth_unix.c
100336 @@ -414,7 +414,7 @@ struct unix_gid {
100337 struct group_info *gi;
100338 };
100339
100340 -static int unix_gid_hash(kuid_t uid)
100341 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
100342 {
100343 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
100344 }
100345 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
100346 (*bpp)[-1] = '\n';
100347 }
100348
100349 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
100350 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
100351
100352 static int unix_gid_parse(struct cache_detail *cd,
100353 char *mesg, int mlen)
100354 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
100355 index c1b6270..05089c1 100644
100356 --- a/net/sunrpc/xprtrdma/svc_rdma.c
100357 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
100358 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
100359 static unsigned int min_max_inline = 4096;
100360 static unsigned int max_max_inline = 65536;
100361
100362 -atomic_t rdma_stat_recv;
100363 -atomic_t rdma_stat_read;
100364 -atomic_t rdma_stat_write;
100365 -atomic_t rdma_stat_sq_starve;
100366 -atomic_t rdma_stat_rq_starve;
100367 -atomic_t rdma_stat_rq_poll;
100368 -atomic_t rdma_stat_rq_prod;
100369 -atomic_t rdma_stat_sq_poll;
100370 -atomic_t rdma_stat_sq_prod;
100371 +atomic_unchecked_t rdma_stat_recv;
100372 +atomic_unchecked_t rdma_stat_read;
100373 +atomic_unchecked_t rdma_stat_write;
100374 +atomic_unchecked_t rdma_stat_sq_starve;
100375 +atomic_unchecked_t rdma_stat_rq_starve;
100376 +atomic_unchecked_t rdma_stat_rq_poll;
100377 +atomic_unchecked_t rdma_stat_rq_prod;
100378 +atomic_unchecked_t rdma_stat_sq_poll;
100379 +atomic_unchecked_t rdma_stat_sq_prod;
100380
100381 /* Temporary NFS request map and context caches */
100382 struct kmem_cache *svc_rdma_map_cachep;
100383 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
100384 len -= *ppos;
100385 if (len > *lenp)
100386 len = *lenp;
100387 - if (len && copy_to_user(buffer, str_buf, len))
100388 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
100389 return -EFAULT;
100390 *lenp = len;
100391 *ppos += len;
100392 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
100393 {
100394 .procname = "rdma_stat_read",
100395 .data = &rdma_stat_read,
100396 - .maxlen = sizeof(atomic_t),
100397 + .maxlen = sizeof(atomic_unchecked_t),
100398 .mode = 0644,
100399 .proc_handler = read_reset_stat,
100400 },
100401 {
100402 .procname = "rdma_stat_recv",
100403 .data = &rdma_stat_recv,
100404 - .maxlen = sizeof(atomic_t),
100405 + .maxlen = sizeof(atomic_unchecked_t),
100406 .mode = 0644,
100407 .proc_handler = read_reset_stat,
100408 },
100409 {
100410 .procname = "rdma_stat_write",
100411 .data = &rdma_stat_write,
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_sq_starve",
100419 .data = &rdma_stat_sq_starve,
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_rq_starve",
100427 .data = &rdma_stat_rq_starve,
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_rq_poll",
100435 .data = &rdma_stat_rq_poll,
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_prod",
100443 .data = &rdma_stat_rq_prod,
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_sq_poll",
100451 .data = &rdma_stat_sq_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_sq_prod",
100459 .data = &rdma_stat_sq_prod,
100460 - .maxlen = sizeof(atomic_t),
100461 + .maxlen = sizeof(atomic_unchecked_t),
100462 .mode = 0644,
100463 .proc_handler = read_reset_stat,
100464 },
100465 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
100466 index 0ce7552..d074459 100644
100467 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
100468 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
100469 @@ -501,7 +501,7 @@ next_sge:
100470 svc_rdma_put_context(ctxt, 0);
100471 goto out;
100472 }
100473 - atomic_inc(&rdma_stat_read);
100474 + atomic_inc_unchecked(&rdma_stat_read);
100475
100476 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
100477 chl_map->ch[ch_no].count -= read_wr.num_sge;
100478 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
100479 dto_q);
100480 list_del_init(&ctxt->dto_q);
100481 } else {
100482 - atomic_inc(&rdma_stat_rq_starve);
100483 + atomic_inc_unchecked(&rdma_stat_rq_starve);
100484 clear_bit(XPT_DATA, &xprt->xpt_flags);
100485 ctxt = NULL;
100486 }
100487 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
100488 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
100489 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
100490 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
100491 - atomic_inc(&rdma_stat_recv);
100492 + atomic_inc_unchecked(&rdma_stat_recv);
100493
100494 /* Build up the XDR from the receive buffers. */
100495 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
100496 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
100497 index c1d124d..acfc59e 100644
100498 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
100499 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
100500 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
100501 write_wr.wr.rdma.remote_addr = to;
100502
100503 /* Post It */
100504 - atomic_inc(&rdma_stat_write);
100505 + atomic_inc_unchecked(&rdma_stat_write);
100506 if (svc_rdma_send(xprt, &write_wr))
100507 goto err;
100508 return 0;
100509 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
100510 index 62e4f9b..dd3f2d7 100644
100511 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
100512 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
100513 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
100514 return;
100515
100516 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
100517 - atomic_inc(&rdma_stat_rq_poll);
100518 + atomic_inc_unchecked(&rdma_stat_rq_poll);
100519
100520 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
100521 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
100522 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
100523 }
100524
100525 if (ctxt)
100526 - atomic_inc(&rdma_stat_rq_prod);
100527 + atomic_inc_unchecked(&rdma_stat_rq_prod);
100528
100529 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
100530 /*
100531 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
100532 return;
100533
100534 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
100535 - atomic_inc(&rdma_stat_sq_poll);
100536 + atomic_inc_unchecked(&rdma_stat_sq_poll);
100537 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
100538 if (wc.status != IB_WC_SUCCESS)
100539 /* Close the transport */
100540 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
100541 }
100542
100543 if (ctxt)
100544 - atomic_inc(&rdma_stat_sq_prod);
100545 + atomic_inc_unchecked(&rdma_stat_sq_prod);
100546 }
100547
100548 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
100549 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
100550 spin_lock_bh(&xprt->sc_lock);
100551 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
100552 spin_unlock_bh(&xprt->sc_lock);
100553 - atomic_inc(&rdma_stat_sq_starve);
100554 + atomic_inc_unchecked(&rdma_stat_sq_starve);
100555
100556 /* See if we can opportunistically reap SQ WR to make room */
100557 sq_cq_reap(xprt);
100558 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
100559 index e7000be..e3b0ba7 100644
100560 --- a/net/sysctl_net.c
100561 +++ b/net/sysctl_net.c
100562 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
100563 kgid_t root_gid = make_kgid(net->user_ns, 0);
100564
100565 /* Allow network administrator to have same access as root. */
100566 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
100567 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
100568 uid_eq(root_uid, current_euid())) {
100569 int mode = (table->mode >> 6) & 7;
100570 return (mode << 6) | (mode << 3) | mode;
100571 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
100572 index d38bb45..38d5df5 100644
100573 --- a/net/tipc/subscr.c
100574 +++ b/net/tipc/subscr.c
100575 @@ -98,7 +98,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
100576 struct kvec msg_sect;
100577 int ret;
100578
100579 - msg_sect.iov_base = (void *)&sub->evt;
100580 + msg_sect.iov_base = &sub->evt;
100581 msg_sect.iov_len = sizeof(struct tipc_event);
100582
100583 sub->evt.event = htohl(event, sub->swap);
100584 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
100585 index a427623..387c80b 100644
100586 --- a/net/unix/af_unix.c
100587 +++ b/net/unix/af_unix.c
100588 @@ -790,6 +790,12 @@ static struct sock *unix_find_other(struct net *net,
100589 err = -ECONNREFUSED;
100590 if (!S_ISSOCK(inode->i_mode))
100591 goto put_fail;
100592 +
100593 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
100594 + err = -EACCES;
100595 + goto put_fail;
100596 + }
100597 +
100598 u = unix_find_socket_byinode(inode);
100599 if (!u)
100600 goto put_fail;
100601 @@ -810,6 +816,13 @@ static struct sock *unix_find_other(struct net *net,
100602 if (u) {
100603 struct dentry *dentry;
100604 dentry = unix_sk(u)->path.dentry;
100605 +
100606 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
100607 + err = -EPERM;
100608 + sock_put(u);
100609 + goto fail;
100610 + }
100611 +
100612 if (dentry)
100613 touch_atime(&unix_sk(u)->path);
100614 } else
100615 @@ -843,12 +856,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
100616 */
100617 err = security_path_mknod(&path, dentry, mode, 0);
100618 if (!err) {
100619 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
100620 + err = -EACCES;
100621 + goto out;
100622 + }
100623 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
100624 if (!err) {
100625 res->mnt = mntget(path.mnt);
100626 res->dentry = dget(dentry);
100627 + gr_handle_create(dentry, path.mnt);
100628 }
100629 }
100630 +out:
100631 done_path_create(&path, dentry);
100632 return err;
100633 }
100634 @@ -2336,9 +2355,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
100635 seq_puts(seq, "Num RefCount Protocol Flags Type St "
100636 "Inode Path\n");
100637 else {
100638 - struct sock *s = v;
100639 + struct sock *s = v, *peer;
100640 struct unix_sock *u = unix_sk(s);
100641 unix_state_lock(s);
100642 + peer = unix_peer(s);
100643 + unix_state_unlock(s);
100644 +
100645 + unix_state_double_lock(s, peer);
100646
100647 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
100648 s,
100649 @@ -2365,8 +2388,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
100650 }
100651 for ( ; i < len; i++)
100652 seq_putc(seq, u->addr->name->sun_path[i]);
100653 - }
100654 - unix_state_unlock(s);
100655 + } else if (peer)
100656 + seq_printf(seq, " P%lu", sock_i_ino(peer));
100657 +
100658 + unix_state_double_unlock(s, peer);
100659 seq_putc(seq, '\n');
100660 }
100661
100662 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
100663 index b3d5150..ff3a837 100644
100664 --- a/net/unix/sysctl_net_unix.c
100665 +++ b/net/unix/sysctl_net_unix.c
100666 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
100667
100668 int __net_init unix_sysctl_register(struct net *net)
100669 {
100670 - struct ctl_table *table;
100671 + ctl_table_no_const *table;
100672
100673 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
100674 if (table == NULL)
100675 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
100676 index 9a73074..aecba9a 100644
100677 --- a/net/vmw_vsock/vmci_transport_notify.c
100678 +++ b/net/vmw_vsock/vmci_transport_notify.c
100679 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
100680
100681 /* Socket control packet based operations. */
100682 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
100683 - vmci_transport_notify_pkt_socket_init,
100684 - vmci_transport_notify_pkt_socket_destruct,
100685 - vmci_transport_notify_pkt_poll_in,
100686 - vmci_transport_notify_pkt_poll_out,
100687 - vmci_transport_notify_pkt_handle_pkt,
100688 - vmci_transport_notify_pkt_recv_init,
100689 - vmci_transport_notify_pkt_recv_pre_block,
100690 - vmci_transport_notify_pkt_recv_pre_dequeue,
100691 - vmci_transport_notify_pkt_recv_post_dequeue,
100692 - vmci_transport_notify_pkt_send_init,
100693 - vmci_transport_notify_pkt_send_pre_block,
100694 - vmci_transport_notify_pkt_send_pre_enqueue,
100695 - vmci_transport_notify_pkt_send_post_enqueue,
100696 - vmci_transport_notify_pkt_process_request,
100697 - vmci_transport_notify_pkt_process_negotiate,
100698 + .socket_init = vmci_transport_notify_pkt_socket_init,
100699 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
100700 + .poll_in = vmci_transport_notify_pkt_poll_in,
100701 + .poll_out = vmci_transport_notify_pkt_poll_out,
100702 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
100703 + .recv_init = vmci_transport_notify_pkt_recv_init,
100704 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
100705 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
100706 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
100707 + .send_init = vmci_transport_notify_pkt_send_init,
100708 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
100709 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
100710 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
100711 + .process_request = vmci_transport_notify_pkt_process_request,
100712 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
100713 };
100714 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
100715 index 622bd7a..b92086c 100644
100716 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
100717 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
100718 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
100719
100720 /* Socket always on control packet based operations. */
100721 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
100722 - vmci_transport_notify_pkt_socket_init,
100723 - vmci_transport_notify_pkt_socket_destruct,
100724 - vmci_transport_notify_pkt_poll_in,
100725 - vmci_transport_notify_pkt_poll_out,
100726 - vmci_transport_notify_pkt_handle_pkt,
100727 - vmci_transport_notify_pkt_recv_init,
100728 - vmci_transport_notify_pkt_recv_pre_block,
100729 - vmci_transport_notify_pkt_recv_pre_dequeue,
100730 - vmci_transport_notify_pkt_recv_post_dequeue,
100731 - vmci_transport_notify_pkt_send_init,
100732 - vmci_transport_notify_pkt_send_pre_block,
100733 - vmci_transport_notify_pkt_send_pre_enqueue,
100734 - vmci_transport_notify_pkt_send_post_enqueue,
100735 - vmci_transport_notify_pkt_process_request,
100736 - vmci_transport_notify_pkt_process_negotiate,
100737 + .socket_init = vmci_transport_notify_pkt_socket_init,
100738 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
100739 + .poll_in = vmci_transport_notify_pkt_poll_in,
100740 + .poll_out = vmci_transport_notify_pkt_poll_out,
100741 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
100742 + .recv_init = vmci_transport_notify_pkt_recv_init,
100743 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
100744 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
100745 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
100746 + .send_init = vmci_transport_notify_pkt_send_init,
100747 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
100748 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
100749 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
100750 + .process_request = vmci_transport_notify_pkt_process_request,
100751 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
100752 };
100753 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
100754 index c8717c1..08539f5 100644
100755 --- a/net/wireless/wext-core.c
100756 +++ b/net/wireless/wext-core.c
100757 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
100758 */
100759
100760 /* Support for very large requests */
100761 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
100762 - (user_length > descr->max_tokens)) {
100763 + if (user_length > descr->max_tokens) {
100764 /* Allow userspace to GET more than max so
100765 * we can support any size GET requests.
100766 * There is still a limit : -ENOMEM.
100767 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
100768 }
100769 }
100770
100771 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
100772 - /*
100773 - * If this is a GET, but not NOMAX, it means that the extra
100774 - * data is not bounded by userspace, but by max_tokens. Thus
100775 - * set the length to max_tokens. This matches the extra data
100776 - * allocation.
100777 - * The driver should fill it with the number of tokens it
100778 - * provided, and it may check iwp->length rather than having
100779 - * knowledge of max_tokens. If the driver doesn't change the
100780 - * iwp->length, this ioctl just copies back max_token tokens
100781 - * filled with zeroes. Hopefully the driver isn't claiming
100782 - * them to be valid data.
100783 - */
100784 - iwp->length = descr->max_tokens;
100785 - }
100786 -
100787 err = handler(dev, info, (union iwreq_data *) iwp, extra);
100788
100789 iwp->length += essid_compat;
100790 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
100791 index 4323952..a06dfe1 100644
100792 --- a/net/x25/sysctl_net_x25.c
100793 +++ b/net/x25/sysctl_net_x25.c
100794 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
100795 .mode = 0644,
100796 .proc_handler = proc_dointvec,
100797 },
100798 - { 0, },
100799 + { },
100800 };
100801
100802 void __init x25_register_sysctl(void)
100803 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
100804 index 9a91f74..502f6605 100644
100805 --- a/net/xfrm/xfrm_policy.c
100806 +++ b/net/xfrm/xfrm_policy.c
100807 @@ -332,7 +332,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
100808 {
100809 policy->walk.dead = 1;
100810
100811 - atomic_inc(&policy->genid);
100812 + atomic_inc_unchecked(&policy->genid);
100813
100814 if (del_timer(&policy->polq.hold_timer))
100815 xfrm_pol_put(policy);
100816 @@ -660,7 +660,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
100817 hlist_add_head(&policy->bydst, chain);
100818 xfrm_pol_hold(policy);
100819 net->xfrm.policy_count[dir]++;
100820 - atomic_inc(&flow_cache_genid);
100821 + atomic_inc_unchecked(&flow_cache_genid);
100822
100823 /* After previous checking, family can either be AF_INET or AF_INET6 */
100824 if (policy->family == AF_INET)
100825 @@ -1636,7 +1636,7 @@ free_dst:
100826 goto out;
100827 }
100828
100829 -static int inline
100830 +static inline int
100831 xfrm_dst_alloc_copy(void **target, const void *src, int size)
100832 {
100833 if (!*target) {
100834 @@ -1648,7 +1648,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
100835 return 0;
100836 }
100837
100838 -static int inline
100839 +static inline int
100840 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
100841 {
100842 #ifdef CONFIG_XFRM_SUB_POLICY
100843 @@ -1660,7 +1660,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
100844 #endif
100845 }
100846
100847 -static int inline
100848 +static inline int
100849 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
100850 {
100851 #ifdef CONFIG_XFRM_SUB_POLICY
100852 @@ -1754,7 +1754,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
100853
100854 xdst->num_pols = num_pols;
100855 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
100856 - xdst->policy_genid = atomic_read(&pols[0]->genid);
100857 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
100858
100859 return xdst;
100860 }
100861 @@ -2582,11 +2582,12 @@ void xfrm_garbage_collect(struct net *net)
100862 }
100863 EXPORT_SYMBOL(xfrm_garbage_collect);
100864
100865 -static void xfrm_garbage_collect_deferred(struct net *net)
100866 +void xfrm_garbage_collect_deferred(struct net *net)
100867 {
100868 flow_cache_flush_deferred();
100869 __xfrm_garbage_collect(net);
100870 }
100871 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
100872
100873 static void xfrm_init_pmtu(struct dst_entry *dst)
100874 {
100875 @@ -2636,7 +2637,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
100876 if (xdst->xfrm_genid != dst->xfrm->genid)
100877 return 0;
100878 if (xdst->num_pols > 0 &&
100879 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
100880 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
100881 return 0;
100882
100883 mtu = dst_mtu(dst->child);
100884 @@ -2724,8 +2725,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
100885 dst_ops->link_failure = xfrm_link_failure;
100886 if (likely(dst_ops->neigh_lookup == NULL))
100887 dst_ops->neigh_lookup = xfrm_neigh_lookup;
100888 - if (likely(afinfo->garbage_collect == NULL))
100889 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
100890 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
100891 }
100892 spin_unlock(&xfrm_policy_afinfo_lock);
100893 @@ -2779,7 +2778,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
100894 dst_ops->check = NULL;
100895 dst_ops->negative_advice = NULL;
100896 dst_ops->link_failure = NULL;
100897 - afinfo->garbage_collect = NULL;
100898 }
100899 return err;
100900 }
100901 @@ -3162,7 +3160,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
100902 sizeof(pol->xfrm_vec[i].saddr));
100903 pol->xfrm_vec[i].encap_family = mp->new_family;
100904 /* flush bundles */
100905 - atomic_inc(&pol->genid);
100906 + atomic_inc_unchecked(&pol->genid);
100907 }
100908 }
100909
100910 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
100911 index 68c2f35..9eb05ca 100644
100912 --- a/net/xfrm/xfrm_state.c
100913 +++ b/net/xfrm/xfrm_state.c
100914 @@ -174,12 +174,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
100915
100916 if (unlikely(afinfo == NULL))
100917 return -EAFNOSUPPORT;
100918 - typemap = afinfo->type_map;
100919 + typemap = (const struct xfrm_type **)afinfo->type_map;
100920 spin_lock_bh(&xfrm_type_lock);
100921
100922 - if (likely(typemap[type->proto] == NULL))
100923 + if (likely(typemap[type->proto] == NULL)) {
100924 + pax_open_kernel();
100925 typemap[type->proto] = type;
100926 - else
100927 + pax_close_kernel();
100928 + } else
100929 err = -EEXIST;
100930 spin_unlock_bh(&xfrm_type_lock);
100931 xfrm_state_put_afinfo(afinfo);
100932 @@ -195,13 +197,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
100933
100934 if (unlikely(afinfo == NULL))
100935 return -EAFNOSUPPORT;
100936 - typemap = afinfo->type_map;
100937 + typemap = (const struct xfrm_type **)afinfo->type_map;
100938 spin_lock_bh(&xfrm_type_lock);
100939
100940 if (unlikely(typemap[type->proto] != type))
100941 err = -ENOENT;
100942 - else
100943 + else {
100944 + pax_open_kernel();
100945 typemap[type->proto] = NULL;
100946 + pax_close_kernel();
100947 + }
100948 spin_unlock_bh(&xfrm_type_lock);
100949 xfrm_state_put_afinfo(afinfo);
100950 return err;
100951 @@ -211,7 +216,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
100952 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
100953 {
100954 struct xfrm_state_afinfo *afinfo;
100955 - const struct xfrm_type **typemap;
100956 const struct xfrm_type *type;
100957 int modload_attempted = 0;
100958
100959 @@ -219,9 +223,8 @@ retry:
100960 afinfo = xfrm_state_get_afinfo(family);
100961 if (unlikely(afinfo == NULL))
100962 return NULL;
100963 - typemap = afinfo->type_map;
100964
100965 - type = typemap[proto];
100966 + type = afinfo->type_map[proto];
100967 if (unlikely(type && !try_module_get(type->owner)))
100968 type = NULL;
100969 if (!type && !modload_attempted) {
100970 @@ -255,7 +258,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
100971 return -EAFNOSUPPORT;
100972
100973 err = -EEXIST;
100974 - modemap = afinfo->mode_map;
100975 + modemap = (struct xfrm_mode **)afinfo->mode_map;
100976 spin_lock_bh(&xfrm_mode_lock);
100977 if (modemap[mode->encap])
100978 goto out;
100979 @@ -264,8 +267,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
100980 if (!try_module_get(afinfo->owner))
100981 goto out;
100982
100983 - mode->afinfo = afinfo;
100984 + pax_open_kernel();
100985 + *(const void **)&mode->afinfo = afinfo;
100986 modemap[mode->encap] = mode;
100987 + pax_close_kernel();
100988 err = 0;
100989
100990 out:
100991 @@ -289,10 +294,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
100992 return -EAFNOSUPPORT;
100993
100994 err = -ENOENT;
100995 - modemap = afinfo->mode_map;
100996 + modemap = (struct xfrm_mode **)afinfo->mode_map;
100997 spin_lock_bh(&xfrm_mode_lock);
100998 if (likely(modemap[mode->encap] == mode)) {
100999 + pax_open_kernel();
101000 modemap[mode->encap] = NULL;
101001 + pax_close_kernel();
101002 module_put(mode->afinfo->owner);
101003 err = 0;
101004 }
101005 @@ -1486,10 +1493,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
101006 u32 xfrm_get_acqseq(void)
101007 {
101008 u32 res;
101009 - static atomic_t acqseq;
101010 + static atomic_unchecked_t acqseq;
101011
101012 do {
101013 - res = atomic_inc_return(&acqseq);
101014 + res = atomic_inc_return_unchecked(&acqseq);
101015 } while (!res);
101016
101017 return res;
101018 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
101019 index 05a6e3d..6716ec9 100644
101020 --- a/net/xfrm/xfrm_sysctl.c
101021 +++ b/net/xfrm/xfrm_sysctl.c
101022 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
101023
101024 int __net_init xfrm_sysctl_init(struct net *net)
101025 {
101026 - struct ctl_table *table;
101027 + ctl_table_no_const *table;
101028
101029 __xfrm_sysctl_init(net);
101030
101031 diff --git a/scripts/Makefile b/scripts/Makefile
101032 index 01e7adb..6176d5d 100644
101033 --- a/scripts/Makefile
101034 +++ b/scripts/Makefile
101035 @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
101036
101037 # Let clean descend into subdirs
101038 subdir- += basic kconfig package selinux
101039 +
101040 +clean-files := randstruct.seed
101041 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
101042 index d5d859c..781cbcb 100644
101043 --- a/scripts/Makefile.build
101044 +++ b/scripts/Makefile.build
101045 @@ -111,7 +111,7 @@ endif
101046 endif
101047
101048 # Do not include host rules unless needed
101049 -ifneq ($(hostprogs-y)$(hostprogs-m),)
101050 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
101051 include scripts/Makefile.host
101052 endif
101053
101054 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
101055 index 686cb0d..9d653bf 100644
101056 --- a/scripts/Makefile.clean
101057 +++ b/scripts/Makefile.clean
101058 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
101059 __clean-files := $(extra-y) $(always) \
101060 $(targets) $(clean-files) \
101061 $(host-progs) \
101062 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
101063 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
101064 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
101065
101066 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
101067
101068 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
101069 index 1ac414f..38575f7 100644
101070 --- a/scripts/Makefile.host
101071 +++ b/scripts/Makefile.host
101072 @@ -31,6 +31,8 @@
101073 # Note: Shared libraries consisting of C++ files are not supported
101074
101075 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
101076 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
101077 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
101078
101079 # C code
101080 # Executables compiled from a single .c file
101081 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
101082 # Shared libaries (only .c supported)
101083 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
101084 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
101085 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
101086 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
101087 # Remove .so files from "xxx-objs"
101088 host-cobjs := $(filter-out %.so,$(host-cobjs))
101089 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
101090
101091 -#Object (.o) files used by the shared libaries
101092 +# Object (.o) files used by the shared libaries
101093 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
101094 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
101095
101096 # output directory for programs/.o files
101097 # hostprogs-y := tools/build may have been specified. Retrieve directory
101098 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
101099 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
101100 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
101101 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
101102 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
101103 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
101104 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
101105 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
101106
101107 obj-dirs += $(host-objdirs)
101108 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
101109 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
101110 $(call if_changed_dep,host-cshobjs)
101111
101112 +# Compile .c file, create position independent .o file
101113 +# host-cxxshobjs -> .o
101114 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
101115 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
101116 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
101117 + $(call if_changed_dep,host-cxxshobjs)
101118 +
101119 # Link a shared library, based on position independent .o files
101120 # *.o -> .so shared library (host-cshlib)
101121 quiet_cmd_host-cshlib = HOSTLLD -shared $@
101122 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
101123 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
101124 $(call if_changed,host-cshlib)
101125
101126 +# Link a shared library, based on position independent .o files
101127 +# *.o -> .so shared library (host-cxxshlib)
101128 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
101129 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
101130 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
101131 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
101132 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
101133 + $(call if_changed,host-cxxshlib)
101134 +
101135 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
101136 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
101137 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
101138
101139 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
101140 index 078fe1d..fbdb363 100644
101141 --- a/scripts/basic/fixdep.c
101142 +++ b/scripts/basic/fixdep.c
101143 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
101144 /*
101145 * Lookup a value in the configuration string.
101146 */
101147 -static int is_defined_config(const char *name, int len, unsigned int hash)
101148 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
101149 {
101150 struct item *aux;
101151
101152 @@ -211,10 +211,10 @@ static void clear_config(void)
101153 /*
101154 * Record the use of a CONFIG_* word.
101155 */
101156 -static void use_config(const char *m, int slen)
101157 +static void use_config(const char *m, unsigned int slen)
101158 {
101159 unsigned int hash = strhash(m, slen);
101160 - int c, i;
101161 + unsigned int c, i;
101162
101163 if (is_defined_config(m, slen, hash))
101164 return;
101165 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
101166
101167 static void parse_config_file(const char *map, size_t len)
101168 {
101169 - const int *end = (const int *) (map + len);
101170 + const unsigned int *end = (const unsigned int *) (map + len);
101171 /* start at +1, so that p can never be < map */
101172 - const int *m = (const int *) map + 1;
101173 + const unsigned int *m = (const unsigned int *) map + 1;
101174 const char *p, *q;
101175
101176 for (; m < end; m++) {
101177 @@ -435,7 +435,7 @@ static void print_deps(void)
101178 static void traps(void)
101179 {
101180 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
101181 - int *p = (int *)test;
101182 + unsigned int *p = (unsigned int *)test;
101183
101184 if (*p != INT_CONF) {
101185 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
101186 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
101187 new file mode 100644
101188 index 0000000..5e0222d
101189 --- /dev/null
101190 +++ b/scripts/gcc-plugin.sh
101191 @@ -0,0 +1,17 @@
101192 +#!/bin/bash
101193 +plugincc=`$1 -E -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
101194 +#include "gcc-plugin.h"
101195 +#include "tree.h"
101196 +#include "tm.h"
101197 +#include "rtl.h"
101198 +#ifdef ENABLE_BUILD_WITH_CXX
101199 +#warning $2
101200 +#else
101201 +#warning $1
101202 +#endif
101203 +EOF`
101204 +if [ $? -eq 0 ]
101205 +then
101206 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
101207 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
101208 +fi
101209 diff --git a/scripts/gen-random-seed.sh b/scripts/gen-random-seed.sh
101210 new file mode 100644
101211 index 0000000..17b3162
101212 --- /dev/null
101213 +++ b/scripts/gen-random-seed.sh
101214 @@ -0,0 +1,8 @@
101215 +#!/bin/sh
101216 +
101217 +if [ ! -f 'tools/gcc/randstruct.seed' ]; then
101218 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
101219 + echo "$SEED" > tools/gcc/randstruct.seed
101220 +fi
101221 +cat tools/gcc/randstruct.seed | sha256sum | cut -d" " -f1 | tr -d "\n" > tools/gcc/randstruct.hashed_seed
101222 +cat tools/gcc/randstruct.seed
101223 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
101224 index 5de5660..d3deb89 100644
101225 --- a/scripts/headers_install.sh
101226 +++ b/scripts/headers_install.sh
101227 @@ -32,6 +32,7 @@ do
101228 FILE="$(basename "$i")"
101229 sed -r \
101230 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
101231 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
101232 -e 's/__attribute_const__([ \t]|$)/\1/g' \
101233 -e 's@^#include <linux/compiler.h>@@' \
101234 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
101235 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
101236 index 2dcb377..a82c500 100644
101237 --- a/scripts/link-vmlinux.sh
101238 +++ b/scripts/link-vmlinux.sh
101239 @@ -162,7 +162,7 @@ else
101240 fi;
101241
101242 # final build of init/
101243 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
101244 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
101245
101246 kallsymso=""
101247 kallsyms_vmlinux=""
101248 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
101249 index 2370863..212fbca 100644
101250 --- a/scripts/mod/file2alias.c
101251 +++ b/scripts/mod/file2alias.c
101252 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
101253 unsigned long size, unsigned long id_size,
101254 void *symval)
101255 {
101256 - int i;
101257 + unsigned int i;
101258
101259 if (size % id_size || size < id_size) {
101260 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
101261 @@ -170,7 +170,7 @@ static void device_id_check(const char *modname, const char *device_id,
101262 /* USB is special because the bcdDevice can be matched against a numeric range */
101263 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
101264 static void do_usb_entry(void *symval,
101265 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
101266 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
101267 unsigned char range_lo, unsigned char range_hi,
101268 unsigned char max, struct module *mod)
101269 {
101270 @@ -280,7 +280,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
101271 {
101272 unsigned int devlo, devhi;
101273 unsigned char chi, clo, max;
101274 - int ndigits;
101275 + unsigned int ndigits;
101276
101277 DEF_FIELD(symval, usb_device_id, match_flags);
101278 DEF_FIELD(symval, usb_device_id, idVendor);
101279 @@ -533,7 +533,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
101280 for (i = 0; i < count; i++) {
101281 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
101282 char acpi_id[sizeof(*id)];
101283 - int j;
101284 + unsigned int j;
101285
101286 buf_printf(&mod->dev_table_buf,
101287 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
101288 @@ -562,7 +562,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
101289
101290 for (j = 0; j < PNP_MAX_DEVICES; j++) {
101291 const char *id = (char *)(*devs)[j].id;
101292 - int i2, j2;
101293 + unsigned int i2, j2;
101294 int dup = 0;
101295
101296 if (!id[0])
101297 @@ -588,7 +588,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
101298 /* add an individual alias for every device entry */
101299 if (!dup) {
101300 char acpi_id[PNP_ID_LEN];
101301 - int k;
101302 + unsigned int k;
101303
101304 buf_printf(&mod->dev_table_buf,
101305 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
101306 @@ -940,7 +940,7 @@ static void dmi_ascii_filter(char *d, const char *s)
101307 static int do_dmi_entry(const char *filename, void *symval,
101308 char *alias)
101309 {
101310 - int i, j;
101311 + unsigned int i, j;
101312 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
101313 sprintf(alias, "dmi*");
101314
101315 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
101316 index 1785576..5e8e06a 100644
101317 --- a/scripts/mod/modpost.c
101318 +++ b/scripts/mod/modpost.c
101319 @@ -941,6 +941,7 @@ enum mismatch {
101320 ANY_INIT_TO_ANY_EXIT,
101321 ANY_EXIT_TO_ANY_INIT,
101322 EXPORT_TO_INIT_EXIT,
101323 + DATA_TO_TEXT
101324 };
101325
101326 struct sectioncheck {
101327 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
101328 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
101329 .mismatch = EXPORT_TO_INIT_EXIT,
101330 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
101331 +},
101332 +/* Do not reference code from writable data */
101333 +{
101334 + .fromsec = { DATA_SECTIONS, NULL },
101335 + .tosec = { TEXT_SECTIONS, NULL },
101336 + .mismatch = DATA_TO_TEXT
101337 }
101338 };
101339
101340 @@ -1147,10 +1154,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
101341 continue;
101342 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
101343 continue;
101344 - if (sym->st_value == addr)
101345 - return sym;
101346 /* Find a symbol nearby - addr are maybe negative */
101347 d = sym->st_value - addr;
101348 + if (d == 0)
101349 + return sym;
101350 if (d < 0)
101351 d = addr - sym->st_value;
101352 if (d < distance) {
101353 @@ -1428,6 +1435,14 @@ static void report_sec_mismatch(const char *modname,
101354 tosym, prl_to, prl_to, tosym);
101355 free(prl_to);
101356 break;
101357 + case DATA_TO_TEXT:
101358 +#if 0
101359 + fprintf(stderr,
101360 + "The %s %s:%s references\n"
101361 + "the %s %s:%s%s\n",
101362 + from, fromsec, fromsym, to, tosec, tosym, to_p);
101363 +#endif
101364 + break;
101365 }
101366 fprintf(stderr, "\n");
101367 }
101368 @@ -1662,7 +1677,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
101369 static void check_sec_ref(struct module *mod, const char *modname,
101370 struct elf_info *elf)
101371 {
101372 - int i;
101373 + unsigned int i;
101374 Elf_Shdr *sechdrs = elf->sechdrs;
101375
101376 /* Walk through all sections */
101377 @@ -1781,7 +1796,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
101378 va_end(ap);
101379 }
101380
101381 -void buf_write(struct buffer *buf, const char *s, int len)
101382 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
101383 {
101384 if (buf->size - buf->pos < len) {
101385 buf->size += len + SZ;
101386 @@ -2000,7 +2015,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
101387 if (fstat(fileno(file), &st) < 0)
101388 goto close_write;
101389
101390 - if (st.st_size != b->pos)
101391 + if (st.st_size != (off_t)b->pos)
101392 goto close_write;
101393
101394 tmp = NOFAIL(malloc(b->pos));
101395 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
101396 index 51207e4..f7d603d 100644
101397 --- a/scripts/mod/modpost.h
101398 +++ b/scripts/mod/modpost.h
101399 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
101400
101401 struct buffer {
101402 char *p;
101403 - int pos;
101404 - int size;
101405 + unsigned int pos;
101406 + unsigned int size;
101407 };
101408
101409 void __attribute__((format(printf, 2, 3)))
101410 buf_printf(struct buffer *buf, const char *fmt, ...);
101411
101412 void
101413 -buf_write(struct buffer *buf, const char *s, int len);
101414 +buf_write(struct buffer *buf, const char *s, unsigned int len);
101415
101416 struct module {
101417 struct module *next;
101418 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
101419 index deb2994..af4f63e 100644
101420 --- a/scripts/mod/sumversion.c
101421 +++ b/scripts/mod/sumversion.c
101422 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
101423 goto out;
101424 }
101425
101426 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
101427 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
101428 warn("writing sum in %s failed: %s\n",
101429 filename, strerror(errno));
101430 goto out;
101431 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
101432 index 0865b3e..7235dd4 100644
101433 --- a/scripts/module-common.lds
101434 +++ b/scripts/module-common.lds
101435 @@ -6,6 +6,10 @@
101436 SECTIONS {
101437 /DISCARD/ : { *(.discard) }
101438
101439 + .rodata : {
101440 + *(.rodata) *(.rodata.*)
101441 + *(.data..read_only)
101442 + }
101443 __ksymtab : { *(SORT(___ksymtab+*)) }
101444 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
101445 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
101446 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
101447 index 90e521f..e9eaf8f 100644
101448 --- a/scripts/package/builddeb
101449 +++ b/scripts/package/builddeb
101450 @@ -281,6 +281,7 @@ fi
101451 (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
101452 (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
101453 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
101454 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
101455 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
101456 mkdir -p "$destdir"
101457 (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
101458 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
101459 index 68bb4ef..2f419e1 100644
101460 --- a/scripts/pnmtologo.c
101461 +++ b/scripts/pnmtologo.c
101462 @@ -244,14 +244,14 @@ static void write_header(void)
101463 fprintf(out, " * Linux logo %s\n", logoname);
101464 fputs(" */\n\n", out);
101465 fputs("#include <linux/linux_logo.h>\n\n", out);
101466 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
101467 + fprintf(out, "static unsigned char %s_data[] = {\n",
101468 logoname);
101469 }
101470
101471 static void write_footer(void)
101472 {
101473 fputs("\n};\n\n", out);
101474 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
101475 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
101476 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
101477 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
101478 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
101479 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
101480 fputs("\n};\n\n", out);
101481
101482 /* write logo clut */
101483 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
101484 + fprintf(out, "static unsigned char %s_clut[] = {\n",
101485 logoname);
101486 write_hex_cnt = 0;
101487 for (i = 0; i < logo_clutsize; i++) {
101488 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
101489 index 8fac3fd..32ff38d 100644
101490 --- a/scripts/sortextable.h
101491 +++ b/scripts/sortextable.h
101492 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
101493 const char *secstrtab;
101494 const char *strtab;
101495 char *extab_image;
101496 - int extab_index = 0;
101497 - int i;
101498 - int idx;
101499 + unsigned int extab_index = 0;
101500 + unsigned int i;
101501 + unsigned int idx;
101502 unsigned int num_sections;
101503 unsigned int secindex_strings;
101504
101505 diff --git a/security/Kconfig b/security/Kconfig
101506 index e9c6ac7..9551ea7 100644
101507 --- a/security/Kconfig
101508 +++ b/security/Kconfig
101509 @@ -4,6 +4,958 @@
101510
101511 menu "Security options"
101512
101513 +menu "Grsecurity"
101514 +
101515 + config ARCH_TRACK_EXEC_LIMIT
101516 + bool
101517 +
101518 + config PAX_KERNEXEC_PLUGIN
101519 + bool
101520 +
101521 + config PAX_PER_CPU_PGD
101522 + bool
101523 +
101524 + config TASK_SIZE_MAX_SHIFT
101525 + int
101526 + depends on X86_64
101527 + default 47 if !PAX_PER_CPU_PGD
101528 + default 42 if PAX_PER_CPU_PGD
101529 +
101530 + config PAX_ENABLE_PAE
101531 + bool
101532 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
101533 +
101534 + config PAX_USERCOPY_SLABS
101535 + bool
101536 +
101537 +config GRKERNSEC
101538 + bool "Grsecurity"
101539 + select CRYPTO
101540 + select CRYPTO_SHA256
101541 + select PROC_FS
101542 + select STOP_MACHINE
101543 + select TTY
101544 + select DEBUG_LIST
101545 + help
101546 + If you say Y here, you will be able to configure many features
101547 + that will enhance the security of your system. It is highly
101548 + recommended that you say Y here and read through the help
101549 + for each option so that you fully understand the features and
101550 + can evaluate their usefulness for your machine.
101551 +
101552 +choice
101553 + prompt "Configuration Method"
101554 + depends on GRKERNSEC
101555 + default GRKERNSEC_CONFIG_CUSTOM
101556 + help
101557 +
101558 +config GRKERNSEC_CONFIG_AUTO
101559 + bool "Automatic"
101560 + help
101561 + If you choose this configuration method, you'll be able to answer a small
101562 + number of simple questions about how you plan to use this kernel.
101563 + The settings of grsecurity and PaX will be automatically configured for
101564 + the highest commonly-used settings within the provided constraints.
101565 +
101566 + If you require additional configuration, custom changes can still be made
101567 + from the "custom configuration" menu.
101568 +
101569 +config GRKERNSEC_CONFIG_CUSTOM
101570 + bool "Custom"
101571 + help
101572 + If you choose this configuration method, you'll be able to configure all
101573 + grsecurity and PaX settings manually. Via this method, no options are
101574 + automatically enabled.
101575 +
101576 +endchoice
101577 +
101578 +choice
101579 + prompt "Usage Type"
101580 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
101581 + default GRKERNSEC_CONFIG_SERVER
101582 + help
101583 +
101584 +config GRKERNSEC_CONFIG_SERVER
101585 + bool "Server"
101586 + help
101587 + Choose this option if you plan to use this kernel on a server.
101588 +
101589 +config GRKERNSEC_CONFIG_DESKTOP
101590 + bool "Desktop"
101591 + help
101592 + Choose this option if you plan to use this kernel on a desktop.
101593 +
101594 +endchoice
101595 +
101596 +choice
101597 + prompt "Virtualization Type"
101598 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
101599 + default GRKERNSEC_CONFIG_VIRT_NONE
101600 + help
101601 +
101602 +config GRKERNSEC_CONFIG_VIRT_NONE
101603 + bool "None"
101604 + help
101605 + Choose this option if this kernel will be run on bare metal.
101606 +
101607 +config GRKERNSEC_CONFIG_VIRT_GUEST
101608 + bool "Guest"
101609 + help
101610 + Choose this option if this kernel will be run as a VM guest.
101611 +
101612 +config GRKERNSEC_CONFIG_VIRT_HOST
101613 + bool "Host"
101614 + help
101615 + Choose this option if this kernel will be run as a VM host.
101616 +
101617 +endchoice
101618 +
101619 +choice
101620 + prompt "Virtualization Hardware"
101621 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
101622 + help
101623 +
101624 +config GRKERNSEC_CONFIG_VIRT_EPT
101625 + bool "EPT/RVI Processor Support"
101626 + depends on X86
101627 + help
101628 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
101629 + hardware virtualization. This allows for additional kernel hardening protections
101630 + to operate without additional performance impact.
101631 +
101632 + To see if your Intel processor supports EPT, see:
101633 + http://ark.intel.com/Products/VirtualizationTechnology
101634 + (Most Core i3/5/7 support EPT)
101635 +
101636 + To see if your AMD processor supports RVI, see:
101637 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
101638 +
101639 +config GRKERNSEC_CONFIG_VIRT_SOFT
101640 + bool "First-gen/No Hardware Virtualization"
101641 + help
101642 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
101643 + support hardware virtualization or doesn't support the EPT/RVI extensions.
101644 +
101645 +endchoice
101646 +
101647 +choice
101648 + prompt "Virtualization Software"
101649 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
101650 + help
101651 +
101652 +config GRKERNSEC_CONFIG_VIRT_XEN
101653 + bool "Xen"
101654 + help
101655 + Choose this option if this kernel is running as a Xen guest or host.
101656 +
101657 +config GRKERNSEC_CONFIG_VIRT_VMWARE
101658 + bool "VMWare"
101659 + help
101660 + Choose this option if this kernel is running as a VMWare guest or host.
101661 +
101662 +config GRKERNSEC_CONFIG_VIRT_KVM
101663 + bool "KVM"
101664 + help
101665 + Choose this option if this kernel is running as a KVM guest or host.
101666 +
101667 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
101668 + bool "VirtualBox"
101669 + help
101670 + Choose this option if this kernel is running as a VirtualBox guest or host.
101671 +
101672 +endchoice
101673 +
101674 +choice
101675 + prompt "Required Priorities"
101676 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
101677 + default GRKERNSEC_CONFIG_PRIORITY_PERF
101678 + help
101679 +
101680 +config GRKERNSEC_CONFIG_PRIORITY_PERF
101681 + bool "Performance"
101682 + help
101683 + Choose this option if performance is of highest priority for this deployment
101684 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
101685 + clearing of structures intended for userland, and freed memory sanitizing will
101686 + be disabled.
101687 +
101688 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
101689 + bool "Security"
101690 + help
101691 + Choose this option if security is of highest priority for this deployment of
101692 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
101693 + for userland, and freed memory sanitizing will be enabled for this kernel.
101694 + In a worst-case scenario, these features can introduce a 20% performance hit
101695 + (UDEREF on x64 contributing half of this hit).
101696 +
101697 +endchoice
101698 +
101699 +menu "Default Special Groups"
101700 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
101701 +
101702 +config GRKERNSEC_PROC_GID
101703 + int "GID exempted from /proc restrictions"
101704 + default 1001
101705 + help
101706 + Setting this GID determines which group will be exempted from
101707 + grsecurity's /proc restrictions, allowing users of the specified
101708 + group to view network statistics and the existence of other users'
101709 + processes on the system. This GID may also be chosen at boot time
101710 + via "grsec_proc_gid=" on the kernel commandline.
101711 +
101712 +config GRKERNSEC_TPE_UNTRUSTED_GID
101713 + int "GID for TPE-untrusted users"
101714 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
101715 + default 1005
101716 + help
101717 + Setting this GID determines which group untrusted users should
101718 + be added to. These users will be placed under grsecurity's Trusted Path
101719 + Execution mechanism, preventing them from executing their own binaries.
101720 + The users will only be able to execute binaries in directories owned and
101721 + writable only by the root user. If the sysctl option is enabled, a sysctl
101722 + option with name "tpe_gid" is created.
101723 +
101724 +config GRKERNSEC_TPE_TRUSTED_GID
101725 + int "GID for TPE-trusted users"
101726 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
101727 + default 1005
101728 + help
101729 + Setting this GID determines what group TPE restrictions will be
101730 + *disabled* for. If the sysctl option is enabled, a sysctl option
101731 + with name "tpe_gid" is created.
101732 +
101733 +config GRKERNSEC_SYMLINKOWN_GID
101734 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
101735 + depends on GRKERNSEC_CONFIG_SERVER
101736 + default 1006
101737 + help
101738 + Setting this GID determines what group kernel-enforced
101739 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
101740 + is enabled, a sysctl option with name "symlinkown_gid" is created.
101741 +
101742 +
101743 +endmenu
101744 +
101745 +menu "Customize Configuration"
101746 +depends on GRKERNSEC
101747 +
101748 +menu "PaX"
101749 +
101750 +config PAX
101751 + bool "Enable various PaX features"
101752 + default y if GRKERNSEC_CONFIG_AUTO
101753 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
101754 + help
101755 + This allows you to enable various PaX features. PaX adds
101756 + intrusion prevention mechanisms to the kernel that reduce
101757 + the risks posed by exploitable memory corruption bugs.
101758 +
101759 +menu "PaX Control"
101760 + depends on PAX
101761 +
101762 +config PAX_SOFTMODE
101763 + bool 'Support soft mode'
101764 + help
101765 + Enabling this option will allow you to run PaX in soft mode, that
101766 + is, PaX features will not be enforced by default, only on executables
101767 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
101768 + support as they are the only way to mark executables for soft mode use.
101769 +
101770 + Soft mode can be activated by using the "pax_softmode=1" kernel command
101771 + line option on boot. Furthermore you can control various PaX features
101772 + at runtime via the entries in /proc/sys/kernel/pax.
101773 +
101774 +config PAX_EI_PAX
101775 + bool 'Use legacy ELF header marking'
101776 + default y if GRKERNSEC_CONFIG_AUTO
101777 + help
101778 + Enabling this option will allow you to control PaX features on
101779 + a per executable basis via the 'chpax' utility available at
101780 + http://pax.grsecurity.net/. The control flags will be read from
101781 + an otherwise reserved part of the ELF header. This marking has
101782 + numerous drawbacks (no support for soft-mode, toolchain does not
101783 + know about the non-standard use of the ELF header) therefore it
101784 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
101785 + support.
101786 +
101787 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
101788 + support as well, they will override the legacy EI_PAX marks.
101789 +
101790 + If you enable none of the marking options then all applications
101791 + will run with PaX enabled on them by default.
101792 +
101793 +config PAX_PT_PAX_FLAGS
101794 + bool 'Use ELF program header marking'
101795 + default y if GRKERNSEC_CONFIG_AUTO
101796 + help
101797 + Enabling this option will allow you to control PaX features on
101798 + a per executable basis via the 'paxctl' utility available at
101799 + http://pax.grsecurity.net/. The control flags will be read from
101800 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
101801 + has the benefits of supporting both soft mode and being fully
101802 + integrated into the toolchain (the binutils patch is available
101803 + from http://pax.grsecurity.net).
101804 +
101805 + Note that if you enable the legacy EI_PAX marking support as well,
101806 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
101807 +
101808 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
101809 + must make sure that the marks are the same if a binary has both marks.
101810 +
101811 + If you enable none of the marking options then all applications
101812 + will run with PaX enabled on them by default.
101813 +
101814 +config PAX_XATTR_PAX_FLAGS
101815 + bool 'Use filesystem extended attributes marking'
101816 + default y if GRKERNSEC_CONFIG_AUTO
101817 + select CIFS_XATTR if CIFS
101818 + select EXT2_FS_XATTR if EXT2_FS
101819 + select EXT3_FS_XATTR if EXT3_FS
101820 + select JFFS2_FS_XATTR if JFFS2_FS
101821 + select REISERFS_FS_XATTR if REISERFS_FS
101822 + select SQUASHFS_XATTR if SQUASHFS
101823 + select TMPFS_XATTR if TMPFS
101824 + select UBIFS_FS_XATTR if UBIFS_FS
101825 + help
101826 + Enabling this option will allow you to control PaX features on
101827 + a per executable basis via the 'setfattr' utility. The control
101828 + flags will be read from the user.pax.flags extended attribute of
101829 + the file. This marking has the benefit of supporting binary-only
101830 + applications that self-check themselves (e.g., skype) and would
101831 + not tolerate chpax/paxctl changes. The main drawback is that
101832 + extended attributes are not supported by some filesystems (e.g.,
101833 + isofs, udf, vfat) so copying files through such filesystems will
101834 + lose the extended attributes and these PaX markings.
101835 +
101836 + Note that if you enable the legacy EI_PAX marking support as well,
101837 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
101838 +
101839 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
101840 + must make sure that the marks are the same if a binary has both marks.
101841 +
101842 + If you enable none of the marking options then all applications
101843 + will run with PaX enabled on them by default.
101844 +
101845 +choice
101846 + prompt 'MAC system integration'
101847 + default PAX_HAVE_ACL_FLAGS
101848 + help
101849 + Mandatory Access Control systems have the option of controlling
101850 + PaX flags on a per executable basis, choose the method supported
101851 + by your particular system.
101852 +
101853 + - "none": if your MAC system does not interact with PaX,
101854 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
101855 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
101856 +
101857 + NOTE: this option is for developers/integrators only.
101858 +
101859 + config PAX_NO_ACL_FLAGS
101860 + bool 'none'
101861 +
101862 + config PAX_HAVE_ACL_FLAGS
101863 + bool 'direct'
101864 +
101865 + config PAX_HOOK_ACL_FLAGS
101866 + bool 'hook'
101867 +endchoice
101868 +
101869 +endmenu
101870 +
101871 +menu "Non-executable pages"
101872 + depends on PAX
101873 +
101874 +config PAX_NOEXEC
101875 + bool "Enforce non-executable pages"
101876 + default y if GRKERNSEC_CONFIG_AUTO
101877 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
101878 + help
101879 + By design some architectures do not allow for protecting memory
101880 + pages against execution or even if they do, Linux does not make
101881 + use of this feature. In practice this means that if a page is
101882 + readable (such as the stack or heap) it is also executable.
101883 +
101884 + There is a well known exploit technique that makes use of this
101885 + fact and a common programming mistake where an attacker can
101886 + introduce code of his choice somewhere in the attacked program's
101887 + memory (typically the stack or the heap) and then execute it.
101888 +
101889 + If the attacked program was running with different (typically
101890 + higher) privileges than that of the attacker, then he can elevate
101891 + his own privilege level (e.g. get a root shell, write to files for
101892 + which he does not have write access to, etc).
101893 +
101894 + Enabling this option will let you choose from various features
101895 + that prevent the injection and execution of 'foreign' code in
101896 + a program.
101897 +
101898 + This will also break programs that rely on the old behaviour and
101899 + expect that dynamically allocated memory via the malloc() family
101900 + of functions is executable (which it is not). Notable examples
101901 + are the XFree86 4.x server, the java runtime and wine.
101902 +
101903 +config PAX_PAGEEXEC
101904 + bool "Paging based non-executable pages"
101905 + default y if GRKERNSEC_CONFIG_AUTO
101906 + 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)
101907 + select ARCH_TRACK_EXEC_LIMIT if X86_32
101908 + help
101909 + This implementation is based on the paging feature of the CPU.
101910 + On i386 without hardware non-executable bit support there is a
101911 + variable but usually low performance impact, however on Intel's
101912 + P4 core based CPUs it is very high so you should not enable this
101913 + for kernels meant to be used on such CPUs.
101914 +
101915 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
101916 + with hardware non-executable bit support there is no performance
101917 + impact, on ppc the impact is negligible.
101918 +
101919 + Note that several architectures require various emulations due to
101920 + badly designed userland ABIs, this will cause a performance impact
101921 + but will disappear as soon as userland is fixed. For example, ppc
101922 + userland MUST have been built with secure-plt by a recent toolchain.
101923 +
101924 +config PAX_SEGMEXEC
101925 + bool "Segmentation based non-executable pages"
101926 + default y if GRKERNSEC_CONFIG_AUTO
101927 + depends on PAX_NOEXEC && X86_32
101928 + help
101929 + This implementation is based on the segmentation feature of the
101930 + CPU and has a very small performance impact, however applications
101931 + will be limited to a 1.5 GB address space instead of the normal
101932 + 3 GB.
101933 +
101934 +config PAX_EMUTRAMP
101935 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
101936 + default y if PARISC
101937 + help
101938 + There are some programs and libraries that for one reason or
101939 + another attempt to execute special small code snippets from
101940 + non-executable memory pages. Most notable examples are the
101941 + signal handler return code generated by the kernel itself and
101942 + the GCC trampolines.
101943 +
101944 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
101945 + such programs will no longer work under your kernel.
101946 +
101947 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
101948 + utilities to enable trampoline emulation for the affected programs
101949 + yet still have the protection provided by the non-executable pages.
101950 +
101951 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
101952 + your system will not even boot.
101953 +
101954 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
101955 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
101956 + for the affected files.
101957 +
101958 + NOTE: enabling this feature *may* open up a loophole in the
101959 + protection provided by non-executable pages that an attacker
101960 + could abuse. Therefore the best solution is to not have any
101961 + files on your system that would require this option. This can
101962 + be achieved by not using libc5 (which relies on the kernel
101963 + signal handler return code) and not using or rewriting programs
101964 + that make use of the nested function implementation of GCC.
101965 + Skilled users can just fix GCC itself so that it implements
101966 + nested function calls in a way that does not interfere with PaX.
101967 +
101968 +config PAX_EMUSIGRT
101969 + bool "Automatically emulate sigreturn trampolines"
101970 + depends on PAX_EMUTRAMP && PARISC
101971 + default y
101972 + help
101973 + Enabling this option will have the kernel automatically detect
101974 + and emulate signal return trampolines executing on the stack
101975 + that would otherwise lead to task termination.
101976 +
101977 + This solution is intended as a temporary one for users with
101978 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
101979 + Modula-3 runtime, etc) or executables linked to such, basically
101980 + everything that does not specify its own SA_RESTORER function in
101981 + normal executable memory like glibc 2.1+ does.
101982 +
101983 + On parisc you MUST enable this option, otherwise your system will
101984 + not even boot.
101985 +
101986 + NOTE: this feature cannot be disabled on a per executable basis
101987 + and since it *does* open up a loophole in the protection provided
101988 + by non-executable pages, the best solution is to not have any
101989 + files on your system that would require this option.
101990 +
101991 +config PAX_MPROTECT
101992 + bool "Restrict mprotect()"
101993 + default y if GRKERNSEC_CONFIG_AUTO
101994 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
101995 + help
101996 + Enabling this option will prevent programs from
101997 + - changing the executable status of memory pages that were
101998 + not originally created as executable,
101999 + - making read-only executable pages writable again,
102000 + - creating executable pages from anonymous memory,
102001 + - making read-only-after-relocations (RELRO) data pages writable again.
102002 +
102003 + You should say Y here to complete the protection provided by
102004 + the enforcement of non-executable pages.
102005 +
102006 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
102007 + this feature on a per file basis.
102008 +
102009 +config PAX_MPROTECT_COMPAT
102010 + bool "Use legacy/compat protection demoting (read help)"
102011 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
102012 + depends on PAX_MPROTECT
102013 + help
102014 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
102015 + by sending the proper error code to the application. For some broken
102016 + userland, this can cause problems with Python or other applications. The
102017 + current implementation however allows for applications like clamav to
102018 + detect if JIT compilation/execution is allowed and to fall back gracefully
102019 + to an interpreter-based mode if it does not. While we encourage everyone
102020 + to use the current implementation as-is and push upstream to fix broken
102021 + userland (note that the RWX logging option can assist with this), in some
102022 + environments this may not be possible. Having to disable MPROTECT
102023 + completely on certain binaries reduces the security benefit of PaX,
102024 + so this option is provided for those environments to revert to the old
102025 + behavior.
102026 +
102027 +config PAX_ELFRELOCS
102028 + bool "Allow ELF text relocations (read help)"
102029 + depends on PAX_MPROTECT
102030 + default n
102031 + help
102032 + Non-executable pages and mprotect() restrictions are effective
102033 + in preventing the introduction of new executable code into an
102034 + attacked task's address space. There remain only two venues
102035 + for this kind of attack: if the attacker can execute already
102036 + existing code in the attacked task then he can either have it
102037 + create and mmap() a file containing his code or have it mmap()
102038 + an already existing ELF library that does not have position
102039 + independent code in it and use mprotect() on it to make it
102040 + writable and copy his code there. While protecting against
102041 + the former approach is beyond PaX, the latter can be prevented
102042 + by having only PIC ELF libraries on one's system (which do not
102043 + need to relocate their code). If you are sure this is your case,
102044 + as is the case with all modern Linux distributions, then leave
102045 + this option disabled. You should say 'n' here.
102046 +
102047 +config PAX_ETEXECRELOCS
102048 + bool "Allow ELF ET_EXEC text relocations"
102049 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
102050 + select PAX_ELFRELOCS
102051 + default y
102052 + help
102053 + On some architectures there are incorrectly created applications
102054 + that require text relocations and would not work without enabling
102055 + this option. If you are an alpha, ia64 or parisc user, you should
102056 + enable this option and disable it once you have made sure that
102057 + none of your applications need it.
102058 +
102059 +config PAX_EMUPLT
102060 + bool "Automatically emulate ELF PLT"
102061 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
102062 + default y
102063 + help
102064 + Enabling this option will have the kernel automatically detect
102065 + and emulate the Procedure Linkage Table entries in ELF files.
102066 + On some architectures such entries are in writable memory, and
102067 + become non-executable leading to task termination. Therefore
102068 + it is mandatory that you enable this option on alpha, parisc,
102069 + sparc and sparc64, otherwise your system would not even boot.
102070 +
102071 + NOTE: this feature *does* open up a loophole in the protection
102072 + provided by the non-executable pages, therefore the proper
102073 + solution is to modify the toolchain to produce a PLT that does
102074 + not need to be writable.
102075 +
102076 +config PAX_DLRESOLVE
102077 + bool 'Emulate old glibc resolver stub'
102078 + depends on PAX_EMUPLT && SPARC
102079 + default n
102080 + help
102081 + This option is needed if userland has an old glibc (before 2.4)
102082 + that puts a 'save' instruction into the runtime generated resolver
102083 + stub that needs special emulation.
102084 +
102085 +config PAX_KERNEXEC
102086 + bool "Enforce non-executable kernel pages"
102087 + 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))
102088 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
102089 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
102090 + select PAX_KERNEXEC_PLUGIN if X86_64
102091 + help
102092 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
102093 + that is, enabling this option will make it harder to inject
102094 + and execute 'foreign' code in kernel memory itself.
102095 +
102096 +choice
102097 + prompt "Return Address Instrumentation Method"
102098 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
102099 + depends on PAX_KERNEXEC_PLUGIN
102100 + help
102101 + Select the method used to instrument function pointer dereferences.
102102 + Note that binary modules cannot be instrumented by this approach.
102103 +
102104 + Note that the implementation requires a gcc with plugin support,
102105 + i.e., gcc 4.5 or newer. You may need to install the supporting
102106 + headers explicitly in addition to the normal gcc package.
102107 +
102108 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
102109 + bool "bts"
102110 + help
102111 + This method is compatible with binary only modules but has
102112 + a higher runtime overhead.
102113 +
102114 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
102115 + bool "or"
102116 + depends on !PARAVIRT
102117 + help
102118 + This method is incompatible with binary only modules but has
102119 + a lower runtime overhead.
102120 +endchoice
102121 +
102122 +config PAX_KERNEXEC_PLUGIN_METHOD
102123 + string
102124 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
102125 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
102126 + default ""
102127 +
102128 +config PAX_KERNEXEC_MODULE_TEXT
102129 + int "Minimum amount of memory reserved for module code"
102130 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
102131 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
102132 + depends on PAX_KERNEXEC && X86_32
102133 + help
102134 + Due to implementation details the kernel must reserve a fixed
102135 + amount of memory for runtime allocated code (such as modules)
102136 + at compile time that cannot be changed at runtime. Here you
102137 + can specify the minimum amount in MB that will be reserved.
102138 + Due to the same implementation details this size will always
102139 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
102140 + the actually available memory for runtime allocated code will
102141 + usually be more than this minimum.
102142 +
102143 + The default 4 MB should be enough for most users but if you have
102144 + an excessive number of modules (e.g., most distribution configs
102145 + compile many drivers as modules) or use huge modules such as
102146 + nvidia's kernel driver, you will need to adjust this amount.
102147 + A good rule of thumb is to look at your currently loaded kernel
102148 + modules and add up their sizes.
102149 +
102150 +endmenu
102151 +
102152 +menu "Address Space Layout Randomization"
102153 + depends on PAX
102154 +
102155 +config PAX_ASLR
102156 + bool "Address Space Layout Randomization"
102157 + default y if GRKERNSEC_CONFIG_AUTO
102158 + help
102159 + Many if not most exploit techniques rely on the knowledge of
102160 + certain addresses in the attacked program. The following options
102161 + will allow the kernel to apply a certain amount of randomization
102162 + to specific parts of the program thereby forcing an attacker to
102163 + guess them in most cases. Any failed guess will most likely crash
102164 + the attacked program which allows the kernel to detect such attempts
102165 + and react on them. PaX itself provides no reaction mechanisms,
102166 + instead it is strongly encouraged that you make use of Nergal's
102167 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
102168 + (http://www.grsecurity.net/) built-in crash detection features or
102169 + develop one yourself.
102170 +
102171 + By saying Y here you can choose to randomize the following areas:
102172 + - top of the task's kernel stack
102173 + - top of the task's userland stack
102174 + - base address for mmap() requests that do not specify one
102175 + (this includes all libraries)
102176 + - base address of the main executable
102177 +
102178 + It is strongly recommended to say Y here as address space layout
102179 + randomization has negligible impact on performance yet it provides
102180 + a very effective protection.
102181 +
102182 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
102183 + this feature on a per file basis.
102184 +
102185 +config PAX_RANDKSTACK
102186 + bool "Randomize kernel stack base"
102187 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
102188 + depends on X86_TSC && X86
102189 + help
102190 + By saying Y here the kernel will randomize every task's kernel
102191 + stack on every system call. This will not only force an attacker
102192 + to guess it but also prevent him from making use of possible
102193 + leaked information about it.
102194 +
102195 + Since the kernel stack is a rather scarce resource, randomization
102196 + may cause unexpected stack overflows, therefore you should very
102197 + carefully test your system. Note that once enabled in the kernel
102198 + configuration, this feature cannot be disabled on a per file basis.
102199 +
102200 +config PAX_RANDUSTACK
102201 + bool "Randomize user stack base"
102202 + default y if GRKERNSEC_CONFIG_AUTO
102203 + depends on PAX_ASLR
102204 + help
102205 + By saying Y here the kernel will randomize every task's userland
102206 + stack. The randomization is done in two steps where the second
102207 + one may apply a big amount of shift to the top of the stack and
102208 + cause problems for programs that want to use lots of memory (more
102209 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
102210 + For this reason the second step can be controlled by 'chpax' or
102211 + 'paxctl' on a per file basis.
102212 +
102213 +config PAX_RANDMMAP
102214 + bool "Randomize mmap() base"
102215 + default y if GRKERNSEC_CONFIG_AUTO
102216 + depends on PAX_ASLR
102217 + help
102218 + By saying Y here the kernel will use a randomized base address for
102219 + mmap() requests that do not specify one themselves. As a result
102220 + all dynamically loaded libraries will appear at random addresses
102221 + and therefore be harder to exploit by a technique where an attacker
102222 + attempts to execute library code for his purposes (e.g. spawn a
102223 + shell from an exploited program that is running at an elevated
102224 + privilege level).
102225 +
102226 + Furthermore, if a program is relinked as a dynamic ELF file, its
102227 + base address will be randomized as well, completing the full
102228 + randomization of the address space layout. Attacking such programs
102229 + becomes a guess game. You can find an example of doing this at
102230 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
102231 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
102232 +
102233 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
102234 + feature on a per file basis.
102235 +
102236 +endmenu
102237 +
102238 +menu "Miscellaneous hardening features"
102239 +
102240 +config PAX_MEMORY_SANITIZE
102241 + bool "Sanitize all freed memory"
102242 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
102243 + help
102244 + By saying Y here the kernel will erase memory pages and slab objects
102245 + as soon as they are freed. This in turn reduces the lifetime of data
102246 + stored in them, making it less likely that sensitive information such
102247 + as passwords, cryptographic secrets, etc stay in memory for too long.
102248 +
102249 + This is especially useful for programs whose runtime is short, long
102250 + lived processes and the kernel itself benefit from this as long as
102251 + they ensure timely freeing of memory that may hold sensitive
102252 + information.
102253 +
102254 + A nice side effect of the sanitization of slab objects is the
102255 + reduction of possible info leaks caused by padding bytes within the
102256 + leaky structures. Use-after-free bugs for structures containing
102257 + pointers can also be detected as dereferencing the sanitized pointer
102258 + will generate an access violation.
102259 +
102260 + The tradeoff is performance impact, on a single CPU system kernel
102261 + compilation sees a 3% slowdown, other systems and workloads may vary
102262 + and you are advised to test this feature on your expected workload
102263 + before deploying it.
102264 +
102265 + To reduce the performance penalty by sanitizing pages only, albeit
102266 + limiting the effectiveness of this feature at the same time, slab
102267 + sanitization can be disabled with the kernel commandline parameter
102268 + "pax_sanitize_slab=0".
102269 +
102270 + Note that this feature does not protect data stored in live pages,
102271 + e.g., process memory swapped to disk may stay there for a long time.
102272 +
102273 +config PAX_MEMORY_STACKLEAK
102274 + bool "Sanitize kernel stack"
102275 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
102276 + depends on X86
102277 + help
102278 + By saying Y here the kernel will erase the kernel stack before it
102279 + returns from a system call. This in turn reduces the information
102280 + that a kernel stack leak bug can reveal.
102281 +
102282 + Note that such a bug can still leak information that was put on
102283 + the stack by the current system call (the one eventually triggering
102284 + the bug) but traces of earlier system calls on the kernel stack
102285 + cannot leak anymore.
102286 +
102287 + The tradeoff is performance impact: on a single CPU system kernel
102288 + compilation sees a 1% slowdown, other systems and workloads may vary
102289 + and you are advised to test this feature on your expected workload
102290 + before deploying it.
102291 +
102292 + Note that the full feature requires a gcc with plugin support,
102293 + i.e., gcc 4.5 or newer. You may need to install the supporting
102294 + headers explicitly in addition to the normal gcc package. Using
102295 + older gcc versions means that functions with large enough stack
102296 + frames may leave uninitialized memory behind that may be exposed
102297 + to a later syscall leaking the stack.
102298 +
102299 +config PAX_MEMORY_STRUCTLEAK
102300 + bool "Forcibly initialize local variables copied to userland"
102301 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
102302 + help
102303 + By saying Y here the kernel will zero initialize some local
102304 + variables that are going to be copied to userland. This in
102305 + turn prevents unintended information leakage from the kernel
102306 + stack should later code forget to explicitly set all parts of
102307 + the copied variable.
102308 +
102309 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
102310 + at a much smaller coverage.
102311 +
102312 + Note that the implementation requires a gcc with plugin support,
102313 + i.e., gcc 4.5 or newer. You may need to install the supporting
102314 + headers explicitly in addition to the normal gcc package.
102315 +
102316 +config PAX_MEMORY_UDEREF
102317 + bool "Prevent invalid userland pointer dereference"
102318 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
102319 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
102320 + select PAX_PER_CPU_PGD if X86_64
102321 + help
102322 + By saying Y here the kernel will be prevented from dereferencing
102323 + userland pointers in contexts where the kernel expects only kernel
102324 + pointers. This is both a useful runtime debugging feature and a
102325 + security measure that prevents exploiting a class of kernel bugs.
102326 +
102327 + The tradeoff is that some virtualization solutions may experience
102328 + a huge slowdown and therefore you should not enable this feature
102329 + for kernels meant to run in such environments. Whether a given VM
102330 + solution is affected or not is best determined by simply trying it
102331 + out, the performance impact will be obvious right on boot as this
102332 + mechanism engages from very early on. A good rule of thumb is that
102333 + VMs running on CPUs without hardware virtualization support (i.e.,
102334 + the majority of IA-32 CPUs) will likely experience the slowdown.
102335 +
102336 + On X86_64 the kernel will make use of PCID support when available
102337 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
102338 + or performance impact. Pass pax_weakuderef on the kernel command
102339 + line to choose the latter.
102340 +
102341 +config PAX_REFCOUNT
102342 + bool "Prevent various kernel object reference counter overflows"
102343 + default y if GRKERNSEC_CONFIG_AUTO
102344 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
102345 + help
102346 + By saying Y here the kernel will detect and prevent overflowing
102347 + various (but not all) kinds of object reference counters. Such
102348 + overflows can normally occur due to bugs only and are often, if
102349 + not always, exploitable.
102350 +
102351 + The tradeoff is that data structures protected by an overflowed
102352 + refcount will never be freed and therefore will leak memory. Note
102353 + that this leak also happens even without this protection but in
102354 + that case the overflow can eventually trigger the freeing of the
102355 + data structure while it is still being used elsewhere, resulting
102356 + in the exploitable situation that this feature prevents.
102357 +
102358 + Since this has a negligible performance impact, you should enable
102359 + this feature.
102360 +
102361 +config PAX_CONSTIFY_PLUGIN
102362 + bool "Automatically constify eligible structures"
102363 + default y
102364 + depends on !UML && PAX_KERNEXEC
102365 + help
102366 + By saying Y here the compiler will automatically constify a class
102367 + of types that contain only function pointers. This reduces the
102368 + kernel's attack surface and also produces a better memory layout.
102369 +
102370 + Note that the implementation requires a gcc with plugin support,
102371 + i.e., gcc 4.5 or newer. You may need to install the supporting
102372 + headers explicitly in addition to the normal gcc package.
102373 +
102374 + Note that if some code really has to modify constified variables
102375 + then the source code will have to be patched to allow it. Examples
102376 + can be found in PaX itself (the no_const attribute) and for some
102377 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
102378 +
102379 +config PAX_USERCOPY
102380 + bool "Harden heap object copies between kernel and userland"
102381 + default y if GRKERNSEC_CONFIG_AUTO
102382 + depends on ARM || IA64 || PPC || SPARC || X86
102383 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
102384 + select PAX_USERCOPY_SLABS
102385 + help
102386 + By saying Y here the kernel will enforce the size of heap objects
102387 + when they are copied in either direction between the kernel and
102388 + userland, even if only a part of the heap object is copied.
102389 +
102390 + Specifically, this checking prevents information leaking from the
102391 + kernel heap during kernel to userland copies (if the kernel heap
102392 + object is otherwise fully initialized) and prevents kernel heap
102393 + overflows during userland to kernel copies.
102394 +
102395 + Note that the current implementation provides the strictest bounds
102396 + checks for the SLUB allocator.
102397 +
102398 + Enabling this option also enables per-slab cache protection against
102399 + data in a given cache being copied into/out of via userland
102400 + accessors. Though the whitelist of regions will be reduced over
102401 + time, it notably protects important data structures like task structs.
102402 +
102403 + If frame pointers are enabled on x86, this option will also restrict
102404 + copies into and out of the kernel stack to local variables within a
102405 + single frame.
102406 +
102407 + Since this has a negligible performance impact, you should enable
102408 + this feature.
102409 +
102410 +config PAX_USERCOPY_DEBUG
102411 + bool
102412 + depends on X86 && PAX_USERCOPY
102413 + default n
102414 +
102415 +config PAX_SIZE_OVERFLOW
102416 + bool "Prevent various integer overflows in function size parameters"
102417 + default y if GRKERNSEC_CONFIG_AUTO
102418 + depends on X86
102419 + help
102420 + By saying Y here the kernel recomputes expressions of function
102421 + arguments marked by a size_overflow attribute with double integer
102422 + precision (DImode/TImode for 32/64 bit integer types).
102423 +
102424 + The recomputed argument is checked against TYPE_MAX and an event
102425 + is logged on overflow and the triggering process is killed.
102426 +
102427 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
102428 +
102429 + Note that the implementation requires a gcc with plugin support,
102430 + i.e., gcc 4.5 or newer. You may need to install the supporting
102431 + headers explicitly in addition to the normal gcc package.
102432 +
102433 +config PAX_LATENT_ENTROPY
102434 + bool "Generate some entropy during boot and runtime"
102435 + default y if GRKERNSEC_CONFIG_AUTO
102436 + help
102437 + By saying Y here the kernel will instrument some kernel code to
102438 + extract some entropy from both original and artificially created
102439 + program state. This will help especially embedded systems where
102440 + there is little 'natural' source of entropy normally. The cost
102441 + is some slowdown of the boot process and fork and irq processing.
102442 +
102443 + When pax_extra_latent_entropy is passed on the kernel command line,
102444 + entropy will be extracted from up to the first 4GB of RAM while the
102445 + runtime memory allocator is being initialized. This costs even more
102446 + slowdown of the boot process.
102447 +
102448 + Note that the implementation requires a gcc with plugin support,
102449 + i.e., gcc 4.5 or newer. You may need to install the supporting
102450 + headers explicitly in addition to the normal gcc package.
102451 +
102452 + Note that entropy extracted this way is not cryptographically
102453 + secure!
102454 +
102455 +endmenu
102456 +
102457 +endmenu
102458 +
102459 +source grsecurity/Kconfig
102460 +
102461 +endmenu
102462 +
102463 +endmenu
102464 +
102465 source security/keys/Kconfig
102466
102467 config SECURITY_DMESG_RESTRICT
102468 @@ -103,7 +1055,7 @@ config INTEL_TXT
102469 config LSM_MMAP_MIN_ADDR
102470 int "Low address space for LSM to protect from user allocation"
102471 depends on SECURITY && SECURITY_SELINUX
102472 - default 32768 if ARM
102473 + default 32768 if ALPHA || ARM || PARISC || SPARC32
102474 default 65536
102475 help
102476 This is the portion of low virtual memory which should be protected
102477 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
102478 index 4257b7e..f0c9438 100644
102479 --- a/security/apparmor/lsm.c
102480 +++ b/security/apparmor/lsm.c
102481 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
102482 return error;
102483 }
102484
102485 -static struct security_operations apparmor_ops = {
102486 +static struct security_operations apparmor_ops __read_only = {
102487 .name = "apparmor",
102488
102489 .ptrace_access_check = apparmor_ptrace_access_check,
102490 diff --git a/security/commoncap.c b/security/commoncap.c
102491 index b9d613e..f68305c 100644
102492 --- a/security/commoncap.c
102493 +++ b/security/commoncap.c
102494 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
102495 return 0;
102496 }
102497
102498 +/* returns:
102499 + 1 for suid privilege
102500 + 2 for sgid privilege
102501 + 3 for fscap privilege
102502 +*/
102503 +int is_privileged_binary(const struct dentry *dentry)
102504 +{
102505 + struct cpu_vfs_cap_data capdata;
102506 + struct inode *inode = dentry->d_inode;
102507 +
102508 + if (!inode || S_ISDIR(inode->i_mode))
102509 + return 0;
102510 +
102511 + if (inode->i_mode & S_ISUID)
102512 + return 1;
102513 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
102514 + return 2;
102515 +
102516 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
102517 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
102518 + return 3;
102519 + }
102520 +
102521 + return 0;
102522 +}
102523 +
102524 /*
102525 * Attempt to get the on-exec apply capability sets for an executable file from
102526 * its xattrs and, if present, apply them to the proposed credentials being
102527 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
102528 const struct cred *cred = current_cred();
102529 kuid_t root_uid = make_kuid(cred->user_ns, 0);
102530
102531 + if (gr_acl_enable_at_secure())
102532 + return 1;
102533 +
102534 if (!uid_eq(cred->uid, root_uid)) {
102535 if (bprm->cap_effective)
102536 return 1;
102537 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
102538 index 0356e1d..72332ab 100644
102539 --- a/security/integrity/ima/ima.h
102540 +++ b/security/integrity/ima/ima.h
102541 @@ -118,8 +118,8 @@ int ima_init_template(void);
102542 extern spinlock_t ima_queue_lock;
102543
102544 struct ima_h_table {
102545 - atomic_long_t len; /* number of stored measurements in the list */
102546 - atomic_long_t violations;
102547 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
102548 + atomic_long_unchecked_t violations;
102549 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
102550 };
102551 extern struct ima_h_table ima_htable;
102552 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
102553 index c38bbce..f45133d 100644
102554 --- a/security/integrity/ima/ima_api.c
102555 +++ b/security/integrity/ima/ima_api.c
102556 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
102557 int result;
102558
102559 /* can overflow, only indicator */
102560 - atomic_long_inc(&ima_htable.violations);
102561 + atomic_long_inc_unchecked(&ima_htable.violations);
102562
102563 result = ima_alloc_init_template(NULL, file, filename,
102564 NULL, 0, &entry);
102565 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
102566 index db01125..61f6597 100644
102567 --- a/security/integrity/ima/ima_fs.c
102568 +++ b/security/integrity/ima/ima_fs.c
102569 @@ -28,12 +28,12 @@
102570 static int valid_policy = 1;
102571 #define TMPBUFLEN 12
102572 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
102573 - loff_t *ppos, atomic_long_t *val)
102574 + loff_t *ppos, atomic_long_unchecked_t *val)
102575 {
102576 char tmpbuf[TMPBUFLEN];
102577 ssize_t len;
102578
102579 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
102580 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
102581 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
102582 }
102583
102584 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
102585 index d85e997..6992813 100644
102586 --- a/security/integrity/ima/ima_queue.c
102587 +++ b/security/integrity/ima/ima_queue.c
102588 @@ -80,7 +80,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
102589 INIT_LIST_HEAD(&qe->later);
102590 list_add_tail_rcu(&qe->later, &ima_measurements);
102591
102592 - atomic_long_inc(&ima_htable.len);
102593 + atomic_long_inc_unchecked(&ima_htable.len);
102594 key = ima_hash_key(entry->digest);
102595 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
102596 return 0;
102597 diff --git a/security/keys/compat.c b/security/keys/compat.c
102598 index bbd32c7..c60c927 100644
102599 --- a/security/keys/compat.c
102600 +++ b/security/keys/compat.c
102601 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
102602 if (ret == 0)
102603 goto no_payload_free;
102604
102605 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
102606 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
102607 err:
102608 if (iov != iovstack)
102609 kfree(iov);
102610 diff --git a/security/keys/internal.h b/security/keys/internal.h
102611 index 80b2aac..bb7ee65 100644
102612 --- a/security/keys/internal.h
102613 +++ b/security/keys/internal.h
102614 @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
102615 extern long keyctl_invalidate_key(key_serial_t);
102616
102617 extern long keyctl_instantiate_key_common(key_serial_t,
102618 - const struct iovec *,
102619 + const struct iovec __user *,
102620 unsigned, size_t, key_serial_t);
102621 #ifdef CONFIG_PERSISTENT_KEYRINGS
102622 extern long keyctl_get_persistent(uid_t, key_serial_t);
102623 diff --git a/security/keys/key.c b/security/keys/key.c
102624 index 6e21c11..9ed67ca 100644
102625 --- a/security/keys/key.c
102626 +++ b/security/keys/key.c
102627 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
102628
102629 atomic_set(&key->usage, 1);
102630 init_rwsem(&key->sem);
102631 - lockdep_set_class(&key->sem, &type->lock_class);
102632 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
102633 key->index_key.type = type;
102634 key->user = user;
102635 key->quotalen = quotalen;
102636 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
102637 struct key_type *p;
102638 int ret;
102639
102640 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
102641 + pax_open_kernel();
102642 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
102643 + pax_close_kernel();
102644
102645 ret = -EEXIST;
102646 down_write(&key_types_sem);
102647 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
102648 }
102649
102650 /* store the type */
102651 - list_add(&ktype->link, &key_types_list);
102652 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
102653
102654 pr_notice("Key type %s registered\n", ktype->name);
102655 ret = 0;
102656 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
102657 void unregister_key_type(struct key_type *ktype)
102658 {
102659 down_write(&key_types_sem);
102660 - list_del_init(&ktype->link);
102661 + pax_list_del_init((struct list_head *)&ktype->link);
102662 downgrade_write(&key_types_sem);
102663 key_gc_keytype(ktype);
102664 pr_notice("Key type %s unregistered\n", ktype->name);
102665 @@ -1088,10 +1090,10 @@ void __init key_init(void)
102666 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
102667
102668 /* add the special key types */
102669 - list_add_tail(&key_type_keyring.link, &key_types_list);
102670 - list_add_tail(&key_type_dead.link, &key_types_list);
102671 - list_add_tail(&key_type_user.link, &key_types_list);
102672 - list_add_tail(&key_type_logon.link, &key_types_list);
102673 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
102674 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
102675 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
102676 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
102677
102678 /* record the root user tracking */
102679 rb_link_node(&root_key_user.node,
102680 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
102681 index cee72ce..e46074a 100644
102682 --- a/security/keys/keyctl.c
102683 +++ b/security/keys/keyctl.c
102684 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
102685 /*
102686 * Copy the iovec data from userspace
102687 */
102688 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
102689 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
102690 unsigned ioc)
102691 {
102692 for (; ioc > 0; ioc--) {
102693 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
102694 * If successful, 0 will be returned.
102695 */
102696 long keyctl_instantiate_key_common(key_serial_t id,
102697 - const struct iovec *payload_iov,
102698 + const struct iovec __user *payload_iov,
102699 unsigned ioc,
102700 size_t plen,
102701 key_serial_t ringid)
102702 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
102703 [0].iov_len = plen
102704 };
102705
102706 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
102707 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
102708 }
102709
102710 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
102711 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
102712 if (ret == 0)
102713 goto no_payload_free;
102714
102715 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
102716 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
102717 err:
102718 if (iov != iovstack)
102719 kfree(iov);
102720 diff --git a/security/min_addr.c b/security/min_addr.c
102721 index f728728..6457a0c 100644
102722 --- a/security/min_addr.c
102723 +++ b/security/min_addr.c
102724 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
102725 */
102726 static void update_mmap_min_addr(void)
102727 {
102728 +#ifndef SPARC
102729 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
102730 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
102731 mmap_min_addr = dac_mmap_min_addr;
102732 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
102733 #else
102734 mmap_min_addr = dac_mmap_min_addr;
102735 #endif
102736 +#endif
102737 }
102738
102739 /*
102740 diff --git a/security/security.c b/security/security.c
102741 index 15b6928..60d03ec 100644
102742 --- a/security/security.c
102743 +++ b/security/security.c
102744 @@ -33,8 +33,8 @@
102745 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
102746 CONFIG_DEFAULT_SECURITY;
102747
102748 -static struct security_operations *security_ops;
102749 -static struct security_operations default_security_ops = {
102750 +struct security_operations *security_ops __read_only;
102751 +struct security_operations default_security_ops __read_only = {
102752 .name = "default",
102753 };
102754
102755 @@ -73,11 +73,6 @@ int __init security_init(void)
102756 return 0;
102757 }
102758
102759 -void reset_security_ops(void)
102760 -{
102761 - security_ops = &default_security_ops;
102762 -}
102763 -
102764 /* Save user chosen LSM */
102765 static int __init choose_lsm(char *str)
102766 {
102767 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
102768 index fc3e662..7844c60 100644
102769 --- a/security/selinux/avc.c
102770 +++ b/security/selinux/avc.c
102771 @@ -59,7 +59,7 @@ struct avc_node {
102772 struct avc_cache {
102773 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
102774 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
102775 - atomic_t lru_hint; /* LRU hint for reclaim scan */
102776 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
102777 atomic_t active_nodes;
102778 u32 latest_notif; /* latest revocation notification */
102779 };
102780 @@ -167,7 +167,7 @@ void __init avc_init(void)
102781 spin_lock_init(&avc_cache.slots_lock[i]);
102782 }
102783 atomic_set(&avc_cache.active_nodes, 0);
102784 - atomic_set(&avc_cache.lru_hint, 0);
102785 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
102786
102787 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
102788 0, SLAB_PANIC, NULL);
102789 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
102790 spinlock_t *lock;
102791
102792 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
102793 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
102794 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
102795 head = &avc_cache.slots[hvalue];
102796 lock = &avc_cache.slots_lock[hvalue];
102797
102798 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
102799 index 57b0b49..402063e 100644
102800 --- a/security/selinux/hooks.c
102801 +++ b/security/selinux/hooks.c
102802 @@ -96,8 +96,6 @@
102803 #include "audit.h"
102804 #include "avc_ss.h"
102805
102806 -extern struct security_operations *security_ops;
102807 -
102808 /* SECMARK reference count */
102809 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
102810
102811 @@ -5745,7 +5743,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
102812
102813 #endif
102814
102815 -static struct security_operations selinux_ops = {
102816 +static struct security_operations selinux_ops __read_only = {
102817 .name = "selinux",
102818
102819 .ptrace_access_check = selinux_ptrace_access_check,
102820 @@ -6098,6 +6096,9 @@ static void selinux_nf_ip_exit(void)
102821 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
102822 static int selinux_disabled;
102823
102824 +extern struct security_operations *security_ops;
102825 +extern struct security_operations default_security_ops;
102826 +
102827 int selinux_disable(void)
102828 {
102829 if (ss_initialized) {
102830 @@ -6115,7 +6116,9 @@ int selinux_disable(void)
102831 selinux_disabled = 1;
102832 selinux_enabled = 0;
102833
102834 - reset_security_ops();
102835 + pax_open_kernel();
102836 + security_ops = &default_security_ops;
102837 + pax_close_kernel();
102838
102839 /* Try to destroy the avc node cache */
102840 avc_disable();
102841 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
102842 index 48c3cc9..8022cf7 100644
102843 --- a/security/selinux/include/xfrm.h
102844 +++ b/security/selinux/include/xfrm.h
102845 @@ -45,7 +45,7 @@ static inline void selinux_xfrm_notify_policyload(void)
102846 {
102847 struct net *net;
102848
102849 - atomic_inc(&flow_cache_genid);
102850 + atomic_inc_unchecked(&flow_cache_genid);
102851 rtnl_lock();
102852 for_each_net(net)
102853 rt_genid_bump_all(net);
102854 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
102855 index b0be893..646bd94 100644
102856 --- a/security/smack/smack_lsm.c
102857 +++ b/security/smack/smack_lsm.c
102858 @@ -3731,7 +3731,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
102859 return 0;
102860 }
102861
102862 -struct security_operations smack_ops = {
102863 +struct security_operations smack_ops __read_only = {
102864 .name = "smack",
102865
102866 .ptrace_access_check = smack_ptrace_access_check,
102867 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
102868 index 390c646..f2f8db3 100644
102869 --- a/security/tomoyo/mount.c
102870 +++ b/security/tomoyo/mount.c
102871 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
102872 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
102873 need_dev = -1; /* dev_name is a directory */
102874 } else {
102875 + if (!capable(CAP_SYS_ADMIN)) {
102876 + error = -EPERM;
102877 + goto out;
102878 + }
102879 fstype = get_fs_type(type);
102880 if (!fstype) {
102881 error = -ENODEV;
102882 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
102883 index f0b756e..b129202 100644
102884 --- a/security/tomoyo/tomoyo.c
102885 +++ b/security/tomoyo/tomoyo.c
102886 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
102887 * tomoyo_security_ops is a "struct security_operations" which is used for
102888 * registering TOMOYO.
102889 */
102890 -static struct security_operations tomoyo_security_ops = {
102891 +static struct security_operations tomoyo_security_ops __read_only = {
102892 .name = "tomoyo",
102893 .cred_alloc_blank = tomoyo_cred_alloc_blank,
102894 .cred_prepare = tomoyo_cred_prepare,
102895 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
102896 index 20ef514..4182bed 100644
102897 --- a/security/yama/Kconfig
102898 +++ b/security/yama/Kconfig
102899 @@ -1,6 +1,6 @@
102900 config SECURITY_YAMA
102901 bool "Yama support"
102902 - depends on SECURITY
102903 + depends on SECURITY && !GRKERNSEC
102904 select SECURITYFS
102905 select SECURITY_PATH
102906 default n
102907 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
102908 index 13c88fbc..f8c115e 100644
102909 --- a/security/yama/yama_lsm.c
102910 +++ b/security/yama/yama_lsm.c
102911 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
102912 }
102913
102914 #ifndef CONFIG_SECURITY_YAMA_STACKED
102915 -static struct security_operations yama_ops = {
102916 +static struct security_operations yama_ops __read_only = {
102917 .name = "yama",
102918
102919 .ptrace_access_check = yama_ptrace_access_check,
102920 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
102921 #endif
102922
102923 #ifdef CONFIG_SYSCTL
102924 +static int zero __read_only;
102925 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
102926 +
102927 static int yama_dointvec_minmax(struct ctl_table *table, int write,
102928 void __user *buffer, size_t *lenp, loff_t *ppos)
102929 {
102930 - int rc;
102931 + ctl_table_no_const yama_table;
102932
102933 if (write && !capable(CAP_SYS_PTRACE))
102934 return -EPERM;
102935
102936 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
102937 - if (rc)
102938 - return rc;
102939 -
102940 + yama_table = *table;
102941 /* Lock the max value if it ever gets set. */
102942 - if (write && *(int *)table->data == *(int *)table->extra2)
102943 - table->extra1 = table->extra2;
102944 -
102945 - return rc;
102946 + if (ptrace_scope == max_scope)
102947 + yama_table.extra1 = &max_scope;
102948 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
102949 }
102950
102951 -static int zero;
102952 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
102953 -
102954 struct ctl_path yama_sysctl_path[] = {
102955 { .procname = "kernel", },
102956 { .procname = "yama", },
102957 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
102958 index 4cedc69..e59d8a3 100644
102959 --- a/sound/aoa/codecs/onyx.c
102960 +++ b/sound/aoa/codecs/onyx.c
102961 @@ -54,7 +54,7 @@ struct onyx {
102962 spdif_locked:1,
102963 analog_locked:1,
102964 original_mute:2;
102965 - int open_count;
102966 + local_t open_count;
102967 struct codec_info *codec_info;
102968
102969 /* mutex serializes concurrent access to the device
102970 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
102971 struct onyx *onyx = cii->codec_data;
102972
102973 mutex_lock(&onyx->mutex);
102974 - onyx->open_count++;
102975 + local_inc(&onyx->open_count);
102976 mutex_unlock(&onyx->mutex);
102977
102978 return 0;
102979 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
102980 struct onyx *onyx = cii->codec_data;
102981
102982 mutex_lock(&onyx->mutex);
102983 - onyx->open_count--;
102984 - if (!onyx->open_count)
102985 + if (local_dec_and_test(&onyx->open_count))
102986 onyx->spdif_locked = onyx->analog_locked = 0;
102987 mutex_unlock(&onyx->mutex);
102988
102989 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
102990 index ffd2025..df062c9 100644
102991 --- a/sound/aoa/codecs/onyx.h
102992 +++ b/sound/aoa/codecs/onyx.h
102993 @@ -11,6 +11,7 @@
102994 #include <linux/i2c.h>
102995 #include <asm/pmac_low_i2c.h>
102996 #include <asm/prom.h>
102997 +#include <asm/local.h>
102998
102999 /* PCM3052 register definitions */
103000
103001 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
103002 index 4c1cc51..16040040 100644
103003 --- a/sound/core/oss/pcm_oss.c
103004 +++ b/sound/core/oss/pcm_oss.c
103005 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
103006 if (in_kernel) {
103007 mm_segment_t fs;
103008 fs = snd_enter_user();
103009 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
103010 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
103011 snd_leave_user(fs);
103012 } else {
103013 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
103014 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
103015 }
103016 if (ret != -EPIPE && ret != -ESTRPIPE)
103017 break;
103018 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
103019 if (in_kernel) {
103020 mm_segment_t fs;
103021 fs = snd_enter_user();
103022 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
103023 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
103024 snd_leave_user(fs);
103025 } else {
103026 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
103027 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
103028 }
103029 if (ret == -EPIPE) {
103030 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
103031 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
103032 struct snd_pcm_plugin_channel *channels;
103033 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
103034 if (!in_kernel) {
103035 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
103036 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
103037 return -EFAULT;
103038 buf = runtime->oss.buffer;
103039 }
103040 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
103041 }
103042 } else {
103043 tmp = snd_pcm_oss_write2(substream,
103044 - (const char __force *)buf,
103045 + (const char __force_kernel *)buf,
103046 runtime->oss.period_bytes, 0);
103047 if (tmp <= 0)
103048 goto err;
103049 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
103050 struct snd_pcm_runtime *runtime = substream->runtime;
103051 snd_pcm_sframes_t frames, frames1;
103052 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
103053 - char __user *final_dst = (char __force __user *)buf;
103054 + char __user *final_dst = (char __force_user *)buf;
103055 if (runtime->oss.plugin_first) {
103056 struct snd_pcm_plugin_channel *channels;
103057 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
103058 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
103059 xfer += tmp;
103060 runtime->oss.buffer_used -= tmp;
103061 } else {
103062 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
103063 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
103064 runtime->oss.period_bytes, 0);
103065 if (tmp <= 0)
103066 goto err;
103067 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
103068 size1);
103069 size1 /= runtime->channels; /* frames */
103070 fs = snd_enter_user();
103071 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
103072 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
103073 snd_leave_user(fs);
103074 }
103075 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
103076 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
103077 index af49721..e85058e 100644
103078 --- a/sound/core/pcm_compat.c
103079 +++ b/sound/core/pcm_compat.c
103080 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
103081 int err;
103082
103083 fs = snd_enter_user();
103084 - err = snd_pcm_delay(substream, &delay);
103085 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
103086 snd_leave_user(fs);
103087 if (err < 0)
103088 return err;
103089 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
103090 index 01a5e05..c6bb425 100644
103091 --- a/sound/core/pcm_native.c
103092 +++ b/sound/core/pcm_native.c
103093 @@ -2811,11 +2811,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
103094 switch (substream->stream) {
103095 case SNDRV_PCM_STREAM_PLAYBACK:
103096 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
103097 - (void __user *)arg);
103098 + (void __force_user *)arg);
103099 break;
103100 case SNDRV_PCM_STREAM_CAPTURE:
103101 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
103102 - (void __user *)arg);
103103 + (void __force_user *)arg);
103104 break;
103105 default:
103106 result = -EINVAL;
103107 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
103108 index 8d4d5e8..fdd0826 100644
103109 --- a/sound/core/seq/oss/seq_oss.c
103110 +++ b/sound/core/seq/oss/seq_oss.c
103111 @@ -75,8 +75,8 @@ static int __init alsa_seq_oss_init(void)
103112 {
103113 int rc;
103114 static struct snd_seq_dev_ops ops = {
103115 - snd_seq_oss_synth_register,
103116 - snd_seq_oss_synth_unregister,
103117 + .init_device = snd_seq_oss_synth_register,
103118 + .free_device = snd_seq_oss_synth_unregister,
103119 };
103120
103121 snd_seq_autoload_lock();
103122 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
103123 index 040c60e..989a19a 100644
103124 --- a/sound/core/seq/seq_device.c
103125 +++ b/sound/core/seq/seq_device.c
103126 @@ -64,7 +64,7 @@ struct ops_list {
103127 int argsize; /* argument size */
103128
103129 /* operators */
103130 - struct snd_seq_dev_ops ops;
103131 + struct snd_seq_dev_ops *ops;
103132
103133 /* registered devices */
103134 struct list_head dev_list; /* list of devices */
103135 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
103136
103137 mutex_lock(&ops->reg_mutex);
103138 /* copy driver operators */
103139 - ops->ops = *entry;
103140 + ops->ops = entry;
103141 ops->driver |= DRIVER_LOADED;
103142 ops->argsize = argsize;
103143
103144 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
103145 dev->name, ops->id, ops->argsize, dev->argsize);
103146 return -EINVAL;
103147 }
103148 - if (ops->ops.init_device(dev) >= 0) {
103149 + if (ops->ops->init_device(dev) >= 0) {
103150 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
103151 ops->num_init_devices++;
103152 } else {
103153 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
103154 dev->name, ops->id, ops->argsize, dev->argsize);
103155 return -EINVAL;
103156 }
103157 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
103158 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
103159 dev->status = SNDRV_SEQ_DEVICE_FREE;
103160 dev->driver_data = NULL;
103161 ops->num_init_devices--;
103162 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
103163 index 64069db..3c6d392 100644
103164 --- a/sound/core/seq/seq_midi.c
103165 +++ b/sound/core/seq/seq_midi.c
103166 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
103167 static int __init alsa_seq_midi_init(void)
103168 {
103169 static struct snd_seq_dev_ops ops = {
103170 - snd_seq_midisynth_register_port,
103171 - snd_seq_midisynth_unregister_port,
103172 + .init_device = snd_seq_midisynth_register_port,
103173 + .free_device = snd_seq_midisynth_unregister_port,
103174 };
103175 memset(&synths, 0, sizeof(synths));
103176 snd_seq_autoload_lock();
103177 diff --git a/sound/core/sound.c b/sound/core/sound.c
103178 index 437c25e..cd040ab 100644
103179 --- a/sound/core/sound.c
103180 +++ b/sound/core/sound.c
103181 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
103182 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
103183 default: return;
103184 }
103185 - request_module(str);
103186 + request_module("%s", str);
103187 }
103188
103189 #endif /* modular kernel */
103190 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
103191 index 4e0dd22..7a1f32c 100644
103192 --- a/sound/drivers/mts64.c
103193 +++ b/sound/drivers/mts64.c
103194 @@ -29,6 +29,7 @@
103195 #include <sound/initval.h>
103196 #include <sound/rawmidi.h>
103197 #include <sound/control.h>
103198 +#include <asm/local.h>
103199
103200 #define CARD_NAME "Miditerminal 4140"
103201 #define DRIVER_NAME "MTS64"
103202 @@ -67,7 +68,7 @@ struct mts64 {
103203 struct pardevice *pardev;
103204 int pardev_claimed;
103205
103206 - int open_count;
103207 + local_t open_count;
103208 int current_midi_output_port;
103209 int current_midi_input_port;
103210 u8 mode[MTS64_NUM_INPUT_PORTS];
103211 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
103212 {
103213 struct mts64 *mts = substream->rmidi->private_data;
103214
103215 - if (mts->open_count == 0) {
103216 + if (local_read(&mts->open_count) == 0) {
103217 /* We don't need a spinlock here, because this is just called
103218 if the device has not been opened before.
103219 So there aren't any IRQs from the device */
103220 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
103221
103222 msleep(50);
103223 }
103224 - ++(mts->open_count);
103225 + local_inc(&mts->open_count);
103226
103227 return 0;
103228 }
103229 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
103230 struct mts64 *mts = substream->rmidi->private_data;
103231 unsigned long flags;
103232
103233 - --(mts->open_count);
103234 - if (mts->open_count == 0) {
103235 + if (local_dec_return(&mts->open_count) == 0) {
103236 /* We need the spinlock_irqsave here because we can still
103237 have IRQs at this point */
103238 spin_lock_irqsave(&mts->lock, flags);
103239 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
103240
103241 msleep(500);
103242
103243 - } else if (mts->open_count < 0)
103244 - mts->open_count = 0;
103245 + } else if (local_read(&mts->open_count) < 0)
103246 + local_set(&mts->open_count, 0);
103247
103248 return 0;
103249 }
103250 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
103251 index 6839953..7a0f4b9 100644
103252 --- a/sound/drivers/opl3/opl3_seq.c
103253 +++ b/sound/drivers/opl3/opl3_seq.c
103254 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
103255 {
103256 static struct snd_seq_dev_ops ops =
103257 {
103258 - snd_opl3_seq_new_device,
103259 - snd_opl3_seq_delete_device
103260 + .init_device = snd_opl3_seq_new_device,
103261 + .free_device = snd_opl3_seq_delete_device
103262 };
103263
103264 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
103265 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
103266 index b953fb4..1999c01 100644
103267 --- a/sound/drivers/opl4/opl4_lib.c
103268 +++ b/sound/drivers/opl4/opl4_lib.c
103269 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
103270 MODULE_DESCRIPTION("OPL4 driver");
103271 MODULE_LICENSE("GPL");
103272
103273 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
103274 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
103275 {
103276 int timeout = 10;
103277 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
103278 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
103279 index 9919769..d7de36c 100644
103280 --- a/sound/drivers/opl4/opl4_seq.c
103281 +++ b/sound/drivers/opl4/opl4_seq.c
103282 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
103283 static int __init alsa_opl4_synth_init(void)
103284 {
103285 static struct snd_seq_dev_ops ops = {
103286 - snd_opl4_seq_new_device,
103287 - snd_opl4_seq_delete_device
103288 + .init_device = snd_opl4_seq_new_device,
103289 + .free_device = snd_opl4_seq_delete_device
103290 };
103291
103292 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
103293 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
103294 index 991018d..8984740 100644
103295 --- a/sound/drivers/portman2x4.c
103296 +++ b/sound/drivers/portman2x4.c
103297 @@ -48,6 +48,7 @@
103298 #include <sound/initval.h>
103299 #include <sound/rawmidi.h>
103300 #include <sound/control.h>
103301 +#include <asm/local.h>
103302
103303 #define CARD_NAME "Portman 2x4"
103304 #define DRIVER_NAME "portman"
103305 @@ -85,7 +86,7 @@ struct portman {
103306 struct pardevice *pardev;
103307 int pardev_claimed;
103308
103309 - int open_count;
103310 + local_t open_count;
103311 int mode[PORTMAN_NUM_INPUT_PORTS];
103312 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
103313 };
103314 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
103315 index 9048777..2d8b1fc 100644
103316 --- a/sound/firewire/amdtp.c
103317 +++ b/sound/firewire/amdtp.c
103318 @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
103319 ptr = s->pcm_buffer_pointer + data_blocks;
103320 if (ptr >= pcm->runtime->buffer_size)
103321 ptr -= pcm->runtime->buffer_size;
103322 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
103323 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
103324
103325 s->pcm_period_pointer += data_blocks;
103326 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
103327 @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
103328 */
103329 void amdtp_out_stream_update(struct amdtp_out_stream *s)
103330 {
103331 - ACCESS_ONCE(s->source_node_id_field) =
103332 + ACCESS_ONCE_RW(s->source_node_id_field) =
103333 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
103334 }
103335 EXPORT_SYMBOL(amdtp_out_stream_update);
103336 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
103337 index 2746ecd..c35dedd 100644
103338 --- a/sound/firewire/amdtp.h
103339 +++ b/sound/firewire/amdtp.h
103340 @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
103341 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
103342 struct snd_pcm_substream *pcm)
103343 {
103344 - ACCESS_ONCE(s->pcm) = pcm;
103345 + ACCESS_ONCE_RW(s->pcm) = pcm;
103346 }
103347
103348 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
103349 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
103350 index fd42e6b..c041971 100644
103351 --- a/sound/firewire/isight.c
103352 +++ b/sound/firewire/isight.c
103353 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
103354 ptr += count;
103355 if (ptr >= runtime->buffer_size)
103356 ptr -= runtime->buffer_size;
103357 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
103358 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
103359
103360 isight->period_counter += count;
103361 if (isight->period_counter >= runtime->period_size) {
103362 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
103363 if (err < 0)
103364 return err;
103365
103366 - ACCESS_ONCE(isight->pcm_active) = true;
103367 + ACCESS_ONCE_RW(isight->pcm_active) = true;
103368
103369 return 0;
103370 }
103371 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
103372 {
103373 struct isight *isight = substream->private_data;
103374
103375 - ACCESS_ONCE(isight->pcm_active) = false;
103376 + ACCESS_ONCE_RW(isight->pcm_active) = false;
103377
103378 mutex_lock(&isight->mutex);
103379 isight_stop_streaming(isight);
103380 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
103381
103382 switch (cmd) {
103383 case SNDRV_PCM_TRIGGER_START:
103384 - ACCESS_ONCE(isight->pcm_running) = true;
103385 + ACCESS_ONCE_RW(isight->pcm_running) = true;
103386 break;
103387 case SNDRV_PCM_TRIGGER_STOP:
103388 - ACCESS_ONCE(isight->pcm_running) = false;
103389 + ACCESS_ONCE_RW(isight->pcm_running) = false;
103390 break;
103391 default:
103392 return -EINVAL;
103393 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
103394 index 858023c..83b3d3c 100644
103395 --- a/sound/firewire/scs1x.c
103396 +++ b/sound/firewire/scs1x.c
103397 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
103398 {
103399 struct scs *scs = stream->rmidi->private_data;
103400
103401 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
103402 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
103403 if (up) {
103404 scs->output_idle = false;
103405 tasklet_schedule(&scs->tasklet);
103406 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
103407 {
103408 struct scs *scs = stream->rmidi->private_data;
103409
103410 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
103411 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
103412 }
103413
103414 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
103415 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
103416
103417 snd_card_disconnect(scs->card);
103418
103419 - ACCESS_ONCE(scs->output) = NULL;
103420 - ACCESS_ONCE(scs->input) = NULL;
103421 + ACCESS_ONCE_RW(scs->output) = NULL;
103422 + ACCESS_ONCE_RW(scs->input) = NULL;
103423
103424 wait_event(scs->idle_wait, scs->output_idle);
103425
103426 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
103427 index 4e3fcfb..ab45a9d 100644
103428 --- a/sound/isa/sb/emu8000_synth.c
103429 +++ b/sound/isa/sb/emu8000_synth.c
103430 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
103431 {
103432
103433 static struct snd_seq_dev_ops ops = {
103434 - snd_emu8000_new_device,
103435 - snd_emu8000_delete_device,
103436 + .init_device = snd_emu8000_new_device,
103437 + .free_device = snd_emu8000_delete_device,
103438 };
103439 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
103440 sizeof(struct snd_emu8000*));
103441 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
103442 index 048439a..3be9f6f 100644
103443 --- a/sound/oss/sb_audio.c
103444 +++ b/sound/oss/sb_audio.c
103445 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
103446 buf16 = (signed short *)(localbuf + localoffs);
103447 while (c)
103448 {
103449 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
103450 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
103451 if (copy_from_user(lbuf8,
103452 userbuf+useroffs + p,
103453 locallen))
103454 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
103455 index 7d8803a..559f8d0 100644
103456 --- a/sound/oss/swarm_cs4297a.c
103457 +++ b/sound/oss/swarm_cs4297a.c
103458 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
103459 {
103460 struct cs4297a_state *s;
103461 u32 pwr, id;
103462 - mm_segment_t fs;
103463 int rval;
103464 #ifndef CONFIG_BCM_CS4297A_CSWARM
103465 u64 cfg;
103466 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
103467 if (!rval) {
103468 char *sb1250_duart_present;
103469
103470 +#if 0
103471 + mm_segment_t fs;
103472 fs = get_fs();
103473 set_fs(KERNEL_DS);
103474 -#if 0
103475 val = SOUND_MASK_LINE;
103476 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
103477 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
103478 val = initvol[i].vol;
103479 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
103480 }
103481 + set_fs(fs);
103482 // cs4297a_write_ac97(s, 0x18, 0x0808);
103483 #else
103484 // cs4297a_write_ac97(s, 0x5e, 0x180);
103485 cs4297a_write_ac97(s, 0x02, 0x0808);
103486 cs4297a_write_ac97(s, 0x18, 0x0808);
103487 #endif
103488 - set_fs(fs);
103489
103490 list_add(&s->list, &cs4297a_devs);
103491
103492 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
103493 index 4c41c90..37f3631 100644
103494 --- a/sound/pci/emu10k1/emu10k1_synth.c
103495 +++ b/sound/pci/emu10k1/emu10k1_synth.c
103496 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
103497 {
103498
103499 static struct snd_seq_dev_ops ops = {
103500 - snd_emu10k1_synth_new_device,
103501 - snd_emu10k1_synth_delete_device,
103502 + .init_device = snd_emu10k1_synth_new_device,
103503 + .free_device = snd_emu10k1_synth_delete_device,
103504 };
103505 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
103506 sizeof(struct snd_emu10k1_synth_arg));
103507 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
103508 index 69178c4..4493d52 100644
103509 --- a/sound/pci/hda/hda_codec.c
103510 +++ b/sound/pci/hda/hda_codec.c
103511 @@ -976,14 +976,10 @@ find_codec_preset(struct hda_codec *codec)
103512 mutex_unlock(&preset_mutex);
103513
103514 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
103515 - char name[32];
103516 if (!mod_requested)
103517 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
103518 - codec->vendor_id);
103519 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
103520 else
103521 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
103522 - (codec->vendor_id >> 16) & 0xffff);
103523 - request_module(name);
103524 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
103525 mod_requested++;
103526 goto again;
103527 }
103528 @@ -2668,7 +2664,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
103529 /* FIXME: set_fs() hack for obtaining user-space TLV data */
103530 mm_segment_t fs = get_fs();
103531 set_fs(get_ds());
103532 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
103533 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
103534 tlv = _tlv;
103535 set_fs(fs);
103536 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
103537 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
103538 index 4631a23..001ae57 100644
103539 --- a/sound/pci/ymfpci/ymfpci.h
103540 +++ b/sound/pci/ymfpci/ymfpci.h
103541 @@ -358,7 +358,7 @@ struct snd_ymfpci {
103542 spinlock_t reg_lock;
103543 spinlock_t voice_lock;
103544 wait_queue_head_t interrupt_sleep;
103545 - atomic_t interrupt_sleep_count;
103546 + atomic_unchecked_t interrupt_sleep_count;
103547 struct snd_info_entry *proc_entry;
103548 const struct firmware *dsp_microcode;
103549 const struct firmware *controller_microcode;
103550 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
103551 index d591c15..8cb8f94 100644
103552 --- a/sound/pci/ymfpci/ymfpci_main.c
103553 +++ b/sound/pci/ymfpci/ymfpci_main.c
103554 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
103555 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
103556 break;
103557 }
103558 - if (atomic_read(&chip->interrupt_sleep_count)) {
103559 - atomic_set(&chip->interrupt_sleep_count, 0);
103560 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
103561 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
103562 wake_up(&chip->interrupt_sleep);
103563 }
103564 __end:
103565 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
103566 continue;
103567 init_waitqueue_entry(&wait, current);
103568 add_wait_queue(&chip->interrupt_sleep, &wait);
103569 - atomic_inc(&chip->interrupt_sleep_count);
103570 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
103571 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
103572 remove_wait_queue(&chip->interrupt_sleep, &wait);
103573 }
103574 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
103575 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
103576 spin_unlock(&chip->reg_lock);
103577
103578 - if (atomic_read(&chip->interrupt_sleep_count)) {
103579 - atomic_set(&chip->interrupt_sleep_count, 0);
103580 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
103581 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
103582 wake_up(&chip->interrupt_sleep);
103583 }
103584 }
103585 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
103586 spin_lock_init(&chip->reg_lock);
103587 spin_lock_init(&chip->voice_lock);
103588 init_waitqueue_head(&chip->interrupt_sleep);
103589 - atomic_set(&chip->interrupt_sleep_count, 0);
103590 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
103591 chip->card = card;
103592 chip->pci = pci;
103593 chip->irq = -1;
103594 diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
103595 index 35e2773..6d6ceee 100644
103596 --- a/sound/soc/fsl/fsl_ssi.c
103597 +++ b/sound/soc/fsl/fsl_ssi.c
103598 @@ -857,7 +857,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
103599 {
103600 struct fsl_ssi_private *ssi_private;
103601 int ret = 0;
103602 - struct device_attribute *dev_attr = NULL;
103603 + device_attribute_no_const *dev_attr = NULL;
103604 struct device_node *np = pdev->dev.of_node;
103605 const char *p, *sprop;
103606 const uint32_t *iprop;
103607 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
103608 index a66783e..ed1d791 100644
103609 --- a/sound/soc/soc-core.c
103610 +++ b/sound/soc/soc-core.c
103611 @@ -2253,8 +2253,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
103612 if (ret)
103613 return ret;
103614
103615 - ops->warm_reset = snd_soc_ac97_warm_reset;
103616 - ops->reset = snd_soc_ac97_reset;
103617 + pax_open_kernel();
103618 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
103619 + *(void **)&ops->reset = snd_soc_ac97_reset;
103620 + pax_close_kernel();
103621
103622 snd_ac97_rst_cfg = cfg;
103623 return 0;
103624 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
103625 index 7778b8e..3d619fc 100644
103626 --- a/sound/synth/emux/emux_seq.c
103627 +++ b/sound/synth/emux/emux_seq.c
103628 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
103629 * MIDI emulation operators
103630 */
103631 static struct snd_midi_op emux_ops = {
103632 - snd_emux_note_on,
103633 - snd_emux_note_off,
103634 - snd_emux_key_press,
103635 - snd_emux_terminate_note,
103636 - snd_emux_control,
103637 - snd_emux_nrpn,
103638 - snd_emux_sysex,
103639 + .note_on = snd_emux_note_on,
103640 + .note_off = snd_emux_note_off,
103641 + .key_press = snd_emux_key_press,
103642 + .note_terminate = snd_emux_terminate_note,
103643 + .control = snd_emux_control,
103644 + .nrpn = snd_emux_nrpn,
103645 + .sysex = snd_emux_sysex,
103646 };
103647
103648
103649 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
103650 new file mode 100644
103651 index 0000000..8eb55ca
103652 --- /dev/null
103653 +++ b/tools/gcc/.gitignore
103654 @@ -0,0 +1,3 @@
103655 +size_overflow_hash.h
103656 +randstruct.seed
103657 +randstruct.hashed_seed
103658 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
103659 new file mode 100644
103660 index 0000000..f8ef8a3
103661 --- /dev/null
103662 +++ b/tools/gcc/Makefile
103663 @@ -0,0 +1,47 @@
103664 +#CC := gcc
103665 +#PLUGIN_SOURCE_FILES := pax_plugin.c
103666 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
103667 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
103668 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
103669 +
103670 +ifeq ($(PLUGINCC),$(HOSTCC))
103671 +HOSTLIBS := hostlibs
103672 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu99 -ggdb
103673 +else
103674 +HOSTLIBS := hostcxxlibs
103675 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter
103676 +endif
103677 +
103678 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
103679 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
103680 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
103681 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
103682 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
103683 +$(HOSTLIBS)-y += colorize_plugin.so
103684 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
103685 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
103686 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
103687 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
103688 +
103689 +always := $($(HOSTLIBS)-y)
103690 +
103691 +constify_plugin-objs := constify_plugin.o
103692 +stackleak_plugin-objs := stackleak_plugin.o
103693 +kallocstat_plugin-objs := kallocstat_plugin.o
103694 +kernexec_plugin-objs := kernexec_plugin.o
103695 +checker_plugin-objs := checker_plugin.o
103696 +colorize_plugin-objs := colorize_plugin.o
103697 +size_overflow_plugin-objs := size_overflow_plugin.o
103698 +latent_entropy_plugin-objs := latent_entropy_plugin.o
103699 +structleak_plugin-objs := structleak_plugin.o
103700 +randomize_layout_plugin-objs := randomize_layout_plugin.o
103701 +
103702 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
103703 +
103704 +quiet_cmd_build_size_overflow_hash = GENHASH $@
103705 + cmd_build_size_overflow_hash = \
103706 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
103707 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
103708 + $(call if_changed,build_size_overflow_hash)
103709 +
103710 +targets += size_overflow_hash.h
103711 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
103712 new file mode 100644
103713 index 0000000..5452feea
103714 --- /dev/null
103715 +++ b/tools/gcc/checker_plugin.c
103716 @@ -0,0 +1,150 @@
103717 +/*
103718 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
103719 + * Licensed under the GPL v2
103720 + *
103721 + * Note: the choice of the license means that the compilation process is
103722 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
103723 + * but for the kernel it doesn't matter since it doesn't link against
103724 + * any of the gcc libraries
103725 + *
103726 + * gcc plugin to implement various sparse (source code checker) features
103727 + *
103728 + * TODO:
103729 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
103730 + *
103731 + * BUGS:
103732 + * - none known
103733 + */
103734 +
103735 +#include "gcc-common.h"
103736 +
103737 +extern void c_register_addr_space (const char *str, addr_space_t as);
103738 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
103739 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
103740 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
103741 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
103742 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
103743 +
103744 +int plugin_is_GPL_compatible;
103745 +
103746 +static struct plugin_info checker_plugin_info = {
103747 + .version = "201304082245",
103748 + .help = NULL,
103749 +};
103750 +
103751 +#define ADDR_SPACE_KERNEL 0
103752 +#define ADDR_SPACE_FORCE_KERNEL 1
103753 +#define ADDR_SPACE_USER 2
103754 +#define ADDR_SPACE_FORCE_USER 3
103755 +#define ADDR_SPACE_IOMEM 0
103756 +#define ADDR_SPACE_FORCE_IOMEM 0
103757 +#define ADDR_SPACE_PERCPU 0
103758 +#define ADDR_SPACE_FORCE_PERCPU 0
103759 +#define ADDR_SPACE_RCU 0
103760 +#define ADDR_SPACE_FORCE_RCU 0
103761 +
103762 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
103763 +{
103764 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
103765 +}
103766 +
103767 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
103768 +{
103769 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
103770 +}
103771 +
103772 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
103773 +{
103774 + return default_addr_space_valid_pointer_mode(mode, as);
103775 +}
103776 +
103777 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
103778 +{
103779 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
103780 +}
103781 +
103782 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
103783 +{
103784 + return default_addr_space_legitimize_address(x, oldx, mode, as);
103785 +}
103786 +
103787 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
103788 +{
103789 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
103790 + return true;
103791 +
103792 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
103793 + return true;
103794 +
103795 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
103796 + return true;
103797 +
103798 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
103799 + return true;
103800 +
103801 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
103802 + return true;
103803 +
103804 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
103805 + return true;
103806 +
103807 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
103808 + return true;
103809 +
103810 + return subset == superset;
103811 +}
103812 +
103813 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
103814 +{
103815 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
103816 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
103817 +
103818 + return op;
103819 +}
103820 +
103821 +static void register_checker_address_spaces(void *event_data, void *data)
103822 +{
103823 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
103824 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
103825 + c_register_addr_space("__user", ADDR_SPACE_USER);
103826 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
103827 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
103828 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
103829 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
103830 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
103831 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
103832 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
103833 +
103834 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
103835 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
103836 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
103837 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
103838 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
103839 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
103840 + targetm.addr_space.convert = checker_addr_space_convert;
103841 +}
103842 +
103843 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
103844 +{
103845 + const char * const plugin_name = plugin_info->base_name;
103846 + const int argc = plugin_info->argc;
103847 + const struct plugin_argument * const argv = plugin_info->argv;
103848 + int i;
103849 +
103850 + if (!plugin_default_version_check(version, &gcc_version)) {
103851 + error(G_("incompatible gcc/plugin versions"));
103852 + return 1;
103853 + }
103854 +
103855 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
103856 +
103857 + for (i = 0; i < argc; ++i)
103858 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
103859 +
103860 + if (TARGET_64BIT == 0)
103861 + return 0;
103862 +
103863 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
103864 +
103865 + return 0;
103866 +}
103867 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
103868 new file mode 100644
103869 index 0000000..06dcfda
103870 --- /dev/null
103871 +++ b/tools/gcc/colorize_plugin.c
103872 @@ -0,0 +1,169 @@
103873 +/*
103874 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
103875 + * Licensed under the GPL v2
103876 + *
103877 + * Note: the choice of the license means that the compilation process is
103878 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
103879 + * but for the kernel it doesn't matter since it doesn't link against
103880 + * any of the gcc libraries
103881 + *
103882 + * gcc plugin to colorize diagnostic output
103883 + *
103884 + */
103885 +
103886 +#include "gcc-common.h"
103887 +
103888 +int plugin_is_GPL_compatible;
103889 +
103890 +static struct plugin_info colorize_plugin_info = {
103891 + .version = "201401260140",
103892 + .help = NULL,
103893 +};
103894 +
103895 +#define GREEN "\033[32m\033[2m"
103896 +#define LIGHTGREEN "\033[32m\033[1m"
103897 +#define YELLOW "\033[33m\033[2m"
103898 +#define LIGHTYELLOW "\033[33m\033[1m"
103899 +#define RED "\033[31m\033[2m"
103900 +#define LIGHTRED "\033[31m\033[1m"
103901 +#define BLUE "\033[34m\033[2m"
103902 +#define LIGHTBLUE "\033[34m\033[1m"
103903 +#define BRIGHT "\033[m\033[1m"
103904 +#define NORMAL "\033[m"
103905 +
103906 +static diagnostic_starter_fn old_starter;
103907 +static diagnostic_finalizer_fn old_finalizer;
103908 +
103909 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
103910 +{
103911 + const char *color;
103912 + char *newprefix;
103913 +
103914 + switch (diagnostic->kind) {
103915 + case DK_NOTE:
103916 + color = LIGHTBLUE;
103917 + break;
103918 +
103919 + case DK_PEDWARN:
103920 + case DK_WARNING:
103921 + color = LIGHTYELLOW;
103922 + break;
103923 +
103924 + case DK_ERROR:
103925 + case DK_FATAL:
103926 + case DK_ICE:
103927 + case DK_PERMERROR:
103928 + case DK_SORRY:
103929 + color = LIGHTRED;
103930 + break;
103931 +
103932 + default:
103933 + color = NORMAL;
103934 + }
103935 +
103936 + old_starter(context, diagnostic);
103937 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
103938 + return;
103939 + pp_destroy_prefix(context->printer);
103940 + pp_set_prefix(context->printer, newprefix);
103941 +}
103942 +
103943 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
103944 +{
103945 + old_finalizer(context, diagnostic);
103946 +}
103947 +
103948 +static void colorize_arm(void)
103949 +{
103950 + old_starter = diagnostic_starter(global_dc);
103951 + old_finalizer = diagnostic_finalizer(global_dc);
103952 +
103953 + diagnostic_starter(global_dc) = start_colorize;
103954 + diagnostic_finalizer(global_dc) = finalize_colorize;
103955 +}
103956 +
103957 +static unsigned int execute_colorize_rearm(void)
103958 +{
103959 + if (diagnostic_starter(global_dc) == start_colorize)
103960 + return 0;
103961 +
103962 + colorize_arm();
103963 + return 0;
103964 +}
103965 +
103966 +#if BUILDING_GCC_VERSION >= 4009
103967 +static const struct pass_data colorize_rearm_pass_data = {
103968 +#else
103969 +struct simple_ipa_opt_pass colorize_rearm_pass = {
103970 + .pass = {
103971 +#endif
103972 + .type = SIMPLE_IPA_PASS,
103973 + .name = "colorize_rearm",
103974 +#if BUILDING_GCC_VERSION >= 4008
103975 + .optinfo_flags = OPTGROUP_NONE,
103976 +#endif
103977 +#if BUILDING_GCC_VERSION >= 4009
103978 + .has_gate = false,
103979 + .has_execute = true,
103980 +#else
103981 + .gate = NULL,
103982 + .execute = execute_colorize_rearm,
103983 + .sub = NULL,
103984 + .next = NULL,
103985 + .static_pass_number = 0,
103986 +#endif
103987 + .tv_id = TV_NONE,
103988 + .properties_required = 0,
103989 + .properties_provided = 0,
103990 + .properties_destroyed = 0,
103991 + .todo_flags_start = 0,
103992 + .todo_flags_finish = 0
103993 +#if BUILDING_GCC_VERSION < 4009
103994 + }
103995 +#endif
103996 +};
103997 +
103998 +#if BUILDING_GCC_VERSION >= 4009
103999 +namespace {
104000 +class colorize_rearm_pass : public simple_ipa_opt_pass {
104001 +public:
104002 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
104003 + unsigned int execute() { return execute_colorize_rearm(); }
104004 +};
104005 +}
104006 +#endif
104007 +
104008 +static struct opt_pass *make_colorize_rearm_pass(void)
104009 +{
104010 +#if BUILDING_GCC_VERSION >= 4009
104011 + return new colorize_rearm_pass();
104012 +#else
104013 + return &colorize_rearm_pass.pass;
104014 +#endif
104015 +}
104016 +
104017 +static void colorize_start_unit(void *gcc_data, void *user_data)
104018 +{
104019 + colorize_arm();
104020 +}
104021 +
104022 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
104023 +{
104024 + const char * const plugin_name = plugin_info->base_name;
104025 + struct register_pass_info colorize_rearm_pass_info;
104026 +
104027 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
104028 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
104029 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
104030 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
104031 +
104032 + if (!plugin_default_version_check(version, &gcc_version)) {
104033 + error(G_("incompatible gcc/plugin versions"));
104034 + return 1;
104035 + }
104036 +
104037 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
104038 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
104039 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
104040 + return 0;
104041 +}
104042 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
104043 new file mode 100644
104044 index 0000000..4f67ac1
104045 --- /dev/null
104046 +++ b/tools/gcc/constify_plugin.c
104047 @@ -0,0 +1,552 @@
104048 +/*
104049 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
104050 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
104051 + * Licensed under the GPL v2, or (at your option) v3
104052 + *
104053 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
104054 + *
104055 + * Homepage:
104056 + * http://www.grsecurity.net/~ephox/const_plugin/
104057 + *
104058 + * Usage:
104059 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
104060 + * $ gcc -fplugin=constify_plugin.so test.c -O2
104061 + */
104062 +
104063 +#include "gcc-common.h"
104064 +
104065 +// unused C type flag in all versions 4.5-4.9
104066 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
104067 +
104068 +int plugin_is_GPL_compatible;
104069 +
104070 +static struct plugin_info const_plugin_info = {
104071 + .version = "201401270210",
104072 + .help = "no-constify\tturn off constification\n",
104073 +};
104074 +
104075 +typedef struct {
104076 + bool has_fptr_field;
104077 + bool has_writable_field;
104078 + bool has_do_const_field;
104079 + bool has_no_const_field;
104080 +} constify_info;
104081 +
104082 +static const_tree get_field_type(const_tree field)
104083 +{
104084 + return strip_array_types(TREE_TYPE(field));
104085 +}
104086 +
104087 +static bool is_fptr(const_tree field)
104088 +{
104089 + const_tree ptr = get_field_type(field);
104090 +
104091 + if (TREE_CODE(ptr) != POINTER_TYPE)
104092 + return false;
104093 +
104094 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
104095 +}
104096 +
104097 +/*
104098 + * determine whether the given structure type meets the requirements for automatic constification,
104099 + * including the constification attributes on nested structure types
104100 + */
104101 +static void constifiable(const_tree node, constify_info *cinfo)
104102 +{
104103 + const_tree field;
104104 +
104105 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
104106 +
104107 + // e.g., pointer to structure fields while still constructing the structure type
104108 + if (TYPE_FIELDS(node) == NULL_TREE)
104109 + return;
104110 +
104111 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
104112 + const_tree type = get_field_type(field);
104113 + enum tree_code code = TREE_CODE(type);
104114 +
104115 + if (node == type)
104116 + continue;
104117 +
104118 + if (is_fptr(field))
104119 + cinfo->has_fptr_field = true;
104120 + else if (!TREE_READONLY(field))
104121 + cinfo->has_writable_field = true;
104122 +
104123 + if (code == RECORD_TYPE || code == UNION_TYPE) {
104124 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
104125 + cinfo->has_do_const_field = true;
104126 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
104127 + cinfo->has_no_const_field = true;
104128 + else
104129 + constifiable(type, cinfo);
104130 + }
104131 + }
104132 +}
104133 +
104134 +static bool constified(const_tree node)
104135 +{
104136 + constify_info cinfo = {
104137 + .has_fptr_field = false,
104138 + .has_writable_field = false,
104139 + .has_do_const_field = false,
104140 + .has_no_const_field = false
104141 + };
104142 +
104143 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
104144 +
104145 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
104146 +// gcc_assert(!TYPE_READONLY(node));
104147 + return false;
104148 + }
104149 +
104150 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
104151 + gcc_assert(TYPE_READONLY(node));
104152 + return true;
104153 + }
104154 +
104155 + constifiable(node, &cinfo);
104156 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
104157 + return false;
104158 +
104159 + return TYPE_READONLY(node);
104160 +}
104161 +
104162 +static void deconstify_tree(tree node);
104163 +
104164 +static void deconstify_type(tree type)
104165 +{
104166 + tree field;
104167 +
104168 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
104169 +
104170 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
104171 + const_tree fieldtype = get_field_type(field);
104172 +
104173 + // special case handling of simple ptr-to-same-array-type members
104174 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
104175 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
104176 +
104177 + if (TREE_TYPE(TREE_TYPE(field)) == type)
104178 + continue;
104179 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
104180 + continue;
104181 + if (!constified(ptrtype))
104182 + continue;
104183 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
104184 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
104185 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
104186 + }
104187 + continue;
104188 + }
104189 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
104190 + continue;
104191 + if (!constified(fieldtype))
104192 + continue;
104193 +
104194 + deconstify_tree(field);
104195 + TREE_READONLY(field) = 0;
104196 + }
104197 + TYPE_READONLY(type) = 0;
104198 + C_TYPE_FIELDS_READONLY(type) = 0;
104199 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
104200 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
104201 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
104202 + }
104203 +}
104204 +
104205 +static void deconstify_tree(tree node)
104206 +{
104207 + tree old_type, new_type, field;
104208 +
104209 + old_type = TREE_TYPE(node);
104210 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
104211 + node = TREE_TYPE(node) = copy_node(old_type);
104212 + old_type = TREE_TYPE(old_type);
104213 + }
104214 +
104215 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
104216 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
104217 +
104218 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
104219 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
104220 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
104221 + DECL_FIELD_CONTEXT(field) = new_type;
104222 +
104223 + deconstify_type(new_type);
104224 +
104225 + TREE_TYPE(node) = new_type;
104226 +}
104227 +
104228 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
104229 +{
104230 + tree type;
104231 + constify_info cinfo = {
104232 + .has_fptr_field = false,
104233 + .has_writable_field = false,
104234 + .has_do_const_field = false,
104235 + .has_no_const_field = false
104236 + };
104237 +
104238 + *no_add_attrs = true;
104239 + if (TREE_CODE(*node) == FUNCTION_DECL) {
104240 + error("%qE attribute does not apply to functions (%qF)", name, *node);
104241 + return NULL_TREE;
104242 + }
104243 +
104244 + if (TREE_CODE(*node) == PARM_DECL) {
104245 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
104246 + return NULL_TREE;
104247 + }
104248 +
104249 + if (TREE_CODE(*node) == VAR_DECL) {
104250 + error("%qE attribute does not apply to variables (%qD)", name, *node);
104251 + return NULL_TREE;
104252 + }
104253 +
104254 + if (TYPE_P(*node)) {
104255 + type = *node;
104256 + } else {
104257 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
104258 + type = TREE_TYPE(*node);
104259 + }
104260 +
104261 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
104262 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
104263 + return NULL_TREE;
104264 + }
104265 +
104266 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
104267 + error("%qE attribute is already applied to the type %qT", name, type);
104268 + return NULL_TREE;
104269 + }
104270 +
104271 + if (TYPE_P(*node)) {
104272 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
104273 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
104274 + else
104275 + *no_add_attrs = false;
104276 + return NULL_TREE;
104277 + }
104278 +
104279 + constifiable(type, &cinfo);
104280 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
104281 + deconstify_tree(*node);
104282 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
104283 + return NULL_TREE;
104284 + }
104285 +
104286 + error("%qE attribute used on type %qT that is not constified", name, type);
104287 + return NULL_TREE;
104288 +}
104289 +
104290 +static void constify_type(tree type)
104291 +{
104292 + TYPE_READONLY(type) = 1;
104293 + C_TYPE_FIELDS_READONLY(type) = 1;
104294 + TYPE_CONSTIFY_VISITED(type) = 1;
104295 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
104296 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
104297 +}
104298 +
104299 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
104300 +{
104301 + *no_add_attrs = true;
104302 + if (!TYPE_P(*node)) {
104303 + error("%qE attribute applies to types only (%qD)", name, *node);
104304 + return NULL_TREE;
104305 + }
104306 +
104307 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
104308 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
104309 + return NULL_TREE;
104310 + }
104311 +
104312 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
104313 + error("%qE attribute used on %qT is already applied to the type", name, *node);
104314 + return NULL_TREE;
104315 + }
104316 +
104317 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
104318 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
104319 + return NULL_TREE;
104320 + }
104321 +
104322 + *no_add_attrs = false;
104323 + return NULL_TREE;
104324 +}
104325 +
104326 +static struct attribute_spec no_const_attr = {
104327 + .name = "no_const",
104328 + .min_length = 0,
104329 + .max_length = 0,
104330 + .decl_required = false,
104331 + .type_required = false,
104332 + .function_type_required = false,
104333 + .handler = handle_no_const_attribute,
104334 +#if BUILDING_GCC_VERSION >= 4007
104335 + .affects_type_identity = true
104336 +#endif
104337 +};
104338 +
104339 +static struct attribute_spec do_const_attr = {
104340 + .name = "do_const",
104341 + .min_length = 0,
104342 + .max_length = 0,
104343 + .decl_required = false,
104344 + .type_required = false,
104345 + .function_type_required = false,
104346 + .handler = handle_do_const_attribute,
104347 +#if BUILDING_GCC_VERSION >= 4007
104348 + .affects_type_identity = true
104349 +#endif
104350 +};
104351 +
104352 +static void register_attributes(void *event_data, void *data)
104353 +{
104354 + register_attribute(&no_const_attr);
104355 + register_attribute(&do_const_attr);
104356 +}
104357 +
104358 +static void finish_type(void *event_data, void *data)
104359 +{
104360 + tree type = (tree)event_data;
104361 + constify_info cinfo = {
104362 + .has_fptr_field = false,
104363 + .has_writable_field = false,
104364 + .has_do_const_field = false,
104365 + .has_no_const_field = false
104366 + };
104367 +
104368 + if (type == NULL_TREE || type == error_mark_node)
104369 + return;
104370 +
104371 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
104372 + return;
104373 +
104374 + constifiable(type, &cinfo);
104375 +
104376 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
104377 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
104378 + deconstify_type(type);
104379 + TYPE_CONSTIFY_VISITED(type) = 1;
104380 + } else
104381 + error("'no_const' attribute used on type %qT that is not constified", type);
104382 + return;
104383 + }
104384 +
104385 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
104386 + if (!cinfo.has_writable_field) {
104387 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
104388 + return;
104389 + }
104390 + constify_type(type);
104391 + return;
104392 + }
104393 +
104394 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
104395 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
104396 + error("'do_const' attribute used on type %qT that is constified", type);
104397 + return;
104398 + }
104399 + constify_type(type);
104400 + return;
104401 + }
104402 +
104403 + deconstify_type(type);
104404 + TYPE_CONSTIFY_VISITED(type) = 1;
104405 +}
104406 +
104407 +static void check_global_variables(void *event_data, void *data)
104408 +{
104409 + struct varpool_node *node;
104410 +
104411 + FOR_EACH_VARIABLE(node) {
104412 + tree var = NODE_DECL(node);
104413 + tree type = TREE_TYPE(var);
104414 +
104415 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
104416 + continue;
104417 +
104418 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
104419 + continue;
104420 +
104421 + if (!TYPE_CONSTIFY_VISITED(type))
104422 + continue;
104423 +
104424 + if (DECL_EXTERNAL(var))
104425 + continue;
104426 +
104427 + if (DECL_INITIAL(var))
104428 + continue;
104429 +
104430 + // this works around a gcc bug/feature where uninitialized globals
104431 + // are moved into the .bss section regardless of any constification
104432 + DECL_INITIAL(var) = build_constructor(type, NULL);
104433 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
104434 + }
104435 +}
104436 +
104437 +static unsigned int check_local_variables(void)
104438 +{
104439 + unsigned int ret = 0;
104440 + tree var;
104441 +
104442 + unsigned int i;
104443 +
104444 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
104445 + tree type = TREE_TYPE(var);
104446 +
104447 + gcc_assert(DECL_P(var));
104448 + if (is_global_var(var))
104449 + continue;
104450 +
104451 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
104452 + continue;
104453 +
104454 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
104455 + continue;
104456 +
104457 + if (!TYPE_CONSTIFY_VISITED(type))
104458 + continue;
104459 +
104460 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
104461 + ret = 1;
104462 + }
104463 + return ret;
104464 +}
104465 +
104466 +#if BUILDING_GCC_VERSION >= 4009
104467 +static const struct pass_data check_local_variables_pass_data = {
104468 +#else
104469 +static struct gimple_opt_pass check_local_variables_pass = {
104470 + .pass = {
104471 +#endif
104472 + .type = GIMPLE_PASS,
104473 + .name = "check_local_variables",
104474 +#if BUILDING_GCC_VERSION >= 4008
104475 + .optinfo_flags = OPTGROUP_NONE,
104476 +#endif
104477 +#if BUILDING_GCC_VERSION >= 4009
104478 + .has_gate = false,
104479 + .has_execute = true,
104480 +#else
104481 + .gate = NULL,
104482 + .execute = check_local_variables,
104483 + .sub = NULL,
104484 + .next = NULL,
104485 + .static_pass_number = 0,
104486 +#endif
104487 + .tv_id = TV_NONE,
104488 + .properties_required = 0,
104489 + .properties_provided = 0,
104490 + .properties_destroyed = 0,
104491 + .todo_flags_start = 0,
104492 + .todo_flags_finish = 0
104493 +#if BUILDING_GCC_VERSION < 4009
104494 + }
104495 +#endif
104496 +};
104497 +
104498 +#if BUILDING_GCC_VERSION >= 4009
104499 +namespace {
104500 +class check_local_variables_pass : public gimple_opt_pass {
104501 +public:
104502 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
104503 + unsigned int execute() { return check_local_variables(); }
104504 +};
104505 +}
104506 +#endif
104507 +
104508 +static struct opt_pass *make_check_local_variables_pass(void)
104509 +{
104510 +#if BUILDING_GCC_VERSION >= 4009
104511 + return new check_local_variables_pass();
104512 +#else
104513 + return &check_local_variables_pass.pass;
104514 +#endif
104515 +}
104516 +
104517 +static struct {
104518 + const char *name;
104519 + const char *asm_op;
104520 +} sections[] = {
104521 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
104522 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
104523 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
104524 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
104525 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
104526 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
104527 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
104528 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
104529 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
104530 +};
104531 +
104532 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
104533 +
104534 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
104535 +{
104536 + size_t i;
104537 +
104538 + for (i = 0; i < ARRAY_SIZE(sections); i++)
104539 + if (!strcmp(sections[i].name, name))
104540 + return 0;
104541 + return old_section_type_flags(decl, name, reloc);
104542 +}
104543 +
104544 +static void constify_start_unit(void *gcc_data, void *user_data)
104545 +{
104546 +// size_t i;
104547 +
104548 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
104549 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
104550 +// sections[i].section = get_section(sections[i].name, 0, NULL);
104551 +
104552 + old_section_type_flags = targetm.section_type_flags;
104553 + targetm.section_type_flags = constify_section_type_flags;
104554 +}
104555 +
104556 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
104557 +{
104558 + const char * const plugin_name = plugin_info->base_name;
104559 + const int argc = plugin_info->argc;
104560 + const struct plugin_argument * const argv = plugin_info->argv;
104561 + int i;
104562 + bool constify = true;
104563 +
104564 + struct register_pass_info check_local_variables_pass_info;
104565 +
104566 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
104567 + check_local_variables_pass_info.reference_pass_name = "ssa";
104568 + check_local_variables_pass_info.ref_pass_instance_number = 1;
104569 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
104570 +
104571 + if (!plugin_default_version_check(version, &gcc_version)) {
104572 + error(G_("incompatible gcc/plugin versions"));
104573 + return 1;
104574 + }
104575 +
104576 + for (i = 0; i < argc; ++i) {
104577 + if (!(strcmp(argv[i].key, "no-constify"))) {
104578 + constify = false;
104579 + continue;
104580 + }
104581 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
104582 + }
104583 +
104584 + if (strcmp(lang_hooks.name, "GNU C")) {
104585 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
104586 + constify = false;
104587 + }
104588 +
104589 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
104590 + if (constify) {
104591 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
104592 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
104593 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
104594 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
104595 + }
104596 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
104597 +
104598 + return 0;
104599 +}
104600 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
104601 new file mode 100644
104602 index 0000000..986f39b
104603 --- /dev/null
104604 +++ b/tools/gcc/gcc-common.h
104605 @@ -0,0 +1,267 @@
104606 +#ifndef GCC_COMMON_H_INCLUDED
104607 +#define GCC_COMMON_H_INCLUDED
104608 +
104609 +#include "plugin.h"
104610 +#include "bversion.h"
104611 +#include "plugin-version.h"
104612 +#include "config.h"
104613 +#include "system.h"
104614 +#include "coretypes.h"
104615 +#include "tm.h"
104616 +#include "line-map.h"
104617 +#include "input.h"
104618 +#include "tree.h"
104619 +
104620 +#include "tree-inline.h"
104621 +#include "version.h"
104622 +#include "rtl.h"
104623 +#include "tm_p.h"
104624 +#include "flags.h"
104625 +//#include "insn-attr.h"
104626 +//#include "insn-config.h"
104627 +//#include "insn-flags.h"
104628 +#include "hard-reg-set.h"
104629 +//#include "recog.h"
104630 +#include "output.h"
104631 +#include "except.h"
104632 +#include "function.h"
104633 +#include "toplev.h"
104634 +//#include "expr.h"
104635 +#include "basic-block.h"
104636 +#include "intl.h"
104637 +#include "ggc.h"
104638 +//#include "regs.h"
104639 +#include "timevar.h"
104640 +
104641 +#include "params.h"
104642 +#include "pointer-set.h"
104643 +#include "emit-rtl.h"
104644 +//#include "reload.h"
104645 +//#include "ira.h"
104646 +//#include "dwarf2asm.h"
104647 +#include "debug.h"
104648 +#include "target.h"
104649 +#include "langhooks.h"
104650 +#include "cfgloop.h"
104651 +//#include "hosthooks.h"
104652 +#include "cgraph.h"
104653 +#include "opts.h"
104654 +//#include "coverage.h"
104655 +//#include "value-prof.h"
104656 +
104657 +#if BUILDING_GCC_VERSION >= 4007
104658 +#include "tree-pretty-print.h"
104659 +#include "gimple-pretty-print.h"
104660 +#include "c-tree.h"
104661 +//#include "alloc-pool.h"
104662 +#endif
104663 +
104664 +#if BUILDING_GCC_VERSION <= 4008
104665 +#include "tree-flow.h"
104666 +#endif
104667 +
104668 +#include "diagnostic.h"
104669 +//#include "tree-diagnostic.h"
104670 +#include "tree-dump.h"
104671 +#include "tree-pass.h"
104672 +//#include "df.h"
104673 +#include "predict.h"
104674 +//#include "lto-streamer.h"
104675 +#include "ipa-utils.h"
104676 +
104677 +#if BUILDING_GCC_VERSION >= 4009
104678 +#include "varasm.h"
104679 +#include "stor-layout.h"
104680 +#include "internal-fn.h"
104681 +#include "gimple-expr.h"
104682 +//#include "diagnostic-color.h"
104683 +#include "context.h"
104684 +#include "tree-ssa-alias.h"
104685 +#include "stringpool.h"
104686 +#include "tree-ssanames.h"
104687 +#include "print-tree.h"
104688 +#include "tree-eh.h"
104689 +#endif
104690 +
104691 +#include "gimple.h"
104692 +
104693 +#if BUILDING_GCC_VERSION >= 4009
104694 +#include "tree-ssa-operands.h"
104695 +#include "tree-phinodes.h"
104696 +#include "gimple-iterator.h"
104697 +#include "gimple-ssa.h"
104698 +#include "ssa-iterators.h"
104699 +#endif
104700 +
104701 +//#include "expr.h" where are you...
104702 +extern rtx emit_move_insn(rtx x, rtx y);
104703 +
104704 +#define __unused __attribute__((__unused__))
104705 +
104706 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
104707 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
104708 +
104709 +#if BUILDING_GCC_VERSION == 4005
104710 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
104711 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
104712 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
104713 +
104714 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
104715 +{
104716 + tree fndecl;
104717 +
104718 + if (!is_gimple_call(stmt))
104719 + return false;
104720 + fndecl = gimple_call_fndecl(stmt);
104721 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
104722 + return false;
104723 +// print_node(stderr, "pax", fndecl, 4);
104724 + return DECL_FUNCTION_CODE(fndecl) == code;
104725 +}
104726 +
104727 +static inline bool is_simple_builtin(tree decl)
104728 +{
104729 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
104730 + return false;
104731 +
104732 + switch (DECL_FUNCTION_CODE(decl)) {
104733 + /* Builtins that expand to constants. */
104734 + case BUILT_IN_CONSTANT_P:
104735 + case BUILT_IN_EXPECT:
104736 + case BUILT_IN_OBJECT_SIZE:
104737 + case BUILT_IN_UNREACHABLE:
104738 + /* Simple register moves or loads from stack. */
104739 + case BUILT_IN_RETURN_ADDRESS:
104740 + case BUILT_IN_EXTRACT_RETURN_ADDR:
104741 + case BUILT_IN_FROB_RETURN_ADDR:
104742 + case BUILT_IN_RETURN:
104743 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
104744 + case BUILT_IN_FRAME_ADDRESS:
104745 + case BUILT_IN_VA_END:
104746 + case BUILT_IN_STACK_SAVE:
104747 + case BUILT_IN_STACK_RESTORE:
104748 + /* Exception state returns or moves registers around. */
104749 + case BUILT_IN_EH_FILTER:
104750 + case BUILT_IN_EH_POINTER:
104751 + case BUILT_IN_EH_COPY_VALUES:
104752 + return true;
104753 +
104754 + default:
104755 + return false;
104756 + }
104757 +}
104758 +#endif
104759 +
104760 +#if BUILDING_GCC_VERSION <= 4006
104761 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
104762 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
104763 +
104764 +// should come from c-tree.h if only it were installed for gcc 4.5...
104765 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
104766 +
104767 +#define get_random_seed(noinit) ({ \
104768 + unsigned HOST_WIDE_INT seed; \
104769 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
104770 + seed * seed; })
104771 +
104772 +static inline bool gimple_clobber_p(gimple s)
104773 +{
104774 + return false;
104775 +}
104776 +
104777 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
104778 +{
104779 + return implicit_built_in_decls[fncode];
104780 +}
104781 +
104782 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
104783 +{
104784 + struct cgraph_node *node = cgraph_get_node(decl);
104785 +
104786 + return node ? node : cgraph_node(decl);
104787 +}
104788 +
104789 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
104790 +{
104791 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
104792 +}
104793 +
104794 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
104795 +{
104796 + struct cgraph_node *node;
104797 +
104798 + for (node = cgraph_nodes; node; node = node->next)
104799 + if (cgraph_function_with_gimple_body_p(node))
104800 + return node;
104801 + return NULL;
104802 +}
104803 +
104804 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
104805 +{
104806 + for (node = node->next; node; node = node->next)
104807 + if (cgraph_function_with_gimple_body_p(node))
104808 + return node;
104809 + return NULL;
104810 +}
104811 +
104812 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
104813 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
104814 + (node) = cgraph_next_function_with_gimple_body(node))
104815 +#endif
104816 +
104817 +#if BUILDING_GCC_VERSION == 4006
104818 +extern void debug_gimple_stmt(gimple);
104819 +extern void debug_gimple_seq(gimple_seq);
104820 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
104821 +extern void print_gimple_stmt(FILE *, gimple, int, int);
104822 +extern void print_gimple_expr(FILE *, gimple, int, int);
104823 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
104824 +#endif
104825 +
104826 +#if BUILDING_GCC_VERSION <= 4007
104827 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
104828 +
104829 +static inline bool gimple_store_p(gimple gs)
104830 +{
104831 + tree lhs = gimple_get_lhs(gs);
104832 + return lhs && !is_gimple_reg(lhs);
104833 +}
104834 +#endif
104835 +
104836 +#if BUILDING_GCC_VERSION >= 4007
104837 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
104838 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
104839 +#endif
104840 +
104841 +#if BUILDING_GCC_VERSION <= 4008
104842 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
104843 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
104844 +
104845 +static inline const char *get_tree_code_name(enum tree_code code)
104846 +{
104847 + gcc_assert(code < MAX_TREE_CODES);
104848 + return tree_code_name[code];
104849 +}
104850 +
104851 +#define ipa_remove_stmt_references(cnode, stmt)
104852 +#endif
104853 +
104854 +#if BUILDING_GCC_VERSION == 4008
104855 +#define NODE_DECL(node) node->symbol.decl
104856 +#else
104857 +#define NODE_DECL(node) node->decl
104858 +#endif
104859 +
104860 +#if BUILDING_GCC_VERSION >= 4008
104861 +#define add_referenced_var(var)
104862 +#define mark_sym_for_renaming(var)
104863 +#define varpool_mark_needed_node(node)
104864 +#define TODO_dump_func 0
104865 +#define TODO_dump_cgraph 0
104866 +#endif
104867 +
104868 +#if BUILDING_GCC_VERSION >= 4009
104869 +#define TODO_ggc_collect 0
104870 +#endif
104871 +
104872 +#endif
104873 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
104874 new file mode 100644
104875 index 0000000..e518932
104876 --- /dev/null
104877 +++ b/tools/gcc/generate_size_overflow_hash.sh
104878 @@ -0,0 +1,94 @@
104879 +#!/bin/bash
104880 +
104881 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
104882 +
104883 +header1="size_overflow_hash.h"
104884 +database="size_overflow_hash.data"
104885 +n=65536
104886 +
104887 +usage() {
104888 +cat <<EOF
104889 +usage: $0 options
104890 +OPTIONS:
104891 + -h|--help help
104892 + -o header file
104893 + -d database file
104894 + -n hash array size
104895 +EOF
104896 + return 0
104897 +}
104898 +
104899 +while true
104900 +do
104901 + case "$1" in
104902 + -h|--help) usage && exit 0;;
104903 + -n) n=$2; shift 2;;
104904 + -o) header1="$2"; shift 2;;
104905 + -d) database="$2"; shift 2;;
104906 + --) shift 1; break ;;
104907 + *) break ;;
104908 + esac
104909 +done
104910 +
104911 +create_defines() {
104912 + for i in `seq 0 31`
104913 + do
104914 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
104915 + done
104916 + echo >> "$header1"
104917 +}
104918 +
104919 +create_structs() {
104920 + rm -f "$header1"
104921 +
104922 + create_defines
104923 +
104924 + cat "$database" | while read data
104925 + do
104926 + data_array=($data)
104927 + struct_hash_name="${data_array[0]}"
104928 + funcn="${data_array[1]}"
104929 + params="${data_array[2]}"
104930 + next="${data_array[4]}"
104931 +
104932 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
104933 +
104934 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
104935 + echo -en "\t.param\t= " >> "$header1"
104936 + line=
104937 + for param_num in ${params//-/ };
104938 + do
104939 + line="${line}PARAM"$param_num"|"
104940 + done
104941 +
104942 + echo -e "${line%?},\n};\n" >> "$header1"
104943 + done
104944 +}
104945 +
104946 +create_headers() {
104947 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
104948 +}
104949 +
104950 +create_array_elements() {
104951 + index=0
104952 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
104953 + do
104954 + data_array=($data)
104955 + i="${data_array[3]}"
104956 + hash="${data_array[0]}"
104957 + while [[ $index -lt $i ]]
104958 + do
104959 + echo -e "\t["$index"]\t= NULL," >> "$header1"
104960 + index=$(($index + 1))
104961 + done
104962 + index=$(($index + 1))
104963 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
104964 + done
104965 + echo '};' >> $header1
104966 +}
104967 +
104968 +create_structs
104969 +create_headers
104970 +create_array_elements
104971 +
104972 +exit 0
104973 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
104974 new file mode 100644
104975 index 0000000..b559327
104976 --- /dev/null
104977 +++ b/tools/gcc/kallocstat_plugin.c
104978 @@ -0,0 +1,182 @@
104979 +/*
104980 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
104981 + * Licensed under the GPL v2
104982 + *
104983 + * Note: the choice of the license means that the compilation process is
104984 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
104985 + * but for the kernel it doesn't matter since it doesn't link against
104986 + * any of the gcc libraries
104987 + *
104988 + * gcc plugin to find the distribution of k*alloc sizes
104989 + *
104990 + * TODO:
104991 + *
104992 + * BUGS:
104993 + * - none known
104994 + */
104995 +
104996 +#include "gcc-common.h"
104997 +
104998 +int plugin_is_GPL_compatible;
104999 +
105000 +static struct plugin_info kallocstat_plugin_info = {
105001 + .version = "201401260140",
105002 + .help = NULL
105003 +};
105004 +
105005 +static const char * const kalloc_functions[] = {
105006 + "__kmalloc",
105007 + "kmalloc",
105008 + "kmalloc_large",
105009 + "kmalloc_node",
105010 + "kmalloc_order",
105011 + "kmalloc_order_trace",
105012 + "kmalloc_slab",
105013 + "kzalloc",
105014 + "kzalloc_node",
105015 +};
105016 +
105017 +static bool is_kalloc(const char *fnname)
105018 +{
105019 + size_t i;
105020 +
105021 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
105022 + if (!strcmp(fnname, kalloc_functions[i]))
105023 + return true;
105024 + return false;
105025 +}
105026 +
105027 +static unsigned int execute_kallocstat(void)
105028 +{
105029 + basic_block bb;
105030 +
105031 + // 1. loop through BBs and GIMPLE statements
105032 + FOR_EACH_BB_FN(bb, cfun) {
105033 + gimple_stmt_iterator gsi;
105034 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
105035 + // gimple match:
105036 + tree fndecl, size;
105037 + gimple stmt;
105038 + const char *fnname;
105039 +
105040 + // is it a call
105041 + stmt = gsi_stmt(gsi);
105042 + if (!is_gimple_call(stmt))
105043 + continue;
105044 + fndecl = gimple_call_fndecl(stmt);
105045 + if (fndecl == NULL_TREE)
105046 + continue;
105047 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
105048 + continue;
105049 +
105050 + // is it a call to k*alloc
105051 + fnname = DECL_NAME_POINTER(fndecl);
105052 + if (!is_kalloc(fnname))
105053 + continue;
105054 +
105055 + // is the size arg const or the result of a simple const assignment
105056 + size = gimple_call_arg(stmt, 0);
105057 + while (true) {
105058 + expanded_location xloc;
105059 + size_t size_val;
105060 +
105061 + if (TREE_CONSTANT(size)) {
105062 + xloc = expand_location(gimple_location(stmt));
105063 + if (!xloc.file)
105064 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
105065 + size_val = TREE_INT_CST_LOW(size);
105066 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
105067 + break;
105068 + }
105069 +
105070 + if (TREE_CODE(size) != SSA_NAME)
105071 + break;
105072 + stmt = SSA_NAME_DEF_STMT(size);
105073 +//debug_gimple_stmt(stmt);
105074 +//debug_tree(size);
105075 + if (!stmt || !is_gimple_assign(stmt))
105076 + break;
105077 + if (gimple_num_ops(stmt) != 2)
105078 + break;
105079 + size = gimple_assign_rhs1(stmt);
105080 + }
105081 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
105082 +//debug_tree(gimple_call_fn(call_stmt));
105083 +//print_node(stderr, "pax", fndecl, 4);
105084 + }
105085 + }
105086 +
105087 + return 0;
105088 +}
105089 +
105090 +#if BUILDING_GCC_VERSION >= 4009
105091 +static const struct pass_data kallocstat_pass_data = {
105092 +#else
105093 +static struct gimple_opt_pass kallocstat_pass = {
105094 + .pass = {
105095 +#endif
105096 + .type = GIMPLE_PASS,
105097 + .name = "kallocstat",
105098 +#if BUILDING_GCC_VERSION >= 4008
105099 + .optinfo_flags = OPTGROUP_NONE,
105100 +#endif
105101 +#if BUILDING_GCC_VERSION >= 4009
105102 + .has_gate = false,
105103 + .has_execute = true,
105104 +#else
105105 + .gate = NULL,
105106 + .execute = execute_kallocstat,
105107 + .sub = NULL,
105108 + .next = NULL,
105109 + .static_pass_number = 0,
105110 +#endif
105111 + .tv_id = TV_NONE,
105112 + .properties_required = 0,
105113 + .properties_provided = 0,
105114 + .properties_destroyed = 0,
105115 + .todo_flags_start = 0,
105116 + .todo_flags_finish = 0
105117 +#if BUILDING_GCC_VERSION < 4009
105118 + }
105119 +#endif
105120 +};
105121 +
105122 +#if BUILDING_GCC_VERSION >= 4009
105123 +namespace {
105124 +class kallocstat_pass : public gimple_opt_pass {
105125 +public:
105126 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
105127 + unsigned int execute() { return execute_kallocstat(); }
105128 +};
105129 +}
105130 +#endif
105131 +
105132 +static struct opt_pass *make_kallocstat_pass(void)
105133 +{
105134 +#if BUILDING_GCC_VERSION >= 4009
105135 + return new kallocstat_pass();
105136 +#else
105137 + return &kallocstat_pass.pass;
105138 +#endif
105139 +}
105140 +
105141 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105142 +{
105143 + const char * const plugin_name = plugin_info->base_name;
105144 + struct register_pass_info kallocstat_pass_info;
105145 +
105146 + kallocstat_pass_info.pass = make_kallocstat_pass();
105147 + kallocstat_pass_info.reference_pass_name = "ssa";
105148 + kallocstat_pass_info.ref_pass_instance_number = 1;
105149 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105150 +
105151 + if (!plugin_default_version_check(version, &gcc_version)) {
105152 + error(G_("incompatible gcc/plugin versions"));
105153 + return 1;
105154 + }
105155 +
105156 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
105157 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
105158 +
105159 + return 0;
105160 +}
105161 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
105162 new file mode 100644
105163 index 0000000..dd73713
105164 --- /dev/null
105165 +++ b/tools/gcc/kernexec_plugin.c
105166 @@ -0,0 +1,519 @@
105167 +/*
105168 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
105169 + * Licensed under the GPL v2
105170 + *
105171 + * Note: the choice of the license means that the compilation process is
105172 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105173 + * but for the kernel it doesn't matter since it doesn't link against
105174 + * any of the gcc libraries
105175 + *
105176 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
105177 + *
105178 + * TODO:
105179 + *
105180 + * BUGS:
105181 + * - none known
105182 + */
105183 +
105184 +#include "gcc-common.h"
105185 +
105186 +int plugin_is_GPL_compatible;
105187 +
105188 +static struct plugin_info kernexec_plugin_info = {
105189 + .version = "201401260140",
105190 + .help = "method=[bts|or]\tinstrumentation method\n"
105191 +};
105192 +
105193 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
105194 +static void (*kernexec_instrument_retaddr)(rtx);
105195 +
105196 +/*
105197 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
105198 + */
105199 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
105200 +{
105201 + gimple asm_movabs_stmt;
105202 +
105203 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
105204 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
105205 + gimple_asm_set_volatile(asm_movabs_stmt, true);
105206 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
105207 + update_stmt(asm_movabs_stmt);
105208 +}
105209 +
105210 +/*
105211 + * find all asm() stmts that clobber r12 and add a reload of r12
105212 + */
105213 +static unsigned int execute_kernexec_reload(void)
105214 +{
105215 + basic_block bb;
105216 +
105217 + // 1. loop through BBs and GIMPLE statements
105218 + FOR_EACH_BB_FN(bb, cfun) {
105219 + gimple_stmt_iterator gsi;
105220 +
105221 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
105222 + // gimple match: __asm__ ("" : : : "r12");
105223 + gimple asm_stmt;
105224 + size_t nclobbers;
105225 +
105226 + // is it an asm ...
105227 + asm_stmt = gsi_stmt(gsi);
105228 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
105229 + continue;
105230 +
105231 + // ... clobbering r12
105232 + nclobbers = gimple_asm_nclobbers(asm_stmt);
105233 + while (nclobbers--) {
105234 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
105235 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
105236 + continue;
105237 + kernexec_reload_fptr_mask(&gsi);
105238 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
105239 + break;
105240 + }
105241 + }
105242 + }
105243 +
105244 + return 0;
105245 +}
105246 +
105247 +/*
105248 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
105249 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
105250 + */
105251 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
105252 +{
105253 + gimple assign_intptr, assign_new_fptr, call_stmt;
105254 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
105255 +
105256 + call_stmt = gsi_stmt(*gsi);
105257 + old_fptr = gimple_call_fn(call_stmt);
105258 +
105259 + // create temporary unsigned long variable used for bitops and cast fptr to it
105260 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
105261 + add_referenced_var(intptr);
105262 + intptr = make_ssa_name(intptr, NULL);
105263 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
105264 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
105265 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
105266 + update_stmt(assign_intptr);
105267 +
105268 + // apply logical or to temporary unsigned long and bitmask
105269 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
105270 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
105271 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
105272 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
105273 + assign_intptr = gimple_build_assign(intptr, orptr);
105274 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
105275 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
105276 + update_stmt(assign_intptr);
105277 +
105278 + // cast temporary unsigned long back to a temporary fptr variable
105279 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
105280 + add_referenced_var(new_fptr);
105281 + new_fptr = make_ssa_name(new_fptr, NULL);
105282 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
105283 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
105284 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
105285 + update_stmt(assign_new_fptr);
105286 +
105287 + // replace call stmt fn with the new fptr
105288 + gimple_call_set_fn(call_stmt, new_fptr);
105289 + update_stmt(call_stmt);
105290 +}
105291 +
105292 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
105293 +{
105294 + gimple asm_or_stmt, call_stmt;
105295 + tree old_fptr, new_fptr, input, output;
105296 +#if BUILDING_GCC_VERSION <= 4007
105297 + VEC(tree, gc) *inputs = NULL;
105298 + VEC(tree, gc) *outputs = NULL;
105299 +#else
105300 + vec<tree, va_gc> *inputs = NULL;
105301 + vec<tree, va_gc> *outputs = NULL;
105302 +#endif
105303 +
105304 + call_stmt = gsi_stmt(*gsi);
105305 + old_fptr = gimple_call_fn(call_stmt);
105306 +
105307 + // create temporary fptr variable
105308 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
105309 + add_referenced_var(new_fptr);
105310 + new_fptr = make_ssa_name(new_fptr, NULL);
105311 +
105312 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
105313 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
105314 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
105315 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
105316 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
105317 +#if BUILDING_GCC_VERSION <= 4007
105318 + VEC_safe_push(tree, gc, inputs, input);
105319 + VEC_safe_push(tree, gc, outputs, output);
105320 +#else
105321 + vec_safe_push(inputs, input);
105322 + vec_safe_push(outputs, output);
105323 +#endif
105324 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
105325 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
105326 + gimple_asm_set_volatile(asm_or_stmt, true);
105327 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
105328 + update_stmt(asm_or_stmt);
105329 +
105330 + // replace call stmt fn with the new fptr
105331 + gimple_call_set_fn(call_stmt, new_fptr);
105332 + update_stmt(call_stmt);
105333 +}
105334 +
105335 +/*
105336 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
105337 + */
105338 +static unsigned int execute_kernexec_fptr(void)
105339 +{
105340 + basic_block bb;
105341 +
105342 + // 1. loop through BBs and GIMPLE statements
105343 + FOR_EACH_BB_FN(bb, cfun) {
105344 + gimple_stmt_iterator gsi;
105345 +
105346 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
105347 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
105348 + tree fn;
105349 + gimple call_stmt;
105350 +
105351 + // is it a call ...
105352 + call_stmt = gsi_stmt(gsi);
105353 + if (!is_gimple_call(call_stmt))
105354 + continue;
105355 + fn = gimple_call_fn(call_stmt);
105356 + if (TREE_CODE(fn) == ADDR_EXPR)
105357 + continue;
105358 + if (TREE_CODE(fn) != SSA_NAME)
105359 + gcc_unreachable();
105360 +
105361 + // ... through a function pointer
105362 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
105363 + fn = SSA_NAME_VAR(fn);
105364 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
105365 + debug_tree(fn);
105366 + gcc_unreachable();
105367 + }
105368 + }
105369 + fn = TREE_TYPE(fn);
105370 + if (TREE_CODE(fn) != POINTER_TYPE)
105371 + continue;
105372 + fn = TREE_TYPE(fn);
105373 + if (TREE_CODE(fn) != FUNCTION_TYPE)
105374 + continue;
105375 +
105376 + kernexec_instrument_fptr(&gsi);
105377 +
105378 +//debug_tree(gimple_call_fn(call_stmt));
105379 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
105380 + }
105381 + }
105382 +
105383 + return 0;
105384 +}
105385 +
105386 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
105387 +static void kernexec_instrument_retaddr_bts(rtx insn)
105388 +{
105389 + rtx btsq;
105390 + rtvec argvec, constraintvec, labelvec;
105391 + int line;
105392 +
105393 + // create asm volatile("btsq $63,(%%rsp)":::)
105394 + argvec = rtvec_alloc(0);
105395 + constraintvec = rtvec_alloc(0);
105396 + labelvec = rtvec_alloc(0);
105397 + line = expand_location(RTL_LOCATION(insn)).line;
105398 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
105399 + MEM_VOLATILE_P(btsq) = 1;
105400 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
105401 + emit_insn_before(btsq, insn);
105402 +}
105403 +
105404 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
105405 +static void kernexec_instrument_retaddr_or(rtx insn)
105406 +{
105407 + rtx orq;
105408 + rtvec argvec, constraintvec, labelvec;
105409 + int line;
105410 +
105411 + // create asm volatile("orq %%r12,(%%rsp)":::)
105412 + argvec = rtvec_alloc(0);
105413 + constraintvec = rtvec_alloc(0);
105414 + labelvec = rtvec_alloc(0);
105415 + line = expand_location(RTL_LOCATION(insn)).line;
105416 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
105417 + MEM_VOLATILE_P(orq) = 1;
105418 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
105419 + emit_insn_before(orq, insn);
105420 +}
105421 +
105422 +/*
105423 + * find all asm level function returns and forcibly set the highest bit of the return address
105424 + */
105425 +static unsigned int execute_kernexec_retaddr(void)
105426 +{
105427 + rtx insn;
105428 +
105429 +// if (stack_realign_drap)
105430 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
105431 +
105432 + // 1. find function returns
105433 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
105434 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
105435 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
105436 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
105437 + rtx body;
105438 +
105439 + // is it a retn
105440 + if (!JUMP_P(insn))
105441 + continue;
105442 + body = PATTERN(insn);
105443 + if (GET_CODE(body) == PARALLEL)
105444 + body = XVECEXP(body, 0, 0);
105445 + if (!ANY_RETURN_P(body))
105446 + continue;
105447 + kernexec_instrument_retaddr(insn);
105448 + }
105449 +
105450 +// print_simple_rtl(stderr, get_insns());
105451 +// print_rtl(stderr, get_insns());
105452 +
105453 + return 0;
105454 +}
105455 +
105456 +static bool kernexec_cmodel_check(void)
105457 +{
105458 + tree section;
105459 +
105460 + if (ix86_cmodel != CM_KERNEL)
105461 + return false;
105462 +
105463 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
105464 + if (!section || !TREE_VALUE(section))
105465 + return true;
105466 +
105467 + section = TREE_VALUE(TREE_VALUE(section));
105468 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
105469 + return true;
105470 +
105471 + return false;
105472 +}
105473 +
105474 +#if BUILDING_GCC_VERSION >= 4009
105475 +static const struct pass_data kernexec_reload_pass_data = {
105476 +#else
105477 +static struct gimple_opt_pass kernexec_reload_pass = {
105478 + .pass = {
105479 +#endif
105480 + .type = GIMPLE_PASS,
105481 + .name = "kernexec_reload",
105482 +#if BUILDING_GCC_VERSION >= 4008
105483 + .optinfo_flags = OPTGROUP_NONE,
105484 +#endif
105485 +#if BUILDING_GCC_VERSION >= 4009
105486 + .has_gate = true,
105487 + .has_execute = true,
105488 +#else
105489 + .gate = kernexec_cmodel_check,
105490 + .execute = execute_kernexec_reload,
105491 + .sub = NULL,
105492 + .next = NULL,
105493 + .static_pass_number = 0,
105494 +#endif
105495 + .tv_id = TV_NONE,
105496 + .properties_required = 0,
105497 + .properties_provided = 0,
105498 + .properties_destroyed = 0,
105499 + .todo_flags_start = 0,
105500 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
105501 +#if BUILDING_GCC_VERSION < 4009
105502 + }
105503 +#endif
105504 +};
105505 +
105506 +#if BUILDING_GCC_VERSION >= 4009
105507 +static const struct pass_data kernexec_fptr_pass_data = {
105508 +#else
105509 +static struct gimple_opt_pass kernexec_fptr_pass = {
105510 + .pass = {
105511 +#endif
105512 + .type = GIMPLE_PASS,
105513 + .name = "kernexec_fptr",
105514 +#if BUILDING_GCC_VERSION >= 4008
105515 + .optinfo_flags = OPTGROUP_NONE,
105516 +#endif
105517 +#if BUILDING_GCC_VERSION >= 4009
105518 + .has_gate = true,
105519 + .has_execute = true,
105520 +#else
105521 + .gate = kernexec_cmodel_check,
105522 + .execute = execute_kernexec_fptr,
105523 + .sub = NULL,
105524 + .next = NULL,
105525 + .static_pass_number = 0,
105526 +#endif
105527 + .tv_id = TV_NONE,
105528 + .properties_required = 0,
105529 + .properties_provided = 0,
105530 + .properties_destroyed = 0,
105531 + .todo_flags_start = 0,
105532 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
105533 +#if BUILDING_GCC_VERSION < 4009
105534 + }
105535 +#endif
105536 +};
105537 +
105538 +#if BUILDING_GCC_VERSION >= 4009
105539 +static const struct pass_data kernexec_retaddr_pass_data = {
105540 +#else
105541 +static struct rtl_opt_pass kernexec_retaddr_pass = {
105542 + .pass = {
105543 +#endif
105544 + .type = RTL_PASS,
105545 + .name = "kernexec_retaddr",
105546 +#if BUILDING_GCC_VERSION >= 4008
105547 + .optinfo_flags = OPTGROUP_NONE,
105548 +#endif
105549 +#if BUILDING_GCC_VERSION >= 4009
105550 + .has_gate = true,
105551 + .has_execute = true,
105552 +#else
105553 + .gate = kernexec_cmodel_check,
105554 + .execute = execute_kernexec_retaddr,
105555 + .sub = NULL,
105556 + .next = NULL,
105557 + .static_pass_number = 0,
105558 +#endif
105559 + .tv_id = TV_NONE,
105560 + .properties_required = 0,
105561 + .properties_provided = 0,
105562 + .properties_destroyed = 0,
105563 + .todo_flags_start = 0,
105564 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
105565 +#if BUILDING_GCC_VERSION < 4009
105566 + }
105567 +#endif
105568 +};
105569 +
105570 +#if BUILDING_GCC_VERSION >= 4009
105571 +namespace {
105572 +class kernexec_reload_pass : public gimple_opt_pass {
105573 +public:
105574 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
105575 + bool gate() { return kernexec_cmodel_check(); }
105576 + unsigned int execute() { return execute_kernexec_reload(); }
105577 +};
105578 +
105579 +class kernexec_fptr_pass : public gimple_opt_pass {
105580 +public:
105581 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
105582 + bool gate() { return kernexec_cmodel_check(); }
105583 + unsigned int execute() { return execute_kernexec_fptr(); }
105584 +};
105585 +
105586 +class kernexec_retaddr_pass : public rtl_opt_pass {
105587 +public:
105588 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
105589 + bool gate() { return kernexec_cmodel_check(); }
105590 + unsigned int execute() { return execute_kernexec_retaddr(); }
105591 +};
105592 +}
105593 +#endif
105594 +
105595 +static struct opt_pass *make_kernexec_reload_pass(void)
105596 +{
105597 +#if BUILDING_GCC_VERSION >= 4009
105598 + return new kernexec_reload_pass();
105599 +#else
105600 + return &kernexec_reload_pass.pass;
105601 +#endif
105602 +}
105603 +
105604 +static struct opt_pass *make_kernexec_fptr_pass(void)
105605 +{
105606 +#if BUILDING_GCC_VERSION >= 4009
105607 + return new kernexec_fptr_pass();
105608 +#else
105609 + return &kernexec_fptr_pass.pass;
105610 +#endif
105611 +}
105612 +
105613 +static struct opt_pass *make_kernexec_retaddr_pass(void)
105614 +{
105615 +#if BUILDING_GCC_VERSION >= 4009
105616 + return new kernexec_retaddr_pass();
105617 +#else
105618 + return &kernexec_retaddr_pass.pass;
105619 +#endif
105620 +}
105621 +
105622 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105623 +{
105624 + const char * const plugin_name = plugin_info->base_name;
105625 + const int argc = plugin_info->argc;
105626 + const struct plugin_argument * const argv = plugin_info->argv;
105627 + int i;
105628 + struct register_pass_info kernexec_reload_pass_info;
105629 + struct register_pass_info kernexec_fptr_pass_info;
105630 + struct register_pass_info kernexec_retaddr_pass_info;
105631 +
105632 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
105633 + kernexec_reload_pass_info.reference_pass_name = "ssa";
105634 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
105635 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105636 +
105637 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
105638 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
105639 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
105640 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105641 +
105642 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
105643 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
105644 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
105645 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105646 +
105647 + if (!plugin_default_version_check(version, &gcc_version)) {
105648 + error(G_("incompatible gcc/plugin versions"));
105649 + return 1;
105650 + }
105651 +
105652 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
105653 +
105654 + if (TARGET_64BIT == 0)
105655 + return 0;
105656 +
105657 + for (i = 0; i < argc; ++i) {
105658 + if (!strcmp(argv[i].key, "method")) {
105659 + if (!argv[i].value) {
105660 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105661 + continue;
105662 + }
105663 + if (!strcmp(argv[i].value, "bts")) {
105664 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
105665 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
105666 + } else if (!strcmp(argv[i].value, "or")) {
105667 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
105668 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
105669 + fix_register("r12", 1, 1);
105670 + } else
105671 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
105672 + continue;
105673 + }
105674 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105675 + }
105676 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
105677 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
105678 +
105679 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
105680 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
105681 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
105682 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
105683 +
105684 + return 0;
105685 +}
105686 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
105687 new file mode 100644
105688 index 0000000..f04b680
105689 --- /dev/null
105690 +++ b/tools/gcc/latent_entropy_plugin.c
105691 @@ -0,0 +1,325 @@
105692 +/*
105693 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
105694 + * Licensed under the GPL v2
105695 + *
105696 + * Note: the choice of the license means that the compilation process is
105697 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105698 + * but for the kernel it doesn't matter since it doesn't link against
105699 + * any of the gcc libraries
105700 + *
105701 + * gcc plugin to help generate a little bit of entropy from program state,
105702 + * used during boot in the kernel
105703 + *
105704 + * TODO:
105705 + * - add ipa pass to identify not explicitly marked candidate functions
105706 + * - mix in more program state (function arguments/return values, loop variables, etc)
105707 + * - more instrumentation control via attribute parameters
105708 + *
105709 + * BUGS:
105710 + * - LTO needs -flto-partition=none for now
105711 + */
105712 +
105713 +#include "gcc-common.h"
105714 +
105715 +int plugin_is_GPL_compatible;
105716 +
105717 +static tree latent_entropy_decl;
105718 +
105719 +static struct plugin_info latent_entropy_plugin_info = {
105720 + .version = "201401260140",
105721 + .help = NULL
105722 +};
105723 +
105724 +static unsigned HOST_WIDE_INT seed;
105725 +static unsigned HOST_WIDE_INT get_random_const(void)
105726 +{
105727 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
105728 + return seed;
105729 +}
105730 +
105731 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
105732 +{
105733 + switch (TREE_CODE(*node)) {
105734 + default:
105735 + *no_add_attrs = true;
105736 + error("%qE attribute only applies to functions and variables", name);
105737 + break;
105738 +
105739 + case VAR_DECL:
105740 + if (DECL_INITIAL(*node)) {
105741 + *no_add_attrs = true;
105742 + error("variable %qD with %qE attribute must not be initialized", *node, name);
105743 + break;
105744 + }
105745 + DECL_INITIAL(*node) = build_int_cstu(long_long_unsigned_type_node, get_random_const());
105746 + break;
105747 +
105748 + case FUNCTION_DECL:
105749 + break;
105750 + }
105751 +
105752 + return NULL_TREE;
105753 +}
105754 +
105755 +static struct attribute_spec latent_entropy_attr = {
105756 + .name = "latent_entropy",
105757 + .min_length = 0,
105758 + .max_length = 0,
105759 + .decl_required = true,
105760 + .type_required = false,
105761 + .function_type_required = false,
105762 + .handler = handle_latent_entropy_attribute,
105763 +#if BUILDING_GCC_VERSION >= 4007
105764 + .affects_type_identity = false
105765 +#endif
105766 +};
105767 +
105768 +static void register_attributes(void *event_data, void *data)
105769 +{
105770 + register_attribute(&latent_entropy_attr);
105771 +}
105772 +
105773 +static bool gate_latent_entropy(void)
105774 +{
105775 + tree latent_entropy_attr;
105776 +
105777 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
105778 + return latent_entropy_attr != NULL_TREE;
105779 +}
105780 +
105781 +static enum tree_code get_op(tree *rhs)
105782 +{
105783 + static enum tree_code op;
105784 + unsigned HOST_WIDE_INT random_const;
105785 +
105786 + random_const = get_random_const();
105787 +
105788 + switch (op) {
105789 + case BIT_XOR_EXPR:
105790 + op = PLUS_EXPR;
105791 + break;
105792 +
105793 + case PLUS_EXPR:
105794 + if (rhs) {
105795 + op = LROTATE_EXPR;
105796 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
105797 + break;
105798 + }
105799 +
105800 + case LROTATE_EXPR:
105801 + default:
105802 + op = BIT_XOR_EXPR;
105803 + break;
105804 + }
105805 + if (rhs)
105806 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
105807 + return op;
105808 +}
105809 +
105810 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
105811 +{
105812 + gimple_stmt_iterator gsi;
105813 + gimple assign;
105814 + tree addxorrol, rhs;
105815 + enum tree_code op;
105816 +
105817 + op = get_op(&rhs);
105818 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
105819 + assign = gimple_build_assign(local_entropy, addxorrol);
105820 + gsi = gsi_after_labels(bb);
105821 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
105822 + update_stmt(assign);
105823 +//debug_bb(bb);
105824 +}
105825 +
105826 +static void perturb_latent_entropy(basic_block bb, tree rhs)
105827 +{
105828 + gimple_stmt_iterator gsi;
105829 + gimple assign;
105830 + tree addxorrol, temp;
105831 +
105832 + // 1. create temporary copy of latent_entropy
105833 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
105834 + add_referenced_var(temp);
105835 +
105836 + // 2. read...
105837 + temp = make_ssa_name(temp, NULL);
105838 + assign = gimple_build_assign(temp, latent_entropy_decl);
105839 + SSA_NAME_DEF_STMT(temp) = assign;
105840 + add_referenced_var(latent_entropy_decl);
105841 + gsi = gsi_after_labels(bb);
105842 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
105843 + update_stmt(assign);
105844 +
105845 + // 3. ...modify...
105846 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
105847 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
105848 + assign = gimple_build_assign(temp, addxorrol);
105849 + SSA_NAME_DEF_STMT(temp) = assign;
105850 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
105851 + update_stmt(assign);
105852 +
105853 + // 4. ...write latent_entropy
105854 + assign = gimple_build_assign(latent_entropy_decl, temp);
105855 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
105856 + update_stmt(assign);
105857 +}
105858 +
105859 +static unsigned int execute_latent_entropy(void)
105860 +{
105861 + basic_block bb;
105862 + gimple assign;
105863 + gimple_stmt_iterator gsi;
105864 + tree local_entropy;
105865 +
105866 + if (!latent_entropy_decl) {
105867 + struct varpool_node *node;
105868 +
105869 + FOR_EACH_VARIABLE(node) {
105870 + tree var = NODE_DECL(node);
105871 +
105872 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
105873 + continue;
105874 + latent_entropy_decl = var;
105875 +// debug_tree(var);
105876 + break;
105877 + }
105878 + if (!latent_entropy_decl) {
105879 +// debug_tree(current_function_decl);
105880 + return 0;
105881 + }
105882 + }
105883 +
105884 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
105885 +
105886 + // 1. create local entropy variable
105887 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
105888 + add_referenced_var(local_entropy);
105889 + mark_sym_for_renaming(local_entropy);
105890 +
105891 + // 2. initialize local entropy variable
105892 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
105893 + if (dom_info_available_p(CDI_DOMINATORS))
105894 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
105895 + gsi = gsi_start_bb(bb);
105896 +
105897 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
105898 +// gimple_set_location(assign, loc);
105899 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
105900 + update_stmt(assign);
105901 +//debug_bb(bb);
105902 + bb = bb->next_bb;
105903 +
105904 + // 3. instrument each BB with an operation on the local entropy variable
105905 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
105906 + perturb_local_entropy(bb, local_entropy);
105907 +//debug_bb(bb);
105908 + bb = bb->next_bb;
105909 + };
105910 +
105911 + // 4. mix local entropy into the global entropy variable
105912 + perturb_latent_entropy(EXIT_BLOCK_PTR_FOR_FN(cfun)->prev_bb, local_entropy);
105913 +//debug_bb(EXIT_BLOCK_PTR_FOR_FN(cfun)->prev_bb);
105914 + return 0;
105915 +}
105916 +
105917 +static void start_unit_callback(void *gcc_data, void *user_data)
105918 +{
105919 + tree latent_entropy_type;
105920 +
105921 + seed = get_random_seed(false);
105922 +
105923 + if (in_lto_p)
105924 + return;
105925 +
105926 + // extern volatile u64 latent_entropy
105927 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
105928 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
105929 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
105930 +
105931 + TREE_STATIC(latent_entropy_decl) = 1;
105932 + TREE_PUBLIC(latent_entropy_decl) = 1;
105933 + TREE_USED(latent_entropy_decl) = 1;
105934 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
105935 + DECL_EXTERNAL(latent_entropy_decl) = 1;
105936 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
105937 + lang_hooks.decls.pushdecl(latent_entropy_decl);
105938 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
105939 +// varpool_finalize_decl(latent_entropy_decl);
105940 +// varpool_mark_needed_node(latent_entropy_decl);
105941 +}
105942 +
105943 +#if BUILDING_GCC_VERSION >= 4009
105944 +static const struct pass_data latent_entropy_pass_data = {
105945 +#else
105946 +static struct gimple_opt_pass latent_entropy_pass = {
105947 + .pass = {
105948 +#endif
105949 + .type = GIMPLE_PASS,
105950 + .name = "latent_entropy",
105951 +#if BUILDING_GCC_VERSION >= 4008
105952 + .optinfo_flags = OPTGROUP_NONE,
105953 +#endif
105954 +#if BUILDING_GCC_VERSION >= 4009
105955 + .has_gate = true,
105956 + .has_execute = true,
105957 +#else
105958 + .gate = gate_latent_entropy,
105959 + .execute = execute_latent_entropy,
105960 + .sub = NULL,
105961 + .next = NULL,
105962 + .static_pass_number = 0,
105963 +#endif
105964 + .tv_id = TV_NONE,
105965 + .properties_required = PROP_gimple_leh | PROP_cfg,
105966 + .properties_provided = 0,
105967 + .properties_destroyed = 0,
105968 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
105969 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
105970 +#if BUILDING_GCC_VERSION < 4009
105971 + }
105972 +#endif
105973 +};
105974 +
105975 +#if BUILDING_GCC_VERSION >= 4009
105976 +namespace {
105977 +class latent_entropy_pass : public gimple_opt_pass {
105978 +public:
105979 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
105980 + bool gate() { return gate_latent_entropy(); }
105981 + unsigned int execute() { return execute_latent_entropy(); }
105982 +};
105983 +}
105984 +#endif
105985 +
105986 +static struct opt_pass *make_latent_entropy_pass(void)
105987 +{
105988 +#if BUILDING_GCC_VERSION >= 4009
105989 + return new latent_entropy_pass();
105990 +#else
105991 + return &latent_entropy_pass.pass;
105992 +#endif
105993 +}
105994 +
105995 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105996 +{
105997 + const char * const plugin_name = plugin_info->base_name;
105998 + struct register_pass_info latent_entropy_pass_info;
105999 +
106000 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
106001 + latent_entropy_pass_info.reference_pass_name = "optimized";
106002 + latent_entropy_pass_info.ref_pass_instance_number = 1;
106003 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
106004 +
106005 + if (!plugin_default_version_check(version, &gcc_version)) {
106006 + error(G_("incompatible gcc/plugin versions"));
106007 + return 1;
106008 + }
106009 +
106010 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
106011 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
106012 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
106013 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
106014 +
106015 + return 0;
106016 +}
106017 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
106018 new file mode 100644
106019 index 0000000..4aceb10
106020 --- /dev/null
106021 +++ b/tools/gcc/randomize_layout_plugin.c
106022 @@ -0,0 +1,746 @@
106023 +/*
106024 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
106025 + * and PaX Team <pageexec@freemail.hu>
106026 + * Licensed under the GPL v2
106027 + *
106028 + * Usage:
106029 + * $ # for 4.5/4.6/C based 4.7
106030 + * $ 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
106031 + * $ # for C++ based 4.7/4.8+
106032 + * $ 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
106033 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
106034 + */
106035 +
106036 +#include "gcc-common.h"
106037 +
106038 +#define ORIG_TYPE_NAME(node) \
106039 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
106040 +
106041 +int plugin_is_GPL_compatible;
106042 +
106043 +static int performance_mode;
106044 +
106045 +static struct plugin_info randomize_layout_plugin_info = {
106046 + .version = "201401251240",
106047 + .help = "disable\t\t\tdo not activate plugin\n"
106048 + "seed\t\t\tprovide a required 64-byte seed in hex format\n"
106049 + "performance-mode\tenable cacheline-aware layout randomization\n"
106050 +};
106051 +
106052 +/* from old Linux dcache.h */
106053 +static inline unsigned long
106054 +partial_name_hash(unsigned long c, unsigned long prevhash)
106055 +{
106056 + return (prevhash + (c << 4) + (c >> 4)) * 11;
106057 +}
106058 +static inline unsigned int
106059 +name_hash(const unsigned char *name)
106060 +{
106061 + unsigned long hash = 0;
106062 + unsigned int len = strlen((const char *)name);
106063 + while (len--)
106064 + hash = partial_name_hash(*name++, hash);
106065 + return (unsigned int)hash;
106066 +}
106067 +
106068 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
106069 +{
106070 + tree type;
106071 +
106072 + *no_add_attrs = true;
106073 + if (TREE_CODE(*node) == FUNCTION_DECL) {
106074 + error("%qE attribute does not apply to functions (%qF)", name, *node);
106075 + return NULL_TREE;
106076 + }
106077 +
106078 + if (TREE_CODE(*node) == PARM_DECL) {
106079 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
106080 + return NULL_TREE;
106081 + }
106082 +
106083 + if (TREE_CODE(*node) == VAR_DECL) {
106084 + error("%qE attribute does not apply to variables (%qD)", name, *node);
106085 + return NULL_TREE;
106086 + }
106087 +
106088 + if (TYPE_P(*node)) {
106089 + type = *node;
106090 + } else {
106091 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
106092 + type = TREE_TYPE(*node);
106093 + }
106094 +
106095 + if (TREE_CODE(type) != RECORD_TYPE) {
106096 + error("%qE attribute used on %qT applies to struct types only", name, type);
106097 + return NULL_TREE;
106098 + }
106099 +
106100 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
106101 + error("%qE attribute is already applied to the type %qT", name, type);
106102 + return NULL_TREE;
106103 + }
106104 +
106105 + *no_add_attrs = false;
106106 +
106107 + return NULL_TREE;
106108 +}
106109 +
106110 +/* set on complete types that we don't need to inspect further at all */
106111 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
106112 +{
106113 + *no_add_attrs = false;
106114 + return NULL_TREE;
106115 +}
106116 +
106117 +/*
106118 + * set on types that we've performed a shuffle on, to prevent re-shuffling
106119 + * this does not preclude us from inspecting its fields for potential shuffles
106120 + */
106121 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
106122 +{
106123 + *no_add_attrs = false;
106124 + return NULL_TREE;
106125 +}
106126 +
106127 +/*
106128 + * 64bit variant of Bob Jenkins' public domain PRNG
106129 + * 256 bits of internal state
106130 + */
106131 +
106132 +typedef unsigned long long u64;
106133 +
106134 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
106135 +
106136 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
106137 +static u64 ranval(ranctx *x) {
106138 + u64 e = x->a - rot(x->b, 7);
106139 + x->a = x->b ^ rot(x->c, 13);
106140 + x->b = x->c + rot(x->d, 37);
106141 + x->c = x->d + e;
106142 + x->d = e + x->a;
106143 + return x->d;
106144 +}
106145 +
106146 +static void raninit(ranctx *x, u64 *seed) {
106147 + int i;
106148 +
106149 + x->a = seed[0];
106150 + x->b = seed[1];
106151 + x->c = seed[2];
106152 + x->d = seed[3];
106153 +
106154 + for (i=0; i < 30; ++i)
106155 + (void)ranval(x);
106156 +}
106157 +
106158 +static u64 shuffle_seed[4];
106159 +
106160 +struct partition_group {
106161 + tree tree_start;
106162 + unsigned long start;
106163 + unsigned long length;
106164 +};
106165 +
106166 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
106167 +{
106168 + unsigned long i;
106169 + unsigned long accum_size = 0;
106170 + unsigned long accum_length = 0;
106171 + unsigned long group_idx = 0;
106172 +
106173 + gcc_assert(length < INT_MAX);
106174 +
106175 + memset(size_groups, 0, sizeof(struct partition_group) * length);
106176 +
106177 + for (i = 0; i < length; i++) {
106178 + if (size_groups[group_idx].tree_start == NULL_TREE) {
106179 + size_groups[group_idx].tree_start = fields[i];
106180 + size_groups[group_idx].start = i;
106181 + accum_length = 0;
106182 + accum_size = 0;
106183 + }
106184 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
106185 + accum_length++;
106186 + if (accum_size >= 64) {
106187 + size_groups[group_idx].length = accum_length;
106188 + accum_length = 0;
106189 + group_idx++;
106190 + }
106191 + }
106192 +
106193 + if (size_groups[group_idx].tree_start != NULL_TREE &&
106194 + !size_groups[group_idx].length) {
106195 + size_groups[group_idx].length = accum_length;
106196 + group_idx++;
106197 + }
106198 +
106199 + *num_groups = group_idx;
106200 +}
106201 +
106202 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
106203 +{
106204 + unsigned long i, x;
106205 + struct partition_group size_group[length];
106206 + unsigned long num_groups = 0;
106207 + unsigned long randnum;
106208 +
106209 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
106210 + for (i = num_groups - 1; i > 0; i--) {
106211 + struct partition_group tmp;
106212 + randnum = ranval(prng_state) % (i + 1);
106213 + tmp = size_group[i];
106214 + size_group[i] = size_group[randnum];
106215 + size_group[randnum] = tmp;
106216 + }
106217 +
106218 + for (x = 0; x < num_groups; x++) {
106219 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
106220 + tree tmp;
106221 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
106222 + continue;
106223 + randnum = ranval(prng_state) % (i + 1);
106224 + // we could handle this case differently if desired
106225 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
106226 + continue;
106227 + tmp = newtree[i];
106228 + newtree[i] = newtree[randnum];
106229 + newtree[randnum] = tmp;
106230 + }
106231 + }
106232 +}
106233 +
106234 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
106235 +{
106236 + unsigned long i, randnum;
106237 +
106238 + for (i = length - 1; i > 0; i--) {
106239 + tree tmp;
106240 + randnum = ranval(prng_state) % (i + 1);
106241 + tmp = newtree[i];
106242 + newtree[i] = newtree[randnum];
106243 + newtree[randnum] = tmp;
106244 + }
106245 +}
106246 +
106247 +/* modern in-place Fisher-Yates shuffle */
106248 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
106249 +{
106250 + unsigned long i;
106251 + u64 seed[4];
106252 + ranctx prng_state;
106253 + const unsigned char *structname;
106254 +
106255 + if (length == 0)
106256 + return;
106257 +
106258 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
106259 +
106260 + structname = ORIG_TYPE_NAME(type);
106261 +
106262 +#ifdef __DEBUG_PLUGIN
106263 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
106264 +#ifdef __DEBUG_VERBOSE
106265 + debug_tree((tree)type);
106266 +#endif
106267 +#endif
106268 +
106269 + for (i = 0; i < 4; i++) {
106270 + seed[i] = shuffle_seed[i];
106271 + seed[i] ^= name_hash(structname);
106272 + }
106273 +
106274 + raninit(&prng_state, (u64 *)&seed);
106275 +
106276 + if (performance_mode)
106277 + performance_shuffle(newtree, length, &prng_state);
106278 + else
106279 + full_shuffle(newtree, length, &prng_state);
106280 +}
106281 +
106282 +static bool is_flexible_array(const_tree field)
106283 +{
106284 + const_tree fieldtype;
106285 + const_tree typesize;
106286 + const_tree elemtype;
106287 + const_tree elemsize;
106288 +
106289 + fieldtype = TREE_TYPE(field);
106290 + typesize = TYPE_SIZE(fieldtype);
106291 +
106292 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
106293 + return false;
106294 +
106295 + elemtype = TREE_TYPE(fieldtype);
106296 + elemsize = TYPE_SIZE(elemtype);
106297 +
106298 + /* size of type is represented in bits */
106299 +
106300 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
106301 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
106302 + return true;
106303 +
106304 + if (typesize != NULL_TREE &&
106305 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
106306 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
106307 + return true;
106308 +
106309 + return false;
106310 +}
106311 +
106312 +static int relayout_struct(tree type)
106313 +{
106314 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
106315 + unsigned long shuffle_length = num_fields;
106316 + tree field;
106317 + tree newtree[num_fields];
106318 + unsigned long i;
106319 + tree list;
106320 + tree variant;
106321 +
106322 + if (TYPE_FIELDS(type) == NULL_TREE)
106323 + return 0;
106324 +
106325 + if (num_fields < 2)
106326 + return 0;
106327 +
106328 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
106329 +
106330 + gcc_assert(num_fields < INT_MAX);
106331 +
106332 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
106333 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
106334 + return 0;
106335 +
106336 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
106337 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
106338 + newtree[i] = field;
106339 + }
106340 +
106341 + /*
106342 + * enforce that we don't randomize the layout of the last
106343 + * element of a struct if it's a 0 or 1-length array
106344 + * or a proper flexible array
106345 + */
106346 + if (is_flexible_array(newtree[num_fields - 1]))
106347 + shuffle_length--;
106348 +
106349 + shuffle(type, (tree *)newtree, shuffle_length);
106350 +
106351 + /*
106352 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
106353 + * as gcc provides no other way to detect such code
106354 + */
106355 + list = make_node(FIELD_DECL);
106356 + TREE_CHAIN(list) = newtree[0];
106357 + TREE_TYPE(list) = void_type_node;
106358 + DECL_SIZE(list) = bitsize_zero_node;
106359 + DECL_NONADDRESSABLE_P(list) = 1;
106360 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
106361 + DECL_SIZE_UNIT(list) = size_zero_node;
106362 + DECL_FIELD_OFFSET(list) = size_zero_node;
106363 + // to satisfy the constify plugin
106364 + TREE_READONLY(list) = 1;
106365 +
106366 + for (i = 0; i < num_fields - 1; i++)
106367 + TREE_CHAIN(newtree[i]) = newtree[i+1];
106368 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
106369 +
106370 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
106371 + TYPE_FIELDS(variant) = list;
106372 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
106373 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
106374 + // force a re-layout
106375 + TYPE_SIZE(variant) = NULL_TREE;
106376 + layout_type(variant);
106377 + }
106378 +
106379 + return 1;
106380 +}
106381 +
106382 +/* from constify plugin */
106383 +static const_tree get_field_type(const_tree field)
106384 +{
106385 + return strip_array_types(TREE_TYPE(field));
106386 +}
106387 +
106388 +/* from constify plugin */
106389 +static bool is_fptr(const_tree fieldtype)
106390 +{
106391 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
106392 + return false;
106393 +
106394 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
106395 +}
106396 +
106397 +/* derived from constify plugin */
106398 +static int is_pure_ops_struct(const_tree node)
106399 +{
106400 + const_tree field;
106401 +
106402 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
106403 +
106404 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
106405 + const_tree fieldtype = get_field_type(field);
106406 + enum tree_code code = TREE_CODE(fieldtype);
106407 +
106408 + if (node == fieldtype)
106409 + continue;
106410 +
106411 + if (!is_fptr(fieldtype))
106412 + return 0;
106413 +
106414 + if (code != RECORD_TYPE && code != UNION_TYPE)
106415 + continue;
106416 +
106417 + if (!is_pure_ops_struct(fieldtype))
106418 + return 0;
106419 + }
106420 +
106421 + return 1;
106422 +}
106423 +
106424 +static void randomize_type(tree type)
106425 +{
106426 + tree variant;
106427 +
106428 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
106429 +
106430 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
106431 + return;
106432 +
106433 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
106434 + relayout_struct(type);
106435 +
106436 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
106437 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
106438 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
106439 + }
106440 +#ifdef __DEBUG_PLUGIN
106441 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
106442 +#ifdef __DEBUG_VERBOSE
106443 + debug_tree(type);
106444 +#endif
106445 +#endif
106446 +}
106447 +
106448 +static void finish_type(void *event_data, void *data)
106449 +{
106450 + tree type = (tree)event_data;
106451 +
106452 + if (type == NULL_TREE || type == error_mark_node)
106453 + return;
106454 +
106455 + if (TREE_CODE(type) != RECORD_TYPE)
106456 + return;
106457 +
106458 + if (TYPE_FIELDS(type) == NULL_TREE)
106459 + return;
106460 +
106461 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
106462 + return;
106463 +
106464 +#ifdef __DEBUG_PLUGIN
106465 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
106466 +#endif
106467 +#ifdef __DEBUG_VERBOSE
106468 + debug_tree(type);
106469 +#endif
106470 + randomize_type(type);
106471 +
106472 + return;
106473 +}
106474 +
106475 +static struct attribute_spec randomize_layout_attr = {
106476 + .name = "randomize_layout",
106477 + // related to args
106478 + .min_length = 0,
106479 + .max_length = 0,
106480 + .decl_required = false,
106481 + // need type declaration
106482 + .type_required = true,
106483 + .function_type_required = false,
106484 + .handler = handle_randomize_layout_attr,
106485 +#if BUILDING_GCC_VERSION >= 4007
106486 + .affects_type_identity = true
106487 +#endif
106488 +};
106489 +
106490 +static struct attribute_spec no_randomize_layout_attr = {
106491 + .name = "no_randomize_layout",
106492 + // related to args
106493 + .min_length = 0,
106494 + .max_length = 0,
106495 + .decl_required = false,
106496 + // need type declaration
106497 + .type_required = true,
106498 + .function_type_required = false,
106499 + .handler = handle_randomize_layout_attr,
106500 +#if BUILDING_GCC_VERSION >= 4007
106501 + .affects_type_identity = true
106502 +#endif
106503 +};
106504 +
106505 +static struct attribute_spec randomize_considered_attr = {
106506 + .name = "randomize_considered",
106507 + // related to args
106508 + .min_length = 0,
106509 + .max_length = 0,
106510 + .decl_required = false,
106511 + // need type declaration
106512 + .type_required = true,
106513 + .function_type_required = false,
106514 + .handler = handle_randomize_considered_attr,
106515 +#if BUILDING_GCC_VERSION >= 4007
106516 + .affects_type_identity = false
106517 +#endif
106518 +};
106519 +
106520 +static struct attribute_spec randomize_performed_attr = {
106521 + .name = "randomize_performed",
106522 + // related to args
106523 + .min_length = 0,
106524 + .max_length = 0,
106525 + .decl_required = false,
106526 + // need type declaration
106527 + .type_required = true,
106528 + .function_type_required = false,
106529 + .handler = handle_randomize_performed_attr,
106530 +#if BUILDING_GCC_VERSION >= 4007
106531 + .affects_type_identity = false
106532 +#endif
106533 +};
106534 +
106535 +static void register_attributes(void *event_data, void *data)
106536 +{
106537 + register_attribute(&randomize_layout_attr);
106538 + register_attribute(&no_randomize_layout_attr);
106539 + register_attribute(&randomize_considered_attr);
106540 + register_attribute(&randomize_performed_attr);
106541 +}
106542 +
106543 +/*
106544 + * iterate over all statements to find "bad" casts:
106545 + * those where the address of the start of a structure is cast
106546 + * to a pointer of a structure of a different type, or a
106547 + * structure pointer type is cast to a different structure pointer type
106548 + */
106549 +static unsigned int find_bad_casts(void)
106550 +{
106551 + basic_block bb;
106552 +
106553 + FOR_ALL_BB(bb) {
106554 + gimple_stmt_iterator gsi;
106555 +
106556 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106557 + gimple stmt;
106558 + const_tree lhs;
106559 + const_tree lhs_type;
106560 + const_tree rhs1;
106561 + const_tree rhs_type;
106562 + const_tree ptr_lhs_type;
106563 + const_tree ptr_rhs_type;
106564 + const_tree op0;
106565 + const_tree op0_type;
106566 + enum tree_code rhs_code;
106567 +
106568 + stmt = gsi_stmt(gsi);
106569 +
106570 +#ifdef __DEBUG_PLUGIN
106571 +#ifdef __DEBUG_VERBOSE
106572 + debug_gimple_stmt(stmt);
106573 + debug_tree(gimple_get_lhs(stmt));
106574 +#endif
106575 +#endif
106576 +
106577 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
106578 + continue;
106579 +
106580 +#ifdef __DEBUG_PLUGIN
106581 +#ifdef __DEBUG_VERBOSE
106582 + debug_tree(gimple_assign_rhs1(stmt));
106583 +#endif
106584 +#endif
106585 +
106586 + rhs_code = gimple_assign_rhs_code(stmt);
106587 +
106588 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
106589 + continue;
106590 +
106591 + lhs = gimple_get_lhs(stmt);
106592 + lhs_type = TREE_TYPE(lhs);
106593 + rhs1 = gimple_assign_rhs1(stmt);
106594 + rhs_type = TREE_TYPE(rhs1);
106595 +
106596 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
106597 + TREE_CODE(lhs_type) != POINTER_TYPE)
106598 + continue;
106599 +
106600 + ptr_lhs_type = strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type)));
106601 + ptr_rhs_type = strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type)));
106602 +
106603 + if (TREE_CODE(ptr_lhs_type) != RECORD_TYPE)
106604 + continue;
106605 +
106606 + if (ptr_rhs_type == void_type_node)
106607 + continue;
106608 +
106609 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
106610 +#ifndef __DEBUG_PLUGIN
106611 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
106612 +#endif
106613 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
106614 + continue;
106615 + }
106616 +
106617 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
106618 + continue;
106619 +
106620 + if (rhs_code == ADDR_EXPR) {
106621 + op0 = TREE_OPERAND(rhs1, 0);
106622 +
106623 + if (op0 == NULL_TREE)
106624 + continue;
106625 +
106626 + if (TREE_CODE(op0) != VAR_DECL)
106627 + continue;
106628 +
106629 + op0_type = strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0)));
106630 + if (op0_type == ptr_lhs_type)
106631 + continue;
106632 +
106633 +#ifndef __DEBUG_PLUGIN
106634 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
106635 +#endif
106636 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
106637 + } else {
106638 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
106639 + /* skip bogus type casts introduced by container_of */
106640 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
106641 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
106642 + continue;
106643 +#ifndef __DEBUG_PLUGIN
106644 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
106645 +#endif
106646 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
106647 + }
106648 +
106649 + }
106650 + }
106651 + return 0;
106652 +}
106653 +
106654 +#if BUILDING_GCC_VERSION >= 4009
106655 +static const struct pass_data randomize_layout_bad_cast_data = {
106656 +#else
106657 +static struct gimple_opt_pass randomize_layout_bad_cast = {
106658 + .pass = {
106659 +#endif
106660 + .type = GIMPLE_PASS,
106661 + .name = "randomize_layout_bad_cast",
106662 +#if BUILDING_GCC_VERSION >= 4008
106663 + .optinfo_flags = OPTGROUP_NONE,
106664 +#endif
106665 +#if BUILDING_GCC_VERSION >= 4009
106666 + .has_gate = false,
106667 + .has_execute = true,
106668 +#else
106669 + .gate = NULL,
106670 + .execute = find_bad_casts,
106671 + .sub = NULL,
106672 + .next = NULL,
106673 + .static_pass_number = 0,
106674 +#endif
106675 + .tv_id = TV_NONE,
106676 + .properties_required = PROP_cfg,
106677 + .properties_provided = 0,
106678 + .properties_destroyed = 0,
106679 + .todo_flags_start = 0,
106680 + .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
106681 +#if BUILDING_GCC_VERSION < 4009
106682 + }
106683 +#endif
106684 +};
106685 +
106686 +#if BUILDING_GCC_VERSION >= 4009
106687 +namespace {
106688 +class randomize_layout_bad_cast : public gimple_opt_pass {
106689 +public:
106690 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
106691 + unsigned int execute() { return find_bad_casts(); }
106692 +};
106693 +}
106694 +#endif
106695 +
106696 +static struct opt_pass *make_randomize_layout_bad_cast(void)
106697 +{
106698 +#if BUILDING_GCC_VERSION >= 4009
106699 + return new randomize_layout_bad_cast();
106700 +#else
106701 + return &randomize_layout_bad_cast.pass;
106702 +#endif
106703 +}
106704 +
106705 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106706 +{
106707 + int i;
106708 + const char * const plugin_name = plugin_info->base_name;
106709 + const int argc = plugin_info->argc;
106710 + const struct plugin_argument * const argv = plugin_info->argv;
106711 + bool enable = true;
106712 + int obtained_seed = 0;
106713 + struct register_pass_info randomize_layout_bad_cast_info;
106714 +
106715 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
106716 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
106717 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
106718 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
106719 +
106720 + if (!plugin_default_version_check(version, &gcc_version)) {
106721 + error(G_("incompatible gcc/plugin versions"));
106722 + return 1;
106723 + }
106724 +
106725 + if (strcmp(lang_hooks.name, "GNU C")) {
106726 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
106727 + enable = false;
106728 + }
106729 +
106730 + for (i = 0; i < argc; ++i) {
106731 + if (!strcmp(argv[i].key, "disable")) {
106732 + enable = false;
106733 + continue;
106734 + }
106735 + if (!strcmp(argv[i].key, "performance-mode")) {
106736 + performance_mode = 1;
106737 + continue;
106738 + }
106739 + if (!strcmp(argv[i].key, "seed")) {
106740 + if (!argv[i].value) {
106741 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
106742 + continue;
106743 + }
106744 + if (strlen(argv[i].value) != 64) {
106745 + error(G_("invalid value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
106746 + continue;
106747 + }
106748 + obtained_seed = sscanf(argv[i].value, "%016llx%016llx%016llx%016llx",
106749 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
106750 + continue;
106751 + }
106752 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
106753 + }
106754 +
106755 + if (obtained_seed != 4) {
106756 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
106757 + return 1;
106758 + }
106759 +
106760 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
106761 + if (enable) {
106762 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
106763 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
106764 + }
106765 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
106766 +
106767 + return 0;
106768 +}
106769 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
106770 new file mode 100644
106771 index 0000000..0c980be
106772 --- /dev/null
106773 +++ b/tools/gcc/size_overflow_hash.data
106774 @@ -0,0 +1,5697 @@
106775 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
106776 +ocfs2_get_refcount_tree_3 ocfs2_get_refcount_tree 0 3 NULL
106777 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
106778 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
106779 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
106780 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
106781 +padzero_55 padzero 1 55 &sel_read_policyvers_55
106782 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
106783 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
106784 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
106785 +load_msg_95 load_msg 2 95 NULL
106786 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
106787 +init_q_132 init_q 4 132 NULL
106788 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
106789 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
106790 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
106791 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
106792 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
106793 +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
106794 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
106795 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
106796 +br_port_info_size_268 br_port_info_size 0 268 NULL
106797 +generic_file_direct_write_291 generic_file_direct_write 0 291 NULL
106798 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
106799 +SYSC_connect_304 SYSC_connect 3 304 NULL
106800 +syslog_print_307 syslog_print 2 307 NULL
106801 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
106802 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
106803 +hw_device_state_409 hw_device_state 0 409 NULL
106804 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
106805 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
106806 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
106807 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
106808 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
106809 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
106810 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
106811 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
106812 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
106813 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
106814 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
106815 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
106816 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
106817 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
106818 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
106819 +ocfs2_refcounted_xattr_delete_need_584 ocfs2_refcounted_xattr_delete_need 0 584 NULL
106820 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
106821 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
106822 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
106823 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
106824 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
106825 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
106826 +clone_split_bio_633 clone_split_bio 6 633 NULL
106827 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
106828 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
106829 +unlink_queued_645 unlink_queued 4 645 NULL
106830 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
106831 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
106832 +persistent_ram_vmap_709 persistent_ram_vmap 1-2 709 NULL
106833 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
106834 +dvb_video_write_754 dvb_video_write 3 754 NULL
106835 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
106836 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
106837 +if_writecmd_815 if_writecmd 2 815 NULL
106838 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
106839 +error_state_read_859 error_state_read 6 859 NULL
106840 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
106841 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
106842 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
106843 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
106844 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
106845 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
106846 +memcmp_990 memcmp 0 990 NULL
106847 +readreg_1017 readreg 0-1 1017 NULL
106848 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
106849 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
106850 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
106851 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
106852 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
106853 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
106854 +llc_mac_hdr_init_1094 llc_mac_hdr_init 0 1094 NULL
106855 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
106856 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
106857 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
106858 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
106859 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
106860 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
106861 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
106862 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
106863 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
106864 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
106865 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
106866 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
106867 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
106868 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
106869 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
106870 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
106871 +ffs_1322 ffs 0 1322 NULL
106872 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
106873 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
106874 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
106875 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
106876 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
106877 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
106878 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
106879 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
106880 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
106881 +file_read_actor_1401 file_read_actor 4-0 1401 NULL
106882 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
106883 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
106884 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
106885 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
106886 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
106887 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
106888 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
106889 +fpregs_set_1497 fpregs_set 4 1497 NULL
106890 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
106891 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
106892 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
106893 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
106894 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
106895 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
106896 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
106897 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
106898 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
106899 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
106900 +rmap_add_1677 rmap_add 3 1677 NULL
106901 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
106902 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
106903 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
106904 +internal_create_group_1733 internal_create_group 0 1733 NULL
106905 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
106906 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
106907 +cosa_write_1774 cosa_write 3 1774 NULL
106908 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
106909 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
106910 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
106911 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
106912 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
106913 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
106914 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
106915 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
106916 +bdev_erase_1933 bdev_erase 3 1933 NULL
106917 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
106918 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
106919 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
106920 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
106921 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
106922 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
106923 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
106924 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
106925 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
106926 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
106927 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
106928 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
106929 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
106930 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
106931 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
106932 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
106933 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
106934 +audit_expand_2098 audit_expand 0 2098 NULL
106935 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
106936 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
106937 +enable_read_2117 enable_read 3 2117 NULL
106938 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
106939 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
106940 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
106941 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
106942 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
106943 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
106944 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
106945 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
106946 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
106947 +vhci_write_2224 vhci_write 3 2224 NULL
106948 +__ocfs2_journal_access_2241 __ocfs2_journal_access 0 2241 NULL
106949 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
106950 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
106951 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
106952 +do_update_counters_2259 do_update_counters 4 2259 NULL
106953 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
106954 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
106955 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
106956 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
106957 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
106958 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
106959 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
106960 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
106961 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
106962 +sysfs_add_file_mode_ns_2362 sysfs_add_file_mode_ns 0 2362 NULL
106963 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
106964 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
106965 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
106966 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
106967 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
106968 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
106969 +raid1_size_2419 raid1_size 0-2 2419 NULL
106970 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
106971 +wiphy_new_2482 wiphy_new 2 2482 NULL
106972 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
106973 +hfsplus_user_setxattr_2485 hfsplus_user_setxattr 4 2485 NULL
106974 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
106975 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
106976 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
106977 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
106978 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
106979 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
106980 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
106981 +slot_bytes_2609 slot_bytes 0 2609 NULL
106982 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
106983 +switch_status_2629 switch_status 5 2629 NULL
106984 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
106985 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
106986 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
106987 +oti6858_write_2692 oti6858_write 4 2692 NULL
106988 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
106989 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
106990 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
106991 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
106992 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
106993 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
106994 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
106995 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
106996 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
106997 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
106998 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
106999 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
107000 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
107001 +nla_padlen_2883 nla_padlen 1 2883 NULL
107002 +cmm_write_2896 cmm_write 3 2896 NULL
107003 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
107004 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
107005 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
107006 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
107007 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
107008 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
107009 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
107010 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
107011 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
107012 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
107013 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
107014 +depth_write_3021 depth_write 3 3021 NULL
107015 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
107016 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
107017 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
107018 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
107019 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
107020 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
107021 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
107022 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
107023 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
107024 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
107025 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
107026 +clone_bio_3100 clone_bio 6 3100 NULL nohasharray
107027 +ttusb2_msg_3100 ttusb2_msg 4 3100 &clone_bio_3100
107028 +rb_alloc_3102 rb_alloc 1 3102 NULL
107029 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
107030 +print_time_3132 print_time 0 3132 NULL
107031 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
107032 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
107033 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
107034 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
107035 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 NULL
107036 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
107037 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
107038 +alloc_context_3194 alloc_context 1 3194 NULL
107039 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
107040 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
107041 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
107042 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
107043 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
107044 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
107045 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
107046 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
107047 +key_key_read_3241 key_key_read 3 3241 NULL
107048 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
107049 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
107050 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
107051 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
107052 +ocfs2_extend_xattr_bucket_3328 ocfs2_extend_xattr_bucket 4 3328 NULL
107053 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
107054 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
107055 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
107056 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
107057 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
107058 +scnprintf_3360 scnprintf 0-2 3360 NULL
107059 +ReadByteAmd7930_3365 ReadByteAmd7930 0 3365 NULL
107060 +sr_read_3366 sr_read 3 3366 NULL
107061 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
107062 +send_stream_3397 send_stream 4 3397 NULL
107063 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
107064 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
107065 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
107066 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
107067 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
107068 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
107069 +s3fb_ddc_read_3451 s3fb_ddc_read 0 3451 NULL
107070 +softsynth_write_3455 softsynth_write 3 3455 NULL
107071 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL nohasharray
107072 +jffs2_acl_setxattr_3464 jffs2_acl_setxattr 4 3464 &snd_pcm_lib_readv_transfer_3464
107073 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
107074 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
107075 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
107076 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
107077 +SyS_readv_3539 SyS_readv 3 3539 NULL
107078 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
107079 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
107080 +evtchn_read_3569 evtchn_read 3 3569 NULL
107081 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
107082 +vc_resize_3585 vc_resize 3-2 3585 NULL
107083 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
107084 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
107085 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
107086 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
107087 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
107088 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
107089 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
107090 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
107091 +ci_ll_write_3740 ci_ll_write 4 3740 NULL nohasharray
107092 +ath6kl_mgmt_tx_3740 ath6kl_mgmt_tx 7 3740 &ci_ll_write_3740
107093 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
107094 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
107095 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
107096 +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
107097 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
107098 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
107099 +get_fd_set_3866 get_fd_set 1 3866 NULL
107100 +apei_res_sub_3873 apei_res_sub 0 3873 NULL
107101 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
107102 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
107103 +nvram_write_3894 nvram_write 3 3894 NULL
107104 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
107105 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
107106 +vcs_write_3910 vcs_write 3 3910 NULL
107107 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
107108 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
107109 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
107110 +ll_get_max_mdsize_3962 ll_get_max_mdsize 0 3962 NULL
107111 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
107112 +do_add_counters_3992 do_add_counters 3 3992 NULL
107113 +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
107114 +userspace_status_4004 userspace_status 4 4004 NULL
107115 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
107116 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
107117 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
107118 +blk_end_request_4024 blk_end_request 3 4024 NULL
107119 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
107120 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
107121 +read_file_queues_4078 read_file_queues 3 4078 NULL
107122 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
107123 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
107124 +tm6000_read_4151 tm6000_read 3 4151 NULL
107125 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
107126 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
107127 +get_alua_req_4166 get_alua_req 3 4166 NULL
107128 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
107129 +read_file_bool_4180 read_file_bool 3 4180 NULL
107130 +ocfs2_find_cpos_for_right_leaf_4194 ocfs2_find_cpos_for_right_leaf 0 4194 NULL
107131 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
107132 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
107133 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
107134 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
107135 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
107136 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
107137 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
107138 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 3-2-5 4303 NULL
107139 +count_strings_4315 count_strings 0 4315 NULL
107140 +__sysfs_add_one_4326 __sysfs_add_one 0 4326 NULL
107141 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
107142 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
107143 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
107144 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
107145 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
107146 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
107147 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
107148 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
107149 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
107150 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
107151 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
107152 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
107153 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
107154 +set_link_security_4502 set_link_security 4 4502 NULL
107155 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
107156 +tty_register_device_4544 tty_register_device 2 4544 NULL
107157 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
107158 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
107159 +bch_alloc_4593 bch_alloc 1 4593 NULL
107160 +ocfs2_refcount_lock_4595 ocfs2_refcount_lock 0 4595 NULL
107161 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
107162 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
107163 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
107164 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
107165 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
107166 +kone_receive_4690 kone_receive 4 4690 NULL
107167 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
107168 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
107169 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
107170 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
107171 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 NULL nohasharray
107172 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 &bitmap_startwrite_4736
107173 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
107174 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
107175 +create_subvol_4791 create_subvol 4 4791 NULL
107176 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
107177 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
107178 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
107179 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
107180 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
107181 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
107182 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
107183 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
107184 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
107185 +ocfs2_should_refresh_lock_res_4958 ocfs2_should_refresh_lock_res 0 4958 NULL
107186 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
107187 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
107188 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
107189 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
107190 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
107191 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
107192 +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
107193 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
107194 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
107195 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
107196 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
107197 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
107198 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
107199 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
107200 +sound_write_5102 sound_write 3 5102 NULL
107201 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
107202 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
107203 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
107204 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
107205 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
107206 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
107207 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
107208 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
107209 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
107210 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
107211 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
107212 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
107213 +cq_free_res_5355 cq_free_res 5 5355 NULL
107214 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
107215 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
107216 +__split_bvec_across_targets_5454 __split_bvec_across_targets 3 5454 NULL
107217 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
107218 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
107219 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
107220 +tty_write_5494 tty_write 3 5494 NULL
107221 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
107222 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
107223 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
107224 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
107225 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
107226 +le_readq_5557 le_readq 0 5557 NULL
107227 +inw_5558 inw 0 5558 NULL
107228 +bioset_create_5580 bioset_create 1 5580 NULL
107229 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
107230 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
107231 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
107232 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
107233 +get_arg_5694 get_arg 3 5694 NULL
107234 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
107235 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
107236 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
107237 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
107238 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
107239 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
107240 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
107241 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
107242 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
107243 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
107244 +setup_req_5848 setup_req 3-0 5848 NULL
107245 +ria_page_count_5849 ria_page_count 0 5849 NULL
107246 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
107247 +config_buf_5862 config_buf 0 5862 NULL
107248 +iwl_dbgfs_scan_ant_rxchain_write_5877 iwl_dbgfs_scan_ant_rxchain_write 3 5877 NULL
107249 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
107250 +port_show_regs_5904 port_show_regs 3 5904 NULL
107251 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
107252 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
107253 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
107254 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
107255 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
107256 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
107257 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
107258 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
107259 +SyS_semop_5980 SyS_semop 3 5980 NULL
107260 +alloc_msg_6072 alloc_msg 1 6072 NULL
107261 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
107262 +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
107263 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL
107264 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
107265 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
107266 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
107267 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
107268 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
107269 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
107270 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
107271 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
107272 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
107273 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
107274 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
107275 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
107276 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
107277 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
107278 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
107279 +serial_port_in_6291 serial_port_in 0 6291 NULL
107280 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
107281 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
107282 +SyS_mincore_6329 SyS_mincore 2-1 6329 &hfa384x_inw_6329
107283 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
107284 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
107285 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
107286 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
107287 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
107288 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
107289 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
107290 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
107291 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
107292 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
107293 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
107294 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
107295 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
107296 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
107297 +mei_read_6507 mei_read 3 6507 NULL
107298 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
107299 +wdm_read_6549 wdm_read 3 6549 NULL
107300 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
107301 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
107302 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
107303 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
107304 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
107305 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
107306 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
107307 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
107308 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
107309 +mpeg_read_6708 mpeg_read 3 6708 NULL
107310 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
107311 +video_proc_write_6724 video_proc_write 3 6724 NULL
107312 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
107313 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
107314 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
107315 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
107316 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
107317 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
107318 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
107319 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
107320 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
107321 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
107322 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
107323 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
107324 +dio_complete_6879 dio_complete 0-2-3 6879 NULL
107325 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
107326 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
107327 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
107328 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
107329 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
107330 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
107331 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
107332 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
107333 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
107334 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
107335 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
107336 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
107337 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
107338 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL nohasharray
107339 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 &rsa_extract_mpi_6973
107340 +request_key_async_6990 request_key_async 4 6990 NULL
107341 +tpl_write_6998 tpl_write 3 6998 NULL
107342 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
107343 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
107344 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
107345 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
107346 +wimax_msg_7030 wimax_msg 4 7030 NULL
107347 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
107348 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
107349 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
107350 +event_enable_read_7074 event_enable_read 3 7074 NULL
107351 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
107352 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
107353 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
107354 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
107355 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
107356 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
107357 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
107358 +f_midi_start_ep_7270 f_midi_start_ep 0 7270 NULL
107359 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
107360 +get_string_7302 get_string 0 7302 NULL
107361 +mgmt_control_7349 mgmt_control 3 7349 NULL
107362 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
107363 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
107364 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
107365 +hweight_long_7388 hweight_long 1-0 7388 NULL
107366 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
107367 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
107368 +readb_7401 readb 0 7401 NULL
107369 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
107370 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
107371 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
107372 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
107373 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
107374 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
107375 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
107376 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
107377 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
107378 +iwl_mvm_power_dbgfs_read_7502 iwl_mvm_power_dbgfs_read 0 7502 NULL
107379 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
107380 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
107381 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
107382 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
107383 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
107384 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
107385 +ocfs2_lock_create_7612 ocfs2_lock_create 0 7612 NULL
107386 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
107387 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
107388 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
107389 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
107390 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
107391 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
107392 +dev_write_7708 dev_write 3 7708 NULL
107393 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
107394 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
107395 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
107396 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
107397 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
107398 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
107399 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
107400 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
107401 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
107402 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
107403 +config_desc_7878 config_desc 0 7878 NULL
107404 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
107405 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
107406 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
107407 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
107408 +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
107409 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
107410 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
107411 +vcs_read_8017 vcs_read 3 8017 NULL
107412 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
107413 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
107414 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
107415 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
107416 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
107417 +venus_lookup_8121 venus_lookup 4 8121 NULL
107418 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
107419 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
107420 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
107421 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
107422 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
107423 +__ocfs2_lock_refcount_tree_8207 __ocfs2_lock_refcount_tree 0 8207 NULL
107424 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
107425 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
107426 +play_iframe_8219 play_iframe 3 8219 NULL
107427 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
107428 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
107429 +ceph_sync_write_8233 ceph_sync_write 4 8233 NULL
107430 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
107431 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
107432 +init_cdev_8274 init_cdev 1 8274 NULL
107433 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
107434 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
107435 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
107436 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
107437 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
107438 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
107439 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
107440 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
107441 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
107442 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
107443 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
107444 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
107445 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
107446 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
107447 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
107448 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
107449 +dev_config_8506 dev_config 3 8506 NULL
107450 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
107451 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
107452 +user_on_off_8552 user_on_off 2 8552 NULL
107453 +profile_remove_8556 profile_remove 3 8556 NULL
107454 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
107455 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
107456 +tower_write_8580 tower_write 3 8580 NULL
107457 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
107458 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
107459 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
107460 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
107461 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
107462 +generic_acl_set_8658 generic_acl_set 4 8658 NULL
107463 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
107464 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
107465 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
107466 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
107467 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
107468 +arcfb_write_8702 arcfb_write 3 8702 NULL
107469 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
107470 +init_header_8703 init_header 0 8703 &i_size_read_8703
107471 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
107472 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
107473 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
107474 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
107475 +__create_irqs_8733 __create_irqs 2 8733 NULL
107476 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
107477 +compound_order_8750 compound_order 0 8750 NULL
107478 +ocfs2_find_path_8754 ocfs2_find_path 0 8754 NULL
107479 +yurex_write_8761 yurex_write 3 8761 NULL
107480 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
107481 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
107482 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
107483 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
107484 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
107485 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
107486 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
107487 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
107488 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
107489 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
107490 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
107491 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
107492 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
107493 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
107494 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
107495 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
107496 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
107497 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
107498 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
107499 +write_file_ani_8918 write_file_ani 3 8918 NULL
107500 +layout_commit_8926 layout_commit 3 8926 NULL
107501 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
107502 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
107503 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
107504 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
107505 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
107506 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
107507 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
107508 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
107509 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
107510 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
107511 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
107512 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
107513 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
107514 +nla_put_9042 nla_put 3 9042 NULL
107515 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
107516 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
107517 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
107518 +create_queues_9088 create_queues 2-3 9088 NULL
107519 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
107520 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
107521 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
107522 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 &caif_stream_sendmsg_9110
107523 +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
107524 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
107525 +apei_resources_merge_9149 apei_resources_merge 0 9149 NULL
107526 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
107527 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
107528 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
107529 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
107530 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
107531 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
107532 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
107533 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
107534 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
107535 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
107536 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
107537 +flakey_status_9274 flakey_status 5 9274 NULL
107538 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
107539 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
107540 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
107541 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
107542 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
107543 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
107544 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
107545 +get_request_type_9393 get_request_type 0 9393 NULL nohasharray
107546 +mlx4_bitmap_init_9393 mlx4_bitmap_init 5-2 9393 &get_request_type_9393
107547 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
107548 +read_9397 read 3 9397 NULL
107549 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
107550 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
107551 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
107552 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
107553 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
107554 +ext3_xattr_set_acl_9467 ext3_xattr_set_acl 4 9467 NULL
107555 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL nohasharray
107556 +get_registers_9470 get_registers 4 9470 &agp_generic_alloc_user_9470
107557 +crypt_status_9492 crypt_status 5 9492 NULL
107558 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
107559 +lp_write_9511 lp_write 3 9511 NULL
107560 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
107561 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
107562 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
107563 +read_file_dma_9530 read_file_dma 3 9530 NULL
107564 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
107565 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
107566 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
107567 +fw_node_create_9559 fw_node_create 2 9559 NULL
107568 +kobj_map_9566 kobj_map 2-3 9566 NULL
107569 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
107570 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
107571 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
107572 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
107573 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
107574 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
107575 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
107576 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
107577 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
107578 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
107579 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
107580 +dns_query_9676 dns_query 3 9676 NULL
107581 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
107582 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
107583 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
107584 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
107585 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
107586 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
107587 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
107588 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
107589 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
107590 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
107591 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
107592 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 NULL
107593 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
107594 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
107595 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
107596 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
107597 +parse_uac2_sample_rate_range_9801 parse_uac2_sample_rate_range 0 9801 NULL
107598 +tpm_data_in_9802 tpm_data_in 0 9802 NULL
107599 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
107600 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
107601 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
107602 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
107603 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
107604 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
107605 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
107606 +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
107607 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 5-3 9895 NULL
107608 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
107609 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
107610 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
107611 +read_file_misc_9948 read_file_misc 3 9948 NULL
107612 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
107613 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
107614 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
107615 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
107616 +gameport_read_9983 gameport_read 0 9983 NULL
107617 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
107618 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
107619 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
107620 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
107621 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
107622 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
107623 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
107624 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
107625 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
107626 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
107627 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
107628 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
107629 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
107630 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
107631 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
107632 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
107633 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
107634 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
107635 +read_emulate_10310 read_emulate 2-4 10310 NULL
107636 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
107637 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
107638 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
107639 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
107640 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
107641 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
107642 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
107643 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
107644 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
107645 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
107646 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
107647 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
107648 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
107649 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
107650 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
107651 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
107652 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
107653 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
107654 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
107655 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
107656 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
107657 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
107658 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
107659 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
107660 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
107661 +otp_read_10594 otp_read 2-4-5 10594 NULL
107662 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
107663 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
107664 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
107665 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
107666 +parport_write_10669 parport_write 0 10669 NULL
107667 +edge_write_10692 edge_write 4 10692 NULL
107668 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
107669 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
107670 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
107671 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
107672 +spi_sync_10731 spi_sync 0 10731 NULL
107673 +apu_get_register_10737 apu_get_register 0 10737 NULL nohasharray
107674 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 &apu_get_register_10737
107675 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
107676 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
107677 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
107678 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
107679 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
107680 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
107681 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
107682 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
107683 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
107684 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
107685 +get_scq_10897 get_scq 2 10897 NULL
107686 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
107687 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
107688 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
107689 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
107690 +kobject_add_10919 kobject_add 0 10919 NULL
107691 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
107692 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
107693 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
107694 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
107695 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
107696 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
107697 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
107698 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
107699 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
107700 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
107701 +count_argc_11083 count_argc 0 11083 NULL
107702 +ocfs2_blocks_per_xattr_bucket_11099 ocfs2_blocks_per_xattr_bucket 0 11099 NULL
107703 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
107704 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
107705 +page_offset_11120 page_offset 0 11120 NULL
107706 +cea_db_payload_len_11124 cea_db_payload_len 0 11124 NULL nohasharray
107707 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 &cea_db_payload_len_11124
107708 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
107709 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 4-3 11172 NULL
107710 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
107711 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
107712 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
107713 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
107714 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
107715 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
107716 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
107717 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
107718 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
107719 +construct_key_11329 construct_key 3 11329 NULL nohasharray
107720 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
107721 +next_segment_11330 next_segment 0-2-1 11330 NULL
107722 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 2-1 11332 NULL
107723 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
107724 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
107725 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
107726 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
107727 +nft_value_dump_11381 nft_value_dump 3 11381 NULL
107728 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
107729 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
107730 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
107731 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
107732 +str_to_user_11411 str_to_user 2 11411 NULL
107733 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
107734 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
107735 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL nohasharray
107736 +import_sec_validate_get_11417 import_sec_validate_get 0 11417 &adis16480_show_firmware_revision_11417
107737 +trace_options_read_11419 trace_options_read 3 11419 NULL
107738 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
107739 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
107740 +bttv_read_11432 bttv_read 3 11432 NULL
107741 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
107742 +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
107743 +pci_set_power_state_11479 pci_set_power_state 0 11479 NULL nohasharray
107744 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 &pci_set_power_state_11479
107745 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
107746 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
107747 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
107748 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
107749 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
107750 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
107751 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
107752 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
107753 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
107754 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
107755 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
107756 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
107757 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
107758 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
107759 +nla_total_size_11658 nla_total_size 1-0 11658 NULL
107760 +slab_ksize_11664 slab_ksize 0 11664 NULL
107761 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
107762 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
107763 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
107764 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
107765 +split_11691 split 2 11691 NULL
107766 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
107767 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
107768 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
107769 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
107770 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
107771 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
107772 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
107773 +umc_device_register_11824 umc_device_register 0 11824 NULL
107774 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
107775 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
107776 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
107777 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
107778 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
107779 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
107780 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
107781 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
107782 +ti_write_11916 ti_write 4 11916 NULL
107783 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
107784 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
107785 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
107786 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
107787 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
107788 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
107789 +i40e_pci_sriov_configure_12011 i40e_pci_sriov_configure 2 12011 NULL
107790 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
107791 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
107792 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
107793 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
107794 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
107795 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
107796 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
107797 +set_powered_12129 set_powered 4 12129 NULL
107798 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
107799 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
107800 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
107801 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
107802 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
107803 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
107804 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
107805 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
107806 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
107807 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
107808 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
107809 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
107810 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
107811 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
107812 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
107813 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
107814 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
107815 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
107816 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
107817 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
107818 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
107819 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
107820 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
107821 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
107822 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
107823 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
107824 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 NULL nohasharray
107825 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391 nohasharray
107826 +write_file_dump_12391 write_file_dump 3 12391 &populate_dir_12391
107827 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
107828 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
107829 +ptlrpc_set_wait_12426 ptlrpc_set_wait 0 12426 NULL
107830 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
107831 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
107832 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
107833 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
107834 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
107835 +xfs_get_extsz_hint_12531 xfs_get_extsz_hint 0 12531 NULL
107836 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
107837 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
107838 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
107839 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
107840 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
107841 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
107842 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
107843 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
107844 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
107845 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
107846 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
107847 +lustre_pack_request_v2_12665 lustre_pack_request_v2 0 12665 NULL
107848 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
107849 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
107850 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
107851 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
107852 +ivtv_write_12721 ivtv_write 3 12721 NULL
107853 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
107854 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
107855 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
107856 +listxattr_12769 listxattr 3 12769 NULL
107857 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
107858 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
107859 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
107860 +readq_12825 readq 0 12825 NULL
107861 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
107862 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
107863 +spidev_sync_12842 spidev_sync 0 12842 NULL
107864 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
107865 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
107866 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
107867 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
107868 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
107869 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
107870 +bm_status_write_12964 bm_status_write 3 12964 NULL
107871 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
107872 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
107873 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
107874 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
107875 +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
107876 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
107877 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
107878 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
107879 +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
107880 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
107881 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
107882 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
107883 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
107884 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
107885 +blk_update_request_13146 blk_update_request 3 13146 NULL
107886 +ocfs2_quota_trans_credits_13150 ocfs2_quota_trans_credits 0 13150 NULL
107887 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
107888 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
107889 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
107890 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
107891 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
107892 +comedi_read_13199 comedi_read 3 13199 NULL
107893 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
107894 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
107895 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
107896 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
107897 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
107898 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
107899 +bio_integrity_trim_13259 bio_integrity_trim 3 13259 NULL
107900 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
107901 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
107902 +il4965_stats_flag_13281 il4965_stats_flag 3-0 13281 NULL
107903 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
107904 +sd_major_13294 sd_major 0-1 13294 NULL
107905 +module_param_sysfs_setup_13296 module_param_sysfs_setup 0 13296 NULL
107906 +__clone_and_map_data_bio_13334 __clone_and_map_data_bio 4-8 13334 NULL
107907 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
107908 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
107909 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
107910 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
107911 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
107912 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
107913 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
107914 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
107915 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
107916 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 8-9-7 13443 NULL
107917 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
107918 +data_read_13494 data_read 3 13494 NULL
107919 +ioat_chansts_32_13506 ioat_chansts_32 0 13506 NULL
107920 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
107921 +core_status_13515 core_status 4 13515 NULL
107922 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
107923 +bm_init_13529 bm_init 2 13529 NULL
107924 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
107925 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
107926 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
107927 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
107928 +cache_write_13589 cache_write 3 13589 NULL
107929 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
107930 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
107931 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
107932 +packet_snd_13634 packet_snd 3 13634 NULL
107933 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
107934 +cache_downcall_13666 cache_downcall 3 13666 NULL
107935 +ext3_xattr_list_entries_13682 ext3_xattr_list_entries 0 13682 NULL
107936 +nv94_aux_13689 nv94_aux 2-5 13689 NULL
107937 +usb_get_string_13693 usb_get_string 0 13693 NULL
107938 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
107939 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
107940 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
107941 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
107942 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
107943 +random_read_13815 random_read 3 13815 NULL
107944 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
107945 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
107946 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
107947 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
107948 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
107949 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
107950 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
107951 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
107952 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
107953 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
107954 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
107955 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
107956 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
107957 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
107958 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
107959 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
107960 +ocfs2_refresh_slot_info_13957 ocfs2_refresh_slot_info 0 13957 NULL
107961 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
107962 +qcam_read_13977 qcam_read 3 13977 NULL
107963 +dsp_read_13980 dsp_read 2 13980 NULL
107964 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
107965 +create_files_14003 create_files 0 14003 NULL
107966 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
107967 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
107968 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
107969 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
107970 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
107971 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
107972 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
107973 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
107974 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
107975 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
107976 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
107977 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
107978 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
107979 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
107980 +em_canid_change_14150 em_canid_change 3 14150 NULL
107981 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
107982 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
107983 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
107984 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
107985 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
107986 +alloc_async_14208 alloc_async 1 14208 NULL
107987 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
107988 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
107989 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
107990 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
107991 +rr_status_14293 rr_status 5 14293 NULL
107992 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
107993 +oo_objects_14319 oo_objects 0 14319 NULL
107994 +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
107995 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
107996 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
107997 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
107998 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
107999 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
108000 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
108001 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
108002 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
108003 +block_size_14443 block_size 0 14443 NULL
108004 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
108005 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
108006 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
108007 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
108008 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
108009 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
108010 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
108011 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
108012 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
108013 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 &ep0_write_14536
108014 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
108015 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
108016 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
108017 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
108018 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
108019 +dbJoin_14644 dbJoin 0 14644 NULL
108020 +profile_replace_14652 profile_replace 3 14652 NULL
108021 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
108022 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
108023 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
108024 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
108025 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
108026 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
108027 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
108028 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
108029 +cgroup_path_14713 cgroup_path 3 14713 NULL
108030 +vfd_write_14717 vfd_write 3 14717 NULL
108031 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
108032 +raid1_resize_14740 raid1_resize 2 14740 NULL
108033 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
108034 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
108035 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
108036 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
108037 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
108038 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
108039 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
108040 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
108041 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
108042 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
108043 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
108044 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
108045 +lcd_write_14857 lcd_write 3 14857 NULL
108046 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
108047 +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
108048 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
108049 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
108050 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
108051 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
108052 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
108053 +queue_cnt_14951 queue_cnt 0 14951 NULL
108054 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
108055 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
108056 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
108057 +setkey_14987 setkey 3 14987 NULL nohasharray
108058 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
108059 +xfs_dinode_size_14996 xfs_dinode_size 0 14996 NULL
108060 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
108061 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
108062 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
108063 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
108064 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
108065 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
108066 +ceph_calc_ceph_pg_15075 ceph_calc_ceph_pg 0 15075 NULL
108067 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
108068 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
108069 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
108070 +start_port_15124 start_port 0 15124 NULL
108071 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
108072 +iwl_dbgfs_sta_drain_write_15167 iwl_dbgfs_sta_drain_write 3 15167 NULL
108073 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
108074 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
108075 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
108076 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
108077 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
108078 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
108079 +simple_strtol_15273 simple_strtol 0 15273 NULL
108080 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
108081 +ocfs2_read_refcount_block_15305 ocfs2_read_refcount_block 0 15305 NULL
108082 +xlog_ticket_alloc_15335 xlog_ticket_alloc 2 15335 NULL
108083 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
108084 +ioread16_15342 ioread16 0 15342 NULL
108085 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
108086 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
108087 +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
108088 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
108089 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
108090 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
108091 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
108092 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
108093 +get_modalias_15406 get_modalias 2 15406 NULL
108094 +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
108095 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
108096 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
108097 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
108098 +memweight_15450 memweight 2 15450 NULL
108099 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
108100 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
108101 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
108102 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
108103 +persistent_status_15574 persistent_status 4 15574 NULL
108104 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
108105 +vme_user_write_15587 vme_user_write 3 15587 NULL
108106 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
108107 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
108108 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
108109 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &tomoyo_scan_bprm_15642 nohasharray
108110 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &sk_memory_allocated_add_15642
108111 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
108112 +fs_path_add_15648 fs_path_add 3 15648 NULL
108113 +xsd_read_15653 xsd_read 3 15653 NULL
108114 +unix_bind_15668 unix_bind 3 15668 NULL
108115 +dm_read_15674 dm_read 3 15674 NULL nohasharray
108116 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
108117 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
108118 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
108119 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
108120 +nameseq_list_15817 nameseq_list 3-0 15817 NULL nohasharray
108121 +gnttab_expand_15817 gnttab_expand 1 15817 &nameseq_list_15817
108122 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
108123 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
108124 +table_size_15851 table_size 0-1-2 15851 NULL
108125 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
108126 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
108127 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
108128 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
108129 +native_read_msr_15905 native_read_msr 0 15905 NULL
108130 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
108131 +power_read_15939 power_read 3 15939 NULL
108132 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
108133 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
108134 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
108135 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
108136 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
108137 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
108138 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
108139 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
108140 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
108141 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
108142 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
108143 +fsm_init_16134 fsm_init 2 16134 NULL
108144 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
108145 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
108146 +mapping_level_16188 mapping_level 2-0 16188 NULL
108147 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
108148 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
108149 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
108150 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
108151 +create_table_16213 create_table 2 16213 NULL
108152 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
108153 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
108154 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
108155 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
108156 +btrfs_dev_extent_chunk_offset_16247 btrfs_dev_extent_chunk_offset 0 16247 NULL nohasharray
108157 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 &btrfs_dev_extent_chunk_offset_16247
108158 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
108159 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
108160 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
108161 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
108162 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
108163 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
108164 +account_16283 account 0-4-2 16283 NULL nohasharray
108165 +mirror_status_16283 mirror_status 5 16283 &account_16283
108166 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
108167 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
108168 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
108169 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
108170 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
108171 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
108172 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
108173 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
108174 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
108175 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
108176 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
108177 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
108178 +cmdline_store_16442 cmdline_store 4 16442 NULL
108179 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
108180 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
108181 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
108182 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
108183 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
108184 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
108185 +raid10_resize_16537 raid10_resize 2 16537 NULL
108186 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
108187 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
108188 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
108189 +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
108190 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
108191 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
108192 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
108193 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
108194 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
108195 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
108196 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
108197 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
108198 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
108199 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
108200 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
108201 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
108202 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
108203 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
108204 +st_write_16874 st_write 3 16874 NULL
108205 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
108206 +transport_init_session_tags_16878 transport_init_session_tags 1-2 16878 NULL
108207 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 NULL nohasharray
108208 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 &snd_gf1_mem_proc_dump_16926
108209 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
108210 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
108211 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
108212 +ocfs2_read_quota_phys_block_16990 ocfs2_read_quota_phys_block 0 16990 NULL
108213 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
108214 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
108215 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
108216 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
108217 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
108218 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
108219 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
108220 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
108221 +entry_length_17093 entry_length 0 17093 NULL
108222 +ocfs2_get_refcount_cpos_end_17113 ocfs2_get_refcount_cpos_end 0 17113 NULL
108223 +write_mem_17114 write_mem 3 17114 NULL
108224 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
108225 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
108226 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
108227 +sep_read_17161 sep_read 3 17161 NULL
108228 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
108229 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
108230 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
108231 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
108232 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189 nohasharray
108233 +ocfs2_flock_handle_signal_17189 ocfs2_flock_handle_signal 0 17189 &iwl_dbgfs_txfifo_flush_write_17189
108234 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
108235 +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
108236 +sync_request_17208 sync_request 2 17208 NULL
108237 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
108238 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
108239 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
108240 +alloc_ep_17269 alloc_ep 1 17269 NULL
108241 +pg_read_17276 pg_read 3 17276 NULL
108242 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
108243 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
108244 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
108245 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
108246 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 0 17298 NULL
108247 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
108248 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
108249 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
108250 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
108251 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
108252 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
108253 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
108254 +compat_sys_ppoll_17430 compat_sys_ppoll 2 17430 NULL
108255 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
108256 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
108257 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
108258 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
108259 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
108260 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
108261 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
108262 +qp_free_res_17541 qp_free_res 5 17541 NULL
108263 +__copy_to_user_17551 __copy_to_user 3-0 17551 NULL
108264 +copy_from_user_17559 copy_from_user 0-3 17559 NULL
108265 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
108266 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
108267 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
108268 +osst_execute_17607 osst_execute 7-6 17607 NULL
108269 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
108270 +dma_map_page_17628 dma_map_page 0 17628 NULL
108271 +ocfs2_rotate_subtree_left_17634 ocfs2_rotate_subtree_left 5 17634 NULL
108272 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
108273 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
108274 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
108275 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
108276 +venus_rename_17707 venus_rename 4-5 17707 NULL nohasharray
108277 +__einj_error_trigger_17707 __einj_error_trigger 0 17707 &venus_rename_17707
108278 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
108279 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
108280 +dgap_do_fep_load_17765 dgap_do_fep_load 3 17765 NULL
108281 +brcmf_sdio_chip_verifynvram_17776 brcmf_sdio_chip_verifynvram 4 17776 NULL
108282 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
108283 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
108284 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
108285 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
108286 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
108287 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
108288 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
108289 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
108290 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
108291 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
108292 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
108293 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
108294 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
108295 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
108296 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
108297 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
108298 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
108299 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
108300 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
108301 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
108302 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
108303 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
108304 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
108305 +cpufreq_add_dev_symlink_18028 cpufreq_add_dev_symlink 0 18028 NULL
108306 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
108307 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
108308 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
108309 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
108310 +fpregs_get_18066 fpregs_get 4 18066 NULL
108311 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
108312 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
108313 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
108314 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
108315 +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
108316 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
108317 +svc_getnl_18120 svc_getnl 0 18120 NULL
108318 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
108319 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
108320 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
108321 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
108322 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
108323 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
108324 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
108325 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
108326 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
108327 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
108328 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
108329 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
108330 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
108331 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
108332 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
108333 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
108334 +um_idi_write_18293 um_idi_write 3 18293 NULL
108335 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
108336 +vga_r_18310 vga_r 0 18310 NULL
108337 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
108338 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
108339 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
108340 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
108341 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
108342 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
108343 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
108344 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
108345 +ep_io_18367 ep_io 0 18367 NULL
108346 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
108347 +ci_role_write_18388 ci_role_write 3 18388 NULL
108348 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
108349 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
108350 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
108351 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
108352 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
108353 +flash_dev_cache_miss_18454 flash_dev_cache_miss 4 18454 NULL
108354 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
108355 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
108356 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
108357 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
108358 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
108359 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
108360 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
108361 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
108362 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
108363 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
108364 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
108365 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
108366 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
108367 +debug_output_18575 debug_output 3 18575 NULL
108368 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
108369 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
108370 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
108371 +nvc0_ram_create__18624 nvc0_ram_create_ 4 18624 NULL nohasharray
108372 +audio_get_endpoint_req_18624 audio_get_endpoint_req 0 18624 &nvc0_ram_create__18624
108373 +from_buffer_18625 from_buffer 3 18625 NULL
108374 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
108375 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
108376 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
108377 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
108378 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
108379 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
108380 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
108381 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
108382 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
108383 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
108384 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
108385 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
108386 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
108387 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
108388 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
108389 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
108390 +prealloc_18800 prealloc 0 18800 NULL
108391 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
108392 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
108393 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
108394 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
108395 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
108396 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
108397 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
108398 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
108399 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
108400 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
108401 +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
108402 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
108403 +huge_page_size_19008 huge_page_size 0 19008 NULL
108404 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
108405 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
108406 +revalidate_19043 revalidate 2 19043 NULL
108407 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
108408 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
108409 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
108410 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
108411 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
108412 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
108413 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
108414 +ATOMIC_SUB_RETURN_19115 ATOMIC_SUB_RETURN 2 19115 NULL
108415 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
108416 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
108417 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
108418 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
108419 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
108420 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
108421 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
108422 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
108423 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
108424 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
108425 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
108426 +ucma_query_19260 ucma_query 4 19260 NULL
108427 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
108428 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
108429 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
108430 +qc_capture_19298 qc_capture 3 19298 NULL
108431 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
108432 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
108433 +debug_read_19322 debug_read 3 19322 NULL
108434 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
108435 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
108436 +closure_sub_19359 closure_sub 2 19359 NULL
108437 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
108438 +read_zero_19366 read_zero 3 19366 NULL
108439 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
108440 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
108441 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
108442 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
108443 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
108444 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
108445 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
108446 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
108447 +sky2_read16_19475 sky2_read16 0 19475 NULL
108448 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
108449 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
108450 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
108451 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
108452 +apei_exec_pre_map_gars_19529 apei_exec_pre_map_gars 0 19529 NULL nohasharray
108453 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 &apei_exec_pre_map_gars_19529
108454 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
108455 +howmany_64_19548 howmany_64 2 19548 NULL
108456 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
108457 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
108458 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
108459 +nfsd_read_19568 nfsd_read 5 19568 NULL
108460 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
108461 +bm_status_read_19583 bm_status_read 3 19583 NULL
108462 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
108463 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
108464 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
108465 +iwl_dbgfs_pm_params_write_19660 iwl_dbgfs_pm_params_write 3 19660 NULL
108466 +read_reg_19723 read_reg 0 19723 NULL
108467 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
108468 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
108469 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
108470 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
108471 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
108472 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
108473 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
108474 +readhscx_19769 readhscx 0 19769 NULL
108475 +__set_print_fmt_19776 __set_print_fmt 0 19776 NULL
108476 +iwl_dbgfs_disable_power_off_write_19823 iwl_dbgfs_disable_power_off_write 3 19823 NULL
108477 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
108478 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
108479 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
108480 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
108481 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
108482 +__nla_put_19857 __nla_put 3 19857 NULL
108483 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
108484 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
108485 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
108486 +mangle_name_19923 mangle_name 0 19923 NULL
108487 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
108488 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
108489 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
108490 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
108491 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
108492 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
108493 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
108494 +lustre_pack_request_19992 lustre_pack_request 0 19992 NULL
108495 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
108496 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL
108497 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
108498 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
108499 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
108500 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 4 20067 NULL
108501 +target_message_20072 target_message 2 20072 NULL
108502 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
108503 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
108504 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
108505 +team_options_register_20091 team_options_register 3 20091 NULL
108506 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
108507 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
108508 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
108509 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
108510 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
108511 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
108512 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
108513 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
108514 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
108515 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
108516 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
108517 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
108518 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
108519 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
108520 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
108521 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
108522 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
108523 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
108524 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
108525 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL nohasharray
108526 +read_7220_creg32_20394 read_7220_creg32 0 20394 &snd_nm256_readl_20394
108527 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL nohasharray
108528 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 &__kfifo_from_user_20399
108529 +nfs3_setxattr_20458 nfs3_setxattr 4 20458 NULL
108530 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
108531 +read_buf_20469 read_buf 2 20469 NULL
108532 +bio_trim_20472 bio_trim 2 20472 NULL
108533 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
108534 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
108535 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
108536 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
108537 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
108538 +venus_create_20555 venus_create 4 20555 NULL
108539 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
108540 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
108541 +ocfs2_cluster_lock_20588 ocfs2_cluster_lock 0 20588 NULL
108542 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
108543 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
108544 +lirc_write_20604 lirc_write 3 20604 NULL
108545 +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
108546 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
108547 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
108548 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
108549 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
108550 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
108551 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
108552 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
108553 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
108554 +cpumask_size_20683 cpumask_size 0 20683 NULL
108555 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
108556 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
108557 +__maestro_read_20700 __maestro_read 0 20700 NULL
108558 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
108559 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
108560 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
108561 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
108562 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
108563 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
108564 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
108565 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
108566 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
108567 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
108568 +strndup_user_20819 strndup_user 2 20819 NULL
108569 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
108570 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
108571 +uvc_alloc_entity_20836 uvc_alloc_entity 3-4 20836 NULL
108572 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
108573 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
108574 +get_name_20855 get_name 4 20855 NULL
108575 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
108576 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
108577 +srq_free_res_20868 srq_free_res 5 20868 NULL
108578 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
108579 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
108580 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
108581 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
108582 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
108583 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
108584 +htable_bits_20933 htable_bits 0 20933 NULL
108585 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
108586 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
108587 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
108588 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
108589 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
108590 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
108591 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
108592 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
108593 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
108594 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
108595 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
108596 +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
108597 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
108598 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
108599 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
108600 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
108601 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
108602 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
108603 +ocfs2_extend_meta_needed_21104 ocfs2_extend_meta_needed 0 21104 NULL
108604 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
108605 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
108606 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
108607 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
108608 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
108609 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
108610 +input_ff_create_21240 input_ff_create 2 21240 NULL
108611 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
108612 +use_debug_keys_read_21251 use_debug_keys_read 3 21251 NULL
108613 +fru_length_21257 fru_length 0 21257 NULL
108614 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
108615 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
108616 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
108617 +add_res_range_21310 add_res_range 4 21310 NULL
108618 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
108619 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
108620 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
108621 +ocfs2_find_subtree_root_21351 ocfs2_find_subtree_root 0 21351 NULL
108622 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
108623 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
108624 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
108625 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
108626 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
108627 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
108628 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
108629 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
108630 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
108631 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
108632 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
108633 +ReadISAR_21453 ReadISAR 0 21453 NULL
108634 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
108635 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
108636 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
108637 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
108638 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
108639 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
108640 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
108641 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
108642 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
108643 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
108644 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
108645 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
108646 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
108647 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
108648 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
108649 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
108650 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
108651 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
108652 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
108653 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
108654 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
108655 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
108656 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
108657 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
108658 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
108659 +__ocfs2_cluster_lock_21812 __ocfs2_cluster_lock 0 21812 NULL
108660 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
108661 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
108662 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
108663 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
108664 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
108665 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
108666 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
108667 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
108668 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
108669 +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
108670 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
108671 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
108672 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
108673 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
108674 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
108675 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
108676 +mem_rw_22085 mem_rw 3 22085 NULL
108677 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
108678 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
108679 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
108680 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
108681 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
108682 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
108683 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
108684 +mem_write_22232 mem_write 3 22232 NULL
108685 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
108686 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
108687 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
108688 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
108689 +add_res_tree_22263 add_res_tree 7 22263 NULL
108690 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
108691 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
108692 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
108693 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
108694 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
108695 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
108696 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
108697 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
108698 +atomic_read_22342 atomic_read 0 22342 NULL
108699 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
108700 +memcg_size_22360 memcg_size 0 22360 NULL
108701 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
108702 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
108703 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
108704 +zoran_write_22404 zoran_write 3 22404 NULL
108705 +ATOMIC_ADD_RETURN_22413 ATOMIC_ADD_RETURN 2 22413 NULL
108706 +queue_reply_22416 queue_reply 3 22416 NULL
108707 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
108708 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
108709 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
108710 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
108711 +source_sink_start_ep_22472 source_sink_start_ep 0 22472 NULL
108712 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
108713 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
108714 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
108715 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
108716 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
108717 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
108718 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
108719 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
108720 +snapshot_read_22601 snapshot_read 3 22601 NULL
108721 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
108722 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
108723 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
108724 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
108725 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
108726 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
108727 +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
108728 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
108729 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
108730 +reg_umr_22686 reg_umr 5 22686 NULL
108731 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
108732 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
108733 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
108734 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
108735 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
108736 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
108737 +print_frame_22769 print_frame 0 22769 NULL
108738 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
108739 +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
108740 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
108741 +clone_bio_integrity_22842 clone_bio_integrity 4 22842 NULL
108742 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
108743 +create_attr_set_22861 create_attr_set 1 22861 NULL
108744 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
108745 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
108746 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
108747 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
108748 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 NULL
108749 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
108750 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
108751 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
108752 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
108753 +vme_get_size_22964 vme_get_size 0 22964 NULL
108754 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
108755 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
108756 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
108757 +brcmf_sdio_chip_exit_download_23001 brcmf_sdio_chip_exit_download 4 23001 NULL
108758 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
108759 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
108760 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 0-6-7 23029 NULL
108761 +st_status_23032 st_status 5 23032 NULL
108762 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
108763 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
108764 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
108765 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
108766 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
108767 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
108768 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
108769 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
108770 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
108771 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
108772 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
108773 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
108774 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
108775 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
108776 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 NULL
108777 +__clear_user_23118 __clear_user 0-2 23118 NULL
108778 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
108779 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
108780 +read_file_ani_23161 read_file_ani 3 23161 NULL
108781 +usblp_write_23178 usblp_write 3 23178 NULL
108782 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
108783 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
108784 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
108785 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
108786 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
108787 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
108788 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
108789 +__gfn_to_rmap_23240 __gfn_to_rmap 2-1 23240 NULL
108790 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
108791 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
108792 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
108793 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
108794 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
108795 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
108796 +page_readlink_23346 page_readlink 3 23346 NULL
108797 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
108798 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
108799 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
108800 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
108801 +vga_mm_r_23419 vga_mm_r 0 23419 NULL
108802 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
108803 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
108804 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
108805 +linear_conf_23485 linear_conf 2 23485 NULL
108806 +event_filter_read_23494 event_filter_read 3 23494 NULL
108807 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
108808 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
108809 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
108810 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
108811 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
108812 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
108813 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
108814 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
108815 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
108816 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
108817 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
108818 +ocfs2_journal_access_23616 ocfs2_journal_access 0 23616 NULL
108819 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
108820 +sInW_23663 sInW 0 23663 NULL
108821 +SyS_connect_23669 SyS_connect 3 23669 NULL
108822 +cx18_read_23699 cx18_read 3 23699 NULL
108823 +at_get_23708 at_get 0 23708 NULL
108824 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
108825 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
108826 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
108827 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
108828 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
108829 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
108830 +map_write_23795 map_write 3 23795 NULL
108831 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
108832 +ocfs2_replace_cow_23803 ocfs2_replace_cow 0 23803 NULL
108833 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
108834 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
108835 +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 3-4 23829 NULL
108836 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
108837 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
108838 +p54_init_common_23850 p54_init_common 1 23850 NULL
108839 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
108840 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
108841 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
108842 +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 NULL
108843 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
108844 +usbg_prepare_w_request_23895 usbg_prepare_w_request 0 23895 NULL
108845 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
108846 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
108847 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
108848 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 NULL nohasharray
108849 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 &mpihelp_mul_karatsuba_case_23918
108850 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
108851 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
108852 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
108853 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
108854 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
108855 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
108856 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
108857 +give_pages_24021 give_pages 3 24021 NULL
108858 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
108859 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
108860 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
108861 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
108862 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
108863 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
108864 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
108865 +lov_brw_24122 lov_brw 4 24122 NULL
108866 +mpu401_read_24126 mpu401_read 3-0 24126 NULL
108867 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
108868 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
108869 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
108870 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
108871 +adu_read_24177 adu_read 3 24177 NULL
108872 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
108873 +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
108874 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
108875 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
108876 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
108877 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
108878 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
108879 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
108880 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
108881 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
108882 +thin_status_24278 thin_status 5 24278 NULL
108883 +msg_size_24288 msg_size 0 24288 NULL
108884 +gserial_connect_24302 gserial_connect 0 24302 NULL
108885 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
108886 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
108887 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
108888 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
108889 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
108890 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
108891 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
108892 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
108893 +igetword_24373 igetword 0 24373 NULL
108894 +max_io_len_24384 max_io_len 0-1 24384 NULL
108895 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
108896 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
108897 +getxattr_24398 getxattr 4 24398 NULL nohasharray
108898 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
108899 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
108900 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
108901 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
108902 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
108903 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
108904 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
108905 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
108906 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
108907 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
108908 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
108909 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
108910 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
108911 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
108912 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
108913 +pd_video_read_24510 pd_video_read 3 24510 NULL
108914 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
108915 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
108916 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
108917 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
108918 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
108919 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
108920 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
108921 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
108922 +SyS_poll_24620 SyS_poll 2 24620 NULL
108923 +context_alloc_24645 context_alloc 3 24645 NULL
108924 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
108925 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
108926 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
108927 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
108928 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
108929 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
108930 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
108931 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
108932 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
108933 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
108934 +cache_read_24790 cache_read 3 24790 NULL
108935 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
108936 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
108937 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
108938 +net2272_read_24825 net2272_read 0 24825 NULL
108939 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
108940 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
108941 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
108942 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
108943 +queues_read_24877 queues_read 3 24877 NULL
108944 +__vxge_hw_vp_initialize_24885 __vxge_hw_vp_initialize 2 24885 NULL
108945 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
108946 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL nohasharray
108947 +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 &v4l2_ctrl_new_24927
108948 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
108949 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
108950 +ll_layout_fetch_24961 ll_layout_fetch 0 24961 NULL
108951 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
108952 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
108953 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
108954 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
108955 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
108956 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
108957 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
108958 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
108959 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
108960 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
108961 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
108962 +iwl_dbgfs_tx_flush_write_25091 iwl_dbgfs_tx_flush_write 3 25091 NULL
108963 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
108964 +blkg_path_25099 blkg_path 3 25099 NULL
108965 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
108966 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
108967 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
108968 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
108969 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
108970 +stripe_status_25259 stripe_status 5 25259 NULL
108971 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
108972 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
108973 +vfs_writev_25278 vfs_writev 3 25278 NULL
108974 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
108975 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
108976 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
108977 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
108978 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
108979 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
108980 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
108981 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
108982 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
108983 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
108984 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
108985 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
108986 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
108987 +sb_permission_25523 sb_permission 0 25523 NULL
108988 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
108989 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
108990 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
108991 +ht_print_chan_25556 ht_print_chan 3-4-0 25556 NULL
108992 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
108993 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
108994 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
108995 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
108996 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
108997 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
108998 +__direct_map_25647 __direct_map 6-5 25647 NULL
108999 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
109000 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
109001 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
109002 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
109003 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
109004 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
109005 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
109006 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
109007 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
109008 +sg_read_25799 sg_read 3 25799 NULL
109009 +system_enable_read_25815 system_enable_read 3 25815 NULL
109010 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
109011 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
109012 +parport_read_25855 parport_read 0 25855 NULL
109013 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
109014 +key_attr_size_25865 key_attr_size 0 25865 NULL
109015 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
109016 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
109017 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
109018 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
109019 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
109020 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
109021 +rcname_read_25919 rcname_read 3 25919 NULL
109022 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
109023 +key_flags_read_25931 key_flags_read 3 25931 NULL
109024 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
109025 +flush_25957 flush 2 25957 NULL
109026 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
109027 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
109028 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
109029 +xfs_xattr_acl_set_26028 xfs_xattr_acl_set 4 26028 NULL
109030 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
109031 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
109032 +tun_do_read_26047 tun_do_read 5 26047 NULL
109033 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
109034 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
109035 +read_sb_page_26119 read_sb_page 5 26119 NULL
109036 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
109037 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
109038 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
109039 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
109040 +disk_devt_26180 disk_devt 0 26180 NULL
109041 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
109042 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
109043 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
109044 +mce_write_26201 mce_write 3 26201 NULL
109045 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
109046 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
109047 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
109048 +bio_split_26235 bio_split 2 26235 NULL
109049 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
109050 +apei_resources_request_26279 apei_resources_request 0 26279 NULL
109051 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
109052 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL nohasharray
109053 +pax_get_random_long_26309 pax_get_random_long 0 26309 &snd_pcm_plug_client_channels_buf_26309
109054 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
109055 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
109056 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
109057 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
109058 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
109059 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
109060 +ntty_write_26404 ntty_write 3 26404 NULL
109061 +firmware_store_26408 firmware_store 4 26408 NULL
109062 +pagemap_read_26441 pagemap_read 3 26441 NULL
109063 +tower_read_26461 tower_read 3 26461 NULL nohasharray
109064 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
109065 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
109066 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
109067 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
109068 +read_vmcore_26501 read_vmcore 3 26501 NULL
109069 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
109070 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
109071 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
109072 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
109073 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
109074 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
109075 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
109076 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
109077 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
109078 +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
109079 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
109080 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
109081 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
109082 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
109083 +bos_desc_26752 bos_desc 0 26752 NULL
109084 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
109085 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
109086 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
109087 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
109088 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
109089 +smk_write_load_26829 smk_write_load 3 26829 NULL
109090 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
109091 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
109092 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
109093 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
109094 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
109095 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
109096 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
109097 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
109098 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
109099 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
109100 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
109101 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
109102 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
109103 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
109104 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
109105 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
109106 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
109107 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
109108 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
109109 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
109110 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
109111 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
109112 +get_kernel_page_27133 get_kernel_page 0 27133 NULL
109113 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
109114 +pms_capture_27142 pms_capture 4 27142 NULL
109115 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
109116 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
109117 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
109118 +__sg_alloc_table_27198 __sg_alloc_table 0 27198 NULL
109119 +write_kmem_27225 write_kmem 3 27225 NULL
109120 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
109121 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
109122 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
109123 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
109124 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
109125 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
109126 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
109127 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
109128 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
109129 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
109130 +seq_read_27411 seq_read 3 27411 NULL
109131 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
109132 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
109133 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 0-3-4 27422 NULL
109134 +cypress_write_27423 cypress_write 4 27423 NULL
109135 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
109136 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
109137 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
109138 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
109139 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
109140 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
109141 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
109142 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
109143 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
109144 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
109145 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
109146 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
109147 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
109148 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
109149 +read_flush_procfs_27642 read_flush_procfs 3 27642 &nl80211_send_connect_result_27642 nohasharray
109150 +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &read_flush_procfs_27642
109151 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
109152 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
109153 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
109154 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
109155 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
109156 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
109157 +evm_write_key_27715 evm_write_key 3 27715 NULL
109158 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
109159 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
109160 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
109161 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
109162 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
109163 +SyS_readv_27804 SyS_readv 3 27804 NULL
109164 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
109165 +fwtty_buffer_rx_27821 fwtty_buffer_rx 3 27821 NULL
109166 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
109167 +init_header_complete_27833 init_header_complete 0 27833 NULL
109168 +read_profile_27859 read_profile 3 27859 NULL
109169 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
109170 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
109171 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
109172 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
109173 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
109174 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
109175 +device_register_27972 device_register 0 27972 NULL nohasharray
109176 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 &device_register_27972
109177 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
109178 +f2fs_bio_alloc_27983 f2fs_bio_alloc 2 27983 NULL
109179 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
109180 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
109181 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
109182 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
109183 +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
109184 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
109185 +pool_status_28055 pool_status 5 28055 NULL
109186 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
109187 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
109188 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
109189 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
109190 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
109191 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
109192 +video_read_28148 video_read 3 28148 NULL
109193 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
109194 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
109195 +vread_28173 vread 0-3 28173 NULL
109196 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
109197 +counter_free_res_28187 counter_free_res 5 28187 NULL
109198 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
109199 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
109200 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
109201 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
109202 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
109203 +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
109204 +usemap_size_28281 usemap_size 0 28281 NULL
109205 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
109206 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
109207 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
109208 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
109209 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
109210 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
109211 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
109212 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
109213 +snapshot_write_28351 snapshot_write 3 28351 NULL
109214 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
109215 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
109216 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
109217 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
109218 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
109219 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
109220 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
109221 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
109222 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
109223 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
109224 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
109225 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
109226 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
109227 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
109228 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
109229 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &mptctl_getiocinfo_28545 nohasharray
109230 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545
109231 +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
109232 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
109233 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
109234 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
109235 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
109236 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
109237 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
109238 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
109239 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
109240 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
109241 +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
109242 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
109243 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
109244 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
109245 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
109246 +spi_execute_28736 spi_execute 5 28736 NULL
109247 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
109248 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
109249 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
109250 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
109251 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
109252 +sel_write_member_28800 sel_write_member 3 28800 NULL
109253 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
109254 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
109255 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
109256 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
109257 +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
109258 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
109259 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
109260 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
109261 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
109262 +push_rx_28939 push_rx 3 28939 NULL
109263 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
109264 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
109265 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
109266 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
109267 +bin_uuid_28999 bin_uuid 3 28999 NULL
109268 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
109269 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
109270 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
109271 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
109272 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
109273 +roundup_64_29066 roundup_64 2-0-1 29066 NULL
109274 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
109275 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
109276 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
109277 +i915_error_object_create_sized_29091 i915_error_object_create_sized 3 29091 NULL
109278 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
109279 +snprintf_29125 snprintf 0 29125 NULL
109280 +iov_shorten_29130 iov_shorten 0 29130 NULL
109281 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
109282 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
109283 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
109284 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
109285 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
109286 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
109287 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
109288 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
109289 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
109290 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
109291 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
109292 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
109293 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
109294 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
109295 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
109296 +tun_put_user_29337 tun_put_user 5 29337 NULL
109297 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
109298 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
109299 +mwifiex_cfg80211_mgmt_tx_29387 mwifiex_cfg80211_mgmt_tx 7 29387 NULL
109300 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
109301 +mempool_create_29437 mempool_create 1 29437 NULL
109302 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
109303 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
109304 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
109305 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
109306 +do_register_entry_29478 do_register_entry 4 29478 NULL
109307 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
109308 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
109309 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
109310 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
109311 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
109312 +ftrace_write_29551 ftrace_write 3 29551 NULL
109313 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
109314 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
109315 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
109316 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
109317 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
109318 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
109319 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
109320 +slots_per_page_29601 slots_per_page 0 29601 NULL
109321 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
109322 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
109323 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
109324 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
109325 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
109326 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
109327 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
109328 +probes_write_29711 probes_write 3 29711 NULL
109329 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
109330 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
109331 +std_nic_write_29752 std_nic_write 3 29752 NULL
109332 +dbAlloc_29794 dbAlloc 0 29794 NULL
109333 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
109334 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
109335 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
109336 +count_partial_29850 count_partial 0 29850 NULL
109337 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
109338 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
109339 +scsi_end_request_29876 scsi_end_request 3 29876 NULL
109340 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
109341 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
109342 +write_file_queue_29922 write_file_queue 3 29922 NULL
109343 +ext4_xattr_set_acl_29930 ext4_xattr_set_acl 4 29930 NULL
109344 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
109345 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
109346 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
109347 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
109348 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
109349 +drp_wmove_30043 drp_wmove 4 30043 NULL
109350 +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
109351 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
109352 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
109353 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
109354 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
109355 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
109356 +recv_stream_30138 recv_stream 4 30138 NULL
109357 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
109358 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
109359 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
109360 +expand_inode_data_30169 expand_inode_data 2-3 30169 NULL
109361 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
109362 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
109363 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
109364 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
109365 +SyS_semop_30227 SyS_semop 3 30227 NULL
109366 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
109367 +ocfs2_calc_bg_discontig_credits_30230 ocfs2_calc_bg_discontig_credits 0 30230 NULL
109368 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
109369 +hfsplus_trusted_setxattr_30270 hfsplus_trusted_setxattr 4 30270 NULL
109370 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
109371 +compat_readv_30273 compat_readv 3 30273 NULL
109372 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
109373 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
109374 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
109375 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
109376 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
109377 +i8254_read_30330 i8254_read 0 30330 NULL
109378 +resource_from_user_30341 resource_from_user 3 30341 NULL
109379 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
109380 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
109381 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
109382 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
109383 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
109384 +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
109385 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
109386 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
109387 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
109388 +enable_write_30456 enable_write 3 30456 NULL
109389 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
109390 +urandom_read_30462 urandom_read 3 30462 NULL
109391 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
109392 +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
109393 +adu_write_30487 adu_write 3 30487 NULL
109394 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
109395 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
109396 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
109397 +set_config_30526 set_config 0 30526 NULL nohasharray
109398 +debug_debug2_read_30526 debug_debug2_read 3 30526 &set_config_30526
109399 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
109400 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
109401 +set_le_30581 set_le 4 30581 NULL
109402 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
109403 +i2c_hid_get_report_length_30598 i2c_hid_get_report_length 0 30598 NULL
109404 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL nohasharray
109405 +cpufreq_get_global_kobject_30610 cpufreq_get_global_kobject 0 30610 &sgl_map_user_pages_30610
109406 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
109407 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
109408 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
109409 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
109410 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
109411 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
109412 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
109413 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
109414 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
109415 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
109416 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
109417 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
109418 +snapshot_status_30744 snapshot_status 5 30744 NULL
109419 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
109420 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
109421 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
109422 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
109423 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
109424 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
109425 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
109426 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
109427 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
109428 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
109429 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
109430 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
109431 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
109432 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
109433 +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
109434 +stride_pg_count_31053 stride_pg_count 0-2-1-4-3-5 31053 NULL
109435 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
109436 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
109437 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
109438 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
109439 +depth_read_31112 depth_read 3 31112 NULL
109440 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
109441 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
109442 +size_inside_page_31141 size_inside_page 0 31141 NULL
109443 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
109444 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
109445 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
109446 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
109447 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
109448 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
109449 +__read_reg_31216 __read_reg 0 31216 NULL
109450 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
109451 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
109452 +cyy_readb_31240 cyy_readb 0 31240 NULL
109453 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
109454 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
109455 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
109456 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
109457 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
109458 +command_file_write_31318 command_file_write 3 31318 NULL
109459 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
109460 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
109461 +outlen_write_31358 outlen_write 3 31358 NULL
109462 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
109463 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
109464 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
109465 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
109466 +inb_31388 inb 0 31388 NULL
109467 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
109468 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
109469 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
109470 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
109471 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
109472 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
109473 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
109474 +alg_setkey_31485 alg_setkey 3 31485 NULL
109475 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
109476 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
109477 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
109478 +hidraw_write_31536 hidraw_write 3 31536 NULL
109479 +usbvision_read_31555 usbvision_read 3 31555 NULL
109480 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
109481 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
109482 +osst_write_31581 osst_write 3 31581 NULL
109483 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
109484 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
109485 +mtd_get_user_prot_info_31616 mtd_get_user_prot_info 0 31616 NULL
109486 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
109487 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
109488 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
109489 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
109490 +__lgread_31668 __lgread 4 31668 NULL
109491 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
109492 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
109493 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
109494 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 NULL nohasharray
109495 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 &utf16s_to_utf8s_31735
109496 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
109497 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
109498 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
109499 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
109500 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
109501 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
109502 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
109503 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
109504 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
109505 +data_write_31805 data_write 3 31805 NULL
109506 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
109507 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
109508 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
109509 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
109510 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
109511 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
109512 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
109513 +xattr_permission_31907 xattr_permission 0 31907 NULL
109514 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
109515 +new_dir_31919 new_dir 3 31919 NULL
109516 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
109517 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
109518 +read_mem_31942 read_mem 3 31942 NULL nohasharray
109519 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
109520 +vb2_write_31948 vb2_write 3 31948 NULL
109521 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
109522 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
109523 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
109524 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
109525 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
109526 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
109527 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
109528 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
109529 +calc_hmac_32010 calc_hmac 3 32010 NULL
109530 +aead_len_32021 aead_len 0 32021 NULL
109531 +posix_acl_set_32037 posix_acl_set 4 32037 NULL
109532 +stk_read_32038 stk_read 3 32038 NULL
109533 +ocfs2_update_edge_lengths_32046 ocfs2_update_edge_lengths 3 32046 NULL
109534 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
109535 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
109536 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
109537 +bio_alloc_32095 bio_alloc 2 32095 NULL
109538 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
109539 +disk_status_32120 disk_status 4 32120 NULL
109540 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
109541 +venus_link_32165 venus_link 5 32165 NULL
109542 +do_writepages_32173 do_writepages 0 32173 NULL
109543 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
109544 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
109545 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
109546 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
109547 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
109548 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
109549 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
109550 +SyS_select_32319 SyS_select 1 32319 NULL
109551 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
109552 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
109553 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
109554 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
109555 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
109556 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 NULL nohasharray
109557 +sel_read_initcon_32362 sel_read_initcon 3 32362 &ReadHDLCPCI_32362
109558 +ocfs2_cancel_convert_32392 ocfs2_cancel_convert 0 32392 NULL
109559 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
109560 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
109561 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
109562 +cache_status_32462 cache_status 5 32462 NULL
109563 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
109564 +dgap_usertoboard_32490 dgap_usertoboard 4 32490 NULL
109565 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
109566 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
109567 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
109568 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
109569 +disconnect_32521 disconnect 4 32521 NULL
109570 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
109571 +ocfs2_refresh_qinfo_32524 ocfs2_refresh_qinfo 0 32524 NULL nohasharray
109572 +audio_get_intf_req_32524 audio_get_intf_req 0 32524 &ocfs2_refresh_qinfo_32524
109573 +ilo_read_32531 ilo_read 3 32531 NULL
109574 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
109575 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
109576 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
109577 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
109578 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
109579 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
109580 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
109581 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
109582 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
109583 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
109584 +kvmalloc_32646 kvmalloc 1 32646 NULL
109585 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
109586 +generic_readlink_32654 generic_readlink 3 32654 NULL
109587 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
109588 +apei_res_add_32674 apei_res_add 0 32674 NULL
109589 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
109590 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
109591 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
109592 +i40e_pci_sriov_enable_32742 i40e_pci_sriov_enable 2 32742 NULL
109593 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
109594 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
109595 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
109596 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
109597 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
109598 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
109599 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
109600 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
109601 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 6-4 32884 NULL
109602 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
109603 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
109604 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
109605 +xfs_log_reserve_32959 xfs_log_reserve 2 32959 NULL
109606 +ocfs2_check_dir_trailer_32968 ocfs2_check_dir_trailer 0 32968 NULL
109607 +compat_filldir_32999 compat_filldir 3 32999 NULL
109608 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
109609 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
109610 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
109611 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
109612 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
109613 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
109614 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
109615 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
109616 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
109617 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
109618 +alloc_tio_33077 alloc_tio 3 33077 NULL
109619 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
109620 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
109621 +__len_within_target_33132 __len_within_target 0 33132 NULL
109622 +SyS_poll_33152 SyS_poll 2 33152 NULL
109623 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
109624 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
109625 +pp_read_33210 pp_read 3 33210 NULL
109626 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
109627 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
109628 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
109629 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
109630 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
109631 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
109632 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
109633 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
109634 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
109635 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
109636 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
109637 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
109638 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
109639 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
109640 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
109641 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
109642 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
109643 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
109644 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
109645 +message_stats_list_33440 message_stats_list 5 33440 NULL
109646 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
109647 +create_entry_33479 create_entry 2 33479 NULL
109648 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL nohasharray
109649 +elf_map_33487 elf_map 0-2 33487 &ip_setsockopt_33487
109650 +res_counter_read_33499 res_counter_read 4 33499 NULL
109651 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
109652 +fb_read_33506 fb_read 3 33506 NULL
109653 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
109654 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
109655 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
109656 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
109657 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
109658 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
109659 +count_subheaders_33591 count_subheaders 0 33591 NULL
109660 +scsi_execute_33596 scsi_execute 5 33596 NULL
109661 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
109662 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
109663 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
109664 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
109665 +stride_page_count_33641 stride_page_count 2 33641 NULL
109666 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
109667 +inw_p_33668 inw_p 0 33668 NULL
109668 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
109669 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
109670 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
109671 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
109672 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
109673 +ext4_wb_update_i_disksize_33717 ext4_wb_update_i_disksize 2 33717 NULL
109674 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
109675 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
109676 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
109677 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
109678 +hashtab_create_33769 hashtab_create 3 33769 NULL
109679 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
109680 +filter_write_33819 filter_write 3 33819 NULL
109681 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
109682 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
109683 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
109684 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
109685 +get_user_pages_33908 get_user_pages 0 33908 NULL
109686 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
109687 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
109688 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
109689 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
109690 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
109691 +hfsplus_osx_setxattr_33952 hfsplus_osx_setxattr 4 33952 NULL
109692 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
109693 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
109694 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
109695 +ppp_write_34034 ppp_write 3 34034 NULL
109696 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
109697 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
109698 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
109699 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
109700 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
109701 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
109702 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
109703 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
109704 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
109705 +ocfs2_xattr_list_entry_34165 ocfs2_xattr_list_entry 0 34165 NULL
109706 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
109707 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
109708 +sysfs_bin_read_34228 sysfs_bin_read 3 34228 NULL
109709 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
109710 +ocfs2_dlm_lock_34265 ocfs2_dlm_lock 0 34265 NULL
109711 +device_private_init_34279 device_private_init 0 34279 NULL
109712 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
109713 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
109714 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
109715 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
109716 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
109717 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
109718 +ea_read_34378 ea_read 0 34378 NULL
109719 +fuse_send_read_34379 fuse_send_read 4 34379 NULL
109720 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
109721 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
109722 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
109723 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
109724 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
109725 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
109726 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
109727 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
109728 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
109729 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
109730 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
109731 +ocfs2_mv_xattr_buckets_34484 ocfs2_mv_xattr_buckets 6 34484 NULL
109732 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
109733 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
109734 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
109735 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
109736 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
109737 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
109738 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
109739 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
109740 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
109741 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
109742 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
109743 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
109744 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
109745 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
109746 +brcmf_cfg80211_mgmt_tx_34608 brcmf_cfg80211_mgmt_tx 7 34608 NULL
109747 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
109748 +apei_get_nvs_resources_34616 apei_get_nvs_resources 0 34616 NULL
109749 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
109750 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
109751 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
109752 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
109753 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
109754 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
109755 +port_print_34704 port_print 3 34704 NULL
109756 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
109757 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
109758 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
109759 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
109760 +bootmode_store_34762 bootmode_store 4 34762 NULL
109761 +device_add_34766 device_add 0 34766 NULL
109762 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
109763 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
109764 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
109765 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
109766 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
109767 +file_page_index_34820 file_page_index 0-2 34820 NULL
109768 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
109769 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
109770 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
109771 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
109772 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
109773 +msg_print_text_34889 msg_print_text 0 34889 NULL
109774 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
109775 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
109776 +__inode_permission_34925 __inode_permission 0 34925 NULL nohasharray
109777 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 &__inode_permission_34925
109778 +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
109779 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
109780 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
109781 +i2c_transfer_34958 i2c_transfer 0 34958 NULL
109782 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
109783 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
109784 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
109785 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
109786 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
109787 +brcmf_sdio_chip_writenvram_35042 brcmf_sdio_chip_writenvram 4 35042 NULL
109788 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
109789 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
109790 +capi_write_35104 capi_write 3 35104 NULL nohasharray
109791 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
109792 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
109793 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
109794 +message_stats_print_35158 message_stats_print 6 35158 NULL
109795 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
109796 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
109797 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
109798 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 NULL nohasharray
109799 +striped_read_35218 striped_read 0-2 35218 &security_key_getsecurity_35218
109800 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
109801 +set_fd_set_35249 set_fd_set 1 35249 NULL
109802 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
109803 +jbd2_journal_get_write_access_35263 jbd2_journal_get_write_access 0 35263 NULL
109804 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
109805 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
109806 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
109807 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
109808 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
109809 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
109810 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
109811 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
109812 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
109813 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
109814 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
109815 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
109816 +read_kmem_35372 read_kmem 3 35372 NULL
109817 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
109818 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
109819 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
109820 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
109821 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
109822 +async_setkey_35521 async_setkey 3 35521 NULL
109823 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
109824 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
109825 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
109826 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
109827 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
109828 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
109829 +sysfs_create_subdir_35567 sysfs_create_subdir 0 35567 NULL
109830 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
109831 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
109832 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
109833 +kernel_readv_35617 kernel_readv 3 35617 NULL
109834 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
109835 +pci_request_regions_35635 pci_request_regions 0 35635 NULL
109836 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
109837 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
109838 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
109839 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
109840 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
109841 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
109842 +md_super_write_35703 md_super_write 4 35703 NULL
109843 +ocfs2_extent_recs_per_gd_35710 ocfs2_extent_recs_per_gd 0 35710 NULL
109844 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
109845 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
109846 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
109847 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
109848 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
109849 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
109850 +fls64_35862 fls64 0 35862 NULL
109851 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
109852 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
109853 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
109854 +SyS_set_mempolicy_35909 SyS_set_mempolicy 3 35909 NULL
109855 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
109856 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
109857 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
109858 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
109859 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
109860 +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
109861 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL nohasharray
109862 +generic_ocp_read_35974 generic_ocp_read 3 35974 &ceph_buffer_new_35974
109863 +acl_alloc_35979 acl_alloc 1 35979 NULL
109864 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
109865 +generic_file_aio_read_35987 generic_file_aio_read 0 35987 NULL
109866 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
109867 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
109868 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
109869 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
109870 +account_shadowed_36048 account_shadowed 2 36048 NULL
109871 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
109872 +write_emulate_36065 write_emulate 2-4 36065 NULL
109873 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
109874 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
109875 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
109876 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
109877 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
109878 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
109879 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
109880 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
109881 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
109882 +twl_set_36154 twl_set 2 36154 NULL
109883 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
109884 +btrfs_file_extent_inline_len_36158 btrfs_file_extent_inline_len 0 36158 NULL
109885 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
109886 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
109887 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
109888 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
109889 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
109890 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
109891 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
109892 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
109893 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
109894 +scrub_stripe_36248 scrub_stripe 5-4 36248 NULL
109895 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
109896 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL nohasharray
109897 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 &usb_buffer_alloc_36276
109898 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
109899 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
109900 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
109901 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
109902 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
109903 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
109904 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
109905 +lc_create_36332 lc_create 4 36332 NULL
109906 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
109907 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
109908 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
109909 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
109910 +to_sector_36361 to_sector 0-1 36361 NULL
109911 +tunables_read_36385 tunables_read 3 36385 NULL
109912 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
109913 +sierra_write_36402 sierra_write 4 36402 NULL
109914 +iwl_dbgfs_d3_sram_write_36403 iwl_dbgfs_d3_sram_write 3 36403 NULL
109915 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
109916 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
109917 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
109918 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
109919 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
109920 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
109921 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
109922 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
109923 +cmd_loop_36491 cmd_loop 0 36491 NULL
109924 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
109925 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
109926 +get_param_l_36518 get_param_l 0 36518 NULL
109927 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
109928 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
109929 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
109930 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL nohasharray
109931 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
109932 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
109933 +__erst_read_36579 __erst_read 0 36579 NULL
109934 +put_cmsg_36589 put_cmsg 4 36589 NULL
109935 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
109936 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
109937 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
109938 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
109939 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
109940 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
109941 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
109942 +xillybus_read_36678 xillybus_read 3 36678 NULL
109943 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
109944 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
109945 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
109946 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
109947 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
109948 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 2-3-4-5 36796 NULL
109949 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
109950 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
109951 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
109952 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
109953 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
109954 +cm_write_36858 cm_write 3 36858 NULL
109955 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
109956 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
109957 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
109958 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
109959 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
109960 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
109961 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
109962 +audio_set_endpoint_req_36918 audio_set_endpoint_req 0 36918 NULL
109963 +crypto_blkcipher_ivsize_36944 crypto_blkcipher_ivsize 0 36944 NULL
109964 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
109965 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
109966 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
109967 +setxattr_37006 setxattr 4 37006 NULL
109968 +ocfs2_dlm_unlock_37037 ocfs2_dlm_unlock 0 37037 NULL
109969 +command_file_read_37038 command_file_read 3 37038 NULL
109970 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
109971 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL nohasharray
109972 +qp_broker_create_37053 qp_broker_create 6-5 37053 &ieee80211_if_read_drop_unencrypted_37053
109973 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
109974 +parse_command_37079 parse_command 2 37079 NULL
109975 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
109976 +tun_get_user_37094 tun_get_user 5 37094 NULL
109977 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
109978 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
109979 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
109980 +msg_word_37164 msg_word 0 37164 NULL
109981 +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
109982 +can_set_xattr_37182 can_set_xattr 4 37182 NULL
109983 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
109984 +sysfs_add_file_37200 sysfs_add_file 0 37200 NULL
109985 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
109986 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
109987 +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 0-4 37212 &crypto_shash_descsize_37212
109988 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
109989 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
109990 +__do_replace_37227 __do_replace 5 37227 NULL
109991 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
109992 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
109993 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
109994 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
109995 +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
109996 +ocfs2_calc_extend_credits_37310 ocfs2_calc_extend_credits 0 37310 NULL
109997 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
109998 +send_msg_37323 send_msg 4 37323 NULL
109999 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
110000 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
110001 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
110002 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
110003 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
110004 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
110005 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
110006 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
110007 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 7-9-0 37433 NULL
110008 +fru_alloc_37442 fru_alloc 1 37442 NULL
110009 +tcp_established_options_37450 tcp_established_options 0 37450 NULL nohasharray
110010 +tipc_send2port_37450 tipc_send2port 4 37450 &tcp_established_options_37450
110011 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
110012 +get_est_timing_37484 get_est_timing 0 37484 NULL
110013 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
110014 +__hfsplus_setxattr_37499 __hfsplus_setxattr 4 37499 NULL
110015 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
110016 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
110017 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
110018 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
110019 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
110020 +hdr_size_37536 hdr_size 0 37536 NULL
110021 +extent_map_end_37550 extent_map_end 0 37550 NULL
110022 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
110023 +ioat_chansts_37558 ioat_chansts 0 37558 NULL
110024 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
110025 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
110026 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
110027 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
110028 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
110029 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
110030 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
110031 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
110032 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
110033 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
110034 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
110035 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
110036 +page_chain_free_37697 page_chain_free 0 37697 NULL
110037 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
110038 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
110039 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
110040 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
110041 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
110042 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
110043 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
110044 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
110045 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
110046 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
110047 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
110048 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
110049 +jbd2_journal_get_undo_access_37837 jbd2_journal_get_undo_access 0 37837 NULL
110050 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
110051 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
110052 +set_registers_37883 set_registers 4 37883 NULL
110053 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
110054 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL nohasharray
110055 +_rtw_malloc_37928 _rtw_malloc 1 37928 &pkt_alloc_packet_data_37928
110056 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
110057 +write_file_bool_37957 write_file_bool 3 37957 NULL
110058 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
110059 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
110060 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
110061 +vfs_readv_38011 vfs_readv 3 38011 NULL
110062 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
110063 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
110064 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
110065 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
110066 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
110067 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
110068 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
110069 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
110070 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL nohasharray
110071 +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 &xfs_buf_readahead_map_38081
110072 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
110073 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
110074 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
110075 +ep0_read_38095 ep0_read 3 38095 NULL
110076 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 NULL nohasharray
110077 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 &sk_wmem_schedule_38096
110078 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
110079 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
110080 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
110081 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 0-4-3 38153 NULL
110082 +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
110083 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
110084 +cdev_add_38176 cdev_add 2-3 38176 NULL
110085 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
110086 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
110087 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
110088 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
110089 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
110090 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
110091 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
110092 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
110093 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
110094 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
110095 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
110096 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
110097 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
110098 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
110099 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
110100 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
110101 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
110102 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
110103 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
110104 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
110105 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
110106 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
110107 +dev_names_read_38509 dev_names_read 3 38509 NULL
110108 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
110109 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
110110 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
110111 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
110112 +kuc_len_38557 kuc_len 0-1 38557 NULL
110113 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
110114 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
110115 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
110116 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
110117 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
110118 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
110119 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
110120 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
110121 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
110122 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
110123 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
110124 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
110125 +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
110126 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
110127 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
110128 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
110129 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
110130 +udf_readpages_38761 udf_readpages 4 38761 NULL
110131 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
110132 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
110133 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
110134 +slab_order_38794 slab_order 0 38794 NULL
110135 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
110136 +err_decode_38804 err_decode 2 38804 NULL
110137 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
110138 +direct_entry_38836 direct_entry 3 38836 NULL
110139 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
110140 +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
110141 +interfaces_38859 interfaces 2 38859 NULL
110142 +pci_msix_table_size_38867 pci_msix_table_size 0 38867 NULL
110143 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
110144 +f2fs_xattr_set_acl_38895 f2fs_xattr_set_acl 4 38895 NULL
110145 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
110146 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
110147 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
110148 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
110149 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
110150 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
110151 +get_nodes_39012 get_nodes 3 39012 NULL
110152 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
110153 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
110154 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
110155 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
110156 +ReadHFC_39104 ReadHFC 0 39104 NULL
110157 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
110158 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
110159 +ea_foreach_39133 ea_foreach 0 39133 NULL
110160 +generic_permission_39150 generic_permission 0 39150 NULL
110161 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
110162 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
110163 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
110164 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
110165 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
110166 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
110167 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
110168 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
110169 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
110170 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
110171 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
110172 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
110173 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
110174 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
110175 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
110176 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
110177 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
110178 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
110179 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
110180 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
110181 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
110182 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
110183 +__send_to_port_39386 __send_to_port 3 39386 NULL
110184 +user_power_read_39414 user_power_read 3 39414 NULL
110185 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
110186 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
110187 +apei_resources_add_39470 apei_resources_add 0 39470 NULL
110188 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
110189 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
110190 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
110191 +int_proc_write_39542 int_proc_write 3 39542 NULL
110192 +mdc_unpack_capa_39553 mdc_unpack_capa 0 39553 NULL
110193 +pp_write_39554 pp_write 3 39554 NULL
110194 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
110195 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
110196 +ext_depth_39607 ext_depth 0 39607 NULL
110197 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
110198 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
110199 +sdio_readb_39618 sdio_readb 0 39618 NULL
110200 +set_dev_class_39645 set_dev_class 4 39645 NULL
110201 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
110202 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
110203 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
110204 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
110205 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
110206 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
110207 +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
110208 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
110209 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
110210 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
110211 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
110212 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
110213 +pkt_add_39897 pkt_add 3 39897 NULL
110214 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
110215 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
110216 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
110217 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
110218 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
110219 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
110220 +__spi_async_39932 __spi_async 0 39932 NULL
110221 +__get_order_39935 __get_order 0 39935 NULL
110222 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
110223 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
110224 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
110225 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
110226 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
110227 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
110228 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
110229 +server_name2svname_39998 server_name2svname 4 39998 NULL
110230 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
110231 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
110232 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
110233 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
110234 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
110235 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
110236 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
110237 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
110238 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
110239 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
110240 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
110241 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
110242 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
110243 +pt_write_40159 pt_write 3 40159 NULL
110244 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
110245 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
110246 +allocate_probes_40204 allocate_probes 1 40204 NULL
110247 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
110248 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
110249 +osst_read_40237 osst_read 3 40237 NULL
110250 +lpage_info_slot_40243 lpage_info_slot 3-1 40243 NULL
110251 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
110252 +ptlrpc_queue_wait_40252 ptlrpc_queue_wait 0 40252 NULL
110253 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
110254 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
110255 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
110256 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
110257 +SyS_bind_40303 SyS_bind 3 40303 NULL
110258 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
110259 +mmio_read_40348 mmio_read 4 40348 NULL
110260 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
110261 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
110262 +get_chars_40373 get_chars 3 40373 NULL
110263 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
110264 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
110265 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
110266 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
110267 +SyS_writev_40467 SyS_writev 3 40467 NULL
110268 +SyS_select_40473 SyS_select 1 40473 NULL
110269 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
110270 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
110271 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
110272 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
110273 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
110274 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
110275 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
110276 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
110277 +b1_get_byte_40597 b1_get_byte 0 40597 NULL
110278 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
110279 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
110280 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
110281 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
110282 +fops_read_40672 fops_read 3 40672 NULL
110283 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
110284 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
110285 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
110286 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
110287 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
110288 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
110289 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
110290 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
110291 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
110292 +card_send_command_40757 card_send_command 3 40757 NULL
110293 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
110294 +pg_write_40766 pg_write 3 40766 NULL
110295 +show_list_40775 show_list 3-0 40775 NULL
110296 +kfifo_out_copy_r_40784 kfifo_out_copy_r 3-0 40784 NULL
110297 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
110298 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
110299 +add_action_40811 add_action 4 40811 NULL
110300 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
110301 +SyS_mbind_40828 SyS_mbind 5 40828 NULL
110302 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
110303 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
110304 +read_file_queue_40895 read_file_queue 3 40895 NULL
110305 +waiters_read_40902 waiters_read 3 40902 NULL
110306 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
110307 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
110308 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
110309 +snd_vx_create_40948 snd_vx_create 4 40948 NULL nohasharray
110310 +sg_alloc_table_40948 sg_alloc_table 0 40948 &snd_vx_create_40948
110311 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
110312 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
110313 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
110314 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
110315 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
110316 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
110317 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
110318 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
110319 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
110320 +calculate_order_41061 calculate_order 0 41061 NULL
110321 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
110322 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
110323 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
110324 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
110325 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
110326 +dma_attach_41094 dma_attach 5-6 41094 NULL
110327 +provide_user_output_41105 provide_user_output 3 41105 NULL
110328 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
110329 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
110330 +ocfs2_extend_trans_41116 ocfs2_extend_trans 2 41116 NULL
110331 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
110332 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
110333 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
110334 +dgap_driver_kzmalloc_41189 dgap_driver_kzmalloc 1 41189 NULL
110335 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
110336 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
110337 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
110338 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
110339 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
110340 +erst_read_41260 erst_read 0 41260 NULL
110341 +alloc_context_41283 alloc_context 1 41283 NULL
110342 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
110343 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
110344 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
110345 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
110346 +kmp_init_41373 kmp_init 2 41373 NULL
110347 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
110348 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
110349 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
110350 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
110351 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
110352 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
110353 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
110354 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
110355 +se_io_cb_41461 se_io_cb 3 41461 NULL
110356 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
110357 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
110358 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
110359 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
110360 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
110361 +SyS_get_mempolicy_41495 SyS_get_mempolicy 3 41495 NULL
110362 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
110363 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
110364 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
110365 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
110366 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
110367 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
110368 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
110369 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
110370 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
110371 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
110372 +vga_io_r_41609 vga_io_r 0 41609 NULL
110373 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
110374 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
110375 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
110376 +a2mp_send_41615 a2mp_send 4 41615 NULL
110377 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
110378 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
110379 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
110380 +get_std_timing_41654 get_std_timing 0 41654 NULL
110381 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
110382 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
110383 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
110384 +apei_exec_for_each_entry_41717 apei_exec_for_each_entry 0 41717 NULL
110385 +fillonedir_41746 fillonedir 3 41746 NULL
110386 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
110387 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
110388 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
110389 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
110390 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
110391 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
110392 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
110393 +pci_map_single_41869 pci_map_single 0 41869 NULL
110394 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
110395 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
110396 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
110397 +nfsd_getxattr_41934 nfsd_getxattr 0 41934 NULL
110398 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
110399 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
110400 +read_gssp_41947 read_gssp 3 41947 NULL
110401 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
110402 +portnames_read_41958 portnames_read 3 41958 NULL
110403 +dst_mtu_41969 dst_mtu 0 41969 NULL
110404 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
110405 +pool_allocate_42012 pool_allocate 3 42012 NULL
110406 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
110407 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
110408 +create_dir_42025 create_dir 0 42025 NULL
110409 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
110410 +__btrfs_drop_extents_42032 __btrfs_drop_extents 5 42032 NULL
110411 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
110412 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
110413 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
110414 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
110415 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
110416 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
110417 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
110418 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
110419 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
110420 +obd_get_info_42156 obd_get_info 0 42156 NULL
110421 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
110422 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
110423 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
110424 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
110425 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
110426 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
110427 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
110428 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
110429 +find_last_bit_42260 find_last_bit 0 42260 NULL
110430 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
110431 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
110432 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
110433 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
110434 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
110435 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
110436 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
110437 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
110438 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
110439 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
110440 +tipc_send_42374 tipc_send 3 42374 NULL
110441 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
110442 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
110443 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
110444 +krng_get_random_42420 krng_get_random 3 42420 NULL
110445 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
110446 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
110447 +alloc_request_42448 alloc_request 0 42448 NULL
110448 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
110449 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
110450 +kuc_free_42455 kuc_free 2 42455 NULL
110451 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
110452 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
110453 +bypass_write_42498 bypass_write 3 42498 NULL
110454 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
110455 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
110456 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
110457 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
110458 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
110459 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
110460 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
110461 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
110462 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
110463 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
110464 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
110465 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
110466 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
110467 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
110468 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
110469 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
110470 +vb2_read_42703 vb2_read 3 42703 NULL
110471 +read_status_42722 read_status 0 42722 NULL
110472 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
110473 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
110474 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
110475 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
110476 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
110477 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
110478 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
110479 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
110480 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
110481 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
110482 +ptlrpc_request_bufs_pack_42793 ptlrpc_request_bufs_pack 0 42793 NULL
110483 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
110484 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
110485 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
110486 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
110487 +set_arg_42824 set_arg 3 42824 NULL
110488 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
110489 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
110490 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
110491 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
110492 +hd_end_request_42904 hd_end_request 2 42904 NULL
110493 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
110494 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL nohasharray
110495 +mdc_unpack_acl_42941 mdc_unpack_acl 0 42941 &sctp_getsockopt_maxburst_42941
110496 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
110497 +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
110498 +read_file_node_stat_42964 read_file_node_stat 3 42964 NULL
110499 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
110500 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
110501 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
110502 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
110503 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
110504 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
110505 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
110506 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
110507 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
110508 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
110509 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
110510 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
110511 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
110512 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
110513 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
110514 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
110515 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
110516 +uio_write_43202 uio_write 3 43202 NULL
110517 +iso_callback_43208 iso_callback 3 43208 NULL
110518 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
110519 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
110520 +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
110521 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
110522 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
110523 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
110524 +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
110525 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 NULL nohasharray
110526 +evtchn_write_43278 evtchn_write 3 43278 &parport_pc_ecp_write_block_pio_43278
110527 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
110528 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
110529 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
110530 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
110531 +xenfb_write_43412 xenfb_write 3 43412 NULL
110532 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
110533 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
110534 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
110535 +usb_string_43443 usb_string 0 43443 NULL nohasharray
110536 +usemap_size_43443 usemap_size 0-2-1 43443 &usb_string_43443
110537 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
110538 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
110539 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
110540 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
110541 +do_readlink_43518 do_readlink 2 43518 NULL
110542 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
110543 +read_events_43534 read_events 3 43534 NULL
110544 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
110545 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
110546 +request_resource_43548 request_resource 0 43548 NULL
110547 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
110548 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
110549 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
110550 +proc_read_43614 proc_read 3 43614 NULL
110551 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
110552 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
110553 +random_write_43656 random_write 3 43656 NULL
110554 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
110555 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
110556 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
110557 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
110558 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
110559 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
110560 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
110561 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
110562 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
110563 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
110564 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
110565 +byte_pos_43787 byte_pos 0-2 43787 &ocfs2_xattr_get_value_outside_43787
110566 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
110567 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
110568 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
110569 +read_flush_43851 read_flush 3 43851 NULL
110570 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
110571 +SendString_43928 SendString 3 43928 NULL
110572 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
110573 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
110574 +nla_reserve_43984 nla_reserve 3 43984 NULL
110575 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
110576 +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
110577 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &scsi_command_size_43992 nohasharray
110578 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &kvm_read_guest_virt_43992
110579 +emit_flags_44006 emit_flags 4-3 44006 NULL
110580 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
110581 +fru_strlen_44046 fru_strlen 0 44046 NULL
110582 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
110583 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
110584 +__vxge_hw_vpath_tim_configure_44093 __vxge_hw_vpath_tim_configure 2 44093 NULL
110585 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
110586 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
110587 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
110588 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
110589 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
110590 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
110591 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
110592 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
110593 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
110594 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
110595 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
110596 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
110597 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
110598 +apei_resources_sub_44252 apei_resources_sub 0 44252 NULL
110599 +device_create_file_44285 device_create_file 0 44285 NULL
110600 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
110601 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
110602 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
110603 +rs_init_44327 rs_init 1 44327 NULL
110604 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
110605 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
110606 +alloc_requests_44372 alloc_requests 0 44372 NULL
110607 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
110608 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
110609 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
110610 +strlcpy_44400 strlcpy 3 44400 NULL
110611 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
110612 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
110613 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
110614 +iwl_dbgfs_bf_params_write_44450 iwl_dbgfs_bf_params_write 3 44450 NULL
110615 +write_file_debug_44476 write_file_debug 3 44476 NULL
110616 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
110617 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
110618 +bio_advance_44496 bio_advance 2 44496 NULL
110619 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
110620 +ac_register_board_44504 ac_register_board 3 44504 NULL
110621 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
110622 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
110623 +spidev_write_44510 spidev_write 3 44510 NULL
110624 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
110625 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
110626 +comm_write_44537 comm_write 3 44537 NULL
110627 +xfs_log_calc_unit_res_44540 xfs_log_calc_unit_res 0-2 44540 NULL
110628 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
110629 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
110630 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
110631 +mpi_resize_44674 mpi_resize 2 44674 NULL
110632 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
110633 +ts_read_44687 ts_read 3 44687 NULL
110634 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
110635 +__ocfs2_rotate_tree_left_44705 __ocfs2_rotate_tree_left 3 44705 NULL
110636 +xfer_to_user_44713 xfer_to_user 3 44713 NULL nohasharray
110637 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 &xfer_to_user_44713
110638 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
110639 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
110640 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
110641 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
110642 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
110643 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
110644 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
110645 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
110646 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
110647 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
110648 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
110649 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
110650 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
110651 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
110652 +sisusb_write_44834 sisusb_write 3 44834 NULL
110653 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
110654 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
110655 +copydesc_user_44855 copydesc_user 3 44855 NULL
110656 +set_advertising_44870 set_advertising 4 44870 NULL
110657 +init_rs_44873 init_rs 1 44873 NULL
110658 +skb_availroom_44883 skb_availroom 0 44883 NULL
110659 +ocfs2_wait_for_mask_44893 ocfs2_wait_for_mask 0 44893 NULL
110660 +do_tty_write_44896 do_tty_write 5 44896 NULL
110661 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
110662 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
110663 +bytepos_delta_45017 bytepos_delta 0-2 45017 NULL
110664 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
110665 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
110666 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
110667 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
110668 +sel_write_user_45060 sel_write_user 3 45060 NULL
110669 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
110670 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
110671 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
110672 +usbdev_read_45114 usbdev_read 3 45114 NULL
110673 +send_to_tty_45141 send_to_tty 3 45141 NULL
110674 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
110675 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
110676 +device_write_45156 device_write 3 45156 NULL nohasharray
110677 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
110678 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
110679 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
110680 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
110681 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
110682 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
110683 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
110684 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
110685 +event_enable_write_45238 event_enable_write 3 45238 NULL
110686 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
110687 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
110688 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
110689 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
110690 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
110691 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
110692 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
110693 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
110694 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
110695 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
110696 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
110697 +__node_remap_45458 __node_remap 4 45458 NULL
110698 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
110699 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
110700 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
110701 +i40e_alloc_vfs_45511 i40e_alloc_vfs 2 45511 NULL
110702 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
110703 +copy_macs_45534 copy_macs 4 45534 NULL
110704 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
110705 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
110706 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
110707 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
110708 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
110709 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
110710 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
110711 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
110712 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
110713 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
110714 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
110715 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
110716 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL nohasharray
110717 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 &unix_dgram_sendmsg_45699
110718 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
110719 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL nohasharray
110720 +task_cgroup_path_45734 task_cgroup_path 3 45734 &snd_cs46xx_io_read_45734
110721 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
110722 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
110723 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
110724 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
110725 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
110726 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
110727 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
110728 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
110729 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
110730 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
110731 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
110732 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
110733 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
110734 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
110735 +isdn_write_45863 isdn_write 3 45863 NULL
110736 +tpm_config_in_45880 tpm_config_in 0 45880 NULL
110737 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
110738 +ima_eventdigest_init_common_45889 ima_eventdigest_init_common 2 45889 NULL
110739 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
110740 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
110741 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
110742 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
110743 +alloc_mr_45935 alloc_mr 1 45935 NULL
110744 +copy_to_45969 copy_to 3 45969 NULL
110745 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
110746 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
110747 +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
110748 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
110749 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
110750 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
110751 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
110752 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
110753 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
110754 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
110755 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
110756 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL nohasharray
110757 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 &il3945_ucode_general_stats_read_46111
110758 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
110759 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
110760 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
110761 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
110762 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
110763 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
110764 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
110765 +fq_resize_46195 fq_resize 2 46195 NULL
110766 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
110767 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
110768 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
110769 +dsp_write_46218 dsp_write 2 46218 NULL
110770 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
110771 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
110772 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
110773 +ReadReg_46277 ReadReg 0 46277 NULL
110774 +sptlrpc_req_get_ctx_46303 sptlrpc_req_get_ctx 0 46303 NULL
110775 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
110776 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
110777 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
110778 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
110779 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
110780 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
110781 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
110782 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
110783 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
110784 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
110785 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
110786 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
110787 +filldir64_46469 filldir64 3 46469 NULL
110788 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
110789 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
110790 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
110791 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
110792 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
110793 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
110794 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
110795 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
110796 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
110797 +il3945_stats_flag_46606 il3945_stats_flag 3-0 46606 NULL
110798 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
110799 +__kfifo_out_r_46623 __kfifo_out_r 3-0 46623 NULL
110800 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
110801 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
110802 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
110803 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
110804 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
110805 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
110806 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
110807 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
110808 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
110809 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
110810 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
110811 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
110812 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
110813 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
110814 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
110815 +readreg_46845 readreg 0 46845 NULL
110816 +spi_async_46857 spi_async 0 46857 NULL
110817 +SyS_move_pages_46863 SyS_move_pages 2 46863 NULL nohasharray
110818 +vsnprintf_46863 vsnprintf 0 46863 &SyS_move_pages_46863
110819 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
110820 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
110821 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
110822 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
110823 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
110824 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
110825 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
110826 +fb_write_46924 fb_write 3 46924 NULL
110827 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
110828 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
110829 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
110830 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
110831 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
110832 +strlcat_46985 strlcat 3 46985 NULL
110833 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
110834 +sel_write_bool_46996 sel_write_bool 3 46996 NULL nohasharray
110835 +gfs2_xattr_system_set_46996 gfs2_xattr_system_set 4 46996 &sel_write_bool_46996
110836 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
110837 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
110838 +fs_path_len_47060 fs_path_len 0 47060 NULL
110839 +ext4_xattr_list_entries_47070 ext4_xattr_list_entries 0 47070 NULL
110840 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
110841 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
110842 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
110843 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
110844 +mousedev_read_47123 mousedev_read 3 47123 NULL
110845 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
110846 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
110847 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
110848 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
110849 +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
110850 +can_set_system_xattr_47182 can_set_system_xattr 4 47182 NULL
110851 +options_write_47243 options_write 3 47243 NULL
110852 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
110853 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
110854 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
110855 +vsnprintf_47291 vsnprintf 0 47291 NULL
110856 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
110857 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
110858 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
110859 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
110860 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
110861 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
110862 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
110863 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
110864 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL nohasharray
110865 +nv_rd32_47390 nv_rd32 0 47390 &trace_options_core_read_47390
110866 +nametbl_list_47391 nametbl_list 2 47391 NULL
110867 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
110868 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
110869 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
110870 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
110871 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
110872 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
110873 +posix_acl_from_disk_47445 posix_acl_from_disk 2 47445 NULL
110874 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
110875 +newpart_47485 newpart 6-4 47485 NULL
110876 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
110877 +core_sys_select_47494 core_sys_select 1 47494 NULL
110878 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
110879 +unlink_simple_47506 unlink_simple 3 47506 NULL
110880 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
110881 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
110882 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
110883 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
110884 +einj_check_trigger_header_47534 einj_check_trigger_header 0 47534 NULL
110885 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
110886 +read_ldt_47570 read_ldt 2 47570 NULL
110887 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
110888 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
110889 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
110890 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
110891 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
110892 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
110893 +get_size_47644 get_size 1-2 47644 NULL
110894 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
110895 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
110896 +save_microcode_47717 save_microcode 3 47717 NULL
110897 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
110898 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
110899 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
110900 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
110901 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
110902 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
110903 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
110904 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
110905 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
110906 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
110907 +lov_packmd_47810 lov_packmd 0 47810 NULL
110908 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
110909 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
110910 +vhci_read_47878 vhci_read 3 47878 NULL
110911 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
110912 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
110913 +comedi_write_47926 comedi_write 3 47926 NULL
110914 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
110915 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
110916 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
110917 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
110918 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
110919 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
110920 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
110921 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
110922 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
110923 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
110924 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
110925 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
110926 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
110927 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
110928 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
110929 +disc_write_48070 disc_write 3 48070 NULL
110930 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
110931 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
110932 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
110933 +set_discoverable_48141 set_discoverable 4 48141 NULL
110934 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
110935 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
110936 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
110937 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
110938 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
110939 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
110940 +brcmf_sdio_chip_cm3_exitdl_48192 brcmf_sdio_chip_cm3_exitdl 4 48192 NULL
110941 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
110942 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
110943 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
110944 +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
110945 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
110946 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
110947 +read_file_recv_48232 read_file_recv 3 48232 NULL
110948 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
110949 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
110950 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
110951 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
110952 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
110953 +trace_options_write_48275 trace_options_write 3 48275 NULL
110954 +send_set_info_48288 send_set_info 7 48288 NULL
110955 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
110956 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
110957 +hash_setkey_48310 hash_setkey 3 48310 NULL
110958 +audio_set_intf_req_48319 audio_set_intf_req 0 48319 NULL
110959 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
110960 +skb_add_data_48363 skb_add_data 3 48363 NULL
110961 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
110962 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
110963 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
110964 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
110965 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
110966 +print_filtered_48442 print_filtered 2-0 48442 NULL
110967 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
110968 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
110969 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
110970 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
110971 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
110972 +send_control_msg_48498 send_control_msg 6 48498 NULL
110973 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
110974 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
110975 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
110976 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
110977 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
110978 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
110979 +llog_data_len_48607 llog_data_len 1 48607 NULL
110980 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
110981 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
110982 +mtd_read_48655 mtd_read 0 48655 NULL
110983 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
110984 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
110985 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
110986 +altera_drscan_48698 altera_drscan 2 48698 NULL
110987 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
110988 +recv_msg_48709 recv_msg 4 48709 NULL
110989 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
110990 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
110991 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
110992 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
110993 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
110994 +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
110995 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
110996 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
110997 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
110998 +azx_get_position_48841 azx_get_position 0 48841 NULL
110999 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
111000 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
111001 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
111002 +sptlrpc_cli_alloc_reqbuf_48855 sptlrpc_cli_alloc_reqbuf 0 48855 NULL
111003 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
111004 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
111005 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
111006 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
111007 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
111008 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
111009 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
111010 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
111011 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
111012 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
111013 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
111014 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
111015 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
111016 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
111017 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
111018 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
111019 +aic_inb_49023 aic_inb 0 49023 NULL
111020 +transient_status_49027 transient_status 4 49027 NULL
111021 +iwl_mvm_power_legacy_dbgfs_read_49038 iwl_mvm_power_legacy_dbgfs_read 4 49038 NULL
111022 +aic7xxx_rem_scb_from_disc_list_49041 aic7xxx_rem_scb_from_disc_list 0 49041 NULL
111023 +scsi_register_49094 scsi_register 2 49094 NULL
111024 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
111025 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
111026 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
111027 +pt_read_49136 pt_read 3 49136 NULL
111028 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
111029 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
111030 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
111031 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
111032 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
111033 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
111034 +print_queue_49191 print_queue 4-0 49191 NULL
111035 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
111036 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
111037 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
111038 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
111039 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
111040 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
111041 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
111042 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
111043 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
111044 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
111045 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
111046 +uio_read_49300 uio_read 3 49300 NULL
111047 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
111048 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
111049 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
111050 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
111051 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
111052 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
111053 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
111054 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
111055 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
111056 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
111057 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
111058 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
111059 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
111060 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
111061 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
111062 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
111063 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
111064 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
111065 +smk_write_access_49561 smk_write_access 3 49561 NULL
111066 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
111067 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
111068 +ptlrpc_request_pack_49581 ptlrpc_request_pack 0 49581 NULL
111069 +readfifo_49583 readfifo 1 49583 NULL
111070 +tap_write_49595 tap_write 3 49595 NULL
111071 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
111072 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
111073 +heap_init_49617 heap_init 2 49617 NULL
111074 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
111075 +port_fops_read_49626 port_fops_read 3 49626 NULL
111076 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
111077 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 4-3 49683 NULL
111078 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
111079 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
111080 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
111081 +write_pool_49718 write_pool 3 49718 NULL
111082 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
111083 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
111084 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
111085 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
111086 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
111087 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
111088 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
111089 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
111090 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
111091 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
111092 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
111093 +add_uuid_49831 add_uuid 4 49831 NULL
111094 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
111095 +twl4030_write_49846 twl4030_write 2 49846 NULL
111096 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
111097 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
111098 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
111099 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
111100 +ceph_get_caps_49890 ceph_get_caps 0 49890 NULL
111101 +osc_brw_49896 osc_brw 4 49896 NULL
111102 +config_ep_by_speed_49939 config_ep_by_speed 0 49939 NULL
111103 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
111104 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
111105 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
111106 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
111107 +isdn_read_50021 isdn_read 3 50021 NULL
111108 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
111109 +ioread8_50049 ioread8 0 50049 NULL
111110 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
111111 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
111112 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
111113 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
111114 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
111115 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
111116 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
111117 +read_file_slot_50111 read_file_slot 3 50111 NULL
111118 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
111119 +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
111120 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
111121 +copy_items_50140 copy_items 6 50140 NULL
111122 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
111123 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
111124 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
111125 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
111126 +odev_update_50169 odev_update 2 50169 NULL
111127 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
111128 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
111129 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
111130 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
111131 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
111132 +mthca_buddy_init_50206 mthca_buddy_init 2 50206 NULL
111133 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
111134 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
111135 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
111136 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
111137 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
111138 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
111139 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
111140 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
111141 +do_launder_page_50329 do_launder_page 0 50329 NULL
111142 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
111143 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
111144 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
111145 +tpm_read_50344 tpm_read 3 50344 NULL
111146 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
111147 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
111148 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
111149 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
111150 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
111151 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
111152 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
111153 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
111154 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
111155 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
111156 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
111157 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
111158 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
111159 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
111160 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
111161 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
111162 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
111163 +fat_readpages_50582 fat_readpages 4 50582 NULL
111164 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
111165 +xillybus_write_50605 xillybus_write 3 50605 NULL
111166 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
111167 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
111168 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
111169 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
111170 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
111171 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
111172 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
111173 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
111174 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
111175 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
111176 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
111177 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
111178 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
111179 +tpm_write_50798 tpm_write 3 50798 NULL
111180 +write_flush_50803 write_flush 3 50803 NULL
111181 +dvb_play_50814 dvb_play 3 50814 NULL
111182 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
111183 +SetArea_50835 SetArea 4 50835 NULL
111184 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
111185 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
111186 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
111187 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
111188 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
111189 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
111190 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
111191 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
111192 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
111193 +show_device_status_50947 show_device_status 0 50947 NULL
111194 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
111195 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
111196 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
111197 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
111198 +iwl_statistics_flag_50981 iwl_statistics_flag 3-0 50981 NULL
111199 +timeout_write_50991 timeout_write 3 50991 NULL
111200 +proc_write_51003 proc_write 3 51003 NULL
111201 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
111202 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
111203 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
111204 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
111205 +dump_midi_51040 dump_midi 3 51040 NULL
111206 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
111207 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
111208 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
111209 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
111210 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
111211 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
111212 +ti_recv_51110 ti_recv 3 51110 NULL
111213 +uasp_prepare_r_request_51124 uasp_prepare_r_request 0 51124 NULL
111214 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
111215 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
111216 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
111217 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
111218 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
111219 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
111220 +drm_property_create_51239 drm_property_create 4 51239 NULL
111221 +__mxt_read_reg_51249 __mxt_read_reg 0 51249 NULL
111222 +st_read_51251 st_read 3 51251 NULL
111223 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
111224 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
111225 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
111226 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
111227 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
111228 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
111229 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
111230 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
111231 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
111232 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
111233 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
111234 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
111235 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
111236 +ceph_sync_read_51410 ceph_sync_read 3-0 51410 NULL
111237 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
111238 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
111239 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
111240 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
111241 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
111242 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
111243 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
111244 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
111245 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
111246 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
111247 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
111248 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
111249 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
111250 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
111251 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
111252 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
111253 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
111254 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
111255 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
111256 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
111257 +sel_write_access_51704 sel_write_access 3 51704 NULL
111258 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
111259 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
111260 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
111261 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
111262 +cm4040_read_51732 cm4040_read 3 51732 NULL
111263 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
111264 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
111265 +if_write_51756 if_write 3 51756 NULL
111266 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
111267 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
111268 +ioread32_51847 ioread32 0 51847 NULL nohasharray
111269 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
111270 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
111271 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
111272 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
111273 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
111274 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
111275 +user_read_51881 user_read 3 51881 NULL
111276 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
111277 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
111278 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
111279 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
111280 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
111281 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
111282 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
111283 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
111284 +__blkdev_get_51972 __blkdev_get 0 51972 NULL
111285 +get_zone_51981 get_zone 0-1 51981 NULL
111286 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
111287 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
111288 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
111289 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
111290 +rdmalt_52022 rdmalt 0 52022 NULL
111291 +override_release_52032 override_release 2 52032 NULL
111292 +end_port_52042 end_port 0 52042 NULL
111293 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
111294 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
111295 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
111296 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
111297 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
111298 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
111299 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
111300 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
111301 +retry_count_read_52129 retry_count_read 3 52129 NULL
111302 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
111303 +sub_alloc_52140 sub_alloc 0 52140 NULL
111304 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
111305 +htable_size_52148 htable_size 0-1 52148 NULL
111306 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
111307 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
111308 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
111309 +print_prefix_52176 print_prefix 0 52176 NULL
111310 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
111311 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
111312 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL nohasharray
111313 +xfs_iomap_eof_align_last_fsb_52243 xfs_iomap_eof_align_last_fsb 3 52243 &fuse_request_alloc_52243
111314 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
111315 +shrink_slab_52261 shrink_slab 2 52261 NULL
111316 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
111317 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
111318 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
111319 +read_file_reset_52310 read_file_reset 3 52310 NULL
111320 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
111321 +hwflags_read_52318 hwflags_read 3 52318 NULL
111322 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
111323 +hur_len_52339 hur_len 0 52339 NULL
111324 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
111325 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
111326 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
111327 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
111328 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
111329 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
111330 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
111331 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
111332 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
111333 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
111334 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
111335 +delay_status_52431 delay_status 5 52431 NULL
111336 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
111337 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
111338 +acpi_nvs_for_each_region_52448 acpi_nvs_for_each_region 0 52448 NULL
111339 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
111340 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
111341 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
111342 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
111343 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
111344 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
111345 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
111346 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
111347 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
111348 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
111349 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
111350 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
111351 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
111352 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
111353 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
111354 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
111355 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
111356 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
111357 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
111358 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
111359 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
111360 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
111361 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
111362 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
111363 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
111364 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
111365 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
111366 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
111367 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
111368 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
111369 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
111370 +ext2_xattr_set_acl_52857 ext2_xattr_set_acl 4 52857 NULL
111371 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
111372 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
111373 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
111374 +twlreg_write_52880 twlreg_write 3 52880 NULL
111375 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
111376 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
111377 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
111378 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
111379 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
111380 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
111381 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
111382 +send_packet_52960 send_packet 4 52960 NULL
111383 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
111384 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
111385 +num_node_state_52989 num_node_state 0 52989 NULL
111386 +uasp_alloc_stream_res_53015 uasp_alloc_stream_res 0 53015 NULL
111387 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
111388 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
111389 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
111390 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
111391 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
111392 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
111393 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
111394 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
111395 +verity_status_53120 verity_status 5 53120 NULL
111396 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
111397 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
111398 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
111399 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
111400 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
111401 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
111402 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
111403 +hfsplus_xattr_set_posix_acl_53249 hfsplus_xattr_set_posix_acl 4 53249 NULL
111404 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
111405 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
111406 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
111407 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
111408 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
111409 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
111410 +vm_mmap_53339 vm_mmap 0 53339 NULL
111411 +read_6120_creg32_53363 read_6120_creg32 0 53363 NULL
111412 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
111413 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
111414 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
111415 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
111416 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
111417 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
111418 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL
111419 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
111420 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
111421 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
111422 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
111423 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
111424 +ocfs2_xattr_set_acl_53508 ocfs2_xattr_set_acl 4 53508 NULL
111425 +check_acl_53512 check_acl 0 53512 NULL
111426 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
111427 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
111428 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
111429 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
111430 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
111431 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
111432 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
111433 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
111434 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
111435 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
111436 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
111437 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
111438 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
111439 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
111440 +bio_integrity_split_53714 bio_integrity_split 3 53714 NULL
111441 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
111442 +wdm_write_53735 wdm_write 3 53735 NULL
111443 +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 NULL nohasharray
111444 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 &amdtp_out_stream_get_max_payload_53755
111445 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
111446 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
111447 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
111448 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
111449 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
111450 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
111451 +setup_data_read_53822 setup_data_read 3 53822 NULL
111452 +pms_read_53873 pms_read 3 53873 NULL
111453 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
111454 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
111455 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
111456 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
111457 +ocfs2_make_clusters_writable_53938 ocfs2_make_clusters_writable 0 53938 NULL
111458 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
111459 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
111460 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
111461 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
111462 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
111463 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
111464 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
111465 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
111466 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
111467 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
111468 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
111469 +_malloc_54077 _malloc 1 54077 NULL
111470 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
111471 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
111472 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
111473 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
111474 +strn_len_54122 strn_len 0 54122 NULL
111475 +isku_receive_54130 isku_receive 4 54130 NULL
111476 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
111477 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
111478 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
111479 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
111480 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
111481 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
111482 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
111483 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
111484 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
111485 +reada_add_block_54247 reada_add_block 2 54247 NULL
111486 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
111487 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
111488 +audio_write_54261 audio_write 4 54261 NULL nohasharray
111489 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
111490 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
111491 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
111492 +tipc_multicast_54285 tipc_multicast 4 54285 NULL
111493 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
111494 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
111495 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
111496 +sprintf_54306 sprintf 0 54306 NULL
111497 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
111498 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
111499 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
111500 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
111501 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
111502 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
111503 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
111504 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
111505 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
111506 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
111507 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 3-0 54387 NULL
111508 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
111509 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
111510 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
111511 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
111512 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
111513 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
111514 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
111515 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
111516 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
111517 +viacam_read_54526 viacam_read 3 54526 NULL
111518 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
111519 +setsockopt_54539 setsockopt 5 54539 NULL
111520 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
111521 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
111522 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
111523 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
111524 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
111525 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
111526 +port_fops_write_54627 port_fops_write 3 54627 NULL
111527 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
111528 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
111529 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
111530 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
111531 +bus_add_device_54665 bus_add_device 0 54665 NULL
111532 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
111533 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
111534 +evm_read_key_54674 evm_read_key 3 54674 NULL
111535 +tipc_link_send_sections_fast_54689 tipc_link_send_sections_fast 3 54689 NULL
111536 +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
111537 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
111538 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
111539 +kzalloc_54740 kzalloc 1 54740 NULL
111540 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
111541 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
111542 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
111543 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
111544 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
111545 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
111546 +nfsd_write_54809 nfsd_write 6 54809 NULL
111547 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
111548 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
111549 +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
111550 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
111551 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
111552 +write_rio_54837 write_rio 3 54837 NULL
111553 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
111554 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
111555 +ll_layout_conf_54841 ll_layout_conf 0 54841 NULL
111556 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
111557 +printer_read_54851 printer_read 3 54851 NULL
111558 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
111559 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
111560 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
111561 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
111562 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
111563 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
111564 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
111565 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
111566 +add_port_54941 add_port 2 54941 NULL
111567 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 3-0 54949 NULL
111568 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
111569 +c4_add_card_54968 c4_add_card 3 54968 NULL
111570 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
111571 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
111572 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
111573 +dgap_do_bios_load_55025 dgap_do_bios_load 3 55025 NULL
111574 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
111575 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
111576 +read_dma_55086 read_dma 3 55086 NULL
111577 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
111578 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
111579 +filldir_55137 filldir 3 55137 NULL
111580 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
111581 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
111582 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
111583 +mtd_get_fact_prot_info_55186 mtd_get_fact_prot_info 0 55186 NULL
111584 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
111585 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
111586 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
111587 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
111588 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
111589 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
111590 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
111591 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
111592 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
111593 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
111594 +persistent_ram_new_55286 persistent_ram_new 2-1 55286 NULL
111595 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
111596 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
111597 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
111598 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
111599 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL
111600 +__vxge_hw_vpath_initialize_55328 __vxge_hw_vpath_initialize 2 55328 NULL
111601 +vme_user_read_55338 vme_user_read 3 55338 NULL
111602 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
111603 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
111604 +tipc_send2name_55373 tipc_send2name 5 55373 NULL
111605 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
111606 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
111607 +sysfs_chmod_file_55408 sysfs_chmod_file 0 55408 NULL
111608 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
111609 +sysfs_sd_setattr_55437 sysfs_sd_setattr 0 55437 NULL
111610 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
111611 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
111612 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
111613 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
111614 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
111615 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
111616 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
111617 +ea_get_55522 ea_get 3-0 55522 NULL
111618 +buffer_size_55534 buffer_size 0 55534 NULL
111619 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
111620 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
111621 +dgap_do_config_load_55548 dgap_do_config_load 2 55548 NULL
111622 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
111623 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
111624 +add_partition_55588 add_partition 2 55588 NULL
111625 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
111626 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL nohasharray
111627 +config_buf_55602 config_buf 0 55602 &SyS_keyctl_55602
111628 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
111629 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
111630 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
111631 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL nohasharray
111632 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 &pktgen_if_write_55628
111633 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
111634 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
111635 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
111636 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
111637 +get_info_55681 get_info 3 55681 NULL
111638 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
111639 +echo_big_lmm_get_55690 echo_big_lmm_get 0 55690 NULL
111640 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
111641 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
111642 +ocfs2_lock_refcount_tree_55719 ocfs2_lock_refcount_tree 0 55719 NULL
111643 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
111644 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
111645 +set_local_name_55757 set_local_name 4 55757 NULL
111646 +strlen_55778 strlen 0 55778 NULL
111647 +set_spte_55783 set_spte 4-5 55783 NULL
111648 +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
111649 +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
111650 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
111651 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
111652 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
111653 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
111654 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
111655 +hsc_write_55875 hsc_write 3 55875 NULL
111656 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
111657 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
111658 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
111659 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
111660 +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
111661 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
111662 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
111663 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
111664 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
111665 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
111666 +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
111667 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
111668 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
111669 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
111670 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
111671 +add_sysfs_param_56108 add_sysfs_param 0 56108 NULL
111672 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
111673 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
111674 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
111675 +__i2c_transfer_56162 __i2c_transfer 0 56162 NULL
111676 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
111677 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
111678 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
111679 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
111680 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
111681 +fd_copyin_56247 fd_copyin 3 56247 NULL
111682 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
111683 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
111684 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
111685 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
111686 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
111687 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
111688 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
111689 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
111690 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
111691 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
111692 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
111693 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
111694 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
111695 +dev_read_56369 dev_read 3 56369 NULL
111696 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
111697 +write_gssp_56404 write_gssp 3 56404 NULL
111698 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
111699 +do_get_write_access_56410 do_get_write_access 0 56410 NULL
111700 +store_msg_56417 store_msg 3 56417 NULL
111701 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
111702 +fl_create_56435 fl_create 5 56435 NULL
111703 +gnttab_map_56439 gnttab_map 2 56439 NULL
111704 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
111705 +set_connectable_56458 set_connectable 4 56458 NULL
111706 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
111707 +putused_user_56467 putused_user 3 56467 NULL
111708 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
111709 +calc_linear_pos_56472 calc_linear_pos 0-3 56472 NULL
111710 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
111711 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
111712 +init_map_ip_56508 init_map_ip 5 56508 NULL
111713 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
111714 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
111715 +ip_options_get_56538 ip_options_get 4 56538 NULL
111716 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
111717 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
111718 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
111719 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
111720 +event_filter_write_56609 event_filter_write 3 56609 NULL
111721 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
111722 +edac_device_create_block_56619 edac_device_create_block 0 56619 NULL
111723 +gather_array_56641 gather_array 3 56641 NULL
111724 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
111725 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
111726 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
111727 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
111728 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
111729 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
111730 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
111731 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
111732 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
111733 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
111734 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
111735 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
111736 +do_syslog_56807 do_syslog 3 56807 NULL
111737 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
111738 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
111739 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
111740 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
111741 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
111742 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
111743 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL
111744 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
111745 +hfsplus_setxattr_56902 hfsplus_setxattr 4 56902 NULL
111746 +strcspn_56913 strcspn 0 56913 NULL
111747 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
111748 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
111749 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
111750 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
111751 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
111752 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
111753 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
111754 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
111755 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
111756 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
111757 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
111758 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
111759 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
111760 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
111761 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
111762 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
111763 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
111764 +altera_get_note_57099 altera_get_note 6 57099 NULL
111765 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
111766 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
111767 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
111768 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
111769 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 NULL nohasharray
111770 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136 nohasharray
111771 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 &nl80211_send_deauth_57136
111772 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
111773 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
111774 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
111775 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
111776 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
111777 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
111778 +dma_fifo_alloc_57236 dma_fifo_alloc 5-3-2 57236 NULL
111779 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
111780 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
111781 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
111782 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
111783 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
111784 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
111785 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
111786 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
111787 +write_file_regval_57313 write_file_regval 3 57313 NULL
111788 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
111789 +usblp_read_57342 usblp_read 3 57342 NULL
111790 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
111791 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
111792 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
111793 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
111794 +read_file_blob_57406 read_file_blob 3 57406 NULL
111795 +enclosure_register_57412 enclosure_register 3 57412 NULL
111796 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
111797 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
111798 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
111799 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
111800 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
111801 +tipc_port_reject_sections_57478 tipc_port_reject_sections 4 57478 NULL
111802 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
111803 +skb_headlen_57501 skb_headlen 0 57501 NULL
111804 +copy_in_user_57502 copy_in_user 3 57502 NULL
111805 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
111806 +init_tag_map_57515 init_tag_map 3 57515 NULL
111807 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL nohasharray
111808 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 &il_dbgfs_force_reset_read_57517
111809 +cmm_read_57520 cmm_read 3 57520 NULL
111810 +inode_permission_57531 inode_permission 0 57531 NULL
111811 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
111812 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
111813 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
111814 +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
111815 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
111816 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
111817 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
111818 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
111819 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
111820 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
111821 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
111822 +mem_read_57631 mem_read 3 57631 NULL
111823 +r3964_write_57662 r3964_write 4 57662 NULL
111824 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
111825 +__lgwrite_57669 __lgwrite 4 57669 NULL
111826 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
111827 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
111828 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
111829 +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
111830 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL nohasharray
111831 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 &pppol2tp_recvmsg_57742
111832 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
111833 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
111834 +apei_exec_collect_resources_57788 apei_exec_collect_resources 0 57788 NULL
111835 +ld2_57794 ld2 0 57794 NULL
111836 +ivtv_read_57796 ivtv_read 3 57796 NULL
111837 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
111838 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
111839 +flash_read_57843 flash_read 3 57843 NULL
111840 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
111841 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
111842 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
111843 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
111844 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
111845 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
111846 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
111847 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
111848 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
111849 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
111850 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
111851 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
111852 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
111853 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
111854 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
111855 +mce_async_out_58056 mce_async_out 3 58056 NULL
111856 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
111857 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
111858 +cm4040_write_58079 cm4040_write 3 58079 NULL
111859 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
111860 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
111861 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
111862 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
111863 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
111864 +read_file_debug_58256 read_file_debug 3 58256 NULL
111865 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
111866 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
111867 +profile_load_58267 profile_load 3 58267 NULL
111868 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
111869 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
111870 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
111871 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
111872 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
111873 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
111874 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
111875 +SyS_migrate_pages_58348 SyS_migrate_pages 2 58348 NULL
111876 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
111877 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
111878 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
111879 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
111880 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
111881 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
111882 +capabilities_read_58457 capabilities_read 3 58457 NULL
111883 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
111884 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
111885 +nv_rd08_58472 nv_rd08 0 58472 NULL
111886 +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
111887 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
111888 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
111889 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
111890 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
111891 +ldlm_srv_pool_shrink_58554 ldlm_srv_pool_shrink 0 58554 NULL
111892 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
111893 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
111894 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
111895 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
111896 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
111897 +xip_file_read_58592 xip_file_read 3 58592 NULL
111898 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
111899 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
111900 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
111901 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
111902 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
111903 +find_zero_58685 find_zero 0-1 58685 NULL
111904 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
111905 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
111906 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
111907 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
111908 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
111909 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
111910 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
111911 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
111912 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
111913 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
111914 +ep_read_58813 ep_read 3 58813 NULL
111915 +command_write_58841 command_write 3 58841 NULL
111916 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
111917 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
111918 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
111919 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
111920 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
111921 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
111922 +sptlrpc_import_sec_adapt_58948 sptlrpc_import_sec_adapt 0 58948 NULL
111923 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
111924 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
111925 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
111926 +init_list_set_59005 init_list_set 3 59005 NULL
111927 +ep_write_59008 ep_write 3 59008 NULL
111928 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
111929 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
111930 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
111931 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
111932 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
111933 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
111934 +sysfs_link_sibling_59078 sysfs_link_sibling 0 59078 NULL
111935 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
111936 +scsi_io_completion_59122 scsi_io_completion 2 59122 NULL
111937 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
111938 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 NULL nohasharray
111939 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 &print_devstats_dot11RTSSuccessCount_59145
111940 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
111941 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
111942 +md_getxattr_59161 md_getxattr 0 59161 NULL
111943 +ksize_59176 ksize 0 59176 NULL
111944 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
111945 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
111946 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
111947 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
111948 +dt3155_read_59226 dt3155_read 3 59226 NULL
111949 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
111950 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
111951 +nla_len_59258 nla_len 0 59258 NULL
111952 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
111953 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
111954 +fd_copyout_59323 fd_copyout 3 59323 NULL
111955 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
111956 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
111957 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
111958 +__map_request_59350 __map_request 0 59350 NULL
111959 +f2fs_fallocate_59377 f2fs_fallocate 3-4 59377 NULL
111960 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
111961 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
111962 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
111963 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
111964 +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
111965 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
111966 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
111967 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
111968 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
111969 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
111970 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
111971 +tunables_write_59563 tunables_write 3 59563 NULL
111972 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
111973 +write_pbl_59583 write_pbl 4 59583 NULL
111974 +memdup_user_59590 memdup_user 2 59590 NULL
111975 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
111976 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
111977 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
111978 +mtrr_write_59622 mtrr_write 3 59622 NULL
111979 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
111980 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
111981 +hidraw_read_59650 hidraw_read 3 59650 NULL
111982 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
111983 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
111984 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
111985 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
111986 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
111987 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
111988 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
111989 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
111990 +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
111991 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
111992 +strnlen_59746 strnlen 0 59746 NULL
111993 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
111994 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
111995 +venus_remove_59781 venus_remove 4 59781 NULL
111996 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
111997 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
111998 +ipw_write_59807 ipw_write 3 59807 NULL
111999 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
112000 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
112001 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
112002 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
112003 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
112004 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
112005 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
112006 +ocfs2_extend_rotate_transaction_59894 ocfs2_extend_rotate_transaction 2-3 59894 NULL
112007 +aic7xxx_abort_waiting_scb_59932 aic7xxx_abort_waiting_scb 0 59932 NULL
112008 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
112009 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
112010 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
112011 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
112012 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
112013 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
112014 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
112015 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
112016 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
112017 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
112018 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
112019 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
112020 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
112021 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
112022 +vcs_size_60050 vcs_size 0 60050 NULL
112023 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
112024 +compat_writev_60063 compat_writev 3 60063 NULL
112025 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
112026 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
112027 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
112028 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
112029 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
112030 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
112031 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
112032 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
112033 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
112034 +init_state_60165 init_state 2 60165 NULL
112035 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
112036 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
112037 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
112038 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
112039 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
112040 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
112041 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
112042 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
112043 +printer_write_60276 printer_write 3 60276 NULL
112044 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
112045 +getDataLength_60301 getDataLength 0 60301 NULL
112046 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
112047 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
112048 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
112049 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
112050 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
112051 +driver_names_read_60399 driver_names_read 3 60399 NULL
112052 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
112053 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
112054 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
112055 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
112056 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
112057 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
112058 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
112059 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
112060 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
112061 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
112062 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
112063 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
112064 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
112065 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
112066 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
112067 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
112068 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
112069 +vga_rcrt_60731 vga_rcrt 0 60731 NULL
112070 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
112071 +raid_status_60755 raid_status 5 60755 NULL
112072 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
112073 +opticon_write_60775 opticon_write 4 60775 NULL
112074 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
112075 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
112076 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
112077 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
112078 +generic_writepages_60871 generic_writepages 0 60871 NULL
112079 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
112080 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
112081 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
112082 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
112083 +scrub_chunk_60926 scrub_chunk 5 60926 NULL
112084 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
112085 +pti_char_write_60960 pti_char_write 3 60960 NULL
112086 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
112087 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
112088 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
112089 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
112090 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
112091 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
112092 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
112093 +symtab_init_61050 symtab_init 2 61050 NULL
112094 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
112095 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
112096 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
112097 +get_derived_key_61100 get_derived_key 4 61100 NULL
112098 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-1-2-3-4 61104 NULL
112099 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
112100 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
112101 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
112102 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
112103 +brcmf_sdio_chip_cr4_exitdl_61143 brcmf_sdio_chip_cr4_exitdl 4 61143 NULL
112104 +pair_device_61175 pair_device 4 61175 NULL nohasharray
112105 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
112106 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
112107 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
112108 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
112109 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
112110 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
112111 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270 nohasharray
112112 +ifalias_store_61270 ifalias_store 4 61270 &find_get_pages_tag_61270
112113 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
112114 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
112115 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
112116 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
112117 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
112118 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
112119 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
112120 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
112121 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
112122 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
112123 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
112124 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
112125 +system_enable_write_61396 system_enable_write 3 61396 NULL
112126 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
112127 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
112128 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
112129 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
112130 +ocfs2_get_refcount_rec_61514 ocfs2_get_refcount_rec 0 61514 NULL
112131 +erst_errno_61526 erst_errno 0 61526 NULL
112132 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
112133 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
112134 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
112135 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
112136 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
112137 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
112138 +seq_open_private_61589 seq_open_private 3 61589 NULL
112139 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
112140 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
112141 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
112142 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
112143 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
112144 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
112145 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL
112146 +resize_stripes_61650 resize_stripes 2 61650 NULL
112147 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
112148 +insert_one_name_61668 insert_one_name 7 61668 NULL
112149 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
112150 +lock_loop_61681 lock_loop 1 61681 NULL
112151 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
112152 +filter_read_61692 filter_read 3 61692 NULL
112153 +iov_length_61716 iov_length 0 61716 NULL
112154 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
112155 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
112156 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
112157 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
112158 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
112159 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
112160 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
112161 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
112162 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
112163 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
112164 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
112165 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
112166 +get_fw_name_61874 get_fw_name 3 61874 NULL
112167 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
112168 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
112169 +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
112170 +clear_refs_write_61904 clear_refs_write 3 61904 NULL nohasharray
112171 +import_sec_check_expire_61904 import_sec_check_expire 0 61904 &clear_refs_write_61904
112172 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
112173 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
112174 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
112175 +edac_device_create_instance_61940 edac_device_create_instance 0 61940 NULL
112176 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
112177 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
112178 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
112179 +fix_read_error_61965 fix_read_error 4 61965 NULL
112180 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
112181 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
112182 +cow_file_range_61979 cow_file_range 3 61979 NULL
112183 +dequeue_event_62000 dequeue_event 3 62000 NULL
112184 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
112185 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
112186 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
112187 +SYSC_select_62024 SYSC_select 1 62024 NULL
112188 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
112189 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
112190 +do_pselect_62061 do_pselect 1 62061 NULL
112191 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
112192 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
112193 +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
112194 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
112195 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
112196 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
112197 +kobject_add_varg_62133 kobject_add_varg 0 62133 NULL nohasharray
112198 +qib_diag_write_62133 qib_diag_write 3 62133 &kobject_add_varg_62133
112199 +device_add_attrs_62135 device_add_attrs 0 62135 NULL nohasharray
112200 +ql_status_62135 ql_status 5 62135 &device_add_attrs_62135
112201 +video_usercopy_62151 video_usercopy 2 62151 NULL
112202 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
112203 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
112204 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
112205 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
112206 +btrfs_xattr_acl_set_62203 btrfs_xattr_acl_set 4 62203 NULL
112207 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
112208 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
112209 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
112210 +subtract_dirty_62242 subtract_dirty 2-3 62242 NULL
112211 +get_random_int_62279 get_random_int 0 62279 NULL
112212 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
112213 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
112214 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
112215 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
112216 +ocfs2_xattr_buckets_per_cluster_62330 ocfs2_xattr_buckets_per_cluster 0 62330 NULL
112217 +subseq_list_62332 subseq_list 3-0 62332 NULL
112218 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
112219 +flash_write_62354 flash_write 3 62354 NULL
112220 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
112221 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
112222 +altera_irscan_62396 altera_irscan 2 62396 NULL
112223 +set_ssp_62411 set_ssp 4 62411 NULL
112224 +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
112225 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
112226 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
112227 +debugfs_read_62535 debugfs_read 3 62535 NULL
112228 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
112229 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
112230 +link_send_sections_long_62557 link_send_sections_long 3 62557 NULL
112231 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
112232 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
112233 +get_subdir_62581 get_subdir 3 62581 NULL
112234 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
112235 +tipc_port_recv_sections_62609 tipc_port_recv_sections 3 62609 NULL
112236 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
112237 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
112238 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
112239 +ocfs2_wait_for_mask_interruptible_62675 ocfs2_wait_for_mask_interruptible 0 62675 NULL
112240 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
112241 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
112242 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
112243 +rdm_62719 rdm 0 62719 NULL
112244 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
112245 +key_replays_read_62746 key_replays_read 3 62746 NULL
112246 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
112247 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
112248 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
112249 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
112250 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
112251 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
112252 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
112253 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
112254 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
112255 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
112256 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
112257 +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
112258 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
112259 +aoechr_write_62883 aoechr_write 3 62883 NULL
112260 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
112261 +ocfs2_validate_gd_parent_62905 ocfs2_validate_gd_parent 0 62905 NULL
112262 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
112263 +getdqbuf_62908 getdqbuf 1 62908 NULL
112264 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
112265 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
112266 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
112267 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
112268 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
112269 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
112270 +unlink1_63059 unlink1 3 63059 NULL
112271 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
112272 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
112273 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
112274 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
112275 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
112276 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
112277 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
112278 +vme_master_read_63221 vme_master_read 0 63221 NULL
112279 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
112280 +ptp_read_63251 ptp_read 4 63251 NULL
112281 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
112282 +raid5_resize_63306 raid5_resize 2 63306 NULL
112283 +proc_info_read_63344 proc_info_read 3 63344 NULL
112284 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
112285 +idmouse_read_63374 idmouse_read 3 63374 NULL
112286 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
112287 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
112288 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
112289 +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
112290 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
112291 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
112292 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
112293 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
112294 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
112295 +read_kcore_63488 read_kcore 3 63488 NULL
112296 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
112297 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
112298 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
112299 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
112300 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
112301 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
112302 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
112303 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
112304 +write_debug_level_63613 write_debug_level 3 63613 NULL
112305 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
112306 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
112307 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
112308 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
112309 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
112310 +vbi_read_63673 vbi_read 3 63673 NULL
112311 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
112312 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
112313 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
112314 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
112315 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
112316 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
112317 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
112318 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
112319 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
112320 +prepare_copy_63826 prepare_copy 2 63826 NULL
112321 +sel_write_load_63830 sel_write_load 3 63830 NULL
112322 +ll_readlink_63836 ll_readlink 3 63836 NULL
112323 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
112324 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
112325 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
112326 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
112327 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
112328 +__team_options_register_63941 __team_options_register 3 63941 NULL
112329 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
112330 +sysfs_add_one_63969 sysfs_add_one 0 63969 NULL
112331 +set_bredr_63975 set_bredr 4 63975 NULL
112332 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
112333 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
112334 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
112335 +hfsplus_security_setxattr_64009 hfsplus_security_setxattr 4 64009 NULL
112336 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
112337 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
112338 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
112339 +get_u8_64076 get_u8 0 64076 NULL
112340 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
112341 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
112342 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
112343 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
112344 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
112345 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
112346 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
112347 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
112348 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
112349 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
112350 +init_bch_64130 init_bch 1-2 64130 NULL
112351 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
112352 +read_div_64147 read_div 0 64147 NULL
112353 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
112354 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
112355 +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
112356 +read_pulse_64227 read_pulse 0-3 64227 NULL
112357 +ea_len_64229 ea_len 0 64229 NULL
112358 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
112359 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
112360 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
112361 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
112362 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
112363 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
112364 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
112365 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
112366 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
112367 +ts_write_64336 ts_write 3 64336 NULL
112368 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
112369 +bnx2x_vfop_mcast_cmd_64354 bnx2x_vfop_mcast_cmd 5 64354 NULL
112370 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
112371 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
112372 +reg_create_64372 reg_create 5 64372 NULL
112373 +ilo_write_64378 ilo_write 3 64378 NULL
112374 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
112375 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
112376 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
112377 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
112378 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
112379 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
112380 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
112381 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
112382 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
112383 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
112384 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
112385 +single_open_size_64483 single_open_size 4 64483 NULL
112386 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
112387 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
112388 +remove_uuid_64505 remove_uuid 4 64505 NULL
112389 +crypto_blkcipher_alignmask_64520 crypto_blkcipher_alignmask 0 64520 NULL
112390 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
112391 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
112392 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
112393 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
112394 +SyS_bind_64544 SyS_bind 3 64544 NULL
112395 +rbd_obj_read_sync_64554 rbd_obj_read_sync 4-3 64554 NULL
112396 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
112397 +__spi_sync_64561 __spi_sync 0 64561 NULL nohasharray
112398 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 &__spi_sync_64561
112399 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
112400 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
112401 +do_erase_64574 do_erase 4 64574 NULL
112402 +fanotify_write_64623 fanotify_write 3 64623 NULL
112403 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
112404 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
112405 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
112406 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
112407 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
112408 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
112409 +sec_bulk_write_64691 sec_bulk_write 2-3 64691 NULL
112410 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
112411 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
112412 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
112413 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
112414 +AscGetChipVersion_64737 AscGetChipVersion 0 64737 NULL
112415 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
112416 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
112417 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
112418 +message_for_md_64777 message_for_md 5 64777 NULL
112419 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
112420 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
112421 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
112422 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
112423 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
112424 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
112425 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
112426 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
112427 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
112428 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
112429 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
112430 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
112431 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
112432 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
112433 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
112434 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
112435 +insert_dent_65034 insert_dent 7 65034 NULL
112436 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
112437 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
112438 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
112439 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
112440 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
112441 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
112442 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
112443 +uasp_alloc_cmd_65097 uasp_alloc_cmd 0 65097 NULL
112444 +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
112445 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
112446 +print_endpoint_stat_65232 print_endpoint_stat 3-4-0 65232 NULL
112447 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
112448 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
112449 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
112450 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
112451 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
112452 +get_var_len_65304 get_var_len 0 65304 NULL
112453 +unpack_array_65318 unpack_array 0 65318 NULL
112454 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
112455 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
112456 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
112457 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
112458 +SyS_writev_65372 SyS_writev 3 65372 NULL
112459 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
112460 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
112461 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
112462 +usb_ep_enable_65405 usb_ep_enable 0 65405 NULL
112463 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
112464 +device_add_groups_65423 device_add_groups 0 65423 NULL
112465 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
112466 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
112467 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
112468 +clear_user_65470 clear_user 2 65470 NULL
112469 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
112470 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
112471 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
112472 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
112473 new file mode 100644
112474 index 0000000..94aa56d
112475 --- /dev/null
112476 +++ b/tools/gcc/size_overflow_plugin.c
112477 @@ -0,0 +1,4040 @@
112478 +/*
112479 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
112480 + * Licensed under the GPL v2, or (at your option) v3
112481 + *
112482 + * Homepage:
112483 + * http://www.grsecurity.net/~ephox/overflow_plugin/
112484 + *
112485 + * Documentation:
112486 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
112487 + *
112488 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
112489 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
112490 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
112491 + *
112492 + * Usage:
112493 + * $ 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
112494 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
112495 + */
112496 +
112497 +#include "gcc-common.h"
112498 +
112499 +int plugin_is_GPL_compatible;
112500 +
112501 +static struct plugin_info size_overflow_plugin_info = {
112502 + .version = "20140128",
112503 + .help = "no-size-overflow\tturn off size overflow checking\n",
112504 +};
112505 +
112506 +#define BEFORE_STMT true
112507 +#define AFTER_STMT false
112508 +#define CREATE_NEW_VAR NULL_TREE
112509 +#define CODES_LIMIT 32
112510 +#define MAX_PARAM 31
112511 +#define VEC_LEN 128
112512 +#define MY_STMT GF_PLF_1
112513 +#define NO_CAST_CHECK GF_PLF_2
112514 +#define RET_CHECK NULL_TREE
112515 +#define CANNOT_FIND_ARG 32
112516 +#define WRONG_NODE 32
112517 +#define NOT_INTENTIONAL_ASM NULL
112518 +#define MIN_CHECK true
112519 +#define MAX_CHECK false
112520 +
112521 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
112522 +#define YES_ASM_STR "# size_overflow MARK_YES "
112523 +#define OK_ASM_STR "# size_overflow "
112524 +
112525 +struct size_overflow_hash {
112526 + const struct size_overflow_hash * const next;
112527 + const char * const name;
112528 + const unsigned int param;
112529 +};
112530 +
112531 +#include "size_overflow_hash.h"
112532 +
112533 +enum mark {
112534 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
112535 +};
112536 +
112537 +static unsigned int call_count;
112538 +
112539 +struct visited {
112540 + struct visited *next;
112541 + const_tree fndecl;
112542 + unsigned int num;
112543 + const_tree rhs;
112544 +};
112545 +
112546 +struct next_cgraph_node {
112547 + struct next_cgraph_node *next;
112548 + struct cgraph_node *current_function;
112549 + tree callee_fndecl;
112550 + unsigned int num;
112551 +};
112552 +
112553 +struct interesting_node {
112554 + struct interesting_node *next;
112555 + gimple first_stmt;
112556 + const_tree fndecl;
112557 + tree node;
112558 +#if BUILDING_GCC_VERSION <= 4007
112559 + VEC(tree, gc) *last_nodes;
112560 +#else
112561 + vec<tree, va_gc> *last_nodes;
112562 +#endif
112563 + unsigned int num;
112564 + enum mark intentional_attr_decl;
112565 + enum mark intentional_attr_cur_fndecl;
112566 + gimple intentional_mark_from_gimple;
112567 +};
112568 +
112569 +static tree report_size_overflow_decl;
112570 +static const_tree const_char_ptr_type_node;
112571 +
112572 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs);
112573 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
112574 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
112575 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
112576 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
112577 +
112578 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
112579 +static tree get_size_overflow_type(gimple stmt, const_tree node);
112580 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
112581 +
112582 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
112583 +{
112584 + unsigned int arg_count;
112585 + enum tree_code code = TREE_CODE(*node);
112586 +
112587 + switch (code) {
112588 + case FUNCTION_DECL:
112589 + arg_count = type_num_arguments(TREE_TYPE(*node));
112590 + break;
112591 + case FUNCTION_TYPE:
112592 + case METHOD_TYPE:
112593 + arg_count = type_num_arguments(*node);
112594 + break;
112595 + default:
112596 + *no_add_attrs = true;
112597 + error("%s: %qE attribute only applies to functions", __func__, name);
112598 + return NULL_TREE;
112599 + }
112600 +
112601 + for (; args; args = TREE_CHAIN(args)) {
112602 + tree position = TREE_VALUE(args);
112603 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
112604 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
112605 + *no_add_attrs = true;
112606 + }
112607 + }
112608 + return NULL_TREE;
112609 +}
112610 +
112611 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
112612 +{
112613 + unsigned int arg_count;
112614 + enum tree_code code = TREE_CODE(*node);
112615 +
112616 + switch (code) {
112617 + case FUNCTION_DECL:
112618 + arg_count = type_num_arguments(TREE_TYPE(*node));
112619 + break;
112620 + case FUNCTION_TYPE:
112621 + case METHOD_TYPE:
112622 + arg_count = type_num_arguments(*node);
112623 + break;
112624 + case FIELD_DECL:
112625 + return NULL_TREE;
112626 + default:
112627 + *no_add_attrs = true;
112628 + error("%qE attribute only applies to functions", name);
112629 + return NULL_TREE;
112630 + }
112631 +
112632 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
112633 + return NULL_TREE;
112634 +
112635 + for (; args; args = TREE_CHAIN(args)) {
112636 + tree position = TREE_VALUE(args);
112637 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
112638 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
112639 + *no_add_attrs = true;
112640 + }
112641 + }
112642 + return NULL_TREE;
112643 +}
112644 +
112645 +static struct attribute_spec size_overflow_attr = {
112646 + .name = "size_overflow",
112647 + .min_length = 1,
112648 + .max_length = -1,
112649 + .decl_required = true,
112650 + .type_required = false,
112651 + .function_type_required = false,
112652 + .handler = handle_size_overflow_attribute,
112653 +#if BUILDING_GCC_VERSION >= 4007
112654 + .affects_type_identity = false
112655 +#endif
112656 +};
112657 +
112658 +static struct attribute_spec intentional_overflow_attr = {
112659 + .name = "intentional_overflow",
112660 + .min_length = 1,
112661 + .max_length = -1,
112662 + .decl_required = true,
112663 + .type_required = false,
112664 + .function_type_required = false,
112665 + .handler = handle_intentional_overflow_attribute,
112666 +#if BUILDING_GCC_VERSION >= 4007
112667 + .affects_type_identity = false
112668 +#endif
112669 +};
112670 +
112671 +static void register_attributes(void __unused *event_data, void __unused *data)
112672 +{
112673 + register_attribute(&size_overflow_attr);
112674 + register_attribute(&intentional_overflow_attr);
112675 +}
112676 +
112677 +static bool is_bool(const_tree node)
112678 +{
112679 + const_tree type;
112680 +
112681 + if (node == NULL_TREE)
112682 + return false;
112683 +
112684 + type = TREE_TYPE(node);
112685 + if (!INTEGRAL_TYPE_P(type))
112686 + return false;
112687 + if (TREE_CODE(type) == BOOLEAN_TYPE)
112688 + return true;
112689 + if (TYPE_PRECISION(type) == 1)
112690 + return true;
112691 + return false;
112692 +}
112693 +
112694 +static bool skip_types(const_tree var)
112695 +{
112696 + tree type;
112697 + enum tree_code code;
112698 +
112699 + if (is_gimple_constant(var))
112700 + return true;
112701 +
112702 + switch (TREE_CODE(var)) {
112703 + case ADDR_EXPR:
112704 +#if BUILDING_GCC_VERSION >= 4006
112705 + case MEM_REF:
112706 +#endif
112707 + case ARRAY_REF:
112708 + case BIT_FIELD_REF:
112709 + case INDIRECT_REF:
112710 + case TARGET_MEM_REF:
112711 + case COMPONENT_REF:
112712 + case VAR_DECL:
112713 + case VIEW_CONVERT_EXPR:
112714 + return true;
112715 + default:
112716 + break;
112717 + }
112718 +
112719 + code = TREE_CODE(var);
112720 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
112721 +
112722 + type = TREE_TYPE(var);
112723 + switch (TREE_CODE(type)) {
112724 + case INTEGER_TYPE:
112725 + case ENUMERAL_TYPE:
112726 + return false;
112727 + case BOOLEAN_TYPE:
112728 + return is_bool(var);
112729 + default:
112730 + return true;
112731 + }
112732 +}
112733 +
112734 +static inline gimple get_def_stmt(const_tree node)
112735 +{
112736 + gcc_assert(node != NULL_TREE);
112737 +
112738 + if (skip_types(node))
112739 + return NULL;
112740 +
112741 + if (TREE_CODE(node) != SSA_NAME)
112742 + return NULL;
112743 + return SSA_NAME_DEF_STMT(node);
112744 +}
112745 +
112746 +static unsigned char get_tree_code(const_tree type)
112747 +{
112748 + switch (TREE_CODE(type)) {
112749 + case ARRAY_TYPE:
112750 + return 0;
112751 + case BOOLEAN_TYPE:
112752 + return 1;
112753 + case ENUMERAL_TYPE:
112754 + return 2;
112755 + case FUNCTION_TYPE:
112756 + return 3;
112757 + case INTEGER_TYPE:
112758 + return 4;
112759 + case POINTER_TYPE:
112760 + return 5;
112761 + case RECORD_TYPE:
112762 + return 6;
112763 + case UNION_TYPE:
112764 + return 7;
112765 + case VOID_TYPE:
112766 + return 8;
112767 + case REAL_TYPE:
112768 + return 9;
112769 + case VECTOR_TYPE:
112770 + return 10;
112771 + case REFERENCE_TYPE:
112772 + return 11;
112773 + case OFFSET_TYPE:
112774 + return 12;
112775 + case COMPLEX_TYPE:
112776 + return 13;
112777 + default:
112778 + debug_tree((tree)type);
112779 + gcc_unreachable();
112780 + }
112781 +}
112782 +
112783 +struct function_hash {
112784 + size_t tree_codes_len;
112785 + unsigned char tree_codes[CODES_LIMIT];
112786 + const_tree fndecl;
112787 + unsigned int hash;
112788 +};
112789 +
112790 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
112791 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
112792 +{
112793 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
112794 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
112795 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
112796 +
112797 + unsigned int m = 0x57559429;
112798 + unsigned int n = 0x5052acdb;
112799 + const unsigned int *key4 = (const unsigned int *)key;
112800 + unsigned int h = len;
112801 + unsigned int k = len + seed + n;
112802 + unsigned long long p;
112803 +
112804 + while (len >= 8) {
112805 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
112806 + len -= 8;
112807 + }
112808 + if (len >= 4) {
112809 + cwmixb(key4[0]) key4 += 1;
112810 + len -= 4;
112811 + }
112812 + if (len)
112813 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
112814 + cwmixb(h ^ (k + n));
112815 + return k ^ h;
112816 +
112817 +#undef cwfold
112818 +#undef cwmixa
112819 +#undef cwmixb
112820 +}
112821 +
112822 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
112823 +{
112824 + unsigned int fn, codes, seed = 0;
112825 +
112826 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
112827 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
112828 +
112829 + fn_hash_data->hash = fn ^ codes;
112830 +}
112831 +
112832 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
112833 +{
112834 + gcc_assert(type != NULL_TREE);
112835 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
112836 +
112837 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
112838 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
112839 + fn_hash_data->tree_codes_len++;
112840 + type = TREE_TYPE(type);
112841 + }
112842 +}
112843 +
112844 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
112845 +{
112846 + const_tree result;
112847 +
112848 + gcc_assert(node != NULL_TREE);
112849 +
112850 + if (DECL_P(node)) {
112851 + result = DECL_RESULT(node);
112852 + if (result != NULL_TREE)
112853 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
112854 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
112855 + }
112856 +
112857 + gcc_assert(TYPE_P(node));
112858 +
112859 + if (TREE_CODE(node) == FUNCTION_TYPE)
112860 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
112861 +
112862 + return set_node_codes(node, fn_hash_data);
112863 +}
112864 +
112865 +static void set_function_codes(struct function_hash *fn_hash_data)
112866 +{
112867 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
112868 + enum tree_code code = TREE_CODE(type);
112869 +
112870 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
112871 +
112872 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
112873 +
112874 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
112875 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
112876 +}
112877 +
112878 +static const struct size_overflow_hash *get_function_hash(const_tree fndecl)
112879 +{
112880 + const struct size_overflow_hash *entry;
112881 + struct function_hash fn_hash_data;
112882 + const char *func_name;
112883 +
112884 + // skip builtins __builtin_constant_p
112885 + if (DECL_BUILT_IN(fndecl))
112886 + return NULL;
112887 +
112888 + fn_hash_data.fndecl = fndecl;
112889 + fn_hash_data.tree_codes_len = 0;
112890 +
112891 + set_function_codes(&fn_hash_data);
112892 + gcc_assert(fn_hash_data.tree_codes_len != 0);
112893 +
112894 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
112895 + set_hash(func_name, &fn_hash_data);
112896 +
112897 + entry = size_overflow_hash[fn_hash_data.hash];
112898 +
112899 + while (entry) {
112900 + if (!strcmp(entry->name, func_name))
112901 + return entry;
112902 + entry = entry->next;
112903 + }
112904 + return NULL;
112905 +}
112906 +
112907 +static void print_missing_msg(const_tree func, unsigned int argnum)
112908 +{
112909 + location_t loc;
112910 + const char *curfunc;
112911 + struct function_hash fn_hash_data;
112912 +
112913 + fn_hash_data.fndecl = DECL_ORIGIN(func);
112914 + fn_hash_data.tree_codes_len = 0;
112915 +
112916 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
112917 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
112918 +
112919 + set_function_codes(&fn_hash_data);
112920 + set_hash(curfunc, &fn_hash_data);
112921 +
112922 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
112923 +}
112924 +
112925 +static unsigned int find_arg_number_tree(const_tree arg, const_tree func)
112926 +{
112927 + tree var;
112928 + unsigned int argnum = 1;
112929 +
112930 + if (TREE_CODE(arg) == SSA_NAME)
112931 + arg = SSA_NAME_VAR(arg);
112932 +
112933 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
112934 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
112935 + continue;
112936 + if (!skip_types(var))
112937 + return argnum;
112938 + }
112939 +
112940 + return CANNOT_FIND_ARG;
112941 +}
112942 +
112943 +static tree create_new_var(tree type)
112944 +{
112945 + tree new_var = create_tmp_var(type, "cicus");
112946 +
112947 + add_referenced_var(new_var);
112948 + return new_var;
112949 +}
112950 +
112951 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
112952 +{
112953 + gimple assign;
112954 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
112955 + tree type = TREE_TYPE(rhs1);
112956 + tree lhs = create_new_var(type);
112957 +
112958 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
112959 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
112960 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
112961 +
112962 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
112963 + update_stmt(assign);
112964 + gimple_set_plf(assign, MY_STMT, true);
112965 + return assign;
112966 +}
112967 +
112968 +static tree cast_a_tree(tree type, tree var)
112969 +{
112970 + gcc_assert(type != NULL_TREE);
112971 + gcc_assert(var != NULL_TREE);
112972 + gcc_assert(fold_convertible_p(type, var));
112973 +
112974 + return fold_convert(type, var);
112975 +}
112976 +
112977 +static tree get_lhs(const_gimple stmt)
112978 +{
112979 + switch (gimple_code(stmt)) {
112980 + case GIMPLE_ASSIGN:
112981 + case GIMPLE_CALL:
112982 + return gimple_get_lhs(stmt);
112983 + case GIMPLE_PHI:
112984 + return gimple_phi_result(stmt);
112985 + default:
112986 + return NULL_TREE;
112987 + }
112988 +}
112989 +
112990 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
112991 +{
112992 + const_gimple def_stmt = get_def_stmt(rhs);
112993 +
112994 + if (force)
112995 + return false;
112996 +
112997 + if (is_gimple_constant(rhs))
112998 + return false;
112999 +
113000 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
113001 + return false;
113002 +
113003 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
113004 + return false;
113005 +
113006 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
113007 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
113008 + return false;
113009 +
113010 + return true;
113011 +}
113012 +
113013 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
113014 +{
113015 + gimple assign, def_stmt;
113016 +
113017 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
113018 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
113019 + gcc_unreachable();
113020 +
113021 + def_stmt = get_def_stmt(rhs);
113022 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && gimple_plf(def_stmt, MY_STMT))
113023 + return def_stmt;
113024 +
113025 + if (lhs == CREATE_NEW_VAR)
113026 + lhs = create_new_var(dst_type);
113027 +
113028 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
113029 +
113030 + if (!gsi_end_p(*gsi)) {
113031 + location_t loc = gimple_location(gsi_stmt(*gsi));
113032 + gimple_set_location(assign, loc);
113033 + }
113034 +
113035 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
113036 +
113037 + if (before)
113038 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
113039 + else
113040 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
113041 + update_stmt(assign);
113042 + return assign;
113043 +}
113044 +
113045 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
113046 +{
113047 + gimple_stmt_iterator gsi;
113048 + tree lhs;
113049 + gimple new_stmt;
113050 +
113051 + if (rhs == NULL_TREE)
113052 + return NULL_TREE;
113053 +
113054 + gsi = gsi_for_stmt(stmt);
113055 + new_stmt = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
113056 + gimple_set_plf(new_stmt, MY_STMT, true);
113057 +
113058 + lhs = get_lhs(new_stmt);
113059 + gcc_assert(lhs != NULL_TREE);
113060 + return lhs;
113061 +}
113062 +
113063 +static tree cast_to_TI_type(gimple stmt, tree node)
113064 +{
113065 + gimple_stmt_iterator gsi;
113066 + gimple cast_stmt;
113067 + tree type = TREE_TYPE(node);
113068 +
113069 + if (types_compatible_p(type, intTI_type_node))
113070 + return node;
113071 +
113072 + gsi = gsi_for_stmt(stmt);
113073 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113074 + gimple_set_plf(cast_stmt, MY_STMT, true);
113075 + return gimple_assign_lhs(cast_stmt);
113076 +}
113077 +
113078 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
113079 +{
113080 + tree lhs, new_lhs;
113081 + gimple_stmt_iterator gsi;
113082 +
113083 + if (rhs1 == NULL_TREE) {
113084 + debug_gimple_stmt(oldstmt);
113085 + error("%s: rhs1 is NULL_TREE", __func__);
113086 + gcc_unreachable();
113087 + }
113088 +
113089 + switch (gimple_code(oldstmt)) {
113090 + case GIMPLE_ASM:
113091 + lhs = rhs1;
113092 + break;
113093 + case GIMPLE_CALL:
113094 + case GIMPLE_ASSIGN:
113095 + lhs = gimple_get_lhs(oldstmt);
113096 + break;
113097 + default:
113098 + debug_gimple_stmt(oldstmt);
113099 + gcc_unreachable();
113100 + }
113101 +
113102 + gsi = gsi_for_stmt(oldstmt);
113103 + pointer_set_insert(visited, oldstmt);
113104 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
113105 + basic_block next_bb, cur_bb;
113106 + const_edge e;
113107 +
113108 + gcc_assert(before == false);
113109 + gcc_assert(stmt_can_throw_internal(oldstmt));
113110 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
113111 + gcc_assert(!gsi_end_p(gsi));
113112 +
113113 + cur_bb = gimple_bb(oldstmt);
113114 + next_bb = cur_bb->next_bb;
113115 + e = find_edge(cur_bb, next_bb);
113116 + gcc_assert(e != NULL);
113117 + gcc_assert(e->flags & EDGE_FALLTHRU);
113118 +
113119 + gsi = gsi_after_labels(next_bb);
113120 + gcc_assert(!gsi_end_p(gsi));
113121 +
113122 + before = true;
113123 + oldstmt = gsi_stmt(gsi);
113124 + }
113125 +
113126 + new_lhs = cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
113127 + return new_lhs;
113128 +}
113129 +
113130 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
113131 +{
113132 + gimple stmt;
113133 + gimple_stmt_iterator gsi;
113134 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
113135 +
113136 + if (gimple_plf(oldstmt, MY_STMT))
113137 + return lhs;
113138 +
113139 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
113140 + rhs1 = gimple_assign_rhs1(oldstmt);
113141 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
113142 + }
113143 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
113144 + rhs2 = gimple_assign_rhs2(oldstmt);
113145 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
113146 + }
113147 +
113148 + stmt = gimple_copy(oldstmt);
113149 + gimple_set_location(stmt, gimple_location(oldstmt));
113150 + gimple_set_plf(stmt, MY_STMT, true);
113151 +
113152 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
113153 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
113154 +
113155 + size_overflow_type = get_size_overflow_type(oldstmt, node);
113156 +
113157 + new_var = create_new_var(size_overflow_type);
113158 + new_var = make_ssa_name(new_var, stmt);
113159 + gimple_assign_set_lhs(stmt, new_var);
113160 +
113161 + if (rhs1 != NULL_TREE)
113162 + gimple_assign_set_rhs1(stmt, rhs1);
113163 +
113164 + if (rhs2 != NULL_TREE)
113165 + gimple_assign_set_rhs2(stmt, rhs2);
113166 +#if BUILDING_GCC_VERSION >= 4006
113167 + if (rhs3 != NULL_TREE)
113168 + gimple_assign_set_rhs3(stmt, rhs3);
113169 +#endif
113170 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
113171 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
113172 +
113173 + gsi = gsi_for_stmt(oldstmt);
113174 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
113175 + update_stmt(stmt);
113176 + pointer_set_insert(visited, oldstmt);
113177 + return gimple_assign_lhs(stmt);
113178 +}
113179 +
113180 +static tree cast_parm_decl(tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
113181 +{
113182 + gimple assign;
113183 + gimple_stmt_iterator gsi;
113184 + basic_block first_bb;
113185 +
113186 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
113187 +
113188 + if (bb->index == 0) {
113189 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
113190 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
113191 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
113192 + bb = first_bb;
113193 + }
113194 +
113195 + gsi = gsi_after_labels(bb);
113196 + assign = build_cast_stmt(size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
113197 + gimple_set_plf(assign, MY_STMT, true);
113198 +
113199 + return gimple_assign_lhs(assign);
113200 +}
113201 +
113202 +static tree use_phi_ssa_name(tree ssa_name_var, tree new_arg)
113203 +{
113204 + gimple_stmt_iterator gsi;
113205 + gimple assign, def_stmt = get_def_stmt(new_arg);
113206 +
113207 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
113208 + gsi = gsi_after_labels(gimple_bb(def_stmt));
113209 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
113210 + } else {
113211 + gsi = gsi_for_stmt(def_stmt);
113212 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
113213 + }
113214 +
113215 + gimple_set_plf(assign, MY_STMT, true);
113216 + return gimple_assign_lhs(assign);
113217 +}
113218 +
113219 +static tree cast_visited_phi_arg(tree ssa_name_var, tree arg, tree size_overflow_type)
113220 +{
113221 + basic_block bb;
113222 + gimple_stmt_iterator gsi;
113223 + const_gimple def_stmt;
113224 + gimple assign;
113225 +
113226 + def_stmt = get_def_stmt(arg);
113227 + bb = gimple_bb(def_stmt);
113228 + gcc_assert(bb->index != 0);
113229 + gsi = gsi_after_labels(bb);
113230 +
113231 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
113232 + gimple_set_plf(assign, MY_STMT, true);
113233 + return gimple_assign_lhs(assign);
113234 +}
113235 +
113236 +static tree create_new_phi_arg(tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
113237 +{
113238 + tree size_overflow_type;
113239 + tree arg;
113240 + const_gimple def_stmt;
113241 +
113242 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
113243 + return new_arg;
113244 +
113245 + arg = gimple_phi_arg_def(oldstmt, i);
113246 + def_stmt = get_def_stmt(arg);
113247 + gcc_assert(def_stmt != NULL);
113248 + size_overflow_type = get_size_overflow_type(oldstmt, arg);
113249 +
113250 + switch (gimple_code(def_stmt)) {
113251 + case GIMPLE_PHI:
113252 + return cast_visited_phi_arg(ssa_name_var, arg, size_overflow_type);
113253 + case GIMPLE_NOP: {
113254 + basic_block bb;
113255 +
113256 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
113257 + return cast_parm_decl(ssa_name_var, arg, size_overflow_type, bb);
113258 + }
113259 + case GIMPLE_ASM: {
113260 + gimple_stmt_iterator gsi;
113261 + gimple assign, stmt = get_def_stmt(arg);
113262 +
113263 + gsi = gsi_for_stmt(stmt);
113264 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
113265 + gimple_set_plf(assign, MY_STMT, true);
113266 + return gimple_assign_lhs(assign);
113267 + }
113268 + default:
113269 + gcc_assert(new_arg != NULL_TREE);
113270 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
113271 + return use_phi_ssa_name(ssa_name_var, new_arg);
113272 + }
113273 +}
113274 +
113275 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
113276 +{
113277 + basic_block bb;
113278 + gimple phi;
113279 + gimple_seq seq;
113280 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
113281 +
113282 + bb = gsi_bb(gsi);
113283 +
113284 + if (result == NULL_TREE) {
113285 + tree old_result = gimple_phi_result(oldstmt);
113286 + tree size_overflow_type = get_size_overflow_type(oldstmt, old_result);
113287 +
113288 + result = create_new_var(size_overflow_type);
113289 + }
113290 +
113291 + phi = create_phi_node(result, bb);
113292 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
113293 + seq = phi_nodes(bb);
113294 + gsi = gsi_last(seq);
113295 + gsi_remove(&gsi, false);
113296 +
113297 + gsi = gsi_for_stmt(oldstmt);
113298 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
113299 + gimple_set_bb(phi, bb);
113300 + gimple_set_plf(phi, MY_STMT, true);
113301 + return phi;
113302 +}
113303 +
113304 +#if BUILDING_GCC_VERSION <= 4007
113305 +static tree create_new_phi_node(VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
113306 +#else
113307 +static tree create_new_phi_node(vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
113308 +#endif
113309 +{
113310 + gimple new_phi;
113311 + unsigned int i;
113312 + tree arg, result;
113313 + location_t loc = gimple_location(oldstmt);
113314 +
113315 +#if BUILDING_GCC_VERSION <= 4007
113316 + gcc_assert(!VEC_empty(tree, *args));
113317 +#else
113318 + gcc_assert(!args->is_empty());
113319 +#endif
113320 +
113321 + new_phi = overflow_create_phi_node(oldstmt, ssa_name_var);
113322 + result = gimple_phi_result(new_phi);
113323 + ssa_name_var = SSA_NAME_VAR(result);
113324 +
113325 +#if BUILDING_GCC_VERSION <= 4007
113326 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
113327 +#else
113328 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
113329 +#endif
113330 + arg = create_new_phi_arg(ssa_name_var, arg, oldstmt, i);
113331 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
113332 + }
113333 +
113334 +#if BUILDING_GCC_VERSION <= 4007
113335 + VEC_free(tree, heap, *args);
113336 +#else
113337 + vec_free(args);
113338 +#endif
113339 + update_stmt(new_phi);
113340 + return result;
113341 +}
113342 +
113343 +static tree handle_phi(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree orig_result)
113344 +{
113345 + tree ssa_name_var = NULL_TREE;
113346 +#if BUILDING_GCC_VERSION <= 4007
113347 + VEC(tree, heap) *args = NULL;
113348 +#else
113349 + vec<tree, va_heap, vl_embed> *args = NULL;
113350 +#endif
113351 + gimple oldstmt = get_def_stmt(orig_result);
113352 + unsigned int i, len = gimple_phi_num_args(oldstmt);
113353 +
113354 + pointer_set_insert(visited, oldstmt);
113355 + for (i = 0; i < len; i++) {
113356 + tree arg, new_arg;
113357 +
113358 + arg = gimple_phi_arg_def(oldstmt, i);
113359 + new_arg = expand(visited, caller_node, arg);
113360 +
113361 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
113362 + ssa_name_var = SSA_NAME_VAR(new_arg);
113363 +
113364 + if (is_gimple_constant(arg)) {
113365 + tree size_overflow_type = get_size_overflow_type(oldstmt, arg);
113366 +
113367 + new_arg = cast_a_tree(size_overflow_type, arg);
113368 + }
113369 +
113370 +#if BUILDING_GCC_VERSION <= 4007
113371 + VEC_safe_push(tree, heap, args, new_arg);
113372 +#else
113373 + vec_safe_push(args, new_arg);
113374 +#endif
113375 + }
113376 +
113377 +#if BUILDING_GCC_VERSION <= 4007
113378 + return create_new_phi_node(&args, ssa_name_var, oldstmt);
113379 +#else
113380 + return create_new_phi_node(args, ssa_name_var, oldstmt);
113381 +#endif
113382 +}
113383 +
113384 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
113385 +{
113386 + gimple assign;
113387 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113388 + tree origtype = TREE_TYPE(orig_rhs);
113389 +
113390 + gcc_assert(is_gimple_assign(stmt));
113391 +
113392 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113393 + gimple_set_plf(assign, MY_STMT, true);
113394 + return gimple_assign_lhs(assign);
113395 +}
113396 +
113397 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
113398 +{
113399 + const_tree rhs1, lhs, rhs1_type, lhs_type;
113400 + enum machine_mode lhs_mode, rhs_mode;
113401 + gimple def_stmt = get_def_stmt(no_const_rhs);
113402 +
113403 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113404 + return false;
113405 +
113406 + rhs1 = gimple_assign_rhs1(def_stmt);
113407 + lhs = gimple_assign_lhs(def_stmt);
113408 + rhs1_type = TREE_TYPE(rhs1);
113409 + lhs_type = TREE_TYPE(lhs);
113410 + rhs_mode = TYPE_MODE(rhs1_type);
113411 + lhs_mode = TYPE_MODE(lhs_type);
113412 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
113413 + return false;
113414 +
113415 + return true;
113416 +}
113417 +
113418 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
113419 +{
113420 + tree rhs1 = gimple_assign_rhs1(stmt);
113421 + tree lhs = gimple_assign_lhs(stmt);
113422 + const_tree rhs1_type = TREE_TYPE(rhs1);
113423 + const_tree lhs_type = TREE_TYPE(lhs);
113424 +
113425 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
113426 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113427 +
113428 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
113429 +}
113430 +
113431 +static bool no_uses(tree node)
113432 +{
113433 + imm_use_iterator imm_iter;
113434 + use_operand_p use_p;
113435 +
113436 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
113437 + const_gimple use_stmt = USE_STMT(use_p);
113438 +
113439 + if (use_stmt == NULL)
113440 + return true;
113441 + if (is_gimple_debug(use_stmt))
113442 + continue;
113443 + return false;
113444 + }
113445 + return true;
113446 +}
113447 +
113448 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
113449 +static bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
113450 +{
113451 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
113452 + gimple def_stmt = get_def_stmt(lhs);
113453 +
113454 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113455 + return false;
113456 +
113457 + rhs1 = gimple_assign_rhs1(def_stmt);
113458 + rhs_type = TREE_TYPE(rhs1);
113459 + lhs_type = TREE_TYPE(lhs);
113460 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
113461 + return false;
113462 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
113463 + return false;
113464 +
113465 + def_stmt = get_def_stmt(rhs1);
113466 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
113467 + return false;
113468 +
113469 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
113470 + return false;
113471 +
113472 + rhs1 = gimple_assign_rhs1(def_stmt);
113473 + rhs2 = gimple_assign_rhs2(def_stmt);
113474 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
113475 + return false;
113476 +
113477 + if (is_gimple_constant(rhs2))
113478 + not_const_rhs = rhs1;
113479 + else
113480 + not_const_rhs = rhs2;
113481 +
113482 + return no_uses(not_const_rhs);
113483 +}
113484 +
113485 +static bool skip_lhs_cast_check(const_gimple stmt)
113486 +{
113487 + const_tree rhs = gimple_assign_rhs1(stmt);
113488 + const_gimple def_stmt = get_def_stmt(rhs);
113489 +
113490 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
113491 + if (gimple_code(def_stmt) == GIMPLE_ASM)
113492 + return true;
113493 +
113494 + if (is_const_plus_unsigned_signed_truncation(rhs))
113495 + return true;
113496 +
113497 + return false;
113498 +}
113499 +
113500 +static tree create_cast_overflow_check(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
113501 +{
113502 + bool cast_lhs, cast_rhs;
113503 + tree lhs = gimple_assign_lhs(stmt);
113504 + tree rhs = gimple_assign_rhs1(stmt);
113505 + const_tree lhs_type = TREE_TYPE(lhs);
113506 + const_tree rhs_type = TREE_TYPE(rhs);
113507 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
113508 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
113509 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
113510 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
113511 +
113512 + static bool check_lhs[3][4] = {
113513 + // ss su us uu
113514 + { false, true, true, false }, // lhs > rhs
113515 + { false, false, false, false }, // lhs = rhs
113516 + { true, true, true, true }, // lhs < rhs
113517 + };
113518 +
113519 + static bool check_rhs[3][4] = {
113520 + // ss su us uu
113521 + { true, false, true, true }, // lhs > rhs
113522 + { true, false, true, true }, // lhs = rhs
113523 + { true, false, true, true }, // lhs < rhs
113524 + };
113525 +
113526 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
113527 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
113528 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113529 +
113530 + if (lhs_size > rhs_size) {
113531 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113532 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113533 + } else if (lhs_size == rhs_size) {
113534 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113535 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113536 + } else {
113537 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113538 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113539 + }
113540 +
113541 + if (!cast_lhs && !cast_rhs)
113542 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
113543 +
113544 + if (cast_lhs && !skip_lhs_cast_check(stmt))
113545 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
113546 +
113547 + if (cast_rhs)
113548 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
113549 +
113550 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
113551 +}
113552 +
113553 +static tree handle_unary_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
113554 +{
113555 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
113556 +
113557 + if (gimple_plf(stmt, MY_STMT))
113558 + return lhs;
113559 +
113560 + rhs1 = gimple_assign_rhs1(stmt);
113561 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
113562 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113563 +
113564 + new_rhs1 = expand(visited, caller_node, rhs1);
113565 +
113566 + if (new_rhs1 == NULL_TREE)
113567 + return create_cast_assign(visited, stmt);
113568 +
113569 + if (gimple_plf(stmt, NO_CAST_CHECK))
113570 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
113571 +
113572 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
113573 + tree size_overflow_type = get_size_overflow_type(stmt, rhs1);
113574 +
113575 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
113576 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
113577 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113578 + }
113579 +
113580 + if (!gimple_assign_cast_p(stmt))
113581 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
113582 +
113583 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
113584 +}
113585 +
113586 +static tree handle_unary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
113587 +{
113588 + tree rhs1, lhs = gimple_assign_lhs(stmt);
113589 + gimple def_stmt = get_def_stmt(lhs);
113590 +
113591 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
113592 + rhs1 = gimple_assign_rhs1(def_stmt);
113593 +
113594 + if (is_gimple_constant(rhs1))
113595 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
113596 +
113597 + switch (TREE_CODE(rhs1)) {
113598 + case SSA_NAME:
113599 + return handle_unary_rhs(visited, caller_node, def_stmt);
113600 + case ARRAY_REF:
113601 + case BIT_FIELD_REF:
113602 + case ADDR_EXPR:
113603 + case COMPONENT_REF:
113604 + case INDIRECT_REF:
113605 +#if BUILDING_GCC_VERSION >= 4006
113606 + case MEM_REF:
113607 +#endif
113608 + case TARGET_MEM_REF:
113609 + case VIEW_CONVERT_EXPR:
113610 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
113611 + case PARM_DECL:
113612 + case VAR_DECL:
113613 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113614 +
113615 + default:
113616 + debug_gimple_stmt(def_stmt);
113617 + debug_tree(rhs1);
113618 + gcc_unreachable();
113619 + }
113620 +}
113621 +
113622 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
113623 +{
113624 + gimple cond_stmt;
113625 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
113626 +
113627 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
113628 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
113629 + update_stmt(cond_stmt);
113630 +}
113631 +
113632 +static tree create_string_param(tree string)
113633 +{
113634 + tree i_type, a_type;
113635 + const int length = TREE_STRING_LENGTH(string);
113636 +
113637 + gcc_assert(length > 0);
113638 +
113639 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
113640 + a_type = build_array_type(char_type_node, i_type);
113641 +
113642 + TREE_TYPE(string) = a_type;
113643 + TREE_CONSTANT(string) = 1;
113644 + TREE_READONLY(string) = 1;
113645 +
113646 + return build1(ADDR_EXPR, ptr_type_node, string);
113647 +}
113648 +
113649 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
113650 +{
113651 + gimple func_stmt;
113652 + const_gimple def_stmt;
113653 + const_tree loc_line;
113654 + tree loc_file, ssa_name, current_func;
113655 + expanded_location xloc;
113656 + char *ssa_name_buf;
113657 + int len;
113658 + struct cgraph_edge *edge;
113659 + struct cgraph_node *callee_node;
113660 + int frequency;
113661 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
113662 +
113663 + def_stmt = get_def_stmt(arg);
113664 + xloc = expand_location(gimple_location(def_stmt));
113665 +
113666 + if (!gimple_has_location(def_stmt)) {
113667 + xloc = expand_location(gimple_location(stmt));
113668 + if (!gimple_has_location(stmt))
113669 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
113670 + }
113671 +
113672 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
113673 +
113674 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
113675 + loc_file = create_string_param(loc_file);
113676 +
113677 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
113678 + current_func = create_string_param(current_func);
113679 +
113680 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
113681 + call_count++;
113682 + 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);
113683 + gcc_assert(len > 0);
113684 + ssa_name = build_string(len + 1, ssa_name_buf);
113685 + free(ssa_name_buf);
113686 + ssa_name = create_string_param(ssa_name);
113687 +
113688 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
113689 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
113690 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
113691 +
113692 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
113693 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
113694 +
113695 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
113696 + gcc_assert(edge != NULL);
113697 +}
113698 +
113699 +static void __unused print_the_code_insertions(const_gimple stmt)
113700 +{
113701 + location_t loc = gimple_location(stmt);
113702 +
113703 + inform(loc, "Integer size_overflow check applied here.");
113704 +}
113705 +
113706 +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)
113707 +{
113708 + basic_block cond_bb, join_bb, bb_true;
113709 + edge e;
113710 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113711 +
113712 + cond_bb = gimple_bb(stmt);
113713 + if (before)
113714 + gsi_prev(&gsi);
113715 + if (gsi_end_p(gsi))
113716 + e = split_block_after_labels(cond_bb);
113717 + else
113718 + e = split_block(cond_bb, gsi_stmt(gsi));
113719 + cond_bb = e->src;
113720 + join_bb = e->dest;
113721 + e->flags = EDGE_FALSE_VALUE;
113722 + e->probability = REG_BR_PROB_BASE;
113723 +
113724 + bb_true = create_empty_bb(cond_bb);
113725 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
113726 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
113727 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
113728 +
113729 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
113730 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
113731 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
113732 +
113733 + if (current_loops != NULL) {
113734 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
113735 + add_bb_to_loop(bb_true, cond_bb->loop_father);
113736 + }
113737 +
113738 + insert_cond(cond_bb, arg, cond_code, type_value);
113739 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
113740 +
113741 +// print_the_code_insertions(stmt);
113742 +}
113743 +
113744 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
113745 +{
113746 + const_tree rhs_type = TREE_TYPE(rhs);
113747 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
113748 +
113749 + gcc_assert(rhs_type != NULL_TREE);
113750 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
113751 + return;
113752 +
113753 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
113754 +
113755 + if (is_const_plus_unsigned_signed_truncation(rhs))
113756 + return;
113757 +
113758 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
113759 + // typemax (-1) < typemin (0)
113760 + if (TREE_OVERFLOW(type_max))
113761 + return;
113762 +
113763 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
113764 +
113765 + cast_rhs_type = TREE_TYPE(cast_rhs);
113766 + type_max_type = TREE_TYPE(type_max);
113767 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
113768 +
113769 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
113770 +
113771 + // special case: get_size_overflow_type(), 32, u64->s
113772 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
113773 + return;
113774 +
113775 + type_min_type = TREE_TYPE(type_min);
113776 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
113777 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
113778 +}
113779 +
113780 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
113781 +{
113782 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
113783 + return false;
113784 + if (!is_gimple_constant(rhs))
113785 + return false;
113786 + return true;
113787 +}
113788 +
113789 +static tree get_def_stmt_rhs(const_tree var)
113790 +{
113791 + tree rhs1, def_stmt_rhs1;
113792 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
113793 +
113794 + def_stmt = get_def_stmt(var);
113795 + if (!gimple_assign_cast_p(def_stmt))
113796 + return NULL_TREE;
113797 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
113798 +
113799 + rhs1 = gimple_assign_rhs1(def_stmt);
113800 + rhs1_def_stmt = get_def_stmt(rhs1);
113801 + if (!gimple_assign_cast_p(rhs1_def_stmt))
113802 + return rhs1;
113803 +
113804 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
113805 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
113806 +
113807 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
113808 + case GIMPLE_CALL:
113809 + case GIMPLE_NOP:
113810 + case GIMPLE_ASM:
113811 + case GIMPLE_PHI:
113812 + return def_stmt_rhs1;
113813 + case GIMPLE_ASSIGN:
113814 + return rhs1;
113815 + default:
113816 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
113817 + gcc_unreachable();
113818 + }
113819 +}
113820 +
113821 +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)
113822 +{
113823 + tree new_rhs, orig_rhs;
113824 + void (*gimple_assign_set_rhs)(gimple, tree);
113825 + tree rhs1 = gimple_assign_rhs1(stmt);
113826 + tree rhs2 = gimple_assign_rhs2(stmt);
113827 + tree lhs = gimple_assign_lhs(stmt);
113828 +
113829 + if (!check_overflow)
113830 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113831 +
113832 + if (change_rhs == NULL_TREE)
113833 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113834 +
113835 + if (new_rhs2 == NULL_TREE) {
113836 + orig_rhs = rhs1;
113837 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
113838 + } else {
113839 + orig_rhs = rhs2;
113840 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
113841 + }
113842 +
113843 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
113844 +
113845 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
113846 + gimple_assign_set_rhs(stmt, new_rhs);
113847 + update_stmt(stmt);
113848 +
113849 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113850 +}
113851 +
113852 +static bool is_subtraction_special(const_gimple stmt)
113853 +{
113854 + gimple rhs1_def_stmt, rhs2_def_stmt;
113855 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
113856 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
113857 + const_tree rhs1 = gimple_assign_rhs1(stmt);
113858 + const_tree rhs2 = gimple_assign_rhs2(stmt);
113859 +
113860 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
113861 + return false;
113862 +
113863 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
113864 +
113865 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
113866 + return false;
113867 +
113868 + rhs1_def_stmt = get_def_stmt(rhs1);
113869 + rhs2_def_stmt = get_def_stmt(rhs2);
113870 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
113871 + return false;
113872 +
113873 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
113874 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
113875 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
113876 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
113877 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
113878 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
113879 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
113880 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
113881 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
113882 + return false;
113883 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
113884 + return false;
113885 +
113886 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
113887 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
113888 + return true;
113889 +}
113890 +
113891 +static tree handle_integer_truncation(struct pointer_set_t *visited, struct cgraph_node *caller_node, const_tree lhs)
113892 +{
113893 + tree new_rhs1, new_rhs2;
113894 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
113895 + gimple assign, stmt = get_def_stmt(lhs);
113896 + tree rhs1 = gimple_assign_rhs1(stmt);
113897 + tree rhs2 = gimple_assign_rhs2(stmt);
113898 +
113899 + if (!is_subtraction_special(stmt))
113900 + return NULL_TREE;
113901 +
113902 + new_rhs1 = expand(visited, caller_node, rhs1);
113903 + new_rhs2 = expand(visited, caller_node, rhs2);
113904 +
113905 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
113906 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
113907 +
113908 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
113909 + return NULL_TREE;
113910 +
113911 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
113912 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
113913 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
113914 + }
113915 +
113916 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
113917 + new_lhs = gimple_assign_lhs(assign);
113918 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
113919 +
113920 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
113921 +}
113922 +
113923 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
113924 +{
113925 + const_gimple def_stmt;
113926 +
113927 + if (TREE_CODE(rhs) != SSA_NAME)
113928 + return false;
113929 +
113930 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
113931 + return false;
113932 +
113933 + def_stmt = get_def_stmt(rhs);
113934 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
113935 + return false;
113936 +
113937 + return true;
113938 +}
113939 +
113940 +static tree handle_binary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
113941 +{
113942 + tree rhs1, rhs2, new_lhs;
113943 + gimple def_stmt = get_def_stmt(lhs);
113944 + tree new_rhs1 = NULL_TREE;
113945 + tree new_rhs2 = NULL_TREE;
113946 +
113947 + rhs1 = gimple_assign_rhs1(def_stmt);
113948 + rhs2 = gimple_assign_rhs2(def_stmt);
113949 +
113950 + /* no DImode/TImode division in the 32/64 bit kernel */
113951 + switch (gimple_assign_rhs_code(def_stmt)) {
113952 + case RDIV_EXPR:
113953 + case TRUNC_DIV_EXPR:
113954 + case CEIL_DIV_EXPR:
113955 + case FLOOR_DIV_EXPR:
113956 + case ROUND_DIV_EXPR:
113957 + case TRUNC_MOD_EXPR:
113958 + case CEIL_MOD_EXPR:
113959 + case FLOOR_MOD_EXPR:
113960 + case ROUND_MOD_EXPR:
113961 + case EXACT_DIV_EXPR:
113962 + case POINTER_PLUS_EXPR:
113963 + case BIT_AND_EXPR:
113964 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
113965 + default:
113966 + break;
113967 + }
113968 +
113969 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
113970 + if (new_lhs != NULL_TREE)
113971 + return new_lhs;
113972 +
113973 + if (TREE_CODE(rhs1) == SSA_NAME)
113974 + new_rhs1 = expand(visited, caller_node, rhs1);
113975 + if (TREE_CODE(rhs2) == SSA_NAME)
113976 + new_rhs2 = expand(visited, caller_node, rhs2);
113977 +
113978 + if (is_a_neg_overflow(def_stmt, rhs2))
113979 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
113980 + if (is_a_neg_overflow(def_stmt, rhs1))
113981 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
113982 +
113983 +
113984 + if (is_a_constant_overflow(def_stmt, rhs2))
113985 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
113986 + if (is_a_constant_overflow(def_stmt, rhs1))
113987 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
113988 +
113989 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
113990 +}
113991 +
113992 +#if BUILDING_GCC_VERSION >= 4006
113993 +static tree get_new_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
113994 +{
113995 + if (is_gimple_constant(rhs))
113996 + return cast_a_tree(size_overflow_type, rhs);
113997 + if (TREE_CODE(rhs) != SSA_NAME)
113998 + return NULL_TREE;
113999 + return expand(visited, caller_node, rhs);
114000 +}
114001 +
114002 +static tree handle_ternary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
114003 +{
114004 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
114005 + gimple def_stmt = get_def_stmt(lhs);
114006 +
114007 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
114008 +
114009 + rhs1 = gimple_assign_rhs1(def_stmt);
114010 + rhs2 = gimple_assign_rhs2(def_stmt);
114011 + rhs3 = gimple_assign_rhs3(def_stmt);
114012 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
114013 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
114014 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
114015 +
114016 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
114017 +}
114018 +#endif
114019 +
114020 +static tree get_size_overflow_type(gimple stmt, const_tree node)
114021 +{
114022 + const_tree type;
114023 + tree new_type;
114024 +
114025 + gcc_assert(node != NULL_TREE);
114026 +
114027 + type = TREE_TYPE(node);
114028 +
114029 + if (gimple_plf(stmt, MY_STMT))
114030 + return TREE_TYPE(node);
114031 +
114032 + switch (TYPE_MODE(type)) {
114033 + case QImode:
114034 + new_type = intHI_type_node;
114035 + break;
114036 + case HImode:
114037 + new_type = intSI_type_node;
114038 + break;
114039 + case SImode:
114040 + new_type = intDI_type_node;
114041 + break;
114042 + case DImode:
114043 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
114044 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
114045 + else
114046 + new_type = intTI_type_node;
114047 + break;
114048 + case TImode:
114049 + gcc_assert(!TYPE_UNSIGNED(type));
114050 + new_type = intTI_type_node;
114051 + break;
114052 + default:
114053 + debug_tree((tree)node);
114054 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
114055 + gcc_unreachable();
114056 + }
114057 +
114058 + if (TYPE_QUALS(type) != 0)
114059 + return build_qualified_type(new_type, TYPE_QUALS(type));
114060 + return new_type;
114061 +}
114062 +
114063 +static tree expand_visited(gimple def_stmt)
114064 +{
114065 + const_gimple next_stmt;
114066 + gimple_stmt_iterator gsi;
114067 + enum gimple_code code = gimple_code(def_stmt);
114068 +
114069 + if (code == GIMPLE_ASM)
114070 + return NULL_TREE;
114071 +
114072 + gsi = gsi_for_stmt(def_stmt);
114073 + gsi_next(&gsi);
114074 +
114075 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
114076 + return NULL_TREE;
114077 + gcc_assert(!gsi_end_p(gsi));
114078 + next_stmt = gsi_stmt(gsi);
114079 +
114080 + if (gimple_code(def_stmt) == GIMPLE_PHI && !gimple_plf((gimple)next_stmt, MY_STMT))
114081 + return NULL_TREE;
114082 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
114083 +
114084 + return get_lhs(next_stmt);
114085 +}
114086 +
114087 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
114088 +{
114089 + gimple def_stmt;
114090 +
114091 + def_stmt = get_def_stmt(lhs);
114092 +
114093 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
114094 + return NULL_TREE;
114095 +
114096 + if (gimple_plf(def_stmt, MY_STMT))
114097 + return lhs;
114098 +
114099 + if (pointer_set_contains(visited, def_stmt))
114100 + return expand_visited(def_stmt);
114101 +
114102 + switch (gimple_code(def_stmt)) {
114103 + case GIMPLE_PHI:
114104 + return handle_phi(visited, caller_node, lhs);
114105 + case GIMPLE_CALL:
114106 + case GIMPLE_ASM:
114107 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
114108 + case GIMPLE_ASSIGN:
114109 + switch (gimple_num_ops(def_stmt)) {
114110 + case 2:
114111 + return handle_unary_ops(visited, caller_node, def_stmt);
114112 + case 3:
114113 + return handle_binary_ops(visited, caller_node, lhs);
114114 +#if BUILDING_GCC_VERSION >= 4006
114115 + case 4:
114116 + return handle_ternary_ops(visited, caller_node, lhs);
114117 +#endif
114118 + }
114119 + default:
114120 + debug_gimple_stmt(def_stmt);
114121 + error("%s: unknown gimple code", __func__);
114122 + gcc_unreachable();
114123 + }
114124 +}
114125 +
114126 +static tree cast_to_orig_type(gimple stmt, const_tree orig_node, tree new_node)
114127 +{
114128 + const_gimple assign;
114129 + tree orig_type = TREE_TYPE(orig_node);
114130 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114131 +
114132 + assign = build_cast_stmt(orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114133 + return gimple_assign_lhs(assign);
114134 +}
114135 +
114136 +static void change_orig_node(struct interesting_node *cur_node, tree new_node)
114137 +{
114138 + void (*set_rhs)(gimple, tree);
114139 + gimple stmt = cur_node->first_stmt;
114140 + const_tree orig_node = cur_node->node;
114141 +
114142 + switch (gimple_code(stmt)) {
114143 + case GIMPLE_RETURN:
114144 + gimple_return_set_retval(stmt, cast_to_orig_type(stmt, orig_node, new_node));
114145 + break;
114146 + case GIMPLE_CALL:
114147 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(stmt, orig_node, new_node));
114148 + break;
114149 + case GIMPLE_ASSIGN:
114150 + switch (cur_node->num) {
114151 + case 1:
114152 + set_rhs = &gimple_assign_set_rhs1;
114153 + break;
114154 + case 2:
114155 + set_rhs = &gimple_assign_set_rhs2;
114156 + break;
114157 +#if BUILDING_GCC_VERSION >= 4006
114158 + case 3:
114159 + set_rhs = &gimple_assign_set_rhs3;
114160 + break;
114161 +#endif
114162 + default:
114163 + gcc_unreachable();
114164 + }
114165 +
114166 + set_rhs(stmt, cast_to_orig_type(stmt, orig_node, new_node));
114167 + break;
114168 + default:
114169 + debug_gimple_stmt(stmt);
114170 + gcc_unreachable();
114171 + }
114172 +
114173 + update_stmt(stmt);
114174 +}
114175 +
114176 +static unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
114177 +{
114178 + const struct size_overflow_hash *hash;
114179 + unsigned int new_argnum;
114180 + tree arg;
114181 + const_tree origarg;
114182 +
114183 + if (argnum == 0)
114184 + return argnum;
114185 +
114186 + hash = get_function_hash(fndecl);
114187 + if (hash && hash->param & (1U << argnum))
114188 + return argnum;
114189 +
114190 + if (DECL_EXTERNAL(fndecl))
114191 + return argnum;
114192 +
114193 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
114194 + argnum--;
114195 + while (origarg && argnum) {
114196 + origarg = TREE_CHAIN(origarg);
114197 + argnum--;
114198 + }
114199 + gcc_assert(argnum == 0);
114200 + gcc_assert(origarg != NULL_TREE);
114201 +
114202 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
114203 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
114204 + return new_argnum;
114205 +
114206 + return CANNOT_FIND_ARG;
114207 +}
114208 +
114209 +// Don't want to duplicate entries in next_cgraph_node
114210 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
114211 +{
114212 + const_tree new_callee_fndecl;
114213 + struct next_cgraph_node *cur_node;
114214 +
114215 + if (fndecl == RET_CHECK)
114216 + new_callee_fndecl = NODE_DECL(node);
114217 + else
114218 + new_callee_fndecl = fndecl;
114219 +
114220 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
114221 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
114222 + continue;
114223 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
114224 + continue;
114225 + if (num == cur_node->num)
114226 + return true;
114227 + }
114228 + return false;
114229 +}
114230 +
114231 +/* Add a next_cgraph_node into the list for handle_function().
114232 + * handle_function() iterates over all the next cgraph nodes and
114233 + * starts the overflow check insertion process.
114234 + */
114235 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
114236 +{
114237 + struct next_cgraph_node *new_node;
114238 +
114239 + if (is_in_next_cgraph_node(head, node, fndecl, num))
114240 + return head;
114241 +
114242 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
114243 + new_node->current_function = node;
114244 + new_node->next = NULL;
114245 + new_node->num = num;
114246 + if (fndecl == RET_CHECK)
114247 + new_node->callee_fndecl = NODE_DECL(node);
114248 + else
114249 + new_node->callee_fndecl = fndecl;
114250 +
114251 + if (!head)
114252 + return new_node;
114253 +
114254 + new_node->next = head;
114255 + return new_node;
114256 +}
114257 +
114258 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
114259 +{
114260 + struct cgraph_edge *e;
114261 +
114262 + if (num == 0)
114263 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
114264 +
114265 + for (e = node->callers; e; e = e->next_caller) {
114266 + tree fndecl = gimple_call_fndecl(e->call_stmt);
114267 +
114268 + gcc_assert(fndecl != NULL_TREE);
114269 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
114270 + }
114271 +
114272 + return head;
114273 +}
114274 +
114275 +static bool is_a_return_check(const_tree node)
114276 +{
114277 + if (TREE_CODE(node) == FUNCTION_DECL)
114278 + return true;
114279 +
114280 + gcc_assert(TREE_CODE(node) == PARM_DECL);
114281 + return false;
114282 +}
114283 +
114284 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
114285 +{
114286 + const struct size_overflow_hash *hash;
114287 +
114288 + hash = get_function_hash(fndecl);
114289 + if (hash && (hash->param & (1U << num)))
114290 + return true;
114291 + return false;
114292 +}
114293 +
114294 +struct missing_functions {
114295 + struct missing_functions *next;
114296 + const_tree node;
114297 + tree fndecl;
114298 +};
114299 +
114300 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
114301 +{
114302 + struct missing_functions *new_function;
114303 +
114304 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
114305 + new_function->node = node;
114306 + new_function->next = NULL;
114307 +
114308 + if (TREE_CODE(node) == FUNCTION_DECL)
114309 + new_function->fndecl = node;
114310 + else
114311 + new_function->fndecl = current_function_decl;
114312 + gcc_assert(new_function->fndecl);
114313 +
114314 + if (!missing_fn_head)
114315 + return new_function;
114316 +
114317 + new_function->next = missing_fn_head;
114318 + return new_function;
114319 +}
114320 +
114321 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
114322 + * If the function is missing everywhere then print the missing message into stderr.
114323 + */
114324 +static bool is_missing_function(const_tree orig_fndecl, unsigned int num)
114325 +{
114326 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
114327 +#if BUILDING_GCC_VERSION >= 4008
114328 + case BUILT_IN_BSWAP16:
114329 +#endif
114330 + case BUILT_IN_BSWAP32:
114331 + case BUILT_IN_BSWAP64:
114332 + case BUILT_IN_EXPECT:
114333 + case BUILT_IN_MEMCMP:
114334 + return false;
114335 + default:
114336 + break;
114337 + }
114338 +
114339 + // skip test.c
114340 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
114341 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
114342 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
114343 + }
114344 +
114345 + if (is_in_hash_table(orig_fndecl, num))
114346 + return false;
114347 +
114348 + print_missing_msg(orig_fndecl, num);
114349 + return true;
114350 +}
114351 +
114352 +// Get the argnum of a function decl, if node is a return then the argnum is 0
114353 +static unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
114354 +{
114355 + if (is_a_return_check(node))
114356 + return 0;
114357 + else
114358 + return find_arg_number_tree(node, orig_fndecl);
114359 +}
114360 +
114361 +/* If the function is missing from the hash table and it is a static function
114362 + * then create a next_cgraph_node from it for handle_function()
114363 + */
114364 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
114365 +{
114366 + unsigned int num;
114367 + const_tree orig_fndecl;
114368 + struct cgraph_node *next_node = NULL;
114369 +
114370 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
114371 +
114372 + num = get_function_num(missing_fn_head->node, orig_fndecl);
114373 + if (num == CANNOT_FIND_ARG)
114374 + return cnodes;
114375 +
114376 + if (!is_missing_function(orig_fndecl, num))
114377 + return cnodes;
114378 +
114379 + next_node = cgraph_get_node(missing_fn_head->fndecl);
114380 + if (next_node && next_node->local.local)
114381 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
114382 + return cnodes;
114383 +}
114384 +
114385 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
114386 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
114387 + */
114388 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
114389 +{
114390 + unsigned int i;
114391 + tree node;
114392 + struct missing_functions *cur, *missing_fn_head = NULL;
114393 +
114394 +#if BUILDING_GCC_VERSION <= 4007
114395 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
114396 +#else
114397 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
114398 +#endif
114399 + switch (TREE_CODE(node)) {
114400 + case PARM_DECL:
114401 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
114402 + break;
114403 + case FUNCTION_DECL:
114404 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
114405 + break;
114406 + default:
114407 + break;
114408 + }
114409 + }
114410 +
114411 + while (missing_fn_head) {
114412 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
114413 +
114414 + cur = missing_fn_head->next;
114415 + free(missing_fn_head);
114416 + missing_fn_head = cur;
114417 + }
114418 +
114419 + return cnodes;
114420 +}
114421 +
114422 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
114423 +{
114424 + gimple phi = get_def_stmt(result);
114425 + unsigned int i, n = gimple_phi_num_args(phi);
114426 +
114427 + pointer_set_insert(visited, phi);
114428 + for (i = 0; i < n; i++) {
114429 + const_tree arg = gimple_phi_arg_def(phi, i);
114430 +
114431 + set_conditions(visited, interesting_conditions, arg);
114432 + }
114433 +}
114434 +
114435 +enum conditions {
114436 + FROM_CONST, NOT_UNARY, CAST
114437 +};
114438 +
114439 +// Search for constants, cast assignments and binary/ternary assignments
114440 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
114441 +{
114442 + gimple def_stmt = get_def_stmt(lhs);
114443 +
114444 + if (is_gimple_constant(lhs)) {
114445 + interesting_conditions[FROM_CONST] = true;
114446 + return;
114447 + }
114448 +
114449 + if (!def_stmt)
114450 + return;
114451 +
114452 + if (pointer_set_contains(visited, def_stmt))
114453 + return;
114454 +
114455 + switch (gimple_code(def_stmt)) {
114456 + case GIMPLE_NOP:
114457 + case GIMPLE_CALL:
114458 + case GIMPLE_ASM:
114459 + return;
114460 + case GIMPLE_PHI:
114461 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
114462 + case GIMPLE_ASSIGN:
114463 + if (gimple_num_ops(def_stmt) == 2) {
114464 + const_tree rhs = gimple_assign_rhs1(def_stmt);
114465 +
114466 + if (gimple_assign_cast_p(def_stmt))
114467 + interesting_conditions[CAST] = true;
114468 +
114469 + return set_conditions(visited, interesting_conditions, rhs);
114470 + } else {
114471 + interesting_conditions[NOT_UNARY] = true;
114472 + return;
114473 + }
114474 + default:
114475 + debug_gimple_stmt(def_stmt);
114476 + gcc_unreachable();
114477 + }
114478 +}
114479 +
114480 +// determine whether duplication will be necessary or not.
114481 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
114482 +{
114483 + struct pointer_set_t *visited;
114484 +
114485 + if (gimple_assign_cast_p(cur_node->first_stmt))
114486 + interesting_conditions[CAST] = true;
114487 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
114488 + interesting_conditions[NOT_UNARY] = true;
114489 +
114490 + visited = pointer_set_create();
114491 + set_conditions(visited, interesting_conditions, cur_node->node);
114492 + pointer_set_destroy(visited);
114493 +}
114494 +
114495 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
114496 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
114497 +{
114498 + gimple assign;
114499 + gimple_stmt_iterator gsi;
114500 +
114501 + // already removed
114502 + if (gimple_bb(asm_stmt) == NULL)
114503 + return;
114504 + gsi = gsi_for_stmt(asm_stmt);
114505 +
114506 + assign = gimple_build_assign(lhs, rhs);
114507 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
114508 + SSA_NAME_DEF_STMT(lhs) = assign;
114509 +
114510 + gsi_remove(&gsi, true);
114511 +}
114512 +
114513 +// Get the field decl of a component ref for intentional_overflow checking
114514 +static const_tree search_field_decl(const_tree comp_ref)
114515 +{
114516 + const_tree field = NULL_TREE;
114517 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
114518 +
114519 + for (i = 0; i < len; i++) {
114520 + field = TREE_OPERAND(comp_ref, i);
114521 + if (TREE_CODE(field) == FIELD_DECL)
114522 + break;
114523 + }
114524 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
114525 + return field;
114526 +}
114527 +
114528 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
114529 + * stmt is a return otherwise it is the callee function.
114530 + */
114531 +static const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
114532 +{
114533 + const_tree fndecl;
114534 +
114535 + if (argnum == 0)
114536 + fndecl = current_function_decl;
114537 + else
114538 + fndecl = gimple_call_fndecl(stmt);
114539 +
114540 + if (fndecl == NULL_TREE)
114541 + return NULL_TREE;
114542 +
114543 + return DECL_ORIGIN(fndecl);
114544 +}
114545 +
114546 +/* Get the param of the intentional_overflow attribute.
114547 + * * 0: MARK_NOT_INTENTIONAL
114548 + * * 1..MAX_PARAM: MARK_YES
114549 + * * -1: MARK_TURN_OFF
114550 + */
114551 +static tree get_attribute_param(const_tree decl)
114552 +{
114553 + const_tree attr;
114554 +
114555 + if (decl == NULL_TREE)
114556 + return NULL_TREE;
114557 +
114558 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
114559 + if (!attr || !TREE_VALUE(attr))
114560 + return NULL_TREE;
114561 +
114562 + return TREE_VALUE(attr);
114563 +}
114564 +
114565 +// MARK_TURN_OFF
114566 +static bool is_turn_off_intentional_attr(const_tree decl)
114567 +{
114568 + const_tree param_head;
114569 +
114570 + param_head = get_attribute_param(decl);
114571 + if (param_head == NULL_TREE)
114572 + return false;
114573 +
114574 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
114575 + return true;
114576 + return false;
114577 +}
114578 +
114579 +// MARK_NOT_INTENTIONAL
114580 +static bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
114581 +{
114582 + const_tree param_head;
114583 +
114584 + if (argnum == 0)
114585 + return false;
114586 +
114587 + param_head = get_attribute_param(decl);
114588 + if (param_head == NULL_TREE)
114589 + return false;
114590 +
114591 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
114592 + return true;
114593 + return false;
114594 +}
114595 +
114596 +// MARK_YES
114597 +static bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
114598 +{
114599 + tree param, param_head;
114600 +
114601 + if (argnum == 0)
114602 + return false;
114603 +
114604 + param_head = get_attribute_param(decl);
114605 + for (param = param_head; param; param = TREE_CHAIN(param))
114606 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
114607 + return true;
114608 + return false;
114609 +}
114610 +
114611 +static const char *get_asm_string(const_gimple stmt)
114612 +{
114613 + if (!stmt)
114614 + return NULL;
114615 + if (gimple_code(stmt) != GIMPLE_ASM)
114616 + return NULL;
114617 +
114618 + return gimple_asm_string(stmt);
114619 +}
114620 +
114621 +static bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
114622 +{
114623 + const char *str;
114624 +
114625 + str = get_asm_string(stmt);
114626 + if (!str)
114627 + return false;
114628 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
114629 +}
114630 +
114631 +static bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
114632 +{
114633 + const char *str;
114634 +
114635 + str = get_asm_string(stmt);
114636 + if (!str)
114637 + return false;
114638 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
114639 +}
114640 +
114641 +static bool is_size_overflow_asm(const_gimple stmt)
114642 +{
114643 + const char *str;
114644 +
114645 + str = get_asm_string(stmt);
114646 + if (!str)
114647 + return false;
114648 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
114649 +}
114650 +
114651 +static void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
114652 +{
114653 + location_t loc;
114654 +
114655 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
114656 + return;
114657 +
114658 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
114659 + return;
114660 +
114661 + loc = DECL_SOURCE_LOCATION(decl);
114662 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
114663 +}
114664 +
114665 +/* Get the type of the intentional_overflow attribute of a node
114666 + * * MARK_TURN_OFF
114667 + * * MARK_YES
114668 + * * MARK_NO
114669 + * * MARK_NOT_INTENTIONAL
114670 + */
114671 +static enum mark get_intentional_attr_type(const_tree node)
114672 +{
114673 + const_tree cur_decl;
114674 +
114675 + if (node == NULL_TREE)
114676 + return MARK_NO;
114677 +
114678 + switch (TREE_CODE(node)) {
114679 + case COMPONENT_REF:
114680 + cur_decl = search_field_decl(node);
114681 + if (is_turn_off_intentional_attr(cur_decl))
114682 + return MARK_TURN_OFF;
114683 + if (is_end_intentional_intentional_attr(cur_decl, 1))
114684 + return MARK_YES;
114685 + break;
114686 + case PARM_DECL: {
114687 + unsigned int argnum;
114688 +
114689 + cur_decl = DECL_ORIGIN(current_function_decl);
114690 + argnum = find_arg_number_tree(node, cur_decl);
114691 + if (argnum == CANNOT_FIND_ARG)
114692 + return MARK_NO;
114693 + if (is_yes_intentional_attr(cur_decl, argnum))
114694 + return MARK_YES;
114695 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
114696 + return MARK_NOT_INTENTIONAL;
114697 + break;
114698 + }
114699 + case FUNCTION_DECL:
114700 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
114701 + return MARK_TURN_OFF;
114702 + break;
114703 + default:
114704 + break;
114705 + }
114706 + return MARK_NO;
114707 +}
114708 +
114709 +// Search for the intentional_overflow attribute on the last nodes
114710 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
114711 +{
114712 + unsigned int i;
114713 + tree last_node;
114714 + enum mark mark = MARK_NO;
114715 +
114716 +#if BUILDING_GCC_VERSION <= 4007
114717 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
114718 +#else
114719 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
114720 +#endif
114721 + mark = get_intentional_attr_type(last_node);
114722 + if (mark != MARK_NO)
114723 + break;
114724 + }
114725 + return mark;
114726 +}
114727 +
114728 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
114729 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
114730 + */
114731 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
114732 +{
114733 + if (!cur_node->intentional_mark_from_gimple)
114734 + return false;
114735 +
114736 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
114737 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
114738 + else
114739 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
114740 +
114741 + // skip param decls
114742 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
114743 + return true;
114744 + return true;
114745 +}
114746 +
114747 +/* Search intentional_overflow attribute on caller and on callee too.
114748 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
114749 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
114750 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
114751 +*/
114752 +static void check_intentional_attribute_ipa(struct interesting_node *cur_node)
114753 +{
114754 + const_tree fndecl;
114755 +
114756 + if (is_intentional_attribute_from_gimple(cur_node))
114757 + return;
114758 +
114759 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
114760 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
114761 + return;
114762 + }
114763 +
114764 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
114765 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
114766 + return;
114767 + }
114768 +
114769 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
114770 + return;
114771 +
114772 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
114773 + if (is_turn_off_intentional_attr(fndecl)) {
114774 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
114775 + return;
114776 + }
114777 +
114778 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
114779 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
114780 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
114781 + cur_node->intentional_attr_decl = MARK_YES;
114782 +
114783 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
114784 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
114785 +}
114786 +
114787 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
114788 +static bool skip_asm(const_tree arg)
114789 +{
114790 + gimple def_stmt = get_def_stmt(arg);
114791 +
114792 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
114793 + return false;
114794 +
114795 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
114796 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
114797 +}
114798 +
114799 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
114800 +{
114801 + gimple phi = get_def_stmt(result);
114802 + unsigned int i, n = gimple_phi_num_args(phi);
114803 +
114804 + pointer_set_insert(visited, phi);
114805 + for (i = 0; i < n; i++) {
114806 + tree arg = gimple_phi_arg_def(phi, i);
114807 +
114808 + walk_use_def(visited, cur_node, arg);
114809 + }
114810 +}
114811 +
114812 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
114813 +{
114814 + gimple def_stmt = get_def_stmt(lhs);
114815 + tree rhs1, rhs2;
114816 +
114817 + rhs1 = gimple_assign_rhs1(def_stmt);
114818 + rhs2 = gimple_assign_rhs2(def_stmt);
114819 +
114820 + walk_use_def(visited, cur_node, rhs1);
114821 + walk_use_def(visited, cur_node, rhs2);
114822 +}
114823 +
114824 +static void insert_last_node(struct interesting_node *cur_node, tree node)
114825 +{
114826 + unsigned int i;
114827 + tree element;
114828 + enum tree_code code;
114829 +
114830 + gcc_assert(node != NULL_TREE);
114831 +
114832 + if (is_gimple_constant(node))
114833 + return;
114834 +
114835 + code = TREE_CODE(node);
114836 + if (code == VAR_DECL) {
114837 + node = DECL_ORIGIN(node);
114838 + code = TREE_CODE(node);
114839 + }
114840 +
114841 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
114842 + return;
114843 +
114844 +#if BUILDING_GCC_VERSION <= 4007
114845 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
114846 +#else
114847 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
114848 +#endif
114849 + if (operand_equal_p(node, element, 0))
114850 + return;
114851 + }
114852 +
114853 +#if BUILDING_GCC_VERSION <= 4007
114854 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
114855 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
114856 +#else
114857 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
114858 + vec_safe_push(cur_node->last_nodes, node);
114859 +#endif
114860 +}
114861 +
114862 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
114863 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
114864 +{
114865 + if (!is_size_overflow_asm(stmt))
114866 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
114867 +}
114868 +
114869 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
114870 + * and component refs (for checking the intentional_overflow attribute).
114871 + */
114872 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
114873 +{
114874 + const_gimple def_stmt;
114875 +
114876 + if (TREE_CODE(lhs) != SSA_NAME) {
114877 + insert_last_node(cur_node, lhs);
114878 + return;
114879 + }
114880 +
114881 + def_stmt = get_def_stmt(lhs);
114882 + if (!def_stmt)
114883 + return;
114884 +
114885 + if (pointer_set_insert(visited, def_stmt))
114886 + return;
114887 +
114888 + switch (gimple_code(def_stmt)) {
114889 + case GIMPLE_NOP:
114890 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
114891 + case GIMPLE_ASM:
114892 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
114893 + case GIMPLE_CALL: {
114894 + tree fndecl = gimple_call_fndecl(def_stmt);
114895 +
114896 + if (fndecl == NULL_TREE)
114897 + return;
114898 + insert_last_node(cur_node, fndecl);
114899 + return;
114900 + }
114901 + case GIMPLE_PHI:
114902 + return walk_use_def_phi(visited, cur_node, lhs);
114903 + case GIMPLE_ASSIGN:
114904 + switch (gimple_num_ops(def_stmt)) {
114905 + case 2:
114906 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
114907 + case 3:
114908 + return walk_use_def_binary(visited, cur_node, lhs);
114909 + }
114910 + default:
114911 + debug_gimple_stmt((gimple)def_stmt);
114912 + error("%s: unknown gimple code", __func__);
114913 + gcc_unreachable();
114914 + }
114915 +}
114916 +
114917 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
114918 +static void set_last_nodes(struct interesting_node *cur_node)
114919 +{
114920 + struct pointer_set_t *visited;
114921 +
114922 + visited = pointer_set_create();
114923 + walk_use_def(visited, cur_node, cur_node->node);
114924 + pointer_set_destroy(visited);
114925 +}
114926 +
114927 +enum precond {
114928 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
114929 +};
114930 +
114931 +/* 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.
114932 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
114933 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
114934 + * 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.
114935 + */
114936 +static enum precond check_preconditions(struct interesting_node *cur_node)
114937 +{
114938 + bool interesting_conditions[3] = {false, false, false};
114939 +
114940 + set_last_nodes(cur_node);
114941 +
114942 + check_intentional_attribute_ipa(cur_node);
114943 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
114944 + return NO_ATTRIBUTE_SEARCH;
114945 +
114946 + search_interesting_conditions(cur_node, interesting_conditions);
114947 +
114948 + // error code
114949 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
114950 + return NO_ATTRIBUTE_SEARCH;
114951 +
114952 + // unnecessary overflow check
114953 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
114954 + return NO_CHECK_INSERT;
114955 +
114956 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
114957 + return NO_CHECK_INSERT;
114958 +
114959 + return NONE;
114960 +}
114961 +
114962 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
114963 + * 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
114964 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
114965 + */
114966 +static struct next_cgraph_node *handle_interesting_stmt(struct next_cgraph_node *cnodes, struct interesting_node *cur_node, struct cgraph_node *caller_node)
114967 +{
114968 + enum precond ret;
114969 + struct pointer_set_t *visited;
114970 + tree new_node, orig_node = cur_node->node;
114971 +
114972 + ret = check_preconditions(cur_node);
114973 + if (ret == NO_ATTRIBUTE_SEARCH)
114974 + return cnodes;
114975 +
114976 + cnodes = search_overflow_attribute(cnodes, cur_node);
114977 +
114978 + if (ret == NO_CHECK_INSERT)
114979 + return cnodes;
114980 +
114981 + visited = pointer_set_create();
114982 + new_node = expand(visited, caller_node, orig_node);
114983 + pointer_set_destroy(visited);
114984 +
114985 + if (new_node == NULL_TREE)
114986 + return cnodes;
114987 +
114988 + change_orig_node(cur_node, new_node);
114989 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
114990 +
114991 + return cnodes;
114992 +}
114993 +
114994 +// Check visited interesting nodes.
114995 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
114996 +{
114997 + struct interesting_node *cur;
114998 +
114999 + for (cur = head; cur; cur = cur->next) {
115000 + if (!operand_equal_p(node, cur->node, 0))
115001 + continue;
115002 + if (num != cur->num)
115003 + continue;
115004 + if (first_stmt == cur->first_stmt)
115005 + return true;
115006 + }
115007 + return false;
115008 +}
115009 +
115010 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
115011 + 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
115012 + 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
115013 + the intentional_overflow attribute check. They are collected by set_last_nodes().
115014 + num: arg count of a call stmt or 0 when it is a ret
115015 + node: the recursion starts from here, it is a call arg or a return value
115016 + 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.
115017 + intentional_attr_decl: intentional_overflow attribute of the callee function
115018 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
115019 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
115020 + */
115021 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
115022 +{
115023 + struct interesting_node *new_node;
115024 + tree fndecl;
115025 + enum gimple_code code;
115026 +
115027 + gcc_assert(node != NULL_TREE);
115028 + code = gimple_code(first_stmt);
115029 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
115030 +
115031 + if (num == CANNOT_FIND_ARG)
115032 + return head;
115033 +
115034 + if (skip_types(node))
115035 + return head;
115036 +
115037 + if (skip_asm(node))
115038 + return head;
115039 +
115040 + if (is_gimple_call(first_stmt))
115041 + fndecl = gimple_call_fndecl(first_stmt);
115042 + else
115043 + fndecl = current_function_decl;
115044 +
115045 + if (fndecl == NULL_TREE)
115046 + return head;
115047 +
115048 + if (is_in_interesting_node(head, first_stmt, node, num))
115049 + return head;
115050 +
115051 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
115052 +
115053 + new_node->next = NULL;
115054 + new_node->first_stmt = first_stmt;
115055 +#if BUILDING_GCC_VERSION <= 4007
115056 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
115057 +#else
115058 + vec_alloc(new_node->last_nodes, VEC_LEN);
115059 +#endif
115060 + new_node->num = num;
115061 + new_node->node = node;
115062 + new_node->fndecl = fndecl;
115063 + new_node->intentional_attr_decl = MARK_NO;
115064 + new_node->intentional_attr_cur_fndecl = MARK_NO;
115065 + new_node->intentional_mark_from_gimple = asm_stmt;
115066 +
115067 + if (!head)
115068 + return new_node;
115069 +
115070 + new_node->next = head;
115071 + return new_node;
115072 +}
115073 +
115074 +/* 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).
115075 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
115076 + */
115077 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
115078 +{
115079 + struct next_cgraph_node *cur_node;
115080 + tree ret = gimple_return_retval(stmt);
115081 +
115082 + if (ret == NULL_TREE)
115083 + return head;
115084 +
115085 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
115086 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
115087 + continue;
115088 + if (cur_node->num == 0)
115089 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
115090 + }
115091 +
115092 + return head;
115093 +}
115094 +
115095 +/* 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).
115096 + * If the call stmt is in the next cgraph node list then it's an interesting call.
115097 + */
115098 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
115099 +{
115100 + unsigned int argnum;
115101 + tree arg;
115102 + const_tree fndecl;
115103 + struct next_cgraph_node *cur_node;
115104 +
115105 + fndecl = gimple_call_fndecl(stmt);
115106 + if (fndecl == NULL_TREE)
115107 + return head;
115108 +
115109 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
115110 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
115111 + continue;
115112 + argnum = get_correct_arg_count(cur_node->num, fndecl);
115113 + gcc_assert(argnum != CANNOT_FIND_ARG);
115114 + if (argnum == 0)
115115 + continue;
115116 +
115117 + arg = gimple_call_arg(stmt, argnum - 1);
115118 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
115119 + }
115120 +
115121 + return head;
115122 +}
115123 +
115124 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
115125 +{
115126 + if (!operand_equal_p(orig_node, node, 0))
115127 + return WRONG_NODE;
115128 + if (skip_types(node))
115129 + return WRONG_NODE;
115130 + return ret_count;
115131 +}
115132 +
115133 +// Get the index of the rhs node in an assignment
115134 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
115135 +{
115136 + const_tree rhs1, rhs2;
115137 + unsigned int ret;
115138 +
115139 + gcc_assert(stmt);
115140 + gcc_assert(is_gimple_assign(stmt));
115141 +
115142 + rhs1 = gimple_assign_rhs1(stmt);
115143 + gcc_assert(rhs1 != NULL_TREE);
115144 +
115145 + switch (gimple_num_ops(stmt)) {
115146 + case 2:
115147 + return check_ops(node, rhs1, 1);
115148 + case 3:
115149 + ret = check_ops(node, rhs1, 1);
115150 + if (ret != WRONG_NODE)
115151 + return ret;
115152 +
115153 + rhs2 = gimple_assign_rhs2(stmt);
115154 + gcc_assert(rhs2 != NULL_TREE);
115155 + return check_ops(node, rhs2, 2);
115156 + default:
115157 + gcc_unreachable();
115158 + }
115159 +}
115160 +
115161 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
115162 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
115163 +{
115164 + unsigned int i;
115165 +
115166 + if (gimple_call_fndecl(stmt) == NULL_TREE)
115167 + return CANNOT_FIND_ARG;
115168 +
115169 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
115170 + tree node;
115171 +
115172 + node = gimple_call_arg(stmt, i);
115173 + if (!operand_equal_p(arg, node, 0))
115174 + continue;
115175 + if (!skip_types(node))
115176 + return i + 1;
115177 + }
115178 +
115179 + return CANNOT_FIND_ARG;
115180 +}
115181 +
115182 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
115183 + * any of return, call or assignment stmts (because of inlining).
115184 + */
115185 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
115186 +{
115187 + use_operand_p use_p;
115188 + imm_use_iterator imm_iter;
115189 + unsigned int argnum;
115190 +
115191 + gcc_assert(TREE_CODE(node) == SSA_NAME);
115192 +
115193 + if (pointer_set_insert(visited, node))
115194 + return head;
115195 +
115196 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
115197 + gimple stmt = USE_STMT(use_p);
115198 +
115199 + if (stmt == NULL)
115200 + return head;
115201 + if (is_gimple_debug(stmt))
115202 + continue;
115203 +
115204 + switch (gimple_code(stmt)) {
115205 + case GIMPLE_CALL:
115206 + argnum = find_arg_number_gimple(node, stmt);
115207 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
115208 + break;
115209 + case GIMPLE_RETURN:
115210 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
115211 + break;
115212 + case GIMPLE_ASSIGN:
115213 + argnum = get_assign_ops_count(stmt, node);
115214 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
115215 + break;
115216 + case GIMPLE_PHI: {
115217 + tree result = gimple_phi_result(stmt);
115218 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
115219 + break;
115220 + }
115221 + case GIMPLE_ASM:
115222 + if (gimple_asm_noutputs(stmt) != 0)
115223 + break;
115224 + if (!is_size_overflow_asm(stmt))
115225 + break;
115226 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
115227 + break;
115228 + case GIMPLE_COND:
115229 + case GIMPLE_SWITCH:
115230 + break;
115231 + default:
115232 + debug_gimple_stmt(stmt);
115233 + gcc_unreachable();
115234 + break;
115235 + }
115236 + }
115237 + return head;
115238 +}
115239 +
115240 +static void remove_size_overflow_asm(gimple stmt)
115241 +{
115242 + gimple_stmt_iterator gsi;
115243 + tree input, output;
115244 +
115245 + if (!is_size_overflow_asm(stmt))
115246 + return;
115247 +
115248 + if (gimple_asm_noutputs(stmt) == 0) {
115249 + gsi = gsi_for_stmt(stmt);
115250 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
115251 + gsi_remove(&gsi, true);
115252 + return;
115253 + }
115254 +
115255 + input = gimple_asm_input_op(stmt, 0);
115256 + output = gimple_asm_output_op(stmt, 0);
115257 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
115258 +}
115259 +
115260 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
115261 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
115262 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
115263 + */
115264 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
115265 +{
115266 + const_tree output;
115267 + struct pointer_set_t *visited;
115268 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
115269 +
115270 + if (!is_size_overflow_asm(stmt))
115271 + return head;
115272 +
115273 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
115274 + intentional_asm = stmt;
115275 +
115276 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
115277 +
115278 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
115279 + return head;
115280 +
115281 + if (gimple_asm_noutputs(stmt) == 0) {
115282 + const_tree input;
115283 +
115284 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
115285 + return head;
115286 +
115287 + input = gimple_asm_input_op(stmt, 0);
115288 + remove_size_overflow_asm(stmt);
115289 + if (is_gimple_constant(TREE_VALUE(input)))
115290 + return head;
115291 + visited = pointer_set_create();
115292 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
115293 + pointer_set_destroy(visited);
115294 + return head;
115295 + }
115296 +
115297 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
115298 + remove_size_overflow_asm(stmt);
115299 +
115300 + visited = pointer_set_create();
115301 + output = gimple_asm_output_op(stmt, 0);
115302 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
115303 + pointer_set_destroy(visited);
115304 + return head;
115305 +}
115306 +
115307 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
115308 + * or a call stmt or a return stmt and store them in the interesting_node list
115309 + */
115310 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
115311 +{
115312 + basic_block bb;
115313 + struct interesting_node *head = NULL;
115314 +
115315 + FOR_ALL_BB_FN(bb, cfun) {
115316 + gimple_stmt_iterator gsi;
115317 +
115318 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
115319 + enum gimple_code code;
115320 + gimple stmt = gsi_stmt(gsi);
115321 +
115322 + code = gimple_code(stmt);
115323 +
115324 + if (code == GIMPLE_ASM)
115325 + head = handle_stmt_by_size_overflow_asm(stmt, head);
115326 +
115327 + if (!next_node)
115328 + continue;
115329 + if (code == GIMPLE_CALL)
115330 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
115331 + if (code == GIMPLE_RETURN)
115332 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
115333 + }
115334 + }
115335 + return head;
115336 +}
115337 +
115338 +static void set_current_function_decl(tree fndecl)
115339 +{
115340 + gcc_assert(fndecl != NULL_TREE);
115341 +
115342 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
115343 + calculate_dominance_info(CDI_DOMINATORS);
115344 + current_function_decl = fndecl;
115345 +}
115346 +
115347 +static void unset_current_function_decl(void)
115348 +{
115349 + free_dominance_info(CDI_DOMINATORS);
115350 + pop_cfun();
115351 + current_function_decl = NULL_TREE;
115352 +}
115353 +
115354 +static void free_interesting_node(struct interesting_node *head)
115355 +{
115356 + struct interesting_node *cur;
115357 +
115358 + while (head) {
115359 + cur = head->next;
115360 +#if BUILDING_GCC_VERSION <= 4007
115361 + VEC_free(tree, gc, head->last_nodes);
115362 +#else
115363 + vec_free(head->last_nodes);
115364 +#endif
115365 + free(head);
115366 + head = cur;
115367 + }
115368 +}
115369 +
115370 +static struct visited *insert_visited_function(struct visited *head, struct interesting_node *cur_node)
115371 +{
115372 + struct visited *new_visited;
115373 +
115374 + new_visited = (struct visited *)xmalloc(sizeof(*new_visited));
115375 + new_visited->fndecl = cur_node->fndecl;
115376 + new_visited->num = cur_node->num;
115377 + new_visited->rhs = cur_node->node;
115378 + new_visited->next = NULL;
115379 +
115380 + if (!head)
115381 + return new_visited;
115382 +
115383 + new_visited->next = head;
115384 + return new_visited;
115385 +}
115386 +
115387 +/* 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
115388 + * it is a visited function.
115389 + */
115390 +static bool is_visited_function(struct visited *head, struct interesting_node *cur_node)
115391 +{
115392 + struct visited *cur;
115393 +
115394 + if (!head)
115395 + return false;
115396 +
115397 + for (cur = head; cur; cur = cur->next) {
115398 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
115399 + continue;
115400 + if (cur_node->num != cur->num)
115401 + continue;
115402 + if (cur_node->node == cur->rhs)
115403 + return true;
115404 + }
115405 + return false;
115406 +}
115407 +
115408 +static void free_next_cgraph_node(struct next_cgraph_node *head)
115409 +{
115410 + struct next_cgraph_node *cur;
115411 +
115412 + while (head) {
115413 + cur = head->next;
115414 + free(head);
115415 + head = cur;
115416 + }
115417 +}
115418 +
115419 +static void remove_all_size_overflow_asm(void)
115420 +{
115421 + basic_block bb;
115422 +
115423 + FOR_ALL_BB_FN(bb, cfun) {
115424 + gimple_stmt_iterator si;
115425 +
115426 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
115427 + remove_size_overflow_asm(gsi_stmt(si));
115428 + }
115429 +}
115430 +
115431 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
115432 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
115433 + * the newly collected interesting functions (they are interesting if there is control flow between
115434 + * the interesting stmts and them).
115435 + */
115436 +static struct visited *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited *visited)
115437 +{
115438 + struct interesting_node *head, *cur_node;
115439 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
115440 +
115441 + set_current_function_decl(NODE_DECL(node));
115442 + call_count = 0;
115443 +
115444 + head = collect_interesting_stmts(next_node);
115445 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
115446 + if (is_visited_function(visited, cur_node))
115447 + continue;
115448 + cnodes_head = handle_interesting_stmt(cnodes_head, cur_node, node);
115449 + visited = insert_visited_function(visited, cur_node);
115450 + }
115451 +
115452 + free_interesting_node(head);
115453 + remove_all_size_overflow_asm();
115454 + unset_current_function_decl();
115455 +
115456 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
115457 + visited = handle_function(cur_cnodes->current_function, cur_cnodes, visited);
115458 +
115459 + free_next_cgraph_node(cnodes_head);
115460 + return visited;
115461 +}
115462 +
115463 +static void free_visited(struct visited *head)
115464 +{
115465 + struct visited *cur;
115466 +
115467 + while (head) {
115468 + cur = head->next;
115469 + free(head);
115470 + head = cur;
115471 + }
115472 +}
115473 +
115474 +// erase the local flag
115475 +static void set_plf_false(void)
115476 +{
115477 + basic_block bb;
115478 +
115479 + FOR_ALL_BB_FN(bb, cfun) {
115480 + gimple_stmt_iterator si;
115481 +
115482 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
115483 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
115484 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
115485 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
115486 + }
115487 +}
115488 +
115489 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
115490 +static unsigned int search_function(void)
115491 +{
115492 + struct cgraph_node *node;
115493 + struct visited *visited = NULL;
115494 +
115495 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
115496 + set_current_function_decl(NODE_DECL(node));
115497 + set_plf_false();
115498 + unset_current_function_decl();
115499 + }
115500 +
115501 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
115502 + gcc_assert(cgraph_function_flags_ready);
115503 +#if BUILDING_GCC_VERSION <= 4007
115504 + gcc_assert(node->reachable);
115505 +#endif
115506 +
115507 + visited = handle_function(node, NULL, visited);
115508 + }
115509 +
115510 + free_visited(visited);
115511 + return 0;
115512 +}
115513 +
115514 +#if BUILDING_GCC_VERSION >= 4009
115515 +static const struct pass_data ipa_pass_data = {
115516 +#else
115517 +static struct ipa_opt_pass_d ipa_pass = {
115518 + .pass = {
115519 +#endif
115520 + .type = SIMPLE_IPA_PASS,
115521 + .name = "size_overflow",
115522 +#if BUILDING_GCC_VERSION >= 4008
115523 + .optinfo_flags = OPTGROUP_NONE,
115524 +#endif
115525 +#if BUILDING_GCC_VERSION >= 4009
115526 + .has_gate = false,
115527 + .has_execute = true,
115528 +#else
115529 + .gate = NULL,
115530 + .execute = search_function,
115531 + .sub = NULL,
115532 + .next = NULL,
115533 + .static_pass_number = 0,
115534 +#endif
115535 + .tv_id = TV_NONE,
115536 + .properties_required = 0,
115537 + .properties_provided = 0,
115538 + .properties_destroyed = 0,
115539 + .todo_flags_start = 0,
115540 + .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,
115541 +#if BUILDING_GCC_VERSION < 4009
115542 + },
115543 + .generate_summary = NULL,
115544 + .write_summary = NULL,
115545 + .read_summary = NULL,
115546 +#if BUILDING_GCC_VERSION >= 4006
115547 + .write_optimization_summary = NULL,
115548 + .read_optimization_summary = NULL,
115549 +#endif
115550 + .stmt_fixup = NULL,
115551 + .function_transform_todo_flags_start = 0,
115552 + .function_transform = NULL,
115553 + .variable_transform = NULL,
115554 +#endif
115555 +};
115556 +
115557 +#if BUILDING_GCC_VERSION >= 4009
115558 +namespace {
115559 +class ipa_pass : public ipa_opt_pass_d {
115560 +public:
115561 + ipa_pass() : ipa_opt_pass_d(ipa_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
115562 + unsigned int execute() { return search_function(); }
115563 +};
115564 +}
115565 +#endif
115566 +
115567 +static struct opt_pass *make_ipa_pass(void)
115568 +{
115569 +#if BUILDING_GCC_VERSION >= 4009
115570 + return new ipa_pass();
115571 +#else
115572 + return &ipa_pass.pass;
115573 +#endif
115574 +}
115575 +
115576 +// data for the size_overflow asm stmt
115577 +struct asm_data {
115578 + gimple def_stmt;
115579 + tree input;
115580 + tree output;
115581 +};
115582 +
115583 +#if BUILDING_GCC_VERSION <= 4007
115584 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
115585 +#else
115586 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
115587 +#endif
115588 +{
115589 + tree list;
115590 +#if BUILDING_GCC_VERSION <= 4007
115591 + VEC(tree, gc) *vec_list = NULL;
115592 +#else
115593 + vec<tree, va_gc> *vec_list = NULL;
115594 +#endif
115595 +
115596 + list = build_tree_list(NULL_TREE, string);
115597 + list = chainon(NULL_TREE, build_tree_list(list, io));
115598 +#if BUILDING_GCC_VERSION <= 4007
115599 + VEC_safe_push(tree, gc, vec_list, list);
115600 +#else
115601 + vec_safe_push(vec_list, list);
115602 +#endif
115603 + return vec_list;
115604 +}
115605 +
115606 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
115607 +{
115608 + gimple asm_stmt;
115609 + gimple_stmt_iterator gsi;
115610 +#if BUILDING_GCC_VERSION <= 4007
115611 + VEC(tree, gc) *input, *output = NULL;
115612 +#else
115613 + vec<tree, va_gc> *input, *output = NULL;
115614 +#endif
115615 +
115616 + input = create_asm_io_list(str_input, asm_data->input);
115617 +
115618 + if (asm_data->output)
115619 + output = create_asm_io_list(str_output, asm_data->output);
115620 +
115621 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
115622 + gsi = gsi_for_stmt(asm_data->def_stmt);
115623 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
115624 +
115625 + if (asm_data->output)
115626 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
115627 +}
115628 +
115629 +static void replace_call_lhs(const struct asm_data *asm_data)
115630 +{
115631 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
115632 + update_stmt(asm_data->def_stmt);
115633 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
115634 +}
115635 +
115636 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
115637 +{
115638 + enum mark cur_fndecl_attr;
115639 + gimple phi = get_def_stmt(result);
115640 + unsigned int i, n = gimple_phi_num_args(phi);
115641 +
115642 + pointer_set_insert(visited, phi);
115643 + for (i = 0; i < n; i++) {
115644 + tree arg = gimple_phi_arg_def(phi, i);
115645 +
115646 + cur_fndecl_attr = search_intentional(visited, arg);
115647 + if (cur_fndecl_attr != MARK_NO)
115648 + return cur_fndecl_attr;
115649 + }
115650 + return MARK_NO;
115651 +}
115652 +
115653 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
115654 +{
115655 + enum mark cur_fndecl_attr;
115656 + const_tree rhs1, rhs2;
115657 + gimple def_stmt = get_def_stmt(lhs);
115658 +
115659 + rhs1 = gimple_assign_rhs1(def_stmt);
115660 + rhs2 = gimple_assign_rhs2(def_stmt);
115661 +
115662 + cur_fndecl_attr = search_intentional(visited, rhs1);
115663 + if (cur_fndecl_attr != MARK_NO)
115664 + return cur_fndecl_attr;
115665 + return search_intentional(visited, rhs2);
115666 +}
115667 +
115668 +// Look up the intentional_overflow attribute on the caller and the callee functions.
115669 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
115670 +{
115671 + const_gimple def_stmt;
115672 +
115673 + if (TREE_CODE(lhs) != SSA_NAME)
115674 + return get_intentional_attr_type(lhs);
115675 +
115676 + def_stmt = get_def_stmt(lhs);
115677 + if (!def_stmt)
115678 + return MARK_NO;
115679 +
115680 + if (pointer_set_contains(visited, def_stmt))
115681 + return MARK_NO;
115682 +
115683 + switch (gimple_code(def_stmt)) {
115684 + case GIMPLE_NOP:
115685 + return search_intentional(visited, SSA_NAME_VAR(lhs));
115686 + case GIMPLE_ASM:
115687 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
115688 + return MARK_TURN_OFF;
115689 + return MARK_NO;
115690 + case GIMPLE_CALL:
115691 + return MARK_NO;
115692 + case GIMPLE_PHI:
115693 + return search_intentional_phi(visited, lhs);
115694 + case GIMPLE_ASSIGN:
115695 + switch (gimple_num_ops(def_stmt)) {
115696 + case 2:
115697 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
115698 + case 3:
115699 + return search_intentional_binary(visited, lhs);
115700 + }
115701 + case GIMPLE_RETURN:
115702 + return MARK_NO;
115703 + default:
115704 + debug_gimple_stmt((gimple)def_stmt);
115705 + error("%s: unknown gimple code", __func__);
115706 + gcc_unreachable();
115707 + }
115708 +}
115709 +
115710 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
115711 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
115712 +{
115713 + const_tree fndecl;
115714 + struct pointer_set_t *visited;
115715 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
115716 +
115717 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
115718 + if (is_end_intentional_intentional_attr(fndecl, argnum))
115719 + decl_attr = MARK_NOT_INTENTIONAL;
115720 + else if (is_yes_intentional_attr(fndecl, argnum))
115721 + decl_attr = MARK_YES;
115722 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
115723 + return MARK_TURN_OFF;
115724 + }
115725 +
115726 + visited = pointer_set_create();
115727 + cur_fndecl_attr = search_intentional(visited, arg);
115728 + pointer_set_destroy(visited);
115729 +
115730 + switch (cur_fndecl_attr) {
115731 + case MARK_NO:
115732 + case MARK_TURN_OFF:
115733 + return cur_fndecl_attr;
115734 + default:
115735 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
115736 + return MARK_YES;
115737 + }
115738 +}
115739 +
115740 +static void check_missing_size_overflow_attribute(tree var)
115741 +{
115742 + tree orig_fndecl;
115743 + unsigned int num;
115744 +
115745 + if (is_a_return_check(var))
115746 + orig_fndecl = DECL_ORIGIN(var);
115747 + else
115748 + orig_fndecl = DECL_ORIGIN(current_function_decl);
115749 +
115750 + num = get_function_num(var, orig_fndecl);
115751 + if (num == CANNOT_FIND_ARG)
115752 + return;
115753 +
115754 + is_missing_function(orig_fndecl, num);
115755 +}
115756 +
115757 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
115758 +{
115759 + gimple phi = get_def_stmt(result);
115760 + unsigned int i, n = gimple_phi_num_args(phi);
115761 +
115762 + pointer_set_insert(visited, phi);
115763 + for (i = 0; i < n; i++) {
115764 + tree arg = gimple_phi_arg_def(phi, i);
115765 +
115766 + search_size_overflow_attribute(visited, arg);
115767 + }
115768 +}
115769 +
115770 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
115771 +{
115772 + const_gimple def_stmt = get_def_stmt(lhs);
115773 + tree rhs1, rhs2;
115774 +
115775 + rhs1 = gimple_assign_rhs1(def_stmt);
115776 + rhs2 = gimple_assign_rhs2(def_stmt);
115777 +
115778 + search_size_overflow_attribute(visited, rhs1);
115779 + search_size_overflow_attribute(visited, rhs2);
115780 +}
115781 +
115782 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
115783 +{
115784 + const_gimple def_stmt;
115785 +
115786 + if (TREE_CODE(lhs) == PARM_DECL) {
115787 + check_missing_size_overflow_attribute(lhs);
115788 + return;
115789 + }
115790 +
115791 + def_stmt = get_def_stmt(lhs);
115792 + if (!def_stmt)
115793 + return;
115794 +
115795 + if (pointer_set_insert(visited, def_stmt))
115796 + return;
115797 +
115798 + switch (gimple_code(def_stmt)) {
115799 + case GIMPLE_NOP:
115800 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
115801 + case GIMPLE_ASM:
115802 + return;
115803 + case GIMPLE_CALL: {
115804 + tree fndecl = gimple_call_fndecl(def_stmt);
115805 +
115806 + if (fndecl == NULL_TREE)
115807 + return;
115808 + check_missing_size_overflow_attribute(fndecl);
115809 + return;
115810 + }
115811 + case GIMPLE_PHI:
115812 + return search_size_overflow_attribute_phi(visited, lhs);
115813 + case GIMPLE_ASSIGN:
115814 + switch (gimple_num_ops(def_stmt)) {
115815 + case 2:
115816 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
115817 + case 3:
115818 + return search_size_overflow_attribute_binary(visited, lhs);
115819 + }
115820 + default:
115821 + debug_gimple_stmt((gimple)def_stmt);
115822 + error("%s: unknown gimple code", __func__);
115823 + gcc_unreachable();
115824 + }
115825 +}
115826 +
115827 +// Search missing entries in the hash table (invoked from the gimple pass)
115828 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
115829 +{
115830 + tree fndecl = NULL_TREE;
115831 + tree lhs;
115832 + struct pointer_set_t *visited;
115833 +
115834 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
115835 + return;
115836 +
115837 + if (num == 0) {
115838 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
115839 + lhs = gimple_return_retval(stmt);
115840 + } else {
115841 + gcc_assert(is_gimple_call(stmt));
115842 + lhs = gimple_call_arg(stmt, num - 1);
115843 + fndecl = gimple_call_fndecl(stmt);
115844 + }
115845 +
115846 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
115847 + return;
115848 +
115849 + visited = pointer_set_create();
115850 + search_size_overflow_attribute(visited, lhs);
115851 + pointer_set_destroy(visited);
115852 +}
115853 +
115854 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
115855 +{
115856 + gimple_stmt_iterator gsi;
115857 + gimple assign;
115858 +
115859 + assign = gimple_build_assign(asm_data->input, asm_data->output);
115860 + gsi = gsi_for_stmt(stmt);
115861 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
115862 + asm_data->def_stmt = assign;
115863 +
115864 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
115865 + asm_data->output = make_ssa_name(asm_data->output, stmt);
115866 + if (gimple_code(stmt) == GIMPLE_RETURN)
115867 + gimple_return_set_retval(stmt, asm_data->output);
115868 + else
115869 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
115870 + update_stmt(stmt);
115871 +}
115872 +
115873 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
115874 +{
115875 + const char *fn_name;
115876 + char *asm_comment;
115877 + unsigned int len;
115878 +
115879 + if (argnum == 0)
115880 + fn_name = DECL_NAME_POINTER(current_function_decl);
115881 + else
115882 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
115883 +
115884 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
115885 + gcc_assert(len > 0);
115886 +
115887 + return asm_comment;
115888 +}
115889 +
115890 +static const char *convert_mark_to_str(enum mark mark)
115891 +{
115892 + switch (mark) {
115893 + case MARK_NO:
115894 + return OK_ASM_STR;
115895 + case MARK_YES:
115896 + case MARK_NOT_INTENTIONAL:
115897 + return YES_ASM_STR;
115898 + case MARK_TURN_OFF:
115899 + return TURN_OFF_ASM_STR;
115900 + }
115901 +
115902 + gcc_unreachable();
115903 +}
115904 +
115905 +/* Create the input of the size_overflow asm stmt.
115906 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
115907 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
115908 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
115909 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
115910 + */
115911 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
115912 +{
115913 + if (!asm_data->def_stmt) {
115914 + asm_data->input = NULL_TREE;
115915 + return;
115916 + }
115917 +
115918 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
115919 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
115920 +
115921 + switch (gimple_code(asm_data->def_stmt)) {
115922 + case GIMPLE_ASSIGN:
115923 + case GIMPLE_CALL:
115924 + replace_call_lhs(asm_data);
115925 + break;
115926 + case GIMPLE_PHI:
115927 + create_output_from_phi(stmt, argnum, asm_data);
115928 + break;
115929 + case GIMPLE_NOP: {
115930 + enum mark mark;
115931 + const char *mark_str;
115932 + char *asm_comment;
115933 +
115934 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
115935 +
115936 + asm_data->input = asm_data->output;
115937 + asm_data->output = NULL;
115938 + asm_data->def_stmt = stmt;
115939 +
115940 + mark_str = convert_mark_to_str(mark);
115941 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
115942 +
115943 + create_asm_stmt(asm_comment, build_string(2, "rm"), NULL, asm_data);
115944 + free(asm_comment);
115945 + asm_data->input = NULL_TREE;
115946 + break;
115947 + }
115948 + case GIMPLE_ASM:
115949 + if (is_size_overflow_asm(asm_data->def_stmt)) {
115950 + asm_data->input = NULL_TREE;
115951 + break;
115952 + }
115953 + default:
115954 + debug_gimple_stmt(asm_data->def_stmt);
115955 + gcc_unreachable();
115956 + }
115957 +}
115958 +
115959 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
115960 + * is of the right kind create the appropriate size_overflow asm stmts:
115961 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
115962 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
115963 + */
115964 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
115965 +{
115966 + struct asm_data asm_data;
115967 + const char *mark_str;
115968 + char *asm_comment;
115969 + enum mark mark;
115970 +
115971 + if (is_gimple_constant(output_node))
115972 + return;
115973 +
115974 + asm_data.output = output_node;
115975 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
115976 + if (mark != MARK_TURN_OFF)
115977 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
115978 +
115979 + asm_data.def_stmt = get_def_stmt(asm_data.output);
115980 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
115981 + return;
115982 +
115983 + create_asm_input(stmt, argnum, &asm_data);
115984 + if (asm_data.input == NULL_TREE)
115985 + return;
115986 +
115987 + mark_str = convert_mark_to_str(mark);
115988 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
115989 + create_asm_stmt(asm_comment, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
115990 + free(asm_comment);
115991 +}
115992 +
115993 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
115994 +static bool create_mark_asm(gimple stmt, enum mark mark)
115995 +{
115996 + struct asm_data asm_data;
115997 + const char *asm_str;
115998 +
115999 + switch (mark) {
116000 + case MARK_TURN_OFF:
116001 + asm_str = TURN_OFF_ASM_STR;
116002 + break;
116003 + case MARK_NOT_INTENTIONAL:
116004 + case MARK_YES:
116005 + asm_str = YES_ASM_STR;
116006 + break;
116007 + default:
116008 + gcc_unreachable();
116009 + }
116010 +
116011 + asm_data.def_stmt = stmt;
116012 + asm_data.output = gimple_call_lhs(stmt);
116013 +
116014 + if (asm_data.output == NULL_TREE) {
116015 + asm_data.input = gimple_call_arg(stmt, 0);
116016 + if (is_gimple_constant(asm_data.input))
116017 + return false;
116018 + asm_data.output = NULL;
116019 + create_asm_stmt(asm_str, build_string(2, "rm"), NULL, &asm_data);
116020 + return true;
116021 + }
116022 +
116023 + create_asm_input(stmt, 0, &asm_data);
116024 + gcc_assert(asm_data.input != NULL_TREE);
116025 +
116026 + create_asm_stmt(asm_str, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
116027 + return true;
116028 +}
116029 +
116030 +static bool is_from_cast(const_tree node)
116031 +{
116032 + gimple def_stmt = get_def_stmt(node);
116033 +
116034 + if (!def_stmt)
116035 + return false;
116036 +
116037 + if (gimple_assign_cast_p(def_stmt))
116038 + return true;
116039 +
116040 + return false;
116041 +}
116042 +
116043 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
116044 +static bool skip_ptr_minus(gimple stmt)
116045 +{
116046 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
116047 +
116048 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
116049 + return false;
116050 +
116051 + rhs1 = gimple_assign_rhs1(stmt);
116052 + if (!is_from_cast(rhs1))
116053 + return false;
116054 +
116055 + rhs2 = gimple_assign_rhs2(stmt);
116056 + if (!is_from_cast(rhs2))
116057 + return false;
116058 +
116059 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
116060 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
116061 +
116062 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
116063 + return false;
116064 +
116065 + create_mark_asm(stmt, MARK_YES);
116066 + return true;
116067 +}
116068 +
116069 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
116070 +{
116071 + gimple def_stmt;
116072 +
116073 + def_stmt = get_def_stmt(lhs);
116074 + if (!def_stmt)
116075 + return;
116076 +
116077 + if (pointer_set_insert(visited, def_stmt))
116078 + return;
116079 +
116080 + switch (gimple_code(def_stmt)) {
116081 + case GIMPLE_NOP:
116082 + case GIMPLE_ASM:
116083 + case GIMPLE_CALL:
116084 + break;
116085 + case GIMPLE_PHI: {
116086 + unsigned int i, n = gimple_phi_num_args(def_stmt);
116087 +
116088 + pointer_set_insert(visited, def_stmt);
116089 +
116090 + for (i = 0; i < n; i++) {
116091 + tree arg = gimple_phi_arg_def(def_stmt, i);
116092 +
116093 + walk_use_def_ptr(visited, arg);
116094 + }
116095 + }
116096 + case GIMPLE_ASSIGN:
116097 + switch (gimple_num_ops(def_stmt)) {
116098 + case 2:
116099 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
116100 + return;
116101 + case 3:
116102 + if (skip_ptr_minus(def_stmt))
116103 + return;
116104 +
116105 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
116106 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
116107 + return;
116108 + default:
116109 + return;
116110 + }
116111 + default:
116112 + debug_gimple_stmt((gimple)def_stmt);
116113 + error("%s: unknown gimple code", __func__);
116114 + gcc_unreachable();
116115 + }
116116 +}
116117 +
116118 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
116119 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
116120 +{
116121 + struct pointer_set_t *visited;
116122 +
116123 + visited = pointer_set_create();
116124 + walk_use_def_ptr(visited, arg);
116125 + pointer_set_destroy(visited);
116126 +}
116127 +
116128 +// Determine the return value and insert the asm stmt to mark the return stmt.
116129 +static void insert_asm_ret(gimple stmt)
116130 +{
116131 + tree ret;
116132 +
116133 + ret = gimple_return_retval(stmt);
116134 + create_size_overflow_asm(stmt, ret, 0);
116135 +}
116136 +
116137 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
116138 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
116139 +{
116140 + tree arg;
116141 + unsigned int argnum;
116142 +
116143 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
116144 + gcc_assert(argnum != 0);
116145 + if (argnum == CANNOT_FIND_ARG)
116146 + return;
116147 +
116148 + arg = gimple_call_arg(stmt, argnum - 1);
116149 + gcc_assert(arg != NULL_TREE);
116150 +
116151 + // skip all ptr - ptr expressions
116152 + insert_mark_not_intentional_asm_at_ptr(arg);
116153 +
116154 + create_size_overflow_asm(stmt, arg, argnum);
116155 +}
116156 +
116157 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
116158 +static void set_argnum_attribute(const_tree attr, bool *argnums)
116159 +{
116160 + unsigned int argnum;
116161 + tree attr_value;
116162 +
116163 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
116164 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
116165 + argnums[argnum] = true;
116166 + }
116167 +}
116168 +
116169 +// If a function arg or the return value is in the hash table then set its index in the array.
116170 +static void set_argnum_hash(tree fndecl, bool *argnums)
116171 +{
116172 + unsigned int num;
116173 + const struct size_overflow_hash *hash;
116174 +
116175 + hash = get_function_hash(DECL_ORIGIN(fndecl));
116176 + if (!hash)
116177 + return;
116178 +
116179 + for (num = 0; num <= MAX_PARAM; num++) {
116180 + if (!(hash->param & (1U << num)))
116181 + continue;
116182 +
116183 + argnums[num] = true;
116184 + }
116185 +}
116186 +
116187 +static bool is_all_the_argnums_empty(bool *argnums)
116188 +{
116189 + unsigned int i;
116190 +
116191 + for (i = 0; i <= MAX_PARAM; i++)
116192 + if (argnums[i])
116193 + return false;
116194 + return true;
116195 +}
116196 +
116197 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
116198 +static void search_interesting_args(tree fndecl, bool *argnums)
116199 +{
116200 + const_tree attr;
116201 +
116202 + set_argnum_hash(fndecl, argnums);
116203 + if (!is_all_the_argnums_empty(argnums))
116204 + return;
116205 +
116206 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
116207 + if (attr && TREE_VALUE(attr))
116208 + set_argnum_attribute(attr, argnums);
116209 +}
116210 +
116211 +/*
116212 + * Look up the intentional_overflow attribute that turns off ipa based duplication
116213 + * on the callee function.
116214 + */
116215 +static bool is_mark_turn_off_attribute(gimple stmt)
116216 +{
116217 + enum mark mark;
116218 + const_tree fndecl = gimple_call_fndecl(stmt);
116219 +
116220 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
116221 + if (mark == MARK_TURN_OFF)
116222 + return true;
116223 + return false;
116224 +}
116225 +
116226 +// 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
116227 +static void handle_interesting_function(gimple stmt)
116228 +{
116229 + unsigned int argnum;
116230 + tree fndecl;
116231 + bool orig_argnums[MAX_PARAM + 1] = {false};
116232 +
116233 + if (gimple_call_num_args(stmt) == 0)
116234 + return;
116235 + fndecl = gimple_call_fndecl(stmt);
116236 + if (fndecl == NULL_TREE)
116237 + return;
116238 + fndecl = DECL_ORIGIN(fndecl);
116239 +
116240 + if (is_mark_turn_off_attribute(stmt)) {
116241 + create_mark_asm(stmt, MARK_TURN_OFF);
116242 + return;
116243 + }
116244 +
116245 + search_interesting_args(fndecl, orig_argnums);
116246 +
116247 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
116248 + if (orig_argnums[argnum])
116249 + insert_asm_arg(stmt, argnum);
116250 +}
116251 +
116252 +// 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
116253 +static void handle_interesting_ret(gimple stmt)
116254 +{
116255 + bool orig_argnums[MAX_PARAM + 1] = {false};
116256 +
116257 + search_interesting_args(current_function_decl, orig_argnums);
116258 +
116259 + if (orig_argnums[0])
116260 + insert_asm_ret(stmt);
116261 +}
116262 +
116263 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
116264 +static unsigned int search_interesting_functions(void)
116265 +{
116266 + basic_block bb;
116267 +
116268 + FOR_ALL_BB_FN(bb, cfun) {
116269 + gimple_stmt_iterator gsi;
116270 +
116271 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116272 + gimple stmt = gsi_stmt(gsi);
116273 +
116274 + if (is_size_overflow_asm(stmt))
116275 + continue;
116276 +
116277 + if (is_gimple_call(stmt))
116278 + handle_interesting_function(stmt);
116279 + else if (gimple_code(stmt) == GIMPLE_RETURN)
116280 + handle_interesting_ret(stmt);
116281 + }
116282 + }
116283 + return 0;
116284 +}
116285 +
116286 +/*
116287 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
116288 + * this pass inserts asm stmts to mark the interesting args
116289 + * that the ipa pass will detect and insert the size overflow checks for.
116290 + */
116291 +#if BUILDING_GCC_VERSION >= 4009
116292 +static const struct pass_data insert_size_overflow_asm_pass_data = {
116293 +#else
116294 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
116295 + .pass = {
116296 +#endif
116297 + .type = GIMPLE_PASS,
116298 + .name = "insert_size_overflow_asm",
116299 +#if BUILDING_GCC_VERSION >= 4008
116300 + .optinfo_flags = OPTGROUP_NONE,
116301 +#endif
116302 +#if BUILDING_GCC_VERSION >= 4009
116303 + .has_gate = false,
116304 + .has_execute = true,
116305 +#else
116306 + .gate = NULL,
116307 + .execute = search_interesting_functions,
116308 + .sub = NULL,
116309 + .next = NULL,
116310 + .static_pass_number = 0,
116311 +#endif
116312 + .tv_id = TV_NONE,
116313 + .properties_required = PROP_cfg,
116314 + .properties_provided = 0,
116315 + .properties_destroyed = 0,
116316 + .todo_flags_start = 0,
116317 + .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
116318 +#if BUILDING_GCC_VERSION < 4009
116319 + }
116320 +#endif
116321 +};
116322 +
116323 +#if BUILDING_GCC_VERSION >= 4009
116324 +namespace {
116325 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
116326 +public:
116327 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
116328 + unsigned int execute() { return search_interesting_functions(); }
116329 +};
116330 +}
116331 +#endif
116332 +
116333 +static struct opt_pass *make_insert_size_overflow_asm_pass(void)
116334 +{
116335 +#if BUILDING_GCC_VERSION >= 4009
116336 + return new insert_size_overflow_asm_pass();
116337 +#else
116338 + return &insert_size_overflow_asm_pass.pass;
116339 +#endif
116340 +}
116341 +
116342 +// Create the noreturn report_size_overflow() function decl.
116343 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
116344 +{
116345 + tree fntype;
116346 +
116347 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
116348 +
116349 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
116350 + fntype = build_function_type_list(void_type_node,
116351 + const_char_ptr_type_node,
116352 + unsigned_type_node,
116353 + const_char_ptr_type_node,
116354 + const_char_ptr_type_node,
116355 + NULL_TREE);
116356 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
116357 +
116358 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
116359 + TREE_PUBLIC(report_size_overflow_decl) = 1;
116360 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
116361 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
116362 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
116363 +}
116364 +
116365 +static unsigned int dump_functions(void)
116366 +{
116367 + struct cgraph_node *node;
116368 +
116369 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
116370 + basic_block bb;
116371 +
116372 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
116373 + current_function_decl = NODE_DECL(node);
116374 +
116375 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
116376 +
116377 + FOR_ALL_BB_FN(bb, cfun) {
116378 + gimple_stmt_iterator si;
116379 +
116380 + fprintf(stderr, "<bb %u>:\n", bb->index);
116381 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
116382 + debug_gimple_stmt(gsi_stmt(si));
116383 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
116384 + debug_gimple_stmt(gsi_stmt(si));
116385 + fprintf(stderr, "\n");
116386 + }
116387 +
116388 + fprintf(stderr, "-------------------------------------------------------------------------\n");
116389 +
116390 + pop_cfun();
116391 + current_function_decl = NULL_TREE;
116392 + }
116393 +
116394 + fprintf(stderr, "###############################################################################\n");
116395 +
116396 + return 0;
116397 +}
116398 +
116399 +#if BUILDING_GCC_VERSION >= 4009
116400 +static const struct pass_data dump_pass_data = {
116401 +#else
116402 +static struct ipa_opt_pass_d dump_pass = {
116403 + .pass = {
116404 +#endif
116405 + .type = SIMPLE_IPA_PASS,
116406 + .name = "dump",
116407 +#if BUILDING_GCC_VERSION >= 4008
116408 + .optinfo_flags = OPTGROUP_NONE,
116409 +#endif
116410 +#if BUILDING_GCC_VERSION >= 4009
116411 + .has_gate = false,
116412 + .has_execute = true,
116413 +#else
116414 + .gate = NULL,
116415 + .execute = dump_functions,
116416 + .sub = NULL,
116417 + .next = NULL,
116418 + .static_pass_number = 0,
116419 +#endif
116420 + .tv_id = TV_NONE,
116421 + .properties_required = 0,
116422 + .properties_provided = 0,
116423 + .properties_destroyed = 0,
116424 + .todo_flags_start = 0,
116425 + .todo_flags_finish = 0,
116426 +#if BUILDING_GCC_VERSION < 4009
116427 + },
116428 + .generate_summary = NULL,
116429 + .write_summary = NULL,
116430 + .read_summary = NULL,
116431 +#if BUILDING_GCC_VERSION >= 4006
116432 + .write_optimization_summary = NULL,
116433 + .read_optimization_summary = NULL,
116434 +#endif
116435 + .stmt_fixup = NULL,
116436 + .function_transform_todo_flags_start = 0,
116437 + .function_transform = NULL,
116438 + .variable_transform = NULL,
116439 +#endif
116440 +};
116441 +
116442 +#if BUILDING_GCC_VERSION >= 4009
116443 +namespace {
116444 +class dump_pass : public ipa_opt_pass_d {
116445 +public:
116446 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
116447 + unsigned int execute() { return dump_functions(); }
116448 +};
116449 +}
116450 +#endif
116451 +
116452 +static struct opt_pass *make_dump_pass(void)
116453 +{
116454 +#if BUILDING_GCC_VERSION >= 4009
116455 + return new dump_pass();
116456 +#else
116457 + return &dump_pass.pass;
116458 +#endif
116459 +}
116460 +
116461 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
116462 +{
116463 + int i;
116464 + const char * const plugin_name = plugin_info->base_name;
116465 + const int argc = plugin_info->argc;
116466 + const struct plugin_argument * const argv = plugin_info->argv;
116467 + bool enable = true;
116468 + struct register_pass_info insert_size_overflow_asm_pass_info;
116469 + struct register_pass_info __unused dump_before_pass_info;
116470 + struct register_pass_info __unused dump_after_pass_info;
116471 + struct register_pass_info ipa_pass_info;
116472 +
116473 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
116474 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
116475 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
116476 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
116477 +
116478 + dump_before_pass_info.pass = make_dump_pass();
116479 + dump_before_pass_info.reference_pass_name = "increase_alignment";
116480 + dump_before_pass_info.ref_pass_instance_number = 1;
116481 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116482 +
116483 + ipa_pass_info.pass = make_ipa_pass();
116484 + ipa_pass_info.reference_pass_name = "increase_alignment";
116485 + ipa_pass_info.ref_pass_instance_number = 1;
116486 + ipa_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116487 +
116488 + dump_after_pass_info.pass = make_dump_pass();
116489 + dump_after_pass_info.reference_pass_name = "increase_alignment";
116490 + dump_after_pass_info.ref_pass_instance_number = 1;
116491 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116492 +
116493 + if (!plugin_default_version_check(version, &gcc_version)) {
116494 + error(G_("incompatible gcc/plugin versions"));
116495 + return 1;
116496 + }
116497 +
116498 + for (i = 0; i < argc; ++i) {
116499 + if (!strcmp(argv[i].key, "no-size-overflow")) {
116500 + enable = false;
116501 + continue;
116502 + }
116503 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
116504 + }
116505 +
116506 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
116507 + if (enable) {
116508 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
116509 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
116510 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
116511 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &ipa_pass_info);
116512 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
116513 + }
116514 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
116515 +
116516 + return 0;
116517 +}
116518 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
116519 new file mode 100644
116520 index 0000000..a4f816a
116521 --- /dev/null
116522 +++ b/tools/gcc/stackleak_plugin.c
116523 @@ -0,0 +1,341 @@
116524 +/*
116525 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
116526 + * Licensed under the GPL v2
116527 + *
116528 + * Note: the choice of the license means that the compilation process is
116529 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
116530 + * but for the kernel it doesn't matter since it doesn't link against
116531 + * any of the gcc libraries
116532 + *
116533 + * gcc plugin to help implement various PaX features
116534 + *
116535 + * - track lowest stack pointer
116536 + *
116537 + * TODO:
116538 + * - initialize all local variables
116539 + *
116540 + * BUGS:
116541 + * - none known
116542 + */
116543 +
116544 +#include "gcc-common.h"
116545 +
116546 +int plugin_is_GPL_compatible;
116547 +
116548 +static int track_frame_size = -1;
116549 +static const char track_function[] = "pax_track_stack";
116550 +static const char check_function[] = "pax_check_alloca";
116551 +static bool init_locals;
116552 +
116553 +static struct plugin_info stackleak_plugin_info = {
116554 + .version = "201401260140",
116555 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
116556 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
116557 +};
116558 +
116559 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
116560 +{
116561 + gimple check_alloca;
116562 + tree fntype, fndecl, alloca_size;
116563 +
116564 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
116565 + fndecl = build_fn_decl(check_function, fntype);
116566 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
116567 +
116568 + // insert call to void pax_check_alloca(unsigned long size)
116569 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
116570 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
116571 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
116572 +}
116573 +
116574 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
116575 +{
116576 + gimple track_stack;
116577 + tree fntype, fndecl;
116578 +
116579 + fntype = build_function_type_list(void_type_node, NULL_TREE);
116580 + fndecl = build_fn_decl(track_function, fntype);
116581 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
116582 +
116583 + // insert call to void pax_track_stack(void)
116584 + track_stack = gimple_build_call(fndecl, 0);
116585 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
116586 +}
116587 +
116588 +static bool is_alloca(gimple stmt)
116589 +{
116590 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
116591 + return true;
116592 +
116593 +#if BUILDING_GCC_VERSION >= 4007
116594 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
116595 + return true;
116596 +#endif
116597 +
116598 + return false;
116599 +}
116600 +
116601 +static unsigned int execute_stackleak_tree_instrument(void)
116602 +{
116603 + basic_block bb, entry_bb;
116604 + bool prologue_instrumented = false, is_leaf = true;
116605 +
116606 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
116607 +
116608 + // 1. loop through BBs and GIMPLE statements
116609 + FOR_EACH_BB_FN(bb, cfun) {
116610 + gimple_stmt_iterator gsi;
116611 +
116612 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116613 + gimple stmt;
116614 +
116615 + stmt = gsi_stmt(gsi);
116616 +
116617 + if (is_gimple_call(stmt))
116618 + is_leaf = false;
116619 +
116620 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
116621 + if (!is_alloca(stmt))
116622 + continue;
116623 +
116624 + // 2. insert stack overflow check before each __builtin_alloca call
116625 + stackleak_check_alloca(&gsi);
116626 +
116627 + // 3. insert track call after each __builtin_alloca call
116628 + stackleak_add_instrumentation(&gsi);
116629 + if (bb == entry_bb)
116630 + prologue_instrumented = true;
116631 + }
116632 + }
116633 +
116634 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
116635 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
116636 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
116637 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
116638 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
116639 + return 0;
116640 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
116641 + return 0;
116642 +
116643 + // 4. insert track call at the beginning
116644 + if (!prologue_instrumented) {
116645 + gimple_stmt_iterator gsi;
116646 +
116647 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
116648 + if (dom_info_available_p(CDI_DOMINATORS))
116649 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
116650 + gsi = gsi_start_bb(bb);
116651 + stackleak_add_instrumentation(&gsi);
116652 + }
116653 +
116654 + return 0;
116655 +}
116656 +
116657 +static unsigned int execute_stackleak_final(void)
116658 +{
116659 + rtx insn, next;
116660 +
116661 + if (cfun->calls_alloca)
116662 + return 0;
116663 +
116664 + // keep calls only if function frame is big enough
116665 + if (get_frame_size() >= track_frame_size)
116666 + return 0;
116667 +
116668 + // 1. find pax_track_stack calls
116669 + for (insn = get_insns(); insn; insn = next) {
116670 + // 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))
116671 + rtx body;
116672 +
116673 + next = NEXT_INSN(insn);
116674 + if (!CALL_P(insn))
116675 + continue;
116676 + body = PATTERN(insn);
116677 + if (GET_CODE(body) != CALL)
116678 + continue;
116679 + body = XEXP(body, 0);
116680 + if (GET_CODE(body) != MEM)
116681 + continue;
116682 + body = XEXP(body, 0);
116683 + if (GET_CODE(body) != SYMBOL_REF)
116684 + continue;
116685 + if (strcmp(XSTR(body, 0), track_function))
116686 + continue;
116687 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
116688 + // 2. delete call
116689 + delete_insn_and_edges(insn);
116690 +#if BUILDING_GCC_VERSION >= 4007
116691 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
116692 + insn = next;
116693 + next = NEXT_INSN(insn);
116694 + delete_insn_and_edges(insn);
116695 + }
116696 +#endif
116697 + }
116698 +
116699 +// print_simple_rtl(stderr, get_insns());
116700 +// print_rtl(stderr, get_insns());
116701 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
116702 +
116703 + return 0;
116704 +}
116705 +
116706 +static bool gate_stackleak_track_stack(void)
116707 +{
116708 + return track_frame_size >= 0;
116709 +}
116710 +
116711 +#if BUILDING_GCC_VERSION >= 4009
116712 +static const struct pass_data stackleak_tree_instrument_pass_data = {
116713 +#else
116714 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
116715 + .pass = {
116716 +#endif
116717 + .type = GIMPLE_PASS,
116718 + .name = "stackleak_tree_instrument",
116719 +#if BUILDING_GCC_VERSION >= 4008
116720 + .optinfo_flags = OPTGROUP_NONE,
116721 +#endif
116722 +#if BUILDING_GCC_VERSION >= 4009
116723 + .has_gate = true,
116724 + .has_execute = true,
116725 +#else
116726 + .gate = gate_stackleak_track_stack,
116727 + .execute = execute_stackleak_tree_instrument,
116728 + .sub = NULL,
116729 + .next = NULL,
116730 + .static_pass_number = 0,
116731 +#endif
116732 + .tv_id = TV_NONE,
116733 + .properties_required = PROP_gimple_leh | PROP_cfg,
116734 + .properties_provided = 0,
116735 + .properties_destroyed = 0,
116736 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
116737 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
116738 +#if BUILDING_GCC_VERSION < 4009
116739 + }
116740 +#endif
116741 +};
116742 +
116743 +#if BUILDING_GCC_VERSION >= 4009
116744 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
116745 +#else
116746 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
116747 + .pass = {
116748 +#endif
116749 + .type = RTL_PASS,
116750 + .name = "stackleak_final",
116751 +#if BUILDING_GCC_VERSION >= 4008
116752 + .optinfo_flags = OPTGROUP_NONE,
116753 +#endif
116754 +#if BUILDING_GCC_VERSION >= 4009
116755 + .has_gate = true,
116756 + .has_execute = true,
116757 +#else
116758 + .gate = gate_stackleak_track_stack,
116759 + .execute = execute_stackleak_final,
116760 + .sub = NULL,
116761 + .next = NULL,
116762 + .static_pass_number = 0,
116763 +#endif
116764 + .tv_id = TV_NONE,
116765 + .properties_required = 0,
116766 + .properties_provided = 0,
116767 + .properties_destroyed = 0,
116768 + .todo_flags_start = 0,
116769 + .todo_flags_finish = TODO_dump_func
116770 +#if BUILDING_GCC_VERSION < 4009
116771 + }
116772 +#endif
116773 +};
116774 +
116775 +#if BUILDING_GCC_VERSION >= 4009
116776 +namespace {
116777 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
116778 +public:
116779 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
116780 + bool gate() { return gate_stackleak_track_stack(); }
116781 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
116782 +};
116783 +
116784 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
116785 +public:
116786 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
116787 + bool gate() { return gate_stackleak_track_stack(); }
116788 + unsigned int execute() { return execute_stackleak_final(); }
116789 +};
116790 +}
116791 +#endif
116792 +
116793 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
116794 +{
116795 +#if BUILDING_GCC_VERSION >= 4009
116796 + return new stackleak_tree_instrument_pass();
116797 +#else
116798 + return &stackleak_tree_instrument_pass.pass;
116799 +#endif
116800 +}
116801 +
116802 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
116803 +{
116804 +#if BUILDING_GCC_VERSION >= 4009
116805 + return new stackleak_final_rtl_opt_pass();
116806 +#else
116807 + return &stackleak_final_rtl_opt_pass.pass;
116808 +#endif
116809 +}
116810 +
116811 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
116812 +{
116813 + const char * const plugin_name = plugin_info->base_name;
116814 + const int argc = plugin_info->argc;
116815 + const struct plugin_argument * const argv = plugin_info->argv;
116816 + int i;
116817 + struct register_pass_info stackleak_tree_instrument_pass_info;
116818 + struct register_pass_info stackleak_final_pass_info;
116819 +
116820 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
116821 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
116822 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
116823 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
116824 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116825 +
116826 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
116827 + stackleak_final_pass_info.reference_pass_name = "final";
116828 + stackleak_final_pass_info.ref_pass_instance_number = 1;
116829 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116830 +
116831 + if (!plugin_default_version_check(version, &gcc_version)) {
116832 + error(G_("incompatible gcc/plugin versions"));
116833 + return 1;
116834 + }
116835 +
116836 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
116837 +
116838 + for (i = 0; i < argc; ++i) {
116839 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
116840 + if (!argv[i].value) {
116841 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
116842 + continue;
116843 + }
116844 + track_frame_size = atoi(argv[i].value);
116845 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
116846 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
116847 + continue;
116848 + }
116849 + if (!strcmp(argv[i].key, "initialize-locals")) {
116850 + if (argv[i].value) {
116851 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
116852 + continue;
116853 + }
116854 + init_locals = true;
116855 + continue;
116856 + }
116857 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
116858 + }
116859 +
116860 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
116861 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
116862 +
116863 + return 0;
116864 +}
116865 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
116866 new file mode 100644
116867 index 0000000..796569a
116868 --- /dev/null
116869 +++ b/tools/gcc/structleak_plugin.c
116870 @@ -0,0 +1,273 @@
116871 +/*
116872 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
116873 + * Licensed under the GPL v2
116874 + *
116875 + * Note: the choice of the license means that the compilation process is
116876 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
116877 + * but for the kernel it doesn't matter since it doesn't link against
116878 + * any of the gcc libraries
116879 + *
116880 + * gcc plugin to forcibly initialize certain local variables that could
116881 + * otherwise leak kernel stack to userland if they aren't properly initialized
116882 + * by later code
116883 + *
116884 + * Homepage: http://pax.grsecurity.net/
116885 + *
116886 + * Usage:
116887 + * $ # for 4.5/4.6/C based 4.7
116888 + * $ 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
116889 + * $ # for C++ based 4.7/4.8+
116890 + * $ 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
116891 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
116892 + *
116893 + * TODO: eliminate redundant initializers
116894 + * increase type coverage
116895 + */
116896 +
116897 +#include "gcc-common.h"
116898 +
116899 +// unused C type flag in all versions 4.5-4.9
116900 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
116901 +
116902 +int plugin_is_GPL_compatible;
116903 +
116904 +static struct plugin_info structleak_plugin_info = {
116905 + .version = "201401260140",
116906 + .help = "disable\tdo not activate plugin\n",
116907 +};
116908 +
116909 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
116910 +{
116911 + *no_add_attrs = true;
116912 +
116913 + // check for types? for now accept everything linux has to offer
116914 + if (TREE_CODE(*node) != FIELD_DECL)
116915 + return NULL_TREE;
116916 +
116917 + *no_add_attrs = false;
116918 + return NULL_TREE;
116919 +}
116920 +
116921 +static struct attribute_spec user_attr = {
116922 + .name = "user",
116923 + .min_length = 0,
116924 + .max_length = 0,
116925 + .decl_required = false,
116926 + .type_required = false,
116927 + .function_type_required = false,
116928 + .handler = handle_user_attribute,
116929 +#if BUILDING_GCC_VERSION >= 4007
116930 + .affects_type_identity = true
116931 +#endif
116932 +};
116933 +
116934 +static void register_attributes(void *event_data, void *data)
116935 +{
116936 + register_attribute(&user_attr);
116937 +// register_attribute(&force_attr);
116938 +}
116939 +
116940 +static tree get_field_type(tree field)
116941 +{
116942 + return strip_array_types(TREE_TYPE(field));
116943 +}
116944 +
116945 +static bool is_userspace_type(tree type)
116946 +{
116947 + tree field;
116948 +
116949 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
116950 + tree fieldtype = get_field_type(field);
116951 + enum tree_code code = TREE_CODE(fieldtype);
116952 +
116953 + if (code == RECORD_TYPE || code == UNION_TYPE)
116954 + if (is_userspace_type(fieldtype))
116955 + return true;
116956 +
116957 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
116958 + return true;
116959 + }
116960 + return false;
116961 +}
116962 +
116963 +static void finish_type(void *event_data, void *data)
116964 +{
116965 + tree type = (tree)event_data;
116966 +
116967 + if (TYPE_USERSPACE(type))
116968 + return;
116969 +
116970 + if (is_userspace_type(type))
116971 + TYPE_USERSPACE(type) = 1;
116972 +}
116973 +
116974 +static void initialize(tree var)
116975 +{
116976 + basic_block bb;
116977 + gimple_stmt_iterator gsi;
116978 + tree initializer;
116979 + gimple init_stmt;
116980 +
116981 + // this is the original entry bb before the forced split
116982 + // TODO: check further BBs in case more splits occured before us
116983 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
116984 +
116985 + // first check if the variable is already initialized, warn otherwise
116986 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116987 + gimple stmt = gsi_stmt(gsi);
116988 + tree rhs1;
116989 +
116990 + // we're looking for an assignment of a single rhs...
116991 + if (!gimple_assign_single_p(stmt))
116992 + continue;
116993 + rhs1 = gimple_assign_rhs1(stmt);
116994 +#if BUILDING_GCC_VERSION >= 4007
116995 + // ... of a non-clobbering expression...
116996 + if (TREE_CLOBBER_P(rhs1))
116997 + continue;
116998 +#endif
116999 + // ... to our variable...
117000 + if (gimple_get_lhs(stmt) != var)
117001 + continue;
117002 + // if it's an initializer then we're good
117003 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
117004 + return;
117005 + }
117006 +
117007 + // these aren't the 0days you're looking for
117008 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
117009 +
117010 + // build the initializer expression
117011 + initializer = build_constructor(TREE_TYPE(var), NULL);
117012 +
117013 + // build the initializer stmt
117014 + init_stmt = gimple_build_assign(var, initializer);
117015 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
117016 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
117017 + update_stmt(init_stmt);
117018 +}
117019 +
117020 +static unsigned int handle_function(void)
117021 +{
117022 + basic_block bb;
117023 + unsigned int ret = 0;
117024 + tree var;
117025 + unsigned int i;
117026 +
117027 + // split the first bb where we can put the forced initializers
117028 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
117029 + if (dom_info_available_p(CDI_DOMINATORS))
117030 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
117031 +
117032 + // enumarate all local variables and forcibly initialize our targets
117033 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
117034 + tree type = TREE_TYPE(var);
117035 +
117036 + gcc_assert(DECL_P(var));
117037 + if (!auto_var_in_fn_p(var, current_function_decl))
117038 + continue;
117039 +
117040 + // only care about structure types
117041 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
117042 + continue;
117043 +
117044 + // if the type is of interest, examine the variable
117045 + if (TYPE_USERSPACE(type))
117046 + initialize(var);
117047 + }
117048 +
117049 + return ret;
117050 +}
117051 +
117052 +#if BUILDING_GCC_VERSION >= 4009
117053 +static const struct pass_data structleak_pass_data = {
117054 +#else
117055 +static struct gimple_opt_pass structleak_pass = {
117056 + .pass = {
117057 +#endif
117058 + .type = GIMPLE_PASS,
117059 + .name = "structleak",
117060 +#if BUILDING_GCC_VERSION >= 4008
117061 + .optinfo_flags = OPTGROUP_NONE,
117062 +#endif
117063 +#if BUILDING_GCC_VERSION >= 4009
117064 + .has_gate = false,
117065 + .has_execute = true,
117066 +#else
117067 + .gate = NULL,
117068 + .execute = handle_function,
117069 + .sub = NULL,
117070 + .next = NULL,
117071 + .static_pass_number = 0,
117072 +#endif
117073 + .tv_id = TV_NONE,
117074 + .properties_required = PROP_cfg,
117075 + .properties_provided = 0,
117076 + .properties_destroyed = 0,
117077 + .todo_flags_start = 0,
117078 + .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
117079 +#if BUILDING_GCC_VERSION < 4009
117080 + }
117081 +#endif
117082 +};
117083 +
117084 +#if BUILDING_GCC_VERSION >= 4009
117085 +namespace {
117086 +class structleak_pass : public gimple_opt_pass {
117087 +public:
117088 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
117089 + unsigned int execute() { return handle_function(); }
117090 +};
117091 +}
117092 +#endif
117093 +
117094 +static struct opt_pass *make_structleak_pass(void)
117095 +{
117096 +#if BUILDING_GCC_VERSION >= 4009
117097 + return new structleak_pass();
117098 +#else
117099 + return &structleak_pass.pass;
117100 +#endif
117101 +}
117102 +
117103 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
117104 +{
117105 + int i;
117106 + const char * const plugin_name = plugin_info->base_name;
117107 + const int argc = plugin_info->argc;
117108 + const struct plugin_argument * const argv = plugin_info->argv;
117109 + bool enable = true;
117110 + struct register_pass_info structleak_pass_info;
117111 +
117112 + structleak_pass_info.pass = make_structleak_pass();
117113 + structleak_pass_info.reference_pass_name = "ssa";
117114 + structleak_pass_info.ref_pass_instance_number = 1;
117115 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
117116 +
117117 + if (!plugin_default_version_check(version, &gcc_version)) {
117118 + error(G_("incompatible gcc/plugin versions"));
117119 + return 1;
117120 + }
117121 +
117122 + if (strcmp(lang_hooks.name, "GNU C")) {
117123 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
117124 + enable = false;
117125 + }
117126 +
117127 + for (i = 0; i < argc; ++i) {
117128 + if (!strcmp(argv[i].key, "disable")) {
117129 + enable = false;
117130 + continue;
117131 + }
117132 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117133 + }
117134 +
117135 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
117136 + if (enable) {
117137 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
117138 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
117139 + }
117140 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
117141 +
117142 + return 0;
117143 +}
117144 diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
117145 index 3dba0a4..97175dc 100644
117146 --- a/tools/lib/lk/Makefile
117147 +++ b/tools/lib/lk/Makefile
117148 @@ -13,7 +13,7 @@ LIB_OBJS += $(OUTPUT)debugfs.o
117149
117150 LIBFILE = liblk.a
117151
117152 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
117153 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
117154 EXTLIBS = -lelf -lpthread -lrt -lm
117155 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
117156 ALL_LDFLAGS = $(LDFLAGS)
117157 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
117158 index 6789d78..4afd019e 100644
117159 --- a/tools/perf/util/include/asm/alternative-asm.h
117160 +++ b/tools/perf/util/include/asm/alternative-asm.h
117161 @@ -5,4 +5,7 @@
117162
117163 #define altinstruction_entry #
117164
117165 + .macro pax_force_retaddr rip=0, reload=0
117166 + .endm
117167 +
117168 #endif
117169 diff --git a/tools/perf/util/include/linux/compiler.h b/tools/perf/util/include/linux/compiler.h
117170 index b003ad7..c0a02f8 100644
117171 --- a/tools/perf/util/include/linux/compiler.h
117172 +++ b/tools/perf/util/include/linux/compiler.h
117173 @@ -27,4 +27,12 @@
117174 # define __weak __attribute__((weak))
117175 #endif
117176
117177 +#ifndef __size_overflow
117178 +# define __size_overflow(...)
117179 +#endif
117180 +
117181 +#ifndef __intentional_overflow
117182 +# define __intentional_overflow(...)
117183 +#endif
117184 +
117185 #endif
117186 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
117187 index 4f588bc..d3cfc5c 100644
117188 --- a/virt/kvm/kvm_main.c
117189 +++ b/virt/kvm/kvm_main.c
117190 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
117191
117192 static cpumask_var_t cpus_hardware_enabled;
117193 static int kvm_usage_count = 0;
117194 -static atomic_t hardware_enable_failed;
117195 +static atomic_unchecked_t hardware_enable_failed;
117196
117197 struct kmem_cache *kvm_vcpu_cache;
117198 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
117199
117200 -static __read_mostly struct preempt_ops kvm_preempt_ops;
117201 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
117202 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
117203 +static struct preempt_ops kvm_preempt_ops = {
117204 + .sched_in = kvm_sched_in,
117205 + .sched_out = kvm_sched_out,
117206 +};
117207
117208 struct dentry *kvm_debugfs_dir;
117209
117210 @@ -751,7 +756,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
117211 /* We can read the guest memory with __xxx_user() later on. */
117212 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
117213 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
117214 - !access_ok(VERIFY_WRITE,
117215 + !__access_ok(VERIFY_WRITE,
117216 (void __user *)(unsigned long)mem->userspace_addr,
117217 mem->memory_size)))
117218 goto out;
117219 @@ -1615,9 +1620,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
117220
117221 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
117222 {
117223 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
117224 + int r;
117225 + unsigned long addr;
117226
117227 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
117228 + addr = gfn_to_hva(kvm, gfn);
117229 + if (kvm_is_error_hva(addr))
117230 + return -EFAULT;
117231 + r = __clear_user((void __user *)addr + offset, len);
117232 + if (r)
117233 + return -EFAULT;
117234 + mark_page_dirty(kvm, gfn);
117235 + return 0;
117236 }
117237 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
117238
117239 @@ -1872,7 +1885,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
117240 return 0;
117241 }
117242
117243 -static struct file_operations kvm_vcpu_fops = {
117244 +static file_operations_no_const kvm_vcpu_fops __read_only = {
117245 .release = kvm_vcpu_release,
117246 .unlocked_ioctl = kvm_vcpu_ioctl,
117247 #ifdef CONFIG_COMPAT
117248 @@ -2532,7 +2545,7 @@ out:
117249 }
117250 #endif
117251
117252 -static struct file_operations kvm_vm_fops = {
117253 +static file_operations_no_const kvm_vm_fops __read_only = {
117254 .release = kvm_vm_release,
117255 .unlocked_ioctl = kvm_vm_ioctl,
117256 #ifdef CONFIG_COMPAT
117257 @@ -2632,7 +2645,7 @@ out:
117258 return r;
117259 }
117260
117261 -static struct file_operations kvm_chardev_ops = {
117262 +static file_operations_no_const kvm_chardev_ops __read_only = {
117263 .unlocked_ioctl = kvm_dev_ioctl,
117264 .compat_ioctl = kvm_dev_ioctl,
117265 .llseek = noop_llseek,
117266 @@ -2658,7 +2671,7 @@ static void hardware_enable_nolock(void *junk)
117267
117268 if (r) {
117269 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
117270 - atomic_inc(&hardware_enable_failed);
117271 + atomic_inc_unchecked(&hardware_enable_failed);
117272 printk(KERN_INFO "kvm: enabling virtualization on "
117273 "CPU%d failed\n", cpu);
117274 }
117275 @@ -2714,10 +2727,10 @@ static int hardware_enable_all(void)
117276
117277 kvm_usage_count++;
117278 if (kvm_usage_count == 1) {
117279 - atomic_set(&hardware_enable_failed, 0);
117280 + atomic_set_unchecked(&hardware_enable_failed, 0);
117281 on_each_cpu(hardware_enable_nolock, NULL, 1);
117282
117283 - if (atomic_read(&hardware_enable_failed)) {
117284 + if (atomic_read_unchecked(&hardware_enable_failed)) {
117285 hardware_disable_all_nolock();
117286 r = -EBUSY;
117287 }
117288 @@ -3148,7 +3161,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
117289 kvm_arch_vcpu_put(vcpu);
117290 }
117291
117292 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117293 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117294 struct module *module)
117295 {
117296 int r;
117297 @@ -3195,7 +3208,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117298 if (!vcpu_align)
117299 vcpu_align = __alignof__(struct kvm_vcpu);
117300 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
117301 - 0, NULL);
117302 + SLAB_USERCOPY, NULL);
117303 if (!kvm_vcpu_cache) {
117304 r = -ENOMEM;
117305 goto out_free_3;
117306 @@ -3205,9 +3218,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117307 if (r)
117308 goto out_free;
117309
117310 + pax_open_kernel();
117311 kvm_chardev_ops.owner = module;
117312 kvm_vm_fops.owner = module;
117313 kvm_vcpu_fops.owner = module;
117314 + pax_close_kernel();
117315
117316 r = misc_register(&kvm_dev);
117317 if (r) {
117318 @@ -3217,9 +3232,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117319
117320 register_syscore_ops(&kvm_syscore_ops);
117321
117322 - kvm_preempt_ops.sched_in = kvm_sched_in;
117323 - kvm_preempt_ops.sched_out = kvm_sched_out;
117324 -
117325 r = kvm_init_debug();
117326 if (r) {
117327 printk(KERN_ERR "kvm: create debugfs files failed\n");