]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.14.1-201404201132.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.14.1-201404201132.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index b89a739..e289b9b 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -69,9 +75,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 +TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56 @@ -80,6 +88,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60 +ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64 @@ -92,32 +101,40 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68 +builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74 +clut_vga16.c
75 +common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82 +config.c
83 config.mak
84 config.mak.autogen
85 +config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89 crc32table.h*
90 cscope.*
91 defkeymap.c
92 +devicetable-offsets.h
93 devlist.h*
94 dnotify_test
95 docproc
96 dslm
97 +dtc-lexer.lex.c
98 elf2ecoff
99 elfconfig.h*
100 evergreen_reg_safe.h
101 +exception_policy.conf
102 fixdep
103 flask.h
104 fore200e_mkfirm
105 @@ -125,12 +142,15 @@ fore200e_pca_fw.c*
106 gconf
107 gconf.glade.h
108 gen-devlist
109 +gen-kdb_cmds.c
110 gen_crc32table
111 gen_init_cpio
112 generated
113 genheaders
114 genksyms
115 *_gray256.c
116 +hash
117 +hid-example
118 hpet_example
119 hugepage-mmap
120 hugepage-shm
121 @@ -145,14 +165,14 @@ int32.c
122 int4.c
123 int8.c
124 kallsyms
125 -kconfig
126 +kern_constants.h
127 keywords.c
128 ksym.c*
129 ksym.h*
130 kxgettext
131 lex.c
132 lex.*.c
133 -linux
134 +lib1funcs.S
135 logo_*.c
136 logo_*_clut224.c
137 logo_*_mono.c
138 @@ -162,14 +182,15 @@ mach-types.h
139 machtypes.h
140 map
141 map_hugetlb
142 -media
143 mconf
144 +mdp
145 miboot*
146 mk_elfconfig
147 mkboot
148 mkbugboot
149 mkcpustr
150 mkdep
151 +mkpiggy
152 mkprep
153 mkregtable
154 mktables
155 @@ -185,6 +206,8 @@ oui.c*
156 page-types
157 parse.c
158 parse.h
159 +parse-events*
160 +pasyms.h
161 patches*
162 pca200e.bin
163 pca200e_ecd.bin2
164 @@ -194,6 +217,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168 +pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172 @@ -203,7 +227,12 @@ r200_reg_safe.h
173 r300_reg_safe.h
174 r420_reg_safe.h
175 r600_reg_safe.h
176 +randomize_layout_hash.h
177 +randomize_layout_seed.h
178 +realmode.lds
179 +realmode.relocs
180 recordmcount
181 +regdb.c
182 relocs
183 rlim_names.h
184 rn50_reg_safe.h
185 @@ -213,8 +242,12 @@ series
186 setup
187 setup.bin
188 setup.elf
189 +signing_key*
190 +size_overflow_hash.h
191 sImage
192 +slabinfo
193 sm_tbl*
194 +sortextable
195 split-include
196 syscalltab.h
197 tables.c
198 @@ -224,6 +257,7 @@ tftpboot.img
199 timeconst.h
200 times.h*
201 trix_boot.h
202 +user_constants.h
203 utsrelease.h*
204 vdso-syms.lds
205 vdso.lds
206 @@ -235,13 +269,17 @@ vdso32.lds
207 vdso32.so.dbg
208 vdso64.lds
209 vdso64.so.dbg
210 +vdsox32.lds
211 +vdsox32-syms.lds
212 version.h*
213 vmImage
214 vmlinux
215 vmlinux-*
216 vmlinux.aout
217 vmlinux.bin.all
218 +vmlinux.bin.bz2
219 vmlinux.lds
220 +vmlinux.relocs
221 vmlinuz
222 voffset.h
223 vsyscall.lds
224 @@ -249,9 +287,12 @@ vsyscall_32.lds
225 wanxlfw.inc
226 uImage
227 unifdef
228 +utsrelease.h
229 wakeup.bin
230 wakeup.elf
231 wakeup.lds
232 +x509*
233 zImage*
234 zconf.hash.c
235 +zconf.lex.c
236 zoffset.h
237 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
238 index 7116fda..d8ed6e8 100644
239 --- a/Documentation/kernel-parameters.txt
240 +++ b/Documentation/kernel-parameters.txt
241 @@ -1084,6 +1084,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 @@ -2080,6 +2084,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 @@ -2347,6 +2355,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 7d0b699..05f9ddb 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 @@ -423,8 +424,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 @@ -585,6 +586,72 @@ 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 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
344 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
345 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
346 +endif
347 +endif
348 +ifdef CONFIG_CHECKER_PLUGIN
349 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
350 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
351 +endif
352 +endif
353 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
354 +ifdef CONFIG_PAX_SIZE_OVERFLOW
355 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
356 +endif
357 +ifdef CONFIG_PAX_LATENT_ENTROPY
358 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
359 +endif
360 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
361 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
362 +endif
363 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
364 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
365 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
366 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
367 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
368 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
369 +ifeq ($(KBUILD_EXTMOD),)
370 +gcc-plugins:
371 + $(Q)$(MAKE) $(build)=tools/gcc
372 +else
373 +gcc-plugins: ;
374 +endif
375 +else
376 +gcc-plugins:
377 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
378 + $(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.))
379 +else
380 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
381 +endif
382 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
383 +endif
384 +endif
385 +
386 include $(srctree)/arch/$(SRCARCH)/Makefile
387
388 ifdef CONFIG_READABLE_ASM
389 @@ -779,7 +846,7 @@ export mod_sign_cmd
390
391
392 ifeq ($(KBUILD_EXTMOD),)
393 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
394 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
395
396 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
397 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
398 @@ -828,6 +895,8 @@ endif
399
400 # The actual objects are generated when descending,
401 # make sure no implicit rule kicks in
402 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
403 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
404 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
405
406 # Handle descending into subdirectories listed in $(vmlinux-dirs)
407 @@ -837,7 +906,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
408 # Error messages still appears in the original language
409
410 PHONY += $(vmlinux-dirs)
411 -$(vmlinux-dirs): prepare scripts
412 +$(vmlinux-dirs): gcc-plugins prepare scripts
413 $(Q)$(MAKE) $(build)=$@
414
415 define filechk_kernel.release
416 @@ -880,10 +949,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
417
418 archprepare: archheaders archscripts prepare1 scripts_basic
419
420 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
421 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
422 prepare0: archprepare FORCE
423 $(Q)$(MAKE) $(build)=.
424
425 # All the preparing..
426 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
427 prepare: prepare0
428
429 # Generate some files
430 @@ -991,6 +1063,8 @@ all: modules
431 # using awk while concatenating to the final file.
432
433 PHONY += modules
434 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
435 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
436 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
437 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
438 @$(kecho) ' Building modules, stage 2.';
439 @@ -1006,7 +1080,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
440
441 # Target to prepare building external modules
442 PHONY += modules_prepare
443 -modules_prepare: prepare scripts
444 +modules_prepare: gcc-plugins prepare scripts
445
446 # Target to install modules
447 PHONY += modules_install
448 @@ -1072,7 +1146,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
449 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
450 signing_key.priv signing_key.x509 x509.genkey \
451 extra_certificates signing_key.x509.keyid \
452 - signing_key.x509.signer
453 + signing_key.x509.signer tools/gcc/size_overflow_hash.h \
454 + tools/gcc/randomize_layout_seed.h
455
456 # clean - Delete most, but leave enough to build external modules
457 #
458 @@ -1112,6 +1187,7 @@ distclean: mrproper
459 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
460 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
461 -o -name '.*.rej' \
462 + -o -name '.*.rej' -o -name '*.so' \
463 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
464 -type f -print | xargs rm -f
465
466 @@ -1273,6 +1349,8 @@ PHONY += $(module-dirs) modules
467 $(module-dirs): crmodverdir $(objtree)/Module.symvers
468 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
469
470 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
471 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
472 modules: $(module-dirs)
473 @$(kecho) ' Building modules, stage 2.';
474 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
475 @@ -1412,17 +1490,21 @@ else
476 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
477 endif
478
479 -%.s: %.c prepare scripts FORCE
480 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
481 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
482 +%.s: %.c gcc-plugins prepare scripts FORCE
483 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
484 %.i: %.c prepare scripts FORCE
485 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
486 -%.o: %.c prepare scripts FORCE
487 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
488 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
489 +%.o: %.c gcc-plugins prepare scripts FORCE
490 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
491 %.lst: %.c prepare scripts FORCE
492 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
493 -%.s: %.S prepare scripts FORCE
494 +%.s: %.S gcc-plugins prepare scripts FORCE
495 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
496 -%.o: %.S prepare scripts FORCE
497 +%.o: %.S gcc-plugins prepare scripts FORCE
498 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
499 %.symtypes: %.c prepare scripts FORCE
500 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
501 @@ -1432,11 +1514,15 @@ endif
502 $(cmd_crmodverdir)
503 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
504 $(build)=$(build-dir)
505 -%/: prepare scripts FORCE
506 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
507 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
508 +%/: gcc-plugins prepare scripts FORCE
509 $(cmd_crmodverdir)
510 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
511 $(build)=$(build-dir)
512 -%.ko: prepare scripts FORCE
513 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
514 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
515 +%.ko: gcc-plugins prepare scripts FORCE
516 $(cmd_crmodverdir)
517 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
518 $(build)=$(build-dir) $(@:.ko=.o)
519 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
520 index 78b03ef..da28a51 100644
521 --- a/arch/alpha/include/asm/atomic.h
522 +++ b/arch/alpha/include/asm/atomic.h
523 @@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
524 #define atomic_dec(v) atomic_sub(1,(v))
525 #define atomic64_dec(v) atomic64_sub(1,(v))
526
527 +#define atomic64_read_unchecked(v) atomic64_read(v)
528 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
529 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
530 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
531 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
532 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
533 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
534 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
535 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
536 +
537 #define smp_mb__before_atomic_dec() smp_mb()
538 #define smp_mb__after_atomic_dec() smp_mb()
539 #define smp_mb__before_atomic_inc() smp_mb()
540 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
541 index ad368a9..fbe0f25 100644
542 --- a/arch/alpha/include/asm/cache.h
543 +++ b/arch/alpha/include/asm/cache.h
544 @@ -4,19 +4,19 @@
545 #ifndef __ARCH_ALPHA_CACHE_H
546 #define __ARCH_ALPHA_CACHE_H
547
548 +#include <linux/const.h>
549
550 /* Bytes per L1 (data) cache line. */
551 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
552 -# define L1_CACHE_BYTES 64
553 # define L1_CACHE_SHIFT 6
554 #else
555 /* Both EV4 and EV5 are write-through, read-allocate,
556 direct-mapped, physical.
557 */
558 -# define L1_CACHE_BYTES 32
559 # define L1_CACHE_SHIFT 5
560 #endif
561
562 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
563 #define SMP_CACHE_BYTES L1_CACHE_BYTES
564
565 #endif
566 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
567 index 968d999..d36b2df 100644
568 --- a/arch/alpha/include/asm/elf.h
569 +++ b/arch/alpha/include/asm/elf.h
570 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
571
572 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
573
574 +#ifdef CONFIG_PAX_ASLR
575 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
576 +
577 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
578 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
579 +#endif
580 +
581 /* $0 is set by ld.so to a pointer to a function which might be
582 registered using atexit. This provides a mean for the dynamic
583 linker to call DT_FINI functions for shared libraries that have
584 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
585 index aab14a0..b4fa3e7 100644
586 --- a/arch/alpha/include/asm/pgalloc.h
587 +++ b/arch/alpha/include/asm/pgalloc.h
588 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
589 pgd_set(pgd, pmd);
590 }
591
592 +static inline void
593 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
594 +{
595 + pgd_populate(mm, pgd, pmd);
596 +}
597 +
598 extern pgd_t *pgd_alloc(struct mm_struct *mm);
599
600 static inline void
601 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
602 index d8f9b7e..f6222fa 100644
603 --- a/arch/alpha/include/asm/pgtable.h
604 +++ b/arch/alpha/include/asm/pgtable.h
605 @@ -102,6 +102,17 @@ struct vm_area_struct;
606 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
607 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
608 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
609 +
610 +#ifdef CONFIG_PAX_PAGEEXEC
611 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
612 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
613 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
614 +#else
615 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
616 +# define PAGE_COPY_NOEXEC PAGE_COPY
617 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
618 +#endif
619 +
620 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
621
622 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
623 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
624 index 2fd00b7..cfd5069 100644
625 --- a/arch/alpha/kernel/module.c
626 +++ b/arch/alpha/kernel/module.c
627 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
628
629 /* The small sections were sorted to the end of the segment.
630 The following should definitely cover them. */
631 - gp = (u64)me->module_core + me->core_size - 0x8000;
632 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
633 got = sechdrs[me->arch.gotsecindex].sh_addr;
634
635 for (i = 0; i < n; i++) {
636 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
637 index 1402fcc..0b1abd2 100644
638 --- a/arch/alpha/kernel/osf_sys.c
639 +++ b/arch/alpha/kernel/osf_sys.c
640 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
641 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
642
643 static unsigned long
644 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
645 - unsigned long limit)
646 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
647 + unsigned long limit, unsigned long flags)
648 {
649 struct vm_unmapped_area_info info;
650 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
651
652 info.flags = 0;
653 info.length = len;
654 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
655 info.high_limit = limit;
656 info.align_mask = 0;
657 info.align_offset = 0;
658 + info.threadstack_offset = offset;
659 return vm_unmapped_area(&info);
660 }
661
662 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
663 merely specific addresses, but regions of memory -- perhaps
664 this feature should be incorporated into all ports? */
665
666 +#ifdef CONFIG_PAX_RANDMMAP
667 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
668 +#endif
669 +
670 if (addr) {
671 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
672 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
673 if (addr != (unsigned long) -ENOMEM)
674 return addr;
675 }
676
677 /* Next, try allocating at TASK_UNMAPPED_BASE. */
678 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
679 - len, limit);
680 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
681 +
682 if (addr != (unsigned long) -ENOMEM)
683 return addr;
684
685 /* Finally, try allocating in low memory. */
686 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
687 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
688
689 return addr;
690 }
691 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
692 index 98838a0..b304fb4 100644
693 --- a/arch/alpha/mm/fault.c
694 +++ b/arch/alpha/mm/fault.c
695 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
696 __reload_thread(pcb);
697 }
698
699 +#ifdef CONFIG_PAX_PAGEEXEC
700 +/*
701 + * PaX: decide what to do with offenders (regs->pc = fault address)
702 + *
703 + * returns 1 when task should be killed
704 + * 2 when patched PLT trampoline was detected
705 + * 3 when unpatched PLT trampoline was detected
706 + */
707 +static int pax_handle_fetch_fault(struct pt_regs *regs)
708 +{
709 +
710 +#ifdef CONFIG_PAX_EMUPLT
711 + int err;
712 +
713 + do { /* PaX: patched PLT emulation #1 */
714 + unsigned int ldah, ldq, jmp;
715 +
716 + err = get_user(ldah, (unsigned int *)regs->pc);
717 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
718 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
719 +
720 + if (err)
721 + break;
722 +
723 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
724 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
725 + jmp == 0x6BFB0000U)
726 + {
727 + unsigned long r27, addr;
728 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
729 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
730 +
731 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
732 + err = get_user(r27, (unsigned long *)addr);
733 + if (err)
734 + break;
735 +
736 + regs->r27 = r27;
737 + regs->pc = r27;
738 + return 2;
739 + }
740 + } while (0);
741 +
742 + do { /* PaX: patched PLT emulation #2 */
743 + unsigned int ldah, lda, br;
744 +
745 + err = get_user(ldah, (unsigned int *)regs->pc);
746 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
747 + err |= get_user(br, (unsigned int *)(regs->pc+8));
748 +
749 + if (err)
750 + break;
751 +
752 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
753 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
754 + (br & 0xFFE00000U) == 0xC3E00000U)
755 + {
756 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
757 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
758 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
759 +
760 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
761 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
762 + return 2;
763 + }
764 + } while (0);
765 +
766 + do { /* PaX: unpatched PLT emulation */
767 + unsigned int br;
768 +
769 + err = get_user(br, (unsigned int *)regs->pc);
770 +
771 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
772 + unsigned int br2, ldq, nop, jmp;
773 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
774 +
775 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
776 + err = get_user(br2, (unsigned int *)addr);
777 + err |= get_user(ldq, (unsigned int *)(addr+4));
778 + err |= get_user(nop, (unsigned int *)(addr+8));
779 + err |= get_user(jmp, (unsigned int *)(addr+12));
780 + err |= get_user(resolver, (unsigned long *)(addr+16));
781 +
782 + if (err)
783 + break;
784 +
785 + if (br2 == 0xC3600000U &&
786 + ldq == 0xA77B000CU &&
787 + nop == 0x47FF041FU &&
788 + jmp == 0x6B7B0000U)
789 + {
790 + regs->r28 = regs->pc+4;
791 + regs->r27 = addr+16;
792 + regs->pc = resolver;
793 + return 3;
794 + }
795 + }
796 + } while (0);
797 +#endif
798 +
799 + return 1;
800 +}
801 +
802 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
803 +{
804 + unsigned long i;
805 +
806 + printk(KERN_ERR "PAX: bytes at PC: ");
807 + for (i = 0; i < 5; i++) {
808 + unsigned int c;
809 + if (get_user(c, (unsigned int *)pc+i))
810 + printk(KERN_CONT "???????? ");
811 + else
812 + printk(KERN_CONT "%08x ", c);
813 + }
814 + printk("\n");
815 +}
816 +#endif
817
818 /*
819 * This routine handles page faults. It determines the address,
820 @@ -133,8 +251,29 @@ retry:
821 good_area:
822 si_code = SEGV_ACCERR;
823 if (cause < 0) {
824 - if (!(vma->vm_flags & VM_EXEC))
825 + if (!(vma->vm_flags & VM_EXEC)) {
826 +
827 +#ifdef CONFIG_PAX_PAGEEXEC
828 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
829 + goto bad_area;
830 +
831 + up_read(&mm->mmap_sem);
832 + switch (pax_handle_fetch_fault(regs)) {
833 +
834 +#ifdef CONFIG_PAX_EMUPLT
835 + case 2:
836 + case 3:
837 + return;
838 +#endif
839 +
840 + }
841 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
842 + do_group_exit(SIGKILL);
843 +#else
844 goto bad_area;
845 +#endif
846 +
847 + }
848 } else if (!cause) {
849 /* Allow reads even for write-only mappings */
850 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
851 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
852 index 1594945..adf4001 100644
853 --- a/arch/arm/Kconfig
854 +++ b/arch/arm/Kconfig
855 @@ -1862,7 +1862,7 @@ config ALIGNMENT_TRAP
856
857 config UACCESS_WITH_MEMCPY
858 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
859 - depends on MMU
860 + depends on MMU && !PAX_MEMORY_UDEREF
861 default y if CPU_FEROCEON
862 help
863 Implement faster copy_to_user and clear_user methods for CPU
864 @@ -2125,6 +2125,7 @@ config XIP_PHYS_ADDR
865 config KEXEC
866 bool "Kexec system call (EXPERIMENTAL)"
867 depends on (!SMP || PM_SLEEP_SMP)
868 + depends on !GRKERNSEC_KMEM
869 help
870 kexec is a system call that implements the ability to shutdown your
871 current kernel, and to start another kernel. It is like a reboot
872 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
873 index 62d2cb5..09d45e3 100644
874 --- a/arch/arm/include/asm/atomic.h
875 +++ b/arch/arm/include/asm/atomic.h
876 @@ -18,17 +18,35 @@
877 #include <asm/barrier.h>
878 #include <asm/cmpxchg.h>
879
880 +#ifdef CONFIG_GENERIC_ATOMIC64
881 +#include <asm-generic/atomic64.h>
882 +#endif
883 +
884 #define ATOMIC_INIT(i) { (i) }
885
886 #ifdef __KERNEL__
887
888 +#define _ASM_EXTABLE(from, to) \
889 +" .pushsection __ex_table,\"a\"\n"\
890 +" .align 3\n" \
891 +" .long " #from ", " #to"\n" \
892 +" .popsection"
893 +
894 /*
895 * On ARM, ordinary assignment (str instruction) doesn't clear the local
896 * strex/ldrex monitor on some implementations. The reason we can use it for
897 * atomic_set() is the clrex or dummy strex done on every exception return.
898 */
899 #define atomic_read(v) (*(volatile int *)&(v)->counter)
900 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
901 +{
902 + return v->counter;
903 +}
904 #define atomic_set(v,i) (((v)->counter) = (i))
905 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
906 +{
907 + v->counter = i;
908 +}
909
910 #if __LINUX_ARM_ARCH__ >= 6
911
912 @@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
913
914 prefetchw(&v->counter);
915 __asm__ __volatile__("@ atomic_add\n"
916 +"1: ldrex %1, [%3]\n"
917 +" adds %0, %1, %4\n"
918 +
919 +#ifdef CONFIG_PAX_REFCOUNT
920 +" bvc 3f\n"
921 +"2: bkpt 0xf103\n"
922 +"3:\n"
923 +#endif
924 +
925 +" strex %1, %0, [%3]\n"
926 +" teq %1, #0\n"
927 +" bne 1b"
928 +
929 +#ifdef CONFIG_PAX_REFCOUNT
930 +"\n4:\n"
931 + _ASM_EXTABLE(2b, 4b)
932 +#endif
933 +
934 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
935 + : "r" (&v->counter), "Ir" (i)
936 + : "cc");
937 +}
938 +
939 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
940 +{
941 + unsigned long tmp;
942 + int result;
943 +
944 + prefetchw(&v->counter);
945 + __asm__ __volatile__("@ atomic_add_unchecked\n"
946 "1: ldrex %0, [%3]\n"
947 " add %0, %0, %4\n"
948 " strex %1, %0, [%3]\n"
949 @@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
950 smp_mb();
951
952 __asm__ __volatile__("@ atomic_add_return\n"
953 +"1: ldrex %1, [%3]\n"
954 +" adds %0, %1, %4\n"
955 +
956 +#ifdef CONFIG_PAX_REFCOUNT
957 +" bvc 3f\n"
958 +" mov %0, %1\n"
959 +"2: bkpt 0xf103\n"
960 +"3:\n"
961 +#endif
962 +
963 +" strex %1, %0, [%3]\n"
964 +" teq %1, #0\n"
965 +" bne 1b"
966 +
967 +#ifdef CONFIG_PAX_REFCOUNT
968 +"\n4:\n"
969 + _ASM_EXTABLE(2b, 4b)
970 +#endif
971 +
972 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
973 + : "r" (&v->counter), "Ir" (i)
974 + : "cc");
975 +
976 + smp_mb();
977 +
978 + return result;
979 +}
980 +
981 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
982 +{
983 + unsigned long tmp;
984 + int result;
985 +
986 + smp_mb();
987 +
988 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
989 "1: ldrex %0, [%3]\n"
990 " add %0, %0, %4\n"
991 " strex %1, %0, [%3]\n"
992 @@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
993
994 prefetchw(&v->counter);
995 __asm__ __volatile__("@ atomic_sub\n"
996 +"1: ldrex %1, [%3]\n"
997 +" subs %0, %1, %4\n"
998 +
999 +#ifdef CONFIG_PAX_REFCOUNT
1000 +" bvc 3f\n"
1001 +"2: bkpt 0xf103\n"
1002 +"3:\n"
1003 +#endif
1004 +
1005 +" strex %1, %0, [%3]\n"
1006 +" teq %1, #0\n"
1007 +" bne 1b"
1008 +
1009 +#ifdef CONFIG_PAX_REFCOUNT
1010 +"\n4:\n"
1011 + _ASM_EXTABLE(2b, 4b)
1012 +#endif
1013 +
1014 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1015 + : "r" (&v->counter), "Ir" (i)
1016 + : "cc");
1017 +}
1018 +
1019 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1020 +{
1021 + unsigned long tmp;
1022 + int result;
1023 +
1024 + prefetchw(&v->counter);
1025 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1026 "1: ldrex %0, [%3]\n"
1027 " sub %0, %0, %4\n"
1028 " strex %1, %0, [%3]\n"
1029 @@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1030 smp_mb();
1031
1032 __asm__ __volatile__("@ atomic_sub_return\n"
1033 -"1: ldrex %0, [%3]\n"
1034 -" sub %0, %0, %4\n"
1035 +"1: ldrex %1, [%3]\n"
1036 +" subs %0, %1, %4\n"
1037 +
1038 +#ifdef CONFIG_PAX_REFCOUNT
1039 +" bvc 3f\n"
1040 +" mov %0, %1\n"
1041 +"2: bkpt 0xf103\n"
1042 +"3:\n"
1043 +#endif
1044 +
1045 " strex %1, %0, [%3]\n"
1046 " teq %1, #0\n"
1047 " bne 1b"
1048 +
1049 +#ifdef CONFIG_PAX_REFCOUNT
1050 +"\n4:\n"
1051 + _ASM_EXTABLE(2b, 4b)
1052 +#endif
1053 +
1054 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1055 : "r" (&v->counter), "Ir" (i)
1056 : "cc");
1057 @@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1058 return oldval;
1059 }
1060
1061 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1062 +{
1063 + unsigned long oldval, res;
1064 +
1065 + smp_mb();
1066 +
1067 + do {
1068 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1069 + "ldrex %1, [%3]\n"
1070 + "mov %0, #0\n"
1071 + "teq %1, %4\n"
1072 + "strexeq %0, %5, [%3]\n"
1073 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1074 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1075 + : "cc");
1076 + } while (res);
1077 +
1078 + smp_mb();
1079 +
1080 + return oldval;
1081 +}
1082 +
1083 #else /* ARM_ARCH_6 */
1084
1085 #ifdef CONFIG_SMP
1086 @@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1087
1088 return val;
1089 }
1090 +
1091 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1092 +{
1093 + return atomic_add_return(i, v);
1094 +}
1095 +
1096 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1097 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1098 +{
1099 + (void) atomic_add_return(i, v);
1100 +}
1101
1102 static inline int atomic_sub_return(int i, atomic_t *v)
1103 {
1104 @@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1105 return val;
1106 }
1107 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1108 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1109 +{
1110 + (void) atomic_sub_return(i, v);
1111 +}
1112
1113 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1114 {
1115 @@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1116 return ret;
1117 }
1118
1119 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1120 +{
1121 + return atomic_cmpxchg(v, old, new);
1122 +}
1123 +
1124 #endif /* __LINUX_ARM_ARCH__ */
1125
1126 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1127 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1128 +{
1129 + return xchg(&v->counter, new);
1130 +}
1131
1132 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1133 {
1134 @@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1135 }
1136
1137 #define atomic_inc(v) atomic_add(1, v)
1138 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1139 +{
1140 + atomic_add_unchecked(1, v);
1141 +}
1142 #define atomic_dec(v) atomic_sub(1, v)
1143 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1144 +{
1145 + atomic_sub_unchecked(1, v);
1146 +}
1147
1148 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1149 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1150 +{
1151 + return atomic_add_return_unchecked(1, v) == 0;
1152 +}
1153 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1154 #define atomic_inc_return(v) (atomic_add_return(1, v))
1155 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1156 +{
1157 + return atomic_add_return_unchecked(1, v);
1158 +}
1159 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1160 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1161
1162 @@ -221,6 +410,14 @@ typedef struct {
1163 long long counter;
1164 } atomic64_t;
1165
1166 +#ifdef CONFIG_PAX_REFCOUNT
1167 +typedef struct {
1168 + long long counter;
1169 +} atomic64_unchecked_t;
1170 +#else
1171 +typedef atomic64_t atomic64_unchecked_t;
1172 +#endif
1173 +
1174 #define ATOMIC64_INIT(i) { (i) }
1175
1176 #ifdef CONFIG_ARM_LPAE
1177 @@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1178 return result;
1179 }
1180
1181 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1182 +{
1183 + long long result;
1184 +
1185 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1186 +" ldrd %0, %H0, [%1]"
1187 + : "=&r" (result)
1188 + : "r" (&v->counter), "Qo" (v->counter)
1189 + );
1190 +
1191 + return result;
1192 +}
1193 +
1194 static inline void atomic64_set(atomic64_t *v, long long i)
1195 {
1196 __asm__ __volatile__("@ atomic64_set\n"
1197 @@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1198 : "r" (&v->counter), "r" (i)
1199 );
1200 }
1201 +
1202 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1203 +{
1204 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1205 +" strd %2, %H2, [%1]"
1206 + : "=Qo" (v->counter)
1207 + : "r" (&v->counter), "r" (i)
1208 + );
1209 +}
1210 #else
1211 static inline long long atomic64_read(const atomic64_t *v)
1212 {
1213 @@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1214 return result;
1215 }
1216
1217 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1218 +{
1219 + long long result;
1220 +
1221 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1222 +" ldrexd %0, %H0, [%1]"
1223 + : "=&r" (result)
1224 + : "r" (&v->counter), "Qo" (v->counter)
1225 + );
1226 +
1227 + return result;
1228 +}
1229 +
1230 static inline void atomic64_set(atomic64_t *v, long long i)
1231 {
1232 long long tmp;
1233 @@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1234 : "r" (&v->counter), "r" (i)
1235 : "cc");
1236 }
1237 +
1238 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1239 +{
1240 + long long tmp;
1241 +
1242 + prefetchw(&v->counter);
1243 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1244 +"1: ldrexd %0, %H0, [%2]\n"
1245 +" strexd %0, %3, %H3, [%2]\n"
1246 +" teq %0, #0\n"
1247 +" bne 1b"
1248 + : "=&r" (tmp), "=Qo" (v->counter)
1249 + : "r" (&v->counter), "r" (i)
1250 + : "cc");
1251 +}
1252 #endif
1253
1254 static inline void atomic64_add(long long i, atomic64_t *v)
1255 @@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1256 __asm__ __volatile__("@ atomic64_add\n"
1257 "1: ldrexd %0, %H0, [%3]\n"
1258 " adds %Q0, %Q0, %Q4\n"
1259 +" adcs %R0, %R0, %R4\n"
1260 +
1261 +#ifdef CONFIG_PAX_REFCOUNT
1262 +" bvc 3f\n"
1263 +"2: bkpt 0xf103\n"
1264 +"3:\n"
1265 +#endif
1266 +
1267 +" strexd %1, %0, %H0, [%3]\n"
1268 +" teq %1, #0\n"
1269 +" bne 1b"
1270 +
1271 +#ifdef CONFIG_PAX_REFCOUNT
1272 +"\n4:\n"
1273 + _ASM_EXTABLE(2b, 4b)
1274 +#endif
1275 +
1276 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1277 + : "r" (&v->counter), "r" (i)
1278 + : "cc");
1279 +}
1280 +
1281 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1282 +{
1283 + long long result;
1284 + unsigned long tmp;
1285 +
1286 + prefetchw(&v->counter);
1287 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1288 +"1: ldrexd %0, %H0, [%3]\n"
1289 +" adds %Q0, %Q0, %Q4\n"
1290 " adc %R0, %R0, %R4\n"
1291 " strexd %1, %0, %H0, [%3]\n"
1292 " teq %1, #0\n"
1293 @@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1294 __asm__ __volatile__("@ atomic64_add_return\n"
1295 "1: ldrexd %0, %H0, [%3]\n"
1296 " adds %Q0, %Q0, %Q4\n"
1297 +" adcs %R0, %R0, %R4\n"
1298 +
1299 +#ifdef CONFIG_PAX_REFCOUNT
1300 +" bvc 3f\n"
1301 +" mov %0, %1\n"
1302 +" mov %H0, %H1\n"
1303 +"2: bkpt 0xf103\n"
1304 +"3:\n"
1305 +#endif
1306 +
1307 +" strexd %1, %0, %H0, [%3]\n"
1308 +" teq %1, #0\n"
1309 +" bne 1b"
1310 +
1311 +#ifdef CONFIG_PAX_REFCOUNT
1312 +"\n4:\n"
1313 + _ASM_EXTABLE(2b, 4b)
1314 +#endif
1315 +
1316 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1317 + : "r" (&v->counter), "r" (i)
1318 + : "cc");
1319 +
1320 + smp_mb();
1321 +
1322 + return result;
1323 +}
1324 +
1325 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1326 +{
1327 + long long result;
1328 + unsigned long tmp;
1329 +
1330 + smp_mb();
1331 +
1332 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1333 +"1: ldrexd %0, %H0, [%3]\n"
1334 +" adds %Q0, %Q0, %Q4\n"
1335 " adc %R0, %R0, %R4\n"
1336 " strexd %1, %0, %H0, [%3]\n"
1337 " teq %1, #0\n"
1338 @@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1339 __asm__ __volatile__("@ atomic64_sub\n"
1340 "1: ldrexd %0, %H0, [%3]\n"
1341 " subs %Q0, %Q0, %Q4\n"
1342 +" sbcs %R0, %R0, %R4\n"
1343 +
1344 +#ifdef CONFIG_PAX_REFCOUNT
1345 +" bvc 3f\n"
1346 +"2: bkpt 0xf103\n"
1347 +"3:\n"
1348 +#endif
1349 +
1350 +" strexd %1, %0, %H0, [%3]\n"
1351 +" teq %1, #0\n"
1352 +" bne 1b"
1353 +
1354 +#ifdef CONFIG_PAX_REFCOUNT
1355 +"\n4:\n"
1356 + _ASM_EXTABLE(2b, 4b)
1357 +#endif
1358 +
1359 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1360 + : "r" (&v->counter), "r" (i)
1361 + : "cc");
1362 +}
1363 +
1364 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1365 +{
1366 + long long result;
1367 + unsigned long tmp;
1368 +
1369 + prefetchw(&v->counter);
1370 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1371 +"1: ldrexd %0, %H0, [%3]\n"
1372 +" subs %Q0, %Q0, %Q4\n"
1373 " sbc %R0, %R0, %R4\n"
1374 " strexd %1, %0, %H0, [%3]\n"
1375 " teq %1, #0\n"
1376 @@ -344,16 +691,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1377 __asm__ __volatile__("@ atomic64_sub_return\n"
1378 "1: ldrexd %0, %H0, [%3]\n"
1379 " subs %Q0, %Q0, %Q4\n"
1380 -" sbc %R0, %R0, %R4\n"
1381 +" sbcs %R0, %R0, %R4\n"
1382 +
1383 +#ifdef CONFIG_PAX_REFCOUNT
1384 +" bvc 3f\n"
1385 +" mov %0, %1\n"
1386 +" mov %H0, %H1\n"
1387 +"2: bkpt 0xf103\n"
1388 +"3:\n"
1389 +#endif
1390 +
1391 " strexd %1, %0, %H0, [%3]\n"
1392 " teq %1, #0\n"
1393 " bne 1b"
1394 +
1395 +#ifdef CONFIG_PAX_REFCOUNT
1396 +"\n4:\n"
1397 + _ASM_EXTABLE(2b, 4b)
1398 +#endif
1399 +
1400 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1401 : "r" (&v->counter), "r" (i)
1402 : "cc");
1403
1404 - smp_mb();
1405 -
1406 return result;
1407 }
1408
1409 @@ -382,6 +742,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1410 return oldval;
1411 }
1412
1413 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1414 + long long new)
1415 +{
1416 + long long oldval;
1417 + unsigned long res;
1418 +
1419 + smp_mb();
1420 +
1421 + do {
1422 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1423 + "ldrexd %1, %H1, [%3]\n"
1424 + "mov %0, #0\n"
1425 + "teq %1, %4\n"
1426 + "teqeq %H1, %H4\n"
1427 + "strexdeq %0, %5, %H5, [%3]"
1428 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1429 + : "r" (&ptr->counter), "r" (old), "r" (new)
1430 + : "cc");
1431 + } while (res);
1432 +
1433 + smp_mb();
1434 +
1435 + return oldval;
1436 +}
1437 +
1438 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1439 {
1440 long long result;
1441 @@ -406,20 +791,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1442 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1443 {
1444 long long result;
1445 - unsigned long tmp;
1446 + u64 tmp;
1447
1448 smp_mb();
1449
1450 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1451 -"1: ldrexd %0, %H0, [%3]\n"
1452 -" subs %Q0, %Q0, #1\n"
1453 -" sbc %R0, %R0, #0\n"
1454 +"1: ldrexd %1, %H1, [%3]\n"
1455 +" subs %Q0, %Q1, #1\n"
1456 +" sbcs %R0, %R1, #0\n"
1457 +
1458 +#ifdef CONFIG_PAX_REFCOUNT
1459 +" bvc 3f\n"
1460 +" mov %Q0, %Q1\n"
1461 +" mov %R0, %R1\n"
1462 +"2: bkpt 0xf103\n"
1463 +"3:\n"
1464 +#endif
1465 +
1466 " teq %R0, #0\n"
1467 -" bmi 2f\n"
1468 +" bmi 4f\n"
1469 " strexd %1, %0, %H0, [%3]\n"
1470 " teq %1, #0\n"
1471 " bne 1b\n"
1472 -"2:"
1473 +"4:\n"
1474 +
1475 +#ifdef CONFIG_PAX_REFCOUNT
1476 + _ASM_EXTABLE(2b, 4b)
1477 +#endif
1478 +
1479 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1480 : "r" (&v->counter)
1481 : "cc");
1482 @@ -442,13 +841,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1483 " teq %0, %5\n"
1484 " teqeq %H0, %H5\n"
1485 " moveq %1, #0\n"
1486 -" beq 2f\n"
1487 +" beq 4f\n"
1488 " adds %Q0, %Q0, %Q6\n"
1489 -" adc %R0, %R0, %R6\n"
1490 +" adcs %R0, %R0, %R6\n"
1491 +
1492 +#ifdef CONFIG_PAX_REFCOUNT
1493 +" bvc 3f\n"
1494 +"2: bkpt 0xf103\n"
1495 +"3:\n"
1496 +#endif
1497 +
1498 " strexd %2, %0, %H0, [%4]\n"
1499 " teq %2, #0\n"
1500 " bne 1b\n"
1501 -"2:"
1502 +"4:\n"
1503 +
1504 +#ifdef CONFIG_PAX_REFCOUNT
1505 + _ASM_EXTABLE(2b, 4b)
1506 +#endif
1507 +
1508 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1509 : "r" (&v->counter), "r" (u), "r" (a)
1510 : "cc");
1511 @@ -461,10 +872,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1512
1513 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1514 #define atomic64_inc(v) atomic64_add(1LL, (v))
1515 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1516 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1517 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1518 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1519 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1520 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1521 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1522 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1523 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1524 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1525 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1526 index 75fe66b..ba3dee4 100644
1527 --- a/arch/arm/include/asm/cache.h
1528 +++ b/arch/arm/include/asm/cache.h
1529 @@ -4,8 +4,10 @@
1530 #ifndef __ASMARM_CACHE_H
1531 #define __ASMARM_CACHE_H
1532
1533 +#include <linux/const.h>
1534 +
1535 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1536 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1537 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1538
1539 /*
1540 * Memory returned by kmalloc() may be used for DMA, so we must make
1541 @@ -24,5 +26,6 @@
1542 #endif
1543
1544 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1545 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1546
1547 #endif
1548 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1549 index 8b8b616..d973d24 100644
1550 --- a/arch/arm/include/asm/cacheflush.h
1551 +++ b/arch/arm/include/asm/cacheflush.h
1552 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1553 void (*dma_unmap_area)(const void *, size_t, int);
1554
1555 void (*dma_flush_range)(const void *, const void *);
1556 -};
1557 +} __no_const;
1558
1559 /*
1560 * Select the calling method
1561 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1562 index 5233151..87a71fa 100644
1563 --- a/arch/arm/include/asm/checksum.h
1564 +++ b/arch/arm/include/asm/checksum.h
1565 @@ -37,7 +37,19 @@ __wsum
1566 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1567
1568 __wsum
1569 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1570 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1571 +
1572 +static inline __wsum
1573 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1574 +{
1575 + __wsum ret;
1576 + pax_open_userland();
1577 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1578 + pax_close_userland();
1579 + return ret;
1580 +}
1581 +
1582 +
1583
1584 /*
1585 * Fold a partial checksum without adding pseudo headers
1586 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1587 index df2fbba..63fe3e1 100644
1588 --- a/arch/arm/include/asm/cmpxchg.h
1589 +++ b/arch/arm/include/asm/cmpxchg.h
1590 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1591
1592 #define xchg(ptr,x) \
1593 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1594 +#define xchg_unchecked(ptr,x) \
1595 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1596
1597 #include <asm-generic/cmpxchg-local.h>
1598
1599 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1600 index 6ddbe44..b5e38b1 100644
1601 --- a/arch/arm/include/asm/domain.h
1602 +++ b/arch/arm/include/asm/domain.h
1603 @@ -48,18 +48,37 @@
1604 * Domain types
1605 */
1606 #define DOMAIN_NOACCESS 0
1607 -#define DOMAIN_CLIENT 1
1608 #ifdef CONFIG_CPU_USE_DOMAINS
1609 +#define DOMAIN_USERCLIENT 1
1610 +#define DOMAIN_KERNELCLIENT 1
1611 #define DOMAIN_MANAGER 3
1612 +#define DOMAIN_VECTORS DOMAIN_USER
1613 #else
1614 +
1615 +#ifdef CONFIG_PAX_KERNEXEC
1616 #define DOMAIN_MANAGER 1
1617 +#define DOMAIN_KERNEXEC 3
1618 +#else
1619 +#define DOMAIN_MANAGER 1
1620 +#endif
1621 +
1622 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1623 +#define DOMAIN_USERCLIENT 0
1624 +#define DOMAIN_UDEREF 1
1625 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1626 +#else
1627 +#define DOMAIN_USERCLIENT 1
1628 +#define DOMAIN_VECTORS DOMAIN_USER
1629 +#endif
1630 +#define DOMAIN_KERNELCLIENT 1
1631 +
1632 #endif
1633
1634 #define domain_val(dom,type) ((type) << (2*(dom)))
1635
1636 #ifndef __ASSEMBLY__
1637
1638 -#ifdef CONFIG_CPU_USE_DOMAINS
1639 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1640 static inline void set_domain(unsigned val)
1641 {
1642 asm volatile(
1643 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1644 isb();
1645 }
1646
1647 -#define modify_domain(dom,type) \
1648 - do { \
1649 - struct thread_info *thread = current_thread_info(); \
1650 - unsigned int domain = thread->cpu_domain; \
1651 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1652 - thread->cpu_domain = domain | domain_val(dom, type); \
1653 - set_domain(thread->cpu_domain); \
1654 - } while (0)
1655 -
1656 +extern void modify_domain(unsigned int dom, unsigned int type);
1657 #else
1658 static inline void set_domain(unsigned val) { }
1659 static inline void modify_domain(unsigned dom, unsigned type) { }
1660 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1661 index f4b46d3..abc9b2b 100644
1662 --- a/arch/arm/include/asm/elf.h
1663 +++ b/arch/arm/include/asm/elf.h
1664 @@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1665 the loader. We need to make sure that it is out of the way of the program
1666 that it will "exec", and that there is sufficient room for the brk. */
1667
1668 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1669 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1670 +
1671 +#ifdef CONFIG_PAX_ASLR
1672 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1673 +
1674 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1675 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1676 +#endif
1677
1678 /* When the program starts, a1 contains a pointer to a function to be
1679 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1680 @@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1681 extern void elf_set_personality(const struct elf32_hdr *);
1682 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1683
1684 -struct mm_struct;
1685 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1686 -#define arch_randomize_brk arch_randomize_brk
1687 -
1688 #ifdef CONFIG_MMU
1689 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1690 struct linux_binprm;
1691 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1692 index de53547..52b9a28 100644
1693 --- a/arch/arm/include/asm/fncpy.h
1694 +++ b/arch/arm/include/asm/fncpy.h
1695 @@ -81,7 +81,9 @@
1696 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1697 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1698 \
1699 + pax_open_kernel(); \
1700 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1701 + pax_close_kernel(); \
1702 flush_icache_range((unsigned long)(dest_buf), \
1703 (unsigned long)(dest_buf) + (size)); \
1704 \
1705 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1706 index e42cf59..7b94b8f 100644
1707 --- a/arch/arm/include/asm/futex.h
1708 +++ b/arch/arm/include/asm/futex.h
1709 @@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1710 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1711 return -EFAULT;
1712
1713 + pax_open_userland();
1714 +
1715 smp_mb();
1716 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1717 "1: ldrex %1, [%4]\n"
1718 @@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1719 : "cc", "memory");
1720 smp_mb();
1721
1722 + pax_close_userland();
1723 +
1724 *uval = val;
1725 return ret;
1726 }
1727 @@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1728 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1729 return -EFAULT;
1730
1731 + pax_open_userland();
1732 +
1733 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1734 "1: " TUSER(ldr) " %1, [%4]\n"
1735 " teq %1, %2\n"
1736 @@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1737 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1738 : "cc", "memory");
1739
1740 + pax_close_userland();
1741 +
1742 *uval = val;
1743 return ret;
1744 }
1745 @@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1746 return -EFAULT;
1747
1748 pagefault_disable(); /* implies preempt_disable() */
1749 + pax_open_userland();
1750
1751 switch (op) {
1752 case FUTEX_OP_SET:
1753 @@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1754 ret = -ENOSYS;
1755 }
1756
1757 + pax_close_userland();
1758 pagefault_enable(); /* subsumes preempt_enable() */
1759
1760 if (!ret) {
1761 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1762 index 83eb2f7..ed77159 100644
1763 --- a/arch/arm/include/asm/kmap_types.h
1764 +++ b/arch/arm/include/asm/kmap_types.h
1765 @@ -4,6 +4,6 @@
1766 /*
1767 * This is the "bare minimum". AIO seems to require this.
1768 */
1769 -#define KM_TYPE_NR 16
1770 +#define KM_TYPE_NR 17
1771
1772 #endif
1773 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1774 index 9e614a1..3302cca 100644
1775 --- a/arch/arm/include/asm/mach/dma.h
1776 +++ b/arch/arm/include/asm/mach/dma.h
1777 @@ -22,7 +22,7 @@ struct dma_ops {
1778 int (*residue)(unsigned int, dma_t *); /* optional */
1779 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1780 const char *type;
1781 -};
1782 +} __do_const;
1783
1784 struct dma_struct {
1785 void *addr; /* single DMA address */
1786 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1787 index f98c7f3..e5c626d 100644
1788 --- a/arch/arm/include/asm/mach/map.h
1789 +++ b/arch/arm/include/asm/mach/map.h
1790 @@ -23,17 +23,19 @@ struct map_desc {
1791
1792 /* types 0-3 are defined in asm/io.h */
1793 enum {
1794 - MT_UNCACHED = 4,
1795 - MT_CACHECLEAN,
1796 - MT_MINICLEAN,
1797 + MT_UNCACHED_RW = 4,
1798 + MT_CACHECLEAN_RO,
1799 + MT_MINICLEAN_RO,
1800 MT_LOW_VECTORS,
1801 MT_HIGH_VECTORS,
1802 - MT_MEMORY_RWX,
1803 + __MT_MEMORY_RWX,
1804 MT_MEMORY_RW,
1805 - MT_ROM,
1806 - MT_MEMORY_RWX_NONCACHED,
1807 + MT_MEMORY_RX,
1808 + MT_ROM_RX,
1809 + MT_MEMORY_RW_NONCACHED,
1810 + MT_MEMORY_RX_NONCACHED,
1811 MT_MEMORY_RW_DTCM,
1812 - MT_MEMORY_RWX_ITCM,
1813 + MT_MEMORY_RX_ITCM,
1814 MT_MEMORY_RW_SO,
1815 MT_MEMORY_DMA_READY,
1816 };
1817 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1818 index f94784f..9a09a4a 100644
1819 --- a/arch/arm/include/asm/outercache.h
1820 +++ b/arch/arm/include/asm/outercache.h
1821 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1822 #endif
1823 void (*set_debug)(unsigned long);
1824 void (*resume)(void);
1825 -};
1826 +} __no_const;
1827
1828 extern struct outer_cache_fns outer_cache;
1829
1830 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1831 index 4355f0e..cd9168e 100644
1832 --- a/arch/arm/include/asm/page.h
1833 +++ b/arch/arm/include/asm/page.h
1834 @@ -23,6 +23,7 @@
1835
1836 #else
1837
1838 +#include <linux/compiler.h>
1839 #include <asm/glue.h>
1840
1841 /*
1842 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1843 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1844 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1845 unsigned long vaddr, struct vm_area_struct *vma);
1846 -};
1847 +} __no_const;
1848
1849 #ifdef MULTI_USER
1850 extern struct cpu_user_fns cpu_user;
1851 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1852 index 78a7793..e3dc06c 100644
1853 --- a/arch/arm/include/asm/pgalloc.h
1854 +++ b/arch/arm/include/asm/pgalloc.h
1855 @@ -17,6 +17,7 @@
1856 #include <asm/processor.h>
1857 #include <asm/cacheflush.h>
1858 #include <asm/tlbflush.h>
1859 +#include <asm/system_info.h>
1860
1861 #define check_pgt_cache() do { } while (0)
1862
1863 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1864 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1865 }
1866
1867 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1868 +{
1869 + pud_populate(mm, pud, pmd);
1870 +}
1871 +
1872 #else /* !CONFIG_ARM_LPAE */
1873
1874 /*
1875 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1876 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1877 #define pmd_free(mm, pmd) do { } while (0)
1878 #define pud_populate(mm,pmd,pte) BUG()
1879 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1880
1881 #endif /* CONFIG_ARM_LPAE */
1882
1883 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1884 __free_page(pte);
1885 }
1886
1887 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1888 +{
1889 +#ifdef CONFIG_ARM_LPAE
1890 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1891 +#else
1892 + if (addr & SECTION_SIZE)
1893 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1894 + else
1895 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1896 +#endif
1897 + flush_pmd_entry(pmdp);
1898 +}
1899 +
1900 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1901 pmdval_t prot)
1902 {
1903 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1904 static inline void
1905 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1906 {
1907 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1908 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1909 }
1910 #define pmd_pgtable(pmd) pmd_page(pmd)
1911
1912 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1913 index 5cfba15..f415e1a 100644
1914 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1915 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1916 @@ -20,12 +20,15 @@
1917 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1918 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1919 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1920 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1921 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1922 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1923 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1924 +
1925 /*
1926 * - section
1927 */
1928 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1929 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1930 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1931 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1932 @@ -37,6 +40,7 @@
1933 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1934 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1935 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1936 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1937
1938 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1939 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1940 @@ -66,6 +70,7 @@
1941 * - extended small page/tiny page
1942 */
1943 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1944 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1945 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1946 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1947 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1948 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1949 index dfff709..ed4c4e7 100644
1950 --- a/arch/arm/include/asm/pgtable-2level.h
1951 +++ b/arch/arm/include/asm/pgtable-2level.h
1952 @@ -126,6 +126,9 @@
1953 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1954 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1955
1956 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1957 +#define L_PTE_PXN (_AT(pteval_t, 0))
1958 +
1959 /*
1960 * These are the memory types, defined to be compatible with
1961 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1962 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1963 index 626989f..9d67a33 100644
1964 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1965 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1966 @@ -75,6 +75,7 @@
1967 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1968 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1969 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1970 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1971 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1972
1973 /*
1974 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1975 index 85c60ad..b0bbd7e 100644
1976 --- a/arch/arm/include/asm/pgtable-3level.h
1977 +++ b/arch/arm/include/asm/pgtable-3level.h
1978 @@ -82,6 +82,7 @@
1979 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1980 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1981 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1982 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1983 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1984 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1985 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1986 @@ -95,6 +96,7 @@
1987 /*
1988 * To be used in assembly code with the upper page attributes.
1989 */
1990 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1991 #define L_PTE_XN_HIGH (1 << (54 - 32))
1992 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1993
1994 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1995 index 7d59b52..27a12f8 100644
1996 --- a/arch/arm/include/asm/pgtable.h
1997 +++ b/arch/arm/include/asm/pgtable.h
1998 @@ -33,6 +33,9 @@
1999 #include <asm/pgtable-2level.h>
2000 #endif
2001
2002 +#define ktla_ktva(addr) (addr)
2003 +#define ktva_ktla(addr) (addr)
2004 +
2005 /*
2006 * Just any arbitrary offset to the start of the vmalloc VM area: the
2007 * current 8MB value just means that there will be a 8MB "hole" after the
2008 @@ -48,6 +51,9 @@
2009 #define LIBRARY_TEXT_START 0x0c000000
2010
2011 #ifndef __ASSEMBLY__
2012 +extern pteval_t __supported_pte_mask;
2013 +extern pmdval_t __supported_pmd_mask;
2014 +
2015 extern void __pte_error(const char *file, int line, pte_t);
2016 extern void __pmd_error(const char *file, int line, pmd_t);
2017 extern void __pgd_error(const char *file, int line, pgd_t);
2018 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2019 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2020 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2021
2022 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2023 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2024 +
2025 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2026 +#include <asm/domain.h>
2027 +#include <linux/thread_info.h>
2028 +#include <linux/preempt.h>
2029 +
2030 +static inline int test_domain(int domain, int domaintype)
2031 +{
2032 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2033 +}
2034 +#endif
2035 +
2036 +#ifdef CONFIG_PAX_KERNEXEC
2037 +static inline unsigned long pax_open_kernel(void) {
2038 +#ifdef CONFIG_ARM_LPAE
2039 + /* TODO */
2040 +#else
2041 + preempt_disable();
2042 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2043 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2044 +#endif
2045 + return 0;
2046 +}
2047 +
2048 +static inline unsigned long pax_close_kernel(void) {
2049 +#ifdef CONFIG_ARM_LPAE
2050 + /* TODO */
2051 +#else
2052 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2053 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2054 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2055 + preempt_enable_no_resched();
2056 +#endif
2057 + return 0;
2058 +}
2059 +#else
2060 +static inline unsigned long pax_open_kernel(void) { return 0; }
2061 +static inline unsigned long pax_close_kernel(void) { return 0; }
2062 +#endif
2063 +
2064 /*
2065 * This is the lowest virtual address we can permit any user space
2066 * mapping to be mapped at. This is particularly important for
2067 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2068 /*
2069 * The pgprot_* and protection_map entries will be fixed up in runtime
2070 * to include the cachable and bufferable bits based on memory policy,
2071 - * as well as any architecture dependent bits like global/ASID and SMP
2072 - * shared mapping bits.
2073 + * as well as any architecture dependent bits like global/ASID, PXN,
2074 + * and SMP shared mapping bits.
2075 */
2076 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2077
2078 @@ -262,7 +310,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2079 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2080 {
2081 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2082 - L_PTE_NONE | L_PTE_VALID;
2083 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2084 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2085 return pte;
2086 }
2087 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2088 index c4ae171..ea0c0c2 100644
2089 --- a/arch/arm/include/asm/psci.h
2090 +++ b/arch/arm/include/asm/psci.h
2091 @@ -29,7 +29,7 @@ struct psci_operations {
2092 int (*cpu_off)(struct psci_power_state state);
2093 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2094 int (*migrate)(unsigned long cpuid);
2095 -};
2096 +} __no_const;
2097
2098 extern struct psci_operations psci_ops;
2099 extern struct smp_operations psci_smp_ops;
2100 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2101 index 22a3b9b..7f214ee 100644
2102 --- a/arch/arm/include/asm/smp.h
2103 +++ b/arch/arm/include/asm/smp.h
2104 @@ -112,7 +112,7 @@ struct smp_operations {
2105 int (*cpu_disable)(unsigned int cpu);
2106 #endif
2107 #endif
2108 -};
2109 +} __no_const;
2110
2111 /*
2112 * set platform specific SMP operations
2113 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2114 index 71a06b2..8bb9ae1 100644
2115 --- a/arch/arm/include/asm/thread_info.h
2116 +++ b/arch/arm/include/asm/thread_info.h
2117 @@ -88,9 +88,9 @@ struct thread_info {
2118 .flags = 0, \
2119 .preempt_count = INIT_PREEMPT_COUNT, \
2120 .addr_limit = KERNEL_DS, \
2121 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2122 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2123 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2124 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2125 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2126 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2127 .restart_block = { \
2128 .fn = do_no_restart_syscall, \
2129 }, \
2130 @@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2131 #define TIF_SYSCALL_AUDIT 9
2132 #define TIF_SYSCALL_TRACEPOINT 10
2133 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2134 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2135 +/* within 8 bits of TIF_SYSCALL_TRACE
2136 + * to meet flexible second operand requirements
2137 + */
2138 +#define TIF_GRSEC_SETXID 12
2139 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2140 #define TIF_USING_IWMMXT 17
2141 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2142 #define TIF_RESTORE_SIGMASK 20
2143 @@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2144 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2145 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2146 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2147 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2148
2149 /* Checks for any syscall work in entry-common.S */
2150 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2151 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2152 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2153
2154 /*
2155 * Change these and you break ASM code in entry-common.S
2156 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2157 index 72abdc5..35acac1 100644
2158 --- a/arch/arm/include/asm/uaccess.h
2159 +++ b/arch/arm/include/asm/uaccess.h
2160 @@ -18,6 +18,7 @@
2161 #include <asm/domain.h>
2162 #include <asm/unified.h>
2163 #include <asm/compiler.h>
2164 +#include <asm/pgtable.h>
2165
2166 #if __LINUX_ARM_ARCH__ < 6
2167 #include <asm-generic/uaccess-unaligned.h>
2168 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2169 static inline void set_fs(mm_segment_t fs)
2170 {
2171 current_thread_info()->addr_limit = fs;
2172 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2173 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2174 }
2175
2176 #define segment_eq(a,b) ((a) == (b))
2177
2178 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2179 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2180 +
2181 +static inline void pax_open_userland(void)
2182 +{
2183 +
2184 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2185 + if (segment_eq(get_fs(), USER_DS)) {
2186 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2187 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2188 + }
2189 +#endif
2190 +
2191 +}
2192 +
2193 +static inline void pax_close_userland(void)
2194 +{
2195 +
2196 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2197 + if (segment_eq(get_fs(), USER_DS)) {
2198 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2199 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2200 + }
2201 +#endif
2202 +
2203 +}
2204 +
2205 #define __addr_ok(addr) ({ \
2206 unsigned long flag; \
2207 __asm__("cmp %2, %0; movlo %0, #0" \
2208 @@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2209
2210 #define get_user(x,p) \
2211 ({ \
2212 + int __e; \
2213 might_fault(); \
2214 - __get_user_check(x,p); \
2215 + pax_open_userland(); \
2216 + __e = __get_user_check(x,p); \
2217 + pax_close_userland(); \
2218 + __e; \
2219 })
2220
2221 extern int __put_user_1(void *, unsigned int);
2222 @@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2223
2224 #define put_user(x,p) \
2225 ({ \
2226 + int __e; \
2227 might_fault(); \
2228 - __put_user_check(x,p); \
2229 + pax_open_userland(); \
2230 + __e = __put_user_check(x,p); \
2231 + pax_close_userland(); \
2232 + __e; \
2233 })
2234
2235 #else /* CONFIG_MMU */
2236 @@ -220,6 +256,7 @@ static inline void set_fs(mm_segment_t fs)
2237
2238 #endif /* CONFIG_MMU */
2239
2240 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2241 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2242
2243 #define user_addr_max() \
2244 @@ -237,13 +274,17 @@ static inline void set_fs(mm_segment_t fs)
2245 #define __get_user(x,ptr) \
2246 ({ \
2247 long __gu_err = 0; \
2248 + pax_open_userland(); \
2249 __get_user_err((x),(ptr),__gu_err); \
2250 + pax_close_userland(); \
2251 __gu_err; \
2252 })
2253
2254 #define __get_user_error(x,ptr,err) \
2255 ({ \
2256 + pax_open_userland(); \
2257 __get_user_err((x),(ptr),err); \
2258 + pax_close_userland(); \
2259 (void) 0; \
2260 })
2261
2262 @@ -319,13 +360,17 @@ do { \
2263 #define __put_user(x,ptr) \
2264 ({ \
2265 long __pu_err = 0; \
2266 + pax_open_userland(); \
2267 __put_user_err((x),(ptr),__pu_err); \
2268 + pax_close_userland(); \
2269 __pu_err; \
2270 })
2271
2272 #define __put_user_error(x,ptr,err) \
2273 ({ \
2274 + pax_open_userland(); \
2275 __put_user_err((x),(ptr),err); \
2276 + pax_close_userland(); \
2277 (void) 0; \
2278 })
2279
2280 @@ -425,11 +470,44 @@ do { \
2281
2282
2283 #ifdef CONFIG_MMU
2284 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2285 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2286 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2287 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2288 +
2289 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2290 +{
2291 + unsigned long ret;
2292 +
2293 + check_object_size(to, n, false);
2294 + pax_open_userland();
2295 + ret = ___copy_from_user(to, from, n);
2296 + pax_close_userland();
2297 + return ret;
2298 +}
2299 +
2300 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2301 +{
2302 + unsigned long ret;
2303 +
2304 + check_object_size(from, n, true);
2305 + pax_open_userland();
2306 + ret = ___copy_to_user(to, from, n);
2307 + pax_close_userland();
2308 + return ret;
2309 +}
2310 +
2311 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2312 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2313 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2314 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2315 +
2316 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2317 +{
2318 + unsigned long ret;
2319 + pax_open_userland();
2320 + ret = ___clear_user(addr, n);
2321 + pax_close_userland();
2322 + return ret;
2323 +}
2324 +
2325 #else
2326 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2327 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2328 @@ -438,6 +516,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2329
2330 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2331 {
2332 + if ((long)n < 0)
2333 + return n;
2334 +
2335 if (access_ok(VERIFY_READ, from, n))
2336 n = __copy_from_user(to, from, n);
2337 else /* security hole - plug it */
2338 @@ -447,6 +528,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2339
2340 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2341 {
2342 + if ((long)n < 0)
2343 + return n;
2344 +
2345 if (access_ok(VERIFY_WRITE, to, n))
2346 n = __copy_to_user(to, from, n);
2347 return n;
2348 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2349 index 5af0ed1..cea83883 100644
2350 --- a/arch/arm/include/uapi/asm/ptrace.h
2351 +++ b/arch/arm/include/uapi/asm/ptrace.h
2352 @@ -92,7 +92,7 @@
2353 * ARMv7 groups of PSR bits
2354 */
2355 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2356 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2357 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2358 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2359 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2360
2361 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2362 index 85e664b..419a1cd 100644
2363 --- a/arch/arm/kernel/armksyms.c
2364 +++ b/arch/arm/kernel/armksyms.c
2365 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2366
2367 /* networking */
2368 EXPORT_SYMBOL(csum_partial);
2369 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2370 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2371 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2372 EXPORT_SYMBOL(__csum_ipv6_magic);
2373
2374 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2375 #ifdef CONFIG_MMU
2376 EXPORT_SYMBOL(copy_page);
2377
2378 -EXPORT_SYMBOL(__copy_from_user);
2379 -EXPORT_SYMBOL(__copy_to_user);
2380 -EXPORT_SYMBOL(__clear_user);
2381 +EXPORT_SYMBOL(___copy_from_user);
2382 +EXPORT_SYMBOL(___copy_to_user);
2383 +EXPORT_SYMBOL(___clear_user);
2384
2385 EXPORT_SYMBOL(__get_user_1);
2386 EXPORT_SYMBOL(__get_user_2);
2387 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2388 index 1879e8d..b2207fc 100644
2389 --- a/arch/arm/kernel/entry-armv.S
2390 +++ b/arch/arm/kernel/entry-armv.S
2391 @@ -47,6 +47,87 @@
2392 9997:
2393 .endm
2394
2395 + .macro pax_enter_kernel
2396 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2397 + @ make aligned space for saved DACR
2398 + sub sp, sp, #8
2399 + @ save regs
2400 + stmdb sp!, {r1, r2}
2401 + @ read DACR from cpu_domain into r1
2402 + mov r2, sp
2403 + @ assume 8K pages, since we have to split the immediate in two
2404 + bic r2, r2, #(0x1fc0)
2405 + bic r2, r2, #(0x3f)
2406 + ldr r1, [r2, #TI_CPU_DOMAIN]
2407 + @ store old DACR on stack
2408 + str r1, [sp, #8]
2409 +#ifdef CONFIG_PAX_KERNEXEC
2410 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2411 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2412 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2413 +#endif
2414 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2415 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2416 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2417 +#endif
2418 + @ write r1 to current_thread_info()->cpu_domain
2419 + str r1, [r2, #TI_CPU_DOMAIN]
2420 + @ write r1 to DACR
2421 + mcr p15, 0, r1, c3, c0, 0
2422 + @ instruction sync
2423 + instr_sync
2424 + @ restore regs
2425 + ldmia sp!, {r1, r2}
2426 +#endif
2427 + .endm
2428 +
2429 + .macro pax_open_userland
2430 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2431 + @ save regs
2432 + stmdb sp!, {r0, r1}
2433 + @ read DACR from cpu_domain into r1
2434 + mov r0, sp
2435 + @ assume 8K pages, since we have to split the immediate in two
2436 + bic r0, r0, #(0x1fc0)
2437 + bic r0, r0, #(0x3f)
2438 + ldr r1, [r0, #TI_CPU_DOMAIN]
2439 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2440 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2441 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2442 + @ write r1 to current_thread_info()->cpu_domain
2443 + str r1, [r0, #TI_CPU_DOMAIN]
2444 + @ write r1 to DACR
2445 + mcr p15, 0, r1, c3, c0, 0
2446 + @ instruction sync
2447 + instr_sync
2448 + @ restore regs
2449 + ldmia sp!, {r0, r1}
2450 +#endif
2451 + .endm
2452 +
2453 + .macro pax_close_userland
2454 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2455 + @ save regs
2456 + stmdb sp!, {r0, r1}
2457 + @ read DACR from cpu_domain into r1
2458 + mov r0, sp
2459 + @ assume 8K pages, since we have to split the immediate in two
2460 + bic r0, r0, #(0x1fc0)
2461 + bic r0, r0, #(0x3f)
2462 + ldr r1, [r0, #TI_CPU_DOMAIN]
2463 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2464 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2465 + @ write r1 to current_thread_info()->cpu_domain
2466 + str r1, [r0, #TI_CPU_DOMAIN]
2467 + @ write r1 to DACR
2468 + mcr p15, 0, r1, c3, c0, 0
2469 + @ instruction sync
2470 + instr_sync
2471 + @ restore regs
2472 + ldmia sp!, {r0, r1}
2473 +#endif
2474 + .endm
2475 +
2476 .macro pabt_helper
2477 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2478 #ifdef MULTI_PABORT
2479 @@ -89,11 +170,15 @@
2480 * Invalid mode handlers
2481 */
2482 .macro inv_entry, reason
2483 +
2484 + pax_enter_kernel
2485 +
2486 sub sp, sp, #S_FRAME_SIZE
2487 ARM( stmib sp, {r1 - lr} )
2488 THUMB( stmia sp, {r0 - r12} )
2489 THUMB( str sp, [sp, #S_SP] )
2490 THUMB( str lr, [sp, #S_LR] )
2491 +
2492 mov r1, #\reason
2493 .endm
2494
2495 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2496 .macro svc_entry, stack_hole=0
2497 UNWIND(.fnstart )
2498 UNWIND(.save {r0 - pc} )
2499 +
2500 + pax_enter_kernel
2501 +
2502 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2503 +
2504 #ifdef CONFIG_THUMB2_KERNEL
2505 SPFIX( str r0, [sp] ) @ temporarily saved
2506 SPFIX( mov r0, sp )
2507 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2508 ldmia r0, {r3 - r5}
2509 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2510 mov r6, #-1 @ "" "" "" ""
2511 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2512 + @ offset sp by 8 as done in pax_enter_kernel
2513 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2514 +#else
2515 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2516 +#endif
2517 SPFIX( addeq r2, r2, #4 )
2518 str r3, [sp, #-4]! @ save the "real" r0 copied
2519 @ from the exception stack
2520 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2521 .macro usr_entry
2522 UNWIND(.fnstart )
2523 UNWIND(.cantunwind ) @ don't unwind the user space
2524 +
2525 + pax_enter_kernel_user
2526 +
2527 sub sp, sp, #S_FRAME_SIZE
2528 ARM( stmib sp, {r1 - r12} )
2529 THUMB( stmia sp, {r0 - r12} )
2530 @@ -416,7 +513,9 @@ __und_usr:
2531 tst r3, #PSR_T_BIT @ Thumb mode?
2532 bne __und_usr_thumb
2533 sub r4, r2, #4 @ ARM instr at LR - 4
2534 + pax_open_userland
2535 1: ldrt r0, [r4]
2536 + pax_close_userland
2537 ARM_BE8(rev r0, r0) @ little endian instruction
2538
2539 @ r0 = 32-bit ARM instruction which caused the exception
2540 @@ -450,11 +549,15 @@ __und_usr_thumb:
2541 */
2542 .arch armv6t2
2543 #endif
2544 + pax_open_userland
2545 2: ldrht r5, [r4]
2546 + pax_close_userland
2547 ARM_BE8(rev16 r5, r5) @ little endian instruction
2548 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2549 blo __und_usr_fault_16 @ 16bit undefined instruction
2550 + pax_open_userland
2551 3: ldrht r0, [r2]
2552 + pax_close_userland
2553 ARM_BE8(rev16 r0, r0) @ little endian instruction
2554 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2555 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2556 @@ -484,7 +587,8 @@ ENDPROC(__und_usr)
2557 */
2558 .pushsection .fixup, "ax"
2559 .align 2
2560 -4: mov pc, r9
2561 +4: pax_close_userland
2562 + mov pc, r9
2563 .popsection
2564 .pushsection __ex_table,"a"
2565 .long 1b, 4b
2566 @@ -694,7 +798,7 @@ ENTRY(__switch_to)
2567 THUMB( str lr, [ip], #4 )
2568 ldr r4, [r2, #TI_TP_VALUE]
2569 ldr r5, [r2, #TI_TP_VALUE + 4]
2570 -#ifdef CONFIG_CPU_USE_DOMAINS
2571 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2572 ldr r6, [r2, #TI_CPU_DOMAIN]
2573 #endif
2574 switch_tls r1, r4, r5, r3, r7
2575 @@ -703,7 +807,7 @@ ENTRY(__switch_to)
2576 ldr r8, =__stack_chk_guard
2577 ldr r7, [r7, #TSK_STACK_CANARY]
2578 #endif
2579 -#ifdef CONFIG_CPU_USE_DOMAINS
2580 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2581 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2582 #endif
2583 mov r5, r0
2584 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2585 index a2dcafd..1048b5a 100644
2586 --- a/arch/arm/kernel/entry-common.S
2587 +++ b/arch/arm/kernel/entry-common.S
2588 @@ -10,18 +10,46 @@
2589
2590 #include <asm/unistd.h>
2591 #include <asm/ftrace.h>
2592 +#include <asm/domain.h>
2593 #include <asm/unwind.h>
2594
2595 +#include "entry-header.S"
2596 +
2597 #ifdef CONFIG_NEED_RET_TO_USER
2598 #include <mach/entry-macro.S>
2599 #else
2600 .macro arch_ret_to_user, tmp1, tmp2
2601 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2602 + @ save regs
2603 + stmdb sp!, {r1, r2}
2604 + @ read DACR from cpu_domain into r1
2605 + mov r2, sp
2606 + @ assume 8K pages, since we have to split the immediate in two
2607 + bic r2, r2, #(0x1fc0)
2608 + bic r2, r2, #(0x3f)
2609 + ldr r1, [r2, #TI_CPU_DOMAIN]
2610 +#ifdef CONFIG_PAX_KERNEXEC
2611 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2612 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2613 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2614 +#endif
2615 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2616 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2617 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2618 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2619 +#endif
2620 + @ write r1 to current_thread_info()->cpu_domain
2621 + str r1, [r2, #TI_CPU_DOMAIN]
2622 + @ write r1 to DACR
2623 + mcr p15, 0, r1, c3, c0, 0
2624 + @ instruction sync
2625 + instr_sync
2626 + @ restore regs
2627 + ldmia sp!, {r1, r2}
2628 +#endif
2629 .endm
2630 #endif
2631
2632 -#include "entry-header.S"
2633 -
2634 -
2635 .align 5
2636 /*
2637 * This is the fast syscall return path. We do as little as
2638 @@ -411,6 +439,12 @@ ENTRY(vector_swi)
2639 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2640 #endif
2641
2642 + /*
2643 + * do this here to avoid a performance hit of wrapping the code above
2644 + * that directly dereferences userland to parse the SWI instruction
2645 + */
2646 + pax_enter_kernel_user
2647 +
2648 adr tbl, sys_call_table @ load syscall table pointer
2649
2650 #if defined(CONFIG_OABI_COMPAT)
2651 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2652 index 39f89fb..d612bd9 100644
2653 --- a/arch/arm/kernel/entry-header.S
2654 +++ b/arch/arm/kernel/entry-header.S
2655 @@ -184,6 +184,60 @@
2656 msr cpsr_c, \rtemp @ switch back to the SVC mode
2657 .endm
2658
2659 + .macro pax_enter_kernel_user
2660 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2661 + @ save regs
2662 + stmdb sp!, {r0, r1}
2663 + @ read DACR from cpu_domain into r1
2664 + mov r0, sp
2665 + @ assume 8K pages, since we have to split the immediate in two
2666 + bic r0, r0, #(0x1fc0)
2667 + bic r0, r0, #(0x3f)
2668 + ldr r1, [r0, #TI_CPU_DOMAIN]
2669 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2670 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2671 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2672 +#endif
2673 +#ifdef CONFIG_PAX_KERNEXEC
2674 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2675 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2676 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2677 +#endif
2678 + @ write r1 to current_thread_info()->cpu_domain
2679 + str r1, [r0, #TI_CPU_DOMAIN]
2680 + @ write r1 to DACR
2681 + mcr p15, 0, r1, c3, c0, 0
2682 + @ instruction sync
2683 + instr_sync
2684 + @ restore regs
2685 + ldmia sp!, {r0, r1}
2686 +#endif
2687 + .endm
2688 +
2689 + .macro pax_exit_kernel
2690 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2691 + @ save regs
2692 + stmdb sp!, {r0, r1}
2693 + @ read old DACR from stack into r1
2694 + ldr r1, [sp, #(8 + S_SP)]
2695 + sub r1, r1, #8
2696 + ldr r1, [r1]
2697 +
2698 + @ write r1 to current_thread_info()->cpu_domain
2699 + mov r0, sp
2700 + @ assume 8K pages, since we have to split the immediate in two
2701 + bic r0, r0, #(0x1fc0)
2702 + bic r0, r0, #(0x3f)
2703 + str r1, [r0, #TI_CPU_DOMAIN]
2704 + @ write r1 to DACR
2705 + mcr p15, 0, r1, c3, c0, 0
2706 + @ instruction sync
2707 + instr_sync
2708 + @ restore regs
2709 + ldmia sp!, {r0, r1}
2710 +#endif
2711 + .endm
2712 +
2713 #ifndef CONFIG_THUMB2_KERNEL
2714 .macro svc_exit, rpsr, irq = 0
2715 .if \irq != 0
2716 @@ -203,6 +257,9 @@
2717 blne trace_hardirqs_off
2718 #endif
2719 .endif
2720 +
2721 + pax_exit_kernel
2722 +
2723 msr spsr_cxsf, \rpsr
2724 #if defined(CONFIG_CPU_V6)
2725 ldr r0, [sp]
2726 @@ -266,6 +323,9 @@
2727 blne trace_hardirqs_off
2728 #endif
2729 .endif
2730 +
2731 + pax_exit_kernel
2732 +
2733 ldr lr, [sp, #S_SP] @ top of the stack
2734 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2735 clrex @ clear the exclusive monitor
2736 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2737 index 918875d..cd5fa27 100644
2738 --- a/arch/arm/kernel/fiq.c
2739 +++ b/arch/arm/kernel/fiq.c
2740 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2741 void *base = vectors_page;
2742 unsigned offset = FIQ_OFFSET;
2743
2744 + pax_open_kernel();
2745 memcpy(base + offset, start, length);
2746 + pax_close_kernel();
2747 +
2748 if (!cache_is_vipt_nonaliasing())
2749 flush_icache_range((unsigned long)base + offset, offset +
2750 length);
2751 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2752 index f5f381d..a6f36a1 100644
2753 --- a/arch/arm/kernel/head.S
2754 +++ b/arch/arm/kernel/head.S
2755 @@ -437,7 +437,7 @@ __enable_mmu:
2756 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2757 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2758 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2759 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2760 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2761 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2762 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2763 #endif
2764 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2765 index 45e4781..8eac93d 100644
2766 --- a/arch/arm/kernel/module.c
2767 +++ b/arch/arm/kernel/module.c
2768 @@ -38,12 +38,39 @@
2769 #endif
2770
2771 #ifdef CONFIG_MMU
2772 -void *module_alloc(unsigned long size)
2773 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2774 {
2775 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2776 + return NULL;
2777 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2778 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2779 + GFP_KERNEL, prot, NUMA_NO_NODE,
2780 __builtin_return_address(0));
2781 }
2782 +
2783 +void *module_alloc(unsigned long size)
2784 +{
2785 +
2786 +#ifdef CONFIG_PAX_KERNEXEC
2787 + return __module_alloc(size, PAGE_KERNEL);
2788 +#else
2789 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2790 +#endif
2791 +
2792 +}
2793 +
2794 +#ifdef CONFIG_PAX_KERNEXEC
2795 +void module_free_exec(struct module *mod, void *module_region)
2796 +{
2797 + module_free(mod, module_region);
2798 +}
2799 +EXPORT_SYMBOL(module_free_exec);
2800 +
2801 +void *module_alloc_exec(unsigned long size)
2802 +{
2803 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2804 +}
2805 +EXPORT_SYMBOL(module_alloc_exec);
2806 +#endif
2807 #endif
2808
2809 int
2810 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2811 index 07314af..c46655c 100644
2812 --- a/arch/arm/kernel/patch.c
2813 +++ b/arch/arm/kernel/patch.c
2814 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2815 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2816 int size;
2817
2818 + pax_open_kernel();
2819 if (thumb2 && __opcode_is_thumb16(insn)) {
2820 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2821 size = sizeof(u16);
2822 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2823 *(u32 *)addr = insn;
2824 size = sizeof(u32);
2825 }
2826 + pax_close_kernel();
2827
2828 flush_icache_range((uintptr_t)(addr),
2829 (uintptr_t)(addr) + size);
2830 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2831 index 92f7b15..7048500 100644
2832 --- a/arch/arm/kernel/process.c
2833 +++ b/arch/arm/kernel/process.c
2834 @@ -217,6 +217,7 @@ void machine_power_off(void)
2835
2836 if (pm_power_off)
2837 pm_power_off();
2838 + BUG();
2839 }
2840
2841 /*
2842 @@ -230,7 +231,7 @@ void machine_power_off(void)
2843 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2844 * to use. Implementing such co-ordination would be essentially impossible.
2845 */
2846 -void machine_restart(char *cmd)
2847 +__noreturn void machine_restart(char *cmd)
2848 {
2849 local_irq_disable();
2850 smp_send_stop();
2851 @@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2852
2853 show_regs_print_info(KERN_DEFAULT);
2854
2855 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2856 - print_symbol("LR is at %s\n", regs->ARM_lr);
2857 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2858 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2859 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2860 "sp : %08lx ip : %08lx fp : %08lx\n",
2861 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2862 @@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2863 return 0;
2864 }
2865
2866 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2867 -{
2868 - unsigned long range_end = mm->brk + 0x02000000;
2869 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2870 -}
2871 -
2872 #ifdef CONFIG_MMU
2873 #ifdef CONFIG_KUSER_HELPERS
2874 /*
2875 @@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2876
2877 static int __init gate_vma_init(void)
2878 {
2879 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2880 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2881 return 0;
2882 }
2883 arch_initcall(gate_vma_init);
2884 @@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2885
2886 const char *arch_vma_name(struct vm_area_struct *vma)
2887 {
2888 - return is_gate_vma(vma) ? "[vectors]" :
2889 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2890 - "[sigpage]" : NULL;
2891 + return is_gate_vma(vma) ? "[vectors]" : NULL;
2892 }
2893
2894 -static struct page *signal_page;
2895 -extern struct page *get_signal_page(void);
2896 -
2897 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2898 {
2899 struct mm_struct *mm = current->mm;
2900 - unsigned long addr;
2901 - int ret;
2902 -
2903 - if (!signal_page)
2904 - signal_page = get_signal_page();
2905 - if (!signal_page)
2906 - return -ENOMEM;
2907
2908 down_write(&mm->mmap_sem);
2909 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2910 - if (IS_ERR_VALUE(addr)) {
2911 - ret = addr;
2912 - goto up_fail;
2913 - }
2914 -
2915 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
2916 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2917 - &signal_page);
2918 -
2919 - if (ret == 0)
2920 - mm->context.sigpage = addr;
2921 -
2922 - up_fail:
2923 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2924 up_write(&mm->mmap_sem);
2925 - return ret;
2926 + return 0;
2927 }
2928 #endif
2929 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2930 index 4693188..4596c5e 100644
2931 --- a/arch/arm/kernel/psci.c
2932 +++ b/arch/arm/kernel/psci.c
2933 @@ -24,7 +24,7 @@
2934 #include <asm/opcodes-virt.h>
2935 #include <asm/psci.h>
2936
2937 -struct psci_operations psci_ops;
2938 +struct psci_operations psci_ops __read_only;
2939
2940 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2941
2942 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2943 index 0dd3b79..e018f64 100644
2944 --- a/arch/arm/kernel/ptrace.c
2945 +++ b/arch/arm/kernel/ptrace.c
2946 @@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2947 return current_thread_info()->syscall;
2948 }
2949
2950 +#ifdef CONFIG_GRKERNSEC_SETXID
2951 +extern void gr_delayed_cred_worker(void);
2952 +#endif
2953 +
2954 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2955 {
2956 current_thread_info()->syscall = scno;
2957
2958 +#ifdef CONFIG_GRKERNSEC_SETXID
2959 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2960 + gr_delayed_cred_worker();
2961 +#endif
2962 +
2963 /* Do the secure computing check first; failures should be fast. */
2964 if (secure_computing(scno) == -1)
2965 return -1;
2966 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2967 index 1e8b030..37c3022 100644
2968 --- a/arch/arm/kernel/setup.c
2969 +++ b/arch/arm/kernel/setup.c
2970 @@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2971 unsigned int elf_hwcap __read_mostly;
2972 EXPORT_SYMBOL(elf_hwcap);
2973
2974 +pteval_t __supported_pte_mask __read_only;
2975 +pmdval_t __supported_pmd_mask __read_only;
2976
2977 #ifdef MULTI_CPU
2978 -struct processor processor __read_mostly;
2979 +struct processor processor __read_only;
2980 #endif
2981 #ifdef MULTI_TLB
2982 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2983 +struct cpu_tlb_fns cpu_tlb __read_only;
2984 #endif
2985 #ifdef MULTI_USER
2986 -struct cpu_user_fns cpu_user __read_mostly;
2987 +struct cpu_user_fns cpu_user __read_only;
2988 #endif
2989 #ifdef MULTI_CACHE
2990 -struct cpu_cache_fns cpu_cache __read_mostly;
2991 +struct cpu_cache_fns cpu_cache __read_only;
2992 #endif
2993 #ifdef CONFIG_OUTER_CACHE
2994 -struct outer_cache_fns outer_cache __read_mostly;
2995 +struct outer_cache_fns outer_cache __read_only;
2996 EXPORT_SYMBOL(outer_cache);
2997 #endif
2998
2999 @@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3000 asm("mrc p15, 0, %0, c0, c1, 4"
3001 : "=r" (mmfr0));
3002 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3003 - (mmfr0 & 0x000000f0) >= 0x00000030)
3004 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3005 cpu_arch = CPU_ARCH_ARMv7;
3006 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3007 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3008 + __supported_pte_mask |= L_PTE_PXN;
3009 + __supported_pmd_mask |= PMD_PXNTABLE;
3010 + }
3011 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3012 (mmfr0 & 0x000000f0) == 0x00000020)
3013 cpu_arch = CPU_ARCH_ARMv6;
3014 else
3015 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3016 index 04d6388..5115238 100644
3017 --- a/arch/arm/kernel/signal.c
3018 +++ b/arch/arm/kernel/signal.c
3019 @@ -23,8 +23,6 @@
3020
3021 extern const unsigned long sigreturn_codes[7];
3022
3023 -static unsigned long signal_return_offset;
3024 -
3025 #ifdef CONFIG_CRUNCH
3026 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3027 {
3028 @@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3029 * except when the MPU has protected the vectors
3030 * page from PL0
3031 */
3032 - retcode = mm->context.sigpage + signal_return_offset +
3033 - (idx << 2) + thumb;
3034 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3035 } else
3036 #endif
3037 {
3038 @@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3039 } while (thread_flags & _TIF_WORK_MASK);
3040 return 0;
3041 }
3042 -
3043 -struct page *get_signal_page(void)
3044 -{
3045 - unsigned long ptr;
3046 - unsigned offset;
3047 - struct page *page;
3048 - void *addr;
3049 -
3050 - page = alloc_pages(GFP_KERNEL, 0);
3051 -
3052 - if (!page)
3053 - return NULL;
3054 -
3055 - addr = page_address(page);
3056 -
3057 - /* Give the signal return code some randomness */
3058 - offset = 0x200 + (get_random_int() & 0x7fc);
3059 - signal_return_offset = offset;
3060 -
3061 - /*
3062 - * Copy signal return handlers into the vector page, and
3063 - * set sigreturn to be a pointer to these.
3064 - */
3065 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3066 -
3067 - ptr = (unsigned long)addr + offset;
3068 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3069 -
3070 - return page;
3071 -}
3072 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3073 index b7b4c86..47c4f77 100644
3074 --- a/arch/arm/kernel/smp.c
3075 +++ b/arch/arm/kernel/smp.c
3076 @@ -73,7 +73,7 @@ enum ipi_msg_type {
3077
3078 static DECLARE_COMPLETION(cpu_running);
3079
3080 -static struct smp_operations smp_ops;
3081 +static struct smp_operations smp_ops __read_only;
3082
3083 void __init smp_set_ops(struct smp_operations *ops)
3084 {
3085 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3086 index 7a3be1d..b00c7de 100644
3087 --- a/arch/arm/kernel/tcm.c
3088 +++ b/arch/arm/kernel/tcm.c
3089 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3090 .virtual = ITCM_OFFSET,
3091 .pfn = __phys_to_pfn(ITCM_OFFSET),
3092 .length = 0,
3093 - .type = MT_MEMORY_RWX_ITCM,
3094 + .type = MT_MEMORY_RX_ITCM,
3095 }
3096 };
3097
3098 @@ -267,7 +267,9 @@ no_dtcm:
3099 start = &__sitcm_text;
3100 end = &__eitcm_text;
3101 ram = &__itcm_start;
3102 + pax_open_kernel();
3103 memcpy(start, ram, itcm_code_sz);
3104 + pax_close_kernel();
3105 pr_debug("CPU ITCM: copied code from %p - %p\n",
3106 start, end);
3107 itcm_present = true;
3108 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3109 index 172ee18..ce4ec3d 100644
3110 --- a/arch/arm/kernel/traps.c
3111 +++ b/arch/arm/kernel/traps.c
3112 @@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3113 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3114 {
3115 #ifdef CONFIG_KALLSYMS
3116 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3117 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3118 #else
3119 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3120 #endif
3121 @@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3122 static int die_owner = -1;
3123 static unsigned int die_nest_count;
3124
3125 +extern void gr_handle_kernel_exploit(void);
3126 +
3127 static unsigned long oops_begin(void)
3128 {
3129 int cpu;
3130 @@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3131 panic("Fatal exception in interrupt");
3132 if (panic_on_oops)
3133 panic("Fatal exception");
3134 +
3135 + gr_handle_kernel_exploit();
3136 +
3137 if (signr)
3138 do_exit(signr);
3139 }
3140 @@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3141 * The user helper at 0xffff0fe0 must be used instead.
3142 * (see entry-armv.S for details)
3143 */
3144 + pax_open_kernel();
3145 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3146 + pax_close_kernel();
3147 }
3148 return 0;
3149
3150 @@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3151 kuser_init(vectors_base);
3152
3153 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3154 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3155 +
3156 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3157 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3158 +#endif
3159 +
3160 #else /* ifndef CONFIG_CPU_V7M */
3161 /*
3162 * on V7-M there is no need to copy the vector table to a dedicated
3163 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3164 index 7bcee5c..e2f3249 100644
3165 --- a/arch/arm/kernel/vmlinux.lds.S
3166 +++ b/arch/arm/kernel/vmlinux.lds.S
3167 @@ -8,7 +8,11 @@
3168 #include <asm/thread_info.h>
3169 #include <asm/memory.h>
3170 #include <asm/page.h>
3171 -
3172 +
3173 +#ifdef CONFIG_PAX_KERNEXEC
3174 +#include <asm/pgtable.h>
3175 +#endif
3176 +
3177 #define PROC_INFO \
3178 . = ALIGN(4); \
3179 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3180 @@ -34,7 +38,7 @@
3181 #endif
3182
3183 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3184 - defined(CONFIG_GENERIC_BUG)
3185 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3186 #define ARM_EXIT_KEEP(x) x
3187 #define ARM_EXIT_DISCARD(x)
3188 #else
3189 @@ -90,6 +94,11 @@ SECTIONS
3190 _text = .;
3191 HEAD_TEXT
3192 }
3193 +
3194 +#ifdef CONFIG_PAX_KERNEXEC
3195 + . = ALIGN(1<<SECTION_SHIFT);
3196 +#endif
3197 +
3198 .text : { /* Real text segment */
3199 _stext = .; /* Text and read-only data */
3200 __exception_text_start = .;
3201 @@ -112,6 +121,8 @@ SECTIONS
3202 ARM_CPU_KEEP(PROC_INFO)
3203 }
3204
3205 + _etext = .; /* End of text section */
3206 +
3207 RO_DATA(PAGE_SIZE)
3208
3209 . = ALIGN(4);
3210 @@ -142,7 +153,9 @@ SECTIONS
3211
3212 NOTES
3213
3214 - _etext = .; /* End of text and rodata section */
3215 +#ifdef CONFIG_PAX_KERNEXEC
3216 + . = ALIGN(1<<SECTION_SHIFT);
3217 +#endif
3218
3219 #ifndef CONFIG_XIP_KERNEL
3220 . = ALIGN(PAGE_SIZE);
3221 @@ -220,6 +233,11 @@ SECTIONS
3222 . = PAGE_OFFSET + TEXT_OFFSET;
3223 #else
3224 __init_end = .;
3225 +
3226 +#ifdef CONFIG_PAX_KERNEXEC
3227 + . = ALIGN(1<<SECTION_SHIFT);
3228 +#endif
3229 +
3230 . = ALIGN(THREAD_SIZE);
3231 __data_loc = .;
3232 #endif
3233 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3234 index bd18bb8..87ede26 100644
3235 --- a/arch/arm/kvm/arm.c
3236 +++ b/arch/arm/kvm/arm.c
3237 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3238 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3239
3240 /* The VMID used in the VTTBR */
3241 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3242 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3243 static u8 kvm_next_vmid;
3244 static DEFINE_SPINLOCK(kvm_vmid_lock);
3245
3246 @@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
3247 */
3248 static bool need_new_vmid_gen(struct kvm *kvm)
3249 {
3250 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3251 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3252 }
3253
3254 /**
3255 @@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
3256
3257 /* First user of a new VMID generation? */
3258 if (unlikely(kvm_next_vmid == 0)) {
3259 - atomic64_inc(&kvm_vmid_gen);
3260 + atomic64_inc_unchecked(&kvm_vmid_gen);
3261 kvm_next_vmid = 1;
3262
3263 /*
3264 @@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
3265 kvm_call_hyp(__kvm_flush_vm_context);
3266 }
3267
3268 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3269 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3270 kvm->arch.vmid = kvm_next_vmid;
3271 kvm_next_vmid++;
3272
3273 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3274 index 14a0d98..7771a7d 100644
3275 --- a/arch/arm/lib/clear_user.S
3276 +++ b/arch/arm/lib/clear_user.S
3277 @@ -12,14 +12,14 @@
3278
3279 .text
3280
3281 -/* Prototype: int __clear_user(void *addr, size_t sz)
3282 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3283 * Purpose : clear some user memory
3284 * Params : addr - user memory address to clear
3285 * : sz - number of bytes to clear
3286 * Returns : number of bytes NOT cleared
3287 */
3288 ENTRY(__clear_user_std)
3289 -WEAK(__clear_user)
3290 +WEAK(___clear_user)
3291 stmfd sp!, {r1, lr}
3292 mov r2, #0
3293 cmp r1, #4
3294 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3295 USER( strnebt r2, [r0])
3296 mov r0, #0
3297 ldmfd sp!, {r1, pc}
3298 -ENDPROC(__clear_user)
3299 +ENDPROC(___clear_user)
3300 ENDPROC(__clear_user_std)
3301
3302 .pushsection .fixup,"ax"
3303 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3304 index 66a477a..bee61d3 100644
3305 --- a/arch/arm/lib/copy_from_user.S
3306 +++ b/arch/arm/lib/copy_from_user.S
3307 @@ -16,7 +16,7 @@
3308 /*
3309 * Prototype:
3310 *
3311 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3312 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3313 *
3314 * Purpose:
3315 *
3316 @@ -84,11 +84,11 @@
3317
3318 .text
3319
3320 -ENTRY(__copy_from_user)
3321 +ENTRY(___copy_from_user)
3322
3323 #include "copy_template.S"
3324
3325 -ENDPROC(__copy_from_user)
3326 +ENDPROC(___copy_from_user)
3327
3328 .pushsection .fixup,"ax"
3329 .align 0
3330 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3331 index 6ee2f67..d1cce76 100644
3332 --- a/arch/arm/lib/copy_page.S
3333 +++ b/arch/arm/lib/copy_page.S
3334 @@ -10,6 +10,7 @@
3335 * ASM optimised string functions
3336 */
3337 #include <linux/linkage.h>
3338 +#include <linux/const.h>
3339 #include <asm/assembler.h>
3340 #include <asm/asm-offsets.h>
3341 #include <asm/cache.h>
3342 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3343 index d066df6..df28194 100644
3344 --- a/arch/arm/lib/copy_to_user.S
3345 +++ b/arch/arm/lib/copy_to_user.S
3346 @@ -16,7 +16,7 @@
3347 /*
3348 * Prototype:
3349 *
3350 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3351 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3352 *
3353 * Purpose:
3354 *
3355 @@ -88,11 +88,11 @@
3356 .text
3357
3358 ENTRY(__copy_to_user_std)
3359 -WEAK(__copy_to_user)
3360 +WEAK(___copy_to_user)
3361
3362 #include "copy_template.S"
3363
3364 -ENDPROC(__copy_to_user)
3365 +ENDPROC(___copy_to_user)
3366 ENDPROC(__copy_to_user_std)
3367
3368 .pushsection .fixup,"ax"
3369 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3370 index 7d08b43..f7ca7ea 100644
3371 --- a/arch/arm/lib/csumpartialcopyuser.S
3372 +++ b/arch/arm/lib/csumpartialcopyuser.S
3373 @@ -57,8 +57,8 @@
3374 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3375 */
3376
3377 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3378 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3379 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3380 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3381
3382 #include "csumpartialcopygeneric.S"
3383
3384 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3385 index 5306de3..aed6d03 100644
3386 --- a/arch/arm/lib/delay.c
3387 +++ b/arch/arm/lib/delay.c
3388 @@ -28,7 +28,7 @@
3389 /*
3390 * Default to the loop-based delay implementation.
3391 */
3392 -struct arm_delay_ops arm_delay_ops = {
3393 +struct arm_delay_ops arm_delay_ops __read_only = {
3394 .delay = __loop_delay,
3395 .const_udelay = __loop_const_udelay,
3396 .udelay = __loop_udelay,
3397 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3398 index 3e58d71..029817c 100644
3399 --- a/arch/arm/lib/uaccess_with_memcpy.c
3400 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3401 @@ -136,7 +136,7 @@ out:
3402 }
3403
3404 unsigned long
3405 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3406 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3407 {
3408 /*
3409 * This test is stubbed out of the main function above to keep
3410 @@ -190,7 +190,7 @@ out:
3411 return n;
3412 }
3413
3414 -unsigned long __clear_user(void __user *addr, unsigned long n)
3415 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3416 {
3417 /* See rational for this in __copy_to_user() above. */
3418 if (n < 64)
3419 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3420 index f7ca97b..3d7e719 100644
3421 --- a/arch/arm/mach-at91/setup.c
3422 +++ b/arch/arm/mach-at91/setup.c
3423 @@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3424
3425 desc->pfn = __phys_to_pfn(base);
3426 desc->length = length;
3427 - desc->type = MT_MEMORY_RWX_NONCACHED;
3428 + desc->type = MT_MEMORY_RW_NONCACHED;
3429
3430 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3431 base, length, desc->virtual);
3432 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3433 index f3407a5..bd4256f 100644
3434 --- a/arch/arm/mach-kirkwood/common.c
3435 +++ b/arch/arm/mach-kirkwood/common.c
3436 @@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3437 clk_gate_ops.disable(hw);
3438 }
3439
3440 -static struct clk_ops clk_gate_fn_ops;
3441 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3442 +{
3443 + return clk_gate_ops.is_enabled(hw);
3444 +}
3445 +
3446 +static struct clk_ops clk_gate_fn_ops = {
3447 + .enable = clk_gate_fn_enable,
3448 + .disable = clk_gate_fn_disable,
3449 + .is_enabled = clk_gate_fn_is_enabled,
3450 +};
3451
3452 static struct clk __init *clk_register_gate_fn(struct device *dev,
3453 const char *name,
3454 @@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3455 gate_fn->fn_en = fn_en;
3456 gate_fn->fn_dis = fn_dis;
3457
3458 - /* ops is the gate ops, but with our enable/disable functions */
3459 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3460 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3461 - clk_gate_fn_ops = clk_gate_ops;
3462 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3463 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3464 - }
3465 -
3466 clk = clk_register(dev, &gate_fn->gate.hw);
3467
3468 if (IS_ERR(clk))
3469 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3470 index aead77a..a2253fa 100644
3471 --- a/arch/arm/mach-omap2/board-n8x0.c
3472 +++ b/arch/arm/mach-omap2/board-n8x0.c
3473 @@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3474 }
3475 #endif
3476
3477 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3478 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3479 .late_init = n8x0_menelaus_late_init,
3480 };
3481
3482 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3483 index ab43755..ccfa231 100644
3484 --- a/arch/arm/mach-omap2/gpmc.c
3485 +++ b/arch/arm/mach-omap2/gpmc.c
3486 @@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3487 };
3488
3489 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3490 -static struct irq_chip gpmc_irq_chip;
3491 static int gpmc_irq_start;
3492
3493 static struct resource gpmc_mem_root;
3494 @@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3495
3496 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3497
3498 +static struct irq_chip gpmc_irq_chip = {
3499 + .name = "gpmc",
3500 + .irq_startup = gpmc_irq_noop_ret,
3501 + .irq_enable = gpmc_irq_enable,
3502 + .irq_disable = gpmc_irq_disable,
3503 + .irq_shutdown = gpmc_irq_noop,
3504 + .irq_ack = gpmc_irq_noop,
3505 + .irq_mask = gpmc_irq_noop,
3506 + .irq_unmask = gpmc_irq_noop,
3507 +
3508 +};
3509 +
3510 static int gpmc_setup_irq(void)
3511 {
3512 int i;
3513 @@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3514 return gpmc_irq_start;
3515 }
3516
3517 - gpmc_irq_chip.name = "gpmc";
3518 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3519 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3520 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3521 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3522 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3523 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3524 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3525 -
3526 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3527 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3528
3529 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3530 index 667915d..2ee1219 100644
3531 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3532 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3533 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3534 int (*finish_suspend)(unsigned long cpu_state);
3535 void (*resume)(void);
3536 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3537 -};
3538 +} __no_const;
3539
3540 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3541 static struct powerdomain *mpuss_pd;
3542 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3543 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3544 {}
3545
3546 -struct cpu_pm_ops omap_pm_ops = {
3547 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3548 .finish_suspend = default_finish_suspend,
3549 .resume = dummy_cpu_resume,
3550 .scu_prepare = dummy_scu_prepare,
3551 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3552 index 3664562..72f85c6 100644
3553 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3554 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3555 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3556 return NOTIFY_OK;
3557 }
3558
3559 -static struct notifier_block __refdata irq_hotplug_notifier = {
3560 +static struct notifier_block irq_hotplug_notifier = {
3561 .notifier_call = irq_cpu_hotplug_notify,
3562 };
3563
3564 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3565 index 01ef59d..32ae28a8 100644
3566 --- a/arch/arm/mach-omap2/omap_device.c
3567 +++ b/arch/arm/mach-omap2/omap_device.c
3568 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3569 struct platform_device __init *omap_device_build(const char *pdev_name,
3570 int pdev_id,
3571 struct omap_hwmod *oh,
3572 - void *pdata, int pdata_len)
3573 + const void *pdata, int pdata_len)
3574 {
3575 struct omap_hwmod *ohs[] = { oh };
3576
3577 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3578 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3579 int pdev_id,
3580 struct omap_hwmod **ohs,
3581 - int oh_cnt, void *pdata,
3582 + int oh_cnt, const void *pdata,
3583 int pdata_len)
3584 {
3585 int ret = -ENOMEM;
3586 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3587 index 78c02b3..c94109a 100644
3588 --- a/arch/arm/mach-omap2/omap_device.h
3589 +++ b/arch/arm/mach-omap2/omap_device.h
3590 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3591 /* Core code interface */
3592
3593 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3594 - struct omap_hwmod *oh, void *pdata,
3595 + struct omap_hwmod *oh, const void *pdata,
3596 int pdata_len);
3597
3598 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3599 struct omap_hwmod **oh, int oh_cnt,
3600 - void *pdata, int pdata_len);
3601 + const void *pdata, int pdata_len);
3602
3603 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3604 struct omap_hwmod **ohs, int oh_cnt);
3605 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3606 index 1f33f5d..b29fa75 100644
3607 --- a/arch/arm/mach-omap2/omap_hwmod.c
3608 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3609 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3610 int (*init_clkdm)(struct omap_hwmod *oh);
3611 void (*update_context_lost)(struct omap_hwmod *oh);
3612 int (*get_context_lost)(struct omap_hwmod *oh);
3613 -};
3614 +} __no_const;
3615
3616 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3617 -static struct omap_hwmod_soc_ops soc_ops;
3618 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3619
3620 /* omap_hwmod_list contains all registered struct omap_hwmods */
3621 static LIST_HEAD(omap_hwmod_list);
3622 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3623 index 95fee54..cfa9cf1 100644
3624 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3625 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3626 @@ -10,6 +10,7 @@
3627
3628 #include <linux/kernel.h>
3629 #include <linux/init.h>
3630 +#include <asm/pgtable.h>
3631
3632 #include "powerdomain.h"
3633
3634 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3635
3636 void __init am43xx_powerdomains_init(void)
3637 {
3638 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3639 + pax_open_kernel();
3640 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3641 + pax_close_kernel();
3642 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3643 pwrdm_register_pwrdms(powerdomains_am43xx);
3644 pwrdm_complete_init();
3645 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3646 index d15c7bb..b2d1f0c 100644
3647 --- a/arch/arm/mach-omap2/wd_timer.c
3648 +++ b/arch/arm/mach-omap2/wd_timer.c
3649 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3650 struct omap_hwmod *oh;
3651 char *oh_name = "wd_timer2";
3652 char *dev_name = "omap_wdt";
3653 - struct omap_wd_timer_platform_data pdata;
3654 + static struct omap_wd_timer_platform_data pdata = {
3655 + .read_reset_sources = prm_read_reset_sources
3656 + };
3657
3658 if (!cpu_class_is_omap2() || of_have_populated_dt())
3659 return 0;
3660 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3661 return -EINVAL;
3662 }
3663
3664 - pdata.read_reset_sources = prm_read_reset_sources;
3665 -
3666 pdev = omap_device_build(dev_name, id, oh, &pdata,
3667 sizeof(struct omap_wd_timer_platform_data));
3668 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3669 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3670 index b82dcae..44ee5b6 100644
3671 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3672 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3673 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3674 bool entered_lp2 = false;
3675
3676 if (tegra_pending_sgi())
3677 - ACCESS_ONCE(abort_flag) = true;
3678 + ACCESS_ONCE_RW(abort_flag) = true;
3679
3680 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3681
3682 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3683 index 2dea8b5..6499da2 100644
3684 --- a/arch/arm/mach-ux500/setup.h
3685 +++ b/arch/arm/mach-ux500/setup.h
3686 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3687 .type = MT_DEVICE, \
3688 }
3689
3690 -#define __MEM_DEV_DESC(x, sz) { \
3691 - .virtual = IO_ADDRESS(x), \
3692 - .pfn = __phys_to_pfn(x), \
3693 - .length = sz, \
3694 - .type = MT_MEMORY_RWX, \
3695 -}
3696 -
3697 extern struct smp_operations ux500_smp_ops;
3698 extern void ux500_cpu_die(unsigned int cpu);
3699
3700 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3701 index 1f8fed9..14d7823 100644
3702 --- a/arch/arm/mm/Kconfig
3703 +++ b/arch/arm/mm/Kconfig
3704 @@ -446,7 +446,7 @@ config CPU_32v5
3705
3706 config CPU_32v6
3707 bool
3708 - select CPU_USE_DOMAINS if CPU_V6 && MMU
3709 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3710 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3711
3712 config CPU_32v6K
3713 @@ -601,6 +601,7 @@ config CPU_CP15_MPU
3714
3715 config CPU_USE_DOMAINS
3716 bool
3717 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3718 help
3719 This option enables or disables the use of domain switching
3720 via the set_fs() function.
3721 @@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3722 config KUSER_HELPERS
3723 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3724 default y
3725 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3726 help
3727 Warning: disabling this option may break user programs.
3728
3729 @@ -812,7 +814,7 @@ config KUSER_HELPERS
3730 See Documentation/arm/kernel_user_helpers.txt for details.
3731
3732 However, the fixed address nature of these helpers can be used
3733 - by ROP (return orientated programming) authors when creating
3734 + by ROP (Return Oriented Programming) authors when creating
3735 exploits.
3736
3737 If all of the binaries and libraries which run on your platform
3738 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3739 index 9240364..a2b8cf3 100644
3740 --- a/arch/arm/mm/alignment.c
3741 +++ b/arch/arm/mm/alignment.c
3742 @@ -212,10 +212,12 @@ union offset_union {
3743 #define __get16_unaligned_check(ins,val,addr) \
3744 do { \
3745 unsigned int err = 0, v, a = addr; \
3746 + pax_open_userland(); \
3747 __get8_unaligned_check(ins,v,a,err); \
3748 val = v << ((BE) ? 8 : 0); \
3749 __get8_unaligned_check(ins,v,a,err); \
3750 val |= v << ((BE) ? 0 : 8); \
3751 + pax_close_userland(); \
3752 if (err) \
3753 goto fault; \
3754 } while (0)
3755 @@ -229,6 +231,7 @@ union offset_union {
3756 #define __get32_unaligned_check(ins,val,addr) \
3757 do { \
3758 unsigned int err = 0, v, a = addr; \
3759 + pax_open_userland(); \
3760 __get8_unaligned_check(ins,v,a,err); \
3761 val = v << ((BE) ? 24 : 0); \
3762 __get8_unaligned_check(ins,v,a,err); \
3763 @@ -237,6 +240,7 @@ union offset_union {
3764 val |= v << ((BE) ? 8 : 16); \
3765 __get8_unaligned_check(ins,v,a,err); \
3766 val |= v << ((BE) ? 0 : 24); \
3767 + pax_close_userland(); \
3768 if (err) \
3769 goto fault; \
3770 } while (0)
3771 @@ -250,6 +254,7 @@ union offset_union {
3772 #define __put16_unaligned_check(ins,val,addr) \
3773 do { \
3774 unsigned int err = 0, v = val, a = addr; \
3775 + pax_open_userland(); \
3776 __asm__( FIRST_BYTE_16 \
3777 ARM( "1: "ins" %1, [%2], #1\n" ) \
3778 THUMB( "1: "ins" %1, [%2]\n" ) \
3779 @@ -269,6 +274,7 @@ union offset_union {
3780 " .popsection\n" \
3781 : "=r" (err), "=&r" (v), "=&r" (a) \
3782 : "0" (err), "1" (v), "2" (a)); \
3783 + pax_close_userland(); \
3784 if (err) \
3785 goto fault; \
3786 } while (0)
3787 @@ -282,6 +288,7 @@ union offset_union {
3788 #define __put32_unaligned_check(ins,val,addr) \
3789 do { \
3790 unsigned int err = 0, v = val, a = addr; \
3791 + pax_open_userland(); \
3792 __asm__( FIRST_BYTE_32 \
3793 ARM( "1: "ins" %1, [%2], #1\n" ) \
3794 THUMB( "1: "ins" %1, [%2]\n" ) \
3795 @@ -311,6 +318,7 @@ union offset_union {
3796 " .popsection\n" \
3797 : "=r" (err), "=&r" (v), "=&r" (a) \
3798 : "0" (err), "1" (v), "2" (a)); \
3799 + pax_close_userland(); \
3800 if (err) \
3801 goto fault; \
3802 } while (0)
3803 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3804 index 7abde2c..9df495f 100644
3805 --- a/arch/arm/mm/cache-l2x0.c
3806 +++ b/arch/arm/mm/cache-l2x0.c
3807 @@ -46,7 +46,7 @@ struct l2x0_of_data {
3808 void (*setup)(const struct device_node *, u32 *, u32 *);
3809 void (*save)(void);
3810 struct outer_cache_fns outer_cache;
3811 -};
3812 +} __do_const;
3813
3814 static bool of_init = false;
3815
3816 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3817 index 6eb97b3..ac509f6 100644
3818 --- a/arch/arm/mm/context.c
3819 +++ b/arch/arm/mm/context.c
3820 @@ -43,7 +43,7 @@
3821 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3822
3823 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3824 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3825 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3826 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3827
3828 static DEFINE_PER_CPU(atomic64_t, active_asids);
3829 @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3830 {
3831 static u32 cur_idx = 1;
3832 u64 asid = atomic64_read(&mm->context.id);
3833 - u64 generation = atomic64_read(&asid_generation);
3834 + u64 generation = atomic64_read_unchecked(&asid_generation);
3835
3836 if (asid != 0 && is_reserved_asid(asid)) {
3837 /*
3838 @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3839 */
3840 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3841 if (asid == NUM_USER_ASIDS) {
3842 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3843 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3844 &asid_generation);
3845 flush_context(cpu);
3846 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3847 @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3848 cpu_set_reserved_ttbr0();
3849
3850 asid = atomic64_read(&mm->context.id);
3851 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3852 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3853 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3854 goto switch_mm_fastpath;
3855
3856 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3857 /* Check that our ASID belongs to the current generation. */
3858 asid = atomic64_read(&mm->context.id);
3859 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3860 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3861 asid = new_context(mm, cpu);
3862 atomic64_set(&mm->context.id, asid);
3863 }
3864 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3865 index eb8830a..5360ce7 100644
3866 --- a/arch/arm/mm/fault.c
3867 +++ b/arch/arm/mm/fault.c
3868 @@ -25,6 +25,7 @@
3869 #include <asm/system_misc.h>
3870 #include <asm/system_info.h>
3871 #include <asm/tlbflush.h>
3872 +#include <asm/sections.h>
3873
3874 #include "fault.h"
3875
3876 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3877 if (fixup_exception(regs))
3878 return;
3879
3880 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3881 + if (addr < TASK_SIZE) {
3882 + if (current->signal->curr_ip)
3883 + 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),
3884 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3885 + else
3886 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3887 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3888 + }
3889 +#endif
3890 +
3891 +#ifdef CONFIG_PAX_KERNEXEC
3892 + if ((fsr & FSR_WRITE) &&
3893 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3894 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3895 + {
3896 + if (current->signal->curr_ip)
3897 + 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),
3898 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3899 + else
3900 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3901 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3902 + }
3903 +#endif
3904 +
3905 /*
3906 * No handler, we'll have to terminate things with extreme prejudice.
3907 */
3908 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3909 }
3910 #endif
3911
3912 +#ifdef CONFIG_PAX_PAGEEXEC
3913 + if (fsr & FSR_LNX_PF) {
3914 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3915 + do_group_exit(SIGKILL);
3916 + }
3917 +#endif
3918 +
3919 tsk->thread.address = addr;
3920 tsk->thread.error_code = fsr;
3921 tsk->thread.trap_no = 14;
3922 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3923 }
3924 #endif /* CONFIG_MMU */
3925
3926 +#ifdef CONFIG_PAX_PAGEEXEC
3927 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3928 +{
3929 + long i;
3930 +
3931 + printk(KERN_ERR "PAX: bytes at PC: ");
3932 + for (i = 0; i < 20; i++) {
3933 + unsigned char c;
3934 + if (get_user(c, (__force unsigned char __user *)pc+i))
3935 + printk(KERN_CONT "?? ");
3936 + else
3937 + printk(KERN_CONT "%02x ", c);
3938 + }
3939 + printk("\n");
3940 +
3941 + printk(KERN_ERR "PAX: bytes at SP-4: ");
3942 + for (i = -1; i < 20; i++) {
3943 + unsigned long c;
3944 + if (get_user(c, (__force unsigned long __user *)sp+i))
3945 + printk(KERN_CONT "???????? ");
3946 + else
3947 + printk(KERN_CONT "%08lx ", c);
3948 + }
3949 + printk("\n");
3950 +}
3951 +#endif
3952 +
3953 /*
3954 * First Level Translation Fault Handler
3955 *
3956 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3957 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3958 struct siginfo info;
3959
3960 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3961 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3962 + if (current->signal->curr_ip)
3963 + 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),
3964 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3965 + else
3966 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3967 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3968 + goto die;
3969 + }
3970 +#endif
3971 +
3972 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3973 return;
3974
3975 +die:
3976 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3977 inf->name, fsr, addr);
3978
3979 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3980 ifsr_info[nr].name = name;
3981 }
3982
3983 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
3984 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3985 +
3986 asmlinkage void __exception
3987 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3988 {
3989 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3990 struct siginfo info;
3991 + unsigned long pc = instruction_pointer(regs);
3992 +
3993 + if (user_mode(regs)) {
3994 + unsigned long sigpage = current->mm->context.sigpage;
3995 +
3996 + if (sigpage <= pc && pc < sigpage + 7*4) {
3997 + if (pc < sigpage + 3*4)
3998 + sys_sigreturn(regs);
3999 + else
4000 + sys_rt_sigreturn(regs);
4001 + return;
4002 + }
4003 + if (pc == 0xffff0f60UL) {
4004 + /*
4005 + * PaX: __kuser_cmpxchg64 emulation
4006 + */
4007 + // TODO
4008 + //regs->ARM_pc = regs->ARM_lr;
4009 + //return;
4010 + }
4011 + if (pc == 0xffff0fa0UL) {
4012 + /*
4013 + * PaX: __kuser_memory_barrier emulation
4014 + */
4015 + // dmb(); implied by the exception
4016 + regs->ARM_pc = regs->ARM_lr;
4017 + return;
4018 + }
4019 + if (pc == 0xffff0fc0UL) {
4020 + /*
4021 + * PaX: __kuser_cmpxchg emulation
4022 + */
4023 + // TODO
4024 + //long new;
4025 + //int op;
4026 +
4027 + //op = FUTEX_OP_SET << 28;
4028 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4029 + //regs->ARM_r0 = old != new;
4030 + //regs->ARM_pc = regs->ARM_lr;
4031 + //return;
4032 + }
4033 + if (pc == 0xffff0fe0UL) {
4034 + /*
4035 + * PaX: __kuser_get_tls emulation
4036 + */
4037 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4038 + regs->ARM_pc = regs->ARM_lr;
4039 + return;
4040 + }
4041 + }
4042 +
4043 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4044 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4045 + if (current->signal->curr_ip)
4046 + 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),
4047 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4048 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4049 + else
4050 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4051 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4052 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4053 + goto die;
4054 + }
4055 +#endif
4056 +
4057 +#ifdef CONFIG_PAX_REFCOUNT
4058 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4059 + unsigned int bkpt;
4060 +
4061 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4062 + current->thread.error_code = ifsr;
4063 + current->thread.trap_no = 0;
4064 + pax_report_refcount_overflow(regs);
4065 + fixup_exception(regs);
4066 + return;
4067 + }
4068 + }
4069 +#endif
4070
4071 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4072 return;
4073
4074 +die:
4075 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4076 inf->name, ifsr, addr);
4077
4078 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4079 index cf08bdf..772656c 100644
4080 --- a/arch/arm/mm/fault.h
4081 +++ b/arch/arm/mm/fault.h
4082 @@ -3,6 +3,7 @@
4083
4084 /*
4085 * Fault status register encodings. We steal bit 31 for our own purposes.
4086 + * Set when the FSR value is from an instruction fault.
4087 */
4088 #define FSR_LNX_PF (1 << 31)
4089 #define FSR_WRITE (1 << 11)
4090 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4091 }
4092 #endif
4093
4094 +/* valid for LPAE and !LPAE */
4095 +static inline int is_xn_fault(unsigned int fsr)
4096 +{
4097 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4098 +}
4099 +
4100 +static inline int is_domain_fault(unsigned int fsr)
4101 +{
4102 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4103 +}
4104 +
4105 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4106 unsigned long search_exception_table(unsigned long addr);
4107
4108 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4109 index 804d615..fcec50a 100644
4110 --- a/arch/arm/mm/init.c
4111 +++ b/arch/arm/mm/init.c
4112 @@ -30,6 +30,8 @@
4113 #include <asm/setup.h>
4114 #include <asm/tlb.h>
4115 #include <asm/fixmap.h>
4116 +#include <asm/system_info.h>
4117 +#include <asm/cp15.h>
4118
4119 #include <asm/mach/arch.h>
4120 #include <asm/mach/map.h>
4121 @@ -625,7 +627,46 @@ void free_initmem(void)
4122 {
4123 #ifdef CONFIG_HAVE_TCM
4124 extern char __tcm_start, __tcm_end;
4125 +#endif
4126
4127 +#ifdef CONFIG_PAX_KERNEXEC
4128 + unsigned long addr;
4129 + pgd_t *pgd;
4130 + pud_t *pud;
4131 + pmd_t *pmd;
4132 + int cpu_arch = cpu_architecture();
4133 + unsigned int cr = get_cr();
4134 +
4135 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4136 + /* make pages tables, etc before .text NX */
4137 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4138 + pgd = pgd_offset_k(addr);
4139 + pud = pud_offset(pgd, addr);
4140 + pmd = pmd_offset(pud, addr);
4141 + __section_update(pmd, addr, PMD_SECT_XN);
4142 + }
4143 + /* make init NX */
4144 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4145 + pgd = pgd_offset_k(addr);
4146 + pud = pud_offset(pgd, addr);
4147 + pmd = pmd_offset(pud, addr);
4148 + __section_update(pmd, addr, PMD_SECT_XN);
4149 + }
4150 + /* make kernel code/rodata RX */
4151 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4152 + pgd = pgd_offset_k(addr);
4153 + pud = pud_offset(pgd, addr);
4154 + pmd = pmd_offset(pud, addr);
4155 +#ifdef CONFIG_ARM_LPAE
4156 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4157 +#else
4158 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4159 +#endif
4160 + }
4161 + }
4162 +#endif
4163 +
4164 +#ifdef CONFIG_HAVE_TCM
4165 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4166 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4167 #endif
4168 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4169 index f9c32ba..8540068 100644
4170 --- a/arch/arm/mm/ioremap.c
4171 +++ b/arch/arm/mm/ioremap.c
4172 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4173 unsigned int mtype;
4174
4175 if (cached)
4176 - mtype = MT_MEMORY_RWX;
4177 + mtype = MT_MEMORY_RX;
4178 else
4179 - mtype = MT_MEMORY_RWX_NONCACHED;
4180 + mtype = MT_MEMORY_RX_NONCACHED;
4181
4182 return __arm_ioremap_caller(phys_addr, size, mtype,
4183 __builtin_return_address(0));
4184 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4185 index 5e85ed3..b10a7ed 100644
4186 --- a/arch/arm/mm/mmap.c
4187 +++ b/arch/arm/mm/mmap.c
4188 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4189 struct vm_area_struct *vma;
4190 int do_align = 0;
4191 int aliasing = cache_is_vipt_aliasing();
4192 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4193 struct vm_unmapped_area_info info;
4194
4195 /*
4196 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4197 if (len > TASK_SIZE)
4198 return -ENOMEM;
4199
4200 +#ifdef CONFIG_PAX_RANDMMAP
4201 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4202 +#endif
4203 +
4204 if (addr) {
4205 if (do_align)
4206 addr = COLOUR_ALIGN(addr, pgoff);
4207 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4208 addr = PAGE_ALIGN(addr);
4209
4210 vma = find_vma(mm, addr);
4211 - if (TASK_SIZE - len >= addr &&
4212 - (!vma || addr + len <= vma->vm_start))
4213 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4214 return addr;
4215 }
4216
4217 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4218 info.high_limit = TASK_SIZE;
4219 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4220 info.align_offset = pgoff << PAGE_SHIFT;
4221 + info.threadstack_offset = offset;
4222 return vm_unmapped_area(&info);
4223 }
4224
4225 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4226 unsigned long addr = addr0;
4227 int do_align = 0;
4228 int aliasing = cache_is_vipt_aliasing();
4229 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4230 struct vm_unmapped_area_info info;
4231
4232 /*
4233 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4234 return addr;
4235 }
4236
4237 +#ifdef CONFIG_PAX_RANDMMAP
4238 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4239 +#endif
4240 +
4241 /* requesting a specific address */
4242 if (addr) {
4243 if (do_align)
4244 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4245 else
4246 addr = PAGE_ALIGN(addr);
4247 vma = find_vma(mm, addr);
4248 - if (TASK_SIZE - len >= addr &&
4249 - (!vma || addr + len <= vma->vm_start))
4250 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4251 return addr;
4252 }
4253
4254 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4255 info.high_limit = mm->mmap_base;
4256 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4257 info.align_offset = pgoff << PAGE_SHIFT;
4258 + info.threadstack_offset = offset;
4259 addr = vm_unmapped_area(&info);
4260
4261 /*
4262 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4263 {
4264 unsigned long random_factor = 0UL;
4265
4266 +#ifdef CONFIG_PAX_RANDMMAP
4267 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4268 +#endif
4269 +
4270 /* 8 bits of randomness in 20 address space bits */
4271 if ((current->flags & PF_RANDOMIZE) &&
4272 !(current->personality & ADDR_NO_RANDOMIZE))
4273 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4274
4275 if (mmap_is_legacy()) {
4276 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4277 +
4278 +#ifdef CONFIG_PAX_RANDMMAP
4279 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4280 + mm->mmap_base += mm->delta_mmap;
4281 +#endif
4282 +
4283 mm->get_unmapped_area = arch_get_unmapped_area;
4284 } else {
4285 mm->mmap_base = mmap_base(random_factor);
4286 +
4287 +#ifdef CONFIG_PAX_RANDMMAP
4288 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4289 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4290 +#endif
4291 +
4292 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4293 }
4294 }
4295 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4296 index a623cb3..a896d84 100644
4297 --- a/arch/arm/mm/mmu.c
4298 +++ b/arch/arm/mm/mmu.c
4299 @@ -39,6 +39,22 @@
4300 #include "mm.h"
4301 #include "tcm.h"
4302
4303 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4304 +void modify_domain(unsigned int dom, unsigned int type)
4305 +{
4306 + struct thread_info *thread = current_thread_info();
4307 + unsigned int domain = thread->cpu_domain;
4308 + /*
4309 + * DOMAIN_MANAGER might be defined to some other value,
4310 + * use the arch-defined constant
4311 + */
4312 + domain &= ~domain_val(dom, 3);
4313 + thread->cpu_domain = domain | domain_val(dom, type);
4314 + set_domain(thread->cpu_domain);
4315 +}
4316 +EXPORT_SYMBOL(modify_domain);
4317 +#endif
4318 +
4319 /*
4320 * empty_zero_page is a special page that is used for
4321 * zero-initialized data and COW.
4322 @@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
4323 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4324 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4325
4326 -static struct mem_type mem_types[] = {
4327 +#ifdef CONFIG_PAX_KERNEXEC
4328 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4329 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4330 +#else
4331 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4332 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4333 +#endif
4334 +
4335 +static struct mem_type mem_types[] __read_only = {
4336 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4337 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4338 L_PTE_SHARED,
4339 @@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
4340 .prot_sect = PROT_SECT_DEVICE,
4341 .domain = DOMAIN_IO,
4342 },
4343 - [MT_UNCACHED] = {
4344 + [MT_UNCACHED_RW] = {
4345 .prot_pte = PROT_PTE_DEVICE,
4346 .prot_l1 = PMD_TYPE_TABLE,
4347 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4348 .domain = DOMAIN_IO,
4349 },
4350 - [MT_CACHECLEAN] = {
4351 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4352 + [MT_CACHECLEAN_RO] = {
4353 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4354 .domain = DOMAIN_KERNEL,
4355 },
4356 #ifndef CONFIG_ARM_LPAE
4357 - [MT_MINICLEAN] = {
4358 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4359 + [MT_MINICLEAN_RO] = {
4360 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4361 .domain = DOMAIN_KERNEL,
4362 },
4363 #endif
4364 @@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
4365 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4366 L_PTE_RDONLY,
4367 .prot_l1 = PMD_TYPE_TABLE,
4368 - .domain = DOMAIN_USER,
4369 + .domain = DOMAIN_VECTORS,
4370 },
4371 [MT_HIGH_VECTORS] = {
4372 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4373 L_PTE_USER | L_PTE_RDONLY,
4374 .prot_l1 = PMD_TYPE_TABLE,
4375 - .domain = DOMAIN_USER,
4376 + .domain = DOMAIN_VECTORS,
4377 },
4378 - [MT_MEMORY_RWX] = {
4379 + [__MT_MEMORY_RWX] = {
4380 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4381 .prot_l1 = PMD_TYPE_TABLE,
4382 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4383 @@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
4384 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4385 .domain = DOMAIN_KERNEL,
4386 },
4387 - [MT_ROM] = {
4388 - .prot_sect = PMD_TYPE_SECT,
4389 + [MT_MEMORY_RX] = {
4390 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4391 + .prot_l1 = PMD_TYPE_TABLE,
4392 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4393 + .domain = DOMAIN_KERNEL,
4394 + },
4395 + [MT_ROM_RX] = {
4396 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4397 .domain = DOMAIN_KERNEL,
4398 },
4399 - [MT_MEMORY_RWX_NONCACHED] = {
4400 + [MT_MEMORY_RW_NONCACHED] = {
4401 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4402 L_PTE_MT_BUFFERABLE,
4403 .prot_l1 = PMD_TYPE_TABLE,
4404 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4405 .domain = DOMAIN_KERNEL,
4406 },
4407 + [MT_MEMORY_RX_NONCACHED] = {
4408 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4409 + L_PTE_MT_BUFFERABLE,
4410 + .prot_l1 = PMD_TYPE_TABLE,
4411 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4412 + .domain = DOMAIN_KERNEL,
4413 + },
4414 [MT_MEMORY_RW_DTCM] = {
4415 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4416 L_PTE_XN,
4417 @@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
4418 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4419 .domain = DOMAIN_KERNEL,
4420 },
4421 - [MT_MEMORY_RWX_ITCM] = {
4422 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4423 + [MT_MEMORY_RX_ITCM] = {
4424 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4425 .prot_l1 = PMD_TYPE_TABLE,
4426 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4427 .domain = DOMAIN_KERNEL,
4428 },
4429 [MT_MEMORY_RW_SO] = {
4430 @@ -524,9 +562,14 @@ static void __init build_mem_type_table(void)
4431 * Mark cache clean areas and XIP ROM read only
4432 * from SVC mode and no access from userspace.
4433 */
4434 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4435 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4436 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4437 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4438 +#ifdef CONFIG_PAX_KERNEXEC
4439 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4440 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4441 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4442 +#endif
4443 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4444 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4445 #endif
4446
4447 if (is_smp()) {
4448 @@ -542,13 +585,17 @@ static void __init build_mem_type_table(void)
4449 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4450 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4451 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4452 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4453 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4454 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4455 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4456 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4457 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4458 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4459 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4460 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4461 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4462 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4463 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4464 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4465 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4466 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4467 }
4468 }
4469
4470 @@ -559,15 +606,20 @@ static void __init build_mem_type_table(void)
4471 if (cpu_arch >= CPU_ARCH_ARMv6) {
4472 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4473 /* Non-cacheable Normal is XCB = 001 */
4474 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4475 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4476 + PMD_SECT_BUFFERED;
4477 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4478 PMD_SECT_BUFFERED;
4479 } else {
4480 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4481 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4482 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4483 + PMD_SECT_TEX(1);
4484 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4485 PMD_SECT_TEX(1);
4486 }
4487 } else {
4488 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4489 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4490 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4491 }
4492
4493 #ifdef CONFIG_ARM_LPAE
4494 @@ -583,6 +635,8 @@ static void __init build_mem_type_table(void)
4495 vecs_pgprot |= PTE_EXT_AF;
4496 #endif
4497
4498 + user_pgprot |= __supported_pte_mask;
4499 +
4500 for (i = 0; i < 16; i++) {
4501 pteval_t v = pgprot_val(protection_map[i]);
4502 protection_map[i] = __pgprot(v | user_pgprot);
4503 @@ -600,21 +654,24 @@ static void __init build_mem_type_table(void)
4504
4505 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4506 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4507 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4508 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4509 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4510 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4511 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4512 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4513 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4514 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4515 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4516 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4517 - mem_types[MT_ROM].prot_sect |= cp->pmd;
4518 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4519 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4520 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4521
4522 switch (cp->pmd) {
4523 case PMD_SECT_WT:
4524 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4525 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4526 break;
4527 case PMD_SECT_WB:
4528 case PMD_SECT_WBWA:
4529 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4530 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4531 break;
4532 }
4533 pr_info("Memory policy: %sData cache %s\n",
4534 @@ -832,7 +889,7 @@ static void __init create_mapping(struct map_desc *md)
4535 return;
4536 }
4537
4538 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4539 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4540 md->virtual >= PAGE_OFFSET &&
4541 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4542 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4543 @@ -1247,18 +1304,15 @@ void __init arm_mm_memblock_reserve(void)
4544 * called function. This means you can't use any function or debugging
4545 * method which may touch any device, otherwise the kernel _will_ crash.
4546 */
4547 +
4548 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4549 +
4550 static void __init devicemaps_init(const struct machine_desc *mdesc)
4551 {
4552 struct map_desc map;
4553 unsigned long addr;
4554 - void *vectors;
4555
4556 - /*
4557 - * Allocate the vector page early.
4558 - */
4559 - vectors = early_alloc(PAGE_SIZE * 2);
4560 -
4561 - early_trap_init(vectors);
4562 + early_trap_init(&vectors);
4563
4564 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4565 pmd_clear(pmd_off_k(addr));
4566 @@ -1271,7 +1325,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4567 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4568 map.virtual = MODULES_VADDR;
4569 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4570 - map.type = MT_ROM;
4571 + map.type = MT_ROM_RX;
4572 create_mapping(&map);
4573 #endif
4574
4575 @@ -1282,14 +1336,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4576 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4577 map.virtual = FLUSH_BASE;
4578 map.length = SZ_1M;
4579 - map.type = MT_CACHECLEAN;
4580 + map.type = MT_CACHECLEAN_RO;
4581 create_mapping(&map);
4582 #endif
4583 #ifdef FLUSH_BASE_MINICACHE
4584 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4585 map.virtual = FLUSH_BASE_MINICACHE;
4586 map.length = SZ_1M;
4587 - map.type = MT_MINICLEAN;
4588 + map.type = MT_MINICLEAN_RO;
4589 create_mapping(&map);
4590 #endif
4591
4592 @@ -1298,7 +1352,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4593 * location (0xffff0000). If we aren't using high-vectors, also
4594 * create a mapping at the low-vectors virtual address.
4595 */
4596 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4597 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4598 map.virtual = 0xffff0000;
4599 map.length = PAGE_SIZE;
4600 #ifdef CONFIG_KUSER_HELPERS
4601 @@ -1355,8 +1409,10 @@ static void __init kmap_init(void)
4602 static void __init map_lowmem(void)
4603 {
4604 struct memblock_region *reg;
4605 +#ifndef CONFIG_PAX_KERNEXEC
4606 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4607 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4608 +#endif
4609
4610 /* Map all the lowmem memory banks. */
4611 for_each_memblock(memory, reg) {
4612 @@ -1369,11 +1425,48 @@ static void __init map_lowmem(void)
4613 if (start >= end)
4614 break;
4615
4616 +#ifdef CONFIG_PAX_KERNEXEC
4617 + map.pfn = __phys_to_pfn(start);
4618 + map.virtual = __phys_to_virt(start);
4619 + map.length = end - start;
4620 +
4621 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4622 + struct map_desc kernel;
4623 + struct map_desc initmap;
4624 +
4625 + /* when freeing initmem we will make this RW */
4626 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4627 + initmap.virtual = (unsigned long)__init_begin;
4628 + initmap.length = _sdata - __init_begin;
4629 + initmap.type = __MT_MEMORY_RWX;
4630 + create_mapping(&initmap);
4631 +
4632 + /* when freeing initmem we will make this RX */
4633 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4634 + kernel.virtual = (unsigned long)_stext;
4635 + kernel.length = __init_begin - _stext;
4636 + kernel.type = __MT_MEMORY_RWX;
4637 + create_mapping(&kernel);
4638 +
4639 + if (map.virtual < (unsigned long)_stext) {
4640 + map.length = (unsigned long)_stext - map.virtual;
4641 + map.type = __MT_MEMORY_RWX;
4642 + create_mapping(&map);
4643 + }
4644 +
4645 + map.pfn = __phys_to_pfn(__pa(_sdata));
4646 + map.virtual = (unsigned long)_sdata;
4647 + map.length = end - __pa(_sdata);
4648 + }
4649 +
4650 + map.type = MT_MEMORY_RW;
4651 + create_mapping(&map);
4652 +#else
4653 if (end < kernel_x_start || start >= kernel_x_end) {
4654 map.pfn = __phys_to_pfn(start);
4655 map.virtual = __phys_to_virt(start);
4656 map.length = end - start;
4657 - map.type = MT_MEMORY_RWX;
4658 + map.type = __MT_MEMORY_RWX;
4659
4660 create_mapping(&map);
4661 } else {
4662 @@ -1390,7 +1483,7 @@ static void __init map_lowmem(void)
4663 map.pfn = __phys_to_pfn(kernel_x_start);
4664 map.virtual = __phys_to_virt(kernel_x_start);
4665 map.length = kernel_x_end - kernel_x_start;
4666 - map.type = MT_MEMORY_RWX;
4667 + map.type = __MT_MEMORY_RWX;
4668
4669 create_mapping(&map);
4670
4671 @@ -1403,6 +1496,7 @@ static void __init map_lowmem(void)
4672 create_mapping(&map);
4673 }
4674 }
4675 +#endif
4676 }
4677 }
4678
4679 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4680 index 5b217f4..c23f40e 100644
4681 --- a/arch/arm/plat-iop/setup.c
4682 +++ b/arch/arm/plat-iop/setup.c
4683 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4684 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4685 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4686 .length = IOP3XX_PERIPHERAL_SIZE,
4687 - .type = MT_UNCACHED,
4688 + .type = MT_UNCACHED_RW,
4689 },
4690 };
4691
4692 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4693 index a5bc92d..0bb4730 100644
4694 --- a/arch/arm/plat-omap/sram.c
4695 +++ b/arch/arm/plat-omap/sram.c
4696 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4697 * Looks like we need to preserve some bootloader code at the
4698 * beginning of SRAM for jumping to flash for reboot to work...
4699 */
4700 + pax_open_kernel();
4701 memset_io(omap_sram_base + omap_sram_skip, 0,
4702 omap_sram_size - omap_sram_skip);
4703 + pax_close_kernel();
4704 }
4705 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4706 index ce6d763..cfea917 100644
4707 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4708 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4709 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4710 int (*started)(unsigned ch);
4711 int (*flush)(unsigned ch);
4712 int (*stop)(unsigned ch);
4713 -};
4714 +} __no_const;
4715
4716 extern void *samsung_dmadev_get_ops(void);
4717 extern void *s3c_dma_get_ops(void);
4718 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4719 index 6c0f684..5faea9d 100644
4720 --- a/arch/arm64/include/asm/uaccess.h
4721 +++ b/arch/arm64/include/asm/uaccess.h
4722 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4723 flag; \
4724 })
4725
4726 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4727 #define access_ok(type, addr, size) __range_ok(addr, size)
4728 #define user_addr_max get_fs
4729
4730 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4731 index c3a58a1..78fbf54 100644
4732 --- a/arch/avr32/include/asm/cache.h
4733 +++ b/arch/avr32/include/asm/cache.h
4734 @@ -1,8 +1,10 @@
4735 #ifndef __ASM_AVR32_CACHE_H
4736 #define __ASM_AVR32_CACHE_H
4737
4738 +#include <linux/const.h>
4739 +
4740 #define L1_CACHE_SHIFT 5
4741 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4742 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4743
4744 /*
4745 * Memory returned by kmalloc() may be used for DMA, so we must make
4746 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4747 index d232888..87c8df1 100644
4748 --- a/arch/avr32/include/asm/elf.h
4749 +++ b/arch/avr32/include/asm/elf.h
4750 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4751 the loader. We need to make sure that it is out of the way of the program
4752 that it will "exec", and that there is sufficient room for the brk. */
4753
4754 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4755 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4756
4757 +#ifdef CONFIG_PAX_ASLR
4758 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4759 +
4760 +#define PAX_DELTA_MMAP_LEN 15
4761 +#define PAX_DELTA_STACK_LEN 15
4762 +#endif
4763
4764 /* This yields a mask that user programs can use to figure out what
4765 instruction set this CPU supports. This could be done in user space,
4766 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4767 index 479330b..53717a8 100644
4768 --- a/arch/avr32/include/asm/kmap_types.h
4769 +++ b/arch/avr32/include/asm/kmap_types.h
4770 @@ -2,9 +2,9 @@
4771 #define __ASM_AVR32_KMAP_TYPES_H
4772
4773 #ifdef CONFIG_DEBUG_HIGHMEM
4774 -# define KM_TYPE_NR 29
4775 +# define KM_TYPE_NR 30
4776 #else
4777 -# define KM_TYPE_NR 14
4778 +# define KM_TYPE_NR 15
4779 #endif
4780
4781 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4782 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4783 index 0eca933..eb78c7b 100644
4784 --- a/arch/avr32/mm/fault.c
4785 +++ b/arch/avr32/mm/fault.c
4786 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4787
4788 int exception_trace = 1;
4789
4790 +#ifdef CONFIG_PAX_PAGEEXEC
4791 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4792 +{
4793 + unsigned long i;
4794 +
4795 + printk(KERN_ERR "PAX: bytes at PC: ");
4796 + for (i = 0; i < 20; i++) {
4797 + unsigned char c;
4798 + if (get_user(c, (unsigned char *)pc+i))
4799 + printk(KERN_CONT "???????? ");
4800 + else
4801 + printk(KERN_CONT "%02x ", c);
4802 + }
4803 + printk("\n");
4804 +}
4805 +#endif
4806 +
4807 /*
4808 * This routine handles page faults. It determines the address and the
4809 * problem, and then passes it off to one of the appropriate routines.
4810 @@ -176,6 +193,16 @@ bad_area:
4811 up_read(&mm->mmap_sem);
4812
4813 if (user_mode(regs)) {
4814 +
4815 +#ifdef CONFIG_PAX_PAGEEXEC
4816 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4817 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4818 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4819 + do_group_exit(SIGKILL);
4820 + }
4821 + }
4822 +#endif
4823 +
4824 if (exception_trace && printk_ratelimit())
4825 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4826 "sp %08lx ecr %lu\n",
4827 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4828 index 568885a..f8008df 100644
4829 --- a/arch/blackfin/include/asm/cache.h
4830 +++ b/arch/blackfin/include/asm/cache.h
4831 @@ -7,6 +7,7 @@
4832 #ifndef __ARCH_BLACKFIN_CACHE_H
4833 #define __ARCH_BLACKFIN_CACHE_H
4834
4835 +#include <linux/const.h>
4836 #include <linux/linkage.h> /* for asmlinkage */
4837
4838 /*
4839 @@ -14,7 +15,7 @@
4840 * Blackfin loads 32 bytes for cache
4841 */
4842 #define L1_CACHE_SHIFT 5
4843 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4844 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4845 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4846
4847 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4848 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4849 index aea2718..3639a60 100644
4850 --- a/arch/cris/include/arch-v10/arch/cache.h
4851 +++ b/arch/cris/include/arch-v10/arch/cache.h
4852 @@ -1,8 +1,9 @@
4853 #ifndef _ASM_ARCH_CACHE_H
4854 #define _ASM_ARCH_CACHE_H
4855
4856 +#include <linux/const.h>
4857 /* Etrax 100LX have 32-byte cache-lines. */
4858 -#define L1_CACHE_BYTES 32
4859 #define L1_CACHE_SHIFT 5
4860 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4861
4862 #endif /* _ASM_ARCH_CACHE_H */
4863 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4864 index 7caf25d..ee65ac5 100644
4865 --- a/arch/cris/include/arch-v32/arch/cache.h
4866 +++ b/arch/cris/include/arch-v32/arch/cache.h
4867 @@ -1,11 +1,12 @@
4868 #ifndef _ASM_CRIS_ARCH_CACHE_H
4869 #define _ASM_CRIS_ARCH_CACHE_H
4870
4871 +#include <linux/const.h>
4872 #include <arch/hwregs/dma.h>
4873
4874 /* A cache-line is 32 bytes. */
4875 -#define L1_CACHE_BYTES 32
4876 #define L1_CACHE_SHIFT 5
4877 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4878
4879 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4880
4881 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4882 index b86329d..6709906 100644
4883 --- a/arch/frv/include/asm/atomic.h
4884 +++ b/arch/frv/include/asm/atomic.h
4885 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4886 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4887 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4888
4889 +#define atomic64_read_unchecked(v) atomic64_read(v)
4890 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4891 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4892 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4893 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4894 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4895 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4896 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4897 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4898 +
4899 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4900 {
4901 int c, old;
4902 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4903 index 2797163..c2a401d 100644
4904 --- a/arch/frv/include/asm/cache.h
4905 +++ b/arch/frv/include/asm/cache.h
4906 @@ -12,10 +12,11 @@
4907 #ifndef __ASM_CACHE_H
4908 #define __ASM_CACHE_H
4909
4910 +#include <linux/const.h>
4911
4912 /* bytes per L1 cache line */
4913 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4914 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4915 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4916
4917 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4918 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4919 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4920 index 43901f2..0d8b865 100644
4921 --- a/arch/frv/include/asm/kmap_types.h
4922 +++ b/arch/frv/include/asm/kmap_types.h
4923 @@ -2,6 +2,6 @@
4924 #ifndef _ASM_KMAP_TYPES_H
4925 #define _ASM_KMAP_TYPES_H
4926
4927 -#define KM_TYPE_NR 17
4928 +#define KM_TYPE_NR 18
4929
4930 #endif
4931 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4932 index 836f147..4cf23f5 100644
4933 --- a/arch/frv/mm/elf-fdpic.c
4934 +++ b/arch/frv/mm/elf-fdpic.c
4935 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4936 {
4937 struct vm_area_struct *vma;
4938 struct vm_unmapped_area_info info;
4939 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4940
4941 if (len > TASK_SIZE)
4942 return -ENOMEM;
4943 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4944 if (addr) {
4945 addr = PAGE_ALIGN(addr);
4946 vma = find_vma(current->mm, addr);
4947 - if (TASK_SIZE - len >= addr &&
4948 - (!vma || addr + len <= vma->vm_start))
4949 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4950 goto success;
4951 }
4952
4953 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4954 info.high_limit = (current->mm->start_stack - 0x00200000);
4955 info.align_mask = 0;
4956 info.align_offset = 0;
4957 + info.threadstack_offset = offset;
4958 addr = vm_unmapped_area(&info);
4959 if (!(addr & ~PAGE_MASK))
4960 goto success;
4961 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4962 index f4ca594..adc72fd6 100644
4963 --- a/arch/hexagon/include/asm/cache.h
4964 +++ b/arch/hexagon/include/asm/cache.h
4965 @@ -21,9 +21,11 @@
4966 #ifndef __ASM_CACHE_H
4967 #define __ASM_CACHE_H
4968
4969 +#include <linux/const.h>
4970 +
4971 /* Bytes per L1 cache line */
4972 -#define L1_CACHE_SHIFT (5)
4973 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4974 +#define L1_CACHE_SHIFT 5
4975 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4976
4977 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4978 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4979 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4980 index 0c8e553..112d734 100644
4981 --- a/arch/ia64/Kconfig
4982 +++ b/arch/ia64/Kconfig
4983 @@ -544,6 +544,7 @@ source "drivers/sn/Kconfig"
4984 config KEXEC
4985 bool "kexec system call"
4986 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4987 + depends on !GRKERNSEC_KMEM
4988 help
4989 kexec is a system call that implements the ability to shutdown your
4990 current kernel, and to start another kernel. It is like a reboot
4991 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4992 index 6e6fe18..a6ae668 100644
4993 --- a/arch/ia64/include/asm/atomic.h
4994 +++ b/arch/ia64/include/asm/atomic.h
4995 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4996 #define atomic64_inc(v) atomic64_add(1, (v))
4997 #define atomic64_dec(v) atomic64_sub(1, (v))
4998
4999 +#define atomic64_read_unchecked(v) atomic64_read(v)
5000 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5001 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5002 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5003 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5004 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5005 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5006 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5007 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5008 +
5009 /* Atomic operations are already serializing */
5010 #define smp_mb__before_atomic_dec() barrier()
5011 #define smp_mb__after_atomic_dec() barrier()
5012 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5013 index 988254a..e1ee885 100644
5014 --- a/arch/ia64/include/asm/cache.h
5015 +++ b/arch/ia64/include/asm/cache.h
5016 @@ -1,6 +1,7 @@
5017 #ifndef _ASM_IA64_CACHE_H
5018 #define _ASM_IA64_CACHE_H
5019
5020 +#include <linux/const.h>
5021
5022 /*
5023 * Copyright (C) 1998-2000 Hewlett-Packard Co
5024 @@ -9,7 +10,7 @@
5025
5026 /* Bytes per L1 (data) cache line. */
5027 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5028 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5029 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5030
5031 #ifdef CONFIG_SMP
5032 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5033 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5034 index 5a83c5c..4d7f553 100644
5035 --- a/arch/ia64/include/asm/elf.h
5036 +++ b/arch/ia64/include/asm/elf.h
5037 @@ -42,6 +42,13 @@
5038 */
5039 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5040
5041 +#ifdef CONFIG_PAX_ASLR
5042 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5043 +
5044 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5045 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5046 +#endif
5047 +
5048 #define PT_IA_64_UNWIND 0x70000001
5049
5050 /* IA-64 relocations: */
5051 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5052 index 5767cdf..7462574 100644
5053 --- a/arch/ia64/include/asm/pgalloc.h
5054 +++ b/arch/ia64/include/asm/pgalloc.h
5055 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5056 pgd_val(*pgd_entry) = __pa(pud);
5057 }
5058
5059 +static inline void
5060 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5061 +{
5062 + pgd_populate(mm, pgd_entry, pud);
5063 +}
5064 +
5065 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5066 {
5067 return quicklist_alloc(0, GFP_KERNEL, NULL);
5068 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5069 pud_val(*pud_entry) = __pa(pmd);
5070 }
5071
5072 +static inline void
5073 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5074 +{
5075 + pud_populate(mm, pud_entry, pmd);
5076 +}
5077 +
5078 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5079 {
5080 return quicklist_alloc(0, GFP_KERNEL, NULL);
5081 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5082 index 7935115..c0eca6a 100644
5083 --- a/arch/ia64/include/asm/pgtable.h
5084 +++ b/arch/ia64/include/asm/pgtable.h
5085 @@ -12,7 +12,7 @@
5086 * David Mosberger-Tang <davidm@hpl.hp.com>
5087 */
5088
5089 -
5090 +#include <linux/const.h>
5091 #include <asm/mman.h>
5092 #include <asm/page.h>
5093 #include <asm/processor.h>
5094 @@ -142,6 +142,17 @@
5095 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5096 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5097 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5098 +
5099 +#ifdef CONFIG_PAX_PAGEEXEC
5100 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5101 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5102 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5103 +#else
5104 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5105 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5106 +# define PAGE_COPY_NOEXEC PAGE_COPY
5107 +#endif
5108 +
5109 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5110 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5111 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5112 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5113 index 45698cd..e8e2dbc 100644
5114 --- a/arch/ia64/include/asm/spinlock.h
5115 +++ b/arch/ia64/include/asm/spinlock.h
5116 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5117 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5118
5119 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5120 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5121 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5122 }
5123
5124 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5125 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5126 index 449c8c0..3d4b1e9 100644
5127 --- a/arch/ia64/include/asm/uaccess.h
5128 +++ b/arch/ia64/include/asm/uaccess.h
5129 @@ -70,6 +70,7 @@
5130 && ((segment).seg == KERNEL_DS.seg \
5131 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5132 })
5133 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5134 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5135
5136 /*
5137 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5138 static inline unsigned long
5139 __copy_to_user (void __user *to, const void *from, unsigned long count)
5140 {
5141 + if (count > INT_MAX)
5142 + return count;
5143 +
5144 + if (!__builtin_constant_p(count))
5145 + check_object_size(from, count, true);
5146 +
5147 return __copy_user(to, (__force void __user *) from, count);
5148 }
5149
5150 static inline unsigned long
5151 __copy_from_user (void *to, const void __user *from, unsigned long count)
5152 {
5153 + if (count > INT_MAX)
5154 + return count;
5155 +
5156 + if (!__builtin_constant_p(count))
5157 + check_object_size(to, count, false);
5158 +
5159 return __copy_user((__force void __user *) to, from, count);
5160 }
5161
5162 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5163 ({ \
5164 void __user *__cu_to = (to); \
5165 const void *__cu_from = (from); \
5166 - long __cu_len = (n); \
5167 + unsigned long __cu_len = (n); \
5168 \
5169 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5170 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5171 + if (!__builtin_constant_p(n)) \
5172 + check_object_size(__cu_from, __cu_len, true); \
5173 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5174 + } \
5175 __cu_len; \
5176 })
5177
5178 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5179 ({ \
5180 void *__cu_to = (to); \
5181 const void __user *__cu_from = (from); \
5182 - long __cu_len = (n); \
5183 + unsigned long __cu_len = (n); \
5184 \
5185 __chk_user_ptr(__cu_from); \
5186 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5187 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5188 + if (!__builtin_constant_p(n)) \
5189 + check_object_size(__cu_to, __cu_len, false); \
5190 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5191 + } \
5192 __cu_len; \
5193 })
5194
5195 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5196 index 24603be..948052d 100644
5197 --- a/arch/ia64/kernel/module.c
5198 +++ b/arch/ia64/kernel/module.c
5199 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5200 void
5201 module_free (struct module *mod, void *module_region)
5202 {
5203 - if (mod && mod->arch.init_unw_table &&
5204 - module_region == mod->module_init) {
5205 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5206 unw_remove_unwind_table(mod->arch.init_unw_table);
5207 mod->arch.init_unw_table = NULL;
5208 }
5209 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5210 }
5211
5212 static inline int
5213 +in_init_rx (const struct module *mod, uint64_t addr)
5214 +{
5215 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5216 +}
5217 +
5218 +static inline int
5219 +in_init_rw (const struct module *mod, uint64_t addr)
5220 +{
5221 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5222 +}
5223 +
5224 +static inline int
5225 in_init (const struct module *mod, uint64_t addr)
5226 {
5227 - return addr - (uint64_t) mod->module_init < mod->init_size;
5228 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5229 +}
5230 +
5231 +static inline int
5232 +in_core_rx (const struct module *mod, uint64_t addr)
5233 +{
5234 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5235 +}
5236 +
5237 +static inline int
5238 +in_core_rw (const struct module *mod, uint64_t addr)
5239 +{
5240 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5241 }
5242
5243 static inline int
5244 in_core (const struct module *mod, uint64_t addr)
5245 {
5246 - return addr - (uint64_t) mod->module_core < mod->core_size;
5247 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5248 }
5249
5250 static inline int
5251 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5252 break;
5253
5254 case RV_BDREL:
5255 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5256 + if (in_init_rx(mod, val))
5257 + val -= (uint64_t) mod->module_init_rx;
5258 + else if (in_init_rw(mod, val))
5259 + val -= (uint64_t) mod->module_init_rw;
5260 + else if (in_core_rx(mod, val))
5261 + val -= (uint64_t) mod->module_core_rx;
5262 + else if (in_core_rw(mod, val))
5263 + val -= (uint64_t) mod->module_core_rw;
5264 break;
5265
5266 case RV_LTV:
5267 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5268 * addresses have been selected...
5269 */
5270 uint64_t gp;
5271 - if (mod->core_size > MAX_LTOFF)
5272 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5273 /*
5274 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5275 * at the end of the module.
5276 */
5277 - gp = mod->core_size - MAX_LTOFF / 2;
5278 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5279 else
5280 - gp = mod->core_size / 2;
5281 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5282 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5283 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5284 mod->arch.gp = gp;
5285 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5286 }
5287 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5288 index ab33328..f39506c 100644
5289 --- a/arch/ia64/kernel/palinfo.c
5290 +++ b/arch/ia64/kernel/palinfo.c
5291 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5292 return NOTIFY_OK;
5293 }
5294
5295 -static struct notifier_block __refdata palinfo_cpu_notifier =
5296 +static struct notifier_block palinfo_cpu_notifier =
5297 {
5298 .notifier_call = palinfo_cpu_callback,
5299 .priority = 0,
5300 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5301 index 41e33f8..65180b2a 100644
5302 --- a/arch/ia64/kernel/sys_ia64.c
5303 +++ b/arch/ia64/kernel/sys_ia64.c
5304 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5305 unsigned long align_mask = 0;
5306 struct mm_struct *mm = current->mm;
5307 struct vm_unmapped_area_info info;
5308 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5309
5310 if (len > RGN_MAP_LIMIT)
5311 return -ENOMEM;
5312 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5313 if (REGION_NUMBER(addr) == RGN_HPAGE)
5314 addr = 0;
5315 #endif
5316 +
5317 +#ifdef CONFIG_PAX_RANDMMAP
5318 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5319 + addr = mm->free_area_cache;
5320 + else
5321 +#endif
5322 +
5323 if (!addr)
5324 addr = TASK_UNMAPPED_BASE;
5325
5326 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5327 info.high_limit = TASK_SIZE;
5328 info.align_mask = align_mask;
5329 info.align_offset = 0;
5330 + info.threadstack_offset = offset;
5331 return vm_unmapped_area(&info);
5332 }
5333
5334 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5335 index 84f8a52..7c76178 100644
5336 --- a/arch/ia64/kernel/vmlinux.lds.S
5337 +++ b/arch/ia64/kernel/vmlinux.lds.S
5338 @@ -192,7 +192,7 @@ SECTIONS {
5339 /* Per-cpu data: */
5340 . = ALIGN(PERCPU_PAGE_SIZE);
5341 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5342 - __phys_per_cpu_start = __per_cpu_load;
5343 + __phys_per_cpu_start = per_cpu_load;
5344 /*
5345 * ensure percpu data fits
5346 * into percpu page size
5347 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5348 index 7225dad..2a7c8256 100644
5349 --- a/arch/ia64/mm/fault.c
5350 +++ b/arch/ia64/mm/fault.c
5351 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5352 return pte_present(pte);
5353 }
5354
5355 +#ifdef CONFIG_PAX_PAGEEXEC
5356 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5357 +{
5358 + unsigned long i;
5359 +
5360 + printk(KERN_ERR "PAX: bytes at PC: ");
5361 + for (i = 0; i < 8; i++) {
5362 + unsigned int c;
5363 + if (get_user(c, (unsigned int *)pc+i))
5364 + printk(KERN_CONT "???????? ");
5365 + else
5366 + printk(KERN_CONT "%08x ", c);
5367 + }
5368 + printk("\n");
5369 +}
5370 +#endif
5371 +
5372 # define VM_READ_BIT 0
5373 # define VM_WRITE_BIT 1
5374 # define VM_EXEC_BIT 2
5375 @@ -151,8 +168,21 @@ retry:
5376 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5377 goto bad_area;
5378
5379 - if ((vma->vm_flags & mask) != mask)
5380 + if ((vma->vm_flags & mask) != mask) {
5381 +
5382 +#ifdef CONFIG_PAX_PAGEEXEC
5383 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5384 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5385 + goto bad_area;
5386 +
5387 + up_read(&mm->mmap_sem);
5388 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5389 + do_group_exit(SIGKILL);
5390 + }
5391 +#endif
5392 +
5393 goto bad_area;
5394 + }
5395
5396 /*
5397 * If for any reason at all we couldn't handle the fault, make
5398 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5399 index 68232db..6ca80af 100644
5400 --- a/arch/ia64/mm/hugetlbpage.c
5401 +++ b/arch/ia64/mm/hugetlbpage.c
5402 @@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5403 unsigned long pgoff, unsigned long flags)
5404 {
5405 struct vm_unmapped_area_info info;
5406 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5407
5408 if (len > RGN_MAP_LIMIT)
5409 return -ENOMEM;
5410 @@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5411 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5412 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5413 info.align_offset = 0;
5414 + info.threadstack_offset = offset;
5415 return vm_unmapped_area(&info);
5416 }
5417
5418 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5419 index 25c3502..560dae7 100644
5420 --- a/arch/ia64/mm/init.c
5421 +++ b/arch/ia64/mm/init.c
5422 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5423 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5424 vma->vm_end = vma->vm_start + PAGE_SIZE;
5425 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5426 +
5427 +#ifdef CONFIG_PAX_PAGEEXEC
5428 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5429 + vma->vm_flags &= ~VM_EXEC;
5430 +
5431 +#ifdef CONFIG_PAX_MPROTECT
5432 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5433 + vma->vm_flags &= ~VM_MAYEXEC;
5434 +#endif
5435 +
5436 + }
5437 +#endif
5438 +
5439 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5440 down_write(&current->mm->mmap_sem);
5441 if (insert_vm_struct(current->mm, vma)) {
5442 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5443 index 40b3ee9..8c2c112 100644
5444 --- a/arch/m32r/include/asm/cache.h
5445 +++ b/arch/m32r/include/asm/cache.h
5446 @@ -1,8 +1,10 @@
5447 #ifndef _ASM_M32R_CACHE_H
5448 #define _ASM_M32R_CACHE_H
5449
5450 +#include <linux/const.h>
5451 +
5452 /* L1 cache line size */
5453 #define L1_CACHE_SHIFT 4
5454 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5455 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5456
5457 #endif /* _ASM_M32R_CACHE_H */
5458 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5459 index 82abd15..d95ae5d 100644
5460 --- a/arch/m32r/lib/usercopy.c
5461 +++ b/arch/m32r/lib/usercopy.c
5462 @@ -14,6 +14,9 @@
5463 unsigned long
5464 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5465 {
5466 + if ((long)n < 0)
5467 + return n;
5468 +
5469 prefetch(from);
5470 if (access_ok(VERIFY_WRITE, to, n))
5471 __copy_user(to,from,n);
5472 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5473 unsigned long
5474 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5475 {
5476 + if ((long)n < 0)
5477 + return n;
5478 +
5479 prefetchw(to);
5480 if (access_ok(VERIFY_READ, from, n))
5481 __copy_user_zeroing(to,from,n);
5482 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5483 index 0395c51..5f26031 100644
5484 --- a/arch/m68k/include/asm/cache.h
5485 +++ b/arch/m68k/include/asm/cache.h
5486 @@ -4,9 +4,11 @@
5487 #ifndef __ARCH_M68K_CACHE_H
5488 #define __ARCH_M68K_CACHE_H
5489
5490 +#include <linux/const.h>
5491 +
5492 /* bytes per L1 cache line */
5493 #define L1_CACHE_SHIFT 4
5494 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5495 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5496
5497 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5498
5499 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5500 index 0424315..defcca9 100644
5501 --- a/arch/metag/mm/hugetlbpage.c
5502 +++ b/arch/metag/mm/hugetlbpage.c
5503 @@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5504 info.high_limit = TASK_SIZE;
5505 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5506 info.align_offset = 0;
5507 + info.threadstack_offset = 0;
5508 return vm_unmapped_area(&info);
5509 }
5510
5511 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5512 index 4efe96a..60e8699 100644
5513 --- a/arch/microblaze/include/asm/cache.h
5514 +++ b/arch/microblaze/include/asm/cache.h
5515 @@ -13,11 +13,12 @@
5516 #ifndef _ASM_MICROBLAZE_CACHE_H
5517 #define _ASM_MICROBLAZE_CACHE_H
5518
5519 +#include <linux/const.h>
5520 #include <asm/registers.h>
5521
5522 #define L1_CACHE_SHIFT 5
5523 /* word-granular cache in microblaze */
5524 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5525 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5526
5527 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5528
5529 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5530 index 95fa1f1..56a6fa2 100644
5531 --- a/arch/mips/Kconfig
5532 +++ b/arch/mips/Kconfig
5533 @@ -2298,6 +2298,7 @@ source "kernel/Kconfig.preempt"
5534
5535 config KEXEC
5536 bool "Kexec system call"
5537 + depends on !GRKERNSEC_KMEM
5538 help
5539 kexec is a system call that implements the ability to shutdown your
5540 current kernel, and to start another kernel. It is like a reboot
5541 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5542 index 02f2444..506969c 100644
5543 --- a/arch/mips/cavium-octeon/dma-octeon.c
5544 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5545 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5546 if (dma_release_from_coherent(dev, order, vaddr))
5547 return;
5548
5549 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5550 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5551 }
5552
5553 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5554 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5555 index 7eed2f2..c4e385d 100644
5556 --- a/arch/mips/include/asm/atomic.h
5557 +++ b/arch/mips/include/asm/atomic.h
5558 @@ -21,15 +21,39 @@
5559 #include <asm/cmpxchg.h>
5560 #include <asm/war.h>
5561
5562 +#ifdef CONFIG_GENERIC_ATOMIC64
5563 +#include <asm-generic/atomic64.h>
5564 +#endif
5565 +
5566 #define ATOMIC_INIT(i) { (i) }
5567
5568 +#ifdef CONFIG_64BIT
5569 +#define _ASM_EXTABLE(from, to) \
5570 +" .section __ex_table,\"a\"\n" \
5571 +" .dword " #from ", " #to"\n" \
5572 +" .previous\n"
5573 +#else
5574 +#define _ASM_EXTABLE(from, to) \
5575 +" .section __ex_table,\"a\"\n" \
5576 +" .word " #from ", " #to"\n" \
5577 +" .previous\n"
5578 +#endif
5579 +
5580 /*
5581 * atomic_read - read atomic variable
5582 * @v: pointer of type atomic_t
5583 *
5584 * Atomically reads the value of @v.
5585 */
5586 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5587 +static inline int atomic_read(const atomic_t *v)
5588 +{
5589 + return (*(volatile const int *) &v->counter);
5590 +}
5591 +
5592 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5593 +{
5594 + return (*(volatile const int *) &v->counter);
5595 +}
5596
5597 /*
5598 * atomic_set - set atomic variable
5599 @@ -38,7 +62,15 @@
5600 *
5601 * Atomically sets the value of @v to @i.
5602 */
5603 -#define atomic_set(v, i) ((v)->counter = (i))
5604 +static inline void atomic_set(atomic_t *v, int i)
5605 +{
5606 + v->counter = i;
5607 +}
5608 +
5609 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5610 +{
5611 + v->counter = i;
5612 +}
5613
5614 /*
5615 * atomic_add - add integer to atomic variable
5616 @@ -47,7 +79,67 @@
5617 *
5618 * Atomically adds @i to @v.
5619 */
5620 -static __inline__ void atomic_add(int i, atomic_t * v)
5621 +static __inline__ void atomic_add(int i, atomic_t *v)
5622 +{
5623 + int temp;
5624 +
5625 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5626 + __asm__ __volatile__(
5627 + " .set mips3 \n"
5628 + "1: ll %0, %1 # atomic_add \n"
5629 +#ifdef CONFIG_PAX_REFCOUNT
5630 + /* Exception on overflow. */
5631 + "2: add %0, %2 \n"
5632 +#else
5633 + " addu %0, %2 \n"
5634 +#endif
5635 + " sc %0, %1 \n"
5636 + " beqzl %0, 1b \n"
5637 +#ifdef CONFIG_PAX_REFCOUNT
5638 + "3: \n"
5639 + _ASM_EXTABLE(2b, 3b)
5640 +#endif
5641 + " .set mips0 \n"
5642 + : "=&r" (temp), "+m" (v->counter)
5643 + : "Ir" (i));
5644 + } else if (kernel_uses_llsc) {
5645 + __asm__ __volatile__(
5646 + " .set mips3 \n"
5647 + "1: ll %0, %1 # atomic_add \n"
5648 +#ifdef CONFIG_PAX_REFCOUNT
5649 + /* Exception on overflow. */
5650 + "2: add %0, %2 \n"
5651 +#else
5652 + " addu %0, %2 \n"
5653 +#endif
5654 + " sc %0, %1 \n"
5655 + " beqz %0, 1b \n"
5656 +#ifdef CONFIG_PAX_REFCOUNT
5657 + "3: \n"
5658 + _ASM_EXTABLE(2b, 3b)
5659 +#endif
5660 + " .set mips0 \n"
5661 + : "=&r" (temp), "+m" (v->counter)
5662 + : "Ir" (i));
5663 + } else {
5664 + unsigned long flags;
5665 +
5666 + raw_local_irq_save(flags);
5667 + __asm__ __volatile__(
5668 +#ifdef CONFIG_PAX_REFCOUNT
5669 + /* Exception on overflow. */
5670 + "1: add %0, %1 \n"
5671 + "2: \n"
5672 + _ASM_EXTABLE(1b, 2b)
5673 +#else
5674 + " addu %0, %1 \n"
5675 +#endif
5676 + : "+r" (v->counter) : "Ir" (i));
5677 + raw_local_irq_restore(flags);
5678 + }
5679 +}
5680 +
5681 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5682 {
5683 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5684 int temp;
5685 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5686 *
5687 * Atomically subtracts @i from @v.
5688 */
5689 -static __inline__ void atomic_sub(int i, atomic_t * v)
5690 +static __inline__ void atomic_sub(int i, atomic_t *v)
5691 +{
5692 + int temp;
5693 +
5694 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5695 + __asm__ __volatile__(
5696 + " .set mips3 \n"
5697 + "1: ll %0, %1 # atomic64_sub \n"
5698 +#ifdef CONFIG_PAX_REFCOUNT
5699 + /* Exception on overflow. */
5700 + "2: sub %0, %2 \n"
5701 +#else
5702 + " subu %0, %2 \n"
5703 +#endif
5704 + " sc %0, %1 \n"
5705 + " beqzl %0, 1b \n"
5706 +#ifdef CONFIG_PAX_REFCOUNT
5707 + "3: \n"
5708 + _ASM_EXTABLE(2b, 3b)
5709 +#endif
5710 + " .set mips0 \n"
5711 + : "=&r" (temp), "+m" (v->counter)
5712 + : "Ir" (i));
5713 + } else if (kernel_uses_llsc) {
5714 + __asm__ __volatile__(
5715 + " .set mips3 \n"
5716 + "1: ll %0, %1 # atomic64_sub \n"
5717 +#ifdef CONFIG_PAX_REFCOUNT
5718 + /* Exception on overflow. */
5719 + "2: sub %0, %2 \n"
5720 +#else
5721 + " subu %0, %2 \n"
5722 +#endif
5723 + " sc %0, %1 \n"
5724 + " beqz %0, 1b \n"
5725 +#ifdef CONFIG_PAX_REFCOUNT
5726 + "3: \n"
5727 + _ASM_EXTABLE(2b, 3b)
5728 +#endif
5729 + " .set mips0 \n"
5730 + : "=&r" (temp), "+m" (v->counter)
5731 + : "Ir" (i));
5732 + } else {
5733 + unsigned long flags;
5734 +
5735 + raw_local_irq_save(flags);
5736 + __asm__ __volatile__(
5737 +#ifdef CONFIG_PAX_REFCOUNT
5738 + /* Exception on overflow. */
5739 + "1: sub %0, %1 \n"
5740 + "2: \n"
5741 + _ASM_EXTABLE(1b, 2b)
5742 +#else
5743 + " subu %0, %1 \n"
5744 +#endif
5745 + : "+r" (v->counter) : "Ir" (i));
5746 + raw_local_irq_restore(flags);
5747 + }
5748 +}
5749 +
5750 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5751 {
5752 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5753 int temp;
5754 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5755 /*
5756 * Same as above, but return the result value
5757 */
5758 -static __inline__ int atomic_add_return(int i, atomic_t * v)
5759 +static __inline__ int atomic_add_return(int i, atomic_t *v)
5760 +{
5761 + int result;
5762 + int temp;
5763 +
5764 + smp_mb__before_llsc();
5765 +
5766 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5767 + __asm__ __volatile__(
5768 + " .set mips3 \n"
5769 + "1: ll %1, %2 # atomic_add_return \n"
5770 +#ifdef CONFIG_PAX_REFCOUNT
5771 + "2: add %0, %1, %3 \n"
5772 +#else
5773 + " addu %0, %1, %3 \n"
5774 +#endif
5775 + " sc %0, %2 \n"
5776 + " beqzl %0, 1b \n"
5777 +#ifdef CONFIG_PAX_REFCOUNT
5778 + " b 4f \n"
5779 + " .set noreorder \n"
5780 + "3: b 5f \n"
5781 + " move %0, %1 \n"
5782 + " .set reorder \n"
5783 + _ASM_EXTABLE(2b, 3b)
5784 +#endif
5785 + "4: addu %0, %1, %3 \n"
5786 +#ifdef CONFIG_PAX_REFCOUNT
5787 + "5: \n"
5788 +#endif
5789 + " .set mips0 \n"
5790 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5791 + : "Ir" (i));
5792 + } else if (kernel_uses_llsc) {
5793 + __asm__ __volatile__(
5794 + " .set mips3 \n"
5795 + "1: ll %1, %2 # atomic_add_return \n"
5796 +#ifdef CONFIG_PAX_REFCOUNT
5797 + "2: add %0, %1, %3 \n"
5798 +#else
5799 + " addu %0, %1, %3 \n"
5800 +#endif
5801 + " sc %0, %2 \n"
5802 + " bnez %0, 4f \n"
5803 + " b 1b \n"
5804 +#ifdef CONFIG_PAX_REFCOUNT
5805 + " .set noreorder \n"
5806 + "3: b 5f \n"
5807 + " move %0, %1 \n"
5808 + " .set reorder \n"
5809 + _ASM_EXTABLE(2b, 3b)
5810 +#endif
5811 + "4: addu %0, %1, %3 \n"
5812 +#ifdef CONFIG_PAX_REFCOUNT
5813 + "5: \n"
5814 +#endif
5815 + " .set mips0 \n"
5816 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5817 + : "Ir" (i));
5818 + } else {
5819 + unsigned long flags;
5820 +
5821 + raw_local_irq_save(flags);
5822 + __asm__ __volatile__(
5823 + " lw %0, %1 \n"
5824 +#ifdef CONFIG_PAX_REFCOUNT
5825 + /* Exception on overflow. */
5826 + "1: add %0, %2 \n"
5827 +#else
5828 + " addu %0, %2 \n"
5829 +#endif
5830 + " sw %0, %1 \n"
5831 +#ifdef CONFIG_PAX_REFCOUNT
5832 + /* Note: Dest reg is not modified on overflow */
5833 + "2: \n"
5834 + _ASM_EXTABLE(1b, 2b)
5835 +#endif
5836 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5837 + raw_local_irq_restore(flags);
5838 + }
5839 +
5840 + smp_llsc_mb();
5841 +
5842 + return result;
5843 +}
5844 +
5845 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5846 {
5847 int result;
5848
5849 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5850 return result;
5851 }
5852
5853 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
5854 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
5855 +{
5856 + int result;
5857 + int temp;
5858 +
5859 + smp_mb__before_llsc();
5860 +
5861 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5862 + __asm__ __volatile__(
5863 + " .set mips3 \n"
5864 + "1: ll %1, %2 # atomic_sub_return \n"
5865 +#ifdef CONFIG_PAX_REFCOUNT
5866 + "2: sub %0, %1, %3 \n"
5867 +#else
5868 + " subu %0, %1, %3 \n"
5869 +#endif
5870 + " sc %0, %2 \n"
5871 + " beqzl %0, 1b \n"
5872 +#ifdef CONFIG_PAX_REFCOUNT
5873 + " b 4f \n"
5874 + " .set noreorder \n"
5875 + "3: b 5f \n"
5876 + " move %0, %1 \n"
5877 + " .set reorder \n"
5878 + _ASM_EXTABLE(2b, 3b)
5879 +#endif
5880 + "4: subu %0, %1, %3 \n"
5881 +#ifdef CONFIG_PAX_REFCOUNT
5882 + "5: \n"
5883 +#endif
5884 + " .set mips0 \n"
5885 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5886 + : "Ir" (i), "m" (v->counter)
5887 + : "memory");
5888 + } else if (kernel_uses_llsc) {
5889 + __asm__ __volatile__(
5890 + " .set mips3 \n"
5891 + "1: ll %1, %2 # atomic_sub_return \n"
5892 +#ifdef CONFIG_PAX_REFCOUNT
5893 + "2: sub %0, %1, %3 \n"
5894 +#else
5895 + " subu %0, %1, %3 \n"
5896 +#endif
5897 + " sc %0, %2 \n"
5898 + " bnez %0, 4f \n"
5899 + " b 1b \n"
5900 +#ifdef CONFIG_PAX_REFCOUNT
5901 + " .set noreorder \n"
5902 + "3: b 5f \n"
5903 + " move %0, %1 \n"
5904 + " .set reorder \n"
5905 + _ASM_EXTABLE(2b, 3b)
5906 +#endif
5907 + "4: subu %0, %1, %3 \n"
5908 +#ifdef CONFIG_PAX_REFCOUNT
5909 + "5: \n"
5910 +#endif
5911 + " .set mips0 \n"
5912 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5913 + : "Ir" (i));
5914 + } else {
5915 + unsigned long flags;
5916 +
5917 + raw_local_irq_save(flags);
5918 + __asm__ __volatile__(
5919 + " lw %0, %1 \n"
5920 +#ifdef CONFIG_PAX_REFCOUNT
5921 + /* Exception on overflow. */
5922 + "1: sub %0, %2 \n"
5923 +#else
5924 + " subu %0, %2 \n"
5925 +#endif
5926 + " sw %0, %1 \n"
5927 +#ifdef CONFIG_PAX_REFCOUNT
5928 + /* Note: Dest reg is not modified on overflow */
5929 + "2: \n"
5930 + _ASM_EXTABLE(1b, 2b)
5931 +#endif
5932 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5933 + raw_local_irq_restore(flags);
5934 + }
5935 +
5936 + smp_llsc_mb();
5937 +
5938 + return result;
5939 +}
5940 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5941 {
5942 int result;
5943
5944 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5945 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5946 * The function returns the old value of @v minus @i.
5947 */
5948 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5949 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5950 {
5951 int result;
5952
5953 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5954 return result;
5955 }
5956
5957 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5958 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5959 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5960 +{
5961 + return cmpxchg(&v->counter, old, new);
5962 +}
5963 +
5964 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5965 + int new)
5966 +{
5967 + return cmpxchg(&(v->counter), old, new);
5968 +}
5969 +
5970 +static inline int atomic_xchg(atomic_t *v, int new)
5971 +{
5972 + return xchg(&v->counter, new);
5973 +}
5974 +
5975 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5976 +{
5977 + return xchg(&(v->counter), new);
5978 +}
5979
5980 /**
5981 * __atomic_add_unless - add unless the number is a given value
5982 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5983
5984 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5985 #define atomic_inc_return(v) atomic_add_return(1, (v))
5986 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5987 +{
5988 + return atomic_add_return_unchecked(1, v);
5989 +}
5990
5991 /*
5992 * atomic_sub_and_test - subtract value from variable and test result
5993 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5994 * other cases.
5995 */
5996 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5997 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5998 +{
5999 + return atomic_add_return_unchecked(1, v) == 0;
6000 +}
6001
6002 /*
6003 * atomic_dec_and_test - decrement by 1 and test
6004 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6005 * Atomically increments @v by 1.
6006 */
6007 #define atomic_inc(v) atomic_add(1, (v))
6008 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6009 +{
6010 + atomic_add_unchecked(1, v);
6011 +}
6012
6013 /*
6014 * atomic_dec - decrement and test
6015 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6016 * Atomically decrements @v by 1.
6017 */
6018 #define atomic_dec(v) atomic_sub(1, (v))
6019 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6020 +{
6021 + atomic_sub_unchecked(1, v);
6022 +}
6023
6024 /*
6025 * atomic_add_negative - add and test if negative
6026 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6027 * @v: pointer of type atomic64_t
6028 *
6029 */
6030 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6031 +static inline long atomic64_read(const atomic64_t *v)
6032 +{
6033 + return (*(volatile const long *) &v->counter);
6034 +}
6035 +
6036 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6037 +{
6038 + return (*(volatile const long *) &v->counter);
6039 +}
6040
6041 /*
6042 * atomic64_set - set atomic variable
6043 * @v: pointer of type atomic64_t
6044 * @i: required value
6045 */
6046 -#define atomic64_set(v, i) ((v)->counter = (i))
6047 +static inline void atomic64_set(atomic64_t *v, long i)
6048 +{
6049 + v->counter = i;
6050 +}
6051 +
6052 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6053 +{
6054 + v->counter = i;
6055 +}
6056
6057 /*
6058 * atomic64_add - add integer to atomic variable
6059 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6060 *
6061 * Atomically adds @i to @v.
6062 */
6063 -static __inline__ void atomic64_add(long i, atomic64_t * v)
6064 +static __inline__ void atomic64_add(long i, atomic64_t *v)
6065 +{
6066 + long temp;
6067 +
6068 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6069 + __asm__ __volatile__(
6070 + " .set mips3 \n"
6071 + "1: lld %0, %1 # atomic64_add \n"
6072 +#ifdef CONFIG_PAX_REFCOUNT
6073 + /* Exception on overflow. */
6074 + "2: dadd %0, %2 \n"
6075 +#else
6076 + " daddu %0, %2 \n"
6077 +#endif
6078 + " scd %0, %1 \n"
6079 + " beqzl %0, 1b \n"
6080 +#ifdef CONFIG_PAX_REFCOUNT
6081 + "3: \n"
6082 + _ASM_EXTABLE(2b, 3b)
6083 +#endif
6084 + " .set mips0 \n"
6085 + : "=&r" (temp), "+m" (v->counter)
6086 + : "Ir" (i));
6087 + } else if (kernel_uses_llsc) {
6088 + __asm__ __volatile__(
6089 + " .set mips3 \n"
6090 + "1: lld %0, %1 # atomic64_add \n"
6091 +#ifdef CONFIG_PAX_REFCOUNT
6092 + /* Exception on overflow. */
6093 + "2: dadd %0, %2 \n"
6094 +#else
6095 + " daddu %0, %2 \n"
6096 +#endif
6097 + " scd %0, %1 \n"
6098 + " beqz %0, 1b \n"
6099 +#ifdef CONFIG_PAX_REFCOUNT
6100 + "3: \n"
6101 + _ASM_EXTABLE(2b, 3b)
6102 +#endif
6103 + " .set mips0 \n"
6104 + : "=&r" (temp), "+m" (v->counter)
6105 + : "Ir" (i));
6106 + } else {
6107 + unsigned long flags;
6108 +
6109 + raw_local_irq_save(flags);
6110 + __asm__ __volatile__(
6111 +#ifdef CONFIG_PAX_REFCOUNT
6112 + /* Exception on overflow. */
6113 + "1: dadd %0, %1 \n"
6114 + "2: \n"
6115 + _ASM_EXTABLE(1b, 2b)
6116 +#else
6117 + " daddu %0, %1 \n"
6118 +#endif
6119 + : "+r" (v->counter) : "Ir" (i));
6120 + raw_local_irq_restore(flags);
6121 + }
6122 +}
6123 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6124 {
6125 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6126 long temp;
6127 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6128 *
6129 * Atomically subtracts @i from @v.
6130 */
6131 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6132 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6133 +{
6134 + long temp;
6135 +
6136 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6137 + __asm__ __volatile__(
6138 + " .set mips3 \n"
6139 + "1: lld %0, %1 # atomic64_sub \n"
6140 +#ifdef CONFIG_PAX_REFCOUNT
6141 + /* Exception on overflow. */
6142 + "2: dsub %0, %2 \n"
6143 +#else
6144 + " dsubu %0, %2 \n"
6145 +#endif
6146 + " scd %0, %1 \n"
6147 + " beqzl %0, 1b \n"
6148 +#ifdef CONFIG_PAX_REFCOUNT
6149 + "3: \n"
6150 + _ASM_EXTABLE(2b, 3b)
6151 +#endif
6152 + " .set mips0 \n"
6153 + : "=&r" (temp), "+m" (v->counter)
6154 + : "Ir" (i));
6155 + } else if (kernel_uses_llsc) {
6156 + __asm__ __volatile__(
6157 + " .set mips3 \n"
6158 + "1: lld %0, %1 # atomic64_sub \n"
6159 +#ifdef CONFIG_PAX_REFCOUNT
6160 + /* Exception on overflow. */
6161 + "2: dsub %0, %2 \n"
6162 +#else
6163 + " dsubu %0, %2 \n"
6164 +#endif
6165 + " scd %0, %1 \n"
6166 + " beqz %0, 1b \n"
6167 +#ifdef CONFIG_PAX_REFCOUNT
6168 + "3: \n"
6169 + _ASM_EXTABLE(2b, 3b)
6170 +#endif
6171 + " .set mips0 \n"
6172 + : "=&r" (temp), "+m" (v->counter)
6173 + : "Ir" (i));
6174 + } else {
6175 + unsigned long flags;
6176 +
6177 + raw_local_irq_save(flags);
6178 + __asm__ __volatile__(
6179 +#ifdef CONFIG_PAX_REFCOUNT
6180 + /* Exception on overflow. */
6181 + "1: dsub %0, %1 \n"
6182 + "2: \n"
6183 + _ASM_EXTABLE(1b, 2b)
6184 +#else
6185 + " dsubu %0, %1 \n"
6186 +#endif
6187 + : "+r" (v->counter) : "Ir" (i));
6188 + raw_local_irq_restore(flags);
6189 + }
6190 +}
6191 +
6192 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6193 {
6194 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6195 long temp;
6196 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6197 /*
6198 * Same as above, but return the result value
6199 */
6200 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6201 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6202 +{
6203 + long result;
6204 + long temp;
6205 +
6206 + smp_mb__before_llsc();
6207 +
6208 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6209 + __asm__ __volatile__(
6210 + " .set mips3 \n"
6211 + "1: lld %1, %2 # atomic64_add_return \n"
6212 +#ifdef CONFIG_PAX_REFCOUNT
6213 + "2: dadd %0, %1, %3 \n"
6214 +#else
6215 + " daddu %0, %1, %3 \n"
6216 +#endif
6217 + " scd %0, %2 \n"
6218 + " beqzl %0, 1b \n"
6219 +#ifdef CONFIG_PAX_REFCOUNT
6220 + " b 4f \n"
6221 + " .set noreorder \n"
6222 + "3: b 5f \n"
6223 + " move %0, %1 \n"
6224 + " .set reorder \n"
6225 + _ASM_EXTABLE(2b, 3b)
6226 +#endif
6227 + "4: daddu %0, %1, %3 \n"
6228 +#ifdef CONFIG_PAX_REFCOUNT
6229 + "5: \n"
6230 +#endif
6231 + " .set mips0 \n"
6232 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6233 + : "Ir" (i));
6234 + } else if (kernel_uses_llsc) {
6235 + __asm__ __volatile__(
6236 + " .set mips3 \n"
6237 + "1: lld %1, %2 # atomic64_add_return \n"
6238 +#ifdef CONFIG_PAX_REFCOUNT
6239 + "2: dadd %0, %1, %3 \n"
6240 +#else
6241 + " daddu %0, %1, %3 \n"
6242 +#endif
6243 + " scd %0, %2 \n"
6244 + " bnez %0, 4f \n"
6245 + " b 1b \n"
6246 +#ifdef CONFIG_PAX_REFCOUNT
6247 + " .set noreorder \n"
6248 + "3: b 5f \n"
6249 + " move %0, %1 \n"
6250 + " .set reorder \n"
6251 + _ASM_EXTABLE(2b, 3b)
6252 +#endif
6253 + "4: daddu %0, %1, %3 \n"
6254 +#ifdef CONFIG_PAX_REFCOUNT
6255 + "5: \n"
6256 +#endif
6257 + " .set mips0 \n"
6258 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6259 + : "Ir" (i), "m" (v->counter)
6260 + : "memory");
6261 + } else {
6262 + unsigned long flags;
6263 +
6264 + raw_local_irq_save(flags);
6265 + __asm__ __volatile__(
6266 + " ld %0, %1 \n"
6267 +#ifdef CONFIG_PAX_REFCOUNT
6268 + /* Exception on overflow. */
6269 + "1: dadd %0, %2 \n"
6270 +#else
6271 + " daddu %0, %2 \n"
6272 +#endif
6273 + " sd %0, %1 \n"
6274 +#ifdef CONFIG_PAX_REFCOUNT
6275 + /* Note: Dest reg is not modified on overflow */
6276 + "2: \n"
6277 + _ASM_EXTABLE(1b, 2b)
6278 +#endif
6279 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6280 + raw_local_irq_restore(flags);
6281 + }
6282 +
6283 + smp_llsc_mb();
6284 +
6285 + return result;
6286 +}
6287 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6288 {
6289 long result;
6290
6291 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6292 return result;
6293 }
6294
6295 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6296 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6297 +{
6298 + long result;
6299 + long temp;
6300 +
6301 + smp_mb__before_llsc();
6302 +
6303 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6304 + long temp;
6305 +
6306 + __asm__ __volatile__(
6307 + " .set mips3 \n"
6308 + "1: lld %1, %2 # atomic64_sub_return \n"
6309 +#ifdef CONFIG_PAX_REFCOUNT
6310 + "2: dsub %0, %1, %3 \n"
6311 +#else
6312 + " dsubu %0, %1, %3 \n"
6313 +#endif
6314 + " scd %0, %2 \n"
6315 + " beqzl %0, 1b \n"
6316 +#ifdef CONFIG_PAX_REFCOUNT
6317 + " b 4f \n"
6318 + " .set noreorder \n"
6319 + "3: b 5f \n"
6320 + " move %0, %1 \n"
6321 + " .set reorder \n"
6322 + _ASM_EXTABLE(2b, 3b)
6323 +#endif
6324 + "4: dsubu %0, %1, %3 \n"
6325 +#ifdef CONFIG_PAX_REFCOUNT
6326 + "5: \n"
6327 +#endif
6328 + " .set mips0 \n"
6329 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6330 + : "Ir" (i), "m" (v->counter)
6331 + : "memory");
6332 + } else if (kernel_uses_llsc) {
6333 + __asm__ __volatile__(
6334 + " .set mips3 \n"
6335 + "1: lld %1, %2 # atomic64_sub_return \n"
6336 +#ifdef CONFIG_PAX_REFCOUNT
6337 + "2: dsub %0, %1, %3 \n"
6338 +#else
6339 + " dsubu %0, %1, %3 \n"
6340 +#endif
6341 + " scd %0, %2 \n"
6342 + " bnez %0, 4f \n"
6343 + " b 1b \n"
6344 +#ifdef CONFIG_PAX_REFCOUNT
6345 + " .set noreorder \n"
6346 + "3: b 5f \n"
6347 + " move %0, %1 \n"
6348 + " .set reorder \n"
6349 + _ASM_EXTABLE(2b, 3b)
6350 +#endif
6351 + "4: dsubu %0, %1, %3 \n"
6352 +#ifdef CONFIG_PAX_REFCOUNT
6353 + "5: \n"
6354 +#endif
6355 + " .set mips0 \n"
6356 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6357 + : "Ir" (i), "m" (v->counter)
6358 + : "memory");
6359 + } else {
6360 + unsigned long flags;
6361 +
6362 + raw_local_irq_save(flags);
6363 + __asm__ __volatile__(
6364 + " ld %0, %1 \n"
6365 +#ifdef CONFIG_PAX_REFCOUNT
6366 + /* Exception on overflow. */
6367 + "1: dsub %0, %2 \n"
6368 +#else
6369 + " dsubu %0, %2 \n"
6370 +#endif
6371 + " sd %0, %1 \n"
6372 +#ifdef CONFIG_PAX_REFCOUNT
6373 + /* Note: Dest reg is not modified on overflow */
6374 + "2: \n"
6375 + _ASM_EXTABLE(1b, 2b)
6376 +#endif
6377 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6378 + raw_local_irq_restore(flags);
6379 + }
6380 +
6381 + smp_llsc_mb();
6382 +
6383 + return result;
6384 +}
6385 +
6386 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6387 {
6388 long result;
6389
6390 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6391 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6392 * The function returns the old value of @v minus @i.
6393 */
6394 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6395 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6396 {
6397 long result;
6398
6399 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6400 return result;
6401 }
6402
6403 -#define atomic64_cmpxchg(v, o, n) \
6404 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6405 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6406 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6407 +{
6408 + return cmpxchg(&v->counter, old, new);
6409 +}
6410 +
6411 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6412 + long new)
6413 +{
6414 + return cmpxchg(&(v->counter), old, new);
6415 +}
6416 +
6417 +static inline long atomic64_xchg(atomic64_t *v, long new)
6418 +{
6419 + return xchg(&v->counter, new);
6420 +}
6421 +
6422 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6423 +{
6424 + return xchg(&(v->counter), new);
6425 +}
6426
6427 /**
6428 * atomic64_add_unless - add unless the number is a given value
6429 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6430
6431 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6432 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6433 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6434
6435 /*
6436 * atomic64_sub_and_test - subtract value from variable and test result
6437 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6438 * other cases.
6439 */
6440 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6441 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6442
6443 /*
6444 * atomic64_dec_and_test - decrement by 1 and test
6445 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6446 * Atomically increments @v by 1.
6447 */
6448 #define atomic64_inc(v) atomic64_add(1, (v))
6449 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6450
6451 /*
6452 * atomic64_dec - decrement and test
6453 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6454 * Atomically decrements @v by 1.
6455 */
6456 #define atomic64_dec(v) atomic64_sub(1, (v))
6457 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6458
6459 /*
6460 * atomic64_add_negative - add and test if negative
6461 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6462 index b4db69f..8f3b093 100644
6463 --- a/arch/mips/include/asm/cache.h
6464 +++ b/arch/mips/include/asm/cache.h
6465 @@ -9,10 +9,11 @@
6466 #ifndef _ASM_CACHE_H
6467 #define _ASM_CACHE_H
6468
6469 +#include <linux/const.h>
6470 #include <kmalloc.h>
6471
6472 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6473 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6474 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6475
6476 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6477 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6478 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6479 index d414405..6bb4ba2 100644
6480 --- a/arch/mips/include/asm/elf.h
6481 +++ b/arch/mips/include/asm/elf.h
6482 @@ -398,13 +398,16 @@ extern const char *__elf_platform;
6483 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6484 #endif
6485
6486 +#ifdef CONFIG_PAX_ASLR
6487 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6488 +
6489 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6490 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6491 +#endif
6492 +
6493 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6494 struct linux_binprm;
6495 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6496 int uses_interp);
6497
6498 -struct mm_struct;
6499 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6500 -#define arch_randomize_brk arch_randomize_brk
6501 -
6502 #endif /* _ASM_ELF_H */
6503 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6504 index c1f6afa..38cc6e9 100644
6505 --- a/arch/mips/include/asm/exec.h
6506 +++ b/arch/mips/include/asm/exec.h
6507 @@ -12,6 +12,6 @@
6508 #ifndef _ASM_EXEC_H
6509 #define _ASM_EXEC_H
6510
6511 -extern unsigned long arch_align_stack(unsigned long sp);
6512 +#define arch_align_stack(x) ((x) & ~0xfUL)
6513
6514 #endif /* _ASM_EXEC_H */
6515 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6516 index 9e8ef59..1139d6b 100644
6517 --- a/arch/mips/include/asm/hw_irq.h
6518 +++ b/arch/mips/include/asm/hw_irq.h
6519 @@ -10,7 +10,7 @@
6520
6521 #include <linux/atomic.h>
6522
6523 -extern atomic_t irq_err_count;
6524 +extern atomic_unchecked_t irq_err_count;
6525
6526 /*
6527 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6528 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6529 index d44622c..64990d2 100644
6530 --- a/arch/mips/include/asm/local.h
6531 +++ b/arch/mips/include/asm/local.h
6532 @@ -12,15 +12,25 @@ typedef struct
6533 atomic_long_t a;
6534 } local_t;
6535
6536 +typedef struct {
6537 + atomic_long_unchecked_t a;
6538 +} local_unchecked_t;
6539 +
6540 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6541
6542 #define local_read(l) atomic_long_read(&(l)->a)
6543 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6544 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6545 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6546
6547 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6548 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6549 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6550 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6551 #define local_inc(l) atomic_long_inc(&(l)->a)
6552 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6553 #define local_dec(l) atomic_long_dec(&(l)->a)
6554 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6555
6556 /*
6557 * Same as above, but return the result value
6558 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6559 return result;
6560 }
6561
6562 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6563 +{
6564 + unsigned long result;
6565 +
6566 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6567 + unsigned long temp;
6568 +
6569 + __asm__ __volatile__(
6570 + " .set mips3 \n"
6571 + "1:" __LL "%1, %2 # local_add_return \n"
6572 + " addu %0, %1, %3 \n"
6573 + __SC "%0, %2 \n"
6574 + " beqzl %0, 1b \n"
6575 + " addu %0, %1, %3 \n"
6576 + " .set mips0 \n"
6577 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6578 + : "Ir" (i), "m" (l->a.counter)
6579 + : "memory");
6580 + } else if (kernel_uses_llsc) {
6581 + unsigned long temp;
6582 +
6583 + __asm__ __volatile__(
6584 + " .set mips3 \n"
6585 + "1:" __LL "%1, %2 # local_add_return \n"
6586 + " addu %0, %1, %3 \n"
6587 + __SC "%0, %2 \n"
6588 + " beqz %0, 1b \n"
6589 + " addu %0, %1, %3 \n"
6590 + " .set mips0 \n"
6591 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6592 + : "Ir" (i), "m" (l->a.counter)
6593 + : "memory");
6594 + } else {
6595 + unsigned long flags;
6596 +
6597 + local_irq_save(flags);
6598 + result = l->a.counter;
6599 + result += i;
6600 + l->a.counter = result;
6601 + local_irq_restore(flags);
6602 + }
6603 +
6604 + return result;
6605 +}
6606 +
6607 static __inline__ long local_sub_return(long i, local_t * l)
6608 {
6609 unsigned long result;
6610 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6611
6612 #define local_cmpxchg(l, o, n) \
6613 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6614 +#define local_cmpxchg_unchecked(l, o, n) \
6615 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6616 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6617
6618 /**
6619 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6620 index 5e08bcc..cfedefc 100644
6621 --- a/arch/mips/include/asm/page.h
6622 +++ b/arch/mips/include/asm/page.h
6623 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6624 #ifdef CONFIG_CPU_MIPS32
6625 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6626 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6627 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6628 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6629 #else
6630 typedef struct { unsigned long long pte; } pte_t;
6631 #define pte_val(x) ((x).pte)
6632 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6633 index b336037..5b874cc 100644
6634 --- a/arch/mips/include/asm/pgalloc.h
6635 +++ b/arch/mips/include/asm/pgalloc.h
6636 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6637 {
6638 set_pud(pud, __pud((unsigned long)pmd));
6639 }
6640 +
6641 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6642 +{
6643 + pud_populate(mm, pud, pmd);
6644 +}
6645 #endif
6646
6647 /*
6648 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6649 index 008324d..f67c239 100644
6650 --- a/arch/mips/include/asm/pgtable.h
6651 +++ b/arch/mips/include/asm/pgtable.h
6652 @@ -20,6 +20,9 @@
6653 #include <asm/io.h>
6654 #include <asm/pgtable-bits.h>
6655
6656 +#define ktla_ktva(addr) (addr)
6657 +#define ktva_ktla(addr) (addr)
6658 +
6659 struct mm_struct;
6660 struct vm_area_struct;
6661
6662 diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6663 index 25da651..ae2a259 100644
6664 --- a/arch/mips/include/asm/smtc_proc.h
6665 +++ b/arch/mips/include/asm/smtc_proc.h
6666 @@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6667
6668 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6669
6670 -extern atomic_t smtc_fpu_recoveries;
6671 +extern atomic_unchecked_t smtc_fpu_recoveries;
6672
6673 #endif /* __ASM_SMTC_PROC_H */
6674 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6675 index 24846f9..61c49f0 100644
6676 --- a/arch/mips/include/asm/thread_info.h
6677 +++ b/arch/mips/include/asm/thread_info.h
6678 @@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6679 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6680 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6681 #define TIF_32BIT_FPREGS 27 /* 32-bit floating point registers */
6682 +/* li takes a 32bit immediate */
6683 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6684 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6685
6686 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6687 @@ -134,13 +136,14 @@ static inline struct thread_info *current_thread_info(void)
6688 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6689 #define _TIF_32BIT_FPREGS (1<<TIF_32BIT_FPREGS)
6690 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6691 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6692
6693 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6694 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6695 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6696
6697 /* work to do in syscall_trace_leave() */
6698 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6699 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6700 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6701
6702 /* work to do on interrupt/exception return */
6703 #define _TIF_WORK_MASK \
6704 @@ -148,7 +151,7 @@ static inline struct thread_info *current_thread_info(void)
6705 /* work to do on any return to u-space */
6706 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6707 _TIF_WORK_SYSCALL_EXIT | \
6708 - _TIF_SYSCALL_TRACEPOINT)
6709 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6710
6711 /*
6712 * We stash processor id into a COP0 register to retrieve it fast
6713 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6714 index f3fa375..3af6637 100644
6715 --- a/arch/mips/include/asm/uaccess.h
6716 +++ b/arch/mips/include/asm/uaccess.h
6717 @@ -128,6 +128,7 @@ extern u64 __ua_limit;
6718 __ok == 0; \
6719 })
6720
6721 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6722 #define access_ok(type, addr, size) \
6723 likely(__access_ok((addr), (size), __access_mask))
6724
6725 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6726 index 1188e00..41cf144 100644
6727 --- a/arch/mips/kernel/binfmt_elfn32.c
6728 +++ b/arch/mips/kernel/binfmt_elfn32.c
6729 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6730 #undef ELF_ET_DYN_BASE
6731 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6732
6733 +#ifdef CONFIG_PAX_ASLR
6734 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6735 +
6736 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6737 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6738 +#endif
6739 +
6740 #include <asm/processor.h>
6741 #include <linux/module.h>
6742 #include <linux/elfcore.h>
6743 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6744 index 7faf5f2..f3d3cf4 100644
6745 --- a/arch/mips/kernel/binfmt_elfo32.c
6746 +++ b/arch/mips/kernel/binfmt_elfo32.c
6747 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6748 #undef ELF_ET_DYN_BASE
6749 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6750
6751 +#ifdef CONFIG_PAX_ASLR
6752 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6753 +
6754 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6755 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6756 +#endif
6757 +
6758 #include <asm/processor.h>
6759
6760 /*
6761 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6762 index 2b91fe8..fe4f6b4 100644
6763 --- a/arch/mips/kernel/i8259.c
6764 +++ b/arch/mips/kernel/i8259.c
6765 @@ -205,7 +205,7 @@ spurious_8259A_irq:
6766 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6767 spurious_irq_mask |= irqmask;
6768 }
6769 - atomic_inc(&irq_err_count);
6770 + atomic_inc_unchecked(&irq_err_count);
6771 /*
6772 * Theoretically we do not have to handle this IRQ,
6773 * but in Linux this does not cause problems and is
6774 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6775 index 44a1f79..2bd6aa3 100644
6776 --- a/arch/mips/kernel/irq-gt641xx.c
6777 +++ b/arch/mips/kernel/irq-gt641xx.c
6778 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6779 }
6780 }
6781
6782 - atomic_inc(&irq_err_count);
6783 + atomic_inc_unchecked(&irq_err_count);
6784 }
6785
6786 void __init gt641xx_irq_init(void)
6787 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6788 index d1fea7a..45602ea 100644
6789 --- a/arch/mips/kernel/irq.c
6790 +++ b/arch/mips/kernel/irq.c
6791 @@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6792 printk("unexpected IRQ # %d\n", irq);
6793 }
6794
6795 -atomic_t irq_err_count;
6796 +atomic_unchecked_t irq_err_count;
6797
6798 int arch_show_interrupts(struct seq_file *p, int prec)
6799 {
6800 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6801 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6802 return 0;
6803 }
6804
6805 asmlinkage void spurious_interrupt(void)
6806 {
6807 - atomic_inc(&irq_err_count);
6808 + atomic_inc_unchecked(&irq_err_count);
6809 }
6810
6811 void __init init_IRQ(void)
6812 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6813 index 6ae540e..b7396dc 100644
6814 --- a/arch/mips/kernel/process.c
6815 +++ b/arch/mips/kernel/process.c
6816 @@ -562,15 +562,3 @@ unsigned long get_wchan(struct task_struct *task)
6817 out:
6818 return pc;
6819 }
6820 -
6821 -/*
6822 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6823 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6824 - */
6825 -unsigned long arch_align_stack(unsigned long sp)
6826 -{
6827 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6828 - sp -= get_random_int() & ~PAGE_MASK;
6829 -
6830 - return sp & ALMASK;
6831 -}
6832 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6833 index 7da9b76..21578be 100644
6834 --- a/arch/mips/kernel/ptrace.c
6835 +++ b/arch/mips/kernel/ptrace.c
6836 @@ -658,6 +658,10 @@ long arch_ptrace(struct task_struct *child, long request,
6837 return ret;
6838 }
6839
6840 +#ifdef CONFIG_GRKERNSEC_SETXID
6841 +extern void gr_delayed_cred_worker(void);
6842 +#endif
6843 +
6844 /*
6845 * Notification of system call entry/exit
6846 * - triggered by current->work.syscall_trace
6847 @@ -674,6 +678,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6848 tracehook_report_syscall_entry(regs))
6849 ret = -1;
6850
6851 +#ifdef CONFIG_GRKERNSEC_SETXID
6852 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6853 + gr_delayed_cred_worker();
6854 +#endif
6855 +
6856 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6857 trace_sys_enter(regs, regs->regs[2]);
6858
6859 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6860 index 07fc524..b9d7f28 100644
6861 --- a/arch/mips/kernel/reset.c
6862 +++ b/arch/mips/kernel/reset.c
6863 @@ -13,6 +13,7 @@
6864 #include <linux/reboot.h>
6865
6866 #include <asm/reboot.h>
6867 +#include <asm/bug.h>
6868
6869 /*
6870 * Urgs ... Too many MIPS machines to handle this in a generic way.
6871 @@ -29,16 +30,19 @@ void machine_restart(char *command)
6872 {
6873 if (_machine_restart)
6874 _machine_restart(command);
6875 + BUG();
6876 }
6877
6878 void machine_halt(void)
6879 {
6880 if (_machine_halt)
6881 _machine_halt();
6882 + BUG();
6883 }
6884
6885 void machine_power_off(void)
6886 {
6887 if (pm_power_off)
6888 pm_power_off();
6889 + BUG();
6890 }
6891 diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6892 index c10aa84..9ec2e60 100644
6893 --- a/arch/mips/kernel/smtc-proc.c
6894 +++ b/arch/mips/kernel/smtc-proc.c
6895 @@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6896
6897 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6898
6899 -atomic_t smtc_fpu_recoveries;
6900 +atomic_unchecked_t smtc_fpu_recoveries;
6901
6902 static int smtc_proc_show(struct seq_file *m, void *v)
6903 {
6904 @@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6905 for(i = 0; i < NR_CPUS; i++)
6906 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6907 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6908 - atomic_read(&smtc_fpu_recoveries));
6909 + atomic_read_unchecked(&smtc_fpu_recoveries));
6910 return 0;
6911 }
6912
6913 @@ -73,7 +73,7 @@ void init_smtc_stats(void)
6914 smtc_cpu_stats[i].selfipis = 0;
6915 }
6916
6917 - atomic_set(&smtc_fpu_recoveries, 0);
6918 + atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6919
6920 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6921 }
6922 diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6923 index dfc1b91..11a2c07 100644
6924 --- a/arch/mips/kernel/smtc.c
6925 +++ b/arch/mips/kernel/smtc.c
6926 @@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6927 }
6928 smtc_ipi_qdump();
6929 printk("%d Recoveries of \"stolen\" FPU\n",
6930 - atomic_read(&smtc_fpu_recoveries));
6931 + atomic_read_unchecked(&smtc_fpu_recoveries));
6932 }
6933
6934
6935 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6936 index c24ad5f..9983ab2 100644
6937 --- a/arch/mips/kernel/sync-r4k.c
6938 +++ b/arch/mips/kernel/sync-r4k.c
6939 @@ -20,8 +20,8 @@
6940 #include <asm/mipsregs.h>
6941
6942 static atomic_t count_start_flag = ATOMIC_INIT(0);
6943 -static atomic_t count_count_start = ATOMIC_INIT(0);
6944 -static atomic_t count_count_stop = ATOMIC_INIT(0);
6945 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6946 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6947 static atomic_t count_reference = ATOMIC_INIT(0);
6948
6949 #define COUNTON 100
6950 @@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
6951
6952 for (i = 0; i < NR_LOOPS; i++) {
6953 /* slaves loop on '!= 2' */
6954 - while (atomic_read(&count_count_start) != 1)
6955 + while (atomic_read_unchecked(&count_count_start) != 1)
6956 mb();
6957 - atomic_set(&count_count_stop, 0);
6958 + atomic_set_unchecked(&count_count_stop, 0);
6959 smp_wmb();
6960
6961 /* this lets the slaves write their count register */
6962 - atomic_inc(&count_count_start);
6963 + atomic_inc_unchecked(&count_count_start);
6964
6965 /*
6966 * Everyone initialises count in the last loop:
6967 @@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
6968 /*
6969 * Wait for all slaves to leave the synchronization point:
6970 */
6971 - while (atomic_read(&count_count_stop) != 1)
6972 + while (atomic_read_unchecked(&count_count_stop) != 1)
6973 mb();
6974 - atomic_set(&count_count_start, 0);
6975 + atomic_set_unchecked(&count_count_start, 0);
6976 smp_wmb();
6977 - atomic_inc(&count_count_stop);
6978 + atomic_inc_unchecked(&count_count_stop);
6979 }
6980 /* Arrange for an interrupt in a short while */
6981 write_c0_compare(read_c0_count() + COUNTON);
6982 @@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
6983 initcount = atomic_read(&count_reference);
6984
6985 for (i = 0; i < NR_LOOPS; i++) {
6986 - atomic_inc(&count_count_start);
6987 - while (atomic_read(&count_count_start) != 2)
6988 + atomic_inc_unchecked(&count_count_start);
6989 + while (atomic_read_unchecked(&count_count_start) != 2)
6990 mb();
6991
6992 /*
6993 @@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
6994 if (i == NR_LOOPS-1)
6995 write_c0_count(initcount);
6996
6997 - atomic_inc(&count_count_stop);
6998 - while (atomic_read(&count_count_stop) != 2)
6999 + atomic_inc_unchecked(&count_count_stop);
7000 + while (atomic_read_unchecked(&count_count_stop) != 2)
7001 mb();
7002 }
7003 /* Arrange for an interrupt in a short while */
7004 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7005 index e0b4996..6b43ce7 100644
7006 --- a/arch/mips/kernel/traps.c
7007 +++ b/arch/mips/kernel/traps.c
7008 @@ -691,7 +691,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7009 siginfo_t info;
7010
7011 prev_state = exception_enter();
7012 - die_if_kernel("Integer overflow", regs);
7013 + if (unlikely(!user_mode(regs))) {
7014 +
7015 +#ifdef CONFIG_PAX_REFCOUNT
7016 + if (fixup_exception(regs)) {
7017 + pax_report_refcount_overflow(regs);
7018 + exception_exit(prev_state);
7019 + return;
7020 + }
7021 +#endif
7022 +
7023 + die("Integer overflow", regs);
7024 + }
7025
7026 info.si_code = FPE_INTOVF;
7027 info.si_signo = SIGFPE;
7028 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7029 index becc42b..9e43d4b 100644
7030 --- a/arch/mips/mm/fault.c
7031 +++ b/arch/mips/mm/fault.c
7032 @@ -28,6 +28,23 @@
7033 #include <asm/highmem.h> /* For VMALLOC_END */
7034 #include <linux/kdebug.h>
7035
7036 +#ifdef CONFIG_PAX_PAGEEXEC
7037 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7038 +{
7039 + unsigned long i;
7040 +
7041 + printk(KERN_ERR "PAX: bytes at PC: ");
7042 + for (i = 0; i < 5; i++) {
7043 + unsigned int c;
7044 + if (get_user(c, (unsigned int *)pc+i))
7045 + printk(KERN_CONT "???????? ");
7046 + else
7047 + printk(KERN_CONT "%08x ", c);
7048 + }
7049 + printk("\n");
7050 +}
7051 +#endif
7052 +
7053 /*
7054 * This routine handles page faults. It determines the address,
7055 * and the problem, and then passes it off to one of the appropriate
7056 @@ -199,6 +216,14 @@ bad_area:
7057 bad_area_nosemaphore:
7058 /* User mode accesses just cause a SIGSEGV */
7059 if (user_mode(regs)) {
7060 +
7061 +#ifdef CONFIG_PAX_PAGEEXEC
7062 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7063 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7064 + do_group_exit(SIGKILL);
7065 + }
7066 +#endif
7067 +
7068 tsk->thread.cp0_badvaddr = address;
7069 tsk->thread.error_code = write;
7070 #if 0
7071 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7072 index f1baadd..5472dca 100644
7073 --- a/arch/mips/mm/mmap.c
7074 +++ b/arch/mips/mm/mmap.c
7075 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7076 struct vm_area_struct *vma;
7077 unsigned long addr = addr0;
7078 int do_color_align;
7079 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7080 struct vm_unmapped_area_info info;
7081
7082 if (unlikely(len > TASK_SIZE))
7083 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7084 do_color_align = 1;
7085
7086 /* requesting a specific address */
7087 +
7088 +#ifdef CONFIG_PAX_RANDMMAP
7089 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7090 +#endif
7091 +
7092 if (addr) {
7093 if (do_color_align)
7094 addr = COLOUR_ALIGN(addr, pgoff);
7095 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7096 addr = PAGE_ALIGN(addr);
7097
7098 vma = find_vma(mm, addr);
7099 - if (TASK_SIZE - len >= addr &&
7100 - (!vma || addr + len <= vma->vm_start))
7101 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7102 return addr;
7103 }
7104
7105 info.length = len;
7106 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7107 info.align_offset = pgoff << PAGE_SHIFT;
7108 + info.threadstack_offset = offset;
7109
7110 if (dir == DOWN) {
7111 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7112 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7113 {
7114 unsigned long random_factor = 0UL;
7115
7116 +#ifdef CONFIG_PAX_RANDMMAP
7117 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7118 +#endif
7119 +
7120 if (current->flags & PF_RANDOMIZE) {
7121 random_factor = get_random_int();
7122 random_factor = random_factor << PAGE_SHIFT;
7123 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7124
7125 if (mmap_is_legacy()) {
7126 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7127 +
7128 +#ifdef CONFIG_PAX_RANDMMAP
7129 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7130 + mm->mmap_base += mm->delta_mmap;
7131 +#endif
7132 +
7133 mm->get_unmapped_area = arch_get_unmapped_area;
7134 } else {
7135 mm->mmap_base = mmap_base(random_factor);
7136 +
7137 +#ifdef CONFIG_PAX_RANDMMAP
7138 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7139 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7140 +#endif
7141 +
7142 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7143 }
7144 }
7145
7146 -static inline unsigned long brk_rnd(void)
7147 -{
7148 - unsigned long rnd = get_random_int();
7149 -
7150 - rnd = rnd << PAGE_SHIFT;
7151 - /* 8MB for 32bit, 256MB for 64bit */
7152 - if (TASK_IS_32BIT_ADDR)
7153 - rnd = rnd & 0x7ffffful;
7154 - else
7155 - rnd = rnd & 0xffffffful;
7156 -
7157 - return rnd;
7158 -}
7159 -
7160 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7161 -{
7162 - unsigned long base = mm->brk;
7163 - unsigned long ret;
7164 -
7165 - ret = PAGE_ALIGN(base + brk_rnd());
7166 -
7167 - if (ret < mm->brk)
7168 - return mm->brk;
7169 -
7170 - return ret;
7171 -}
7172 -
7173 int __virt_addr_valid(const volatile void *kaddr)
7174 {
7175 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7176 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7177 index 59cccd9..f39ac2f 100644
7178 --- a/arch/mips/pci/pci-octeon.c
7179 +++ b/arch/mips/pci/pci-octeon.c
7180 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7181
7182
7183 static struct pci_ops octeon_pci_ops = {
7184 - octeon_read_config,
7185 - octeon_write_config,
7186 + .read = octeon_read_config,
7187 + .write = octeon_write_config,
7188 };
7189
7190 static struct resource octeon_pci_mem_resource = {
7191 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7192 index 5e36c33..eb4a17b 100644
7193 --- a/arch/mips/pci/pcie-octeon.c
7194 +++ b/arch/mips/pci/pcie-octeon.c
7195 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7196 }
7197
7198 static struct pci_ops octeon_pcie0_ops = {
7199 - octeon_pcie0_read_config,
7200 - octeon_pcie0_write_config,
7201 + .read = octeon_pcie0_read_config,
7202 + .write = octeon_pcie0_write_config,
7203 };
7204
7205 static struct resource octeon_pcie0_mem_resource = {
7206 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7207 };
7208
7209 static struct pci_ops octeon_pcie1_ops = {
7210 - octeon_pcie1_read_config,
7211 - octeon_pcie1_write_config,
7212 + .read = octeon_pcie1_read_config,
7213 + .write = octeon_pcie1_write_config,
7214 };
7215
7216 static struct resource octeon_pcie1_mem_resource = {
7217 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7218 };
7219
7220 static struct pci_ops octeon_dummy_ops = {
7221 - octeon_dummy_read_config,
7222 - octeon_dummy_write_config,
7223 + .read = octeon_dummy_read_config,
7224 + .write = octeon_dummy_write_config,
7225 };
7226
7227 static struct resource octeon_dummy_mem_resource = {
7228 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7229 index a2358b4..7cead4f 100644
7230 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7231 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7232 @@ -187,9 +187,9 @@ void
7233 cont_nmi_dump(void)
7234 {
7235 #ifndef REAL_NMI_SIGNAL
7236 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7237 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7238
7239 - atomic_inc(&nmied_cpus);
7240 + atomic_inc_unchecked(&nmied_cpus);
7241 #endif
7242 /*
7243 * Only allow 1 cpu to proceed
7244 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7245 udelay(10000);
7246 }
7247 #else
7248 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7249 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7250 #endif
7251
7252 /*
7253 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7254 index a046b30..6799527 100644
7255 --- a/arch/mips/sni/rm200.c
7256 +++ b/arch/mips/sni/rm200.c
7257 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7258 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7259 spurious_irq_mask |= irqmask;
7260 }
7261 - atomic_inc(&irq_err_count);
7262 + atomic_inc_unchecked(&irq_err_count);
7263 /*
7264 * Theoretically we do not have to handle this IRQ,
7265 * but in Linux this does not cause problems and is
7266 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7267 index 41e873b..34d33a7 100644
7268 --- a/arch/mips/vr41xx/common/icu.c
7269 +++ b/arch/mips/vr41xx/common/icu.c
7270 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7271
7272 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7273
7274 - atomic_inc(&irq_err_count);
7275 + atomic_inc_unchecked(&irq_err_count);
7276
7277 return -1;
7278 }
7279 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7280 index ae0e4ee..e8f0692 100644
7281 --- a/arch/mips/vr41xx/common/irq.c
7282 +++ b/arch/mips/vr41xx/common/irq.c
7283 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7284 irq_cascade_t *cascade;
7285
7286 if (irq >= NR_IRQS) {
7287 - atomic_inc(&irq_err_count);
7288 + atomic_inc_unchecked(&irq_err_count);
7289 return;
7290 }
7291
7292 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7293 ret = cascade->get_irq(irq);
7294 irq = ret;
7295 if (ret < 0)
7296 - atomic_inc(&irq_err_count);
7297 + atomic_inc_unchecked(&irq_err_count);
7298 else
7299 irq_dispatch(irq);
7300 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7301 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7302 index 967d144..db12197 100644
7303 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7304 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7305 @@ -11,12 +11,14 @@
7306 #ifndef _ASM_PROC_CACHE_H
7307 #define _ASM_PROC_CACHE_H
7308
7309 +#include <linux/const.h>
7310 +
7311 /* L1 cache */
7312
7313 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7314 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7315 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7316 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7317 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7318 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7319
7320 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7321 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7322 index bcb5df2..84fabd2 100644
7323 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7324 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7325 @@ -16,13 +16,15 @@
7326 #ifndef _ASM_PROC_CACHE_H
7327 #define _ASM_PROC_CACHE_H
7328
7329 +#include <linux/const.h>
7330 +
7331 /*
7332 * L1 cache
7333 */
7334 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7335 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7336 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7337 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7338 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7339 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7340
7341 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7342 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7343 index 4ce7a01..449202a 100644
7344 --- a/arch/openrisc/include/asm/cache.h
7345 +++ b/arch/openrisc/include/asm/cache.h
7346 @@ -19,11 +19,13 @@
7347 #ifndef __ASM_OPENRISC_CACHE_H
7348 #define __ASM_OPENRISC_CACHE_H
7349
7350 +#include <linux/const.h>
7351 +
7352 /* FIXME: How can we replace these with values from the CPU...
7353 * they shouldn't be hard-coded!
7354 */
7355
7356 -#define L1_CACHE_BYTES 16
7357 #define L1_CACHE_SHIFT 4
7358 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7359
7360 #endif /* __ASM_OPENRISC_CACHE_H */
7361 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7362 index 472886c..00e7df9 100644
7363 --- a/arch/parisc/include/asm/atomic.h
7364 +++ b/arch/parisc/include/asm/atomic.h
7365 @@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7366 return dec;
7367 }
7368
7369 +#define atomic64_read_unchecked(v) atomic64_read(v)
7370 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7371 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7372 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7373 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7374 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7375 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7376 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7377 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7378 +
7379 #endif /* !CONFIG_64BIT */
7380
7381
7382 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7383 index 47f11c7..3420df2 100644
7384 --- a/arch/parisc/include/asm/cache.h
7385 +++ b/arch/parisc/include/asm/cache.h
7386 @@ -5,6 +5,7 @@
7387 #ifndef __ARCH_PARISC_CACHE_H
7388 #define __ARCH_PARISC_CACHE_H
7389
7390 +#include <linux/const.h>
7391
7392 /*
7393 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7394 @@ -15,13 +16,13 @@
7395 * just ruin performance.
7396 */
7397 #ifdef CONFIG_PA20
7398 -#define L1_CACHE_BYTES 64
7399 #define L1_CACHE_SHIFT 6
7400 #else
7401 -#define L1_CACHE_BYTES 32
7402 #define L1_CACHE_SHIFT 5
7403 #endif
7404
7405 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7406 +
7407 #ifndef __ASSEMBLY__
7408
7409 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7410 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7411 index 3391d06..c23a2cc 100644
7412 --- a/arch/parisc/include/asm/elf.h
7413 +++ b/arch/parisc/include/asm/elf.h
7414 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7415
7416 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7417
7418 +#ifdef CONFIG_PAX_ASLR
7419 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7420 +
7421 +#define PAX_DELTA_MMAP_LEN 16
7422 +#define PAX_DELTA_STACK_LEN 16
7423 +#endif
7424 +
7425 /* This yields a mask that user programs can use to figure out what
7426 instruction set this CPU supports. This could be done in user space,
7427 but it's not easy, and we've already done it here. */
7428 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7429 index f213f5b..0af3e8e 100644
7430 --- a/arch/parisc/include/asm/pgalloc.h
7431 +++ b/arch/parisc/include/asm/pgalloc.h
7432 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7433 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7434 }
7435
7436 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7437 +{
7438 + pgd_populate(mm, pgd, pmd);
7439 +}
7440 +
7441 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7442 {
7443 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7444 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7445 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7446 #define pmd_free(mm, x) do { } while (0)
7447 #define pgd_populate(mm, pmd, pte) BUG()
7448 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7449
7450 #endif
7451
7452 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7453 index 22b89d1..ce34230 100644
7454 --- a/arch/parisc/include/asm/pgtable.h
7455 +++ b/arch/parisc/include/asm/pgtable.h
7456 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7457 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7458 #define PAGE_COPY PAGE_EXECREAD
7459 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7460 +
7461 +#ifdef CONFIG_PAX_PAGEEXEC
7462 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7463 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7464 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7465 +#else
7466 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7467 +# define PAGE_COPY_NOEXEC PAGE_COPY
7468 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7469 +#endif
7470 +
7471 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7472 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7473 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7474 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7475 index 4006964..fcb3cc2 100644
7476 --- a/arch/parisc/include/asm/uaccess.h
7477 +++ b/arch/parisc/include/asm/uaccess.h
7478 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7479 const void __user *from,
7480 unsigned long n)
7481 {
7482 - int sz = __compiletime_object_size(to);
7483 + size_t sz = __compiletime_object_size(to);
7484 int ret = -EFAULT;
7485
7486 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7487 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7488 ret = __copy_from_user(to, from, n);
7489 else
7490 copy_from_user_overflow();
7491 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7492 index 50dfafc..b9fc230 100644
7493 --- a/arch/parisc/kernel/module.c
7494 +++ b/arch/parisc/kernel/module.c
7495 @@ -98,16 +98,38 @@
7496
7497 /* three functions to determine where in the module core
7498 * or init pieces the location is */
7499 +static inline int in_init_rx(struct module *me, void *loc)
7500 +{
7501 + return (loc >= me->module_init_rx &&
7502 + loc < (me->module_init_rx + me->init_size_rx));
7503 +}
7504 +
7505 +static inline int in_init_rw(struct module *me, void *loc)
7506 +{
7507 + return (loc >= me->module_init_rw &&
7508 + loc < (me->module_init_rw + me->init_size_rw));
7509 +}
7510 +
7511 static inline int in_init(struct module *me, void *loc)
7512 {
7513 - return (loc >= me->module_init &&
7514 - loc <= (me->module_init + me->init_size));
7515 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7516 +}
7517 +
7518 +static inline int in_core_rx(struct module *me, void *loc)
7519 +{
7520 + return (loc >= me->module_core_rx &&
7521 + loc < (me->module_core_rx + me->core_size_rx));
7522 +}
7523 +
7524 +static inline int in_core_rw(struct module *me, void *loc)
7525 +{
7526 + return (loc >= me->module_core_rw &&
7527 + loc < (me->module_core_rw + me->core_size_rw));
7528 }
7529
7530 static inline int in_core(struct module *me, void *loc)
7531 {
7532 - return (loc >= me->module_core &&
7533 - loc <= (me->module_core + me->core_size));
7534 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7535 }
7536
7537 static inline int in_local(struct module *me, void *loc)
7538 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7539 }
7540
7541 /* align things a bit */
7542 - me->core_size = ALIGN(me->core_size, 16);
7543 - me->arch.got_offset = me->core_size;
7544 - me->core_size += gots * sizeof(struct got_entry);
7545 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7546 + me->arch.got_offset = me->core_size_rw;
7547 + me->core_size_rw += gots * sizeof(struct got_entry);
7548
7549 - me->core_size = ALIGN(me->core_size, 16);
7550 - me->arch.fdesc_offset = me->core_size;
7551 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7552 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7553 + me->arch.fdesc_offset = me->core_size_rw;
7554 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7555
7556 me->arch.got_max = gots;
7557 me->arch.fdesc_max = fdescs;
7558 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7559
7560 BUG_ON(value == 0);
7561
7562 - got = me->module_core + me->arch.got_offset;
7563 + got = me->module_core_rw + me->arch.got_offset;
7564 for (i = 0; got[i].addr; i++)
7565 if (got[i].addr == value)
7566 goto out;
7567 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7568 #ifdef CONFIG_64BIT
7569 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7570 {
7571 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7572 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7573
7574 if (!value) {
7575 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7576 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7577
7578 /* Create new one */
7579 fdesc->addr = value;
7580 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7581 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7582 return (Elf_Addr)fdesc;
7583 }
7584 #endif /* CONFIG_64BIT */
7585 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7586
7587 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7588 end = table + sechdrs[me->arch.unwind_section].sh_size;
7589 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7590 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7591
7592 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7593 me->arch.unwind_section, table, end, gp);
7594 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7595 index b7cadc4..bf4a32d 100644
7596 --- a/arch/parisc/kernel/sys_parisc.c
7597 +++ b/arch/parisc/kernel/sys_parisc.c
7598 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7599 unsigned long task_size = TASK_SIZE;
7600 int do_color_align, last_mmap;
7601 struct vm_unmapped_area_info info;
7602 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7603
7604 if (len > task_size)
7605 return -ENOMEM;
7606 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7607 goto found_addr;
7608 }
7609
7610 +#ifdef CONFIG_PAX_RANDMMAP
7611 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7612 +#endif
7613 +
7614 if (addr) {
7615 if (do_color_align && last_mmap)
7616 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7617 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7618 info.high_limit = mmap_upper_limit();
7619 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7620 info.align_offset = shared_align_offset(last_mmap, pgoff);
7621 + info.threadstack_offset = offset;
7622 addr = vm_unmapped_area(&info);
7623
7624 found_addr:
7625 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7626 unsigned long addr = addr0;
7627 int do_color_align, last_mmap;
7628 struct vm_unmapped_area_info info;
7629 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7630
7631 #ifdef CONFIG_64BIT
7632 /* This should only ever run for 32-bit processes. */
7633 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7634 }
7635
7636 /* requesting a specific address */
7637 +#ifdef CONFIG_PAX_RANDMMAP
7638 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7639 +#endif
7640 +
7641 if (addr) {
7642 if (do_color_align && last_mmap)
7643 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7644 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7645 info.high_limit = mm->mmap_base;
7646 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7647 info.align_offset = shared_align_offset(last_mmap, pgoff);
7648 + info.threadstack_offset = offset;
7649 addr = vm_unmapped_area(&info);
7650 if (!(addr & ~PAGE_MASK))
7651 goto found_addr;
7652 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7653 mm->mmap_legacy_base = mmap_legacy_base();
7654 mm->mmap_base = mmap_upper_limit();
7655
7656 +#ifdef CONFIG_PAX_RANDMMAP
7657 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
7658 + mm->mmap_legacy_base += mm->delta_mmap;
7659 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7660 + }
7661 +#endif
7662 +
7663 if (mmap_is_legacy()) {
7664 mm->mmap_base = mm->mmap_legacy_base;
7665 mm->get_unmapped_area = arch_get_unmapped_area;
7666 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7667 index 1cd1d0c..44ec918 100644
7668 --- a/arch/parisc/kernel/traps.c
7669 +++ b/arch/parisc/kernel/traps.c
7670 @@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7671
7672 down_read(&current->mm->mmap_sem);
7673 vma = find_vma(current->mm,regs->iaoq[0]);
7674 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7675 - && (vma->vm_flags & VM_EXEC)) {
7676 -
7677 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7678 fault_address = regs->iaoq[0];
7679 fault_space = regs->iasq[0];
7680
7681 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7682 index 9d08c71..e2b4d20 100644
7683 --- a/arch/parisc/mm/fault.c
7684 +++ b/arch/parisc/mm/fault.c
7685 @@ -15,6 +15,7 @@
7686 #include <linux/sched.h>
7687 #include <linux/interrupt.h>
7688 #include <linux/module.h>
7689 +#include <linux/unistd.h>
7690
7691 #include <asm/uaccess.h>
7692 #include <asm/traps.h>
7693 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7694 static unsigned long
7695 parisc_acctyp(unsigned long code, unsigned int inst)
7696 {
7697 - if (code == 6 || code == 16)
7698 + if (code == 6 || code == 7 || code == 16)
7699 return VM_EXEC;
7700
7701 switch (inst & 0xf0000000) {
7702 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7703 }
7704 #endif
7705
7706 +#ifdef CONFIG_PAX_PAGEEXEC
7707 +/*
7708 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7709 + *
7710 + * returns 1 when task should be killed
7711 + * 2 when rt_sigreturn trampoline was detected
7712 + * 3 when unpatched PLT trampoline was detected
7713 + */
7714 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7715 +{
7716 +
7717 +#ifdef CONFIG_PAX_EMUPLT
7718 + int err;
7719 +
7720 + do { /* PaX: unpatched PLT emulation */
7721 + unsigned int bl, depwi;
7722 +
7723 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7724 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7725 +
7726 + if (err)
7727 + break;
7728 +
7729 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7730 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7731 +
7732 + err = get_user(ldw, (unsigned int *)addr);
7733 + err |= get_user(bv, (unsigned int *)(addr+4));
7734 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7735 +
7736 + if (err)
7737 + break;
7738 +
7739 + if (ldw == 0x0E801096U &&
7740 + bv == 0xEAC0C000U &&
7741 + ldw2 == 0x0E881095U)
7742 + {
7743 + unsigned int resolver, map;
7744 +
7745 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7746 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7747 + if (err)
7748 + break;
7749 +
7750 + regs->gr[20] = instruction_pointer(regs)+8;
7751 + regs->gr[21] = map;
7752 + regs->gr[22] = resolver;
7753 + regs->iaoq[0] = resolver | 3UL;
7754 + regs->iaoq[1] = regs->iaoq[0] + 4;
7755 + return 3;
7756 + }
7757 + }
7758 + } while (0);
7759 +#endif
7760 +
7761 +#ifdef CONFIG_PAX_EMUTRAMP
7762 +
7763 +#ifndef CONFIG_PAX_EMUSIGRT
7764 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7765 + return 1;
7766 +#endif
7767 +
7768 + do { /* PaX: rt_sigreturn emulation */
7769 + unsigned int ldi1, ldi2, bel, nop;
7770 +
7771 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7772 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7773 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7774 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7775 +
7776 + if (err)
7777 + break;
7778 +
7779 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7780 + ldi2 == 0x3414015AU &&
7781 + bel == 0xE4008200U &&
7782 + nop == 0x08000240U)
7783 + {
7784 + regs->gr[25] = (ldi1 & 2) >> 1;
7785 + regs->gr[20] = __NR_rt_sigreturn;
7786 + regs->gr[31] = regs->iaoq[1] + 16;
7787 + regs->sr[0] = regs->iasq[1];
7788 + regs->iaoq[0] = 0x100UL;
7789 + regs->iaoq[1] = regs->iaoq[0] + 4;
7790 + regs->iasq[0] = regs->sr[2];
7791 + regs->iasq[1] = regs->sr[2];
7792 + return 2;
7793 + }
7794 + } while (0);
7795 +#endif
7796 +
7797 + return 1;
7798 +}
7799 +
7800 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7801 +{
7802 + unsigned long i;
7803 +
7804 + printk(KERN_ERR "PAX: bytes at PC: ");
7805 + for (i = 0; i < 5; i++) {
7806 + unsigned int c;
7807 + if (get_user(c, (unsigned int *)pc+i))
7808 + printk(KERN_CONT "???????? ");
7809 + else
7810 + printk(KERN_CONT "%08x ", c);
7811 + }
7812 + printk("\n");
7813 +}
7814 +#endif
7815 +
7816 int fixup_exception(struct pt_regs *regs)
7817 {
7818 const struct exception_table_entry *fix;
7819 @@ -210,8 +321,33 @@ retry:
7820
7821 good_area:
7822
7823 - if ((vma->vm_flags & acc_type) != acc_type)
7824 + if ((vma->vm_flags & acc_type) != acc_type) {
7825 +
7826 +#ifdef CONFIG_PAX_PAGEEXEC
7827 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7828 + (address & ~3UL) == instruction_pointer(regs))
7829 + {
7830 + up_read(&mm->mmap_sem);
7831 + switch (pax_handle_fetch_fault(regs)) {
7832 +
7833 +#ifdef CONFIG_PAX_EMUPLT
7834 + case 3:
7835 + return;
7836 +#endif
7837 +
7838 +#ifdef CONFIG_PAX_EMUTRAMP
7839 + case 2:
7840 + return;
7841 +#endif
7842 +
7843 + }
7844 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7845 + do_group_exit(SIGKILL);
7846 + }
7847 +#endif
7848 +
7849 goto bad_area;
7850 + }
7851
7852 /*
7853 * If for any reason at all we couldn't handle the fault, make
7854 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7855 index 957bf34..3430cc8 100644
7856 --- a/arch/powerpc/Kconfig
7857 +++ b/arch/powerpc/Kconfig
7858 @@ -393,6 +393,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7859 config KEXEC
7860 bool "kexec system call"
7861 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7862 + depends on !GRKERNSEC_KMEM
7863 help
7864 kexec is a system call that implements the ability to shutdown your
7865 current kernel, and to start another kernel. It is like a reboot
7866 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7867 index e3b1d41..8e81edf 100644
7868 --- a/arch/powerpc/include/asm/atomic.h
7869 +++ b/arch/powerpc/include/asm/atomic.h
7870 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7871 return t1;
7872 }
7873
7874 +#define atomic64_read_unchecked(v) atomic64_read(v)
7875 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7876 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7877 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7878 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7879 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7880 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7881 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7882 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7883 +
7884 #endif /* __powerpc64__ */
7885
7886 #endif /* __KERNEL__ */
7887 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7888 index ed0afc1..0332825 100644
7889 --- a/arch/powerpc/include/asm/cache.h
7890 +++ b/arch/powerpc/include/asm/cache.h
7891 @@ -3,6 +3,7 @@
7892
7893 #ifdef __KERNEL__
7894
7895 +#include <linux/const.h>
7896
7897 /* bytes per L1 cache line */
7898 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7899 @@ -22,7 +23,7 @@
7900 #define L1_CACHE_SHIFT 7
7901 #endif
7902
7903 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7904 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7905
7906 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7907
7908 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7909 index 935b5e7..7001d2d 100644
7910 --- a/arch/powerpc/include/asm/elf.h
7911 +++ b/arch/powerpc/include/asm/elf.h
7912 @@ -28,8 +28,19 @@
7913 the loader. We need to make sure that it is out of the way of the program
7914 that it will "exec", and that there is sufficient room for the brk. */
7915
7916 -extern unsigned long randomize_et_dyn(unsigned long base);
7917 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7918 +#define ELF_ET_DYN_BASE (0x20000000)
7919 +
7920 +#ifdef CONFIG_PAX_ASLR
7921 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7922 +
7923 +#ifdef __powerpc64__
7924 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7925 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7926 +#else
7927 +#define PAX_DELTA_MMAP_LEN 15
7928 +#define PAX_DELTA_STACK_LEN 15
7929 +#endif
7930 +#endif
7931
7932 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7933
7934 @@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7935 (0x7ff >> (PAGE_SHIFT - 12)) : \
7936 (0x3ffff >> (PAGE_SHIFT - 12)))
7937
7938 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7939 -#define arch_randomize_brk arch_randomize_brk
7940 -
7941 -
7942 #ifdef CONFIG_SPU_BASE
7943 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7944 #define NT_SPU 1
7945 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7946 index 8196e9c..d83a9f3 100644
7947 --- a/arch/powerpc/include/asm/exec.h
7948 +++ b/arch/powerpc/include/asm/exec.h
7949 @@ -4,6 +4,6 @@
7950 #ifndef _ASM_POWERPC_EXEC_H
7951 #define _ASM_POWERPC_EXEC_H
7952
7953 -extern unsigned long arch_align_stack(unsigned long sp);
7954 +#define arch_align_stack(x) ((x) & ~0xfUL)
7955
7956 #endif /* _ASM_POWERPC_EXEC_H */
7957 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7958 index 5acabbd..7ea14fa 100644
7959 --- a/arch/powerpc/include/asm/kmap_types.h
7960 +++ b/arch/powerpc/include/asm/kmap_types.h
7961 @@ -10,7 +10,7 @@
7962 * 2 of the License, or (at your option) any later version.
7963 */
7964
7965 -#define KM_TYPE_NR 16
7966 +#define KM_TYPE_NR 17
7967
7968 #endif /* __KERNEL__ */
7969 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7970 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
7971 index b8da913..60b608a 100644
7972 --- a/arch/powerpc/include/asm/local.h
7973 +++ b/arch/powerpc/include/asm/local.h
7974 @@ -9,15 +9,26 @@ typedef struct
7975 atomic_long_t a;
7976 } local_t;
7977
7978 +typedef struct
7979 +{
7980 + atomic_long_unchecked_t a;
7981 +} local_unchecked_t;
7982 +
7983 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
7984
7985 #define local_read(l) atomic_long_read(&(l)->a)
7986 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
7987 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
7988 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
7989
7990 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
7991 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
7992 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
7993 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
7994 #define local_inc(l) atomic_long_inc(&(l)->a)
7995 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
7996 #define local_dec(l) atomic_long_dec(&(l)->a)
7997 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
7998
7999 static __inline__ long local_add_return(long a, local_t *l)
8000 {
8001 @@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8002
8003 return t;
8004 }
8005 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8006
8007 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8008
8009 @@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8010
8011 return t;
8012 }
8013 +#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8014
8015 static __inline__ long local_inc_return(local_t *l)
8016 {
8017 @@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8018
8019 #define local_cmpxchg(l, o, n) \
8020 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8021 +#define local_cmpxchg_unchecked(l, o, n) \
8022 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8023 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8024
8025 /**
8026 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8027 index 8565c25..2865190 100644
8028 --- a/arch/powerpc/include/asm/mman.h
8029 +++ b/arch/powerpc/include/asm/mman.h
8030 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8031 }
8032 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8033
8034 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8035 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8036 {
8037 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8038 }
8039 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8040 index 32e4e21..62afb12 100644
8041 --- a/arch/powerpc/include/asm/page.h
8042 +++ b/arch/powerpc/include/asm/page.h
8043 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8044 * and needs to be executable. This means the whole heap ends
8045 * up being executable.
8046 */
8047 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8048 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8049 +#define VM_DATA_DEFAULT_FLAGS32 \
8050 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8051 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8052
8053 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8054 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8055 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8056 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8057 #endif
8058
8059 +#define ktla_ktva(addr) (addr)
8060 +#define ktva_ktla(addr) (addr)
8061 +
8062 #ifndef CONFIG_PPC_BOOK3S_64
8063 /*
8064 * Use the top bit of the higher-level page table entries to indicate whether
8065 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8066 index 88693ce..ac6f9ab 100644
8067 --- a/arch/powerpc/include/asm/page_64.h
8068 +++ b/arch/powerpc/include/asm/page_64.h
8069 @@ -153,15 +153,18 @@ do { \
8070 * stack by default, so in the absence of a PT_GNU_STACK program header
8071 * we turn execute permission off.
8072 */
8073 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8074 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8075 +#define VM_STACK_DEFAULT_FLAGS32 \
8076 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8077 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8078
8079 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8080 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8081
8082 +#ifndef CONFIG_PAX_PAGEEXEC
8083 #define VM_STACK_DEFAULT_FLAGS \
8084 (is_32bit_task() ? \
8085 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8086 +#endif
8087
8088 #include <asm-generic/getorder.h>
8089
8090 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8091 index 4b0be20..c15a27d 100644
8092 --- a/arch/powerpc/include/asm/pgalloc-64.h
8093 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8094 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8095 #ifndef CONFIG_PPC_64K_PAGES
8096
8097 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8098 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8099
8100 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8101 {
8102 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8103 pud_set(pud, (unsigned long)pmd);
8104 }
8105
8106 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8107 +{
8108 + pud_populate(mm, pud, pmd);
8109 +}
8110 +
8111 #define pmd_populate(mm, pmd, pte_page) \
8112 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8113 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8114 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8115 #endif
8116
8117 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8118 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8119
8120 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8121 pte_t *pte)
8122 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8123 index 3ebb188..e17dddf 100644
8124 --- a/arch/powerpc/include/asm/pgtable.h
8125 +++ b/arch/powerpc/include/asm/pgtable.h
8126 @@ -2,6 +2,7 @@
8127 #define _ASM_POWERPC_PGTABLE_H
8128 #ifdef __KERNEL__
8129
8130 +#include <linux/const.h>
8131 #ifndef __ASSEMBLY__
8132 #include <linux/mmdebug.h>
8133 #include <asm/processor.h> /* For TASK_SIZE */
8134 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8135 index 4aad413..85d86bf 100644
8136 --- a/arch/powerpc/include/asm/pte-hash32.h
8137 +++ b/arch/powerpc/include/asm/pte-hash32.h
8138 @@ -21,6 +21,7 @@
8139 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8140 #define _PAGE_USER 0x004 /* usermode access allowed */
8141 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8142 +#define _PAGE_EXEC _PAGE_GUARDED
8143 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8144 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8145 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8146 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8147 index 90c06ec..3517221 100644
8148 --- a/arch/powerpc/include/asm/reg.h
8149 +++ b/arch/powerpc/include/asm/reg.h
8150 @@ -248,6 +248,7 @@
8151 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8152 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8153 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8154 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8155 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8156 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8157 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8158 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8159 index 084e080..9415a3d 100644
8160 --- a/arch/powerpc/include/asm/smp.h
8161 +++ b/arch/powerpc/include/asm/smp.h
8162 @@ -51,7 +51,7 @@ struct smp_ops_t {
8163 int (*cpu_disable)(void);
8164 void (*cpu_die)(unsigned int nr);
8165 int (*cpu_bootable)(unsigned int nr);
8166 -};
8167 +} __no_const;
8168
8169 extern void smp_send_debugger_break(void);
8170 extern void start_secondary_resume(void);
8171 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8172 index b034ecd..af7e31f 100644
8173 --- a/arch/powerpc/include/asm/thread_info.h
8174 +++ b/arch/powerpc/include/asm/thread_info.h
8175 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8176 #if defined(CONFIG_PPC64)
8177 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8178 #endif
8179 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8180 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8181
8182 /* as above, but as bit values */
8183 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8184 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8185 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8186 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8187 #define _TIF_NOHZ (1<<TIF_NOHZ)
8188 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8189 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8190 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8191 - _TIF_NOHZ)
8192 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8193
8194 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8195 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8196 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8197 index 9485b43..3bd3c16 100644
8198 --- a/arch/powerpc/include/asm/uaccess.h
8199 +++ b/arch/powerpc/include/asm/uaccess.h
8200 @@ -58,6 +58,7 @@
8201
8202 #endif
8203
8204 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8205 #define access_ok(type, addr, size) \
8206 (__chk_user_ptr(addr), \
8207 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8208 @@ -318,52 +319,6 @@ do { \
8209 extern unsigned long __copy_tofrom_user(void __user *to,
8210 const void __user *from, unsigned long size);
8211
8212 -#ifndef __powerpc64__
8213 -
8214 -static inline unsigned long copy_from_user(void *to,
8215 - const void __user *from, unsigned long n)
8216 -{
8217 - unsigned long over;
8218 -
8219 - if (access_ok(VERIFY_READ, from, n))
8220 - return __copy_tofrom_user((__force void __user *)to, from, n);
8221 - if ((unsigned long)from < TASK_SIZE) {
8222 - over = (unsigned long)from + n - TASK_SIZE;
8223 - return __copy_tofrom_user((__force void __user *)to, from,
8224 - n - over) + over;
8225 - }
8226 - return n;
8227 -}
8228 -
8229 -static inline unsigned long copy_to_user(void __user *to,
8230 - const void *from, unsigned long n)
8231 -{
8232 - unsigned long over;
8233 -
8234 - if (access_ok(VERIFY_WRITE, to, n))
8235 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8236 - if ((unsigned long)to < TASK_SIZE) {
8237 - over = (unsigned long)to + n - TASK_SIZE;
8238 - return __copy_tofrom_user(to, (__force void __user *)from,
8239 - n - over) + over;
8240 - }
8241 - return n;
8242 -}
8243 -
8244 -#else /* __powerpc64__ */
8245 -
8246 -#define __copy_in_user(to, from, size) \
8247 - __copy_tofrom_user((to), (from), (size))
8248 -
8249 -extern unsigned long copy_from_user(void *to, const void __user *from,
8250 - unsigned long n);
8251 -extern unsigned long copy_to_user(void __user *to, const void *from,
8252 - unsigned long n);
8253 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8254 - unsigned long n);
8255 -
8256 -#endif /* __powerpc64__ */
8257 -
8258 static inline unsigned long __copy_from_user_inatomic(void *to,
8259 const void __user *from, unsigned long n)
8260 {
8261 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8262 if (ret == 0)
8263 return 0;
8264 }
8265 +
8266 + if (!__builtin_constant_p(n))
8267 + check_object_size(to, n, false);
8268 +
8269 return __copy_tofrom_user((__force void __user *)to, from, n);
8270 }
8271
8272 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8273 if (ret == 0)
8274 return 0;
8275 }
8276 +
8277 + if (!__builtin_constant_p(n))
8278 + check_object_size(from, n, true);
8279 +
8280 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8281 }
8282
8283 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8284 return __copy_to_user_inatomic(to, from, size);
8285 }
8286
8287 +#ifndef __powerpc64__
8288 +
8289 +static inline unsigned long __must_check copy_from_user(void *to,
8290 + const void __user *from, unsigned long n)
8291 +{
8292 + unsigned long over;
8293 +
8294 + if ((long)n < 0)
8295 + return n;
8296 +
8297 + if (access_ok(VERIFY_READ, from, n)) {
8298 + if (!__builtin_constant_p(n))
8299 + check_object_size(to, n, false);
8300 + return __copy_tofrom_user((__force void __user *)to, from, n);
8301 + }
8302 + if ((unsigned long)from < TASK_SIZE) {
8303 + over = (unsigned long)from + n - TASK_SIZE;
8304 + if (!__builtin_constant_p(n - over))
8305 + check_object_size(to, n - over, false);
8306 + return __copy_tofrom_user((__force void __user *)to, from,
8307 + n - over) + over;
8308 + }
8309 + return n;
8310 +}
8311 +
8312 +static inline unsigned long __must_check copy_to_user(void __user *to,
8313 + const void *from, unsigned long n)
8314 +{
8315 + unsigned long over;
8316 +
8317 + if ((long)n < 0)
8318 + return n;
8319 +
8320 + if (access_ok(VERIFY_WRITE, to, n)) {
8321 + if (!__builtin_constant_p(n))
8322 + check_object_size(from, n, true);
8323 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8324 + }
8325 + if ((unsigned long)to < TASK_SIZE) {
8326 + over = (unsigned long)to + n - TASK_SIZE;
8327 + if (!__builtin_constant_p(n))
8328 + check_object_size(from, n - over, true);
8329 + return __copy_tofrom_user(to, (__force void __user *)from,
8330 + n - over) + over;
8331 + }
8332 + return n;
8333 +}
8334 +
8335 +#else /* __powerpc64__ */
8336 +
8337 +#define __copy_in_user(to, from, size) \
8338 + __copy_tofrom_user((to), (from), (size))
8339 +
8340 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8341 +{
8342 + if ((long)n < 0 || n > INT_MAX)
8343 + return n;
8344 +
8345 + if (!__builtin_constant_p(n))
8346 + check_object_size(to, n, false);
8347 +
8348 + if (likely(access_ok(VERIFY_READ, from, n)))
8349 + n = __copy_from_user(to, from, n);
8350 + else
8351 + memset(to, 0, n);
8352 + return n;
8353 +}
8354 +
8355 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8356 +{
8357 + if ((long)n < 0 || n > INT_MAX)
8358 + return n;
8359 +
8360 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8361 + if (!__builtin_constant_p(n))
8362 + check_object_size(from, n, true);
8363 + n = __copy_to_user(to, from, n);
8364 + }
8365 + return n;
8366 +}
8367 +
8368 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8369 + unsigned long n);
8370 +
8371 +#endif /* __powerpc64__ */
8372 +
8373 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8374
8375 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8376 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8377 index fcc9a89..07be2bb 100644
8378 --- a/arch/powerpc/kernel/Makefile
8379 +++ b/arch/powerpc/kernel/Makefile
8380 @@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8381 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8382 endif
8383
8384 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8385 +
8386 obj-y := cputable.o ptrace.o syscalls.o \
8387 irq.o align.o signal_32.o pmc.o vdso.o \
8388 process.o systbl.o idle.o \
8389 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8390 index 063b65d..7a26e9d 100644
8391 --- a/arch/powerpc/kernel/exceptions-64e.S
8392 +++ b/arch/powerpc/kernel/exceptions-64e.S
8393 @@ -771,6 +771,7 @@ storage_fault_common:
8394 std r14,_DAR(r1)
8395 std r15,_DSISR(r1)
8396 addi r3,r1,STACK_FRAME_OVERHEAD
8397 + bl .save_nvgprs
8398 mr r4,r14
8399 mr r5,r15
8400 ld r14,PACA_EXGEN+EX_R14(r13)
8401 @@ -779,8 +780,7 @@ storage_fault_common:
8402 cmpdi r3,0
8403 bne- 1f
8404 b .ret_from_except_lite
8405 -1: bl .save_nvgprs
8406 - mr r5,r3
8407 +1: mr r5,r3
8408 addi r3,r1,STACK_FRAME_OVERHEAD
8409 ld r4,_DAR(r1)
8410 bl .bad_page_fault
8411 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8412 index 38d5073..f00af8d 100644
8413 --- a/arch/powerpc/kernel/exceptions-64s.S
8414 +++ b/arch/powerpc/kernel/exceptions-64s.S
8415 @@ -1584,10 +1584,10 @@ handle_page_fault:
8416 11: ld r4,_DAR(r1)
8417 ld r5,_DSISR(r1)
8418 addi r3,r1,STACK_FRAME_OVERHEAD
8419 + bl .save_nvgprs
8420 bl .do_page_fault
8421 cmpdi r3,0
8422 beq+ 12f
8423 - bl .save_nvgprs
8424 mr r5,r3
8425 addi r3,r1,STACK_FRAME_OVERHEAD
8426 lwz r4,_DAR(r1)
8427 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8428 index 6cff040..74ac5d1 100644
8429 --- a/arch/powerpc/kernel/module_32.c
8430 +++ b/arch/powerpc/kernel/module_32.c
8431 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8432 me->arch.core_plt_section = i;
8433 }
8434 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8435 - printk("Module doesn't contain .plt or .init.plt sections.\n");
8436 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8437 return -ENOEXEC;
8438 }
8439
8440 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8441
8442 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8443 /* Init, or core PLT? */
8444 - if (location >= mod->module_core
8445 - && location < mod->module_core + mod->core_size)
8446 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8447 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8448 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8449 - else
8450 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8451 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8452 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8453 + else {
8454 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8455 + return ~0UL;
8456 + }
8457
8458 /* Find this entry, or if that fails, the next avail. entry */
8459 while (entry->jump[0]) {
8460 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8461 }
8462 #ifdef CONFIG_DYNAMIC_FTRACE
8463 module->arch.tramp =
8464 - do_plt_call(module->module_core,
8465 + do_plt_call(module->module_core_rx,
8466 (unsigned long)ftrace_caller,
8467 sechdrs, module);
8468 #endif
8469 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8470 index af064d2..ce56147 100644
8471 --- a/arch/powerpc/kernel/process.c
8472 +++ b/arch/powerpc/kernel/process.c
8473 @@ -1009,8 +1009,8 @@ void show_regs(struct pt_regs * regs)
8474 * Lookup NIP late so we have the best change of getting the
8475 * above info out without failing
8476 */
8477 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8478 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8479 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8480 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8481 #endif
8482 show_stack(current, (unsigned long *) regs->gpr[1]);
8483 if (!user_mode(regs))
8484 @@ -1532,10 +1532,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8485 newsp = stack[0];
8486 ip = stack[STACK_FRAME_LR_SAVE];
8487 if (!firstframe || ip != lr) {
8488 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8489 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8490 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8491 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8492 - printk(" (%pS)",
8493 + printk(" (%pA)",
8494 (void *)current->ret_stack[curr_frame].ret);
8495 curr_frame--;
8496 }
8497 @@ -1555,7 +1555,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8498 struct pt_regs *regs = (struct pt_regs *)
8499 (sp + STACK_FRAME_OVERHEAD);
8500 lr = regs->link;
8501 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
8502 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
8503 regs->trap, (void *)regs->nip, (void *)lr);
8504 firstframe = 1;
8505 }
8506 @@ -1591,58 +1591,3 @@ void notrace __ppc64_runlatch_off(void)
8507 mtspr(SPRN_CTRLT, ctrl);
8508 }
8509 #endif /* CONFIG_PPC64 */
8510 -
8511 -unsigned long arch_align_stack(unsigned long sp)
8512 -{
8513 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8514 - sp -= get_random_int() & ~PAGE_MASK;
8515 - return sp & ~0xf;
8516 -}
8517 -
8518 -static inline unsigned long brk_rnd(void)
8519 -{
8520 - unsigned long rnd = 0;
8521 -
8522 - /* 8MB for 32bit, 1GB for 64bit */
8523 - if (is_32bit_task())
8524 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8525 - else
8526 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8527 -
8528 - return rnd << PAGE_SHIFT;
8529 -}
8530 -
8531 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8532 -{
8533 - unsigned long base = mm->brk;
8534 - unsigned long ret;
8535 -
8536 -#ifdef CONFIG_PPC_STD_MMU_64
8537 - /*
8538 - * If we are using 1TB segments and we are allowed to randomise
8539 - * the heap, we can put it above 1TB so it is backed by a 1TB
8540 - * segment. Otherwise the heap will be in the bottom 1TB
8541 - * which always uses 256MB segments and this may result in a
8542 - * performance penalty.
8543 - */
8544 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8545 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8546 -#endif
8547 -
8548 - ret = PAGE_ALIGN(base + brk_rnd());
8549 -
8550 - if (ret < mm->brk)
8551 - return mm->brk;
8552 -
8553 - return ret;
8554 -}
8555 -
8556 -unsigned long randomize_et_dyn(unsigned long base)
8557 -{
8558 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8559 -
8560 - if (ret < base)
8561 - return base;
8562 -
8563 - return ret;
8564 -}
8565 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8566 index 2e3d2bf..35df241 100644
8567 --- a/arch/powerpc/kernel/ptrace.c
8568 +++ b/arch/powerpc/kernel/ptrace.c
8569 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8570 return ret;
8571 }
8572
8573 +#ifdef CONFIG_GRKERNSEC_SETXID
8574 +extern void gr_delayed_cred_worker(void);
8575 +#endif
8576 +
8577 /*
8578 * We must return the syscall number to actually look up in the table.
8579 * This can be -1L to skip running any syscall at all.
8580 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8581
8582 secure_computing_strict(regs->gpr[0]);
8583
8584 +#ifdef CONFIG_GRKERNSEC_SETXID
8585 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8586 + gr_delayed_cred_worker();
8587 +#endif
8588 +
8589 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8590 tracehook_report_syscall_entry(regs))
8591 /*
8592 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8593 {
8594 int step;
8595
8596 +#ifdef CONFIG_GRKERNSEC_SETXID
8597 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8598 + gr_delayed_cred_worker();
8599 +#endif
8600 +
8601 audit_syscall_exit(regs);
8602
8603 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8604 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8605 index a67e00a..f71d8c7 100644
8606 --- a/arch/powerpc/kernel/signal_32.c
8607 +++ b/arch/powerpc/kernel/signal_32.c
8608 @@ -1011,7 +1011,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8609 /* Save user registers on the stack */
8610 frame = &rt_sf->uc.uc_mcontext;
8611 addr = frame;
8612 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8613 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8614 sigret = 0;
8615 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8616 } else {
8617 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8618 index 8d253c2..405b337 100644
8619 --- a/arch/powerpc/kernel/signal_64.c
8620 +++ b/arch/powerpc/kernel/signal_64.c
8621 @@ -758,7 +758,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8622 current->thread.fp_state.fpscr = 0;
8623
8624 /* Set up to return from userspace. */
8625 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8626 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8627 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8628 } else {
8629 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8630 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8631 index 33cd7a0..d615344 100644
8632 --- a/arch/powerpc/kernel/traps.c
8633 +++ b/arch/powerpc/kernel/traps.c
8634 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8635 return flags;
8636 }
8637
8638 +extern void gr_handle_kernel_exploit(void);
8639 +
8640 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8641 int signr)
8642 {
8643 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8644 panic("Fatal exception in interrupt");
8645 if (panic_on_oops)
8646 panic("Fatal exception");
8647 +
8648 + gr_handle_kernel_exploit();
8649 +
8650 do_exit(signr);
8651 }
8652
8653 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8654 index 094e45c..d82b848 100644
8655 --- a/arch/powerpc/kernel/vdso.c
8656 +++ b/arch/powerpc/kernel/vdso.c
8657 @@ -35,6 +35,7 @@
8658 #include <asm/vdso.h>
8659 #include <asm/vdso_datapage.h>
8660 #include <asm/setup.h>
8661 +#include <asm/mman.h>
8662
8663 #undef DEBUG
8664
8665 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8666 vdso_base = VDSO32_MBASE;
8667 #endif
8668
8669 - current->mm->context.vdso_base = 0;
8670 + current->mm->context.vdso_base = ~0UL;
8671
8672 /* vDSO has a problem and was disabled, just don't "enable" it for the
8673 * process
8674 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8675 vdso_base = get_unmapped_area(NULL, vdso_base,
8676 (vdso_pages << PAGE_SHIFT) +
8677 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8678 - 0, 0);
8679 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
8680 if (IS_ERR_VALUE(vdso_base)) {
8681 rc = vdso_base;
8682 goto fail_mmapsem;
8683 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8684 index 3cf541a..ab2d825 100644
8685 --- a/arch/powerpc/kvm/powerpc.c
8686 +++ b/arch/powerpc/kvm/powerpc.c
8687 @@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8688 }
8689 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8690
8691 -int kvm_arch_init(void *opaque)
8692 +int kvm_arch_init(const void *opaque)
8693 {
8694 return 0;
8695 }
8696 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8697 index 5eea6f3..5d10396 100644
8698 --- a/arch/powerpc/lib/usercopy_64.c
8699 +++ b/arch/powerpc/lib/usercopy_64.c
8700 @@ -9,22 +9,6 @@
8701 #include <linux/module.h>
8702 #include <asm/uaccess.h>
8703
8704 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8705 -{
8706 - if (likely(access_ok(VERIFY_READ, from, n)))
8707 - n = __copy_from_user(to, from, n);
8708 - else
8709 - memset(to, 0, n);
8710 - return n;
8711 -}
8712 -
8713 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8714 -{
8715 - if (likely(access_ok(VERIFY_WRITE, to, n)))
8716 - n = __copy_to_user(to, from, n);
8717 - return n;
8718 -}
8719 -
8720 unsigned long copy_in_user(void __user *to, const void __user *from,
8721 unsigned long n)
8722 {
8723 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8724 return n;
8725 }
8726
8727 -EXPORT_SYMBOL(copy_from_user);
8728 -EXPORT_SYMBOL(copy_to_user);
8729 EXPORT_SYMBOL(copy_in_user);
8730
8731 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8732 index 51ab9e7..7d3c78b 100644
8733 --- a/arch/powerpc/mm/fault.c
8734 +++ b/arch/powerpc/mm/fault.c
8735 @@ -33,6 +33,10 @@
8736 #include <linux/magic.h>
8737 #include <linux/ratelimit.h>
8738 #include <linux/context_tracking.h>
8739 +#include <linux/slab.h>
8740 +#include <linux/pagemap.h>
8741 +#include <linux/compiler.h>
8742 +#include <linux/unistd.h>
8743
8744 #include <asm/firmware.h>
8745 #include <asm/page.h>
8746 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8747 }
8748 #endif
8749
8750 +#ifdef CONFIG_PAX_PAGEEXEC
8751 +/*
8752 + * PaX: decide what to do with offenders (regs->nip = fault address)
8753 + *
8754 + * returns 1 when task should be killed
8755 + */
8756 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8757 +{
8758 + return 1;
8759 +}
8760 +
8761 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8762 +{
8763 + unsigned long i;
8764 +
8765 + printk(KERN_ERR "PAX: bytes at PC: ");
8766 + for (i = 0; i < 5; i++) {
8767 + unsigned int c;
8768 + if (get_user(c, (unsigned int __user *)pc+i))
8769 + printk(KERN_CONT "???????? ");
8770 + else
8771 + printk(KERN_CONT "%08x ", c);
8772 + }
8773 + printk("\n");
8774 +}
8775 +#endif
8776 +
8777 /*
8778 * Check whether the instruction at regs->nip is a store using
8779 * an update addressing form which will update r1.
8780 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8781 * indicate errors in DSISR but can validly be set in SRR1.
8782 */
8783 if (trap == 0x400)
8784 - error_code &= 0x48200000;
8785 + error_code &= 0x58200000;
8786 else
8787 is_write = error_code & DSISR_ISSTORE;
8788 #else
8789 @@ -378,7 +409,7 @@ good_area:
8790 * "undefined". Of those that can be set, this is the only
8791 * one which seems bad.
8792 */
8793 - if (error_code & 0x10000000)
8794 + if (error_code & DSISR_GUARDED)
8795 /* Guarded storage error. */
8796 goto bad_area;
8797 #endif /* CONFIG_8xx */
8798 @@ -393,7 +424,7 @@ good_area:
8799 * processors use the same I/D cache coherency mechanism
8800 * as embedded.
8801 */
8802 - if (error_code & DSISR_PROTFAULT)
8803 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8804 goto bad_area;
8805 #endif /* CONFIG_PPC_STD_MMU */
8806
8807 @@ -483,6 +514,23 @@ bad_area:
8808 bad_area_nosemaphore:
8809 /* User mode accesses cause a SIGSEGV */
8810 if (user_mode(regs)) {
8811 +
8812 +#ifdef CONFIG_PAX_PAGEEXEC
8813 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8814 +#ifdef CONFIG_PPC_STD_MMU
8815 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8816 +#else
8817 + if (is_exec && regs->nip == address) {
8818 +#endif
8819 + switch (pax_handle_fetch_fault(regs)) {
8820 + }
8821 +
8822 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8823 + do_group_exit(SIGKILL);
8824 + }
8825 + }
8826 +#endif
8827 +
8828 _exception(SIGSEGV, regs, code, address);
8829 goto bail;
8830 }
8831 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8832 index cb8bdbe..cde4bc7 100644
8833 --- a/arch/powerpc/mm/mmap.c
8834 +++ b/arch/powerpc/mm/mmap.c
8835 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8836 return sysctl_legacy_va_layout;
8837 }
8838
8839 -static unsigned long mmap_rnd(void)
8840 +static unsigned long mmap_rnd(struct mm_struct *mm)
8841 {
8842 unsigned long rnd = 0;
8843
8844 +#ifdef CONFIG_PAX_RANDMMAP
8845 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8846 +#endif
8847 +
8848 if (current->flags & PF_RANDOMIZE) {
8849 /* 8MB for 32bit, 1GB for 64bit */
8850 if (is_32bit_task())
8851 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
8852 return rnd << PAGE_SHIFT;
8853 }
8854
8855 -static inline unsigned long mmap_base(void)
8856 +static inline unsigned long mmap_base(struct mm_struct *mm)
8857 {
8858 unsigned long gap = rlimit(RLIMIT_STACK);
8859
8860 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
8861 else if (gap > MAX_GAP)
8862 gap = MAX_GAP;
8863
8864 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
8865 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
8866 }
8867
8868 /*
8869 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8870 */
8871 if (mmap_is_legacy()) {
8872 mm->mmap_base = TASK_UNMAPPED_BASE;
8873 +
8874 +#ifdef CONFIG_PAX_RANDMMAP
8875 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8876 + mm->mmap_base += mm->delta_mmap;
8877 +#endif
8878 +
8879 mm->get_unmapped_area = arch_get_unmapped_area;
8880 } else {
8881 - mm->mmap_base = mmap_base();
8882 + mm->mmap_base = mmap_base(mm);
8883 +
8884 +#ifdef CONFIG_PAX_RANDMMAP
8885 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8886 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8887 +#endif
8888 +
8889 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8890 }
8891 }
8892 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8893 index b0c75cc..ef7fb93 100644
8894 --- a/arch/powerpc/mm/slice.c
8895 +++ b/arch/powerpc/mm/slice.c
8896 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8897 if ((mm->task_size - len) < addr)
8898 return 0;
8899 vma = find_vma(mm, addr);
8900 - return (!vma || (addr + len) <= vma->vm_start);
8901 + return check_heap_stack_gap(vma, addr, len, 0);
8902 }
8903
8904 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8905 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8906 info.align_offset = 0;
8907
8908 addr = TASK_UNMAPPED_BASE;
8909 +
8910 +#ifdef CONFIG_PAX_RANDMMAP
8911 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8912 + addr += mm->delta_mmap;
8913 +#endif
8914 +
8915 while (addr < TASK_SIZE) {
8916 info.low_limit = addr;
8917 if (!slice_scan_available(addr, available, 1, &addr))
8918 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8919 if (fixed && addr > (mm->task_size - len))
8920 return -ENOMEM;
8921
8922 +#ifdef CONFIG_PAX_RANDMMAP
8923 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8924 + addr = 0;
8925 +#endif
8926 +
8927 /* If hint, make sure it matches our alignment restrictions */
8928 if (!fixed && addr) {
8929 addr = _ALIGN_UP(addr, 1ul << pshift);
8930 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8931 index 4278acf..67fd0e6 100644
8932 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8933 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8934 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
8935 }
8936
8937 static struct pci_ops scc_pciex_pci_ops = {
8938 - scc_pciex_read_config,
8939 - scc_pciex_write_config,
8940 + .read = scc_pciex_read_config,
8941 + .write = scc_pciex_write_config,
8942 };
8943
8944 static void pciex_clear_intr_all(unsigned int __iomem *base)
8945 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8946 index 9098692..3d54cd1 100644
8947 --- a/arch/powerpc/platforms/cell/spufs/file.c
8948 +++ b/arch/powerpc/platforms/cell/spufs/file.c
8949 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8950 return VM_FAULT_NOPAGE;
8951 }
8952
8953 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8954 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8955 unsigned long address,
8956 - void *buf, int len, int write)
8957 + void *buf, size_t len, int write)
8958 {
8959 struct spu_context *ctx = vma->vm_file->private_data;
8960 unsigned long offset = address - vma->vm_start;
8961 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8962 index fa9aaf7..3f5d836 100644
8963 --- a/arch/s390/include/asm/atomic.h
8964 +++ b/arch/s390/include/asm/atomic.h
8965 @@ -398,6 +398,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8966 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8967 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8968
8969 +#define atomic64_read_unchecked(v) atomic64_read(v)
8970 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8971 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8972 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8973 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8974 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8975 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8976 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8977 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8978 +
8979 #define smp_mb__before_atomic_dec() smp_mb()
8980 #define smp_mb__after_atomic_dec() smp_mb()
8981 #define smp_mb__before_atomic_inc() smp_mb()
8982 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8983 index 4d7ccac..d03d0ad 100644
8984 --- a/arch/s390/include/asm/cache.h
8985 +++ b/arch/s390/include/asm/cache.h
8986 @@ -9,8 +9,10 @@
8987 #ifndef __ARCH_S390_CACHE_H
8988 #define __ARCH_S390_CACHE_H
8989
8990 -#define L1_CACHE_BYTES 256
8991 +#include <linux/const.h>
8992 +
8993 #define L1_CACHE_SHIFT 8
8994 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8995 #define NET_SKB_PAD 32
8996
8997 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8998 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8999 index 78f4f87..598ce39 100644
9000 --- a/arch/s390/include/asm/elf.h
9001 +++ b/arch/s390/include/asm/elf.h
9002 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9003 the loader. We need to make sure that it is out of the way of the program
9004 that it will "exec", and that there is sufficient room for the brk. */
9005
9006 -extern unsigned long randomize_et_dyn(unsigned long base);
9007 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9008 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9009 +
9010 +#ifdef CONFIG_PAX_ASLR
9011 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9012 +
9013 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9014 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9015 +#endif
9016
9017 /* This yields a mask that user programs can use to figure out what
9018 instruction set this CPU supports. */
9019 @@ -222,9 +228,6 @@ struct linux_binprm;
9020 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9021 int arch_setup_additional_pages(struct linux_binprm *, int);
9022
9023 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9024 -#define arch_randomize_brk arch_randomize_brk
9025 -
9026 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9027
9028 #endif
9029 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9030 index c4a93d6..4d2a9b4 100644
9031 --- a/arch/s390/include/asm/exec.h
9032 +++ b/arch/s390/include/asm/exec.h
9033 @@ -7,6 +7,6 @@
9034 #ifndef __ASM_EXEC_H
9035 #define __ASM_EXEC_H
9036
9037 -extern unsigned long arch_align_stack(unsigned long sp);
9038 +#define arch_align_stack(x) ((x) & ~0xfUL)
9039
9040 #endif /* __ASM_EXEC_H */
9041 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9042 index 79330af..254cf37 100644
9043 --- a/arch/s390/include/asm/uaccess.h
9044 +++ b/arch/s390/include/asm/uaccess.h
9045 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9046 __range_ok((unsigned long)(addr), (size)); \
9047 })
9048
9049 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9050 #define access_ok(type, addr, size) __access_ok(addr, size)
9051
9052 /*
9053 @@ -245,6 +246,10 @@ static inline unsigned long __must_check
9054 copy_to_user(void __user *to, const void *from, unsigned long n)
9055 {
9056 might_fault();
9057 +
9058 + if ((long)n < 0)
9059 + return n;
9060 +
9061 return __copy_to_user(to, from, n);
9062 }
9063
9064 @@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
9065 static inline unsigned long __must_check
9066 __copy_from_user(void *to, const void __user *from, unsigned long n)
9067 {
9068 + if ((long)n < 0)
9069 + return n;
9070 +
9071 return uaccess.copy_from_user(n, from, to);
9072 }
9073
9074 @@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9075 static inline unsigned long __must_check
9076 copy_from_user(void *to, const void __user *from, unsigned long n)
9077 {
9078 - unsigned int sz = __compiletime_object_size(to);
9079 + size_t sz = __compiletime_object_size(to);
9080
9081 might_fault();
9082 - if (unlikely(sz != -1 && sz < n)) {
9083 +
9084 + if ((long)n < 0)
9085 + return n;
9086 +
9087 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9088 copy_from_user_overflow();
9089 return n;
9090 }
9091 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9092 index b89b591..fd9609d 100644
9093 --- a/arch/s390/kernel/module.c
9094 +++ b/arch/s390/kernel/module.c
9095 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9096
9097 /* Increase core size by size of got & plt and set start
9098 offsets for got and plt. */
9099 - me->core_size = ALIGN(me->core_size, 4);
9100 - me->arch.got_offset = me->core_size;
9101 - me->core_size += me->arch.got_size;
9102 - me->arch.plt_offset = me->core_size;
9103 - me->core_size += me->arch.plt_size;
9104 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9105 + me->arch.got_offset = me->core_size_rw;
9106 + me->core_size_rw += me->arch.got_size;
9107 + me->arch.plt_offset = me->core_size_rx;
9108 + me->core_size_rx += me->arch.plt_size;
9109 return 0;
9110 }
9111
9112 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9113 if (info->got_initialized == 0) {
9114 Elf_Addr *gotent;
9115
9116 - gotent = me->module_core + me->arch.got_offset +
9117 + gotent = me->module_core_rw + me->arch.got_offset +
9118 info->got_offset;
9119 *gotent = val;
9120 info->got_initialized = 1;
9121 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9122 rc = apply_rela_bits(loc, val, 0, 64, 0);
9123 else if (r_type == R_390_GOTENT ||
9124 r_type == R_390_GOTPLTENT) {
9125 - val += (Elf_Addr) me->module_core - loc;
9126 + val += (Elf_Addr) me->module_core_rw - loc;
9127 rc = apply_rela_bits(loc, val, 1, 32, 1);
9128 }
9129 break;
9130 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9131 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9132 if (info->plt_initialized == 0) {
9133 unsigned int *ip;
9134 - ip = me->module_core + me->arch.plt_offset +
9135 + ip = me->module_core_rx + me->arch.plt_offset +
9136 info->plt_offset;
9137 #ifndef CONFIG_64BIT
9138 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9139 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9140 val - loc + 0xffffUL < 0x1ffffeUL) ||
9141 (r_type == R_390_PLT32DBL &&
9142 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9143 - val = (Elf_Addr) me->module_core +
9144 + val = (Elf_Addr) me->module_core_rx +
9145 me->arch.plt_offset +
9146 info->plt_offset;
9147 val += rela->r_addend - loc;
9148 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9149 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9150 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9151 val = val + rela->r_addend -
9152 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9153 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9154 if (r_type == R_390_GOTOFF16)
9155 rc = apply_rela_bits(loc, val, 0, 16, 0);
9156 else if (r_type == R_390_GOTOFF32)
9157 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9158 break;
9159 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9160 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9161 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9162 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9163 rela->r_addend - loc;
9164 if (r_type == R_390_GOTPC)
9165 rc = apply_rela_bits(loc, val, 1, 32, 0);
9166 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9167 index dd14532..1dfc145 100644
9168 --- a/arch/s390/kernel/process.c
9169 +++ b/arch/s390/kernel/process.c
9170 @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9171 }
9172 return 0;
9173 }
9174 -
9175 -unsigned long arch_align_stack(unsigned long sp)
9176 -{
9177 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9178 - sp -= get_random_int() & ~PAGE_MASK;
9179 - return sp & ~0xf;
9180 -}
9181 -
9182 -static inline unsigned long brk_rnd(void)
9183 -{
9184 - /* 8MB for 32bit, 1GB for 64bit */
9185 - if (is_32bit_task())
9186 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9187 - else
9188 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9189 -}
9190 -
9191 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9192 -{
9193 - unsigned long ret;
9194 -
9195 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9196 - return (ret > mm->brk) ? ret : mm->brk;
9197 -}
9198 -
9199 -unsigned long randomize_et_dyn(unsigned long base)
9200 -{
9201 - unsigned long ret;
9202 -
9203 - if (!(current->flags & PF_RANDOMIZE))
9204 - return base;
9205 - ret = PAGE_ALIGN(base + brk_rnd());
9206 - return (ret > base) ? ret : base;
9207 -}
9208 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9209 index 9b436c2..54fbf0a 100644
9210 --- a/arch/s390/mm/mmap.c
9211 +++ b/arch/s390/mm/mmap.c
9212 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9213 */
9214 if (mmap_is_legacy()) {
9215 mm->mmap_base = mmap_base_legacy();
9216 +
9217 +#ifdef CONFIG_PAX_RANDMMAP
9218 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9219 + mm->mmap_base += mm->delta_mmap;
9220 +#endif
9221 +
9222 mm->get_unmapped_area = arch_get_unmapped_area;
9223 } else {
9224 mm->mmap_base = mmap_base();
9225 +
9226 +#ifdef CONFIG_PAX_RANDMMAP
9227 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9228 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9229 +#endif
9230 +
9231 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9232 }
9233 }
9234 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9235 */
9236 if (mmap_is_legacy()) {
9237 mm->mmap_base = mmap_base_legacy();
9238 +
9239 +#ifdef CONFIG_PAX_RANDMMAP
9240 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9241 + mm->mmap_base += mm->delta_mmap;
9242 +#endif
9243 +
9244 mm->get_unmapped_area = s390_get_unmapped_area;
9245 } else {
9246 mm->mmap_base = mmap_base();
9247 +
9248 +#ifdef CONFIG_PAX_RANDMMAP
9249 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9250 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9251 +#endif
9252 +
9253 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9254 }
9255 }
9256 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9257 index ae3d59f..f65f075 100644
9258 --- a/arch/score/include/asm/cache.h
9259 +++ b/arch/score/include/asm/cache.h
9260 @@ -1,7 +1,9 @@
9261 #ifndef _ASM_SCORE_CACHE_H
9262 #define _ASM_SCORE_CACHE_H
9263
9264 +#include <linux/const.h>
9265 +
9266 #define L1_CACHE_SHIFT 4
9267 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9268 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9269
9270 #endif /* _ASM_SCORE_CACHE_H */
9271 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9272 index f9f3cd5..58ff438 100644
9273 --- a/arch/score/include/asm/exec.h
9274 +++ b/arch/score/include/asm/exec.h
9275 @@ -1,6 +1,6 @@
9276 #ifndef _ASM_SCORE_EXEC_H
9277 #define _ASM_SCORE_EXEC_H
9278
9279 -extern unsigned long arch_align_stack(unsigned long sp);
9280 +#define arch_align_stack(x) (x)
9281
9282 #endif /* _ASM_SCORE_EXEC_H */
9283 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9284 index a1519ad3..e8ac1ff 100644
9285 --- a/arch/score/kernel/process.c
9286 +++ b/arch/score/kernel/process.c
9287 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9288
9289 return task_pt_regs(task)->cp0_epc;
9290 }
9291 -
9292 -unsigned long arch_align_stack(unsigned long sp)
9293 -{
9294 - return sp;
9295 -}
9296 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9297 index ef9e555..331bd29 100644
9298 --- a/arch/sh/include/asm/cache.h
9299 +++ b/arch/sh/include/asm/cache.h
9300 @@ -9,10 +9,11 @@
9301 #define __ASM_SH_CACHE_H
9302 #ifdef __KERNEL__
9303
9304 +#include <linux/const.h>
9305 #include <linux/init.h>
9306 #include <cpu/cache.h>
9307
9308 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9309 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9310
9311 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9312
9313 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9314 index 6777177..cb5e44f 100644
9315 --- a/arch/sh/mm/mmap.c
9316 +++ b/arch/sh/mm/mmap.c
9317 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9318 struct mm_struct *mm = current->mm;
9319 struct vm_area_struct *vma;
9320 int do_colour_align;
9321 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9322 struct vm_unmapped_area_info info;
9323
9324 if (flags & MAP_FIXED) {
9325 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9326 if (filp || (flags & MAP_SHARED))
9327 do_colour_align = 1;
9328
9329 +#ifdef CONFIG_PAX_RANDMMAP
9330 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9331 +#endif
9332 +
9333 if (addr) {
9334 if (do_colour_align)
9335 addr = COLOUR_ALIGN(addr, pgoff);
9336 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9337 addr = PAGE_ALIGN(addr);
9338
9339 vma = find_vma(mm, addr);
9340 - if (TASK_SIZE - len >= addr &&
9341 - (!vma || addr + len <= vma->vm_start))
9342 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9343 return addr;
9344 }
9345
9346 info.flags = 0;
9347 info.length = len;
9348 - info.low_limit = TASK_UNMAPPED_BASE;
9349 + info.low_limit = mm->mmap_base;
9350 info.high_limit = TASK_SIZE;
9351 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9352 info.align_offset = pgoff << PAGE_SHIFT;
9353 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9354 struct mm_struct *mm = current->mm;
9355 unsigned long addr = addr0;
9356 int do_colour_align;
9357 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9358 struct vm_unmapped_area_info info;
9359
9360 if (flags & MAP_FIXED) {
9361 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9362 if (filp || (flags & MAP_SHARED))
9363 do_colour_align = 1;
9364
9365 +#ifdef CONFIG_PAX_RANDMMAP
9366 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9367 +#endif
9368 +
9369 /* requesting a specific address */
9370 if (addr) {
9371 if (do_colour_align)
9372 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9373 addr = PAGE_ALIGN(addr);
9374
9375 vma = find_vma(mm, addr);
9376 - if (TASK_SIZE - len >= addr &&
9377 - (!vma || addr + len <= vma->vm_start))
9378 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9379 return addr;
9380 }
9381
9382 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9383 VM_BUG_ON(addr != -ENOMEM);
9384 info.flags = 0;
9385 info.low_limit = TASK_UNMAPPED_BASE;
9386 +
9387 +#ifdef CONFIG_PAX_RANDMMAP
9388 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9389 + info.low_limit += mm->delta_mmap;
9390 +#endif
9391 +
9392 info.high_limit = TASK_SIZE;
9393 addr = vm_unmapped_area(&info);
9394 }
9395 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9396 index be56a24..443328f 100644
9397 --- a/arch/sparc/include/asm/atomic_64.h
9398 +++ b/arch/sparc/include/asm/atomic_64.h
9399 @@ -14,18 +14,40 @@
9400 #define ATOMIC64_INIT(i) { (i) }
9401
9402 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9403 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9404 +{
9405 + return v->counter;
9406 +}
9407 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9408 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9409 +{
9410 + return v->counter;
9411 +}
9412
9413 #define atomic_set(v, i) (((v)->counter) = i)
9414 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9415 +{
9416 + v->counter = i;
9417 +}
9418 #define atomic64_set(v, i) (((v)->counter) = i)
9419 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9420 +{
9421 + v->counter = i;
9422 +}
9423
9424 extern void atomic_add(int, atomic_t *);
9425 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9426 extern void atomic64_add(long, atomic64_t *);
9427 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9428 extern void atomic_sub(int, atomic_t *);
9429 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9430 extern void atomic64_sub(long, atomic64_t *);
9431 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9432
9433 extern int atomic_add_ret(int, atomic_t *);
9434 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9435 extern long atomic64_add_ret(long, atomic64_t *);
9436 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9437 extern int atomic_sub_ret(int, atomic_t *);
9438 extern long atomic64_sub_ret(long, atomic64_t *);
9439
9440 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9441 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9442
9443 #define atomic_inc_return(v) atomic_add_ret(1, v)
9444 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9445 +{
9446 + return atomic_add_ret_unchecked(1, v);
9447 +}
9448 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9449 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9450 +{
9451 + return atomic64_add_ret_unchecked(1, v);
9452 +}
9453
9454 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9455 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9456
9457 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9458 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9459 +{
9460 + return atomic_add_ret_unchecked(i, v);
9461 +}
9462 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9463 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9464 +{
9465 + return atomic64_add_ret_unchecked(i, v);
9466 +}
9467
9468 /*
9469 * atomic_inc_and_test - increment and test
9470 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9471 * other cases.
9472 */
9473 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9474 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9475 +{
9476 + return atomic_inc_return_unchecked(v) == 0;
9477 +}
9478 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9479
9480 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9481 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9482 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9483
9484 #define atomic_inc(v) atomic_add(1, v)
9485 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9486 +{
9487 + atomic_add_unchecked(1, v);
9488 +}
9489 #define atomic64_inc(v) atomic64_add(1, v)
9490 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9491 +{
9492 + atomic64_add_unchecked(1, v);
9493 +}
9494
9495 #define atomic_dec(v) atomic_sub(1, v)
9496 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9497 +{
9498 + atomic_sub_unchecked(1, v);
9499 +}
9500 #define atomic64_dec(v) atomic64_sub(1, v)
9501 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9502 +{
9503 + atomic64_sub_unchecked(1, v);
9504 +}
9505
9506 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9507 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9508
9509 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9510 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9511 +{
9512 + return cmpxchg(&v->counter, old, new);
9513 +}
9514 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9515 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9516 +{
9517 + return xchg(&v->counter, new);
9518 +}
9519
9520 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9521 {
9522 - int c, old;
9523 + int c, old, new;
9524 c = atomic_read(v);
9525 for (;;) {
9526 - if (unlikely(c == (u)))
9527 + if (unlikely(c == u))
9528 break;
9529 - old = atomic_cmpxchg((v), c, c + (a));
9530 +
9531 + asm volatile("addcc %2, %0, %0\n"
9532 +
9533 +#ifdef CONFIG_PAX_REFCOUNT
9534 + "tvs %%icc, 6\n"
9535 +#endif
9536 +
9537 + : "=r" (new)
9538 + : "0" (c), "ir" (a)
9539 + : "cc");
9540 +
9541 + old = atomic_cmpxchg(v, c, new);
9542 if (likely(old == c))
9543 break;
9544 c = old;
9545 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9546 #define atomic64_cmpxchg(v, o, n) \
9547 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9548 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9549 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9550 +{
9551 + return xchg(&v->counter, new);
9552 +}
9553
9554 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9555 {
9556 - long c, old;
9557 + long c, old, new;
9558 c = atomic64_read(v);
9559 for (;;) {
9560 - if (unlikely(c == (u)))
9561 + if (unlikely(c == u))
9562 break;
9563 - old = atomic64_cmpxchg((v), c, c + (a));
9564 +
9565 + asm volatile("addcc %2, %0, %0\n"
9566 +
9567 +#ifdef CONFIG_PAX_REFCOUNT
9568 + "tvs %%xcc, 6\n"
9569 +#endif
9570 +
9571 + : "=r" (new)
9572 + : "0" (c), "ir" (a)
9573 + : "cc");
9574 +
9575 + old = atomic64_cmpxchg(v, c, new);
9576 if (likely(old == c))
9577 break;
9578 c = old;
9579 }
9580 - return c != (u);
9581 + return c != u;
9582 }
9583
9584 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9585 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9586 index 5bb6991..5c2132e 100644
9587 --- a/arch/sparc/include/asm/cache.h
9588 +++ b/arch/sparc/include/asm/cache.h
9589 @@ -7,10 +7,12 @@
9590 #ifndef _SPARC_CACHE_H
9591 #define _SPARC_CACHE_H
9592
9593 +#include <linux/const.h>
9594 +
9595 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9596
9597 #define L1_CACHE_SHIFT 5
9598 -#define L1_CACHE_BYTES 32
9599 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9600
9601 #ifdef CONFIG_SPARC32
9602 #define SMP_CACHE_BYTES_SHIFT 5
9603 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9604 index a24e41f..47677ff 100644
9605 --- a/arch/sparc/include/asm/elf_32.h
9606 +++ b/arch/sparc/include/asm/elf_32.h
9607 @@ -114,6 +114,13 @@ typedef struct {
9608
9609 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9610
9611 +#ifdef CONFIG_PAX_ASLR
9612 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
9613 +
9614 +#define PAX_DELTA_MMAP_LEN 16
9615 +#define PAX_DELTA_STACK_LEN 16
9616 +#endif
9617 +
9618 /* This yields a mask that user programs can use to figure out what
9619 instruction set this cpu supports. This can NOT be done in userspace
9620 on Sparc. */
9621 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9622 index 370ca1e..d4f4a98 100644
9623 --- a/arch/sparc/include/asm/elf_64.h
9624 +++ b/arch/sparc/include/asm/elf_64.h
9625 @@ -189,6 +189,13 @@ typedef struct {
9626 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9627 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9628
9629 +#ifdef CONFIG_PAX_ASLR
9630 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9631 +
9632 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9633 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9634 +#endif
9635 +
9636 extern unsigned long sparc64_elf_hwcap;
9637 #define ELF_HWCAP sparc64_elf_hwcap
9638
9639 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9640 index 9b1c36d..209298b 100644
9641 --- a/arch/sparc/include/asm/pgalloc_32.h
9642 +++ b/arch/sparc/include/asm/pgalloc_32.h
9643 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9644 }
9645
9646 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9647 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9648
9649 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9650 unsigned long address)
9651 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9652 index bcfe063..b333142 100644
9653 --- a/arch/sparc/include/asm/pgalloc_64.h
9654 +++ b/arch/sparc/include/asm/pgalloc_64.h
9655 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9656 }
9657
9658 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9659 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9660
9661 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9662 {
9663 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9664 index 59ba6f6..4518128 100644
9665 --- a/arch/sparc/include/asm/pgtable.h
9666 +++ b/arch/sparc/include/asm/pgtable.h
9667 @@ -5,4 +5,8 @@
9668 #else
9669 #include <asm/pgtable_32.h>
9670 #endif
9671 +
9672 +#define ktla_ktva(addr) (addr)
9673 +#define ktva_ktla(addr) (addr)
9674 +
9675 #endif
9676 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9677 index 502f632..da1917f 100644
9678 --- a/arch/sparc/include/asm/pgtable_32.h
9679 +++ b/arch/sparc/include/asm/pgtable_32.h
9680 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9681 #define PAGE_SHARED SRMMU_PAGE_SHARED
9682 #define PAGE_COPY SRMMU_PAGE_COPY
9683 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9684 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9685 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9686 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9687 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9688
9689 /* Top-level page directory - dummy used by init-mm.
9690 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9691
9692 /* xwr */
9693 #define __P000 PAGE_NONE
9694 -#define __P001 PAGE_READONLY
9695 -#define __P010 PAGE_COPY
9696 -#define __P011 PAGE_COPY
9697 +#define __P001 PAGE_READONLY_NOEXEC
9698 +#define __P010 PAGE_COPY_NOEXEC
9699 +#define __P011 PAGE_COPY_NOEXEC
9700 #define __P100 PAGE_READONLY
9701 #define __P101 PAGE_READONLY
9702 #define __P110 PAGE_COPY
9703 #define __P111 PAGE_COPY
9704
9705 #define __S000 PAGE_NONE
9706 -#define __S001 PAGE_READONLY
9707 -#define __S010 PAGE_SHARED
9708 -#define __S011 PAGE_SHARED
9709 +#define __S001 PAGE_READONLY_NOEXEC
9710 +#define __S010 PAGE_SHARED_NOEXEC
9711 +#define __S011 PAGE_SHARED_NOEXEC
9712 #define __S100 PAGE_READONLY
9713 #define __S101 PAGE_READONLY
9714 #define __S110 PAGE_SHARED
9715 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9716 index 79da178..c2eede8 100644
9717 --- a/arch/sparc/include/asm/pgtsrmmu.h
9718 +++ b/arch/sparc/include/asm/pgtsrmmu.h
9719 @@ -115,6 +115,11 @@
9720 SRMMU_EXEC | SRMMU_REF)
9721 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9722 SRMMU_EXEC | SRMMU_REF)
9723 +
9724 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9725 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9726 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9727 +
9728 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9729 SRMMU_DIRTY | SRMMU_REF)
9730
9731 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9732 index 9689176..63c18ea 100644
9733 --- a/arch/sparc/include/asm/spinlock_64.h
9734 +++ b/arch/sparc/include/asm/spinlock_64.h
9735 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9736
9737 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9738
9739 -static void inline arch_read_lock(arch_rwlock_t *lock)
9740 +static inline void arch_read_lock(arch_rwlock_t *lock)
9741 {
9742 unsigned long tmp1, tmp2;
9743
9744 __asm__ __volatile__ (
9745 "1: ldsw [%2], %0\n"
9746 " brlz,pn %0, 2f\n"
9747 -"4: add %0, 1, %1\n"
9748 +"4: addcc %0, 1, %1\n"
9749 +
9750 +#ifdef CONFIG_PAX_REFCOUNT
9751 +" tvs %%icc, 6\n"
9752 +#endif
9753 +
9754 " cas [%2], %0, %1\n"
9755 " cmp %0, %1\n"
9756 " bne,pn %%icc, 1b\n"
9757 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9758 " .previous"
9759 : "=&r" (tmp1), "=&r" (tmp2)
9760 : "r" (lock)
9761 - : "memory");
9762 + : "memory", "cc");
9763 }
9764
9765 -static int inline arch_read_trylock(arch_rwlock_t *lock)
9766 +static inline int arch_read_trylock(arch_rwlock_t *lock)
9767 {
9768 int tmp1, tmp2;
9769
9770 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9771 "1: ldsw [%2], %0\n"
9772 " brlz,a,pn %0, 2f\n"
9773 " mov 0, %0\n"
9774 -" add %0, 1, %1\n"
9775 +" addcc %0, 1, %1\n"
9776 +
9777 +#ifdef CONFIG_PAX_REFCOUNT
9778 +" tvs %%icc, 6\n"
9779 +#endif
9780 +
9781 " cas [%2], %0, %1\n"
9782 " cmp %0, %1\n"
9783 " bne,pn %%icc, 1b\n"
9784 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9785 return tmp1;
9786 }
9787
9788 -static void inline arch_read_unlock(arch_rwlock_t *lock)
9789 +static inline void arch_read_unlock(arch_rwlock_t *lock)
9790 {
9791 unsigned long tmp1, tmp2;
9792
9793 __asm__ __volatile__(
9794 "1: lduw [%2], %0\n"
9795 -" sub %0, 1, %1\n"
9796 +" subcc %0, 1, %1\n"
9797 +
9798 +#ifdef CONFIG_PAX_REFCOUNT
9799 +" tvs %%icc, 6\n"
9800 +#endif
9801 +
9802 " cas [%2], %0, %1\n"
9803 " cmp %0, %1\n"
9804 " bne,pn %%xcc, 1b\n"
9805 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9806 : "memory");
9807 }
9808
9809 -static void inline arch_write_lock(arch_rwlock_t *lock)
9810 +static inline void arch_write_lock(arch_rwlock_t *lock)
9811 {
9812 unsigned long mask, tmp1, tmp2;
9813
9814 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9815 : "memory");
9816 }
9817
9818 -static void inline arch_write_unlock(arch_rwlock_t *lock)
9819 +static inline void arch_write_unlock(arch_rwlock_t *lock)
9820 {
9821 __asm__ __volatile__(
9822 " stw %%g0, [%0]"
9823 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9824 : "memory");
9825 }
9826
9827 -static int inline arch_write_trylock(arch_rwlock_t *lock)
9828 +static inline int arch_write_trylock(arch_rwlock_t *lock)
9829 {
9830 unsigned long mask, tmp1, tmp2, result;
9831
9832 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9833 index 96efa7a..16858bf 100644
9834 --- a/arch/sparc/include/asm/thread_info_32.h
9835 +++ b/arch/sparc/include/asm/thread_info_32.h
9836 @@ -49,6 +49,8 @@ struct thread_info {
9837 unsigned long w_saved;
9838
9839 struct restart_block restart_block;
9840 +
9841 + unsigned long lowest_stack;
9842 };
9843
9844 /*
9845 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9846 index a5f01ac..703b554 100644
9847 --- a/arch/sparc/include/asm/thread_info_64.h
9848 +++ b/arch/sparc/include/asm/thread_info_64.h
9849 @@ -63,6 +63,8 @@ struct thread_info {
9850 struct pt_regs *kern_una_regs;
9851 unsigned int kern_una_insn;
9852
9853 + unsigned long lowest_stack;
9854 +
9855 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9856 };
9857
9858 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
9859 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9860 /* flag bit 4 is available */
9861 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9862 -/* flag bit 6 is available */
9863 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9864 #define TIF_32BIT 7 /* 32-bit binary */
9865 #define TIF_NOHZ 8 /* in adaptive nohz mode */
9866 #define TIF_SECCOMP 9 /* secure computing */
9867 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9868 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9869 +
9870 /* NOTE: Thread flags >= 12 should be ones we have no interest
9871 * in using in assembly, else we can't use the mask as
9872 * an immediate value in instructions such as andcc.
9873 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9874 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9875 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9876 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9877 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9878
9879 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9880 _TIF_DO_NOTIFY_RESUME_MASK | \
9881 _TIF_NEED_RESCHED)
9882 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9883
9884 +#define _TIF_WORK_SYSCALL \
9885 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9886 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
9887 +
9888 +
9889 /*
9890 * Thread-synchronous status.
9891 *
9892 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9893 index 0167d26..767bb0c 100644
9894 --- a/arch/sparc/include/asm/uaccess.h
9895 +++ b/arch/sparc/include/asm/uaccess.h
9896 @@ -1,5 +1,6 @@
9897 #ifndef ___ASM_SPARC_UACCESS_H
9898 #define ___ASM_SPARC_UACCESS_H
9899 +
9900 #if defined(__sparc__) && defined(__arch64__)
9901 #include <asm/uaccess_64.h>
9902 #else
9903 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9904 index 53a28dd..50c38c3 100644
9905 --- a/arch/sparc/include/asm/uaccess_32.h
9906 +++ b/arch/sparc/include/asm/uaccess_32.h
9907 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9908
9909 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9910 {
9911 - if (n && __access_ok((unsigned long) to, n))
9912 + if ((long)n < 0)
9913 + return n;
9914 +
9915 + if (n && __access_ok((unsigned long) to, n)) {
9916 + if (!__builtin_constant_p(n))
9917 + check_object_size(from, n, true);
9918 return __copy_user(to, (__force void __user *) from, n);
9919 - else
9920 + } else
9921 return n;
9922 }
9923
9924 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9925 {
9926 + if ((long)n < 0)
9927 + return n;
9928 +
9929 + if (!__builtin_constant_p(n))
9930 + check_object_size(from, n, true);
9931 +
9932 return __copy_user(to, (__force void __user *) from, n);
9933 }
9934
9935 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9936 {
9937 - if (n && __access_ok((unsigned long) from, n))
9938 + if ((long)n < 0)
9939 + return n;
9940 +
9941 + if (n && __access_ok((unsigned long) from, n)) {
9942 + if (!__builtin_constant_p(n))
9943 + check_object_size(to, n, false);
9944 return __copy_user((__force void __user *) to, from, n);
9945 - else
9946 + } else
9947 return n;
9948 }
9949
9950 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9951 {
9952 + if ((long)n < 0)
9953 + return n;
9954 +
9955 return __copy_user((__force void __user *) to, from, n);
9956 }
9957
9958 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9959 index ad7e178..c9e7423 100644
9960 --- a/arch/sparc/include/asm/uaccess_64.h
9961 +++ b/arch/sparc/include/asm/uaccess_64.h
9962 @@ -10,6 +10,7 @@
9963 #include <linux/compiler.h>
9964 #include <linux/string.h>
9965 #include <linux/thread_info.h>
9966 +#include <linux/kernel.h>
9967 #include <asm/asi.h>
9968 #include <asm/spitfire.h>
9969 #include <asm-generic/uaccess-unaligned.h>
9970 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9971 static inline unsigned long __must_check
9972 copy_from_user(void *to, const void __user *from, unsigned long size)
9973 {
9974 - unsigned long ret = ___copy_from_user(to, from, size);
9975 + unsigned long ret;
9976
9977 + if ((long)size < 0 || size > INT_MAX)
9978 + return size;
9979 +
9980 + if (!__builtin_constant_p(size))
9981 + check_object_size(to, size, false);
9982 +
9983 + ret = ___copy_from_user(to, from, size);
9984 if (unlikely(ret))
9985 ret = copy_from_user_fixup(to, from, size);
9986
9987 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9988 static inline unsigned long __must_check
9989 copy_to_user(void __user *to, const void *from, unsigned long size)
9990 {
9991 - unsigned long ret = ___copy_to_user(to, from, size);
9992 + unsigned long ret;
9993
9994 + if ((long)size < 0 || size > INT_MAX)
9995 + return size;
9996 +
9997 + if (!__builtin_constant_p(size))
9998 + check_object_size(from, size, true);
9999 +
10000 + ret = ___copy_to_user(to, from, size);
10001 if (unlikely(ret))
10002 ret = copy_to_user_fixup(to, from, size);
10003 return ret;
10004 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10005 index d15cc17..d0ae796 100644
10006 --- a/arch/sparc/kernel/Makefile
10007 +++ b/arch/sparc/kernel/Makefile
10008 @@ -4,7 +4,7 @@
10009 #
10010
10011 asflags-y := -ansi
10012 -ccflags-y := -Werror
10013 +#ccflags-y := -Werror
10014
10015 extra-y := head_$(BITS).o
10016
10017 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10018 index 510baec..9ff2607 100644
10019 --- a/arch/sparc/kernel/process_32.c
10020 +++ b/arch/sparc/kernel/process_32.c
10021 @@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10022
10023 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10024 r->psr, r->pc, r->npc, r->y, print_tainted());
10025 - printk("PC: <%pS>\n", (void *) r->pc);
10026 + printk("PC: <%pA>\n", (void *) r->pc);
10027 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10028 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10029 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10030 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10031 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10032 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10033 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10034 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10035
10036 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10037 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10038 @@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10039 rw = (struct reg_window32 *) fp;
10040 pc = rw->ins[7];
10041 printk("[%08lx : ", pc);
10042 - printk("%pS ] ", (void *) pc);
10043 + printk("%pA ] ", (void *) pc);
10044 fp = rw->ins[6];
10045 } while (++count < 16);
10046 printk("\n");
10047 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10048 index d7b4967..2edf827 100644
10049 --- a/arch/sparc/kernel/process_64.c
10050 +++ b/arch/sparc/kernel/process_64.c
10051 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10052 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10053 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10054 if (regs->tstate & TSTATE_PRIV)
10055 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10056 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10057 }
10058
10059 void show_regs(struct pt_regs *regs)
10060 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10061
10062 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10063 regs->tpc, regs->tnpc, regs->y, print_tainted());
10064 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10065 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10066 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10067 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10068 regs->u_regs[3]);
10069 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10070 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10071 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10072 regs->u_regs[15]);
10073 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10074 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10075 show_regwindow(regs);
10076 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10077 }
10078 @@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10079 ((tp && tp->task) ? tp->task->pid : -1));
10080
10081 if (gp->tstate & TSTATE_PRIV) {
10082 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10083 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10084 (void *) gp->tpc,
10085 (void *) gp->o7,
10086 (void *) gp->i7,
10087 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10088 index 79cc0d1..ec62734 100644
10089 --- a/arch/sparc/kernel/prom_common.c
10090 +++ b/arch/sparc/kernel/prom_common.c
10091 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10092
10093 unsigned int prom_early_allocated __initdata;
10094
10095 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10096 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10097 .nextprop = prom_common_nextprop,
10098 .getproplen = prom_getproplen,
10099 .getproperty = prom_getproperty,
10100 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10101 index c13c9f2..d572c34 100644
10102 --- a/arch/sparc/kernel/ptrace_64.c
10103 +++ b/arch/sparc/kernel/ptrace_64.c
10104 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10105 return ret;
10106 }
10107
10108 +#ifdef CONFIG_GRKERNSEC_SETXID
10109 +extern void gr_delayed_cred_worker(void);
10110 +#endif
10111 +
10112 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10113 {
10114 int ret = 0;
10115 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10116 if (test_thread_flag(TIF_NOHZ))
10117 user_exit();
10118
10119 +#ifdef CONFIG_GRKERNSEC_SETXID
10120 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10121 + gr_delayed_cred_worker();
10122 +#endif
10123 +
10124 if (test_thread_flag(TIF_SYSCALL_TRACE))
10125 ret = tracehook_report_syscall_entry(regs);
10126
10127 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10128 if (test_thread_flag(TIF_NOHZ))
10129 user_exit();
10130
10131 +#ifdef CONFIG_GRKERNSEC_SETXID
10132 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10133 + gr_delayed_cred_worker();
10134 +#endif
10135 +
10136 audit_syscall_exit(regs);
10137
10138 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10139 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10140 index b085311..6f885f7 100644
10141 --- a/arch/sparc/kernel/smp_64.c
10142 +++ b/arch/sparc/kernel/smp_64.c
10143 @@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10144 extern unsigned long xcall_flush_dcache_page_spitfire;
10145
10146 #ifdef CONFIG_DEBUG_DCFLUSH
10147 -extern atomic_t dcpage_flushes;
10148 -extern atomic_t dcpage_flushes_xcall;
10149 +extern atomic_unchecked_t dcpage_flushes;
10150 +extern atomic_unchecked_t dcpage_flushes_xcall;
10151 #endif
10152
10153 static inline void __local_flush_dcache_page(struct page *page)
10154 @@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10155 return;
10156
10157 #ifdef CONFIG_DEBUG_DCFLUSH
10158 - atomic_inc(&dcpage_flushes);
10159 + atomic_inc_unchecked(&dcpage_flushes);
10160 #endif
10161
10162 this_cpu = get_cpu();
10163 @@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10164 xcall_deliver(data0, __pa(pg_addr),
10165 (u64) pg_addr, cpumask_of(cpu));
10166 #ifdef CONFIG_DEBUG_DCFLUSH
10167 - atomic_inc(&dcpage_flushes_xcall);
10168 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10169 #endif
10170 }
10171 }
10172 @@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10173 preempt_disable();
10174
10175 #ifdef CONFIG_DEBUG_DCFLUSH
10176 - atomic_inc(&dcpage_flushes);
10177 + atomic_inc_unchecked(&dcpage_flushes);
10178 #endif
10179 data0 = 0;
10180 pg_addr = page_address(page);
10181 @@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10182 xcall_deliver(data0, __pa(pg_addr),
10183 (u64) pg_addr, cpu_online_mask);
10184 #ifdef CONFIG_DEBUG_DCFLUSH
10185 - atomic_inc(&dcpage_flushes_xcall);
10186 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10187 #endif
10188 }
10189 __local_flush_dcache_page(page);
10190 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10191 index 3a8d184..49498a8 100644
10192 --- a/arch/sparc/kernel/sys_sparc_32.c
10193 +++ b/arch/sparc/kernel/sys_sparc_32.c
10194 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10195 if (len > TASK_SIZE - PAGE_SIZE)
10196 return -ENOMEM;
10197 if (!addr)
10198 - addr = TASK_UNMAPPED_BASE;
10199 + addr = current->mm->mmap_base;
10200
10201 info.flags = 0;
10202 info.length = len;
10203 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10204 index beb0b5a..5a153f7 100644
10205 --- a/arch/sparc/kernel/sys_sparc_64.c
10206 +++ b/arch/sparc/kernel/sys_sparc_64.c
10207 @@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10208 struct vm_area_struct * vma;
10209 unsigned long task_size = TASK_SIZE;
10210 int do_color_align;
10211 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10212 struct vm_unmapped_area_info info;
10213
10214 if (flags & MAP_FIXED) {
10215 /* We do not accept a shared mapping if it would violate
10216 * cache aliasing constraints.
10217 */
10218 - if ((flags & MAP_SHARED) &&
10219 + if ((filp || (flags & MAP_SHARED)) &&
10220 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10221 return -EINVAL;
10222 return addr;
10223 @@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10224 if (filp || (flags & MAP_SHARED))
10225 do_color_align = 1;
10226
10227 +#ifdef CONFIG_PAX_RANDMMAP
10228 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10229 +#endif
10230 +
10231 if (addr) {
10232 if (do_color_align)
10233 addr = COLOR_ALIGN(addr, pgoff);
10234 @@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10235 addr = PAGE_ALIGN(addr);
10236
10237 vma = find_vma(mm, addr);
10238 - if (task_size - len >= addr &&
10239 - (!vma || addr + len <= vma->vm_start))
10240 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10241 return addr;
10242 }
10243
10244 info.flags = 0;
10245 info.length = len;
10246 - info.low_limit = TASK_UNMAPPED_BASE;
10247 + info.low_limit = mm->mmap_base;
10248 info.high_limit = min(task_size, VA_EXCLUDE_START);
10249 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10250 info.align_offset = pgoff << PAGE_SHIFT;
10251 + info.threadstack_offset = offset;
10252 addr = vm_unmapped_area(&info);
10253
10254 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10255 VM_BUG_ON(addr != -ENOMEM);
10256 info.low_limit = VA_EXCLUDE_END;
10257 +
10258 +#ifdef CONFIG_PAX_RANDMMAP
10259 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10260 + info.low_limit += mm->delta_mmap;
10261 +#endif
10262 +
10263 info.high_limit = task_size;
10264 addr = vm_unmapped_area(&info);
10265 }
10266 @@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10267 unsigned long task_size = STACK_TOP32;
10268 unsigned long addr = addr0;
10269 int do_color_align;
10270 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10271 struct vm_unmapped_area_info info;
10272
10273 /* This should only ever run for 32-bit processes. */
10274 @@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10275 /* We do not accept a shared mapping if it would violate
10276 * cache aliasing constraints.
10277 */
10278 - if ((flags & MAP_SHARED) &&
10279 + if ((filp || (flags & MAP_SHARED)) &&
10280 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10281 return -EINVAL;
10282 return addr;
10283 @@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10284 if (filp || (flags & MAP_SHARED))
10285 do_color_align = 1;
10286
10287 +#ifdef CONFIG_PAX_RANDMMAP
10288 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10289 +#endif
10290 +
10291 /* requesting a specific address */
10292 if (addr) {
10293 if (do_color_align)
10294 @@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10295 addr = PAGE_ALIGN(addr);
10296
10297 vma = find_vma(mm, addr);
10298 - if (task_size - len >= addr &&
10299 - (!vma || addr + len <= vma->vm_start))
10300 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10301 return addr;
10302 }
10303
10304 @@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10305 info.high_limit = mm->mmap_base;
10306 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10307 info.align_offset = pgoff << PAGE_SHIFT;
10308 + info.threadstack_offset = offset;
10309 addr = vm_unmapped_area(&info);
10310
10311 /*
10312 @@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10313 VM_BUG_ON(addr != -ENOMEM);
10314 info.flags = 0;
10315 info.low_limit = TASK_UNMAPPED_BASE;
10316 +
10317 +#ifdef CONFIG_PAX_RANDMMAP
10318 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10319 + info.low_limit += mm->delta_mmap;
10320 +#endif
10321 +
10322 info.high_limit = STACK_TOP32;
10323 addr = vm_unmapped_area(&info);
10324 }
10325 @@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10326 EXPORT_SYMBOL(get_fb_unmapped_area);
10327
10328 /* Essentially the same as PowerPC. */
10329 -static unsigned long mmap_rnd(void)
10330 +static unsigned long mmap_rnd(struct mm_struct *mm)
10331 {
10332 unsigned long rnd = 0UL;
10333
10334 +#ifdef CONFIG_PAX_RANDMMAP
10335 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10336 +#endif
10337 +
10338 if (current->flags & PF_RANDOMIZE) {
10339 unsigned long val = get_random_int();
10340 if (test_thread_flag(TIF_32BIT))
10341 @@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10342
10343 void arch_pick_mmap_layout(struct mm_struct *mm)
10344 {
10345 - unsigned long random_factor = mmap_rnd();
10346 + unsigned long random_factor = mmap_rnd(mm);
10347 unsigned long gap;
10348
10349 /*
10350 @@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10351 gap == RLIM_INFINITY ||
10352 sysctl_legacy_va_layout) {
10353 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10354 +
10355 +#ifdef CONFIG_PAX_RANDMMAP
10356 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10357 + mm->mmap_base += mm->delta_mmap;
10358 +#endif
10359 +
10360 mm->get_unmapped_area = arch_get_unmapped_area;
10361 } else {
10362 /* We know it's 32-bit */
10363 @@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10364 gap = (task_size / 6 * 5);
10365
10366 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10367 +
10368 +#ifdef CONFIG_PAX_RANDMMAP
10369 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10370 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10371 +#endif
10372 +
10373 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10374 }
10375 }
10376 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10377 index 33a17e7..d87fb1f 100644
10378 --- a/arch/sparc/kernel/syscalls.S
10379 +++ b/arch/sparc/kernel/syscalls.S
10380 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10381 #endif
10382 .align 32
10383 1: ldx [%g6 + TI_FLAGS], %l5
10384 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10385 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10386 be,pt %icc, rtrap
10387 nop
10388 call syscall_trace_leave
10389 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
10390
10391 srl %i3, 0, %o3 ! IEU0
10392 srl %i2, 0, %o2 ! IEU0 Group
10393 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10394 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10395 bne,pn %icc, linux_syscall_trace32 ! CTI
10396 mov %i0, %l5 ! IEU1
10397 5: call %l7 ! CTI Group brk forced
10398 @@ -208,7 +208,7 @@ linux_sparc_syscall:
10399
10400 mov %i3, %o3 ! IEU1
10401 mov %i4, %o4 ! IEU0 Group
10402 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10403 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10404 bne,pn %icc, linux_syscall_trace ! CTI Group
10405 mov %i0, %l5 ! IEU0
10406 2: call %l7 ! CTI Group brk forced
10407 @@ -223,7 +223,7 @@ ret_sys_call:
10408
10409 cmp %o0, -ERESTART_RESTARTBLOCK
10410 bgeu,pn %xcc, 1f
10411 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10412 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10413 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10414
10415 2:
10416 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10417 index 6629829..036032d 100644
10418 --- a/arch/sparc/kernel/traps_32.c
10419 +++ b/arch/sparc/kernel/traps_32.c
10420 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10421 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10422 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10423
10424 +extern void gr_handle_kernel_exploit(void);
10425 +
10426 void die_if_kernel(char *str, struct pt_regs *regs)
10427 {
10428 static int die_counter;
10429 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10430 count++ < 30 &&
10431 (((unsigned long) rw) >= PAGE_OFFSET) &&
10432 !(((unsigned long) rw) & 0x7)) {
10433 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10434 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10435 (void *) rw->ins[7]);
10436 rw = (struct reg_window32 *)rw->ins[6];
10437 }
10438 }
10439 printk("Instruction DUMP:");
10440 instruction_dump ((unsigned long *) regs->pc);
10441 - if(regs->psr & PSR_PS)
10442 + if(regs->psr & PSR_PS) {
10443 + gr_handle_kernel_exploit();
10444 do_exit(SIGKILL);
10445 + }
10446 do_exit(SIGSEGV);
10447 }
10448
10449 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10450 index 4ced92f..965eeed 100644
10451 --- a/arch/sparc/kernel/traps_64.c
10452 +++ b/arch/sparc/kernel/traps_64.c
10453 @@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10454 i + 1,
10455 p->trapstack[i].tstate, p->trapstack[i].tpc,
10456 p->trapstack[i].tnpc, p->trapstack[i].tt);
10457 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10458 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10459 }
10460 }
10461
10462 @@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10463
10464 lvl -= 0x100;
10465 if (regs->tstate & TSTATE_PRIV) {
10466 +
10467 +#ifdef CONFIG_PAX_REFCOUNT
10468 + if (lvl == 6)
10469 + pax_report_refcount_overflow(regs);
10470 +#endif
10471 +
10472 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10473 die_if_kernel(buffer, regs);
10474 }
10475 @@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10476 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10477 {
10478 char buffer[32];
10479 -
10480 +
10481 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10482 0, lvl, SIGTRAP) == NOTIFY_STOP)
10483 return;
10484
10485 +#ifdef CONFIG_PAX_REFCOUNT
10486 + if (lvl == 6)
10487 + pax_report_refcount_overflow(regs);
10488 +#endif
10489 +
10490 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10491
10492 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10493 @@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10494 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10495 printk("%s" "ERROR(%d): ",
10496 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10497 - printk("TPC<%pS>\n", (void *) regs->tpc);
10498 + printk("TPC<%pA>\n", (void *) regs->tpc);
10499 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10500 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10501 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10502 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10503 smp_processor_id(),
10504 (type & 0x1) ? 'I' : 'D',
10505 regs->tpc);
10506 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10507 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10508 panic("Irrecoverable Cheetah+ parity error.");
10509 }
10510
10511 @@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10512 smp_processor_id(),
10513 (type & 0x1) ? 'I' : 'D',
10514 regs->tpc);
10515 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10516 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10517 }
10518
10519 struct sun4v_error_entry {
10520 @@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10521 /*0x38*/u64 reserved_5;
10522 };
10523
10524 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10525 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10526 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10527 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10528
10529 static const char *sun4v_err_type_to_str(u8 type)
10530 {
10531 @@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10532 }
10533
10534 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10535 - int cpu, const char *pfx, atomic_t *ocnt)
10536 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10537 {
10538 u64 *raw_ptr = (u64 *) ent;
10539 u32 attrs;
10540 @@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10541
10542 show_regs(regs);
10543
10544 - if ((cnt = atomic_read(ocnt)) != 0) {
10545 - atomic_set(ocnt, 0);
10546 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10547 + atomic_set_unchecked(ocnt, 0);
10548 wmb();
10549 printk("%s: Queue overflowed %d times.\n",
10550 pfx, cnt);
10551 @@ -2046,7 +2057,7 @@ out:
10552 */
10553 void sun4v_resum_overflow(struct pt_regs *regs)
10554 {
10555 - atomic_inc(&sun4v_resum_oflow_cnt);
10556 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10557 }
10558
10559 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10560 @@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10561 /* XXX Actually even this can make not that much sense. Perhaps
10562 * XXX we should just pull the plug and panic directly from here?
10563 */
10564 - atomic_inc(&sun4v_nonresum_oflow_cnt);
10565 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10566 }
10567
10568 unsigned long sun4v_err_itlb_vaddr;
10569 @@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10570
10571 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10572 regs->tpc, tl);
10573 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10574 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10575 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10576 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10577 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10578 (void *) regs->u_regs[UREG_I7]);
10579 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10580 "pte[%lx] error[%lx]\n",
10581 @@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10582
10583 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10584 regs->tpc, tl);
10585 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10586 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10587 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10588 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10589 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10590 (void *) regs->u_regs[UREG_I7]);
10591 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10592 "pte[%lx] error[%lx]\n",
10593 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10594 fp = (unsigned long)sf->fp + STACK_BIAS;
10595 }
10596
10597 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10598 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10599 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10600 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10601 int index = tsk->curr_ret_stack;
10602 if (tsk->ret_stack && index >= graph) {
10603 pc = tsk->ret_stack[index - graph].ret;
10604 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10605 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10606 graph++;
10607 }
10608 }
10609 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10610 return (struct reg_window *) (fp + STACK_BIAS);
10611 }
10612
10613 +extern void gr_handle_kernel_exploit(void);
10614 +
10615 void die_if_kernel(char *str, struct pt_regs *regs)
10616 {
10617 static int die_counter;
10618 @@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10619 while (rw &&
10620 count++ < 30 &&
10621 kstack_valid(tp, (unsigned long) rw)) {
10622 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
10623 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
10624 (void *) rw->ins[7]);
10625
10626 rw = kernel_stack_up(rw);
10627 @@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10628 }
10629 user_instruction_dump ((unsigned int __user *) regs->tpc);
10630 }
10631 - if (regs->tstate & TSTATE_PRIV)
10632 + if (regs->tstate & TSTATE_PRIV) {
10633 + gr_handle_kernel_exploit();
10634 do_exit(SIGKILL);
10635 + }
10636 do_exit(SIGSEGV);
10637 }
10638 EXPORT_SYMBOL(die_if_kernel);
10639 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10640 index 3c1a7cb..73e1923 100644
10641 --- a/arch/sparc/kernel/unaligned_64.c
10642 +++ b/arch/sparc/kernel/unaligned_64.c
10643 @@ -289,7 +289,7 @@ static void log_unaligned(struct pt_regs *regs)
10644 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10645
10646 if (__ratelimit(&ratelimit)) {
10647 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
10648 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
10649 regs->tpc, (void *) regs->tpc);
10650 }
10651 }
10652 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10653 index dbe119b..089c7c1 100644
10654 --- a/arch/sparc/lib/Makefile
10655 +++ b/arch/sparc/lib/Makefile
10656 @@ -2,7 +2,7 @@
10657 #
10658
10659 asflags-y := -ansi -DST_DIV0=0x02
10660 -ccflags-y := -Werror
10661 +#ccflags-y := -Werror
10662
10663 lib-$(CONFIG_SPARC32) += ashrdi3.o
10664 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10665 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10666 index 85c233d..68500e0 100644
10667 --- a/arch/sparc/lib/atomic_64.S
10668 +++ b/arch/sparc/lib/atomic_64.S
10669 @@ -17,7 +17,12 @@
10670 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10671 BACKOFF_SETUP(%o2)
10672 1: lduw [%o1], %g1
10673 - add %g1, %o0, %g7
10674 + addcc %g1, %o0, %g7
10675 +
10676 +#ifdef CONFIG_PAX_REFCOUNT
10677 + tvs %icc, 6
10678 +#endif
10679 +
10680 cas [%o1], %g1, %g7
10681 cmp %g1, %g7
10682 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10683 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10684 2: BACKOFF_SPIN(%o2, %o3, 1b)
10685 ENDPROC(atomic_add)
10686
10687 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10688 + BACKOFF_SETUP(%o2)
10689 +1: lduw [%o1], %g1
10690 + add %g1, %o0, %g7
10691 + cas [%o1], %g1, %g7
10692 + cmp %g1, %g7
10693 + bne,pn %icc, 2f
10694 + nop
10695 + retl
10696 + nop
10697 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10698 +ENDPROC(atomic_add_unchecked)
10699 +
10700 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10701 BACKOFF_SETUP(%o2)
10702 1: lduw [%o1], %g1
10703 - sub %g1, %o0, %g7
10704 + subcc %g1, %o0, %g7
10705 +
10706 +#ifdef CONFIG_PAX_REFCOUNT
10707 + tvs %icc, 6
10708 +#endif
10709 +
10710 cas [%o1], %g1, %g7
10711 cmp %g1, %g7
10712 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10713 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10714 2: BACKOFF_SPIN(%o2, %o3, 1b)
10715 ENDPROC(atomic_sub)
10716
10717 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10718 + BACKOFF_SETUP(%o2)
10719 +1: lduw [%o1], %g1
10720 + sub %g1, %o0, %g7
10721 + cas [%o1], %g1, %g7
10722 + cmp %g1, %g7
10723 + bne,pn %icc, 2f
10724 + nop
10725 + retl
10726 + nop
10727 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10728 +ENDPROC(atomic_sub_unchecked)
10729 +
10730 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10731 BACKOFF_SETUP(%o2)
10732 1: lduw [%o1], %g1
10733 - add %g1, %o0, %g7
10734 + addcc %g1, %o0, %g7
10735 +
10736 +#ifdef CONFIG_PAX_REFCOUNT
10737 + tvs %icc, 6
10738 +#endif
10739 +
10740 cas [%o1], %g1, %g7
10741 cmp %g1, %g7
10742 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10743 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10744 2: BACKOFF_SPIN(%o2, %o3, 1b)
10745 ENDPROC(atomic_add_ret)
10746
10747 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10748 + BACKOFF_SETUP(%o2)
10749 +1: lduw [%o1], %g1
10750 + addcc %g1, %o0, %g7
10751 + cas [%o1], %g1, %g7
10752 + cmp %g1, %g7
10753 + bne,pn %icc, 2f
10754 + add %g7, %o0, %g7
10755 + sra %g7, 0, %o0
10756 + retl
10757 + nop
10758 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10759 +ENDPROC(atomic_add_ret_unchecked)
10760 +
10761 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10762 BACKOFF_SETUP(%o2)
10763 1: lduw [%o1], %g1
10764 - sub %g1, %o0, %g7
10765 + subcc %g1, %o0, %g7
10766 +
10767 +#ifdef CONFIG_PAX_REFCOUNT
10768 + tvs %icc, 6
10769 +#endif
10770 +
10771 cas [%o1], %g1, %g7
10772 cmp %g1, %g7
10773 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10774 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10775 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10776 BACKOFF_SETUP(%o2)
10777 1: ldx [%o1], %g1
10778 - add %g1, %o0, %g7
10779 + addcc %g1, %o0, %g7
10780 +
10781 +#ifdef CONFIG_PAX_REFCOUNT
10782 + tvs %xcc, 6
10783 +#endif
10784 +
10785 casx [%o1], %g1, %g7
10786 cmp %g1, %g7
10787 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10788 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10789 2: BACKOFF_SPIN(%o2, %o3, 1b)
10790 ENDPROC(atomic64_add)
10791
10792 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10793 + BACKOFF_SETUP(%o2)
10794 +1: ldx [%o1], %g1
10795 + addcc %g1, %o0, %g7
10796 + casx [%o1], %g1, %g7
10797 + cmp %g1, %g7
10798 + bne,pn %xcc, 2f
10799 + nop
10800 + retl
10801 + nop
10802 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10803 +ENDPROC(atomic64_add_unchecked)
10804 +
10805 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10806 BACKOFF_SETUP(%o2)
10807 1: ldx [%o1], %g1
10808 - sub %g1, %o0, %g7
10809 + subcc %g1, %o0, %g7
10810 +
10811 +#ifdef CONFIG_PAX_REFCOUNT
10812 + tvs %xcc, 6
10813 +#endif
10814 +
10815 casx [%o1], %g1, %g7
10816 cmp %g1, %g7
10817 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10818 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10819 2: BACKOFF_SPIN(%o2, %o3, 1b)
10820 ENDPROC(atomic64_sub)
10821
10822 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10823 + BACKOFF_SETUP(%o2)
10824 +1: ldx [%o1], %g1
10825 + subcc %g1, %o0, %g7
10826 + casx [%o1], %g1, %g7
10827 + cmp %g1, %g7
10828 + bne,pn %xcc, 2f
10829 + nop
10830 + retl
10831 + nop
10832 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10833 +ENDPROC(atomic64_sub_unchecked)
10834 +
10835 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10836 BACKOFF_SETUP(%o2)
10837 1: ldx [%o1], %g1
10838 - add %g1, %o0, %g7
10839 + addcc %g1, %o0, %g7
10840 +
10841 +#ifdef CONFIG_PAX_REFCOUNT
10842 + tvs %xcc, 6
10843 +#endif
10844 +
10845 casx [%o1], %g1, %g7
10846 cmp %g1, %g7
10847 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10848 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10849 2: BACKOFF_SPIN(%o2, %o3, 1b)
10850 ENDPROC(atomic64_add_ret)
10851
10852 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10853 + BACKOFF_SETUP(%o2)
10854 +1: ldx [%o1], %g1
10855 + addcc %g1, %o0, %g7
10856 + casx [%o1], %g1, %g7
10857 + cmp %g1, %g7
10858 + bne,pn %xcc, 2f
10859 + add %g7, %o0, %g7
10860 + mov %g7, %o0
10861 + retl
10862 + nop
10863 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10864 +ENDPROC(atomic64_add_ret_unchecked)
10865 +
10866 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10867 BACKOFF_SETUP(%o2)
10868 1: ldx [%o1], %g1
10869 - sub %g1, %o0, %g7
10870 + subcc %g1, %o0, %g7
10871 +
10872 +#ifdef CONFIG_PAX_REFCOUNT
10873 + tvs %xcc, 6
10874 +#endif
10875 +
10876 casx [%o1], %g1, %g7
10877 cmp %g1, %g7
10878 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10879 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10880 index 323335b..ed85ea2 100644
10881 --- a/arch/sparc/lib/ksyms.c
10882 +++ b/arch/sparc/lib/ksyms.c
10883 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10884
10885 /* Atomic counter implementation. */
10886 EXPORT_SYMBOL(atomic_add);
10887 +EXPORT_SYMBOL(atomic_add_unchecked);
10888 EXPORT_SYMBOL(atomic_add_ret);
10889 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
10890 EXPORT_SYMBOL(atomic_sub);
10891 +EXPORT_SYMBOL(atomic_sub_unchecked);
10892 EXPORT_SYMBOL(atomic_sub_ret);
10893 EXPORT_SYMBOL(atomic64_add);
10894 +EXPORT_SYMBOL(atomic64_add_unchecked);
10895 EXPORT_SYMBOL(atomic64_add_ret);
10896 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10897 EXPORT_SYMBOL(atomic64_sub);
10898 +EXPORT_SYMBOL(atomic64_sub_unchecked);
10899 EXPORT_SYMBOL(atomic64_sub_ret);
10900 EXPORT_SYMBOL(atomic64_dec_if_positive);
10901
10902 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10903 index 30c3ecc..736f015 100644
10904 --- a/arch/sparc/mm/Makefile
10905 +++ b/arch/sparc/mm/Makefile
10906 @@ -2,7 +2,7 @@
10907 #
10908
10909 asflags-y := -ansi
10910 -ccflags-y := -Werror
10911 +#ccflags-y := -Werror
10912
10913 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10914 obj-y += fault_$(BITS).o
10915 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10916 index 59dbd46..1dd7f5e 100644
10917 --- a/arch/sparc/mm/fault_32.c
10918 +++ b/arch/sparc/mm/fault_32.c
10919 @@ -21,6 +21,9 @@
10920 #include <linux/perf_event.h>
10921 #include <linux/interrupt.h>
10922 #include <linux/kdebug.h>
10923 +#include <linux/slab.h>
10924 +#include <linux/pagemap.h>
10925 +#include <linux/compiler.h>
10926
10927 #include <asm/page.h>
10928 #include <asm/pgtable.h>
10929 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10930 return safe_compute_effective_address(regs, insn);
10931 }
10932
10933 +#ifdef CONFIG_PAX_PAGEEXEC
10934 +#ifdef CONFIG_PAX_DLRESOLVE
10935 +static void pax_emuplt_close(struct vm_area_struct *vma)
10936 +{
10937 + vma->vm_mm->call_dl_resolve = 0UL;
10938 +}
10939 +
10940 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10941 +{
10942 + unsigned int *kaddr;
10943 +
10944 + vmf->page = alloc_page(GFP_HIGHUSER);
10945 + if (!vmf->page)
10946 + return VM_FAULT_OOM;
10947 +
10948 + kaddr = kmap(vmf->page);
10949 + memset(kaddr, 0, PAGE_SIZE);
10950 + kaddr[0] = 0x9DE3BFA8U; /* save */
10951 + flush_dcache_page(vmf->page);
10952 + kunmap(vmf->page);
10953 + return VM_FAULT_MAJOR;
10954 +}
10955 +
10956 +static const struct vm_operations_struct pax_vm_ops = {
10957 + .close = pax_emuplt_close,
10958 + .fault = pax_emuplt_fault
10959 +};
10960 +
10961 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10962 +{
10963 + int ret;
10964 +
10965 + INIT_LIST_HEAD(&vma->anon_vma_chain);
10966 + vma->vm_mm = current->mm;
10967 + vma->vm_start = addr;
10968 + vma->vm_end = addr + PAGE_SIZE;
10969 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10970 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10971 + vma->vm_ops = &pax_vm_ops;
10972 +
10973 + ret = insert_vm_struct(current->mm, vma);
10974 + if (ret)
10975 + return ret;
10976 +
10977 + ++current->mm->total_vm;
10978 + return 0;
10979 +}
10980 +#endif
10981 +
10982 +/*
10983 + * PaX: decide what to do with offenders (regs->pc = fault address)
10984 + *
10985 + * returns 1 when task should be killed
10986 + * 2 when patched PLT trampoline was detected
10987 + * 3 when unpatched PLT trampoline was detected
10988 + */
10989 +static int pax_handle_fetch_fault(struct pt_regs *regs)
10990 +{
10991 +
10992 +#ifdef CONFIG_PAX_EMUPLT
10993 + int err;
10994 +
10995 + do { /* PaX: patched PLT emulation #1 */
10996 + unsigned int sethi1, sethi2, jmpl;
10997 +
10998 + err = get_user(sethi1, (unsigned int *)regs->pc);
10999 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11000 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11001 +
11002 + if (err)
11003 + break;
11004 +
11005 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11006 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11007 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11008 + {
11009 + unsigned int addr;
11010 +
11011 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11012 + addr = regs->u_regs[UREG_G1];
11013 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11014 + regs->pc = addr;
11015 + regs->npc = addr+4;
11016 + return 2;
11017 + }
11018 + } while (0);
11019 +
11020 + do { /* PaX: patched PLT emulation #2 */
11021 + unsigned int ba;
11022 +
11023 + err = get_user(ba, (unsigned int *)regs->pc);
11024 +
11025 + if (err)
11026 + break;
11027 +
11028 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11029 + unsigned int addr;
11030 +
11031 + if ((ba & 0xFFC00000U) == 0x30800000U)
11032 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11033 + else
11034 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11035 + regs->pc = addr;
11036 + regs->npc = addr+4;
11037 + return 2;
11038 + }
11039 + } while (0);
11040 +
11041 + do { /* PaX: patched PLT emulation #3 */
11042 + unsigned int sethi, bajmpl, nop;
11043 +
11044 + err = get_user(sethi, (unsigned int *)regs->pc);
11045 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11046 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11047 +
11048 + if (err)
11049 + break;
11050 +
11051 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11052 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11053 + nop == 0x01000000U)
11054 + {
11055 + unsigned int addr;
11056 +
11057 + addr = (sethi & 0x003FFFFFU) << 10;
11058 + regs->u_regs[UREG_G1] = addr;
11059 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11060 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11061 + else
11062 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11063 + regs->pc = addr;
11064 + regs->npc = addr+4;
11065 + return 2;
11066 + }
11067 + } while (0);
11068 +
11069 + do { /* PaX: unpatched PLT emulation step 1 */
11070 + unsigned int sethi, ba, nop;
11071 +
11072 + err = get_user(sethi, (unsigned int *)regs->pc);
11073 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11074 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11075 +
11076 + if (err)
11077 + break;
11078 +
11079 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11080 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11081 + nop == 0x01000000U)
11082 + {
11083 + unsigned int addr, save, call;
11084 +
11085 + if ((ba & 0xFFC00000U) == 0x30800000U)
11086 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11087 + else
11088 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11089 +
11090 + err = get_user(save, (unsigned int *)addr);
11091 + err |= get_user(call, (unsigned int *)(addr+4));
11092 + err |= get_user(nop, (unsigned int *)(addr+8));
11093 + if (err)
11094 + break;
11095 +
11096 +#ifdef CONFIG_PAX_DLRESOLVE
11097 + if (save == 0x9DE3BFA8U &&
11098 + (call & 0xC0000000U) == 0x40000000U &&
11099 + nop == 0x01000000U)
11100 + {
11101 + struct vm_area_struct *vma;
11102 + unsigned long call_dl_resolve;
11103 +
11104 + down_read(&current->mm->mmap_sem);
11105 + call_dl_resolve = current->mm->call_dl_resolve;
11106 + up_read(&current->mm->mmap_sem);
11107 + if (likely(call_dl_resolve))
11108 + goto emulate;
11109 +
11110 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11111 +
11112 + down_write(&current->mm->mmap_sem);
11113 + if (current->mm->call_dl_resolve) {
11114 + call_dl_resolve = current->mm->call_dl_resolve;
11115 + up_write(&current->mm->mmap_sem);
11116 + if (vma)
11117 + kmem_cache_free(vm_area_cachep, vma);
11118 + goto emulate;
11119 + }
11120 +
11121 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11122 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11123 + up_write(&current->mm->mmap_sem);
11124 + if (vma)
11125 + kmem_cache_free(vm_area_cachep, vma);
11126 + return 1;
11127 + }
11128 +
11129 + if (pax_insert_vma(vma, call_dl_resolve)) {
11130 + up_write(&current->mm->mmap_sem);
11131 + kmem_cache_free(vm_area_cachep, vma);
11132 + return 1;
11133 + }
11134 +
11135 + current->mm->call_dl_resolve = call_dl_resolve;
11136 + up_write(&current->mm->mmap_sem);
11137 +
11138 +emulate:
11139 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11140 + regs->pc = call_dl_resolve;
11141 + regs->npc = addr+4;
11142 + return 3;
11143 + }
11144 +#endif
11145 +
11146 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11147 + if ((save & 0xFFC00000U) == 0x05000000U &&
11148 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11149 + nop == 0x01000000U)
11150 + {
11151 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11152 + regs->u_regs[UREG_G2] = addr + 4;
11153 + addr = (save & 0x003FFFFFU) << 10;
11154 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11155 + regs->pc = addr;
11156 + regs->npc = addr+4;
11157 + return 3;
11158 + }
11159 + }
11160 + } while (0);
11161 +
11162 + do { /* PaX: unpatched PLT emulation step 2 */
11163 + unsigned int save, call, nop;
11164 +
11165 + err = get_user(save, (unsigned int *)(regs->pc-4));
11166 + err |= get_user(call, (unsigned int *)regs->pc);
11167 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11168 + if (err)
11169 + break;
11170 +
11171 + if (save == 0x9DE3BFA8U &&
11172 + (call & 0xC0000000U) == 0x40000000U &&
11173 + nop == 0x01000000U)
11174 + {
11175 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11176 +
11177 + regs->u_regs[UREG_RETPC] = regs->pc;
11178 + regs->pc = dl_resolve;
11179 + regs->npc = dl_resolve+4;
11180 + return 3;
11181 + }
11182 + } while (0);
11183 +#endif
11184 +
11185 + return 1;
11186 +}
11187 +
11188 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11189 +{
11190 + unsigned long i;
11191 +
11192 + printk(KERN_ERR "PAX: bytes at PC: ");
11193 + for (i = 0; i < 8; i++) {
11194 + unsigned int c;
11195 + if (get_user(c, (unsigned int *)pc+i))
11196 + printk(KERN_CONT "???????? ");
11197 + else
11198 + printk(KERN_CONT "%08x ", c);
11199 + }
11200 + printk("\n");
11201 +}
11202 +#endif
11203 +
11204 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11205 int text_fault)
11206 {
11207 @@ -229,6 +503,24 @@ good_area:
11208 if (!(vma->vm_flags & VM_WRITE))
11209 goto bad_area;
11210 } else {
11211 +
11212 +#ifdef CONFIG_PAX_PAGEEXEC
11213 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11214 + up_read(&mm->mmap_sem);
11215 + switch (pax_handle_fetch_fault(regs)) {
11216 +
11217 +#ifdef CONFIG_PAX_EMUPLT
11218 + case 2:
11219 + case 3:
11220 + return;
11221 +#endif
11222 +
11223 + }
11224 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11225 + do_group_exit(SIGKILL);
11226 + }
11227 +#endif
11228 +
11229 /* Allow reads even for write-only mappings */
11230 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11231 goto bad_area;
11232 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11233 index 69bb818..6ca35c8 100644
11234 --- a/arch/sparc/mm/fault_64.c
11235 +++ b/arch/sparc/mm/fault_64.c
11236 @@ -22,6 +22,9 @@
11237 #include <linux/kdebug.h>
11238 #include <linux/percpu.h>
11239 #include <linux/context_tracking.h>
11240 +#include <linux/slab.h>
11241 +#include <linux/pagemap.h>
11242 +#include <linux/compiler.h>
11243
11244 #include <asm/page.h>
11245 #include <asm/pgtable.h>
11246 @@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11247 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11248 regs->tpc);
11249 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11250 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11251 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11252 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11253 dump_stack();
11254 unhandled_fault(regs->tpc, current, regs);
11255 @@ -271,6 +274,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
11256 show_regs(regs);
11257 }
11258
11259 +#ifdef CONFIG_PAX_PAGEEXEC
11260 +#ifdef CONFIG_PAX_DLRESOLVE
11261 +static void pax_emuplt_close(struct vm_area_struct *vma)
11262 +{
11263 + vma->vm_mm->call_dl_resolve = 0UL;
11264 +}
11265 +
11266 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11267 +{
11268 + unsigned int *kaddr;
11269 +
11270 + vmf->page = alloc_page(GFP_HIGHUSER);
11271 + if (!vmf->page)
11272 + return VM_FAULT_OOM;
11273 +
11274 + kaddr = kmap(vmf->page);
11275 + memset(kaddr, 0, PAGE_SIZE);
11276 + kaddr[0] = 0x9DE3BFA8U; /* save */
11277 + flush_dcache_page(vmf->page);
11278 + kunmap(vmf->page);
11279 + return VM_FAULT_MAJOR;
11280 +}
11281 +
11282 +static const struct vm_operations_struct pax_vm_ops = {
11283 + .close = pax_emuplt_close,
11284 + .fault = pax_emuplt_fault
11285 +};
11286 +
11287 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11288 +{
11289 + int ret;
11290 +
11291 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11292 + vma->vm_mm = current->mm;
11293 + vma->vm_start = addr;
11294 + vma->vm_end = addr + PAGE_SIZE;
11295 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11296 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11297 + vma->vm_ops = &pax_vm_ops;
11298 +
11299 + ret = insert_vm_struct(current->mm, vma);
11300 + if (ret)
11301 + return ret;
11302 +
11303 + ++current->mm->total_vm;
11304 + return 0;
11305 +}
11306 +#endif
11307 +
11308 +/*
11309 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11310 + *
11311 + * returns 1 when task should be killed
11312 + * 2 when patched PLT trampoline was detected
11313 + * 3 when unpatched PLT trampoline was detected
11314 + */
11315 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11316 +{
11317 +
11318 +#ifdef CONFIG_PAX_EMUPLT
11319 + int err;
11320 +
11321 + do { /* PaX: patched PLT emulation #1 */
11322 + unsigned int sethi1, sethi2, jmpl;
11323 +
11324 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11325 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11326 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11327 +
11328 + if (err)
11329 + break;
11330 +
11331 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11332 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11333 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11334 + {
11335 + unsigned long addr;
11336 +
11337 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11338 + addr = regs->u_regs[UREG_G1];
11339 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11340 +
11341 + if (test_thread_flag(TIF_32BIT))
11342 + addr &= 0xFFFFFFFFUL;
11343 +
11344 + regs->tpc = addr;
11345 + regs->tnpc = addr+4;
11346 + return 2;
11347 + }
11348 + } while (0);
11349 +
11350 + do { /* PaX: patched PLT emulation #2 */
11351 + unsigned int ba;
11352 +
11353 + err = get_user(ba, (unsigned int *)regs->tpc);
11354 +
11355 + if (err)
11356 + break;
11357 +
11358 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11359 + unsigned long addr;
11360 +
11361 + if ((ba & 0xFFC00000U) == 0x30800000U)
11362 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11363 + else
11364 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11365 +
11366 + if (test_thread_flag(TIF_32BIT))
11367 + addr &= 0xFFFFFFFFUL;
11368 +
11369 + regs->tpc = addr;
11370 + regs->tnpc = addr+4;
11371 + return 2;
11372 + }
11373 + } while (0);
11374 +
11375 + do { /* PaX: patched PLT emulation #3 */
11376 + unsigned int sethi, bajmpl, nop;
11377 +
11378 + err = get_user(sethi, (unsigned int *)regs->tpc);
11379 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11380 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11381 +
11382 + if (err)
11383 + break;
11384 +
11385 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11386 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11387 + nop == 0x01000000U)
11388 + {
11389 + unsigned long addr;
11390 +
11391 + addr = (sethi & 0x003FFFFFU) << 10;
11392 + regs->u_regs[UREG_G1] = addr;
11393 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11394 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11395 + else
11396 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11397 +
11398 + if (test_thread_flag(TIF_32BIT))
11399 + addr &= 0xFFFFFFFFUL;
11400 +
11401 + regs->tpc = addr;
11402 + regs->tnpc = addr+4;
11403 + return 2;
11404 + }
11405 + } while (0);
11406 +
11407 + do { /* PaX: patched PLT emulation #4 */
11408 + unsigned int sethi, mov1, call, mov2;
11409 +
11410 + err = get_user(sethi, (unsigned int *)regs->tpc);
11411 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11412 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11413 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11414 +
11415 + if (err)
11416 + break;
11417 +
11418 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11419 + mov1 == 0x8210000FU &&
11420 + (call & 0xC0000000U) == 0x40000000U &&
11421 + mov2 == 0x9E100001U)
11422 + {
11423 + unsigned long addr;
11424 +
11425 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11426 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11427 +
11428 + if (test_thread_flag(TIF_32BIT))
11429 + addr &= 0xFFFFFFFFUL;
11430 +
11431 + regs->tpc = addr;
11432 + regs->tnpc = addr+4;
11433 + return 2;
11434 + }
11435 + } while (0);
11436 +
11437 + do { /* PaX: patched PLT emulation #5 */
11438 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11439 +
11440 + err = get_user(sethi, (unsigned int *)regs->tpc);
11441 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11442 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11443 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11444 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11445 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11446 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11447 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11448 +
11449 + if (err)
11450 + break;
11451 +
11452 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11453 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11454 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11455 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11456 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11457 + sllx == 0x83287020U &&
11458 + jmpl == 0x81C04005U &&
11459 + nop == 0x01000000U)
11460 + {
11461 + unsigned long addr;
11462 +
11463 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11464 + regs->u_regs[UREG_G1] <<= 32;
11465 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11466 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11467 + regs->tpc = addr;
11468 + regs->tnpc = addr+4;
11469 + return 2;
11470 + }
11471 + } while (0);
11472 +
11473 + do { /* PaX: patched PLT emulation #6 */
11474 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11475 +
11476 + err = get_user(sethi, (unsigned int *)regs->tpc);
11477 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11478 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11479 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11480 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11481 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11482 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11483 +
11484 + if (err)
11485 + break;
11486 +
11487 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11488 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11489 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11490 + sllx == 0x83287020U &&
11491 + (or & 0xFFFFE000U) == 0x8A116000U &&
11492 + jmpl == 0x81C04005U &&
11493 + nop == 0x01000000U)
11494 + {
11495 + unsigned long addr;
11496 +
11497 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11498 + regs->u_regs[UREG_G1] <<= 32;
11499 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11500 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11501 + regs->tpc = addr;
11502 + regs->tnpc = addr+4;
11503 + return 2;
11504 + }
11505 + } while (0);
11506 +
11507 + do { /* PaX: unpatched PLT emulation step 1 */
11508 + unsigned int sethi, ba, nop;
11509 +
11510 + err = get_user(sethi, (unsigned int *)regs->tpc);
11511 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11512 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11513 +
11514 + if (err)
11515 + break;
11516 +
11517 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11518 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11519 + nop == 0x01000000U)
11520 + {
11521 + unsigned long addr;
11522 + unsigned int save, call;
11523 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11524 +
11525 + if ((ba & 0xFFC00000U) == 0x30800000U)
11526 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11527 + else
11528 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11529 +
11530 + if (test_thread_flag(TIF_32BIT))
11531 + addr &= 0xFFFFFFFFUL;
11532 +
11533 + err = get_user(save, (unsigned int *)addr);
11534 + err |= get_user(call, (unsigned int *)(addr+4));
11535 + err |= get_user(nop, (unsigned int *)(addr+8));
11536 + if (err)
11537 + break;
11538 +
11539 +#ifdef CONFIG_PAX_DLRESOLVE
11540 + if (save == 0x9DE3BFA8U &&
11541 + (call & 0xC0000000U) == 0x40000000U &&
11542 + nop == 0x01000000U)
11543 + {
11544 + struct vm_area_struct *vma;
11545 + unsigned long call_dl_resolve;
11546 +
11547 + down_read(&current->mm->mmap_sem);
11548 + call_dl_resolve = current->mm->call_dl_resolve;
11549 + up_read(&current->mm->mmap_sem);
11550 + if (likely(call_dl_resolve))
11551 + goto emulate;
11552 +
11553 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11554 +
11555 + down_write(&current->mm->mmap_sem);
11556 + if (current->mm->call_dl_resolve) {
11557 + call_dl_resolve = current->mm->call_dl_resolve;
11558 + up_write(&current->mm->mmap_sem);
11559 + if (vma)
11560 + kmem_cache_free(vm_area_cachep, vma);
11561 + goto emulate;
11562 + }
11563 +
11564 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11565 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11566 + up_write(&current->mm->mmap_sem);
11567 + if (vma)
11568 + kmem_cache_free(vm_area_cachep, vma);
11569 + return 1;
11570 + }
11571 +
11572 + if (pax_insert_vma(vma, call_dl_resolve)) {
11573 + up_write(&current->mm->mmap_sem);
11574 + kmem_cache_free(vm_area_cachep, vma);
11575 + return 1;
11576 + }
11577 +
11578 + current->mm->call_dl_resolve = call_dl_resolve;
11579 + up_write(&current->mm->mmap_sem);
11580 +
11581 +emulate:
11582 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11583 + regs->tpc = call_dl_resolve;
11584 + regs->tnpc = addr+4;
11585 + return 3;
11586 + }
11587 +#endif
11588 +
11589 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11590 + if ((save & 0xFFC00000U) == 0x05000000U &&
11591 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11592 + nop == 0x01000000U)
11593 + {
11594 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11595 + regs->u_regs[UREG_G2] = addr + 4;
11596 + addr = (save & 0x003FFFFFU) << 10;
11597 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11598 +
11599 + if (test_thread_flag(TIF_32BIT))
11600 + addr &= 0xFFFFFFFFUL;
11601 +
11602 + regs->tpc = addr;
11603 + regs->tnpc = addr+4;
11604 + return 3;
11605 + }
11606 +
11607 + /* PaX: 64-bit PLT stub */
11608 + err = get_user(sethi1, (unsigned int *)addr);
11609 + err |= get_user(sethi2, (unsigned int *)(addr+4));
11610 + err |= get_user(or1, (unsigned int *)(addr+8));
11611 + err |= get_user(or2, (unsigned int *)(addr+12));
11612 + err |= get_user(sllx, (unsigned int *)(addr+16));
11613 + err |= get_user(add, (unsigned int *)(addr+20));
11614 + err |= get_user(jmpl, (unsigned int *)(addr+24));
11615 + err |= get_user(nop, (unsigned int *)(addr+28));
11616 + if (err)
11617 + break;
11618 +
11619 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11620 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11621 + (or1 & 0xFFFFE000U) == 0x88112000U &&
11622 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11623 + sllx == 0x89293020U &&
11624 + add == 0x8A010005U &&
11625 + jmpl == 0x89C14000U &&
11626 + nop == 0x01000000U)
11627 + {
11628 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11629 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11630 + regs->u_regs[UREG_G4] <<= 32;
11631 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11632 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11633 + regs->u_regs[UREG_G4] = addr + 24;
11634 + addr = regs->u_regs[UREG_G5];
11635 + regs->tpc = addr;
11636 + regs->tnpc = addr+4;
11637 + return 3;
11638 + }
11639 + }
11640 + } while (0);
11641 +
11642 +#ifdef CONFIG_PAX_DLRESOLVE
11643 + do { /* PaX: unpatched PLT emulation step 2 */
11644 + unsigned int save, call, nop;
11645 +
11646 + err = get_user(save, (unsigned int *)(regs->tpc-4));
11647 + err |= get_user(call, (unsigned int *)regs->tpc);
11648 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11649 + if (err)
11650 + break;
11651 +
11652 + if (save == 0x9DE3BFA8U &&
11653 + (call & 0xC0000000U) == 0x40000000U &&
11654 + nop == 0x01000000U)
11655 + {
11656 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11657 +
11658 + if (test_thread_flag(TIF_32BIT))
11659 + dl_resolve &= 0xFFFFFFFFUL;
11660 +
11661 + regs->u_regs[UREG_RETPC] = regs->tpc;
11662 + regs->tpc = dl_resolve;
11663 + regs->tnpc = dl_resolve+4;
11664 + return 3;
11665 + }
11666 + } while (0);
11667 +#endif
11668 +
11669 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11670 + unsigned int sethi, ba, nop;
11671 +
11672 + err = get_user(sethi, (unsigned int *)regs->tpc);
11673 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11674 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11675 +
11676 + if (err)
11677 + break;
11678 +
11679 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11680 + (ba & 0xFFF00000U) == 0x30600000U &&
11681 + nop == 0x01000000U)
11682 + {
11683 + unsigned long addr;
11684 +
11685 + addr = (sethi & 0x003FFFFFU) << 10;
11686 + regs->u_regs[UREG_G1] = addr;
11687 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11688 +
11689 + if (test_thread_flag(TIF_32BIT))
11690 + addr &= 0xFFFFFFFFUL;
11691 +
11692 + regs->tpc = addr;
11693 + regs->tnpc = addr+4;
11694 + return 2;
11695 + }
11696 + } while (0);
11697 +
11698 +#endif
11699 +
11700 + return 1;
11701 +}
11702 +
11703 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11704 +{
11705 + unsigned long i;
11706 +
11707 + printk(KERN_ERR "PAX: bytes at PC: ");
11708 + for (i = 0; i < 8; i++) {
11709 + unsigned int c;
11710 + if (get_user(c, (unsigned int *)pc+i))
11711 + printk(KERN_CONT "???????? ");
11712 + else
11713 + printk(KERN_CONT "%08x ", c);
11714 + }
11715 + printk("\n");
11716 +}
11717 +#endif
11718 +
11719 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11720 {
11721 enum ctx_state prev_state = exception_enter();
11722 @@ -344,6 +807,29 @@ retry:
11723 if (!vma)
11724 goto bad_area;
11725
11726 +#ifdef CONFIG_PAX_PAGEEXEC
11727 + /* PaX: detect ITLB misses on non-exec pages */
11728 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11729 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11730 + {
11731 + if (address != regs->tpc)
11732 + goto good_area;
11733 +
11734 + up_read(&mm->mmap_sem);
11735 + switch (pax_handle_fetch_fault(regs)) {
11736 +
11737 +#ifdef CONFIG_PAX_EMUPLT
11738 + case 2:
11739 + case 3:
11740 + return;
11741 +#endif
11742 +
11743 + }
11744 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11745 + do_group_exit(SIGKILL);
11746 + }
11747 +#endif
11748 +
11749 /* Pure DTLB misses do not tell us whether the fault causing
11750 * load/store/atomic was a write or not, it only says that there
11751 * was no match. So in such a case we (carefully) read the
11752 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11753 index 9bd9ce8..dc84852 100644
11754 --- a/arch/sparc/mm/hugetlbpage.c
11755 +++ b/arch/sparc/mm/hugetlbpage.c
11756 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11757 unsigned long addr,
11758 unsigned long len,
11759 unsigned long pgoff,
11760 - unsigned long flags)
11761 + unsigned long flags,
11762 + unsigned long offset)
11763 {
11764 + struct mm_struct *mm = current->mm;
11765 unsigned long task_size = TASK_SIZE;
11766 struct vm_unmapped_area_info info;
11767
11768 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11769
11770 info.flags = 0;
11771 info.length = len;
11772 - info.low_limit = TASK_UNMAPPED_BASE;
11773 + info.low_limit = mm->mmap_base;
11774 info.high_limit = min(task_size, VA_EXCLUDE_START);
11775 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11776 info.align_offset = 0;
11777 + info.threadstack_offset = offset;
11778 addr = vm_unmapped_area(&info);
11779
11780 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11781 VM_BUG_ON(addr != -ENOMEM);
11782 info.low_limit = VA_EXCLUDE_END;
11783 +
11784 +#ifdef CONFIG_PAX_RANDMMAP
11785 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11786 + info.low_limit += mm->delta_mmap;
11787 +#endif
11788 +
11789 info.high_limit = task_size;
11790 addr = vm_unmapped_area(&info);
11791 }
11792 @@ -55,7 +64,8 @@ static unsigned long
11793 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11794 const unsigned long len,
11795 const unsigned long pgoff,
11796 - const unsigned long flags)
11797 + const unsigned long flags,
11798 + const unsigned long offset)
11799 {
11800 struct mm_struct *mm = current->mm;
11801 unsigned long addr = addr0;
11802 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11803 info.high_limit = mm->mmap_base;
11804 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11805 info.align_offset = 0;
11806 + info.threadstack_offset = offset;
11807 addr = vm_unmapped_area(&info);
11808
11809 /*
11810 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11811 VM_BUG_ON(addr != -ENOMEM);
11812 info.flags = 0;
11813 info.low_limit = TASK_UNMAPPED_BASE;
11814 +
11815 +#ifdef CONFIG_PAX_RANDMMAP
11816 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11817 + info.low_limit += mm->delta_mmap;
11818 +#endif
11819 +
11820 info.high_limit = STACK_TOP32;
11821 addr = vm_unmapped_area(&info);
11822 }
11823 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11824 struct mm_struct *mm = current->mm;
11825 struct vm_area_struct *vma;
11826 unsigned long task_size = TASK_SIZE;
11827 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11828
11829 if (test_thread_flag(TIF_32BIT))
11830 task_size = STACK_TOP32;
11831 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11832 return addr;
11833 }
11834
11835 +#ifdef CONFIG_PAX_RANDMMAP
11836 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11837 +#endif
11838 +
11839 if (addr) {
11840 addr = ALIGN(addr, HPAGE_SIZE);
11841 vma = find_vma(mm, addr);
11842 - if (task_size - len >= addr &&
11843 - (!vma || addr + len <= vma->vm_start))
11844 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11845 return addr;
11846 }
11847 if (mm->get_unmapped_area == arch_get_unmapped_area)
11848 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11849 - pgoff, flags);
11850 + pgoff, flags, offset);
11851 else
11852 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11853 - pgoff, flags);
11854 + pgoff, flags, offset);
11855 }
11856
11857 pte_t *huge_pte_alloc(struct mm_struct *mm,
11858 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11859 index eafbc65..5a8070d 100644
11860 --- a/arch/sparc/mm/init_64.c
11861 +++ b/arch/sparc/mm/init_64.c
11862 @@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11863 int num_kernel_image_mappings;
11864
11865 #ifdef CONFIG_DEBUG_DCFLUSH
11866 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
11867 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11868 #ifdef CONFIG_SMP
11869 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11870 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11871 #endif
11872 #endif
11873
11874 @@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11875 {
11876 BUG_ON(tlb_type == hypervisor);
11877 #ifdef CONFIG_DEBUG_DCFLUSH
11878 - atomic_inc(&dcpage_flushes);
11879 + atomic_inc_unchecked(&dcpage_flushes);
11880 #endif
11881
11882 #ifdef DCACHE_ALIASING_POSSIBLE
11883 @@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11884
11885 #ifdef CONFIG_DEBUG_DCFLUSH
11886 seq_printf(m, "DCPageFlushes\t: %d\n",
11887 - atomic_read(&dcpage_flushes));
11888 + atomic_read_unchecked(&dcpage_flushes));
11889 #ifdef CONFIG_SMP
11890 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11891 - atomic_read(&dcpage_flushes_xcall));
11892 + atomic_read_unchecked(&dcpage_flushes_xcall));
11893 #endif /* CONFIG_SMP */
11894 #endif /* CONFIG_DEBUG_DCFLUSH */
11895 }
11896 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11897 index b3692ce..e4517c9 100644
11898 --- a/arch/tile/Kconfig
11899 +++ b/arch/tile/Kconfig
11900 @@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
11901
11902 config KEXEC
11903 bool "kexec system call"
11904 + depends on !GRKERNSEC_KMEM
11905 ---help---
11906 kexec is a system call that implements the ability to shutdown your
11907 current kernel, and to start another kernel. It is like a reboot
11908 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11909 index ad220ee..2f537b3 100644
11910 --- a/arch/tile/include/asm/atomic_64.h
11911 +++ b/arch/tile/include/asm/atomic_64.h
11912 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11913
11914 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11915
11916 +#define atomic64_read_unchecked(v) atomic64_read(v)
11917 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11918 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11919 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11920 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11921 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
11922 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11923 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
11924 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11925 +
11926 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11927 #define smp_mb__before_atomic_dec() smp_mb()
11928 #define smp_mb__after_atomic_dec() smp_mb()
11929 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11930 index 6160761..00cac88 100644
11931 --- a/arch/tile/include/asm/cache.h
11932 +++ b/arch/tile/include/asm/cache.h
11933 @@ -15,11 +15,12 @@
11934 #ifndef _ASM_TILE_CACHE_H
11935 #define _ASM_TILE_CACHE_H
11936
11937 +#include <linux/const.h>
11938 #include <arch/chip.h>
11939
11940 /* bytes per L1 data cache line */
11941 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11942 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11943 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11944
11945 /* bytes per L2 cache line */
11946 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11947 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11948 index b6cde32..c0cb736 100644
11949 --- a/arch/tile/include/asm/uaccess.h
11950 +++ b/arch/tile/include/asm/uaccess.h
11951 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11952 const void __user *from,
11953 unsigned long n)
11954 {
11955 - int sz = __compiletime_object_size(to);
11956 + size_t sz = __compiletime_object_size(to);
11957
11958 - if (likely(sz == -1 || sz >= n))
11959 + if (likely(sz == (size_t)-1 || sz >= n))
11960 n = _copy_from_user(to, from, n);
11961 else
11962 copy_from_user_overflow();
11963 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11964 index 0cb3bba..7338b2d 100644
11965 --- a/arch/tile/mm/hugetlbpage.c
11966 +++ b/arch/tile/mm/hugetlbpage.c
11967 @@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11968 info.high_limit = TASK_SIZE;
11969 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11970 info.align_offset = 0;
11971 + info.threadstack_offset = 0;
11972 return vm_unmapped_area(&info);
11973 }
11974
11975 @@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11976 info.high_limit = current->mm->mmap_base;
11977 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11978 info.align_offset = 0;
11979 + info.threadstack_offset = 0;
11980 addr = vm_unmapped_area(&info);
11981
11982 /*
11983 diff --git a/arch/um/Makefile b/arch/um/Makefile
11984 index 36e658a..71a5c5a 100644
11985 --- a/arch/um/Makefile
11986 +++ b/arch/um/Makefile
11987 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11988 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11989 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11990
11991 +ifdef CONSTIFY_PLUGIN
11992 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11993 +endif
11994 +
11995 #This will adjust *FLAGS accordingly to the platform.
11996 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11997
11998 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11999 index 19e1bdd..3665b77 100644
12000 --- a/arch/um/include/asm/cache.h
12001 +++ b/arch/um/include/asm/cache.h
12002 @@ -1,6 +1,7 @@
12003 #ifndef __UM_CACHE_H
12004 #define __UM_CACHE_H
12005
12006 +#include <linux/const.h>
12007
12008 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12009 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12010 @@ -12,6 +13,6 @@
12011 # define L1_CACHE_SHIFT 5
12012 #endif
12013
12014 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12015 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12016
12017 #endif
12018 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12019 index 2e0a6b1..a64d0f5 100644
12020 --- a/arch/um/include/asm/kmap_types.h
12021 +++ b/arch/um/include/asm/kmap_types.h
12022 @@ -8,6 +8,6 @@
12023
12024 /* No more #include "asm/arch/kmap_types.h" ! */
12025
12026 -#define KM_TYPE_NR 14
12027 +#define KM_TYPE_NR 15
12028
12029 #endif
12030 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12031 index 5ff53d9..5850cdf 100644
12032 --- a/arch/um/include/asm/page.h
12033 +++ b/arch/um/include/asm/page.h
12034 @@ -14,6 +14,9 @@
12035 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12036 #define PAGE_MASK (~(PAGE_SIZE-1))
12037
12038 +#define ktla_ktva(addr) (addr)
12039 +#define ktva_ktla(addr) (addr)
12040 +
12041 #ifndef __ASSEMBLY__
12042
12043 struct page;
12044 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12045 index 0032f92..cd151e0 100644
12046 --- a/arch/um/include/asm/pgtable-3level.h
12047 +++ b/arch/um/include/asm/pgtable-3level.h
12048 @@ -58,6 +58,7 @@
12049 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12050 #define pud_populate(mm, pud, pmd) \
12051 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12052 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12053
12054 #ifdef CONFIG_64BIT
12055 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12056 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12057 index eecc414..48adb87 100644
12058 --- a/arch/um/kernel/process.c
12059 +++ b/arch/um/kernel/process.c
12060 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12061 return 2;
12062 }
12063
12064 -/*
12065 - * Only x86 and x86_64 have an arch_align_stack().
12066 - * All other arches have "#define arch_align_stack(x) (x)"
12067 - * in their asm/system.h
12068 - * As this is included in UML from asm-um/system-generic.h,
12069 - * we can use it to behave as the subarch does.
12070 - */
12071 -#ifndef arch_align_stack
12072 -unsigned long arch_align_stack(unsigned long sp)
12073 -{
12074 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12075 - sp -= get_random_int() % 8192;
12076 - return sp & ~0xf;
12077 -}
12078 -#endif
12079 -
12080 unsigned long get_wchan(struct task_struct *p)
12081 {
12082 unsigned long stack_page, sp, ip;
12083 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12084 index ad8f795..2c7eec6 100644
12085 --- a/arch/unicore32/include/asm/cache.h
12086 +++ b/arch/unicore32/include/asm/cache.h
12087 @@ -12,8 +12,10 @@
12088 #ifndef __UNICORE_CACHE_H__
12089 #define __UNICORE_CACHE_H__
12090
12091 -#define L1_CACHE_SHIFT (5)
12092 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12093 +#include <linux/const.h>
12094 +
12095 +#define L1_CACHE_SHIFT 5
12096 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12097
12098 /*
12099 * Memory returned by kmalloc() may be used for DMA, so we must make
12100 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12101 index 0af5250..59f9597 100644
12102 --- a/arch/x86/Kconfig
12103 +++ b/arch/x86/Kconfig
12104 @@ -126,7 +126,7 @@ config X86
12105 select RTC_LIB
12106 select HAVE_DEBUG_STACKOVERFLOW
12107 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12108 - select HAVE_CC_STACKPROTECTOR
12109 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12110
12111 config INSTRUCTION_DECODER
12112 def_bool y
12113 @@ -251,7 +251,7 @@ config X86_HT
12114
12115 config X86_32_LAZY_GS
12116 def_bool y
12117 - depends on X86_32 && !CC_STACKPROTECTOR
12118 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12119
12120 config ARCH_HWEIGHT_CFLAGS
12121 string
12122 @@ -589,6 +589,7 @@ config SCHED_OMIT_FRAME_POINTER
12123
12124 menuconfig HYPERVISOR_GUEST
12125 bool "Linux guest support"
12126 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12127 ---help---
12128 Say Y here to enable options for running Linux under various hyper-
12129 visors. This option enables basic hypervisor detection and platform
12130 @@ -1111,7 +1112,7 @@ choice
12131
12132 config NOHIGHMEM
12133 bool "off"
12134 - depends on !X86_NUMAQ
12135 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12136 ---help---
12137 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12138 However, the address space of 32-bit x86 processors is only 4
12139 @@ -1148,7 +1149,7 @@ config NOHIGHMEM
12140
12141 config HIGHMEM4G
12142 bool "4GB"
12143 - depends on !X86_NUMAQ
12144 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12145 ---help---
12146 Select this if you have a 32-bit processor and between 1 and 4
12147 gigabytes of physical RAM.
12148 @@ -1201,7 +1202,7 @@ config PAGE_OFFSET
12149 hex
12150 default 0xB0000000 if VMSPLIT_3G_OPT
12151 default 0x80000000 if VMSPLIT_2G
12152 - default 0x78000000 if VMSPLIT_2G_OPT
12153 + default 0x70000000 if VMSPLIT_2G_OPT
12154 default 0x40000000 if VMSPLIT_1G
12155 default 0xC0000000
12156 depends on X86_32
12157 @@ -1605,6 +1606,7 @@ source kernel/Kconfig.hz
12158
12159 config KEXEC
12160 bool "kexec system call"
12161 + depends on !GRKERNSEC_KMEM
12162 ---help---
12163 kexec is a system call that implements the ability to shutdown your
12164 current kernel, and to start another kernel. It is like a reboot
12165 @@ -1756,7 +1758,9 @@ config X86_NEED_RELOCS
12166
12167 config PHYSICAL_ALIGN
12168 hex "Alignment value to which kernel should be aligned"
12169 - default "0x200000"
12170 + default "0x1000000"
12171 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12172 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12173 range 0x2000 0x1000000 if X86_32
12174 range 0x200000 0x1000000 if X86_64
12175 ---help---
12176 @@ -1836,9 +1840,10 @@ config DEBUG_HOTPLUG_CPU0
12177 If unsure, say N.
12178
12179 config COMPAT_VDSO
12180 - def_bool y
12181 + def_bool n
12182 prompt "Compat VDSO support"
12183 depends on X86_32 || IA32_EMULATION
12184 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12185 ---help---
12186 Map the 32-bit VDSO to the predictable old-style address too.
12187
12188 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12189 index f3aaf23..a1d3c49 100644
12190 --- a/arch/x86/Kconfig.cpu
12191 +++ b/arch/x86/Kconfig.cpu
12192 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12193
12194 config X86_F00F_BUG
12195 def_bool y
12196 - depends on M586MMX || M586TSC || M586 || M486
12197 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12198
12199 config X86_INVD_BUG
12200 def_bool y
12201 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12202
12203 config X86_ALIGNMENT_16
12204 def_bool y
12205 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12206 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12207
12208 config X86_INTEL_USERCOPY
12209 def_bool y
12210 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12211 # generates cmov.
12212 config X86_CMOV
12213 def_bool y
12214 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12215 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12216
12217 config X86_MINIMUM_CPU_FAMILY
12218 int
12219 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12220 index 321a52c..3d51a5e 100644
12221 --- a/arch/x86/Kconfig.debug
12222 +++ b/arch/x86/Kconfig.debug
12223 @@ -84,7 +84,7 @@ config X86_PTDUMP
12224 config DEBUG_RODATA
12225 bool "Write protect kernel read-only data structures"
12226 default y
12227 - depends on DEBUG_KERNEL
12228 + depends on DEBUG_KERNEL && BROKEN
12229 ---help---
12230 Mark the kernel read-only data as write-protected in the pagetables,
12231 in order to catch accidental (and incorrect) writes to such const
12232 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
12233
12234 config DEBUG_SET_MODULE_RONX
12235 bool "Set loadable kernel module data as NX and text as RO"
12236 - depends on MODULES
12237 + depends on MODULES && BROKEN
12238 ---help---
12239 This option helps catch unintended modifications to loadable
12240 kernel module's text and read-only data. It also prevents execution
12241 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12242 index eeda43a..5a238be 100644
12243 --- a/arch/x86/Makefile
12244 +++ b/arch/x86/Makefile
12245 @@ -71,14 +71,12 @@ ifeq ($(CONFIG_X86_32),y)
12246 # CPU-specific tuning. Anything which can be shared with UML should go here.
12247 include $(srctree)/arch/x86/Makefile_32.cpu
12248 KBUILD_CFLAGS += $(cflags-y)
12249 -
12250 - # temporary until string.h is fixed
12251 - KBUILD_CFLAGS += -ffreestanding
12252 else
12253 BITS := 64
12254 UTS_MACHINE := x86_64
12255 CHECKFLAGS += -D__x86_64__ -m64
12256
12257 + biarch := $(call cc-option,-m64)
12258 KBUILD_AFLAGS += -m64
12259 KBUILD_CFLAGS += -m64
12260
12261 @@ -111,6 +109,9 @@ else
12262 KBUILD_CFLAGS += -maccumulate-outgoing-args
12263 endif
12264
12265 +# temporary until string.h is fixed
12266 +KBUILD_CFLAGS += -ffreestanding
12267 +
12268 # Make sure compiler does not have buggy stack-protector support.
12269 ifdef CONFIG_CC_STACKPROTECTOR
12270 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12271 @@ -267,3 +268,12 @@ define archhelp
12272 echo ' FDINITRD=file initrd for the booted kernel'
12273 echo ' kvmconfig - Enable additional options for guest kernel support'
12274 endef
12275 +
12276 +define OLD_LD
12277 +
12278 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12279 +*** Please upgrade your binutils to 2.18 or newer
12280 +endef
12281 +
12282 +archprepare:
12283 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12284 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12285 index 878df7e..a803913 100644
12286 --- a/arch/x86/boot/Makefile
12287 +++ b/arch/x86/boot/Makefile
12288 @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12289 # ---------------------------------------------------------------------------
12290
12291 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12292 +ifdef CONSTIFY_PLUGIN
12293 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12294 +endif
12295 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12296 GCOV_PROFILE := n
12297
12298 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12299 index 878e4b9..20537ab 100644
12300 --- a/arch/x86/boot/bitops.h
12301 +++ b/arch/x86/boot/bitops.h
12302 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12303 u8 v;
12304 const u32 *p = (const u32 *)addr;
12305
12306 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12307 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12308 return v;
12309 }
12310
12311 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12312
12313 static inline void set_bit(int nr, void *addr)
12314 {
12315 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12316 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12317 }
12318
12319 #endif /* BOOT_BITOPS_H */
12320 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12321 index 50f8c5e..4f84fff 100644
12322 --- a/arch/x86/boot/boot.h
12323 +++ b/arch/x86/boot/boot.h
12324 @@ -84,7 +84,7 @@ static inline void io_delay(void)
12325 static inline u16 ds(void)
12326 {
12327 u16 seg;
12328 - asm("movw %%ds,%0" : "=rm" (seg));
12329 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12330 return seg;
12331 }
12332
12333 @@ -180,7 +180,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12334 static inline int memcmp(const void *s1, const void *s2, size_t len)
12335 {
12336 u8 diff;
12337 - asm("repe; cmpsb; setnz %0"
12338 + asm volatile("repe; cmpsb; setnz %0"
12339 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12340 return diff;
12341 }
12342 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12343 index 0fcd913..3bb5c42 100644
12344 --- a/arch/x86/boot/compressed/Makefile
12345 +++ b/arch/x86/boot/compressed/Makefile
12346 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12347 KBUILD_CFLAGS += -mno-mmx -mno-sse
12348 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12349 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12350 +ifdef CONSTIFY_PLUGIN
12351 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12352 +endif
12353
12354 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12355 GCOV_PROFILE := n
12356 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12357 index a53440e..c3dbf1e 100644
12358 --- a/arch/x86/boot/compressed/efi_stub_32.S
12359 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12360 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12361 * parameter 2, ..., param n. To make things easy, we save the return
12362 * address of efi_call_phys in a global variable.
12363 */
12364 - popl %ecx
12365 - movl %ecx, saved_return_addr(%edx)
12366 - /* get the function pointer into ECX*/
12367 - popl %ecx
12368 - movl %ecx, efi_rt_function_ptr(%edx)
12369 + popl saved_return_addr(%edx)
12370 + popl efi_rt_function_ptr(%edx)
12371
12372 /*
12373 * 3. Call the physical function.
12374 */
12375 - call *%ecx
12376 + call *efi_rt_function_ptr(%edx)
12377
12378 /*
12379 * 4. Balance the stack. And because EAX contain the return value,
12380 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12381 1: popl %edx
12382 subl $1b, %edx
12383
12384 - movl efi_rt_function_ptr(%edx), %ecx
12385 - pushl %ecx
12386 + pushl efi_rt_function_ptr(%edx)
12387
12388 /*
12389 * 10. Push the saved return address onto the stack and return.
12390 */
12391 - movl saved_return_addr(%edx), %ecx
12392 - pushl %ecx
12393 - ret
12394 + jmpl *saved_return_addr(%edx)
12395 ENDPROC(efi_call_phys)
12396 .previous
12397
12398 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12399 index 9116aac..abbcdb1 100644
12400 --- a/arch/x86/boot/compressed/head_32.S
12401 +++ b/arch/x86/boot/compressed/head_32.S
12402 @@ -117,10 +117,10 @@ preferred_addr:
12403 addl %eax, %ebx
12404 notl %eax
12405 andl %eax, %ebx
12406 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12407 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12408 jge 1f
12409 #endif
12410 - movl $LOAD_PHYSICAL_ADDR, %ebx
12411 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12412 1:
12413
12414 /* Target address to relocate to for decompression */
12415 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12416 index c5c1ae0..2e76d0e 100644
12417 --- a/arch/x86/boot/compressed/head_64.S
12418 +++ b/arch/x86/boot/compressed/head_64.S
12419 @@ -94,10 +94,10 @@ ENTRY(startup_32)
12420 addl %eax, %ebx
12421 notl %eax
12422 andl %eax, %ebx
12423 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12424 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12425 jge 1f
12426 #endif
12427 - movl $LOAD_PHYSICAL_ADDR, %ebx
12428 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12429 1:
12430
12431 /* Target address to relocate to for decompression */
12432 @@ -271,10 +271,10 @@ preferred_addr:
12433 addq %rax, %rbp
12434 notq %rax
12435 andq %rax, %rbp
12436 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
12437 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12438 jge 1f
12439 #endif
12440 - movq $LOAD_PHYSICAL_ADDR, %rbp
12441 + movq $____LOAD_PHYSICAL_ADDR, %rbp
12442 1:
12443
12444 /* Target address to relocate to for decompression */
12445 @@ -366,8 +366,8 @@ gdt:
12446 .long gdt
12447 .word 0
12448 .quad 0x0000000000000000 /* NULL descriptor */
12449 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12450 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12451 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12452 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12453 .quad 0x0080890000000000 /* TS descriptor */
12454 .quad 0x0000000000000000 /* TS continued */
12455 gdt_end:
12456 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12457 index 196eaf3..c96716d 100644
12458 --- a/arch/x86/boot/compressed/misc.c
12459 +++ b/arch/x86/boot/compressed/misc.c
12460 @@ -218,7 +218,7 @@ void __putstr(const char *s)
12461
12462 void *memset(void *s, int c, size_t n)
12463 {
12464 - int i;
12465 + size_t i;
12466 char *ss = s;
12467
12468 for (i = 0; i < n; i++)
12469 @@ -277,7 +277,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12470 * Calculate the delta between where vmlinux was linked to load
12471 * and where it was actually loaded.
12472 */
12473 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12474 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12475 if (!delta) {
12476 debug_putstr("No relocation needed... ");
12477 return;
12478 @@ -347,7 +347,7 @@ static void parse_elf(void *output)
12479 Elf32_Ehdr ehdr;
12480 Elf32_Phdr *phdrs, *phdr;
12481 #endif
12482 - void *dest;
12483 + void *dest, *prev;
12484 int i;
12485
12486 memcpy(&ehdr, output, sizeof(ehdr));
12487 @@ -374,13 +374,16 @@ static void parse_elf(void *output)
12488 case PT_LOAD:
12489 #ifdef CONFIG_RELOCATABLE
12490 dest = output;
12491 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12492 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12493 #else
12494 dest = (void *)(phdr->p_paddr);
12495 #endif
12496 memcpy(dest,
12497 output + phdr->p_offset,
12498 phdr->p_filesz);
12499 + if (i)
12500 + memset(prev, 0xff, dest - prev);
12501 + prev = dest + phdr->p_filesz;
12502 break;
12503 default: /* Ignore other PT_* */ break;
12504 }
12505 @@ -430,7 +433,7 @@ asmlinkage void *decompress_kernel(void *rmode, memptr heap,
12506 error("Destination address too large");
12507 #endif
12508 #ifndef CONFIG_RELOCATABLE
12509 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12510 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12511 error("Wrong destination address");
12512 #endif
12513
12514 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12515 index 100a9a1..bb3bdb0 100644
12516 --- a/arch/x86/boot/cpucheck.c
12517 +++ b/arch/x86/boot/cpucheck.c
12518 @@ -117,9 +117,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12519 u32 ecx = MSR_K7_HWCR;
12520 u32 eax, edx;
12521
12522 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12523 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12524 eax &= ~(1 << 15);
12525 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12526 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12527
12528 get_cpuflags(); /* Make sure it really did something */
12529 err = check_cpuflags();
12530 @@ -132,9 +132,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12531 u32 ecx = MSR_VIA_FCR;
12532 u32 eax, edx;
12533
12534 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12535 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12536 eax |= (1<<1)|(1<<7);
12537 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12538 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12539
12540 set_bit(X86_FEATURE_CX8, cpu.flags);
12541 err = check_cpuflags();
12542 @@ -145,12 +145,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12543 u32 eax, edx;
12544 u32 level = 1;
12545
12546 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12547 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12548 - asm("cpuid"
12549 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12550 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12551 + asm volatile("cpuid"
12552 : "+a" (level), "=d" (cpu.flags[0])
12553 : : "ecx", "ebx");
12554 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12555 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12556
12557 err = check_cpuflags();
12558 }
12559 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12560 index ec3b8ba..6a0db1f 100644
12561 --- a/arch/x86/boot/header.S
12562 +++ b/arch/x86/boot/header.S
12563 @@ -416,10 +416,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12564 # single linked list of
12565 # struct setup_data
12566
12567 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12568 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12569
12570 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12571 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12572 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12573 +#else
12574 #define VO_INIT_SIZE (VO__end - VO__text)
12575 +#endif
12576 #if ZO_INIT_SIZE > VO_INIT_SIZE
12577 #define INIT_SIZE ZO_INIT_SIZE
12578 #else
12579 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12580 index db75d07..8e6d0af 100644
12581 --- a/arch/x86/boot/memory.c
12582 +++ b/arch/x86/boot/memory.c
12583 @@ -19,7 +19,7 @@
12584
12585 static int detect_memory_e820(void)
12586 {
12587 - int count = 0;
12588 + unsigned int count = 0;
12589 struct biosregs ireg, oreg;
12590 struct e820entry *desc = boot_params.e820_map;
12591 static struct e820entry buf; /* static so it is zeroed */
12592 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12593 index 11e8c6e..fdbb1ed 100644
12594 --- a/arch/x86/boot/video-vesa.c
12595 +++ b/arch/x86/boot/video-vesa.c
12596 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12597
12598 boot_params.screen_info.vesapm_seg = oreg.es;
12599 boot_params.screen_info.vesapm_off = oreg.di;
12600 + boot_params.screen_info.vesapm_size = oreg.cx;
12601 }
12602
12603 /*
12604 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12605 index 43eda28..5ab5fdb 100644
12606 --- a/arch/x86/boot/video.c
12607 +++ b/arch/x86/boot/video.c
12608 @@ -96,7 +96,7 @@ static void store_mode_params(void)
12609 static unsigned int get_entry(void)
12610 {
12611 char entry_buf[4];
12612 - int i, len = 0;
12613 + unsigned int i, len = 0;
12614 int key;
12615 unsigned int v;
12616
12617 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12618 index 9105655..41779c1 100644
12619 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
12620 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12621 @@ -8,6 +8,8 @@
12622 * including this sentence is retained in full.
12623 */
12624
12625 +#include <asm/alternative-asm.h>
12626 +
12627 .extern crypto_ft_tab
12628 .extern crypto_it_tab
12629 .extern crypto_fl_tab
12630 @@ -70,6 +72,8 @@
12631 je B192; \
12632 leaq 32(r9),r9;
12633
12634 +#define ret pax_force_retaddr; ret
12635 +
12636 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12637 movq r1,r2; \
12638 movq r3,r4; \
12639 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12640 index 477e9d7..c92c7d8 100644
12641 --- a/arch/x86/crypto/aesni-intel_asm.S
12642 +++ b/arch/x86/crypto/aesni-intel_asm.S
12643 @@ -31,6 +31,7 @@
12644
12645 #include <linux/linkage.h>
12646 #include <asm/inst.h>
12647 +#include <asm/alternative-asm.h>
12648
12649 #ifdef __x86_64__
12650 .data
12651 @@ -205,7 +206,7 @@ enc: .octa 0x2
12652 * num_initial_blocks = b mod 4
12653 * encrypt the initial num_initial_blocks blocks and apply ghash on
12654 * the ciphertext
12655 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12656 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12657 * are clobbered
12658 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12659 */
12660 @@ -214,8 +215,8 @@ enc: .octa 0x2
12661 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12662 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12663 mov arg7, %r10 # %r10 = AAD
12664 - mov arg8, %r12 # %r12 = aadLen
12665 - mov %r12, %r11
12666 + mov arg8, %r15 # %r15 = aadLen
12667 + mov %r15, %r11
12668 pxor %xmm\i, %xmm\i
12669 _get_AAD_loop\num_initial_blocks\operation:
12670 movd (%r10), \TMP1
12671 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12672 psrldq $4, %xmm\i
12673 pxor \TMP1, %xmm\i
12674 add $4, %r10
12675 - sub $4, %r12
12676 + sub $4, %r15
12677 jne _get_AAD_loop\num_initial_blocks\operation
12678 cmp $16, %r11
12679 je _get_AAD_loop2_done\num_initial_blocks\operation
12680 - mov $16, %r12
12681 + mov $16, %r15
12682 _get_AAD_loop2\num_initial_blocks\operation:
12683 psrldq $4, %xmm\i
12684 - sub $4, %r12
12685 - cmp %r11, %r12
12686 + sub $4, %r15
12687 + cmp %r11, %r15
12688 jne _get_AAD_loop2\num_initial_blocks\operation
12689 _get_AAD_loop2_done\num_initial_blocks\operation:
12690 movdqa SHUF_MASK(%rip), %xmm14
12691 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12692 * num_initial_blocks = b mod 4
12693 * encrypt the initial num_initial_blocks blocks and apply ghash on
12694 * the ciphertext
12695 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12696 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12697 * are clobbered
12698 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12699 */
12700 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12701 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12702 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12703 mov arg7, %r10 # %r10 = AAD
12704 - mov arg8, %r12 # %r12 = aadLen
12705 - mov %r12, %r11
12706 + mov arg8, %r15 # %r15 = aadLen
12707 + mov %r15, %r11
12708 pxor %xmm\i, %xmm\i
12709 _get_AAD_loop\num_initial_blocks\operation:
12710 movd (%r10), \TMP1
12711 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12712 psrldq $4, %xmm\i
12713 pxor \TMP1, %xmm\i
12714 add $4, %r10
12715 - sub $4, %r12
12716 + sub $4, %r15
12717 jne _get_AAD_loop\num_initial_blocks\operation
12718 cmp $16, %r11
12719 je _get_AAD_loop2_done\num_initial_blocks\operation
12720 - mov $16, %r12
12721 + mov $16, %r15
12722 _get_AAD_loop2\num_initial_blocks\operation:
12723 psrldq $4, %xmm\i
12724 - sub $4, %r12
12725 - cmp %r11, %r12
12726 + sub $4, %r15
12727 + cmp %r11, %r15
12728 jne _get_AAD_loop2\num_initial_blocks\operation
12729 _get_AAD_loop2_done\num_initial_blocks\operation:
12730 movdqa SHUF_MASK(%rip), %xmm14
12731 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12732 *
12733 *****************************************************************************/
12734 ENTRY(aesni_gcm_dec)
12735 - push %r12
12736 + push %r15
12737 push %r13
12738 push %r14
12739 mov %rsp, %r14
12740 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12741 */
12742 sub $VARIABLE_OFFSET, %rsp
12743 and $~63, %rsp # align rsp to 64 bytes
12744 - mov %arg6, %r12
12745 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
12746 + mov %arg6, %r15
12747 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
12748 movdqa SHUF_MASK(%rip), %xmm2
12749 PSHUFB_XMM %xmm2, %xmm13
12750
12751 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12752 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12753 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12754 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12755 - mov %r13, %r12
12756 - and $(3<<4), %r12
12757 + mov %r13, %r15
12758 + and $(3<<4), %r15
12759 jz _initial_num_blocks_is_0_decrypt
12760 - cmp $(2<<4), %r12
12761 + cmp $(2<<4), %r15
12762 jb _initial_num_blocks_is_1_decrypt
12763 je _initial_num_blocks_is_2_decrypt
12764 _initial_num_blocks_is_3_decrypt:
12765 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12766 sub $16, %r11
12767 add %r13, %r11
12768 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12769 - lea SHIFT_MASK+16(%rip), %r12
12770 - sub %r13, %r12
12771 + lea SHIFT_MASK+16(%rip), %r15
12772 + sub %r13, %r15
12773 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12774 # (%r13 is the number of bytes in plaintext mod 16)
12775 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12776 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12777 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12778
12779 movdqa %xmm1, %xmm2
12780 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12781 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12782 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12783 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12784 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12785 pand %xmm1, %xmm2
12786 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12787 sub $1, %r13
12788 jne _less_than_8_bytes_left_decrypt
12789 _multiple_of_16_bytes_decrypt:
12790 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
12791 - shl $3, %r12 # convert into number of bits
12792 - movd %r12d, %xmm15 # len(A) in %xmm15
12793 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
12794 + shl $3, %r15 # convert into number of bits
12795 + movd %r15d, %xmm15 # len(A) in %xmm15
12796 shl $3, %arg4 # len(C) in bits (*128)
12797 MOVQ_R64_XMM %arg4, %xmm1
12798 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12799 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12800 mov %r14, %rsp
12801 pop %r14
12802 pop %r13
12803 - pop %r12
12804 + pop %r15
12805 + pax_force_retaddr
12806 ret
12807 ENDPROC(aesni_gcm_dec)
12808
12809 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12810 * poly = x^128 + x^127 + x^126 + x^121 + 1
12811 ***************************************************************************/
12812 ENTRY(aesni_gcm_enc)
12813 - push %r12
12814 + push %r15
12815 push %r13
12816 push %r14
12817 mov %rsp, %r14
12818 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12819 #
12820 sub $VARIABLE_OFFSET, %rsp
12821 and $~63, %rsp
12822 - mov %arg6, %r12
12823 - movdqu (%r12), %xmm13
12824 + mov %arg6, %r15
12825 + movdqu (%r15), %xmm13
12826 movdqa SHUF_MASK(%rip), %xmm2
12827 PSHUFB_XMM %xmm2, %xmm13
12828
12829 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12830 movdqa %xmm13, HashKey(%rsp)
12831 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12832 and $-16, %r13
12833 - mov %r13, %r12
12834 + mov %r13, %r15
12835
12836 # Encrypt first few blocks
12837
12838 - and $(3<<4), %r12
12839 + and $(3<<4), %r15
12840 jz _initial_num_blocks_is_0_encrypt
12841 - cmp $(2<<4), %r12
12842 + cmp $(2<<4), %r15
12843 jb _initial_num_blocks_is_1_encrypt
12844 je _initial_num_blocks_is_2_encrypt
12845 _initial_num_blocks_is_3_encrypt:
12846 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12847 sub $16, %r11
12848 add %r13, %r11
12849 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12850 - lea SHIFT_MASK+16(%rip), %r12
12851 - sub %r13, %r12
12852 + lea SHIFT_MASK+16(%rip), %r15
12853 + sub %r13, %r15
12854 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12855 # (%r13 is the number of bytes in plaintext mod 16)
12856 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12857 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12858 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12859 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12860 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12861 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12862 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12863 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12864 movdqa SHUF_MASK(%rip), %xmm10
12865 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12866 sub $1, %r13
12867 jne _less_than_8_bytes_left_encrypt
12868 _multiple_of_16_bytes_encrypt:
12869 - mov arg8, %r12 # %r12 = addLen (number of bytes)
12870 - shl $3, %r12
12871 - movd %r12d, %xmm15 # len(A) in %xmm15
12872 + mov arg8, %r15 # %r15 = addLen (number of bytes)
12873 + shl $3, %r15
12874 + movd %r15d, %xmm15 # len(A) in %xmm15
12875 shl $3, %arg4 # len(C) in bits (*128)
12876 MOVQ_R64_XMM %arg4, %xmm1
12877 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12878 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12879 mov %r14, %rsp
12880 pop %r14
12881 pop %r13
12882 - pop %r12
12883 + pop %r15
12884 + pax_force_retaddr
12885 ret
12886 ENDPROC(aesni_gcm_enc)
12887
12888 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
12889 pxor %xmm1, %xmm0
12890 movaps %xmm0, (TKEYP)
12891 add $0x10, TKEYP
12892 + pax_force_retaddr
12893 ret
12894 ENDPROC(_key_expansion_128)
12895 ENDPROC(_key_expansion_256a)
12896 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
12897 shufps $0b01001110, %xmm2, %xmm1
12898 movaps %xmm1, 0x10(TKEYP)
12899 add $0x20, TKEYP
12900 + pax_force_retaddr
12901 ret
12902 ENDPROC(_key_expansion_192a)
12903
12904 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
12905
12906 movaps %xmm0, (TKEYP)
12907 add $0x10, TKEYP
12908 + pax_force_retaddr
12909 ret
12910 ENDPROC(_key_expansion_192b)
12911
12912 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
12913 pxor %xmm1, %xmm2
12914 movaps %xmm2, (TKEYP)
12915 add $0x10, TKEYP
12916 + pax_force_retaddr
12917 ret
12918 ENDPROC(_key_expansion_256b)
12919
12920 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12921 #ifndef __x86_64__
12922 popl KEYP
12923 #endif
12924 + pax_force_retaddr
12925 ret
12926 ENDPROC(aesni_set_key)
12927
12928 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12929 popl KLEN
12930 popl KEYP
12931 #endif
12932 + pax_force_retaddr
12933 ret
12934 ENDPROC(aesni_enc)
12935
12936 @@ -1974,6 +1983,7 @@ _aesni_enc1:
12937 AESENC KEY STATE
12938 movaps 0x70(TKEYP), KEY
12939 AESENCLAST KEY STATE
12940 + pax_force_retaddr
12941 ret
12942 ENDPROC(_aesni_enc1)
12943
12944 @@ -2083,6 +2093,7 @@ _aesni_enc4:
12945 AESENCLAST KEY STATE2
12946 AESENCLAST KEY STATE3
12947 AESENCLAST KEY STATE4
12948 + pax_force_retaddr
12949 ret
12950 ENDPROC(_aesni_enc4)
12951
12952 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12953 popl KLEN
12954 popl KEYP
12955 #endif
12956 + pax_force_retaddr
12957 ret
12958 ENDPROC(aesni_dec)
12959
12960 @@ -2164,6 +2176,7 @@ _aesni_dec1:
12961 AESDEC KEY STATE
12962 movaps 0x70(TKEYP), KEY
12963 AESDECLAST KEY STATE
12964 + pax_force_retaddr
12965 ret
12966 ENDPROC(_aesni_dec1)
12967
12968 @@ -2273,6 +2286,7 @@ _aesni_dec4:
12969 AESDECLAST KEY STATE2
12970 AESDECLAST KEY STATE3
12971 AESDECLAST KEY STATE4
12972 + pax_force_retaddr
12973 ret
12974 ENDPROC(_aesni_dec4)
12975
12976 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12977 popl KEYP
12978 popl LEN
12979 #endif
12980 + pax_force_retaddr
12981 ret
12982 ENDPROC(aesni_ecb_enc)
12983
12984 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12985 popl KEYP
12986 popl LEN
12987 #endif
12988 + pax_force_retaddr
12989 ret
12990 ENDPROC(aesni_ecb_dec)
12991
12992 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12993 popl LEN
12994 popl IVP
12995 #endif
12996 + pax_force_retaddr
12997 ret
12998 ENDPROC(aesni_cbc_enc)
12999
13000 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13001 popl LEN
13002 popl IVP
13003 #endif
13004 + pax_force_retaddr
13005 ret
13006 ENDPROC(aesni_cbc_dec)
13007
13008 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13009 mov $1, TCTR_LOW
13010 MOVQ_R64_XMM TCTR_LOW INC
13011 MOVQ_R64_XMM CTR TCTR_LOW
13012 + pax_force_retaddr
13013 ret
13014 ENDPROC(_aesni_inc_init)
13015
13016 @@ -2579,6 +2598,7 @@ _aesni_inc:
13017 .Linc_low:
13018 movaps CTR, IV
13019 PSHUFB_XMM BSWAP_MASK IV
13020 + pax_force_retaddr
13021 ret
13022 ENDPROC(_aesni_inc)
13023
13024 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13025 .Lctr_enc_ret:
13026 movups IV, (IVP)
13027 .Lctr_enc_just_ret:
13028 + pax_force_retaddr
13029 ret
13030 ENDPROC(aesni_ctr_enc)
13031
13032 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13033 pxor INC, STATE4
13034 movdqu STATE4, 0x70(OUTP)
13035
13036 + pax_force_retaddr
13037 ret
13038 ENDPROC(aesni_xts_crypt8)
13039
13040 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13041 index 246c670..466e2d6 100644
13042 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13043 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13044 @@ -21,6 +21,7 @@
13045 */
13046
13047 #include <linux/linkage.h>
13048 +#include <asm/alternative-asm.h>
13049
13050 .file "blowfish-x86_64-asm.S"
13051 .text
13052 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13053 jnz .L__enc_xor;
13054
13055 write_block();
13056 + pax_force_retaddr
13057 ret;
13058 .L__enc_xor:
13059 xor_block();
13060 + pax_force_retaddr
13061 ret;
13062 ENDPROC(__blowfish_enc_blk)
13063
13064 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13065
13066 movq %r11, %rbp;
13067
13068 + pax_force_retaddr
13069 ret;
13070 ENDPROC(blowfish_dec_blk)
13071
13072 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13073
13074 popq %rbx;
13075 popq %rbp;
13076 + pax_force_retaddr
13077 ret;
13078
13079 .L__enc_xor4:
13080 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13081
13082 popq %rbx;
13083 popq %rbp;
13084 + pax_force_retaddr
13085 ret;
13086 ENDPROC(__blowfish_enc_blk_4way)
13087
13088 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13089 popq %rbx;
13090 popq %rbp;
13091
13092 + pax_force_retaddr
13093 ret;
13094 ENDPROC(blowfish_dec_blk_4way)
13095 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13096 index ce71f92..1dce7ec 100644
13097 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13098 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13099 @@ -16,6 +16,7 @@
13100 */
13101
13102 #include <linux/linkage.h>
13103 +#include <asm/alternative-asm.h>
13104
13105 #define CAMELLIA_TABLE_BYTE_LEN 272
13106
13107 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13108 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13109 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13110 %rcx, (%r9));
13111 + pax_force_retaddr
13112 ret;
13113 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13114
13115 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13116 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13117 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13118 %rax, (%r9));
13119 + pax_force_retaddr
13120 ret;
13121 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13122
13123 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13124 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13125 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13126
13127 + pax_force_retaddr
13128 ret;
13129
13130 .align 8
13131 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13132 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13133 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13134
13135 + pax_force_retaddr
13136 ret;
13137
13138 .align 8
13139 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13140 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13141 %xmm8, %rsi);
13142
13143 + pax_force_retaddr
13144 ret;
13145 ENDPROC(camellia_ecb_enc_16way)
13146
13147 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13148 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13149 %xmm8, %rsi);
13150
13151 + pax_force_retaddr
13152 ret;
13153 ENDPROC(camellia_ecb_dec_16way)
13154
13155 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13156 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13157 %xmm8, %rsi);
13158
13159 + pax_force_retaddr
13160 ret;
13161 ENDPROC(camellia_cbc_dec_16way)
13162
13163 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13164 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13165 %xmm8, %rsi);
13166
13167 + pax_force_retaddr
13168 ret;
13169 ENDPROC(camellia_ctr_16way)
13170
13171 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13172 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13173 %xmm8, %rsi);
13174
13175 + pax_force_retaddr
13176 ret;
13177 ENDPROC(camellia_xts_crypt_16way)
13178
13179 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13180 index 0e0b886..5a3123c 100644
13181 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13182 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13183 @@ -11,6 +11,7 @@
13184 */
13185
13186 #include <linux/linkage.h>
13187 +#include <asm/alternative-asm.h>
13188
13189 #define CAMELLIA_TABLE_BYTE_LEN 272
13190
13191 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13192 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13193 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13194 %rcx, (%r9));
13195 + pax_force_retaddr
13196 ret;
13197 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13198
13199 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13200 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13201 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13202 %rax, (%r9));
13203 + pax_force_retaddr
13204 ret;
13205 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13206
13207 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13208 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13209 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13210
13211 + pax_force_retaddr
13212 ret;
13213
13214 .align 8
13215 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13216 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13217 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13218
13219 + pax_force_retaddr
13220 ret;
13221
13222 .align 8
13223 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13224
13225 vzeroupper;
13226
13227 + pax_force_retaddr
13228 ret;
13229 ENDPROC(camellia_ecb_enc_32way)
13230
13231 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13232
13233 vzeroupper;
13234
13235 + pax_force_retaddr
13236 ret;
13237 ENDPROC(camellia_ecb_dec_32way)
13238
13239 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13240
13241 vzeroupper;
13242
13243 + pax_force_retaddr
13244 ret;
13245 ENDPROC(camellia_cbc_dec_32way)
13246
13247 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13248
13249 vzeroupper;
13250
13251 + pax_force_retaddr
13252 ret;
13253 ENDPROC(camellia_ctr_32way)
13254
13255 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13256
13257 vzeroupper;
13258
13259 + pax_force_retaddr
13260 ret;
13261 ENDPROC(camellia_xts_crypt_32way)
13262
13263 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13264 index 310319c..db3d7b5 100644
13265 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13266 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13267 @@ -21,6 +21,7 @@
13268 */
13269
13270 #include <linux/linkage.h>
13271 +#include <asm/alternative-asm.h>
13272
13273 .file "camellia-x86_64-asm_64.S"
13274 .text
13275 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13276 enc_outunpack(mov, RT1);
13277
13278 movq RRBP, %rbp;
13279 + pax_force_retaddr
13280 ret;
13281
13282 .L__enc_xor:
13283 enc_outunpack(xor, RT1);
13284
13285 movq RRBP, %rbp;
13286 + pax_force_retaddr
13287 ret;
13288 ENDPROC(__camellia_enc_blk)
13289
13290 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13291 dec_outunpack();
13292
13293 movq RRBP, %rbp;
13294 + pax_force_retaddr
13295 ret;
13296 ENDPROC(camellia_dec_blk)
13297
13298 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13299
13300 movq RRBP, %rbp;
13301 popq %rbx;
13302 + pax_force_retaddr
13303 ret;
13304
13305 .L__enc2_xor:
13306 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13307
13308 movq RRBP, %rbp;
13309 popq %rbx;
13310 + pax_force_retaddr
13311 ret;
13312 ENDPROC(__camellia_enc_blk_2way)
13313
13314 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13315
13316 movq RRBP, %rbp;
13317 movq RXOR, %rbx;
13318 + pax_force_retaddr
13319 ret;
13320 ENDPROC(camellia_dec_blk_2way)
13321 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13322 index c35fd5d..2d8c7db 100644
13323 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13324 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13325 @@ -24,6 +24,7 @@
13326 */
13327
13328 #include <linux/linkage.h>
13329 +#include <asm/alternative-asm.h>
13330
13331 .file "cast5-avx-x86_64-asm_64.S"
13332
13333 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13334 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13335 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13336
13337 + pax_force_retaddr
13338 ret;
13339 ENDPROC(__cast5_enc_blk16)
13340
13341 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13342 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13343 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13344
13345 + pax_force_retaddr
13346 ret;
13347
13348 .L__skip_dec:
13349 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13350 vmovdqu RR4, (6*4*4)(%r11);
13351 vmovdqu RL4, (7*4*4)(%r11);
13352
13353 + pax_force_retaddr
13354 ret;
13355 ENDPROC(cast5_ecb_enc_16way)
13356
13357 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13358 vmovdqu RR4, (6*4*4)(%r11);
13359 vmovdqu RL4, (7*4*4)(%r11);
13360
13361 + pax_force_retaddr
13362 ret;
13363 ENDPROC(cast5_ecb_dec_16way)
13364
13365 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13366 * %rdx: src
13367 */
13368
13369 - pushq %r12;
13370 + pushq %r14;
13371
13372 movq %rsi, %r11;
13373 - movq %rdx, %r12;
13374 + movq %rdx, %r14;
13375
13376 vmovdqu (0*16)(%rdx), RL1;
13377 vmovdqu (1*16)(%rdx), RR1;
13378 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13379 call __cast5_dec_blk16;
13380
13381 /* xor with src */
13382 - vmovq (%r12), RX;
13383 + vmovq (%r14), RX;
13384 vpshufd $0x4f, RX, RX;
13385 vpxor RX, RR1, RR1;
13386 - vpxor 0*16+8(%r12), RL1, RL1;
13387 - vpxor 1*16+8(%r12), RR2, RR2;
13388 - vpxor 2*16+8(%r12), RL2, RL2;
13389 - vpxor 3*16+8(%r12), RR3, RR3;
13390 - vpxor 4*16+8(%r12), RL3, RL3;
13391 - vpxor 5*16+8(%r12), RR4, RR4;
13392 - vpxor 6*16+8(%r12), RL4, RL4;
13393 + vpxor 0*16+8(%r14), RL1, RL1;
13394 + vpxor 1*16+8(%r14), RR2, RR2;
13395 + vpxor 2*16+8(%r14), RL2, RL2;
13396 + vpxor 3*16+8(%r14), RR3, RR3;
13397 + vpxor 4*16+8(%r14), RL3, RL3;
13398 + vpxor 5*16+8(%r14), RR4, RR4;
13399 + vpxor 6*16+8(%r14), RL4, RL4;
13400
13401 vmovdqu RR1, (0*16)(%r11);
13402 vmovdqu RL1, (1*16)(%r11);
13403 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13404 vmovdqu RR4, (6*16)(%r11);
13405 vmovdqu RL4, (7*16)(%r11);
13406
13407 - popq %r12;
13408 + popq %r14;
13409
13410 + pax_force_retaddr
13411 ret;
13412 ENDPROC(cast5_cbc_dec_16way)
13413
13414 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13415 * %rcx: iv (big endian, 64bit)
13416 */
13417
13418 - pushq %r12;
13419 + pushq %r14;
13420
13421 movq %rsi, %r11;
13422 - movq %rdx, %r12;
13423 + movq %rdx, %r14;
13424
13425 vpcmpeqd RTMP, RTMP, RTMP;
13426 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13427 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13428 call __cast5_enc_blk16;
13429
13430 /* dst = src ^ iv */
13431 - vpxor (0*16)(%r12), RR1, RR1;
13432 - vpxor (1*16)(%r12), RL1, RL1;
13433 - vpxor (2*16)(%r12), RR2, RR2;
13434 - vpxor (3*16)(%r12), RL2, RL2;
13435 - vpxor (4*16)(%r12), RR3, RR3;
13436 - vpxor (5*16)(%r12), RL3, RL3;
13437 - vpxor (6*16)(%r12), RR4, RR4;
13438 - vpxor (7*16)(%r12), RL4, RL4;
13439 + vpxor (0*16)(%r14), RR1, RR1;
13440 + vpxor (1*16)(%r14), RL1, RL1;
13441 + vpxor (2*16)(%r14), RR2, RR2;
13442 + vpxor (3*16)(%r14), RL2, RL2;
13443 + vpxor (4*16)(%r14), RR3, RR3;
13444 + vpxor (5*16)(%r14), RL3, RL3;
13445 + vpxor (6*16)(%r14), RR4, RR4;
13446 + vpxor (7*16)(%r14), RL4, RL4;
13447 vmovdqu RR1, (0*16)(%r11);
13448 vmovdqu RL1, (1*16)(%r11);
13449 vmovdqu RR2, (2*16)(%r11);
13450 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13451 vmovdqu RR4, (6*16)(%r11);
13452 vmovdqu RL4, (7*16)(%r11);
13453
13454 - popq %r12;
13455 + popq %r14;
13456
13457 + pax_force_retaddr
13458 ret;
13459 ENDPROC(cast5_ctr_16way)
13460 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13461 index e3531f8..e123f35 100644
13462 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13463 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13464 @@ -24,6 +24,7 @@
13465 */
13466
13467 #include <linux/linkage.h>
13468 +#include <asm/alternative-asm.h>
13469 #include "glue_helper-asm-avx.S"
13470
13471 .file "cast6-avx-x86_64-asm_64.S"
13472 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13473 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13474 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13475
13476 + pax_force_retaddr
13477 ret;
13478 ENDPROC(__cast6_enc_blk8)
13479
13480 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13481 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13482 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13483
13484 + pax_force_retaddr
13485 ret;
13486 ENDPROC(__cast6_dec_blk8)
13487
13488 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13489
13490 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13491
13492 + pax_force_retaddr
13493 ret;
13494 ENDPROC(cast6_ecb_enc_8way)
13495
13496 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13497
13498 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13499
13500 + pax_force_retaddr
13501 ret;
13502 ENDPROC(cast6_ecb_dec_8way)
13503
13504 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13505 * %rdx: src
13506 */
13507
13508 - pushq %r12;
13509 + pushq %r14;
13510
13511 movq %rsi, %r11;
13512 - movq %rdx, %r12;
13513 + movq %rdx, %r14;
13514
13515 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13516
13517 call __cast6_dec_blk8;
13518
13519 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13520 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13521
13522 - popq %r12;
13523 + popq %r14;
13524
13525 + pax_force_retaddr
13526 ret;
13527 ENDPROC(cast6_cbc_dec_8way)
13528
13529 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13530 * %rcx: iv (little endian, 128bit)
13531 */
13532
13533 - pushq %r12;
13534 + pushq %r14;
13535
13536 movq %rsi, %r11;
13537 - movq %rdx, %r12;
13538 + movq %rdx, %r14;
13539
13540 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13541 RD2, RX, RKR, RKM);
13542
13543 call __cast6_enc_blk8;
13544
13545 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13546 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13547
13548 - popq %r12;
13549 + popq %r14;
13550
13551 + pax_force_retaddr
13552 ret;
13553 ENDPROC(cast6_ctr_8way)
13554
13555 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13556 /* dst <= regs xor IVs(in dst) */
13557 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13558
13559 + pax_force_retaddr
13560 ret;
13561 ENDPROC(cast6_xts_enc_8way)
13562
13563 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13564 /* dst <= regs xor IVs(in dst) */
13565 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13566
13567 + pax_force_retaddr
13568 ret;
13569 ENDPROC(cast6_xts_dec_8way)
13570 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13571 index dbc4339..de6e120 100644
13572 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13573 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13574 @@ -45,6 +45,7 @@
13575
13576 #include <asm/inst.h>
13577 #include <linux/linkage.h>
13578 +#include <asm/alternative-asm.h>
13579
13580 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13581
13582 @@ -312,6 +313,7 @@ do_return:
13583 popq %rsi
13584 popq %rdi
13585 popq %rbx
13586 + pax_force_retaddr
13587 ret
13588
13589 ################################################################
13590 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13591 index 185fad4..ff4cd36 100644
13592 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13593 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13594 @@ -18,6 +18,7 @@
13595
13596 #include <linux/linkage.h>
13597 #include <asm/inst.h>
13598 +#include <asm/alternative-asm.h>
13599
13600 .data
13601
13602 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13603 psrlq $1, T2
13604 pxor T2, T1
13605 pxor T1, DATA
13606 + pax_force_retaddr
13607 ret
13608 ENDPROC(__clmul_gf128mul_ble)
13609
13610 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13611 call __clmul_gf128mul_ble
13612 PSHUFB_XMM BSWAP DATA
13613 movups DATA, (%rdi)
13614 + pax_force_retaddr
13615 ret
13616 ENDPROC(clmul_ghash_mul)
13617
13618 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
13619 PSHUFB_XMM BSWAP DATA
13620 movups DATA, (%rdi)
13621 .Lupdate_just_ret:
13622 + pax_force_retaddr
13623 ret
13624 ENDPROC(clmul_ghash_update)
13625 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13626 index 9279e0b..c4b3d2c 100644
13627 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13628 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13629 @@ -1,4 +1,5 @@
13630 #include <linux/linkage.h>
13631 +#include <asm/alternative-asm.h>
13632
13633 # enter salsa20_encrypt_bytes
13634 ENTRY(salsa20_encrypt_bytes)
13635 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13636 add %r11,%rsp
13637 mov %rdi,%rax
13638 mov %rsi,%rdx
13639 + pax_force_retaddr
13640 ret
13641 # bytesatleast65:
13642 ._bytesatleast65:
13643 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13644 add %r11,%rsp
13645 mov %rdi,%rax
13646 mov %rsi,%rdx
13647 + pax_force_retaddr
13648 ret
13649 ENDPROC(salsa20_keysetup)
13650
13651 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13652 add %r11,%rsp
13653 mov %rdi,%rax
13654 mov %rsi,%rdx
13655 + pax_force_retaddr
13656 ret
13657 ENDPROC(salsa20_ivsetup)
13658 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13659 index 2f202f4..d9164d6 100644
13660 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13661 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13662 @@ -24,6 +24,7 @@
13663 */
13664
13665 #include <linux/linkage.h>
13666 +#include <asm/alternative-asm.h>
13667 #include "glue_helper-asm-avx.S"
13668
13669 .file "serpent-avx-x86_64-asm_64.S"
13670 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13671 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13672 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13673
13674 + pax_force_retaddr
13675 ret;
13676 ENDPROC(__serpent_enc_blk8_avx)
13677
13678 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13679 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13680 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13681
13682 + pax_force_retaddr
13683 ret;
13684 ENDPROC(__serpent_dec_blk8_avx)
13685
13686 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13687
13688 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13689
13690 + pax_force_retaddr
13691 ret;
13692 ENDPROC(serpent_ecb_enc_8way_avx)
13693
13694 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13695
13696 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13697
13698 + pax_force_retaddr
13699 ret;
13700 ENDPROC(serpent_ecb_dec_8way_avx)
13701
13702 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13703
13704 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13705
13706 + pax_force_retaddr
13707 ret;
13708 ENDPROC(serpent_cbc_dec_8way_avx)
13709
13710 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13711
13712 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13713
13714 + pax_force_retaddr
13715 ret;
13716 ENDPROC(serpent_ctr_8way_avx)
13717
13718 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13719 /* dst <= regs xor IVs(in dst) */
13720 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13721
13722 + pax_force_retaddr
13723 ret;
13724 ENDPROC(serpent_xts_enc_8way_avx)
13725
13726 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13727 /* dst <= regs xor IVs(in dst) */
13728 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13729
13730 + pax_force_retaddr
13731 ret;
13732 ENDPROC(serpent_xts_dec_8way_avx)
13733 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13734 index b222085..abd483c 100644
13735 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
13736 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13737 @@ -15,6 +15,7 @@
13738 */
13739
13740 #include <linux/linkage.h>
13741 +#include <asm/alternative-asm.h>
13742 #include "glue_helper-asm-avx2.S"
13743
13744 .file "serpent-avx2-asm_64.S"
13745 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
13746 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13747 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13748
13749 + pax_force_retaddr
13750 ret;
13751 ENDPROC(__serpent_enc_blk16)
13752
13753 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
13754 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13755 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13756
13757 + pax_force_retaddr
13758 ret;
13759 ENDPROC(__serpent_dec_blk16)
13760
13761 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13762
13763 vzeroupper;
13764
13765 + pax_force_retaddr
13766 ret;
13767 ENDPROC(serpent_ecb_enc_16way)
13768
13769 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13770
13771 vzeroupper;
13772
13773 + pax_force_retaddr
13774 ret;
13775 ENDPROC(serpent_ecb_dec_16way)
13776
13777 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13778
13779 vzeroupper;
13780
13781 + pax_force_retaddr
13782 ret;
13783 ENDPROC(serpent_cbc_dec_16way)
13784
13785 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13786
13787 vzeroupper;
13788
13789 + pax_force_retaddr
13790 ret;
13791 ENDPROC(serpent_ctr_16way)
13792
13793 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13794
13795 vzeroupper;
13796
13797 + pax_force_retaddr
13798 ret;
13799 ENDPROC(serpent_xts_enc_16way)
13800
13801 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13802
13803 vzeroupper;
13804
13805 + pax_force_retaddr
13806 ret;
13807 ENDPROC(serpent_xts_dec_16way)
13808 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13809 index acc066c..1559cc4 100644
13810 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13811 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13812 @@ -25,6 +25,7 @@
13813 */
13814
13815 #include <linux/linkage.h>
13816 +#include <asm/alternative-asm.h>
13817
13818 .file "serpent-sse2-x86_64-asm_64.S"
13819 .text
13820 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13821 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13822 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13823
13824 + pax_force_retaddr
13825 ret;
13826
13827 .L__enc_xor8:
13828 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13829 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13830
13831 + pax_force_retaddr
13832 ret;
13833 ENDPROC(__serpent_enc_blk_8way)
13834
13835 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13836 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13837 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13838
13839 + pax_force_retaddr
13840 ret;
13841 ENDPROC(serpent_dec_blk_8way)
13842 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13843 index a410950..9dfe7ad 100644
13844 --- a/arch/x86/crypto/sha1_ssse3_asm.S
13845 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
13846 @@ -29,6 +29,7 @@
13847 */
13848
13849 #include <linux/linkage.h>
13850 +#include <asm/alternative-asm.h>
13851
13852 #define CTX %rdi // arg1
13853 #define BUF %rsi // arg2
13854 @@ -75,9 +76,9 @@
13855
13856 push %rbx
13857 push %rbp
13858 - push %r12
13859 + push %r14
13860
13861 - mov %rsp, %r12
13862 + mov %rsp, %r14
13863 sub $64, %rsp # allocate workspace
13864 and $~15, %rsp # align stack
13865
13866 @@ -99,11 +100,12 @@
13867 xor %rax, %rax
13868 rep stosq
13869
13870 - mov %r12, %rsp # deallocate workspace
13871 + mov %r14, %rsp # deallocate workspace
13872
13873 - pop %r12
13874 + pop %r14
13875 pop %rbp
13876 pop %rbx
13877 + pax_force_retaddr
13878 ret
13879
13880 ENDPROC(\name)
13881 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13882 index 642f156..51a513c 100644
13883 --- a/arch/x86/crypto/sha256-avx-asm.S
13884 +++ b/arch/x86/crypto/sha256-avx-asm.S
13885 @@ -49,6 +49,7 @@
13886
13887 #ifdef CONFIG_AS_AVX
13888 #include <linux/linkage.h>
13889 +#include <asm/alternative-asm.h>
13890
13891 ## assume buffers not aligned
13892 #define VMOVDQ vmovdqu
13893 @@ -460,6 +461,7 @@ done_hash:
13894 popq %r13
13895 popq %rbp
13896 popq %rbx
13897 + pax_force_retaddr
13898 ret
13899 ENDPROC(sha256_transform_avx)
13900
13901 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13902 index 9e86944..3795e6a 100644
13903 --- a/arch/x86/crypto/sha256-avx2-asm.S
13904 +++ b/arch/x86/crypto/sha256-avx2-asm.S
13905 @@ -50,6 +50,7 @@
13906
13907 #ifdef CONFIG_AS_AVX2
13908 #include <linux/linkage.h>
13909 +#include <asm/alternative-asm.h>
13910
13911 ## assume buffers not aligned
13912 #define VMOVDQ vmovdqu
13913 @@ -720,6 +721,7 @@ done_hash:
13914 popq %r12
13915 popq %rbp
13916 popq %rbx
13917 + pax_force_retaddr
13918 ret
13919 ENDPROC(sha256_transform_rorx)
13920
13921 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13922 index f833b74..8c62a9e 100644
13923 --- a/arch/x86/crypto/sha256-ssse3-asm.S
13924 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
13925 @@ -47,6 +47,7 @@
13926 ########################################################################
13927
13928 #include <linux/linkage.h>
13929 +#include <asm/alternative-asm.h>
13930
13931 ## assume buffers not aligned
13932 #define MOVDQ movdqu
13933 @@ -471,6 +472,7 @@ done_hash:
13934 popq %rbp
13935 popq %rbx
13936
13937 + pax_force_retaddr
13938 ret
13939 ENDPROC(sha256_transform_ssse3)
13940
13941 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13942 index 974dde9..a823ff9 100644
13943 --- a/arch/x86/crypto/sha512-avx-asm.S
13944 +++ b/arch/x86/crypto/sha512-avx-asm.S
13945 @@ -49,6 +49,7 @@
13946
13947 #ifdef CONFIG_AS_AVX
13948 #include <linux/linkage.h>
13949 +#include <asm/alternative-asm.h>
13950
13951 .text
13952
13953 @@ -364,6 +365,7 @@ updateblock:
13954 mov frame_RSPSAVE(%rsp), %rsp
13955
13956 nowork:
13957 + pax_force_retaddr
13958 ret
13959 ENDPROC(sha512_transform_avx)
13960
13961 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13962 index 568b961..ed20c37 100644
13963 --- a/arch/x86/crypto/sha512-avx2-asm.S
13964 +++ b/arch/x86/crypto/sha512-avx2-asm.S
13965 @@ -51,6 +51,7 @@
13966
13967 #ifdef CONFIG_AS_AVX2
13968 #include <linux/linkage.h>
13969 +#include <asm/alternative-asm.h>
13970
13971 .text
13972
13973 @@ -678,6 +679,7 @@ done_hash:
13974
13975 # Restore Stack Pointer
13976 mov frame_RSPSAVE(%rsp), %rsp
13977 + pax_force_retaddr
13978 ret
13979 ENDPROC(sha512_transform_rorx)
13980
13981 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13982 index fb56855..6edd768 100644
13983 --- a/arch/x86/crypto/sha512-ssse3-asm.S
13984 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
13985 @@ -48,6 +48,7 @@
13986 ########################################################################
13987
13988 #include <linux/linkage.h>
13989 +#include <asm/alternative-asm.h>
13990
13991 .text
13992
13993 @@ -363,6 +364,7 @@ updateblock:
13994 mov frame_RSPSAVE(%rsp), %rsp
13995
13996 nowork:
13997 + pax_force_retaddr
13998 ret
13999 ENDPROC(sha512_transform_ssse3)
14000
14001 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14002 index 0505813..b067311 100644
14003 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14004 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14005 @@ -24,6 +24,7 @@
14006 */
14007
14008 #include <linux/linkage.h>
14009 +#include <asm/alternative-asm.h>
14010 #include "glue_helper-asm-avx.S"
14011
14012 .file "twofish-avx-x86_64-asm_64.S"
14013 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14014 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14015 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14016
14017 + pax_force_retaddr
14018 ret;
14019 ENDPROC(__twofish_enc_blk8)
14020
14021 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14022 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14023 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14024
14025 + pax_force_retaddr
14026 ret;
14027 ENDPROC(__twofish_dec_blk8)
14028
14029 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14030
14031 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14032
14033 + pax_force_retaddr
14034 ret;
14035 ENDPROC(twofish_ecb_enc_8way)
14036
14037 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14038
14039 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14040
14041 + pax_force_retaddr
14042 ret;
14043 ENDPROC(twofish_ecb_dec_8way)
14044
14045 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14046 * %rdx: src
14047 */
14048
14049 - pushq %r12;
14050 + pushq %r14;
14051
14052 movq %rsi, %r11;
14053 - movq %rdx, %r12;
14054 + movq %rdx, %r14;
14055
14056 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14057
14058 call __twofish_dec_blk8;
14059
14060 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14061 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14062
14063 - popq %r12;
14064 + popq %r14;
14065
14066 + pax_force_retaddr
14067 ret;
14068 ENDPROC(twofish_cbc_dec_8way)
14069
14070 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14071 * %rcx: iv (little endian, 128bit)
14072 */
14073
14074 - pushq %r12;
14075 + pushq %r14;
14076
14077 movq %rsi, %r11;
14078 - movq %rdx, %r12;
14079 + movq %rdx, %r14;
14080
14081 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14082 RD2, RX0, RX1, RY0);
14083
14084 call __twofish_enc_blk8;
14085
14086 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14087 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14088
14089 - popq %r12;
14090 + popq %r14;
14091
14092 + pax_force_retaddr
14093 ret;
14094 ENDPROC(twofish_ctr_8way)
14095
14096 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14097 /* dst <= regs xor IVs(in dst) */
14098 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14099
14100 + pax_force_retaddr
14101 ret;
14102 ENDPROC(twofish_xts_enc_8way)
14103
14104 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14105 /* dst <= regs xor IVs(in dst) */
14106 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14107
14108 + pax_force_retaddr
14109 ret;
14110 ENDPROC(twofish_xts_dec_8way)
14111 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14112 index 1c3b7ce..02f578d 100644
14113 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14114 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14115 @@ -21,6 +21,7 @@
14116 */
14117
14118 #include <linux/linkage.h>
14119 +#include <asm/alternative-asm.h>
14120
14121 .file "twofish-x86_64-asm-3way.S"
14122 .text
14123 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14124 popq %r13;
14125 popq %r14;
14126 popq %r15;
14127 + pax_force_retaddr
14128 ret;
14129
14130 .L__enc_xor3:
14131 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14132 popq %r13;
14133 popq %r14;
14134 popq %r15;
14135 + pax_force_retaddr
14136 ret;
14137 ENDPROC(__twofish_enc_blk_3way)
14138
14139 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14140 popq %r13;
14141 popq %r14;
14142 popq %r15;
14143 + pax_force_retaddr
14144 ret;
14145 ENDPROC(twofish_dec_blk_3way)
14146 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14147 index a039d21..524b8b2 100644
14148 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14149 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14150 @@ -22,6 +22,7 @@
14151
14152 #include <linux/linkage.h>
14153 #include <asm/asm-offsets.h>
14154 +#include <asm/alternative-asm.h>
14155
14156 #define a_offset 0
14157 #define b_offset 4
14158 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14159
14160 popq R1
14161 movq $1,%rax
14162 + pax_force_retaddr
14163 ret
14164 ENDPROC(twofish_enc_blk)
14165
14166 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14167
14168 popq R1
14169 movq $1,%rax
14170 + pax_force_retaddr
14171 ret
14172 ENDPROC(twofish_dec_blk)
14173 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14174 index d21ff89..6da8e6e 100644
14175 --- a/arch/x86/ia32/ia32_aout.c
14176 +++ b/arch/x86/ia32/ia32_aout.c
14177 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14178 unsigned long dump_start, dump_size;
14179 struct user32 dump;
14180
14181 + memset(&dump, 0, sizeof(dump));
14182 +
14183 fs = get_fs();
14184 set_fs(KERNEL_DS);
14185 has_dumped = 1;
14186 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14187 index 2206757..85cbcfa 100644
14188 --- a/arch/x86/ia32/ia32_signal.c
14189 +++ b/arch/x86/ia32/ia32_signal.c
14190 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14191 if (__get_user(set.sig[0], &frame->sc.oldmask)
14192 || (_COMPAT_NSIG_WORDS > 1
14193 && __copy_from_user((((char *) &set.sig) + 4),
14194 - &frame->extramask,
14195 + frame->extramask,
14196 sizeof(frame->extramask))))
14197 goto badframe;
14198
14199 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14200 sp -= frame_size;
14201 /* Align the stack pointer according to the i386 ABI,
14202 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14203 - sp = ((sp + 4) & -16ul) - 4;
14204 + sp = ((sp - 12) & -16ul) - 4;
14205 return (void __user *) sp;
14206 }
14207
14208 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14209 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14210 sigreturn);
14211 else
14212 - restorer = &frame->retcode;
14213 + restorer = frame->retcode;
14214 }
14215
14216 put_user_try {
14217 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14218 * These are actually not used anymore, but left because some
14219 * gdb versions depend on them as a marker.
14220 */
14221 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14222 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14223 } put_user_catch(err);
14224
14225 if (err)
14226 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14227 0xb8,
14228 __NR_ia32_rt_sigreturn,
14229 0x80cd,
14230 - 0,
14231 + 0
14232 };
14233
14234 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14235 @@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14236
14237 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14238 restorer = ksig->ka.sa.sa_restorer;
14239 + else if (current->mm->context.vdso)
14240 + /* Return stub is in 32bit vsyscall page */
14241 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14242 else
14243 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14244 - rt_sigreturn);
14245 + restorer = frame->retcode;
14246 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14247
14248 /*
14249 * Not actually used anymore, but left because some gdb
14250 * versions need it.
14251 */
14252 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14253 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14254 } put_user_catch(err);
14255
14256 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14257 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14258 index 4299eb0..c0687a7 100644
14259 --- a/arch/x86/ia32/ia32entry.S
14260 +++ b/arch/x86/ia32/ia32entry.S
14261 @@ -15,8 +15,10 @@
14262 #include <asm/irqflags.h>
14263 #include <asm/asm.h>
14264 #include <asm/smap.h>
14265 +#include <asm/pgtable.h>
14266 #include <linux/linkage.h>
14267 #include <linux/err.h>
14268 +#include <asm/alternative-asm.h>
14269
14270 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14271 #include <linux/elf-em.h>
14272 @@ -62,12 +64,12 @@
14273 */
14274 .macro LOAD_ARGS32 offset, _r9=0
14275 .if \_r9
14276 - movl \offset+16(%rsp),%r9d
14277 + movl \offset+R9(%rsp),%r9d
14278 .endif
14279 - movl \offset+40(%rsp),%ecx
14280 - movl \offset+48(%rsp),%edx
14281 - movl \offset+56(%rsp),%esi
14282 - movl \offset+64(%rsp),%edi
14283 + movl \offset+RCX(%rsp),%ecx
14284 + movl \offset+RDX(%rsp),%edx
14285 + movl \offset+RSI(%rsp),%esi
14286 + movl \offset+RDI(%rsp),%edi
14287 movl %eax,%eax /* zero extension */
14288 .endm
14289
14290 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14291 ENDPROC(native_irq_enable_sysexit)
14292 #endif
14293
14294 + .macro pax_enter_kernel_user
14295 + pax_set_fptr_mask
14296 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14297 + call pax_enter_kernel_user
14298 +#endif
14299 + .endm
14300 +
14301 + .macro pax_exit_kernel_user
14302 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14303 + call pax_exit_kernel_user
14304 +#endif
14305 +#ifdef CONFIG_PAX_RANDKSTACK
14306 + pushq %rax
14307 + pushq %r11
14308 + call pax_randomize_kstack
14309 + popq %r11
14310 + popq %rax
14311 +#endif
14312 + .endm
14313 +
14314 + .macro pax_erase_kstack
14315 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14316 + call pax_erase_kstack
14317 +#endif
14318 + .endm
14319 +
14320 /*
14321 * 32bit SYSENTER instruction entry.
14322 *
14323 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14324 CFI_REGISTER rsp,rbp
14325 SWAPGS_UNSAFE_STACK
14326 movq PER_CPU_VAR(kernel_stack), %rsp
14327 - addq $(KERNEL_STACK_OFFSET),%rsp
14328 - /*
14329 - * No need to follow this irqs on/off section: the syscall
14330 - * disabled irqs, here we enable it straight after entry:
14331 - */
14332 - ENABLE_INTERRUPTS(CLBR_NONE)
14333 movl %ebp,%ebp /* zero extension */
14334 pushq_cfi $__USER32_DS
14335 /*CFI_REL_OFFSET ss,0*/
14336 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14337 CFI_REL_OFFSET rsp,0
14338 pushfq_cfi
14339 /*CFI_REL_OFFSET rflags,0*/
14340 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14341 - CFI_REGISTER rip,r10
14342 + orl $X86_EFLAGS_IF,(%rsp)
14343 + GET_THREAD_INFO(%r11)
14344 + movl TI_sysenter_return(%r11), %r11d
14345 + CFI_REGISTER rip,r11
14346 pushq_cfi $__USER32_CS
14347 /*CFI_REL_OFFSET cs,0*/
14348 movl %eax, %eax
14349 - pushq_cfi %r10
14350 + pushq_cfi %r11
14351 CFI_REL_OFFSET rip,0
14352 pushq_cfi %rax
14353 cld
14354 SAVE_ARGS 0,1,0
14355 + pax_enter_kernel_user
14356 +
14357 +#ifdef CONFIG_PAX_RANDKSTACK
14358 + pax_erase_kstack
14359 +#endif
14360 +
14361 + /*
14362 + * No need to follow this irqs on/off section: the syscall
14363 + * disabled irqs, here we enable it straight after entry:
14364 + */
14365 + ENABLE_INTERRUPTS(CLBR_NONE)
14366 /* no need to do an access_ok check here because rbp has been
14367 32bit zero extended */
14368 +
14369 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14370 + addq pax_user_shadow_base,%rbp
14371 + ASM_PAX_OPEN_USERLAND
14372 +#endif
14373 +
14374 ASM_STAC
14375 1: movl (%rbp),%ebp
14376 _ASM_EXTABLE(1b,ia32_badarg)
14377 ASM_CLAC
14378 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14379 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14380 +
14381 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14382 + ASM_PAX_CLOSE_USERLAND
14383 +#endif
14384 +
14385 + GET_THREAD_INFO(%r11)
14386 + orl $TS_COMPAT,TI_status(%r11)
14387 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14388 CFI_REMEMBER_STATE
14389 jnz sysenter_tracesys
14390 cmpq $(IA32_NR_syscalls-1),%rax
14391 @@ -162,15 +209,18 @@ sysenter_do_call:
14392 sysenter_dispatch:
14393 call *ia32_sys_call_table(,%rax,8)
14394 movq %rax,RAX-ARGOFFSET(%rsp)
14395 + GET_THREAD_INFO(%r11)
14396 DISABLE_INTERRUPTS(CLBR_NONE)
14397 TRACE_IRQS_OFF
14398 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14399 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14400 jnz sysexit_audit
14401 sysexit_from_sys_call:
14402 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14403 + pax_exit_kernel_user
14404 + pax_erase_kstack
14405 + andl $~TS_COMPAT,TI_status(%r11)
14406 /* clear IF, that popfq doesn't enable interrupts early */
14407 - andl $~0x200,EFLAGS-R11(%rsp)
14408 - movl RIP-R11(%rsp),%edx /* User %eip */
14409 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14410 + movl RIP(%rsp),%edx /* User %eip */
14411 CFI_REGISTER rip,rdx
14412 RESTORE_ARGS 0,24,0,0,0,0
14413 xorq %r8,%r8
14414 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
14415 movl %eax,%esi /* 2nd arg: syscall number */
14416 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14417 call __audit_syscall_entry
14418 +
14419 + pax_erase_kstack
14420 +
14421 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14422 cmpq $(IA32_NR_syscalls-1),%rax
14423 ja ia32_badsys
14424 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
14425 .endm
14426
14427 .macro auditsys_exit exit
14428 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14429 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14430 jnz ia32_ret_from_sys_call
14431 TRACE_IRQS_ON
14432 ENABLE_INTERRUPTS(CLBR_NONE)
14433 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
14434 1: setbe %al /* 1 if error, 0 if not */
14435 movzbl %al,%edi /* zero-extend that into %edi */
14436 call __audit_syscall_exit
14437 + GET_THREAD_INFO(%r11)
14438 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14439 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14440 DISABLE_INTERRUPTS(CLBR_NONE)
14441 TRACE_IRQS_OFF
14442 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14443 + testl %edi,TI_flags(%r11)
14444 jz \exit
14445 CLEAR_RREGS -ARGOFFSET
14446 jmp int_with_check
14447 @@ -237,7 +291,7 @@ sysexit_audit:
14448
14449 sysenter_tracesys:
14450 #ifdef CONFIG_AUDITSYSCALL
14451 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14452 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14453 jz sysenter_auditsys
14454 #endif
14455 SAVE_REST
14456 @@ -249,6 +303,9 @@ sysenter_tracesys:
14457 RESTORE_REST
14458 cmpq $(IA32_NR_syscalls-1),%rax
14459 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14460 +
14461 + pax_erase_kstack
14462 +
14463 jmp sysenter_do_call
14464 CFI_ENDPROC
14465 ENDPROC(ia32_sysenter_target)
14466 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14467 ENTRY(ia32_cstar_target)
14468 CFI_STARTPROC32 simple
14469 CFI_SIGNAL_FRAME
14470 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14471 + CFI_DEF_CFA rsp,0
14472 CFI_REGISTER rip,rcx
14473 /*CFI_REGISTER rflags,r11*/
14474 SWAPGS_UNSAFE_STACK
14475 movl %esp,%r8d
14476 CFI_REGISTER rsp,r8
14477 movq PER_CPU_VAR(kernel_stack),%rsp
14478 + SAVE_ARGS 8*6,0,0
14479 + pax_enter_kernel_user
14480 +
14481 +#ifdef CONFIG_PAX_RANDKSTACK
14482 + pax_erase_kstack
14483 +#endif
14484 +
14485 /*
14486 * No need to follow this irqs on/off section: the syscall
14487 * disabled irqs and here we enable it straight after entry:
14488 */
14489 ENABLE_INTERRUPTS(CLBR_NONE)
14490 - SAVE_ARGS 8,0,0
14491 movl %eax,%eax /* zero extension */
14492 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14493 movq %rcx,RIP-ARGOFFSET(%rsp)
14494 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14495 /* no need to do an access_ok check here because r8 has been
14496 32bit zero extended */
14497 /* hardware stack frame is complete now */
14498 +
14499 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14500 + ASM_PAX_OPEN_USERLAND
14501 + movq pax_user_shadow_base,%r8
14502 + addq RSP-ARGOFFSET(%rsp),%r8
14503 +#endif
14504 +
14505 ASM_STAC
14506 1: movl (%r8),%r9d
14507 _ASM_EXTABLE(1b,ia32_badarg)
14508 ASM_CLAC
14509 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14510 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14511 +
14512 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14513 + ASM_PAX_CLOSE_USERLAND
14514 +#endif
14515 +
14516 + GET_THREAD_INFO(%r11)
14517 + orl $TS_COMPAT,TI_status(%r11)
14518 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14519 CFI_REMEMBER_STATE
14520 jnz cstar_tracesys
14521 cmpq $IA32_NR_syscalls-1,%rax
14522 @@ -319,13 +395,16 @@ cstar_do_call:
14523 cstar_dispatch:
14524 call *ia32_sys_call_table(,%rax,8)
14525 movq %rax,RAX-ARGOFFSET(%rsp)
14526 + GET_THREAD_INFO(%r11)
14527 DISABLE_INTERRUPTS(CLBR_NONE)
14528 TRACE_IRQS_OFF
14529 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14530 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14531 jnz sysretl_audit
14532 sysretl_from_sys_call:
14533 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14534 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14535 + pax_exit_kernel_user
14536 + pax_erase_kstack
14537 + andl $~TS_COMPAT,TI_status(%r11)
14538 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14539 movl RIP-ARGOFFSET(%rsp),%ecx
14540 CFI_REGISTER rip,rcx
14541 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14542 @@ -352,7 +431,7 @@ sysretl_audit:
14543
14544 cstar_tracesys:
14545 #ifdef CONFIG_AUDITSYSCALL
14546 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14547 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14548 jz cstar_auditsys
14549 #endif
14550 xchgl %r9d,%ebp
14551 @@ -366,11 +445,19 @@ cstar_tracesys:
14552 xchgl %ebp,%r9d
14553 cmpq $(IA32_NR_syscalls-1),%rax
14554 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14555 +
14556 + pax_erase_kstack
14557 +
14558 jmp cstar_do_call
14559 END(ia32_cstar_target)
14560
14561 ia32_badarg:
14562 ASM_CLAC
14563 +
14564 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14565 + ASM_PAX_CLOSE_USERLAND
14566 +#endif
14567 +
14568 movq $-EFAULT,%rax
14569 jmp ia32_sysret
14570 CFI_ENDPROC
14571 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14572 CFI_REL_OFFSET rip,RIP-RIP
14573 PARAVIRT_ADJUST_EXCEPTION_FRAME
14574 SWAPGS
14575 - /*
14576 - * No need to follow this irqs on/off section: the syscall
14577 - * disabled irqs and here we enable it straight after entry:
14578 - */
14579 - ENABLE_INTERRUPTS(CLBR_NONE)
14580 movl %eax,%eax
14581 pushq_cfi %rax
14582 cld
14583 /* note the registers are not zero extended to the sf.
14584 this could be a problem. */
14585 SAVE_ARGS 0,1,0
14586 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14587 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14588 + pax_enter_kernel_user
14589 +
14590 +#ifdef CONFIG_PAX_RANDKSTACK
14591 + pax_erase_kstack
14592 +#endif
14593 +
14594 + /*
14595 + * No need to follow this irqs on/off section: the syscall
14596 + * disabled irqs and here we enable it straight after entry:
14597 + */
14598 + ENABLE_INTERRUPTS(CLBR_NONE)
14599 + GET_THREAD_INFO(%r11)
14600 + orl $TS_COMPAT,TI_status(%r11)
14601 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14602 jnz ia32_tracesys
14603 cmpq $(IA32_NR_syscalls-1),%rax
14604 ja ia32_badsys
14605 @@ -442,6 +536,9 @@ ia32_tracesys:
14606 RESTORE_REST
14607 cmpq $(IA32_NR_syscalls-1),%rax
14608 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14609 +
14610 + pax_erase_kstack
14611 +
14612 jmp ia32_do_call
14613 END(ia32_syscall)
14614
14615 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14616 index 8e0ceec..af13504 100644
14617 --- a/arch/x86/ia32/sys_ia32.c
14618 +++ b/arch/x86/ia32/sys_ia32.c
14619 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14620 */
14621 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14622 {
14623 - typeof(ubuf->st_uid) uid = 0;
14624 - typeof(ubuf->st_gid) gid = 0;
14625 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
14626 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
14627 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14628 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14629 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14630 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14631 index 372231c..51b537d 100644
14632 --- a/arch/x86/include/asm/alternative-asm.h
14633 +++ b/arch/x86/include/asm/alternative-asm.h
14634 @@ -18,6 +18,45 @@
14635 .endm
14636 #endif
14637
14638 +#ifdef KERNEXEC_PLUGIN
14639 + .macro pax_force_retaddr_bts rip=0
14640 + btsq $63,\rip(%rsp)
14641 + .endm
14642 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14643 + .macro pax_force_retaddr rip=0, reload=0
14644 + btsq $63,\rip(%rsp)
14645 + .endm
14646 + .macro pax_force_fptr ptr
14647 + btsq $63,\ptr
14648 + .endm
14649 + .macro pax_set_fptr_mask
14650 + .endm
14651 +#endif
14652 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14653 + .macro pax_force_retaddr rip=0, reload=0
14654 + .if \reload
14655 + pax_set_fptr_mask
14656 + .endif
14657 + orq %r12,\rip(%rsp)
14658 + .endm
14659 + .macro pax_force_fptr ptr
14660 + orq %r12,\ptr
14661 + .endm
14662 + .macro pax_set_fptr_mask
14663 + movabs $0x8000000000000000,%r12
14664 + .endm
14665 +#endif
14666 +#else
14667 + .macro pax_force_retaddr rip=0, reload=0
14668 + .endm
14669 + .macro pax_force_fptr ptr
14670 + .endm
14671 + .macro pax_force_retaddr_bts rip=0
14672 + .endm
14673 + .macro pax_set_fptr_mask
14674 + .endm
14675 +#endif
14676 +
14677 .macro altinstruction_entry orig alt feature orig_len alt_len
14678 .long \orig - .
14679 .long \alt - .
14680 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14681 index 0a3f9c9..c9d081d 100644
14682 --- a/arch/x86/include/asm/alternative.h
14683 +++ b/arch/x86/include/asm/alternative.h
14684 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14685 ".pushsection .discard,\"aw\",@progbits\n" \
14686 DISCARD_ENTRY(1) \
14687 ".popsection\n" \
14688 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14689 + ".pushsection .altinstr_replacement, \"a\"\n" \
14690 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14691 ".popsection"
14692
14693 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14694 DISCARD_ENTRY(1) \
14695 DISCARD_ENTRY(2) \
14696 ".popsection\n" \
14697 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14698 + ".pushsection .altinstr_replacement, \"a\"\n" \
14699 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14700 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14701 ".popsection"
14702 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14703 index 1d2091a..f5074c1 100644
14704 --- a/arch/x86/include/asm/apic.h
14705 +++ b/arch/x86/include/asm/apic.h
14706 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14707
14708 #ifdef CONFIG_X86_LOCAL_APIC
14709
14710 -extern unsigned int apic_verbosity;
14711 +extern int apic_verbosity;
14712 extern int local_apic_timer_c2_ok;
14713
14714 extern int disable_apic;
14715 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14716 index 20370c6..a2eb9b0 100644
14717 --- a/arch/x86/include/asm/apm.h
14718 +++ b/arch/x86/include/asm/apm.h
14719 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14720 __asm__ __volatile__(APM_DO_ZERO_SEGS
14721 "pushl %%edi\n\t"
14722 "pushl %%ebp\n\t"
14723 - "lcall *%%cs:apm_bios_entry\n\t"
14724 + "lcall *%%ss:apm_bios_entry\n\t"
14725 "setc %%al\n\t"
14726 "popl %%ebp\n\t"
14727 "popl %%edi\n\t"
14728 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14729 __asm__ __volatile__(APM_DO_ZERO_SEGS
14730 "pushl %%edi\n\t"
14731 "pushl %%ebp\n\t"
14732 - "lcall *%%cs:apm_bios_entry\n\t"
14733 + "lcall *%%ss:apm_bios_entry\n\t"
14734 "setc %%bl\n\t"
14735 "popl %%ebp\n\t"
14736 "popl %%edi\n\t"
14737 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14738 index b17f4f4..9620151 100644
14739 --- a/arch/x86/include/asm/atomic.h
14740 +++ b/arch/x86/include/asm/atomic.h
14741 @@ -23,7 +23,18 @@
14742 */
14743 static inline int atomic_read(const atomic_t *v)
14744 {
14745 - return (*(volatile int *)&(v)->counter);
14746 + return (*(volatile const int *)&(v)->counter);
14747 +}
14748 +
14749 +/**
14750 + * atomic_read_unchecked - read atomic variable
14751 + * @v: pointer of type atomic_unchecked_t
14752 + *
14753 + * Atomically reads the value of @v.
14754 + */
14755 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14756 +{
14757 + return (*(volatile const int *)&(v)->counter);
14758 }
14759
14760 /**
14761 @@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14762 }
14763
14764 /**
14765 + * atomic_set_unchecked - set atomic variable
14766 + * @v: pointer of type atomic_unchecked_t
14767 + * @i: required value
14768 + *
14769 + * Atomically sets the value of @v to @i.
14770 + */
14771 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14772 +{
14773 + v->counter = i;
14774 +}
14775 +
14776 +/**
14777 * atomic_add - add integer to atomic variable
14778 * @i: integer value to add
14779 * @v: pointer of type atomic_t
14780 @@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14781 */
14782 static inline void atomic_add(int i, atomic_t *v)
14783 {
14784 - asm volatile(LOCK_PREFIX "addl %1,%0"
14785 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14786 +
14787 +#ifdef CONFIG_PAX_REFCOUNT
14788 + "jno 0f\n"
14789 + LOCK_PREFIX "subl %1,%0\n"
14790 + "int $4\n0:\n"
14791 + _ASM_EXTABLE(0b, 0b)
14792 +#endif
14793 +
14794 + : "+m" (v->counter)
14795 + : "ir" (i));
14796 +}
14797 +
14798 +/**
14799 + * atomic_add_unchecked - add integer to atomic variable
14800 + * @i: integer value to add
14801 + * @v: pointer of type atomic_unchecked_t
14802 + *
14803 + * Atomically adds @i to @v.
14804 + */
14805 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14806 +{
14807 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14808 : "+m" (v->counter)
14809 : "ir" (i));
14810 }
14811 @@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14812 */
14813 static inline void atomic_sub(int i, atomic_t *v)
14814 {
14815 - asm volatile(LOCK_PREFIX "subl %1,%0"
14816 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14817 +
14818 +#ifdef CONFIG_PAX_REFCOUNT
14819 + "jno 0f\n"
14820 + LOCK_PREFIX "addl %1,%0\n"
14821 + "int $4\n0:\n"
14822 + _ASM_EXTABLE(0b, 0b)
14823 +#endif
14824 +
14825 + : "+m" (v->counter)
14826 + : "ir" (i));
14827 +}
14828 +
14829 +/**
14830 + * atomic_sub_unchecked - subtract integer from atomic variable
14831 + * @i: integer value to subtract
14832 + * @v: pointer of type atomic_unchecked_t
14833 + *
14834 + * Atomically subtracts @i from @v.
14835 + */
14836 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14837 +{
14838 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14839 : "+m" (v->counter)
14840 : "ir" (i));
14841 }
14842 @@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14843 */
14844 static inline int atomic_sub_and_test(int i, atomic_t *v)
14845 {
14846 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14847 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14848 }
14849
14850 /**
14851 @@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14852 */
14853 static inline void atomic_inc(atomic_t *v)
14854 {
14855 - asm volatile(LOCK_PREFIX "incl %0"
14856 + asm volatile(LOCK_PREFIX "incl %0\n"
14857 +
14858 +#ifdef CONFIG_PAX_REFCOUNT
14859 + "jno 0f\n"
14860 + LOCK_PREFIX "decl %0\n"
14861 + "int $4\n0:\n"
14862 + _ASM_EXTABLE(0b, 0b)
14863 +#endif
14864 +
14865 + : "+m" (v->counter));
14866 +}
14867 +
14868 +/**
14869 + * atomic_inc_unchecked - increment atomic variable
14870 + * @v: pointer of type atomic_unchecked_t
14871 + *
14872 + * Atomically increments @v by 1.
14873 + */
14874 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14875 +{
14876 + asm volatile(LOCK_PREFIX "incl %0\n"
14877 : "+m" (v->counter));
14878 }
14879
14880 @@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14881 */
14882 static inline void atomic_dec(atomic_t *v)
14883 {
14884 - asm volatile(LOCK_PREFIX "decl %0"
14885 + asm volatile(LOCK_PREFIX "decl %0\n"
14886 +
14887 +#ifdef CONFIG_PAX_REFCOUNT
14888 + "jno 0f\n"
14889 + LOCK_PREFIX "incl %0\n"
14890 + "int $4\n0:\n"
14891 + _ASM_EXTABLE(0b, 0b)
14892 +#endif
14893 +
14894 + : "+m" (v->counter));
14895 +}
14896 +
14897 +/**
14898 + * atomic_dec_unchecked - decrement atomic variable
14899 + * @v: pointer of type atomic_unchecked_t
14900 + *
14901 + * Atomically decrements @v by 1.
14902 + */
14903 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14904 +{
14905 + asm volatile(LOCK_PREFIX "decl %0\n"
14906 : "+m" (v->counter));
14907 }
14908
14909 @@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
14910 */
14911 static inline int atomic_dec_and_test(atomic_t *v)
14912 {
14913 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
14914 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
14915 }
14916
14917 /**
14918 @@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
14919 */
14920 static inline int atomic_inc_and_test(atomic_t *v)
14921 {
14922 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
14923 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
14924 +}
14925 +
14926 +/**
14927 + * atomic_inc_and_test_unchecked - increment and test
14928 + * @v: pointer of type atomic_unchecked_t
14929 + *
14930 + * Atomically increments @v by 1
14931 + * and returns true if the result is zero, or false for all
14932 + * other cases.
14933 + */
14934 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14935 +{
14936 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
14937 }
14938
14939 /**
14940 @@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
14941 */
14942 static inline int atomic_add_negative(int i, atomic_t *v)
14943 {
14944 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
14945 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
14946 }
14947
14948 /**
14949 @@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14950 */
14951 static inline int atomic_add_return(int i, atomic_t *v)
14952 {
14953 + return i + xadd_check_overflow(&v->counter, i);
14954 +}
14955 +
14956 +/**
14957 + * atomic_add_return_unchecked - add integer and return
14958 + * @i: integer value to add
14959 + * @v: pointer of type atomic_unchecked_t
14960 + *
14961 + * Atomically adds @i to @v and returns @i + @v
14962 + */
14963 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14964 +{
14965 return i + xadd(&v->counter, i);
14966 }
14967
14968 @@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14969 }
14970
14971 #define atomic_inc_return(v) (atomic_add_return(1, v))
14972 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14973 +{
14974 + return atomic_add_return_unchecked(1, v);
14975 +}
14976 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14977
14978 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14979 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
14980 +{
14981 + return cmpxchg(&v->counter, old, new);
14982 +}
14983 +
14984 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14985 {
14986 return cmpxchg(&v->counter, old, new);
14987 }
14988 @@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
14989 return xchg(&v->counter, new);
14990 }
14991
14992 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14993 +{
14994 + return xchg(&v->counter, new);
14995 +}
14996 +
14997 /**
14998 * __atomic_add_unless - add unless the number is already a given value
14999 * @v: pointer of type atomic_t
15000 @@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15001 * Atomically adds @a to @v, so long as @v was not already @u.
15002 * Returns the old value of @v.
15003 */
15004 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15005 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15006 {
15007 - int c, old;
15008 + int c, old, new;
15009 c = atomic_read(v);
15010 for (;;) {
15011 - if (unlikely(c == (u)))
15012 + if (unlikely(c == u))
15013 break;
15014 - old = atomic_cmpxchg((v), c, c + (a));
15015 +
15016 + asm volatile("addl %2,%0\n"
15017 +
15018 +#ifdef CONFIG_PAX_REFCOUNT
15019 + "jno 0f\n"
15020 + "subl %2,%0\n"
15021 + "int $4\n0:\n"
15022 + _ASM_EXTABLE(0b, 0b)
15023 +#endif
15024 +
15025 + : "=r" (new)
15026 + : "0" (c), "ir" (a));
15027 +
15028 + old = atomic_cmpxchg(v, c, new);
15029 if (likely(old == c))
15030 break;
15031 c = old;
15032 @@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15033 }
15034
15035 /**
15036 + * atomic_inc_not_zero_hint - increment if not null
15037 + * @v: pointer of type atomic_t
15038 + * @hint: probable value of the atomic before the increment
15039 + *
15040 + * This version of atomic_inc_not_zero() gives a hint of probable
15041 + * value of the atomic. This helps processor to not read the memory
15042 + * before doing the atomic read/modify/write cycle, lowering
15043 + * number of bus transactions on some arches.
15044 + *
15045 + * Returns: 0 if increment was not done, 1 otherwise.
15046 + */
15047 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15048 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15049 +{
15050 + int val, c = hint, new;
15051 +
15052 + /* sanity test, should be removed by compiler if hint is a constant */
15053 + if (!hint)
15054 + return __atomic_add_unless(v, 1, 0);
15055 +
15056 + do {
15057 + asm volatile("incl %0\n"
15058 +
15059 +#ifdef CONFIG_PAX_REFCOUNT
15060 + "jno 0f\n"
15061 + "decl %0\n"
15062 + "int $4\n0:\n"
15063 + _ASM_EXTABLE(0b, 0b)
15064 +#endif
15065 +
15066 + : "=r" (new)
15067 + : "0" (c));
15068 +
15069 + val = atomic_cmpxchg(v, c, new);
15070 + if (val == c)
15071 + return 1;
15072 + c = val;
15073 + } while (c);
15074 +
15075 + return 0;
15076 +}
15077 +
15078 +/**
15079 * atomic_inc_short - increment of a short integer
15080 * @v: pointer to type int
15081 *
15082 @@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15083 #endif
15084
15085 /* These are x86-specific, used by some header files */
15086 -#define atomic_clear_mask(mask, addr) \
15087 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15088 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15089 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15090 +{
15091 + asm volatile(LOCK_PREFIX "andl %1,%0"
15092 + : "+m" (v->counter)
15093 + : "r" (~(mask))
15094 + : "memory");
15095 +}
15096
15097 -#define atomic_set_mask(mask, addr) \
15098 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15099 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15100 - : "memory")
15101 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15102 +{
15103 + asm volatile(LOCK_PREFIX "andl %1,%0"
15104 + : "+m" (v->counter)
15105 + : "r" (~(mask))
15106 + : "memory");
15107 +}
15108 +
15109 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15110 +{
15111 + asm volatile(LOCK_PREFIX "orl %1,%0"
15112 + : "+m" (v->counter)
15113 + : "r" (mask)
15114 + : "memory");
15115 +}
15116 +
15117 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15118 +{
15119 + asm volatile(LOCK_PREFIX "orl %1,%0"
15120 + : "+m" (v->counter)
15121 + : "r" (mask)
15122 + : "memory");
15123 +}
15124
15125 /* Atomic operations are already serializing on x86 */
15126 #define smp_mb__before_atomic_dec() barrier()
15127 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15128 index b154de7..bf18a5a 100644
15129 --- a/arch/x86/include/asm/atomic64_32.h
15130 +++ b/arch/x86/include/asm/atomic64_32.h
15131 @@ -12,6 +12,14 @@ typedef struct {
15132 u64 __aligned(8) counter;
15133 } atomic64_t;
15134
15135 +#ifdef CONFIG_PAX_REFCOUNT
15136 +typedef struct {
15137 + u64 __aligned(8) counter;
15138 +} atomic64_unchecked_t;
15139 +#else
15140 +typedef atomic64_t atomic64_unchecked_t;
15141 +#endif
15142 +
15143 #define ATOMIC64_INIT(val) { (val) }
15144
15145 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15146 @@ -37,21 +45,31 @@ typedef struct {
15147 ATOMIC64_DECL_ONE(sym##_386)
15148
15149 ATOMIC64_DECL_ONE(add_386);
15150 +ATOMIC64_DECL_ONE(add_unchecked_386);
15151 ATOMIC64_DECL_ONE(sub_386);
15152 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15153 ATOMIC64_DECL_ONE(inc_386);
15154 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15155 ATOMIC64_DECL_ONE(dec_386);
15156 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15157 #endif
15158
15159 #define alternative_atomic64(f, out, in...) \
15160 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15161
15162 ATOMIC64_DECL(read);
15163 +ATOMIC64_DECL(read_unchecked);
15164 ATOMIC64_DECL(set);
15165 +ATOMIC64_DECL(set_unchecked);
15166 ATOMIC64_DECL(xchg);
15167 ATOMIC64_DECL(add_return);
15168 +ATOMIC64_DECL(add_return_unchecked);
15169 ATOMIC64_DECL(sub_return);
15170 +ATOMIC64_DECL(sub_return_unchecked);
15171 ATOMIC64_DECL(inc_return);
15172 +ATOMIC64_DECL(inc_return_unchecked);
15173 ATOMIC64_DECL(dec_return);
15174 +ATOMIC64_DECL(dec_return_unchecked);
15175 ATOMIC64_DECL(dec_if_positive);
15176 ATOMIC64_DECL(inc_not_zero);
15177 ATOMIC64_DECL(add_unless);
15178 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15179 }
15180
15181 /**
15182 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15183 + * @p: pointer to type atomic64_unchecked_t
15184 + * @o: expected value
15185 + * @n: new value
15186 + *
15187 + * Atomically sets @v to @n if it was equal to @o and returns
15188 + * the old value.
15189 + */
15190 +
15191 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15192 +{
15193 + return cmpxchg64(&v->counter, o, n);
15194 +}
15195 +
15196 +/**
15197 * atomic64_xchg - xchg atomic64 variable
15198 * @v: pointer to type atomic64_t
15199 * @n: value to assign
15200 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15201 }
15202
15203 /**
15204 + * atomic64_set_unchecked - set atomic64 variable
15205 + * @v: pointer to type atomic64_unchecked_t
15206 + * @n: value to assign
15207 + *
15208 + * Atomically sets the value of @v to @n.
15209 + */
15210 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15211 +{
15212 + unsigned high = (unsigned)(i >> 32);
15213 + unsigned low = (unsigned)i;
15214 + alternative_atomic64(set, /* no output */,
15215 + "S" (v), "b" (low), "c" (high)
15216 + : "eax", "edx", "memory");
15217 +}
15218 +
15219 +/**
15220 * atomic64_read - read atomic64 variable
15221 * @v: pointer to type atomic64_t
15222 *
15223 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15224 }
15225
15226 /**
15227 + * atomic64_read_unchecked - read atomic64 variable
15228 + * @v: pointer to type atomic64_unchecked_t
15229 + *
15230 + * Atomically reads the value of @v and returns it.
15231 + */
15232 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15233 +{
15234 + long long r;
15235 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15236 + return r;
15237 + }
15238 +
15239 +/**
15240 * atomic64_add_return - add and return
15241 * @i: integer value to add
15242 * @v: pointer to type atomic64_t
15243 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15244 return i;
15245 }
15246
15247 +/**
15248 + * atomic64_add_return_unchecked - add and return
15249 + * @i: integer value to add
15250 + * @v: pointer to type atomic64_unchecked_t
15251 + *
15252 + * Atomically adds @i to @v and returns @i + *@v
15253 + */
15254 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15255 +{
15256 + alternative_atomic64(add_return_unchecked,
15257 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15258 + ASM_NO_INPUT_CLOBBER("memory"));
15259 + return i;
15260 +}
15261 +
15262 /*
15263 * Other variants with different arithmetic operators:
15264 */
15265 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15266 return a;
15267 }
15268
15269 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15270 +{
15271 + long long a;
15272 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15273 + "S" (v) : "memory", "ecx");
15274 + return a;
15275 +}
15276 +
15277 static inline long long atomic64_dec_return(atomic64_t *v)
15278 {
15279 long long a;
15280 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15281 }
15282
15283 /**
15284 + * atomic64_add_unchecked - add integer to atomic64 variable
15285 + * @i: integer value to add
15286 + * @v: pointer to type atomic64_unchecked_t
15287 + *
15288 + * Atomically adds @i to @v.
15289 + */
15290 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15291 +{
15292 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15293 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15294 + ASM_NO_INPUT_CLOBBER("memory"));
15295 + return i;
15296 +}
15297 +
15298 +/**
15299 * atomic64_sub - subtract the atomic64 variable
15300 * @i: integer value to subtract
15301 * @v: pointer to type atomic64_t
15302 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15303 index 46e9052..ae45136 100644
15304 --- a/arch/x86/include/asm/atomic64_64.h
15305 +++ b/arch/x86/include/asm/atomic64_64.h
15306 @@ -18,7 +18,19 @@
15307 */
15308 static inline long atomic64_read(const atomic64_t *v)
15309 {
15310 - return (*(volatile long *)&(v)->counter);
15311 + return (*(volatile const long *)&(v)->counter);
15312 +}
15313 +
15314 +/**
15315 + * atomic64_read_unchecked - read atomic64 variable
15316 + * @v: pointer of type atomic64_unchecked_t
15317 + *
15318 + * Atomically reads the value of @v.
15319 + * Doesn't imply a read memory barrier.
15320 + */
15321 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15322 +{
15323 + return (*(volatile const long *)&(v)->counter);
15324 }
15325
15326 /**
15327 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15328 }
15329
15330 /**
15331 + * atomic64_set_unchecked - set atomic64 variable
15332 + * @v: pointer to type atomic64_unchecked_t
15333 + * @i: required value
15334 + *
15335 + * Atomically sets the value of @v to @i.
15336 + */
15337 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15338 +{
15339 + v->counter = i;
15340 +}
15341 +
15342 +/**
15343 * atomic64_add - add integer to atomic64 variable
15344 * @i: integer value to add
15345 * @v: pointer to type atomic64_t
15346 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15347 */
15348 static inline void atomic64_add(long i, atomic64_t *v)
15349 {
15350 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15351 +
15352 +#ifdef CONFIG_PAX_REFCOUNT
15353 + "jno 0f\n"
15354 + LOCK_PREFIX "subq %1,%0\n"
15355 + "int $4\n0:\n"
15356 + _ASM_EXTABLE(0b, 0b)
15357 +#endif
15358 +
15359 + : "=m" (v->counter)
15360 + : "er" (i), "m" (v->counter));
15361 +}
15362 +
15363 +/**
15364 + * atomic64_add_unchecked - add integer to atomic64 variable
15365 + * @i: integer value to add
15366 + * @v: pointer to type atomic64_unchecked_t
15367 + *
15368 + * Atomically adds @i to @v.
15369 + */
15370 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15371 +{
15372 asm volatile(LOCK_PREFIX "addq %1,%0"
15373 : "=m" (v->counter)
15374 : "er" (i), "m" (v->counter));
15375 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15376 */
15377 static inline void atomic64_sub(long i, atomic64_t *v)
15378 {
15379 - asm volatile(LOCK_PREFIX "subq %1,%0"
15380 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15381 +
15382 +#ifdef CONFIG_PAX_REFCOUNT
15383 + "jno 0f\n"
15384 + LOCK_PREFIX "addq %1,%0\n"
15385 + "int $4\n0:\n"
15386 + _ASM_EXTABLE(0b, 0b)
15387 +#endif
15388 +
15389 + : "=m" (v->counter)
15390 + : "er" (i), "m" (v->counter));
15391 +}
15392 +
15393 +/**
15394 + * atomic64_sub_unchecked - subtract the atomic64 variable
15395 + * @i: integer value to subtract
15396 + * @v: pointer to type atomic64_unchecked_t
15397 + *
15398 + * Atomically subtracts @i from @v.
15399 + */
15400 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15401 +{
15402 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15403 : "=m" (v->counter)
15404 : "er" (i), "m" (v->counter));
15405 }
15406 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15407 */
15408 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15409 {
15410 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15411 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15412 }
15413
15414 /**
15415 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15416 */
15417 static inline void atomic64_inc(atomic64_t *v)
15418 {
15419 + asm volatile(LOCK_PREFIX "incq %0\n"
15420 +
15421 +#ifdef CONFIG_PAX_REFCOUNT
15422 + "jno 0f\n"
15423 + LOCK_PREFIX "decq %0\n"
15424 + "int $4\n0:\n"
15425 + _ASM_EXTABLE(0b, 0b)
15426 +#endif
15427 +
15428 + : "=m" (v->counter)
15429 + : "m" (v->counter));
15430 +}
15431 +
15432 +/**
15433 + * atomic64_inc_unchecked - increment atomic64 variable
15434 + * @v: pointer to type atomic64_unchecked_t
15435 + *
15436 + * Atomically increments @v by 1.
15437 + */
15438 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15439 +{
15440 asm volatile(LOCK_PREFIX "incq %0"
15441 : "=m" (v->counter)
15442 : "m" (v->counter));
15443 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15444 */
15445 static inline void atomic64_dec(atomic64_t *v)
15446 {
15447 - asm volatile(LOCK_PREFIX "decq %0"
15448 + asm volatile(LOCK_PREFIX "decq %0\n"
15449 +
15450 +#ifdef CONFIG_PAX_REFCOUNT
15451 + "jno 0f\n"
15452 + LOCK_PREFIX "incq %0\n"
15453 + "int $4\n0:\n"
15454 + _ASM_EXTABLE(0b, 0b)
15455 +#endif
15456 +
15457 + : "=m" (v->counter)
15458 + : "m" (v->counter));
15459 +}
15460 +
15461 +/**
15462 + * atomic64_dec_unchecked - decrement atomic64 variable
15463 + * @v: pointer to type atomic64_t
15464 + *
15465 + * Atomically decrements @v by 1.
15466 + */
15467 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15468 +{
15469 + asm volatile(LOCK_PREFIX "decq %0\n"
15470 : "=m" (v->counter)
15471 : "m" (v->counter));
15472 }
15473 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15474 */
15475 static inline int atomic64_dec_and_test(atomic64_t *v)
15476 {
15477 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15478 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15479 }
15480
15481 /**
15482 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15483 */
15484 static inline int atomic64_inc_and_test(atomic64_t *v)
15485 {
15486 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15487 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15488 }
15489
15490 /**
15491 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15492 */
15493 static inline int atomic64_add_negative(long i, atomic64_t *v)
15494 {
15495 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15496 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15497 }
15498
15499 /**
15500 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15501 */
15502 static inline long atomic64_add_return(long i, atomic64_t *v)
15503 {
15504 + return i + xadd_check_overflow(&v->counter, i);
15505 +}
15506 +
15507 +/**
15508 + * atomic64_add_return_unchecked - add and return
15509 + * @i: integer value to add
15510 + * @v: pointer to type atomic64_unchecked_t
15511 + *
15512 + * Atomically adds @i to @v and returns @i + @v
15513 + */
15514 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15515 +{
15516 return i + xadd(&v->counter, i);
15517 }
15518
15519 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15520 }
15521
15522 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15523 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15524 +{
15525 + return atomic64_add_return_unchecked(1, v);
15526 +}
15527 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15528
15529 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15530 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15531 return cmpxchg(&v->counter, old, new);
15532 }
15533
15534 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15535 +{
15536 + return cmpxchg(&v->counter, old, new);
15537 +}
15538 +
15539 static inline long atomic64_xchg(atomic64_t *v, long new)
15540 {
15541 return xchg(&v->counter, new);
15542 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15543 */
15544 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15545 {
15546 - long c, old;
15547 + long c, old, new;
15548 c = atomic64_read(v);
15549 for (;;) {
15550 - if (unlikely(c == (u)))
15551 + if (unlikely(c == u))
15552 break;
15553 - old = atomic64_cmpxchg((v), c, c + (a));
15554 +
15555 + asm volatile("add %2,%0\n"
15556 +
15557 +#ifdef CONFIG_PAX_REFCOUNT
15558 + "jno 0f\n"
15559 + "sub %2,%0\n"
15560 + "int $4\n0:\n"
15561 + _ASM_EXTABLE(0b, 0b)
15562 +#endif
15563 +
15564 + : "=r" (new)
15565 + : "0" (c), "ir" (a));
15566 +
15567 + old = atomic64_cmpxchg(v, c, new);
15568 if (likely(old == c))
15569 break;
15570 c = old;
15571 }
15572 - return c != (u);
15573 + return c != u;
15574 }
15575
15576 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15577 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15578 index 9fc1af7..fc71228 100644
15579 --- a/arch/x86/include/asm/bitops.h
15580 +++ b/arch/x86/include/asm/bitops.h
15581 @@ -49,7 +49,7 @@
15582 * a mask operation on a byte.
15583 */
15584 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15585 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15586 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15587 #define CONST_MASK(nr) (1 << ((nr) & 7))
15588
15589 /**
15590 @@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15591 */
15592 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15593 {
15594 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15595 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15596 }
15597
15598 /**
15599 @@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15600 */
15601 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15602 {
15603 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15604 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15605 }
15606
15607 /**
15608 @@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15609 */
15610 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15611 {
15612 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15613 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15614 }
15615
15616 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15617 @@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15618 *
15619 * Undefined if no bit exists, so code should check against 0 first.
15620 */
15621 -static inline unsigned long __ffs(unsigned long word)
15622 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15623 {
15624 asm("rep; bsf %1,%0"
15625 : "=r" (word)
15626 @@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15627 *
15628 * Undefined if no zero exists, so code should check against ~0UL first.
15629 */
15630 -static inline unsigned long ffz(unsigned long word)
15631 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15632 {
15633 asm("rep; bsf %1,%0"
15634 : "=r" (word)
15635 @@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15636 *
15637 * Undefined if no set bit exists, so code should check against 0 first.
15638 */
15639 -static inline unsigned long __fls(unsigned long word)
15640 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15641 {
15642 asm("bsr %1,%0"
15643 : "=r" (word)
15644 @@ -436,7 +436,7 @@ static inline int ffs(int x)
15645 * set bit if value is nonzero. The last (most significant) bit is
15646 * at position 32.
15647 */
15648 -static inline int fls(int x)
15649 +static inline int __intentional_overflow(-1) fls(int x)
15650 {
15651 int r;
15652
15653 @@ -478,7 +478,7 @@ static inline int fls(int x)
15654 * at position 64.
15655 */
15656 #ifdef CONFIG_X86_64
15657 -static __always_inline int fls64(__u64 x)
15658 +static __always_inline long fls64(__u64 x)
15659 {
15660 int bitpos = -1;
15661 /*
15662 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15663 index 4fa687a..60f2d39 100644
15664 --- a/arch/x86/include/asm/boot.h
15665 +++ b/arch/x86/include/asm/boot.h
15666 @@ -6,10 +6,15 @@
15667 #include <uapi/asm/boot.h>
15668
15669 /* Physical address where kernel should be loaded. */
15670 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15671 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15672 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15673 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15674
15675 +#ifndef __ASSEMBLY__
15676 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
15677 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15678 +#endif
15679 +
15680 /* Minimum kernel alignment, as a power of two */
15681 #ifdef CONFIG_X86_64
15682 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15683 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15684 index 48f99f1..d78ebf9 100644
15685 --- a/arch/x86/include/asm/cache.h
15686 +++ b/arch/x86/include/asm/cache.h
15687 @@ -5,12 +5,13 @@
15688
15689 /* L1 cache line size */
15690 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15691 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15692 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15693
15694 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15695 +#define __read_only __attribute__((__section__(".data..read_only")))
15696
15697 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15698 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15699 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15700
15701 #ifdef CONFIG_X86_VSMP
15702 #ifdef CONFIG_SMP
15703 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15704 index 9863ee3..4a1f8e1 100644
15705 --- a/arch/x86/include/asm/cacheflush.h
15706 +++ b/arch/x86/include/asm/cacheflush.h
15707 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15708 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15709
15710 if (pg_flags == _PGMT_DEFAULT)
15711 - return -1;
15712 + return ~0UL;
15713 else if (pg_flags == _PGMT_WC)
15714 return _PAGE_CACHE_WC;
15715 else if (pg_flags == _PGMT_UC_MINUS)
15716 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15717 index cb4c73b..c473c29 100644
15718 --- a/arch/x86/include/asm/calling.h
15719 +++ b/arch/x86/include/asm/calling.h
15720 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15721 #define RSP 152
15722 #define SS 160
15723
15724 -#define ARGOFFSET R11
15725 -#define SWFRAME ORIG_RAX
15726 +#define ARGOFFSET R15
15727
15728 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15729 - subq $9*8+\addskip, %rsp
15730 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15731 - movq_cfi rdi, 8*8
15732 - movq_cfi rsi, 7*8
15733 - movq_cfi rdx, 6*8
15734 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15735 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15736 + movq_cfi rdi, RDI
15737 + movq_cfi rsi, RSI
15738 + movq_cfi rdx, RDX
15739
15740 .if \save_rcx
15741 - movq_cfi rcx, 5*8
15742 + movq_cfi rcx, RCX
15743 .endif
15744
15745 - movq_cfi rax, 4*8
15746 + movq_cfi rax, RAX
15747
15748 .if \save_r891011
15749 - movq_cfi r8, 3*8
15750 - movq_cfi r9, 2*8
15751 - movq_cfi r10, 1*8
15752 - movq_cfi r11, 0*8
15753 + movq_cfi r8, R8
15754 + movq_cfi r9, R9
15755 + movq_cfi r10, R10
15756 + movq_cfi r11, R11
15757 .endif
15758
15759 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15760 + movq_cfi r12, R12
15761 +#endif
15762 +
15763 .endm
15764
15765 -#define ARG_SKIP (9*8)
15766 +#define ARG_SKIP ORIG_RAX
15767
15768 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15769 rstor_r8910=1, rstor_rdx=1
15770 +
15771 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15772 + movq_cfi_restore R12, r12
15773 +#endif
15774 +
15775 .if \rstor_r11
15776 - movq_cfi_restore 0*8, r11
15777 + movq_cfi_restore R11, r11
15778 .endif
15779
15780 .if \rstor_r8910
15781 - movq_cfi_restore 1*8, r10
15782 - movq_cfi_restore 2*8, r9
15783 - movq_cfi_restore 3*8, r8
15784 + movq_cfi_restore R10, r10
15785 + movq_cfi_restore R9, r9
15786 + movq_cfi_restore R8, r8
15787 .endif
15788
15789 .if \rstor_rax
15790 - movq_cfi_restore 4*8, rax
15791 + movq_cfi_restore RAX, rax
15792 .endif
15793
15794 .if \rstor_rcx
15795 - movq_cfi_restore 5*8, rcx
15796 + movq_cfi_restore RCX, rcx
15797 .endif
15798
15799 .if \rstor_rdx
15800 - movq_cfi_restore 6*8, rdx
15801 + movq_cfi_restore RDX, rdx
15802 .endif
15803
15804 - movq_cfi_restore 7*8, rsi
15805 - movq_cfi_restore 8*8, rdi
15806 + movq_cfi_restore RSI, rsi
15807 + movq_cfi_restore RDI, rdi
15808
15809 - .if ARG_SKIP+\addskip > 0
15810 - addq $ARG_SKIP+\addskip, %rsp
15811 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15812 + .if ORIG_RAX+\addskip > 0
15813 + addq $ORIG_RAX+\addskip, %rsp
15814 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15815 .endif
15816 .endm
15817
15818 - .macro LOAD_ARGS offset, skiprax=0
15819 - movq \offset(%rsp), %r11
15820 - movq \offset+8(%rsp), %r10
15821 - movq \offset+16(%rsp), %r9
15822 - movq \offset+24(%rsp), %r8
15823 - movq \offset+40(%rsp), %rcx
15824 - movq \offset+48(%rsp), %rdx
15825 - movq \offset+56(%rsp), %rsi
15826 - movq \offset+64(%rsp), %rdi
15827 + .macro LOAD_ARGS skiprax=0
15828 + movq R11(%rsp), %r11
15829 + movq R10(%rsp), %r10
15830 + movq R9(%rsp), %r9
15831 + movq R8(%rsp), %r8
15832 + movq RCX(%rsp), %rcx
15833 + movq RDX(%rsp), %rdx
15834 + movq RSI(%rsp), %rsi
15835 + movq RDI(%rsp), %rdi
15836 .if \skiprax
15837 .else
15838 - movq \offset+72(%rsp), %rax
15839 + movq RAX(%rsp), %rax
15840 .endif
15841 .endm
15842
15843 -#define REST_SKIP (6*8)
15844 -
15845 .macro SAVE_REST
15846 - subq $REST_SKIP, %rsp
15847 - CFI_ADJUST_CFA_OFFSET REST_SKIP
15848 - movq_cfi rbx, 5*8
15849 - movq_cfi rbp, 4*8
15850 - movq_cfi r12, 3*8
15851 - movq_cfi r13, 2*8
15852 - movq_cfi r14, 1*8
15853 - movq_cfi r15, 0*8
15854 + movq_cfi rbx, RBX
15855 + movq_cfi rbp, RBP
15856 +
15857 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15858 + movq_cfi r12, R12
15859 +#endif
15860 +
15861 + movq_cfi r13, R13
15862 + movq_cfi r14, R14
15863 + movq_cfi r15, R15
15864 .endm
15865
15866 .macro RESTORE_REST
15867 - movq_cfi_restore 0*8, r15
15868 - movq_cfi_restore 1*8, r14
15869 - movq_cfi_restore 2*8, r13
15870 - movq_cfi_restore 3*8, r12
15871 - movq_cfi_restore 4*8, rbp
15872 - movq_cfi_restore 5*8, rbx
15873 - addq $REST_SKIP, %rsp
15874 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15875 + movq_cfi_restore R15, r15
15876 + movq_cfi_restore R14, r14
15877 + movq_cfi_restore R13, r13
15878 +
15879 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15880 + movq_cfi_restore R12, r12
15881 +#endif
15882 +
15883 + movq_cfi_restore RBP, rbp
15884 + movq_cfi_restore RBX, rbx
15885 .endm
15886
15887 .macro SAVE_ALL
15888 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15889 index f50de69..2b0a458 100644
15890 --- a/arch/x86/include/asm/checksum_32.h
15891 +++ b/arch/x86/include/asm/checksum_32.h
15892 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15893 int len, __wsum sum,
15894 int *src_err_ptr, int *dst_err_ptr);
15895
15896 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15897 + int len, __wsum sum,
15898 + int *src_err_ptr, int *dst_err_ptr);
15899 +
15900 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15901 + int len, __wsum sum,
15902 + int *src_err_ptr, int *dst_err_ptr);
15903 +
15904 /*
15905 * Note: when you get a NULL pointer exception here this means someone
15906 * passed in an incorrect kernel address to one of these functions.
15907 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15908
15909 might_sleep();
15910 stac();
15911 - ret = csum_partial_copy_generic((__force void *)src, dst,
15912 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
15913 len, sum, err_ptr, NULL);
15914 clac();
15915
15916 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15917 might_sleep();
15918 if (access_ok(VERIFY_WRITE, dst, len)) {
15919 stac();
15920 - ret = csum_partial_copy_generic(src, (__force void *)dst,
15921 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
15922 len, sum, NULL, err_ptr);
15923 clac();
15924 return ret;
15925 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
15926 index d47786a..ce1b05d 100644
15927 --- a/arch/x86/include/asm/cmpxchg.h
15928 +++ b/arch/x86/include/asm/cmpxchg.h
15929 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
15930 __compiletime_error("Bad argument size for cmpxchg");
15931 extern void __xadd_wrong_size(void)
15932 __compiletime_error("Bad argument size for xadd");
15933 +extern void __xadd_check_overflow_wrong_size(void)
15934 + __compiletime_error("Bad argument size for xadd_check_overflow");
15935 extern void __add_wrong_size(void)
15936 __compiletime_error("Bad argument size for add");
15937 +extern void __add_check_overflow_wrong_size(void)
15938 + __compiletime_error("Bad argument size for add_check_overflow");
15939
15940 /*
15941 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
15942 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
15943 __ret; \
15944 })
15945
15946 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
15947 + ({ \
15948 + __typeof__ (*(ptr)) __ret = (arg); \
15949 + switch (sizeof(*(ptr))) { \
15950 + case __X86_CASE_L: \
15951 + asm volatile (lock #op "l %0, %1\n" \
15952 + "jno 0f\n" \
15953 + "mov %0,%1\n" \
15954 + "int $4\n0:\n" \
15955 + _ASM_EXTABLE(0b, 0b) \
15956 + : "+r" (__ret), "+m" (*(ptr)) \
15957 + : : "memory", "cc"); \
15958 + break; \
15959 + case __X86_CASE_Q: \
15960 + asm volatile (lock #op "q %q0, %1\n" \
15961 + "jno 0f\n" \
15962 + "mov %0,%1\n" \
15963 + "int $4\n0:\n" \
15964 + _ASM_EXTABLE(0b, 0b) \
15965 + : "+r" (__ret), "+m" (*(ptr)) \
15966 + : : "memory", "cc"); \
15967 + break; \
15968 + default: \
15969 + __ ## op ## _check_overflow_wrong_size(); \
15970 + } \
15971 + __ret; \
15972 + })
15973 +
15974 /*
15975 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
15976 * Since this is generally used to protect other memory information, we
15977 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
15978 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
15979 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
15980
15981 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
15982 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
15983 +
15984 #define __add(ptr, inc, lock) \
15985 ({ \
15986 __typeof__ (*(ptr)) __ret = (inc); \
15987 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
15988 index 59c6c40..5e0b22c 100644
15989 --- a/arch/x86/include/asm/compat.h
15990 +++ b/arch/x86/include/asm/compat.h
15991 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
15992 typedef u32 compat_uint_t;
15993 typedef u32 compat_ulong_t;
15994 typedef u64 __attribute__((aligned(4))) compat_u64;
15995 -typedef u32 compat_uptr_t;
15996 +typedef u32 __user compat_uptr_t;
15997
15998 struct compat_timespec {
15999 compat_time_t tv_sec;
16000 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16001 index e099f95..5aa0fb2 100644
16002 --- a/arch/x86/include/asm/cpufeature.h
16003 +++ b/arch/x86/include/asm/cpufeature.h
16004 @@ -203,7 +203,7 @@
16005 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16006 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16007 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16008 -
16009 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16010
16011 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16012 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16013 @@ -211,7 +211,7 @@
16014 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16015 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16016 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16017 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16018 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16019 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16020 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16021 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16022 @@ -354,6 +354,7 @@ extern const char * const x86_power_flags[32];
16023 #undef cpu_has_centaur_mcr
16024 #define cpu_has_centaur_mcr 0
16025
16026 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16027 #endif /* CONFIG_X86_64 */
16028
16029 #if __GNUC__ >= 4
16030 @@ -406,7 +407,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16031
16032 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16033 t_warn:
16034 - warn_pre_alternatives();
16035 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16036 + warn_pre_alternatives();
16037 return false;
16038 #endif
16039
16040 @@ -426,7 +428,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16041 ".section .discard,\"aw\",@progbits\n"
16042 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16043 ".previous\n"
16044 - ".section .altinstr_replacement,\"ax\"\n"
16045 + ".section .altinstr_replacement,\"a\"\n"
16046 "3: movb $1,%0\n"
16047 "4:\n"
16048 ".previous\n"
16049 @@ -463,7 +465,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16050 " .byte 2b - 1b\n" /* src len */
16051 " .byte 4f - 3f\n" /* repl len */
16052 ".previous\n"
16053 - ".section .altinstr_replacement,\"ax\"\n"
16054 + ".section .altinstr_replacement,\"a\"\n"
16055 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16056 "4:\n"
16057 ".previous\n"
16058 @@ -496,7 +498,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16059 ".section .discard,\"aw\",@progbits\n"
16060 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16061 ".previous\n"
16062 - ".section .altinstr_replacement,\"ax\"\n"
16063 + ".section .altinstr_replacement,\"a\"\n"
16064 "3: movb $0,%0\n"
16065 "4:\n"
16066 ".previous\n"
16067 @@ -510,7 +512,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16068 ".section .discard,\"aw\",@progbits\n"
16069 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16070 ".previous\n"
16071 - ".section .altinstr_replacement,\"ax\"\n"
16072 + ".section .altinstr_replacement,\"a\"\n"
16073 "5: movb $1,%0\n"
16074 "6:\n"
16075 ".previous\n"
16076 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16077 index 50d033a..37deb26 100644
16078 --- a/arch/x86/include/asm/desc.h
16079 +++ b/arch/x86/include/asm/desc.h
16080 @@ -4,6 +4,7 @@
16081 #include <asm/desc_defs.h>
16082 #include <asm/ldt.h>
16083 #include <asm/mmu.h>
16084 +#include <asm/pgtable.h>
16085
16086 #include <linux/smp.h>
16087 #include <linux/percpu.h>
16088 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16089
16090 desc->type = (info->read_exec_only ^ 1) << 1;
16091 desc->type |= info->contents << 2;
16092 + desc->type |= info->seg_not_present ^ 1;
16093
16094 desc->s = 1;
16095 desc->dpl = 0x3;
16096 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16097 }
16098
16099 extern struct desc_ptr idt_descr;
16100 -extern gate_desc idt_table[];
16101 -extern struct desc_ptr debug_idt_descr;
16102 -extern gate_desc debug_idt_table[];
16103 -
16104 -struct gdt_page {
16105 - struct desc_struct gdt[GDT_ENTRIES];
16106 -} __attribute__((aligned(PAGE_SIZE)));
16107 -
16108 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16109 +extern gate_desc idt_table[IDT_ENTRIES];
16110 +extern const struct desc_ptr debug_idt_descr;
16111 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16112
16113 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16114 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16115 {
16116 - return per_cpu(gdt_page, cpu).gdt;
16117 + return cpu_gdt_table[cpu];
16118 }
16119
16120 #ifdef CONFIG_X86_64
16121 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16122 unsigned long base, unsigned dpl, unsigned flags,
16123 unsigned short seg)
16124 {
16125 - gate->a = (seg << 16) | (base & 0xffff);
16126 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16127 + gate->gate.offset_low = base;
16128 + gate->gate.seg = seg;
16129 + gate->gate.reserved = 0;
16130 + gate->gate.type = type;
16131 + gate->gate.s = 0;
16132 + gate->gate.dpl = dpl;
16133 + gate->gate.p = 1;
16134 + gate->gate.offset_high = base >> 16;
16135 }
16136
16137 #endif
16138 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16139
16140 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16141 {
16142 + pax_open_kernel();
16143 memcpy(&idt[entry], gate, sizeof(*gate));
16144 + pax_close_kernel();
16145 }
16146
16147 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16148 {
16149 + pax_open_kernel();
16150 memcpy(&ldt[entry], desc, 8);
16151 + pax_close_kernel();
16152 }
16153
16154 static inline void
16155 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16156 default: size = sizeof(*gdt); break;
16157 }
16158
16159 + pax_open_kernel();
16160 memcpy(&gdt[entry], desc, size);
16161 + pax_close_kernel();
16162 }
16163
16164 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16165 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16166
16167 static inline void native_load_tr_desc(void)
16168 {
16169 + pax_open_kernel();
16170 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16171 + pax_close_kernel();
16172 }
16173
16174 static inline void native_load_gdt(const struct desc_ptr *dtr)
16175 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16176 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16177 unsigned int i;
16178
16179 + pax_open_kernel();
16180 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16181 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16182 + pax_close_kernel();
16183 }
16184
16185 #define _LDT_empty(info) \
16186 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16187 preempt_enable();
16188 }
16189
16190 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16191 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16192 {
16193 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16194 }
16195 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16196 }
16197
16198 #ifdef CONFIG_X86_64
16199 -static inline void set_nmi_gate(int gate, void *addr)
16200 +static inline void set_nmi_gate(int gate, const void *addr)
16201 {
16202 gate_desc s;
16203
16204 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16205 #endif
16206
16207 #ifdef CONFIG_TRACING
16208 -extern struct desc_ptr trace_idt_descr;
16209 -extern gate_desc trace_idt_table[];
16210 +extern const struct desc_ptr trace_idt_descr;
16211 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16212 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16213 {
16214 write_idt_entry(trace_idt_table, entry, gate);
16215 }
16216
16217 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16218 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16219 unsigned dpl, unsigned ist, unsigned seg)
16220 {
16221 gate_desc s;
16222 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16223 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16224 #endif
16225
16226 -static inline void _set_gate(int gate, unsigned type, void *addr,
16227 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16228 unsigned dpl, unsigned ist, unsigned seg)
16229 {
16230 gate_desc s;
16231 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16232 #define set_intr_gate(n, addr) \
16233 do { \
16234 BUG_ON((unsigned)n > 0xFF); \
16235 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16236 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16237 __KERNEL_CS); \
16238 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16239 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16240 0, 0, __KERNEL_CS); \
16241 } while (0)
16242
16243 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16244 /*
16245 * This routine sets up an interrupt gate at directory privilege level 3.
16246 */
16247 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16248 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16249 {
16250 BUG_ON((unsigned)n > 0xFF);
16251 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16252 }
16253
16254 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16255 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16256 {
16257 BUG_ON((unsigned)n > 0xFF);
16258 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16259 }
16260
16261 -static inline void set_trap_gate(unsigned int n, void *addr)
16262 +static inline void set_trap_gate(unsigned int n, const void *addr)
16263 {
16264 BUG_ON((unsigned)n > 0xFF);
16265 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16266 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16267 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16268 {
16269 BUG_ON((unsigned)n > 0xFF);
16270 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16271 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16272 }
16273
16274 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16275 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16276 {
16277 BUG_ON((unsigned)n > 0xFF);
16278 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16279 }
16280
16281 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16282 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16283 {
16284 BUG_ON((unsigned)n > 0xFF);
16285 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16286 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16287 else
16288 load_idt((const struct desc_ptr *)&idt_descr);
16289 }
16290 +
16291 +#ifdef CONFIG_X86_32
16292 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16293 +{
16294 + struct desc_struct d;
16295 +
16296 + if (likely(limit))
16297 + limit = (limit - 1UL) >> PAGE_SHIFT;
16298 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16299 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16300 +}
16301 +#endif
16302 +
16303 #endif /* _ASM_X86_DESC_H */
16304 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16305 index 278441f..b95a174 100644
16306 --- a/arch/x86/include/asm/desc_defs.h
16307 +++ b/arch/x86/include/asm/desc_defs.h
16308 @@ -31,6 +31,12 @@ struct desc_struct {
16309 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16310 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16311 };
16312 + struct {
16313 + u16 offset_low;
16314 + u16 seg;
16315 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16316 + unsigned offset_high: 16;
16317 + } gate;
16318 };
16319 } __attribute__((packed));
16320
16321 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16322 index ced283a..ffe04cc 100644
16323 --- a/arch/x86/include/asm/div64.h
16324 +++ b/arch/x86/include/asm/div64.h
16325 @@ -39,7 +39,7 @@
16326 __mod; \
16327 })
16328
16329 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16330 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16331 {
16332 union {
16333 u64 v64;
16334 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16335 index 9c999c1..3860cb8 100644
16336 --- a/arch/x86/include/asm/elf.h
16337 +++ b/arch/x86/include/asm/elf.h
16338 @@ -243,7 +243,25 @@ extern int force_personality32;
16339 the loader. We need to make sure that it is out of the way of the program
16340 that it will "exec", and that there is sufficient room for the brk. */
16341
16342 +#ifdef CONFIG_PAX_SEGMEXEC
16343 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16344 +#else
16345 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16346 +#endif
16347 +
16348 +#ifdef CONFIG_PAX_ASLR
16349 +#ifdef CONFIG_X86_32
16350 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16351 +
16352 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16353 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16354 +#else
16355 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16356 +
16357 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16358 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16359 +#endif
16360 +#endif
16361
16362 /* This yields a mask that user programs can use to figure out what
16363 instruction set this CPU supports. This could be done in user space,
16364 @@ -296,16 +314,12 @@ do { \
16365
16366 #define ARCH_DLINFO \
16367 do { \
16368 - if (vdso_enabled) \
16369 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16370 - (unsigned long)current->mm->context.vdso); \
16371 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16372 } while (0)
16373
16374 #define ARCH_DLINFO_X32 \
16375 do { \
16376 - if (vdso_enabled) \
16377 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16378 - (unsigned long)current->mm->context.vdso); \
16379 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16380 } while (0)
16381
16382 #define AT_SYSINFO 32
16383 @@ -320,7 +334,7 @@ else \
16384
16385 #endif /* !CONFIG_X86_32 */
16386
16387 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16388 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16389
16390 #define VDSO_ENTRY \
16391 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16392 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16393 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16394 #define compat_arch_setup_additional_pages syscall32_setup_pages
16395
16396 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16397 -#define arch_randomize_brk arch_randomize_brk
16398 -
16399 /*
16400 * True on X86_32 or when emulating IA32 on X86_64
16401 */
16402 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16403 index 77a99ac..39ff7f5 100644
16404 --- a/arch/x86/include/asm/emergency-restart.h
16405 +++ b/arch/x86/include/asm/emergency-restart.h
16406 @@ -1,6 +1,6 @@
16407 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16408 #define _ASM_X86_EMERGENCY_RESTART_H
16409
16410 -extern void machine_emergency_restart(void);
16411 +extern void machine_emergency_restart(void) __noreturn;
16412
16413 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16414 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16415 index d3d7469..677ef72 100644
16416 --- a/arch/x86/include/asm/floppy.h
16417 +++ b/arch/x86/include/asm/floppy.h
16418 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16419 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16420 } fd_routine[] = {
16421 {
16422 - request_dma,
16423 - free_dma,
16424 - get_dma_residue,
16425 - dma_mem_alloc,
16426 - hard_dma_setup
16427 + ._request_dma = request_dma,
16428 + ._free_dma = free_dma,
16429 + ._get_dma_residue = get_dma_residue,
16430 + ._dma_mem_alloc = dma_mem_alloc,
16431 + ._dma_setup = hard_dma_setup
16432 },
16433 {
16434 - vdma_request_dma,
16435 - vdma_nop,
16436 - vdma_get_dma_residue,
16437 - vdma_mem_alloc,
16438 - vdma_dma_setup
16439 + ._request_dma = vdma_request_dma,
16440 + ._free_dma = vdma_nop,
16441 + ._get_dma_residue = vdma_get_dma_residue,
16442 + ._dma_mem_alloc = vdma_mem_alloc,
16443 + ._dma_setup = vdma_dma_setup
16444 }
16445 };
16446
16447 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16448 index cea1c76..6c0d79b 100644
16449 --- a/arch/x86/include/asm/fpu-internal.h
16450 +++ b/arch/x86/include/asm/fpu-internal.h
16451 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16452 #define user_insn(insn, output, input...) \
16453 ({ \
16454 int err; \
16455 + pax_open_userland(); \
16456 asm volatile(ASM_STAC "\n" \
16457 - "1:" #insn "\n\t" \
16458 + "1:" \
16459 + __copyuser_seg \
16460 + #insn "\n\t" \
16461 "2: " ASM_CLAC "\n" \
16462 ".section .fixup,\"ax\"\n" \
16463 "3: movl $-1,%[err]\n" \
16464 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16465 _ASM_EXTABLE(1b, 3b) \
16466 : [err] "=r" (err), output \
16467 : "0"(0), input); \
16468 + pax_close_userland(); \
16469 err; \
16470 })
16471
16472 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16473 "fnclex\n\t"
16474 "emms\n\t"
16475 "fildl %P[addr]" /* set F?P to defined value */
16476 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16477 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16478 }
16479
16480 return fpu_restore_checking(&tsk->thread.fpu);
16481 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16482 index b4c1f54..e290c08 100644
16483 --- a/arch/x86/include/asm/futex.h
16484 +++ b/arch/x86/include/asm/futex.h
16485 @@ -12,6 +12,7 @@
16486 #include <asm/smap.h>
16487
16488 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16489 + typecheck(u32 __user *, uaddr); \
16490 asm volatile("\t" ASM_STAC "\n" \
16491 "1:\t" insn "\n" \
16492 "2:\t" ASM_CLAC "\n" \
16493 @@ -20,15 +21,16 @@
16494 "\tjmp\t2b\n" \
16495 "\t.previous\n" \
16496 _ASM_EXTABLE(1b, 3b) \
16497 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16498 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16499 : "i" (-EFAULT), "0" (oparg), "1" (0))
16500
16501 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16502 + typecheck(u32 __user *, uaddr); \
16503 asm volatile("\t" ASM_STAC "\n" \
16504 "1:\tmovl %2, %0\n" \
16505 "\tmovl\t%0, %3\n" \
16506 "\t" insn "\n" \
16507 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16508 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16509 "\tjnz\t1b\n" \
16510 "3:\t" ASM_CLAC "\n" \
16511 "\t.section .fixup,\"ax\"\n" \
16512 @@ -38,7 +40,7 @@
16513 _ASM_EXTABLE(1b, 4b) \
16514 _ASM_EXTABLE(2b, 4b) \
16515 : "=&a" (oldval), "=&r" (ret), \
16516 - "+m" (*uaddr), "=&r" (tem) \
16517 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16518 : "r" (oparg), "i" (-EFAULT), "1" (0))
16519
16520 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16521 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16522
16523 pagefault_disable();
16524
16525 + pax_open_userland();
16526 switch (op) {
16527 case FUTEX_OP_SET:
16528 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16529 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16530 break;
16531 case FUTEX_OP_ADD:
16532 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16533 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16534 uaddr, oparg);
16535 break;
16536 case FUTEX_OP_OR:
16537 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16538 default:
16539 ret = -ENOSYS;
16540 }
16541 + pax_close_userland();
16542
16543 pagefault_enable();
16544
16545 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16546 index 67d69b8..50e4b77 100644
16547 --- a/arch/x86/include/asm/hw_irq.h
16548 +++ b/arch/x86/include/asm/hw_irq.h
16549 @@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16550 extern void enable_IO_APIC(void);
16551
16552 /* Statistics */
16553 -extern atomic_t irq_err_count;
16554 -extern atomic_t irq_mis_count;
16555 +extern atomic_unchecked_t irq_err_count;
16556 +extern atomic_unchecked_t irq_mis_count;
16557
16558 /* EISA */
16559 extern void eisa_set_level_irq(unsigned int irq);
16560 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16561 index a203659..9889f1c 100644
16562 --- a/arch/x86/include/asm/i8259.h
16563 +++ b/arch/x86/include/asm/i8259.h
16564 @@ -62,7 +62,7 @@ struct legacy_pic {
16565 void (*init)(int auto_eoi);
16566 int (*irq_pending)(unsigned int irq);
16567 void (*make_irq)(unsigned int irq);
16568 -};
16569 +} __do_const;
16570
16571 extern struct legacy_pic *legacy_pic;
16572 extern struct legacy_pic null_legacy_pic;
16573 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16574 index 91d9c69..dfae7d0 100644
16575 --- a/arch/x86/include/asm/io.h
16576 +++ b/arch/x86/include/asm/io.h
16577 @@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16578 "m" (*(volatile type __force *)addr) barrier); }
16579
16580 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16581 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16582 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16583 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16584 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16585
16586 build_mmio_read(__readb, "b", unsigned char, "=q", )
16587 -build_mmio_read(__readw, "w", unsigned short, "=r", )
16588 -build_mmio_read(__readl, "l", unsigned int, "=r", )
16589 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16590 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16591
16592 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16593 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16594 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16595 return ioremap_nocache(offset, size);
16596 }
16597
16598 -extern void iounmap(volatile void __iomem *addr);
16599 +extern void iounmap(const volatile void __iomem *addr);
16600
16601 extern void set_iounmap_nonlazy(void);
16602
16603 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16604
16605 #include <linux/vmalloc.h>
16606
16607 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16608 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16609 +{
16610 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16611 +}
16612 +
16613 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16614 +{
16615 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16616 +}
16617 +
16618 /*
16619 * Convert a virtual cached pointer to an uncached pointer
16620 */
16621 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16622 index bba3cf8..06bc8da 100644
16623 --- a/arch/x86/include/asm/irqflags.h
16624 +++ b/arch/x86/include/asm/irqflags.h
16625 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16626 sti; \
16627 sysexit
16628
16629 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
16630 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16631 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
16632 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16633 +
16634 #else
16635 #define INTERRUPT_RETURN iret
16636 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16637 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16638 index 9454c16..e4100e3 100644
16639 --- a/arch/x86/include/asm/kprobes.h
16640 +++ b/arch/x86/include/asm/kprobes.h
16641 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16642 #define RELATIVEJUMP_SIZE 5
16643 #define RELATIVECALL_OPCODE 0xe8
16644 #define RELATIVE_ADDR_SIZE 4
16645 -#define MAX_STACK_SIZE 64
16646 -#define MIN_STACK_SIZE(ADDR) \
16647 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16648 - THREAD_SIZE - (unsigned long)(ADDR))) \
16649 - ? (MAX_STACK_SIZE) \
16650 - : (((unsigned long)current_thread_info()) + \
16651 - THREAD_SIZE - (unsigned long)(ADDR)))
16652 +#define MAX_STACK_SIZE 64UL
16653 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16654
16655 #define flush_insn_slot(p) do { } while (0)
16656
16657 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16658 index 4ad6560..75c7bdd 100644
16659 --- a/arch/x86/include/asm/local.h
16660 +++ b/arch/x86/include/asm/local.h
16661 @@ -10,33 +10,97 @@ typedef struct {
16662 atomic_long_t a;
16663 } local_t;
16664
16665 +typedef struct {
16666 + atomic_long_unchecked_t a;
16667 +} local_unchecked_t;
16668 +
16669 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16670
16671 #define local_read(l) atomic_long_read(&(l)->a)
16672 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16673 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16674 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16675
16676 static inline void local_inc(local_t *l)
16677 {
16678 - asm volatile(_ASM_INC "%0"
16679 + asm volatile(_ASM_INC "%0\n"
16680 +
16681 +#ifdef CONFIG_PAX_REFCOUNT
16682 + "jno 0f\n"
16683 + _ASM_DEC "%0\n"
16684 + "int $4\n0:\n"
16685 + _ASM_EXTABLE(0b, 0b)
16686 +#endif
16687 +
16688 + : "+m" (l->a.counter));
16689 +}
16690 +
16691 +static inline void local_inc_unchecked(local_unchecked_t *l)
16692 +{
16693 + asm volatile(_ASM_INC "%0\n"
16694 : "+m" (l->a.counter));
16695 }
16696
16697 static inline void local_dec(local_t *l)
16698 {
16699 - asm volatile(_ASM_DEC "%0"
16700 + asm volatile(_ASM_DEC "%0\n"
16701 +
16702 +#ifdef CONFIG_PAX_REFCOUNT
16703 + "jno 0f\n"
16704 + _ASM_INC "%0\n"
16705 + "int $4\n0:\n"
16706 + _ASM_EXTABLE(0b, 0b)
16707 +#endif
16708 +
16709 + : "+m" (l->a.counter));
16710 +}
16711 +
16712 +static inline void local_dec_unchecked(local_unchecked_t *l)
16713 +{
16714 + asm volatile(_ASM_DEC "%0\n"
16715 : "+m" (l->a.counter));
16716 }
16717
16718 static inline void local_add(long i, local_t *l)
16719 {
16720 - asm volatile(_ASM_ADD "%1,%0"
16721 + asm volatile(_ASM_ADD "%1,%0\n"
16722 +
16723 +#ifdef CONFIG_PAX_REFCOUNT
16724 + "jno 0f\n"
16725 + _ASM_SUB "%1,%0\n"
16726 + "int $4\n0:\n"
16727 + _ASM_EXTABLE(0b, 0b)
16728 +#endif
16729 +
16730 + : "+m" (l->a.counter)
16731 + : "ir" (i));
16732 +}
16733 +
16734 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
16735 +{
16736 + asm volatile(_ASM_ADD "%1,%0\n"
16737 : "+m" (l->a.counter)
16738 : "ir" (i));
16739 }
16740
16741 static inline void local_sub(long i, local_t *l)
16742 {
16743 - asm volatile(_ASM_SUB "%1,%0"
16744 + asm volatile(_ASM_SUB "%1,%0\n"
16745 +
16746 +#ifdef CONFIG_PAX_REFCOUNT
16747 + "jno 0f\n"
16748 + _ASM_ADD "%1,%0\n"
16749 + "int $4\n0:\n"
16750 + _ASM_EXTABLE(0b, 0b)
16751 +#endif
16752 +
16753 + : "+m" (l->a.counter)
16754 + : "ir" (i));
16755 +}
16756 +
16757 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16758 +{
16759 + asm volatile(_ASM_SUB "%1,%0\n"
16760 : "+m" (l->a.counter)
16761 : "ir" (i));
16762 }
16763 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16764 */
16765 static inline int local_sub_and_test(long i, local_t *l)
16766 {
16767 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16768 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16769 }
16770
16771 /**
16772 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16773 */
16774 static inline int local_dec_and_test(local_t *l)
16775 {
16776 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16777 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16778 }
16779
16780 /**
16781 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16782 */
16783 static inline int local_inc_and_test(local_t *l)
16784 {
16785 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16786 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16787 }
16788
16789 /**
16790 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16791 */
16792 static inline int local_add_negative(long i, local_t *l)
16793 {
16794 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16795 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16796 }
16797
16798 /**
16799 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16800 static inline long local_add_return(long i, local_t *l)
16801 {
16802 long __i = i;
16803 + asm volatile(_ASM_XADD "%0, %1\n"
16804 +
16805 +#ifdef CONFIG_PAX_REFCOUNT
16806 + "jno 0f\n"
16807 + _ASM_MOV "%0,%1\n"
16808 + "int $4\n0:\n"
16809 + _ASM_EXTABLE(0b, 0b)
16810 +#endif
16811 +
16812 + : "+r" (i), "+m" (l->a.counter)
16813 + : : "memory");
16814 + return i + __i;
16815 +}
16816 +
16817 +/**
16818 + * local_add_return_unchecked - add and return
16819 + * @i: integer value to add
16820 + * @l: pointer to type local_unchecked_t
16821 + *
16822 + * Atomically adds @i to @l and returns @i + @l
16823 + */
16824 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16825 +{
16826 + long __i = i;
16827 asm volatile(_ASM_XADD "%0, %1;"
16828 : "+r" (i), "+m" (l->a.counter)
16829 : : "memory");
16830 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16831
16832 #define local_cmpxchg(l, o, n) \
16833 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16834 +#define local_cmpxchg_unchecked(l, o, n) \
16835 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
16836 /* Always has a lock prefix */
16837 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16838
16839 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16840 new file mode 100644
16841 index 0000000..2bfd3ba
16842 --- /dev/null
16843 +++ b/arch/x86/include/asm/mman.h
16844 @@ -0,0 +1,15 @@
16845 +#ifndef _X86_MMAN_H
16846 +#define _X86_MMAN_H
16847 +
16848 +#include <uapi/asm/mman.h>
16849 +
16850 +#ifdef __KERNEL__
16851 +#ifndef __ASSEMBLY__
16852 +#ifdef CONFIG_X86_32
16853 +#define arch_mmap_check i386_mmap_check
16854 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16855 +#endif
16856 +#endif
16857 +#endif
16858 +
16859 +#endif /* X86_MMAN_H */
16860 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16861 index 5f55e69..e20bfb1 100644
16862 --- a/arch/x86/include/asm/mmu.h
16863 +++ b/arch/x86/include/asm/mmu.h
16864 @@ -9,7 +9,7 @@
16865 * we put the segment information here.
16866 */
16867 typedef struct {
16868 - void *ldt;
16869 + struct desc_struct *ldt;
16870 int size;
16871
16872 #ifdef CONFIG_X86_64
16873 @@ -18,7 +18,19 @@ typedef struct {
16874 #endif
16875
16876 struct mutex lock;
16877 - void *vdso;
16878 + unsigned long vdso;
16879 +
16880 +#ifdef CONFIG_X86_32
16881 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16882 + unsigned long user_cs_base;
16883 + unsigned long user_cs_limit;
16884 +
16885 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16886 + cpumask_t cpu_user_cs_mask;
16887 +#endif
16888 +
16889 +#endif
16890 +#endif
16891 } mm_context_t;
16892
16893 #ifdef CONFIG_SMP
16894 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16895 index be12c53..4d24039 100644
16896 --- a/arch/x86/include/asm/mmu_context.h
16897 +++ b/arch/x86/include/asm/mmu_context.h
16898 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
16899
16900 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
16901 {
16902 +
16903 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16904 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
16905 + unsigned int i;
16906 + pgd_t *pgd;
16907 +
16908 + pax_open_kernel();
16909 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
16910 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
16911 + set_pgd_batched(pgd+i, native_make_pgd(0));
16912 + pax_close_kernel();
16913 + }
16914 +#endif
16915 +
16916 #ifdef CONFIG_SMP
16917 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
16918 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
16919 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16920 struct task_struct *tsk)
16921 {
16922 unsigned cpu = smp_processor_id();
16923 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16924 + int tlbstate = TLBSTATE_OK;
16925 +#endif
16926
16927 if (likely(prev != next)) {
16928 #ifdef CONFIG_SMP
16929 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16930 + tlbstate = this_cpu_read(cpu_tlbstate.state);
16931 +#endif
16932 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16933 this_cpu_write(cpu_tlbstate.active_mm, next);
16934 #endif
16935 cpumask_set_cpu(cpu, mm_cpumask(next));
16936
16937 /* Re-load page tables */
16938 +#ifdef CONFIG_PAX_PER_CPU_PGD
16939 + pax_open_kernel();
16940 +
16941 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16942 + if (static_cpu_has(X86_FEATURE_PCID))
16943 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16944 + else
16945 +#endif
16946 +
16947 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16948 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16949 + pax_close_kernel();
16950 + 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));
16951 +
16952 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16953 + if (static_cpu_has(X86_FEATURE_PCID)) {
16954 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
16955 + u64 descriptor[2];
16956 + descriptor[0] = PCID_USER;
16957 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16958 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16959 + descriptor[0] = PCID_KERNEL;
16960 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16961 + }
16962 + } else {
16963 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16964 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16965 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16966 + else
16967 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16968 + }
16969 + } else
16970 +#endif
16971 +
16972 + load_cr3(get_cpu_pgd(cpu, kernel));
16973 +#else
16974 load_cr3(next->pgd);
16975 +#endif
16976
16977 /* Stop flush ipis for the previous mm */
16978 cpumask_clear_cpu(cpu, mm_cpumask(prev));
16979 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16980 /* Load the LDT, if the LDT is different: */
16981 if (unlikely(prev->context.ldt != next->context.ldt))
16982 load_LDT_nolock(&next->context);
16983 +
16984 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16985 + if (!(__supported_pte_mask & _PAGE_NX)) {
16986 + smp_mb__before_clear_bit();
16987 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
16988 + smp_mb__after_clear_bit();
16989 + cpu_set(cpu, next->context.cpu_user_cs_mask);
16990 + }
16991 +#endif
16992 +
16993 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16994 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
16995 + prev->context.user_cs_limit != next->context.user_cs_limit))
16996 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16997 +#ifdef CONFIG_SMP
16998 + else if (unlikely(tlbstate != TLBSTATE_OK))
16999 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17000 +#endif
17001 +#endif
17002 +
17003 }
17004 + else {
17005 +
17006 +#ifdef CONFIG_PAX_PER_CPU_PGD
17007 + pax_open_kernel();
17008 +
17009 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17010 + if (static_cpu_has(X86_FEATURE_PCID))
17011 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17012 + else
17013 +#endif
17014 +
17015 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17016 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17017 + pax_close_kernel();
17018 + 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));
17019 +
17020 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17021 + if (static_cpu_has(X86_FEATURE_PCID)) {
17022 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17023 + u64 descriptor[2];
17024 + descriptor[0] = PCID_USER;
17025 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17026 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17027 + descriptor[0] = PCID_KERNEL;
17028 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17029 + }
17030 + } else {
17031 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17032 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17033 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17034 + else
17035 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17036 + }
17037 + } else
17038 +#endif
17039 +
17040 + load_cr3(get_cpu_pgd(cpu, kernel));
17041 +#endif
17042 +
17043 #ifdef CONFIG_SMP
17044 - else {
17045 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17046 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17047
17048 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17049 * tlb flush IPI delivery. We must reload CR3
17050 * to make sure to use no freed page tables.
17051 */
17052 +
17053 +#ifndef CONFIG_PAX_PER_CPU_PGD
17054 load_cr3(next->pgd);
17055 +#endif
17056 +
17057 load_LDT_nolock(&next->context);
17058 +
17059 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17060 + if (!(__supported_pte_mask & _PAGE_NX))
17061 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17062 +#endif
17063 +
17064 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17065 +#ifdef CONFIG_PAX_PAGEEXEC
17066 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17067 +#endif
17068 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17069 +#endif
17070 +
17071 }
17072 +#endif
17073 }
17074 -#endif
17075 }
17076
17077 #define activate_mm(prev, next) \
17078 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17079 index e3b7819..b257c64 100644
17080 --- a/arch/x86/include/asm/module.h
17081 +++ b/arch/x86/include/asm/module.h
17082 @@ -5,6 +5,7 @@
17083
17084 #ifdef CONFIG_X86_64
17085 /* X86_64 does not define MODULE_PROC_FAMILY */
17086 +#define MODULE_PROC_FAMILY ""
17087 #elif defined CONFIG_M486
17088 #define MODULE_PROC_FAMILY "486 "
17089 #elif defined CONFIG_M586
17090 @@ -57,8 +58,20 @@
17091 #error unknown processor family
17092 #endif
17093
17094 -#ifdef CONFIG_X86_32
17095 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17096 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17097 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17098 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17099 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17100 +#else
17101 +#define MODULE_PAX_KERNEXEC ""
17102 #endif
17103
17104 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17105 +#define MODULE_PAX_UDEREF "UDEREF "
17106 +#else
17107 +#define MODULE_PAX_UDEREF ""
17108 +#endif
17109 +
17110 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17111 +
17112 #endif /* _ASM_X86_MODULE_H */
17113 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17114 index 86f9301..b365cda 100644
17115 --- a/arch/x86/include/asm/nmi.h
17116 +++ b/arch/x86/include/asm/nmi.h
17117 @@ -40,11 +40,11 @@ struct nmiaction {
17118 nmi_handler_t handler;
17119 unsigned long flags;
17120 const char *name;
17121 -};
17122 +} __do_const;
17123
17124 #define register_nmi_handler(t, fn, fg, n, init...) \
17125 ({ \
17126 - static struct nmiaction init fn##_na = { \
17127 + static const struct nmiaction init fn##_na = { \
17128 .handler = (fn), \
17129 .name = (n), \
17130 .flags = (fg), \
17131 @@ -52,7 +52,7 @@ struct nmiaction {
17132 __register_nmi_handler((t), &fn##_na); \
17133 })
17134
17135 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17136 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17137
17138 void unregister_nmi_handler(unsigned int, const char *);
17139
17140 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17141 index 775873d..de5f0304 100644
17142 --- a/arch/x86/include/asm/page.h
17143 +++ b/arch/x86/include/asm/page.h
17144 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17145 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17146
17147 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17148 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17149
17150 #define __boot_va(x) __va(x)
17151 #define __boot_pa(x) __pa(x)
17152 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17153 index 0f1ddee..e2fc3d1 100644
17154 --- a/arch/x86/include/asm/page_64.h
17155 +++ b/arch/x86/include/asm/page_64.h
17156 @@ -7,9 +7,9 @@
17157
17158 /* duplicated to the one in bootmem.h */
17159 extern unsigned long max_pfn;
17160 -extern unsigned long phys_base;
17161 +extern const unsigned long phys_base;
17162
17163 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17164 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17165 {
17166 unsigned long y = x - __START_KERNEL_map;
17167
17168 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17169 index cd6e1610..70f4418 100644
17170 --- a/arch/x86/include/asm/paravirt.h
17171 +++ b/arch/x86/include/asm/paravirt.h
17172 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17173 return (pmd_t) { ret };
17174 }
17175
17176 -static inline pmdval_t pmd_val(pmd_t pmd)
17177 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17178 {
17179 pmdval_t ret;
17180
17181 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17182 val);
17183 }
17184
17185 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17186 +{
17187 + pgdval_t val = native_pgd_val(pgd);
17188 +
17189 + if (sizeof(pgdval_t) > sizeof(long))
17190 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17191 + val, (u64)val >> 32);
17192 + else
17193 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17194 + val);
17195 +}
17196 +
17197 static inline void pgd_clear(pgd_t *pgdp)
17198 {
17199 set_pgd(pgdp, __pgd(0));
17200 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17201 pv_mmu_ops.set_fixmap(idx, phys, flags);
17202 }
17203
17204 +#ifdef CONFIG_PAX_KERNEXEC
17205 +static inline unsigned long pax_open_kernel(void)
17206 +{
17207 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17208 +}
17209 +
17210 +static inline unsigned long pax_close_kernel(void)
17211 +{
17212 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17213 +}
17214 +#else
17215 +static inline unsigned long pax_open_kernel(void) { return 0; }
17216 +static inline unsigned long pax_close_kernel(void) { return 0; }
17217 +#endif
17218 +
17219 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17220
17221 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17222 @@ -906,7 +933,7 @@ extern void default_banner(void);
17223
17224 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17225 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17226 -#define PARA_INDIRECT(addr) *%cs:addr
17227 +#define PARA_INDIRECT(addr) *%ss:addr
17228 #endif
17229
17230 #define INTERRUPT_RETURN \
17231 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17232 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17233 CLBR_NONE, \
17234 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17235 +
17236 +#define GET_CR0_INTO_RDI \
17237 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17238 + mov %rax,%rdi
17239 +
17240 +#define SET_RDI_INTO_CR0 \
17241 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17242 +
17243 +#define GET_CR3_INTO_RDI \
17244 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17245 + mov %rax,%rdi
17246 +
17247 +#define SET_RDI_INTO_CR3 \
17248 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17249 +
17250 #endif /* CONFIG_X86_32 */
17251
17252 #endif /* __ASSEMBLY__ */
17253 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17254 index 7549b8b..f0edfda 100644
17255 --- a/arch/x86/include/asm/paravirt_types.h
17256 +++ b/arch/x86/include/asm/paravirt_types.h
17257 @@ -84,7 +84,7 @@ struct pv_init_ops {
17258 */
17259 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17260 unsigned long addr, unsigned len);
17261 -};
17262 +} __no_const __no_randomize_layout;
17263
17264
17265 struct pv_lazy_ops {
17266 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17267 void (*enter)(void);
17268 void (*leave)(void);
17269 void (*flush)(void);
17270 -};
17271 +} __no_randomize_layout;
17272
17273 struct pv_time_ops {
17274 unsigned long long (*sched_clock)(void);
17275 unsigned long long (*steal_clock)(int cpu);
17276 unsigned long (*get_tsc_khz)(void);
17277 -};
17278 +} __no_const __no_randomize_layout;
17279
17280 struct pv_cpu_ops {
17281 /* hooks for various privileged instructions */
17282 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17283
17284 void (*start_context_switch)(struct task_struct *prev);
17285 void (*end_context_switch)(struct task_struct *next);
17286 -};
17287 +} __no_const __no_randomize_layout;
17288
17289 struct pv_irq_ops {
17290 /*
17291 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17292 #ifdef CONFIG_X86_64
17293 void (*adjust_exception_frame)(void);
17294 #endif
17295 -};
17296 +} __no_randomize_layout;
17297
17298 struct pv_apic_ops {
17299 #ifdef CONFIG_X86_LOCAL_APIC
17300 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17301 unsigned long start_eip,
17302 unsigned long start_esp);
17303 #endif
17304 -};
17305 +} __no_const __no_randomize_layout;
17306
17307 struct pv_mmu_ops {
17308 unsigned long (*read_cr2)(void);
17309 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17310 struct paravirt_callee_save make_pud;
17311
17312 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17313 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17314 #endif /* PAGETABLE_LEVELS == 4 */
17315 #endif /* PAGETABLE_LEVELS >= 3 */
17316
17317 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17318 an mfn. We can tell which is which from the index. */
17319 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17320 phys_addr_t phys, pgprot_t flags);
17321 -};
17322 +
17323 +#ifdef CONFIG_PAX_KERNEXEC
17324 + unsigned long (*pax_open_kernel)(void);
17325 + unsigned long (*pax_close_kernel)(void);
17326 +#endif
17327 +
17328 +} __no_randomize_layout;
17329
17330 struct arch_spinlock;
17331 #ifdef CONFIG_SMP
17332 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17333 struct pv_lock_ops {
17334 struct paravirt_callee_save lock_spinning;
17335 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17336 -};
17337 +} __no_randomize_layout;
17338
17339 /* This contains all the paravirt structures: we get a convenient
17340 * number for each function using the offset which we use to indicate
17341 - * what to patch. */
17342 + * what to patch.
17343 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17344 + */
17345 +
17346 struct paravirt_patch_template {
17347 struct pv_init_ops pv_init_ops;
17348 struct pv_time_ops pv_time_ops;
17349 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17350 struct pv_apic_ops pv_apic_ops;
17351 struct pv_mmu_ops pv_mmu_ops;
17352 struct pv_lock_ops pv_lock_ops;
17353 -};
17354 +} __no_randomize_layout;
17355
17356 extern struct pv_info pv_info;
17357 extern struct pv_init_ops pv_init_ops;
17358 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17359 index c4412e9..90e88c5 100644
17360 --- a/arch/x86/include/asm/pgalloc.h
17361 +++ b/arch/x86/include/asm/pgalloc.h
17362 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17363 pmd_t *pmd, pte_t *pte)
17364 {
17365 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17366 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17367 +}
17368 +
17369 +static inline void pmd_populate_user(struct mm_struct *mm,
17370 + pmd_t *pmd, pte_t *pte)
17371 +{
17372 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17373 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17374 }
17375
17376 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17377
17378 #ifdef CONFIG_X86_PAE
17379 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17380 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17381 +{
17382 + pud_populate(mm, pudp, pmd);
17383 +}
17384 #else /* !CONFIG_X86_PAE */
17385 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17386 {
17387 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17388 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17389 }
17390 +
17391 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17392 +{
17393 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17394 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17395 +}
17396 #endif /* CONFIG_X86_PAE */
17397
17398 #if PAGETABLE_LEVELS > 3
17399 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17400 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17401 }
17402
17403 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17404 +{
17405 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17406 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17407 +}
17408 +
17409 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17410 {
17411 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17412 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17413 index 0d193e2..bf59aeb 100644
17414 --- a/arch/x86/include/asm/pgtable-2level.h
17415 +++ b/arch/x86/include/asm/pgtable-2level.h
17416 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17417
17418 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17419 {
17420 + pax_open_kernel();
17421 *pmdp = pmd;
17422 + pax_close_kernel();
17423 }
17424
17425 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17426 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17427 index 81bb91b..9392125 100644
17428 --- a/arch/x86/include/asm/pgtable-3level.h
17429 +++ b/arch/x86/include/asm/pgtable-3level.h
17430 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17431
17432 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17433 {
17434 + pax_open_kernel();
17435 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17436 + pax_close_kernel();
17437 }
17438
17439 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17440 {
17441 + pax_open_kernel();
17442 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17443 + pax_close_kernel();
17444 }
17445
17446 /*
17447 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17448 index bbc8b12..f228861 100644
17449 --- a/arch/x86/include/asm/pgtable.h
17450 +++ b/arch/x86/include/asm/pgtable.h
17451 @@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17452
17453 #ifndef __PAGETABLE_PUD_FOLDED
17454 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17455 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17456 #define pgd_clear(pgd) native_pgd_clear(pgd)
17457 #endif
17458
17459 @@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17460
17461 #define arch_end_context_switch(prev) do {} while(0)
17462
17463 +#define pax_open_kernel() native_pax_open_kernel()
17464 +#define pax_close_kernel() native_pax_close_kernel()
17465 #endif /* CONFIG_PARAVIRT */
17466
17467 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
17468 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17469 +
17470 +#ifdef CONFIG_PAX_KERNEXEC
17471 +static inline unsigned long native_pax_open_kernel(void)
17472 +{
17473 + unsigned long cr0;
17474 +
17475 + preempt_disable();
17476 + barrier();
17477 + cr0 = read_cr0() ^ X86_CR0_WP;
17478 + BUG_ON(cr0 & X86_CR0_WP);
17479 + write_cr0(cr0);
17480 + return cr0 ^ X86_CR0_WP;
17481 +}
17482 +
17483 +static inline unsigned long native_pax_close_kernel(void)
17484 +{
17485 + unsigned long cr0;
17486 +
17487 + cr0 = read_cr0() ^ X86_CR0_WP;
17488 + BUG_ON(!(cr0 & X86_CR0_WP));
17489 + write_cr0(cr0);
17490 + barrier();
17491 + preempt_enable_no_resched();
17492 + return cr0 ^ X86_CR0_WP;
17493 +}
17494 +#else
17495 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
17496 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
17497 +#endif
17498 +
17499 /*
17500 * The following only work if pte_present() is true.
17501 * Undefined behaviour if not..
17502 */
17503 +static inline int pte_user(pte_t pte)
17504 +{
17505 + return pte_val(pte) & _PAGE_USER;
17506 +}
17507 +
17508 static inline int pte_dirty(pte_t pte)
17509 {
17510 return pte_flags(pte) & _PAGE_DIRTY;
17511 @@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17512 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17513 }
17514
17515 +static inline unsigned long pgd_pfn(pgd_t pgd)
17516 +{
17517 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17518 +}
17519 +
17520 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17521
17522 static inline int pmd_large(pmd_t pte)
17523 @@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17524 return pte_clear_flags(pte, _PAGE_RW);
17525 }
17526
17527 +static inline pte_t pte_mkread(pte_t pte)
17528 +{
17529 + return __pte(pte_val(pte) | _PAGE_USER);
17530 +}
17531 +
17532 static inline pte_t pte_mkexec(pte_t pte)
17533 {
17534 - return pte_clear_flags(pte, _PAGE_NX);
17535 +#ifdef CONFIG_X86_PAE
17536 + if (__supported_pte_mask & _PAGE_NX)
17537 + return pte_clear_flags(pte, _PAGE_NX);
17538 + else
17539 +#endif
17540 + return pte_set_flags(pte, _PAGE_USER);
17541 +}
17542 +
17543 +static inline pte_t pte_exprotect(pte_t pte)
17544 +{
17545 +#ifdef CONFIG_X86_PAE
17546 + if (__supported_pte_mask & _PAGE_NX)
17547 + return pte_set_flags(pte, _PAGE_NX);
17548 + else
17549 +#endif
17550 + return pte_clear_flags(pte, _PAGE_USER);
17551 }
17552
17553 static inline pte_t pte_mkdirty(pte_t pte)
17554 @@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17555 #endif
17556
17557 #ifndef __ASSEMBLY__
17558 +
17559 +#ifdef CONFIG_PAX_PER_CPU_PGD
17560 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17561 +enum cpu_pgd_type {kernel = 0, user = 1};
17562 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17563 +{
17564 + return cpu_pgd[cpu][type];
17565 +}
17566 +#endif
17567 +
17568 #include <linux/mm_types.h>
17569 #include <linux/mmdebug.h>
17570 #include <linux/log2.h>
17571 @@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17572 * Currently stuck as a macro due to indirect forward reference to
17573 * linux/mmzone.h's __section_mem_map_addr() definition:
17574 */
17575 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17576 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17577
17578 /* Find an entry in the second-level page table.. */
17579 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17580 @@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17581 * Currently stuck as a macro due to indirect forward reference to
17582 * linux/mmzone.h's __section_mem_map_addr() definition:
17583 */
17584 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17585 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17586
17587 /* to find an entry in a page-table-directory. */
17588 static inline unsigned long pud_index(unsigned long address)
17589 @@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17590
17591 static inline int pgd_bad(pgd_t pgd)
17592 {
17593 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17594 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17595 }
17596
17597 static inline int pgd_none(pgd_t pgd)
17598 @@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17599 * pgd_offset() returns a (pgd_t *)
17600 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17601 */
17602 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17603 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17604 +
17605 +#ifdef CONFIG_PAX_PER_CPU_PGD
17606 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17607 +#endif
17608 +
17609 /*
17610 * a shortcut which implies the use of the kernel's pgd, instead
17611 * of a process's
17612 @@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17613 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17614 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17615
17616 +#ifdef CONFIG_X86_32
17617 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17618 +#else
17619 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17620 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17621 +
17622 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17623 +#ifdef __ASSEMBLY__
17624 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
17625 +#else
17626 +extern unsigned long pax_user_shadow_base;
17627 +extern pgdval_t clone_pgd_mask;
17628 +#endif
17629 +#endif
17630 +
17631 +#endif
17632 +
17633 #ifndef __ASSEMBLY__
17634
17635 extern int direct_gbpages;
17636 @@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17637 * dst and src can be on the same page, but the range must not overlap,
17638 * and must not cross a page boundary.
17639 */
17640 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17641 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17642 {
17643 - memcpy(dst, src, count * sizeof(pgd_t));
17644 + pax_open_kernel();
17645 + while (count--)
17646 + *dst++ = *src++;
17647 + pax_close_kernel();
17648 }
17649
17650 +#ifdef CONFIG_PAX_PER_CPU_PGD
17651 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17652 +#endif
17653 +
17654 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17655 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17656 +#else
17657 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17658 +#endif
17659 +
17660 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17661 static inline int page_level_shift(enum pg_level level)
17662 {
17663 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17664 index 9ee3221..b979c6b 100644
17665 --- a/arch/x86/include/asm/pgtable_32.h
17666 +++ b/arch/x86/include/asm/pgtable_32.h
17667 @@ -25,9 +25,6 @@
17668 struct mm_struct;
17669 struct vm_area_struct;
17670
17671 -extern pgd_t swapper_pg_dir[1024];
17672 -extern pgd_t initial_page_table[1024];
17673 -
17674 static inline void pgtable_cache_init(void) { }
17675 static inline void check_pgt_cache(void) { }
17676 void paging_init(void);
17677 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17678 # include <asm/pgtable-2level.h>
17679 #endif
17680
17681 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17682 +extern pgd_t initial_page_table[PTRS_PER_PGD];
17683 +#ifdef CONFIG_X86_PAE
17684 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17685 +#endif
17686 +
17687 #if defined(CONFIG_HIGHPTE)
17688 #define pte_offset_map(dir, address) \
17689 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17690 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17691 /* Clear a kernel PTE and flush it from the TLB */
17692 #define kpte_clear_flush(ptep, vaddr) \
17693 do { \
17694 + pax_open_kernel(); \
17695 pte_clear(&init_mm, (vaddr), (ptep)); \
17696 + pax_close_kernel(); \
17697 __flush_tlb_one((vaddr)); \
17698 } while (0)
17699
17700 #endif /* !__ASSEMBLY__ */
17701
17702 +#define HAVE_ARCH_UNMAPPED_AREA
17703 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17704 +
17705 /*
17706 * kern_addr_valid() is (1) for FLATMEM and (0) for
17707 * SPARSEMEM and DISCONTIGMEM
17708 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17709 index ed5903b..c7fe163 100644
17710 --- a/arch/x86/include/asm/pgtable_32_types.h
17711 +++ b/arch/x86/include/asm/pgtable_32_types.h
17712 @@ -8,7 +8,7 @@
17713 */
17714 #ifdef CONFIG_X86_PAE
17715 # include <asm/pgtable-3level_types.h>
17716 -# define PMD_SIZE (1UL << PMD_SHIFT)
17717 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17718 # define PMD_MASK (~(PMD_SIZE - 1))
17719 #else
17720 # include <asm/pgtable-2level_types.h>
17721 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17722 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17723 #endif
17724
17725 +#ifdef CONFIG_PAX_KERNEXEC
17726 +#ifndef __ASSEMBLY__
17727 +extern unsigned char MODULES_EXEC_VADDR[];
17728 +extern unsigned char MODULES_EXEC_END[];
17729 +#endif
17730 +#include <asm/boot.h>
17731 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17732 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17733 +#else
17734 +#define ktla_ktva(addr) (addr)
17735 +#define ktva_ktla(addr) (addr)
17736 +#endif
17737 +
17738 #define MODULES_VADDR VMALLOC_START
17739 #define MODULES_END VMALLOC_END
17740 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17741 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17742 index e22c1db..23a625a 100644
17743 --- a/arch/x86/include/asm/pgtable_64.h
17744 +++ b/arch/x86/include/asm/pgtable_64.h
17745 @@ -16,10 +16,14 @@
17746
17747 extern pud_t level3_kernel_pgt[512];
17748 extern pud_t level3_ident_pgt[512];
17749 +extern pud_t level3_vmalloc_start_pgt[512];
17750 +extern pud_t level3_vmalloc_end_pgt[512];
17751 +extern pud_t level3_vmemmap_pgt[512];
17752 +extern pud_t level2_vmemmap_pgt[512];
17753 extern pmd_t level2_kernel_pgt[512];
17754 extern pmd_t level2_fixmap_pgt[512];
17755 -extern pmd_t level2_ident_pgt[512];
17756 -extern pgd_t init_level4_pgt[];
17757 +extern pmd_t level2_ident_pgt[512*2];
17758 +extern pgd_t init_level4_pgt[512];
17759
17760 #define swapper_pg_dir init_level4_pgt
17761
17762 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17763
17764 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17765 {
17766 + pax_open_kernel();
17767 *pmdp = pmd;
17768 + pax_close_kernel();
17769 }
17770
17771 static inline void native_pmd_clear(pmd_t *pmd)
17772 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17773
17774 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17775 {
17776 + pax_open_kernel();
17777 *pudp = pud;
17778 + pax_close_kernel();
17779 }
17780
17781 static inline void native_pud_clear(pud_t *pud)
17782 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17783
17784 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17785 {
17786 + pax_open_kernel();
17787 + *pgdp = pgd;
17788 + pax_close_kernel();
17789 +}
17790 +
17791 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17792 +{
17793 *pgdp = pgd;
17794 }
17795
17796 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17797 index c883bf7..19970b3 100644
17798 --- a/arch/x86/include/asm/pgtable_64_types.h
17799 +++ b/arch/x86/include/asm/pgtable_64_types.h
17800 @@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17801 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
17802 #define MODULES_END _AC(0xffffffffff000000, UL)
17803 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17804 +#define MODULES_EXEC_VADDR MODULES_VADDR
17805 +#define MODULES_EXEC_END MODULES_END
17806 +
17807 +#define ktla_ktva(addr) (addr)
17808 +#define ktva_ktla(addr) (addr)
17809
17810 #define EARLY_DYNAMIC_PAGE_TABLES 64
17811
17812 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17813 index 94e40f1..ebd03e4 100644
17814 --- a/arch/x86/include/asm/pgtable_types.h
17815 +++ b/arch/x86/include/asm/pgtable_types.h
17816 @@ -16,13 +16,12 @@
17817 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17818 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17819 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17820 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17821 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17822 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17823 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17824 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17825 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17826 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17827 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17828 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17829 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17830 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17831
17832 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17833 @@ -40,7 +39,6 @@
17834 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17835 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17836 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17837 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17838 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17839 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17840 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17841 @@ -87,8 +85,10 @@
17842
17843 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17844 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17845 -#else
17846 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17847 #define _PAGE_NX (_AT(pteval_t, 0))
17848 +#else
17849 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17850 #endif
17851
17852 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17853 @@ -147,6 +147,9 @@
17854 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17855 _PAGE_ACCESSED)
17856
17857 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
17858 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
17859 +
17860 #define __PAGE_KERNEL_EXEC \
17861 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17862 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17863 @@ -157,7 +160,7 @@
17864 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17865 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17866 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17867 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17868 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17869 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17870 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17871 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17872 @@ -219,8 +222,8 @@
17873 * bits are combined, this will alow user to access the high address mapped
17874 * VDSO in the presence of CONFIG_COMPAT_VDSO
17875 */
17876 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
17877 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
17878 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17879 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17880 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
17881 #endif
17882
17883 @@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
17884 {
17885 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
17886 }
17887 +#endif
17888
17889 +#if PAGETABLE_LEVELS == 3
17890 +#include <asm-generic/pgtable-nopud.h>
17891 +#endif
17892 +
17893 +#if PAGETABLE_LEVELS == 2
17894 +#include <asm-generic/pgtable-nopmd.h>
17895 +#endif
17896 +
17897 +#ifndef __ASSEMBLY__
17898 #if PAGETABLE_LEVELS > 3
17899 typedef struct { pudval_t pud; } pud_t;
17900
17901 @@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
17902 return pud.pud;
17903 }
17904 #else
17905 -#include <asm-generic/pgtable-nopud.h>
17906 -
17907 static inline pudval_t native_pud_val(pud_t pud)
17908 {
17909 return native_pgd_val(pud.pgd);
17910 @@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
17911 return pmd.pmd;
17912 }
17913 #else
17914 -#include <asm-generic/pgtable-nopmd.h>
17915 -
17916 static inline pmdval_t native_pmd_val(pmd_t pmd)
17917 {
17918 return native_pgd_val(pmd.pud.pgd);
17919 @@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
17920
17921 extern pteval_t __supported_pte_mask;
17922 extern void set_nx(void);
17923 -extern int nx_enabled;
17924
17925 #define pgprot_writecombine pgprot_writecombine
17926 extern pgprot_t pgprot_writecombine(pgprot_t prot);
17927 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
17928 index c8b0519..fd29e73 100644
17929 --- a/arch/x86/include/asm/preempt.h
17930 +++ b/arch/x86/include/asm/preempt.h
17931 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
17932 */
17933 static __always_inline bool __preempt_count_dec_and_test(void)
17934 {
17935 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
17936 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
17937 }
17938
17939 /*
17940 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
17941 index fdedd38..95c02c2 100644
17942 --- a/arch/x86/include/asm/processor.h
17943 +++ b/arch/x86/include/asm/processor.h
17944 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
17945 /* Index into per_cpu list: */
17946 u16 cpu_index;
17947 u32 microcode;
17948 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
17949 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
17950
17951 #define X86_VENDOR_INTEL 0
17952 #define X86_VENDOR_CYRIX 1
17953 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
17954 : "memory");
17955 }
17956
17957 +/* invpcid (%rdx),%rax */
17958 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
17959 +
17960 +#define INVPCID_SINGLE_ADDRESS 0UL
17961 +#define INVPCID_SINGLE_CONTEXT 1UL
17962 +#define INVPCID_ALL_GLOBAL 2UL
17963 +#define INVPCID_ALL_MONGLOBAL 3UL
17964 +
17965 +#define PCID_KERNEL 0UL
17966 +#define PCID_USER 1UL
17967 +#define PCID_NOFLUSH (1UL << 63)
17968 +
17969 static inline void load_cr3(pgd_t *pgdir)
17970 {
17971 - write_cr3(__pa(pgdir));
17972 + write_cr3(__pa(pgdir) | PCID_KERNEL);
17973 }
17974
17975 #ifdef CONFIG_X86_32
17976 @@ -283,7 +295,7 @@ struct tss_struct {
17977
17978 } ____cacheline_aligned;
17979
17980 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
17981 +extern struct tss_struct init_tss[NR_CPUS];
17982
17983 /*
17984 * Save the original ist values for checking stack pointers during debugging
17985 @@ -470,6 +482,7 @@ struct thread_struct {
17986 unsigned short ds;
17987 unsigned short fsindex;
17988 unsigned short gsindex;
17989 + unsigned short ss;
17990 #endif
17991 #ifdef CONFIG_X86_32
17992 unsigned long ip;
17993 @@ -579,29 +592,8 @@ static inline void load_sp0(struct tss_struct *tss,
17994 extern unsigned long mmu_cr4_features;
17995 extern u32 *trampoline_cr4_features;
17996
17997 -static inline void set_in_cr4(unsigned long mask)
17998 -{
17999 - unsigned long cr4;
18000 -
18001 - mmu_cr4_features |= mask;
18002 - if (trampoline_cr4_features)
18003 - *trampoline_cr4_features = mmu_cr4_features;
18004 - cr4 = read_cr4();
18005 - cr4 |= mask;
18006 - write_cr4(cr4);
18007 -}
18008 -
18009 -static inline void clear_in_cr4(unsigned long mask)
18010 -{
18011 - unsigned long cr4;
18012 -
18013 - mmu_cr4_features &= ~mask;
18014 - if (trampoline_cr4_features)
18015 - *trampoline_cr4_features = mmu_cr4_features;
18016 - cr4 = read_cr4();
18017 - cr4 &= ~mask;
18018 - write_cr4(cr4);
18019 -}
18020 +extern void set_in_cr4(unsigned long mask);
18021 +extern void clear_in_cr4(unsigned long mask);
18022
18023 typedef struct {
18024 unsigned long seg;
18025 @@ -827,11 +819,18 @@ static inline void spin_lock_prefetch(const void *x)
18026 */
18027 #define TASK_SIZE PAGE_OFFSET
18028 #define TASK_SIZE_MAX TASK_SIZE
18029 +
18030 +#ifdef CONFIG_PAX_SEGMEXEC
18031 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18032 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18033 +#else
18034 #define STACK_TOP TASK_SIZE
18035 -#define STACK_TOP_MAX STACK_TOP
18036 +#endif
18037 +
18038 +#define STACK_TOP_MAX TASK_SIZE
18039
18040 #define INIT_THREAD { \
18041 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18042 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18043 .vm86_info = NULL, \
18044 .sysenter_cs = __KERNEL_CS, \
18045 .io_bitmap_ptr = NULL, \
18046 @@ -845,7 +844,7 @@ static inline void spin_lock_prefetch(const void *x)
18047 */
18048 #define INIT_TSS { \
18049 .x86_tss = { \
18050 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18051 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18052 .ss0 = __KERNEL_DS, \
18053 .ss1 = __KERNEL_CS, \
18054 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18055 @@ -856,11 +855,7 @@ static inline void spin_lock_prefetch(const void *x)
18056 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18057
18058 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18059 -#define KSTK_TOP(info) \
18060 -({ \
18061 - unsigned long *__ptr = (unsigned long *)(info); \
18062 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18063 -})
18064 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18065
18066 /*
18067 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18068 @@ -875,7 +870,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18069 #define task_pt_regs(task) \
18070 ({ \
18071 struct pt_regs *__regs__; \
18072 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18073 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18074 __regs__ - 1; \
18075 })
18076
18077 @@ -885,13 +880,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18078 /*
18079 * User space process size. 47bits minus one guard page.
18080 */
18081 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18082 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18083
18084 /* This decides where the kernel will search for a free chunk of vm
18085 * space during mmap's.
18086 */
18087 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18088 - 0xc0000000 : 0xFFFFe000)
18089 + 0xc0000000 : 0xFFFFf000)
18090
18091 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18092 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18093 @@ -902,11 +897,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18094 #define STACK_TOP_MAX TASK_SIZE_MAX
18095
18096 #define INIT_THREAD { \
18097 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18098 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18099 }
18100
18101 #define INIT_TSS { \
18102 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18103 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18104 }
18105
18106 /*
18107 @@ -934,6 +929,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18108 */
18109 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18110
18111 +#ifdef CONFIG_PAX_SEGMEXEC
18112 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18113 +#endif
18114 +
18115 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18116
18117 /* Get/set a process' ability to use the timestamp counter instruction */
18118 @@ -960,7 +959,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18119 return 0;
18120 }
18121
18122 -extern unsigned long arch_align_stack(unsigned long sp);
18123 +#define arch_align_stack(x) ((x) & ~0xfUL)
18124 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18125
18126 void default_idle(void);
18127 @@ -970,6 +969,6 @@ bool xen_set_default_idle(void);
18128 #define xen_set_default_idle 0
18129 #endif
18130
18131 -void stop_this_cpu(void *dummy);
18132 +void stop_this_cpu(void *dummy) __noreturn;
18133 void df_debug(struct pt_regs *regs, long error_code);
18134 #endif /* _ASM_X86_PROCESSOR_H */
18135 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18136 index 14fd6fd..6740420 100644
18137 --- a/arch/x86/include/asm/ptrace.h
18138 +++ b/arch/x86/include/asm/ptrace.h
18139 @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18140 }
18141
18142 /*
18143 - * user_mode_vm(regs) determines whether a register set came from user mode.
18144 + * user_mode(regs) determines whether a register set came from user mode.
18145 * This is true if V8086 mode was enabled OR if the register set was from
18146 * protected mode with RPL-3 CS value. This tricky test checks that with
18147 * one comparison. Many places in the kernel can bypass this full check
18148 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18149 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18150 + * be used.
18151 */
18152 -static inline int user_mode(struct pt_regs *regs)
18153 +static inline int user_mode_novm(struct pt_regs *regs)
18154 {
18155 #ifdef CONFIG_X86_32
18156 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18157 #else
18158 - return !!(regs->cs & 3);
18159 + return !!(regs->cs & SEGMENT_RPL_MASK);
18160 #endif
18161 }
18162
18163 -static inline int user_mode_vm(struct pt_regs *regs)
18164 +static inline int user_mode(struct pt_regs *regs)
18165 {
18166 #ifdef CONFIG_X86_32
18167 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18168 USER_RPL;
18169 #else
18170 - return user_mode(regs);
18171 + return user_mode_novm(regs);
18172 #endif
18173 }
18174
18175 @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18176 #ifdef CONFIG_X86_64
18177 static inline bool user_64bit_mode(struct pt_regs *regs)
18178 {
18179 + unsigned long cs = regs->cs & 0xffff;
18180 #ifndef CONFIG_PARAVIRT
18181 /*
18182 * On non-paravirt systems, this is the only long mode CPL 3
18183 * selector. We do not allow long mode selectors in the LDT.
18184 */
18185 - return regs->cs == __USER_CS;
18186 + return cs == __USER_CS;
18187 #else
18188 /* Headers are too twisted for this to go in paravirt.h. */
18189 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18190 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18191 #endif
18192 }
18193
18194 @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18195 * Traps from the kernel do not save sp and ss.
18196 * Use the helper function to retrieve sp.
18197 */
18198 - if (offset == offsetof(struct pt_regs, sp) &&
18199 - regs->cs == __KERNEL_CS)
18200 - return kernel_stack_pointer(regs);
18201 + if (offset == offsetof(struct pt_regs, sp)) {
18202 + unsigned long cs = regs->cs & 0xffff;
18203 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18204 + return kernel_stack_pointer(regs);
18205 + }
18206 #endif
18207 return *(unsigned long *)((unsigned long)regs + offset);
18208 }
18209 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18210 index 9c6b890..5305f53 100644
18211 --- a/arch/x86/include/asm/realmode.h
18212 +++ b/arch/x86/include/asm/realmode.h
18213 @@ -22,16 +22,14 @@ struct real_mode_header {
18214 #endif
18215 /* APM/BIOS reboot */
18216 u32 machine_real_restart_asm;
18217 -#ifdef CONFIG_X86_64
18218 u32 machine_real_restart_seg;
18219 -#endif
18220 };
18221
18222 /* This must match data at trampoline_32/64.S */
18223 struct trampoline_header {
18224 #ifdef CONFIG_X86_32
18225 u32 start;
18226 - u16 gdt_pad;
18227 + u16 boot_cs;
18228 u16 gdt_limit;
18229 u32 gdt_base;
18230 #else
18231 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18232 index a82c4f1..ac45053 100644
18233 --- a/arch/x86/include/asm/reboot.h
18234 +++ b/arch/x86/include/asm/reboot.h
18235 @@ -6,13 +6,13 @@
18236 struct pt_regs;
18237
18238 struct machine_ops {
18239 - void (*restart)(char *cmd);
18240 - void (*halt)(void);
18241 - void (*power_off)(void);
18242 + void (* __noreturn restart)(char *cmd);
18243 + void (* __noreturn halt)(void);
18244 + void (* __noreturn power_off)(void);
18245 void (*shutdown)(void);
18246 void (*crash_shutdown)(struct pt_regs *);
18247 - void (*emergency_restart)(void);
18248 -};
18249 + void (* __noreturn emergency_restart)(void);
18250 +} __no_const;
18251
18252 extern struct machine_ops machine_ops;
18253
18254 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18255 index 8f7866a..e442f20 100644
18256 --- a/arch/x86/include/asm/rmwcc.h
18257 +++ b/arch/x86/include/asm/rmwcc.h
18258 @@ -3,7 +3,34 @@
18259
18260 #ifdef CC_HAVE_ASM_GOTO
18261
18262 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18263 +#ifdef CONFIG_PAX_REFCOUNT
18264 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18265 +do { \
18266 + asm_volatile_goto (fullop \
18267 + ";jno 0f\n" \
18268 + fullantiop \
18269 + ";int $4\n0:\n" \
18270 + _ASM_EXTABLE(0b, 0b) \
18271 + ";j" cc " %l[cc_label]" \
18272 + : : "m" (var), ## __VA_ARGS__ \
18273 + : "memory" : cc_label); \
18274 + return 0; \
18275 +cc_label: \
18276 + return 1; \
18277 +} while (0)
18278 +#else
18279 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18280 +do { \
18281 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18282 + : : "m" (var), ## __VA_ARGS__ \
18283 + : "memory" : cc_label); \
18284 + return 0; \
18285 +cc_label: \
18286 + return 1; \
18287 +} while (0)
18288 +#endif
18289 +
18290 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18291 do { \
18292 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18293 : : "m" (var), ## __VA_ARGS__ \
18294 @@ -13,15 +40,46 @@ cc_label: \
18295 return 1; \
18296 } while (0)
18297
18298 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18299 - __GEN_RMWcc(op " " arg0, var, cc)
18300 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18301 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18302
18303 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18304 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18305 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18306 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18307 +
18308 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18309 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18310 +
18311 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18312 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18313
18314 #else /* !CC_HAVE_ASM_GOTO */
18315
18316 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18317 +#ifdef CONFIG_PAX_REFCOUNT
18318 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18319 +do { \
18320 + char c; \
18321 + asm volatile (fullop \
18322 + ";jno 0f\n" \
18323 + fullantiop \
18324 + ";int $4\n0:\n" \
18325 + _ASM_EXTABLE(0b, 0b) \
18326 + "; set" cc " %1" \
18327 + : "+m" (var), "=qm" (c) \
18328 + : __VA_ARGS__ : "memory"); \
18329 + return c != 0; \
18330 +} while (0)
18331 +#else
18332 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18333 +do { \
18334 + char c; \
18335 + asm volatile (fullop "; set" cc " %1" \
18336 + : "+m" (var), "=qm" (c) \
18337 + : __VA_ARGS__ : "memory"); \
18338 + return c != 0; \
18339 +} while (0)
18340 +#endif
18341 +
18342 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18343 do { \
18344 char c; \
18345 asm volatile (fullop "; set" cc " %1" \
18346 @@ -30,11 +88,17 @@ do { \
18347 return c != 0; \
18348 } while (0)
18349
18350 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18351 - __GEN_RMWcc(op " " arg0, var, cc)
18352 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18353 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18354 +
18355 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18356 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18357 +
18358 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18359 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18360
18361 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18362 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18363 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18364 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18365
18366 #endif /* CC_HAVE_ASM_GOTO */
18367
18368 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18369 index cad82c9..2e5c5c1 100644
18370 --- a/arch/x86/include/asm/rwsem.h
18371 +++ b/arch/x86/include/asm/rwsem.h
18372 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18373 {
18374 asm volatile("# beginning down_read\n\t"
18375 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18376 +
18377 +#ifdef CONFIG_PAX_REFCOUNT
18378 + "jno 0f\n"
18379 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18380 + "int $4\n0:\n"
18381 + _ASM_EXTABLE(0b, 0b)
18382 +#endif
18383 +
18384 /* adds 0x00000001 */
18385 " jns 1f\n"
18386 " call call_rwsem_down_read_failed\n"
18387 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18388 "1:\n\t"
18389 " mov %1,%2\n\t"
18390 " add %3,%2\n\t"
18391 +
18392 +#ifdef CONFIG_PAX_REFCOUNT
18393 + "jno 0f\n"
18394 + "sub %3,%2\n"
18395 + "int $4\n0:\n"
18396 + _ASM_EXTABLE(0b, 0b)
18397 +#endif
18398 +
18399 " jle 2f\n\t"
18400 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18401 " jnz 1b\n\t"
18402 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18403 long tmp;
18404 asm volatile("# beginning down_write\n\t"
18405 LOCK_PREFIX " xadd %1,(%2)\n\t"
18406 +
18407 +#ifdef CONFIG_PAX_REFCOUNT
18408 + "jno 0f\n"
18409 + "mov %1,(%2)\n"
18410 + "int $4\n0:\n"
18411 + _ASM_EXTABLE(0b, 0b)
18412 +#endif
18413 +
18414 /* adds 0xffff0001, returns the old value */
18415 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18416 /* was the active mask 0 before? */
18417 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18418 long tmp;
18419 asm volatile("# beginning __up_read\n\t"
18420 LOCK_PREFIX " xadd %1,(%2)\n\t"
18421 +
18422 +#ifdef CONFIG_PAX_REFCOUNT
18423 + "jno 0f\n"
18424 + "mov %1,(%2)\n"
18425 + "int $4\n0:\n"
18426 + _ASM_EXTABLE(0b, 0b)
18427 +#endif
18428 +
18429 /* subtracts 1, returns the old value */
18430 " jns 1f\n\t"
18431 " call call_rwsem_wake\n" /* expects old value in %edx */
18432 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18433 long tmp;
18434 asm volatile("# beginning __up_write\n\t"
18435 LOCK_PREFIX " xadd %1,(%2)\n\t"
18436 +
18437 +#ifdef CONFIG_PAX_REFCOUNT
18438 + "jno 0f\n"
18439 + "mov %1,(%2)\n"
18440 + "int $4\n0:\n"
18441 + _ASM_EXTABLE(0b, 0b)
18442 +#endif
18443 +
18444 /* subtracts 0xffff0001, returns the old value */
18445 " jns 1f\n\t"
18446 " call call_rwsem_wake\n" /* expects old value in %edx */
18447 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18448 {
18449 asm volatile("# beginning __downgrade_write\n\t"
18450 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18451 +
18452 +#ifdef CONFIG_PAX_REFCOUNT
18453 + "jno 0f\n"
18454 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18455 + "int $4\n0:\n"
18456 + _ASM_EXTABLE(0b, 0b)
18457 +#endif
18458 +
18459 /*
18460 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18461 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18462 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18463 */
18464 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18465 {
18466 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18467 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18468 +
18469 +#ifdef CONFIG_PAX_REFCOUNT
18470 + "jno 0f\n"
18471 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
18472 + "int $4\n0:\n"
18473 + _ASM_EXTABLE(0b, 0b)
18474 +#endif
18475 +
18476 : "+m" (sem->count)
18477 : "er" (delta));
18478 }
18479 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18480 */
18481 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18482 {
18483 - return delta + xadd(&sem->count, delta);
18484 + return delta + xadd_check_overflow(&sem->count, delta);
18485 }
18486
18487 #endif /* __KERNEL__ */
18488 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18489 index 6f1c3a8..7744f19 100644
18490 --- a/arch/x86/include/asm/segment.h
18491 +++ b/arch/x86/include/asm/segment.h
18492 @@ -64,10 +64,15 @@
18493 * 26 - ESPFIX small SS
18494 * 27 - per-cpu [ offset to per-cpu data area ]
18495 * 28 - stack_canary-20 [ for stack protector ]
18496 - * 29 - unused
18497 - * 30 - unused
18498 + * 29 - PCI BIOS CS
18499 + * 30 - PCI BIOS DS
18500 * 31 - TSS for double fault handler
18501 */
18502 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18503 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18504 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18505 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18506 +
18507 #define GDT_ENTRY_TLS_MIN 6
18508 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18509
18510 @@ -79,6 +84,8 @@
18511
18512 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18513
18514 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18515 +
18516 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18517
18518 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18519 @@ -104,6 +111,12 @@
18520 #define __KERNEL_STACK_CANARY 0
18521 #endif
18522
18523 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18524 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18525 +
18526 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18527 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18528 +
18529 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18530
18531 /*
18532 @@ -141,7 +154,7 @@
18533 */
18534
18535 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18536 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18537 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18538
18539
18540 #else
18541 @@ -165,6 +178,8 @@
18542 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18543 #define __USER32_DS __USER_DS
18544
18545 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18546 +
18547 #define GDT_ENTRY_TSS 8 /* needs two entries */
18548 #define GDT_ENTRY_LDT 10 /* needs two entries */
18549 #define GDT_ENTRY_TLS_MIN 12
18550 @@ -173,6 +188,8 @@
18551 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18552 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18553
18554 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18555 +
18556 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18557 #define FS_TLS 0
18558 #define GS_TLS 1
18559 @@ -180,12 +197,14 @@
18560 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18561 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18562
18563 -#define GDT_ENTRIES 16
18564 +#define GDT_ENTRIES 17
18565
18566 #endif
18567
18568 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18569 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18570 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18571 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18572 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18573 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18574 #ifndef CONFIG_PARAVIRT
18575 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18576 {
18577 unsigned long __limit;
18578 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18579 - return __limit + 1;
18580 + return __limit;
18581 }
18582
18583 #endif /* !__ASSEMBLY__ */
18584 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18585 index 8d3120f..352b440 100644
18586 --- a/arch/x86/include/asm/smap.h
18587 +++ b/arch/x86/include/asm/smap.h
18588 @@ -25,11 +25,40 @@
18589
18590 #include <asm/alternative-asm.h>
18591
18592 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18593 +#define ASM_PAX_OPEN_USERLAND \
18594 + 661: jmp 663f; \
18595 + .pushsection .altinstr_replacement, "a" ; \
18596 + 662: pushq %rax; nop; \
18597 + .popsection ; \
18598 + .pushsection .altinstructions, "a" ; \
18599 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18600 + .popsection ; \
18601 + call __pax_open_userland; \
18602 + popq %rax; \
18603 + 663:
18604 +
18605 +#define ASM_PAX_CLOSE_USERLAND \
18606 + 661: jmp 663f; \
18607 + .pushsection .altinstr_replacement, "a" ; \
18608 + 662: pushq %rax; nop; \
18609 + .popsection; \
18610 + .pushsection .altinstructions, "a" ; \
18611 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18612 + .popsection; \
18613 + call __pax_close_userland; \
18614 + popq %rax; \
18615 + 663:
18616 +#else
18617 +#define ASM_PAX_OPEN_USERLAND
18618 +#define ASM_PAX_CLOSE_USERLAND
18619 +#endif
18620 +
18621 #ifdef CONFIG_X86_SMAP
18622
18623 #define ASM_CLAC \
18624 661: ASM_NOP3 ; \
18625 - .pushsection .altinstr_replacement, "ax" ; \
18626 + .pushsection .altinstr_replacement, "a" ; \
18627 662: __ASM_CLAC ; \
18628 .popsection ; \
18629 .pushsection .altinstructions, "a" ; \
18630 @@ -38,7 +67,7 @@
18631
18632 #define ASM_STAC \
18633 661: ASM_NOP3 ; \
18634 - .pushsection .altinstr_replacement, "ax" ; \
18635 + .pushsection .altinstr_replacement, "a" ; \
18636 662: __ASM_STAC ; \
18637 .popsection ; \
18638 .pushsection .altinstructions, "a" ; \
18639 @@ -56,6 +85,37 @@
18640
18641 #include <asm/alternative.h>
18642
18643 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
18644 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18645 +
18646 +extern void __pax_open_userland(void);
18647 +static __always_inline unsigned long pax_open_userland(void)
18648 +{
18649 +
18650 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18651 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18652 + :
18653 + : [open] "i" (__pax_open_userland)
18654 + : "memory", "rax");
18655 +#endif
18656 +
18657 + return 0;
18658 +}
18659 +
18660 +extern void __pax_close_userland(void);
18661 +static __always_inline unsigned long pax_close_userland(void)
18662 +{
18663 +
18664 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18665 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18666 + :
18667 + : [close] "i" (__pax_close_userland)
18668 + : "memory", "rax");
18669 +#endif
18670 +
18671 + return 0;
18672 +}
18673 +
18674 #ifdef CONFIG_X86_SMAP
18675
18676 static __always_inline void clac(void)
18677 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18678 index 8cd27e0..7f05ec8 100644
18679 --- a/arch/x86/include/asm/smp.h
18680 +++ b/arch/x86/include/asm/smp.h
18681 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18682 /* cpus sharing the last level cache: */
18683 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18684 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18685 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18686 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18687
18688 static inline struct cpumask *cpu_sibling_mask(int cpu)
18689 {
18690 @@ -78,7 +78,7 @@ struct smp_ops {
18691
18692 void (*send_call_func_ipi)(const struct cpumask *mask);
18693 void (*send_call_func_single_ipi)(int cpu);
18694 -};
18695 +} __no_const;
18696
18697 /* Globals due to paravirt */
18698 extern void set_cpu_sibling_map(int cpu);
18699 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
18700 extern int safe_smp_processor_id(void);
18701
18702 #elif defined(CONFIG_X86_64_SMP)
18703 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18704 -
18705 -#define stack_smp_processor_id() \
18706 -({ \
18707 - struct thread_info *ti; \
18708 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18709 - ti->cpu; \
18710 -})
18711 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18712 +#define stack_smp_processor_id() raw_smp_processor_id()
18713 #define safe_smp_processor_id() smp_processor_id()
18714
18715 #endif
18716 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18717 index 0f62f54..cb5d0dd 100644
18718 --- a/arch/x86/include/asm/spinlock.h
18719 +++ b/arch/x86/include/asm/spinlock.h
18720 @@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18721 static inline void arch_read_lock(arch_rwlock_t *rw)
18722 {
18723 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18724 +
18725 +#ifdef CONFIG_PAX_REFCOUNT
18726 + "jno 0f\n"
18727 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18728 + "int $4\n0:\n"
18729 + _ASM_EXTABLE(0b, 0b)
18730 +#endif
18731 +
18732 "jns 1f\n"
18733 "call __read_lock_failed\n\t"
18734 "1:\n"
18735 @@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18736 static inline void arch_write_lock(arch_rwlock_t *rw)
18737 {
18738 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18739 +
18740 +#ifdef CONFIG_PAX_REFCOUNT
18741 + "jno 0f\n"
18742 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18743 + "int $4\n0:\n"
18744 + _ASM_EXTABLE(0b, 0b)
18745 +#endif
18746 +
18747 "jz 1f\n"
18748 "call __write_lock_failed\n\t"
18749 "1:\n"
18750 @@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18751
18752 static inline void arch_read_unlock(arch_rwlock_t *rw)
18753 {
18754 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18755 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18756 +
18757 +#ifdef CONFIG_PAX_REFCOUNT
18758 + "jno 0f\n"
18759 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18760 + "int $4\n0:\n"
18761 + _ASM_EXTABLE(0b, 0b)
18762 +#endif
18763 +
18764 :"+m" (rw->lock) : : "memory");
18765 }
18766
18767 static inline void arch_write_unlock(arch_rwlock_t *rw)
18768 {
18769 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18770 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18771 +
18772 +#ifdef CONFIG_PAX_REFCOUNT
18773 + "jno 0f\n"
18774 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18775 + "int $4\n0:\n"
18776 + _ASM_EXTABLE(0b, 0b)
18777 +#endif
18778 +
18779 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18780 }
18781
18782 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18783 index 6a99859..03cb807 100644
18784 --- a/arch/x86/include/asm/stackprotector.h
18785 +++ b/arch/x86/include/asm/stackprotector.h
18786 @@ -47,7 +47,7 @@
18787 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18788 */
18789 #define GDT_STACK_CANARY_INIT \
18790 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18791 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18792
18793 /*
18794 * Initialize the stackprotector canary value.
18795 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18796
18797 static inline void load_stack_canary_segment(void)
18798 {
18799 -#ifdef CONFIG_X86_32
18800 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18801 asm volatile ("mov %0, %%gs" : : "r" (0));
18802 #endif
18803 }
18804 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18805 index 70bbe39..4ae2bd4 100644
18806 --- a/arch/x86/include/asm/stacktrace.h
18807 +++ b/arch/x86/include/asm/stacktrace.h
18808 @@ -11,28 +11,20 @@
18809
18810 extern int kstack_depth_to_print;
18811
18812 -struct thread_info;
18813 +struct task_struct;
18814 struct stacktrace_ops;
18815
18816 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18817 - unsigned long *stack,
18818 - unsigned long bp,
18819 - const struct stacktrace_ops *ops,
18820 - void *data,
18821 - unsigned long *end,
18822 - int *graph);
18823 +typedef unsigned long walk_stack_t(struct task_struct *task,
18824 + void *stack_start,
18825 + unsigned long *stack,
18826 + unsigned long bp,
18827 + const struct stacktrace_ops *ops,
18828 + void *data,
18829 + unsigned long *end,
18830 + int *graph);
18831
18832 -extern unsigned long
18833 -print_context_stack(struct thread_info *tinfo,
18834 - unsigned long *stack, unsigned long bp,
18835 - const struct stacktrace_ops *ops, void *data,
18836 - unsigned long *end, int *graph);
18837 -
18838 -extern unsigned long
18839 -print_context_stack_bp(struct thread_info *tinfo,
18840 - unsigned long *stack, unsigned long bp,
18841 - const struct stacktrace_ops *ops, void *data,
18842 - unsigned long *end, int *graph);
18843 +extern walk_stack_t print_context_stack;
18844 +extern walk_stack_t print_context_stack_bp;
18845
18846 /* Generic stack tracer with callbacks */
18847
18848 @@ -40,7 +32,7 @@ struct stacktrace_ops {
18849 void (*address)(void *data, unsigned long address, int reliable);
18850 /* On negative return stop dumping */
18851 int (*stack)(void *data, char *name);
18852 - walk_stack_t walk_stack;
18853 + walk_stack_t *walk_stack;
18854 };
18855
18856 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18857 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18858 index d7f3b3b..3cc39f1 100644
18859 --- a/arch/x86/include/asm/switch_to.h
18860 +++ b/arch/x86/include/asm/switch_to.h
18861 @@ -108,7 +108,7 @@ do { \
18862 "call __switch_to\n\t" \
18863 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18864 __switch_canary \
18865 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
18866 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18867 "movq %%rax,%%rdi\n\t" \
18868 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18869 "jnz ret_from_fork\n\t" \
18870 @@ -119,7 +119,7 @@ do { \
18871 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18872 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18873 [_tif_fork] "i" (_TIF_FORK), \
18874 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
18875 + [thread_info] "m" (current_tinfo), \
18876 [current_task] "m" (current_task) \
18877 __switch_canary_iparam \
18878 : "memory", "cc" __EXTRA_CLOBBER)
18879 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
18880 index e1940c0..ac50dd8 100644
18881 --- a/arch/x86/include/asm/thread_info.h
18882 +++ b/arch/x86/include/asm/thread_info.h
18883 @@ -10,6 +10,7 @@
18884 #include <linux/compiler.h>
18885 #include <asm/page.h>
18886 #include <asm/types.h>
18887 +#include <asm/percpu.h>
18888
18889 /*
18890 * low level task data that entry.S needs immediate access to
18891 @@ -23,7 +24,6 @@ struct exec_domain;
18892 #include <linux/atomic.h>
18893
18894 struct thread_info {
18895 - struct task_struct *task; /* main task structure */
18896 struct exec_domain *exec_domain; /* execution domain */
18897 __u32 flags; /* low level flags */
18898 __u32 status; /* thread synchronous flags */
18899 @@ -32,19 +32,13 @@ struct thread_info {
18900 mm_segment_t addr_limit;
18901 struct restart_block restart_block;
18902 void __user *sysenter_return;
18903 -#ifdef CONFIG_X86_32
18904 - unsigned long previous_esp; /* ESP of the previous stack in
18905 - case of nested (IRQ) stacks
18906 - */
18907 - __u8 supervisor_stack[0];
18908 -#endif
18909 + unsigned long lowest_stack;
18910 unsigned int sig_on_uaccess_error:1;
18911 unsigned int uaccess_err:1; /* uaccess failed */
18912 };
18913
18914 -#define INIT_THREAD_INFO(tsk) \
18915 +#define INIT_THREAD_INFO \
18916 { \
18917 - .task = &tsk, \
18918 .exec_domain = &default_exec_domain, \
18919 .flags = 0, \
18920 .cpu = 0, \
18921 @@ -55,7 +49,7 @@ struct thread_info {
18922 }, \
18923 }
18924
18925 -#define init_thread_info (init_thread_union.thread_info)
18926 +#define init_thread_info (init_thread_union.stack)
18927 #define init_stack (init_thread_union.stack)
18928
18929 #else /* !__ASSEMBLY__ */
18930 @@ -95,6 +89,7 @@ struct thread_info {
18931 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
18932 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
18933 #define TIF_X32 30 /* 32-bit native x86-64 binary */
18934 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
18935
18936 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
18937 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
18938 @@ -118,17 +113,18 @@ struct thread_info {
18939 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
18940 #define _TIF_ADDR32 (1 << TIF_ADDR32)
18941 #define _TIF_X32 (1 << TIF_X32)
18942 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
18943
18944 /* work to do in syscall_trace_enter() */
18945 #define _TIF_WORK_SYSCALL_ENTRY \
18946 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
18947 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
18948 - _TIF_NOHZ)
18949 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
18950
18951 /* work to do in syscall_trace_leave() */
18952 #define _TIF_WORK_SYSCALL_EXIT \
18953 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
18954 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
18955 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
18956
18957 /* work to do on interrupt/exception return */
18958 #define _TIF_WORK_MASK \
18959 @@ -139,7 +135,7 @@ struct thread_info {
18960 /* work to do on any return to user space */
18961 #define _TIF_ALLWORK_MASK \
18962 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
18963 - _TIF_NOHZ)
18964 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
18965
18966 /* Only used for 64 bit */
18967 #define _TIF_DO_NOTIFY_MASK \
18968 @@ -153,6 +149,23 @@ struct thread_info {
18969 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
18970 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
18971
18972 +#ifdef __ASSEMBLY__
18973 +/* how to get the thread information struct from ASM */
18974 +#define GET_THREAD_INFO(reg) \
18975 + mov PER_CPU_VAR(current_tinfo), reg
18976 +
18977 +/* use this one if reg already contains %esp */
18978 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
18979 +#else
18980 +/* how to get the thread information struct from C */
18981 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
18982 +
18983 +static __always_inline struct thread_info *current_thread_info(void)
18984 +{
18985 + return this_cpu_read_stable(current_tinfo);
18986 +}
18987 +#endif
18988 +
18989 #ifdef CONFIG_X86_32
18990
18991 #define STACK_WARN (THREAD_SIZE/8)
18992 @@ -169,31 +182,10 @@ struct thread_info {
18993 sp; \
18994 })
18995
18996 -/* how to get the thread information struct from C */
18997 -static inline struct thread_info *current_thread_info(void)
18998 -{
18999 - return (struct thread_info *)
19000 - (current_stack_pointer & ~(THREAD_SIZE - 1));
19001 -}
19002 -
19003 -#else /* !__ASSEMBLY__ */
19004 -
19005 -/* how to get the thread information struct from ASM */
19006 -#define GET_THREAD_INFO(reg) \
19007 - movl $-THREAD_SIZE, reg; \
19008 - andl %esp, reg
19009 -
19010 -/* use this one if reg already contains %esp */
19011 -#define GET_THREAD_INFO_WITH_ESP(reg) \
19012 - andl $-THREAD_SIZE, reg
19013 -
19014 #endif
19015
19016 #else /* X86_32 */
19017
19018 -#include <asm/percpu.h>
19019 -#define KERNEL_STACK_OFFSET (5*8)
19020 -
19021 /*
19022 * macros/functions for gaining access to the thread information structure
19023 * preempt_count needs to be 1 initially, until the scheduler is functional.
19024 @@ -201,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
19025 #ifndef __ASSEMBLY__
19026 DECLARE_PER_CPU(unsigned long, kernel_stack);
19027
19028 -static inline struct thread_info *current_thread_info(void)
19029 -{
19030 - struct thread_info *ti;
19031 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19032 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19033 - return ti;
19034 -}
19035 -
19036 -#else /* !__ASSEMBLY__ */
19037 -
19038 -/* how to get the thread information struct from ASM */
19039 -#define GET_THREAD_INFO(reg) \
19040 - movq PER_CPU_VAR(kernel_stack),reg ; \
19041 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19042 -
19043 -/*
19044 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19045 - * a certain register (to be used in assembler memory operands).
19046 - */
19047 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19048 -
19049 +/* how to get the current stack pointer from C */
19050 +register unsigned long current_stack_pointer asm("rsp") __used;
19051 #endif
19052
19053 #endif /* !X86_32 */
19054 @@ -280,5 +253,12 @@ static inline bool is_ia32_task(void)
19055 extern void arch_task_cache_init(void);
19056 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19057 extern void arch_release_task_struct(struct task_struct *tsk);
19058 +
19059 +#define __HAVE_THREAD_FUNCTIONS
19060 +#define task_thread_info(task) (&(task)->tinfo)
19061 +#define task_stack_page(task) ((task)->stack)
19062 +#define setup_thread_stack(p, org) do {} while (0)
19063 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19064 +
19065 #endif
19066 #endif /* _ASM_X86_THREAD_INFO_H */
19067 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19068 index 04905bf..49203ca 100644
19069 --- a/arch/x86/include/asm/tlbflush.h
19070 +++ b/arch/x86/include/asm/tlbflush.h
19071 @@ -17,18 +17,44 @@
19072
19073 static inline void __native_flush_tlb(void)
19074 {
19075 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19076 + u64 descriptor[2];
19077 +
19078 + descriptor[0] = PCID_KERNEL;
19079 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19080 + return;
19081 + }
19082 +
19083 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19084 + if (static_cpu_has(X86_FEATURE_PCID)) {
19085 + unsigned int cpu = raw_get_cpu();
19086 +
19087 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19088 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19089 + raw_put_cpu_no_resched();
19090 + return;
19091 + }
19092 +#endif
19093 +
19094 native_write_cr3(native_read_cr3());
19095 }
19096
19097 static inline void __native_flush_tlb_global_irq_disabled(void)
19098 {
19099 - unsigned long cr4;
19100 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19101 + u64 descriptor[2];
19102
19103 - cr4 = native_read_cr4();
19104 - /* clear PGE */
19105 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19106 - /* write old PGE again and flush TLBs */
19107 - native_write_cr4(cr4);
19108 + descriptor[0] = PCID_KERNEL;
19109 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19110 + } else {
19111 + unsigned long cr4;
19112 +
19113 + cr4 = native_read_cr4();
19114 + /* clear PGE */
19115 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19116 + /* write old PGE again and flush TLBs */
19117 + native_write_cr4(cr4);
19118 + }
19119 }
19120
19121 static inline void __native_flush_tlb_global(void)
19122 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19123
19124 static inline void __native_flush_tlb_single(unsigned long addr)
19125 {
19126 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19127 + u64 descriptor[2];
19128 +
19129 + descriptor[0] = PCID_KERNEL;
19130 + descriptor[1] = addr;
19131 +
19132 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19133 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19134 + if (addr < TASK_SIZE_MAX)
19135 + descriptor[1] += pax_user_shadow_base;
19136 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19137 + }
19138 +
19139 + descriptor[0] = PCID_USER;
19140 + descriptor[1] = addr;
19141 +#endif
19142 +
19143 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19144 + return;
19145 + }
19146 +
19147 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19148 + if (static_cpu_has(X86_FEATURE_PCID)) {
19149 + unsigned int cpu = raw_get_cpu();
19150 +
19151 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19152 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19153 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19154 + raw_put_cpu_no_resched();
19155 +
19156 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19157 + addr += pax_user_shadow_base;
19158 + }
19159 +#endif
19160 +
19161 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19162 }
19163
19164 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19165 index 0d592e0..f58a222 100644
19166 --- a/arch/x86/include/asm/uaccess.h
19167 +++ b/arch/x86/include/asm/uaccess.h
19168 @@ -7,6 +7,7 @@
19169 #include <linux/compiler.h>
19170 #include <linux/thread_info.h>
19171 #include <linux/string.h>
19172 +#include <linux/spinlock.h>
19173 #include <asm/asm.h>
19174 #include <asm/page.h>
19175 #include <asm/smap.h>
19176 @@ -29,7 +30,12 @@
19177
19178 #define get_ds() (KERNEL_DS)
19179 #define get_fs() (current_thread_info()->addr_limit)
19180 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19181 +void __set_fs(mm_segment_t x);
19182 +void set_fs(mm_segment_t x);
19183 +#else
19184 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19185 +#endif
19186
19187 #define segment_eq(a, b) ((a).seg == (b).seg)
19188
19189 @@ -85,8 +91,34 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19190 * checks that the pointer is in the user space range - after calling
19191 * this function, memory access functions may still return -EFAULT.
19192 */
19193 -#define access_ok(type, addr, size) \
19194 - likely(!__range_not_ok(addr, size, user_addr_max()))
19195 +extern int _cond_resched(void);
19196 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19197 +#define access_ok(type, addr, size) \
19198 +({ \
19199 + long __size = size; \
19200 + unsigned long __addr = (unsigned long)addr; \
19201 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19202 + unsigned long __end_ao = __addr + __size - 1; \
19203 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19204 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19205 + while(__addr_ao <= __end_ao) { \
19206 + char __c_ao; \
19207 + __addr_ao += PAGE_SIZE; \
19208 + if (__size > PAGE_SIZE) \
19209 + _cond_resched(); \
19210 + if (__get_user(__c_ao, (char __user *)__addr)) \
19211 + break; \
19212 + if (type != VERIFY_WRITE) { \
19213 + __addr = __addr_ao; \
19214 + continue; \
19215 + } \
19216 + if (__put_user(__c_ao, (char __user *)__addr)) \
19217 + break; \
19218 + __addr = __addr_ao; \
19219 + } \
19220 + } \
19221 + __ret_ao; \
19222 +})
19223
19224 /*
19225 * The exception table consists of pairs of addresses relative to the
19226 @@ -176,10 +208,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19227 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19228 __chk_user_ptr(ptr); \
19229 might_fault(); \
19230 + pax_open_userland(); \
19231 asm volatile("call __get_user_%P3" \
19232 : "=a" (__ret_gu), "=r" (__val_gu) \
19233 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19234 (x) = (__typeof__(*(ptr))) __val_gu; \
19235 + pax_close_userland(); \
19236 __ret_gu; \
19237 })
19238
19239 @@ -187,13 +221,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19240 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19241 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19242
19243 -
19244 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19245 +#define __copyuser_seg "gs;"
19246 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19247 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19248 +#else
19249 +#define __copyuser_seg
19250 +#define __COPYUSER_SET_ES
19251 +#define __COPYUSER_RESTORE_ES
19252 +#endif
19253
19254 #ifdef CONFIG_X86_32
19255 #define __put_user_asm_u64(x, addr, err, errret) \
19256 asm volatile(ASM_STAC "\n" \
19257 - "1: movl %%eax,0(%2)\n" \
19258 - "2: movl %%edx,4(%2)\n" \
19259 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19260 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19261 "3: " ASM_CLAC "\n" \
19262 ".section .fixup,\"ax\"\n" \
19263 "4: movl %3,%0\n" \
19264 @@ -206,8 +248,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19265
19266 #define __put_user_asm_ex_u64(x, addr) \
19267 asm volatile(ASM_STAC "\n" \
19268 - "1: movl %%eax,0(%1)\n" \
19269 - "2: movl %%edx,4(%1)\n" \
19270 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19271 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19272 "3: " ASM_CLAC "\n" \
19273 _ASM_EXTABLE_EX(1b, 2b) \
19274 _ASM_EXTABLE_EX(2b, 3b) \
19275 @@ -257,7 +299,8 @@ extern void __put_user_8(void);
19276 __typeof__(*(ptr)) __pu_val; \
19277 __chk_user_ptr(ptr); \
19278 might_fault(); \
19279 - __pu_val = x; \
19280 + __pu_val = (x); \
19281 + pax_open_userland(); \
19282 switch (sizeof(*(ptr))) { \
19283 case 1: \
19284 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19285 @@ -275,6 +318,7 @@ extern void __put_user_8(void);
19286 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19287 break; \
19288 } \
19289 + pax_close_userland(); \
19290 __ret_pu; \
19291 })
19292
19293 @@ -355,8 +399,10 @@ do { \
19294 } while (0)
19295
19296 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19297 +do { \
19298 + pax_open_userland(); \
19299 asm volatile(ASM_STAC "\n" \
19300 - "1: mov"itype" %2,%"rtype"1\n" \
19301 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19302 "2: " ASM_CLAC "\n" \
19303 ".section .fixup,\"ax\"\n" \
19304 "3: mov %3,%0\n" \
19305 @@ -364,8 +410,10 @@ do { \
19306 " jmp 2b\n" \
19307 ".previous\n" \
19308 _ASM_EXTABLE(1b, 3b) \
19309 - : "=r" (err), ltype(x) \
19310 - : "m" (__m(addr)), "i" (errret), "0" (err))
19311 + : "=r" (err), ltype (x) \
19312 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19313 + pax_close_userland(); \
19314 +} while (0)
19315
19316 #define __get_user_size_ex(x, ptr, size) \
19317 do { \
19318 @@ -389,7 +437,7 @@ do { \
19319 } while (0)
19320
19321 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19322 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19323 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19324 "2:\n" \
19325 _ASM_EXTABLE_EX(1b, 2b) \
19326 : ltype(x) : "m" (__m(addr)))
19327 @@ -406,13 +454,24 @@ do { \
19328 int __gu_err; \
19329 unsigned long __gu_val; \
19330 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19331 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19332 + (x) = (__typeof__(*(ptr)))__gu_val; \
19333 __gu_err; \
19334 })
19335
19336 /* FIXME: this hack is definitely wrong -AK */
19337 struct __large_struct { unsigned long buf[100]; };
19338 -#define __m(x) (*(struct __large_struct __user *)(x))
19339 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19340 +#define ____m(x) \
19341 +({ \
19342 + unsigned long ____x = (unsigned long)(x); \
19343 + if (____x < pax_user_shadow_base) \
19344 + ____x += pax_user_shadow_base; \
19345 + (typeof(x))____x; \
19346 +})
19347 +#else
19348 +#define ____m(x) (x)
19349 +#endif
19350 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19351
19352 /*
19353 * Tell gcc we read from memory instead of writing: this is because
19354 @@ -420,8 +479,10 @@ struct __large_struct { unsigned long buf[100]; };
19355 * aliasing issues.
19356 */
19357 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19358 +do { \
19359 + pax_open_userland(); \
19360 asm volatile(ASM_STAC "\n" \
19361 - "1: mov"itype" %"rtype"1,%2\n" \
19362 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19363 "2: " ASM_CLAC "\n" \
19364 ".section .fixup,\"ax\"\n" \
19365 "3: mov %3,%0\n" \
19366 @@ -429,10 +490,12 @@ struct __large_struct { unsigned long buf[100]; };
19367 ".previous\n" \
19368 _ASM_EXTABLE(1b, 3b) \
19369 : "=r"(err) \
19370 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19371 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19372 + pax_close_userland(); \
19373 +} while (0)
19374
19375 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19376 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19377 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19378 "2:\n" \
19379 _ASM_EXTABLE_EX(1b, 2b) \
19380 : : ltype(x), "m" (__m(addr)))
19381 @@ -442,11 +505,13 @@ struct __large_struct { unsigned long buf[100]; };
19382 */
19383 #define uaccess_try do { \
19384 current_thread_info()->uaccess_err = 0; \
19385 + pax_open_userland(); \
19386 stac(); \
19387 barrier();
19388
19389 #define uaccess_catch(err) \
19390 clac(); \
19391 + pax_close_userland(); \
19392 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19393 } while (0)
19394
19395 @@ -471,8 +536,12 @@ struct __large_struct { unsigned long buf[100]; };
19396 * On error, the variable @x is set to zero.
19397 */
19398
19399 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19400 +#define __get_user(x, ptr) get_user((x), (ptr))
19401 +#else
19402 #define __get_user(x, ptr) \
19403 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19404 +#endif
19405
19406 /**
19407 * __put_user: - Write a simple value into user space, with less checking.
19408 @@ -494,8 +563,12 @@ struct __large_struct { unsigned long buf[100]; };
19409 * Returns zero on success, or -EFAULT on error.
19410 */
19411
19412 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19413 +#define __put_user(x, ptr) put_user((x), (ptr))
19414 +#else
19415 #define __put_user(x, ptr) \
19416 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19417 +#endif
19418
19419 #define __get_user_unaligned __get_user
19420 #define __put_user_unaligned __put_user
19421 @@ -513,7 +586,7 @@ struct __large_struct { unsigned long buf[100]; };
19422 #define get_user_ex(x, ptr) do { \
19423 unsigned long __gue_val; \
19424 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19425 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19426 + (x) = (__typeof__(*(ptr)))__gue_val; \
19427 } while (0)
19428
19429 #define put_user_try uaccess_try
19430 @@ -542,18 +615,19 @@ extern void __cmpxchg_wrong_size(void)
19431 __typeof__(ptr) __uval = (uval); \
19432 __typeof__(*(ptr)) __old = (old); \
19433 __typeof__(*(ptr)) __new = (new); \
19434 + pax_open_userland(); \
19435 switch (size) { \
19436 case 1: \
19437 { \
19438 asm volatile("\t" ASM_STAC "\n" \
19439 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19440 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19441 "2:\t" ASM_CLAC "\n" \
19442 "\t.section .fixup, \"ax\"\n" \
19443 "3:\tmov %3, %0\n" \
19444 "\tjmp 2b\n" \
19445 "\t.previous\n" \
19446 _ASM_EXTABLE(1b, 3b) \
19447 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19448 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19449 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19450 : "memory" \
19451 ); \
19452 @@ -562,14 +636,14 @@ extern void __cmpxchg_wrong_size(void)
19453 case 2: \
19454 { \
19455 asm volatile("\t" ASM_STAC "\n" \
19456 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19457 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19458 "2:\t" ASM_CLAC "\n" \
19459 "\t.section .fixup, \"ax\"\n" \
19460 "3:\tmov %3, %0\n" \
19461 "\tjmp 2b\n" \
19462 "\t.previous\n" \
19463 _ASM_EXTABLE(1b, 3b) \
19464 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19465 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19466 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19467 : "memory" \
19468 ); \
19469 @@ -578,14 +652,14 @@ extern void __cmpxchg_wrong_size(void)
19470 case 4: \
19471 { \
19472 asm volatile("\t" ASM_STAC "\n" \
19473 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19474 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19475 "2:\t" ASM_CLAC "\n" \
19476 "\t.section .fixup, \"ax\"\n" \
19477 "3:\tmov %3, %0\n" \
19478 "\tjmp 2b\n" \
19479 "\t.previous\n" \
19480 _ASM_EXTABLE(1b, 3b) \
19481 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19482 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19483 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19484 : "memory" \
19485 ); \
19486 @@ -597,14 +671,14 @@ extern void __cmpxchg_wrong_size(void)
19487 __cmpxchg_wrong_size(); \
19488 \
19489 asm volatile("\t" ASM_STAC "\n" \
19490 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19491 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19492 "2:\t" ASM_CLAC "\n" \
19493 "\t.section .fixup, \"ax\"\n" \
19494 "3:\tmov %3, %0\n" \
19495 "\tjmp 2b\n" \
19496 "\t.previous\n" \
19497 _ASM_EXTABLE(1b, 3b) \
19498 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19499 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19500 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19501 : "memory" \
19502 ); \
19503 @@ -613,6 +687,7 @@ extern void __cmpxchg_wrong_size(void)
19504 default: \
19505 __cmpxchg_wrong_size(); \
19506 } \
19507 + pax_close_userland(); \
19508 *__uval = __old; \
19509 __ret; \
19510 })
19511 @@ -636,17 +711,6 @@ extern struct movsl_mask {
19512
19513 #define ARCH_HAS_NOCACHE_UACCESS 1
19514
19515 -#ifdef CONFIG_X86_32
19516 -# include <asm/uaccess_32.h>
19517 -#else
19518 -# include <asm/uaccess_64.h>
19519 -#endif
19520 -
19521 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19522 - unsigned n);
19523 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19524 - unsigned n);
19525 -
19526 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19527 # define copy_user_diag __compiletime_error
19528 #else
19529 @@ -656,7 +720,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19530 extern void copy_user_diag("copy_from_user() buffer size is too small")
19531 copy_from_user_overflow(void);
19532 extern void copy_user_diag("copy_to_user() buffer size is too small")
19533 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19534 +copy_to_user_overflow(void);
19535
19536 #undef copy_user_diag
19537
19538 @@ -669,7 +733,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19539
19540 extern void
19541 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19542 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19543 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19544 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19545
19546 #else
19547 @@ -684,10 +748,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19548
19549 #endif
19550
19551 +#ifdef CONFIG_X86_32
19552 +# include <asm/uaccess_32.h>
19553 +#else
19554 +# include <asm/uaccess_64.h>
19555 +#endif
19556 +
19557 static inline unsigned long __must_check
19558 copy_from_user(void *to, const void __user *from, unsigned long n)
19559 {
19560 - int sz = __compiletime_object_size(to);
19561 + size_t sz = __compiletime_object_size(to);
19562
19563 might_fault();
19564
19565 @@ -709,12 +779,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19566 * case, and do only runtime checking for non-constant sizes.
19567 */
19568
19569 - if (likely(sz < 0 || sz >= n))
19570 - n = _copy_from_user(to, from, n);
19571 - else if(__builtin_constant_p(n))
19572 - copy_from_user_overflow();
19573 - else
19574 - __copy_from_user_overflow(sz, n);
19575 + if (likely(sz != (size_t)-1 && sz < n)) {
19576 + if(__builtin_constant_p(n))
19577 + copy_from_user_overflow();
19578 + else
19579 + __copy_from_user_overflow(sz, n);
19580 + } if (access_ok(VERIFY_READ, from, n))
19581 + n = __copy_from_user(to, from, n);
19582 + else if ((long)n > 0)
19583 + memset(to, 0, n);
19584
19585 return n;
19586 }
19587 @@ -722,17 +795,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19588 static inline unsigned long __must_check
19589 copy_to_user(void __user *to, const void *from, unsigned long n)
19590 {
19591 - int sz = __compiletime_object_size(from);
19592 + size_t sz = __compiletime_object_size(from);
19593
19594 might_fault();
19595
19596 /* See the comment in copy_from_user() above. */
19597 - if (likely(sz < 0 || sz >= n))
19598 - n = _copy_to_user(to, from, n);
19599 - else if(__builtin_constant_p(n))
19600 - copy_to_user_overflow();
19601 - else
19602 - __copy_to_user_overflow(sz, n);
19603 + if (likely(sz != (size_t)-1 && sz < n)) {
19604 + if(__builtin_constant_p(n))
19605 + copy_to_user_overflow();
19606 + else
19607 + __copy_to_user_overflow(sz, n);
19608 + } else if (access_ok(VERIFY_WRITE, to, n))
19609 + n = __copy_to_user(to, from, n);
19610
19611 return n;
19612 }
19613 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19614 index 3c03a5d..1071638 100644
19615 --- a/arch/x86/include/asm/uaccess_32.h
19616 +++ b/arch/x86/include/asm/uaccess_32.h
19617 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19618 static __always_inline unsigned long __must_check
19619 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19620 {
19621 + if ((long)n < 0)
19622 + return n;
19623 +
19624 + check_object_size(from, n, true);
19625 +
19626 if (__builtin_constant_p(n)) {
19627 unsigned long ret;
19628
19629 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19630 __copy_to_user(void __user *to, const void *from, unsigned long n)
19631 {
19632 might_fault();
19633 +
19634 return __copy_to_user_inatomic(to, from, n);
19635 }
19636
19637 static __always_inline unsigned long
19638 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19639 {
19640 + if ((long)n < 0)
19641 + return n;
19642 +
19643 /* Avoid zeroing the tail if the copy fails..
19644 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19645 * but as the zeroing behaviour is only significant when n is not
19646 @@ -137,6 +146,12 @@ static __always_inline unsigned long
19647 __copy_from_user(void *to, const void __user *from, unsigned long n)
19648 {
19649 might_fault();
19650 +
19651 + if ((long)n < 0)
19652 + return n;
19653 +
19654 + check_object_size(to, n, false);
19655 +
19656 if (__builtin_constant_p(n)) {
19657 unsigned long ret;
19658
19659 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19660 const void __user *from, unsigned long n)
19661 {
19662 might_fault();
19663 +
19664 + if ((long)n < 0)
19665 + return n;
19666 +
19667 if (__builtin_constant_p(n)) {
19668 unsigned long ret;
19669
19670 @@ -181,7 +200,10 @@ static __always_inline unsigned long
19671 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19672 unsigned long n)
19673 {
19674 - return __copy_from_user_ll_nocache_nozero(to, from, n);
19675 + if ((long)n < 0)
19676 + return n;
19677 +
19678 + return __copy_from_user_ll_nocache_nozero(to, from, n);
19679 }
19680
19681 #endif /* _ASM_X86_UACCESS_32_H */
19682 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19683 index 12a26b9..206c200 100644
19684 --- a/arch/x86/include/asm/uaccess_64.h
19685 +++ b/arch/x86/include/asm/uaccess_64.h
19686 @@ -10,6 +10,9 @@
19687 #include <asm/alternative.h>
19688 #include <asm/cpufeature.h>
19689 #include <asm/page.h>
19690 +#include <asm/pgtable.h>
19691 +
19692 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
19693
19694 /*
19695 * Copy To/From Userspace
19696 @@ -17,14 +20,14 @@
19697
19698 /* Handles exceptions in both to and from, but doesn't do access_ok */
19699 __must_check unsigned long
19700 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19701 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19702 __must_check unsigned long
19703 -copy_user_generic_string(void *to, const void *from, unsigned len);
19704 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19705 __must_check unsigned long
19706 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19707 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19708
19709 static __always_inline __must_check unsigned long
19710 -copy_user_generic(void *to, const void *from, unsigned len)
19711 +copy_user_generic(void *to, const void *from, unsigned long len)
19712 {
19713 unsigned ret;
19714
19715 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19716 }
19717
19718 __must_check unsigned long
19719 -copy_in_user(void __user *to, const void __user *from, unsigned len);
19720 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
19721
19722 static __always_inline __must_check
19723 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19724 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19725 {
19726 - int ret = 0;
19727 + size_t sz = __compiletime_object_size(dst);
19728 + unsigned ret = 0;
19729 +
19730 + if (size > INT_MAX)
19731 + return size;
19732 +
19733 + check_object_size(dst, size, false);
19734 +
19735 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19736 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19737 + return size;
19738 +#endif
19739 +
19740 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19741 + if(__builtin_constant_p(size))
19742 + copy_from_user_overflow();
19743 + else
19744 + __copy_from_user_overflow(sz, size);
19745 + return size;
19746 + }
19747
19748 if (!__builtin_constant_p(size))
19749 - return copy_user_generic(dst, (__force void *)src, size);
19750 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19751 switch (size) {
19752 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19753 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19754 ret, "b", "b", "=q", 1);
19755 return ret;
19756 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19757 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19758 ret, "w", "w", "=r", 2);
19759 return ret;
19760 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19761 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19762 ret, "l", "k", "=r", 4);
19763 return ret;
19764 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19765 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19766 ret, "q", "", "=r", 8);
19767 return ret;
19768 case 10:
19769 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19770 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19771 ret, "q", "", "=r", 10);
19772 if (unlikely(ret))
19773 return ret;
19774 __get_user_asm(*(u16 *)(8 + (char *)dst),
19775 - (u16 __user *)(8 + (char __user *)src),
19776 + (const u16 __user *)(8 + (const char __user *)src),
19777 ret, "w", "w", "=r", 2);
19778 return ret;
19779 case 16:
19780 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19781 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19782 ret, "q", "", "=r", 16);
19783 if (unlikely(ret))
19784 return ret;
19785 __get_user_asm(*(u64 *)(8 + (char *)dst),
19786 - (u64 __user *)(8 + (char __user *)src),
19787 + (const u64 __user *)(8 + (const char __user *)src),
19788 ret, "q", "", "=r", 8);
19789 return ret;
19790 default:
19791 - return copy_user_generic(dst, (__force void *)src, size);
19792 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19793 }
19794 }
19795
19796 static __always_inline __must_check
19797 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
19798 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19799 {
19800 might_fault();
19801 return __copy_from_user_nocheck(dst, src, size);
19802 }
19803
19804 static __always_inline __must_check
19805 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19806 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19807 {
19808 - int ret = 0;
19809 + size_t sz = __compiletime_object_size(src);
19810 + unsigned ret = 0;
19811 +
19812 + if (size > INT_MAX)
19813 + return size;
19814 +
19815 + check_object_size(src, size, true);
19816 +
19817 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19818 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19819 + return size;
19820 +#endif
19821 +
19822 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19823 + if(__builtin_constant_p(size))
19824 + copy_to_user_overflow();
19825 + else
19826 + __copy_to_user_overflow(sz, size);
19827 + return size;
19828 + }
19829
19830 if (!__builtin_constant_p(size))
19831 - return copy_user_generic((__force void *)dst, src, size);
19832 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19833 switch (size) {
19834 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19835 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19836 ret, "b", "b", "iq", 1);
19837 return ret;
19838 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19839 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19840 ret, "w", "w", "ir", 2);
19841 return ret;
19842 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19843 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19844 ret, "l", "k", "ir", 4);
19845 return ret;
19846 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19847 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19848 ret, "q", "", "er", 8);
19849 return ret;
19850 case 10:
19851 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19852 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19853 ret, "q", "", "er", 10);
19854 if (unlikely(ret))
19855 return ret;
19856 asm("":::"memory");
19857 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19858 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19859 ret, "w", "w", "ir", 2);
19860 return ret;
19861 case 16:
19862 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19863 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19864 ret, "q", "", "er", 16);
19865 if (unlikely(ret))
19866 return ret;
19867 asm("":::"memory");
19868 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19869 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19870 ret, "q", "", "er", 8);
19871 return ret;
19872 default:
19873 - return copy_user_generic((__force void *)dst, src, size);
19874 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19875 }
19876 }
19877
19878 static __always_inline __must_check
19879 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
19880 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19881 {
19882 might_fault();
19883 return __copy_to_user_nocheck(dst, src, size);
19884 }
19885
19886 static __always_inline __must_check
19887 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19888 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19889 {
19890 - int ret = 0;
19891 + unsigned ret = 0;
19892
19893 might_fault();
19894 +
19895 + if (size > INT_MAX)
19896 + return size;
19897 +
19898 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19899 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19900 + return size;
19901 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19902 + return size;
19903 +#endif
19904 +
19905 if (!__builtin_constant_p(size))
19906 - return copy_user_generic((__force void *)dst,
19907 - (__force void *)src, size);
19908 + return copy_user_generic((__force_kernel void *)____m(dst),
19909 + (__force_kernel const void *)____m(src), size);
19910 switch (size) {
19911 case 1: {
19912 u8 tmp;
19913 - __get_user_asm(tmp, (u8 __user *)src,
19914 + __get_user_asm(tmp, (const u8 __user *)src,
19915 ret, "b", "b", "=q", 1);
19916 if (likely(!ret))
19917 __put_user_asm(tmp, (u8 __user *)dst,
19918 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19919 }
19920 case 2: {
19921 u16 tmp;
19922 - __get_user_asm(tmp, (u16 __user *)src,
19923 + __get_user_asm(tmp, (const u16 __user *)src,
19924 ret, "w", "w", "=r", 2);
19925 if (likely(!ret))
19926 __put_user_asm(tmp, (u16 __user *)dst,
19927 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19928
19929 case 4: {
19930 u32 tmp;
19931 - __get_user_asm(tmp, (u32 __user *)src,
19932 + __get_user_asm(tmp, (const u32 __user *)src,
19933 ret, "l", "k", "=r", 4);
19934 if (likely(!ret))
19935 __put_user_asm(tmp, (u32 __user *)dst,
19936 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19937 }
19938 case 8: {
19939 u64 tmp;
19940 - __get_user_asm(tmp, (u64 __user *)src,
19941 + __get_user_asm(tmp, (const u64 __user *)src,
19942 ret, "q", "", "=r", 8);
19943 if (likely(!ret))
19944 __put_user_asm(tmp, (u64 __user *)dst,
19945 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19946 return ret;
19947 }
19948 default:
19949 - return copy_user_generic((__force void *)dst,
19950 - (__force void *)src, size);
19951 + return copy_user_generic((__force_kernel void *)____m(dst),
19952 + (__force_kernel const void *)____m(src), size);
19953 }
19954 }
19955
19956 -static __must_check __always_inline int
19957 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
19958 +static __must_check __always_inline unsigned long
19959 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
19960 {
19961 return __copy_from_user_nocheck(dst, src, size);
19962 }
19963
19964 -static __must_check __always_inline int
19965 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
19966 +static __must_check __always_inline unsigned long
19967 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
19968 {
19969 return __copy_to_user_nocheck(dst, src, size);
19970 }
19971
19972 -extern long __copy_user_nocache(void *dst, const void __user *src,
19973 - unsigned size, int zerorest);
19974 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
19975 + unsigned long size, int zerorest);
19976
19977 -static inline int
19978 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
19979 +static inline unsigned long
19980 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
19981 {
19982 might_fault();
19983 +
19984 + if (size > INT_MAX)
19985 + return size;
19986 +
19987 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19988 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19989 + return size;
19990 +#endif
19991 +
19992 return __copy_user_nocache(dst, src, size, 1);
19993 }
19994
19995 -static inline int
19996 +static inline unsigned long
19997 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
19998 - unsigned size)
19999 + unsigned long size)
20000 {
20001 + if (size > INT_MAX)
20002 + return size;
20003 +
20004 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20005 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20006 + return size;
20007 +#endif
20008 +
20009 return __copy_user_nocache(dst, src, size, 0);
20010 }
20011
20012 unsigned long
20013 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20014 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20015
20016 #endif /* _ASM_X86_UACCESS_64_H */
20017 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20018 index 5b238981..77fdd78 100644
20019 --- a/arch/x86/include/asm/word-at-a-time.h
20020 +++ b/arch/x86/include/asm/word-at-a-time.h
20021 @@ -11,7 +11,7 @@
20022 * and shift, for example.
20023 */
20024 struct word_at_a_time {
20025 - const unsigned long one_bits, high_bits;
20026 + unsigned long one_bits, high_bits;
20027 };
20028
20029 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20030 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20031 index e45e4da..44e8572 100644
20032 --- a/arch/x86/include/asm/x86_init.h
20033 +++ b/arch/x86/include/asm/x86_init.h
20034 @@ -129,7 +129,7 @@ struct x86_init_ops {
20035 struct x86_init_timers timers;
20036 struct x86_init_iommu iommu;
20037 struct x86_init_pci pci;
20038 -};
20039 +} __no_const;
20040
20041 /**
20042 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20043 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20044 void (*setup_percpu_clockev)(void);
20045 void (*early_percpu_clock_init)(void);
20046 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20047 -};
20048 +} __no_const;
20049
20050 struct timespec;
20051
20052 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20053 void (*save_sched_clock_state)(void);
20054 void (*restore_sched_clock_state)(void);
20055 void (*apic_post_init)(void);
20056 -};
20057 +} __no_const;
20058
20059 struct pci_dev;
20060 struct msi_msg;
20061 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20062 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20063 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20064 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20065 -};
20066 +} __no_const;
20067
20068 struct IO_APIC_route_entry;
20069 struct io_apic_irq_attr;
20070 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20071 unsigned int destination, int vector,
20072 struct io_apic_irq_attr *attr);
20073 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20074 -};
20075 +} __no_const;
20076
20077 extern struct x86_init_ops x86_init;
20078 extern struct x86_cpuinit_ops x86_cpuinit;
20079 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20080 index 3e276eb..2eb3c30 100644
20081 --- a/arch/x86/include/asm/xen/page.h
20082 +++ b/arch/x86/include/asm/xen/page.h
20083 @@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20084 extern struct page *m2p_find_override(unsigned long mfn);
20085 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20086
20087 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20088 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20089 {
20090 unsigned long mfn;
20091
20092 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20093 index 5547389..da68716 100644
20094 --- a/arch/x86/include/asm/xsave.h
20095 +++ b/arch/x86/include/asm/xsave.h
20096 @@ -76,8 +76,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20097 if (unlikely(err))
20098 return -EFAULT;
20099
20100 + pax_open_userland();
20101 __asm__ __volatile__(ASM_STAC "\n"
20102 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20103 + "1:"
20104 + __copyuser_seg
20105 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20106 "2: " ASM_CLAC "\n"
20107 ".section .fixup,\"ax\"\n"
20108 "3: movl $-1,%[err]\n"
20109 @@ -87,18 +90,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20110 : [err] "=r" (err)
20111 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20112 : "memory");
20113 + pax_close_userland();
20114 return err;
20115 }
20116
20117 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20118 {
20119 int err;
20120 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20121 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20122 u32 lmask = mask;
20123 u32 hmask = mask >> 32;
20124
20125 + pax_open_userland();
20126 __asm__ __volatile__(ASM_STAC "\n"
20127 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20128 + "1:"
20129 + __copyuser_seg
20130 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20131 "2: " ASM_CLAC "\n"
20132 ".section .fixup,\"ax\"\n"
20133 "3: movl $-1,%[err]\n"
20134 @@ -108,6 +115,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20135 : [err] "=r" (err)
20136 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20137 : "memory"); /* memory required? */
20138 + pax_close_userland();
20139 return err;
20140 }
20141
20142 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20143 index bbae024..e1528f9 100644
20144 --- a/arch/x86/include/uapi/asm/e820.h
20145 +++ b/arch/x86/include/uapi/asm/e820.h
20146 @@ -63,7 +63,7 @@ struct e820map {
20147 #define ISA_START_ADDRESS 0xa0000
20148 #define ISA_END_ADDRESS 0x100000
20149
20150 -#define BIOS_BEGIN 0x000a0000
20151 +#define BIOS_BEGIN 0x000c0000
20152 #define BIOS_END 0x00100000
20153
20154 #define BIOS_ROM_BASE 0xffe00000
20155 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20156 index 7b0a55a..ad115bf 100644
20157 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20158 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20159 @@ -49,7 +49,6 @@
20160 #define EFLAGS 144
20161 #define RSP 152
20162 #define SS 160
20163 -#define ARGOFFSET R11
20164 #endif /* __ASSEMBLY__ */
20165
20166 /* top of stack page */
20167 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20168 index cb648c8..91cb07e 100644
20169 --- a/arch/x86/kernel/Makefile
20170 +++ b/arch/x86/kernel/Makefile
20171 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20172 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20173 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20174 obj-y += probe_roms.o
20175 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20176 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20177 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20178 obj-y += syscall_$(BITS).o
20179 obj-$(CONFIG_X86_64) += vsyscall_64.o
20180 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20181 index 1dac942..19c8b0c 100644
20182 --- a/arch/x86/kernel/acpi/boot.c
20183 +++ b/arch/x86/kernel/acpi/boot.c
20184 @@ -1312,7 +1312,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20185 * If your system is blacklisted here, but you find that acpi=force
20186 * works for you, please contact linux-acpi@vger.kernel.org
20187 */
20188 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20189 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20190 /*
20191 * Boxes that need ACPI disabled
20192 */
20193 @@ -1387,7 +1387,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20194 };
20195
20196 /* second table for DMI checks that should run after early-quirks */
20197 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20198 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20199 /*
20200 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20201 * which includes some code which overrides all temperature
20202 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20203 index 3a2ae4c..9db31d6 100644
20204 --- a/arch/x86/kernel/acpi/sleep.c
20205 +++ b/arch/x86/kernel/acpi/sleep.c
20206 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20207 #else /* CONFIG_64BIT */
20208 #ifdef CONFIG_SMP
20209 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20210 +
20211 + pax_open_kernel();
20212 early_gdt_descr.address =
20213 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20214 + pax_close_kernel();
20215 +
20216 initial_gs = per_cpu_offset(smp_processor_id());
20217 #endif
20218 initial_code = (unsigned long)wakeup_long64;
20219 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20220 index 665c6b7..eae4d56 100644
20221 --- a/arch/x86/kernel/acpi/wakeup_32.S
20222 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20223 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20224 # and restore the stack ... but you need gdt for this to work
20225 movl saved_context_esp, %esp
20226
20227 - movl %cs:saved_magic, %eax
20228 - cmpl $0x12345678, %eax
20229 + cmpl $0x12345678, saved_magic
20230 jne bogus_magic
20231
20232 # jump to place where we left off
20233 - movl saved_eip, %eax
20234 - jmp *%eax
20235 + jmp *(saved_eip)
20236
20237 bogus_magic:
20238 jmp bogus_magic
20239 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20240 index df94598..f3b29bf 100644
20241 --- a/arch/x86/kernel/alternative.c
20242 +++ b/arch/x86/kernel/alternative.c
20243 @@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20244 */
20245 for (a = start; a < end; a++) {
20246 instr = (u8 *)&a->instr_offset + a->instr_offset;
20247 +
20248 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20249 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20250 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20251 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20252 +#endif
20253 +
20254 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20255 BUG_ON(a->replacementlen > a->instrlen);
20256 BUG_ON(a->instrlen > sizeof(insnbuf));
20257 @@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20258 for (poff = start; poff < end; poff++) {
20259 u8 *ptr = (u8 *)poff + *poff;
20260
20261 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20262 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20263 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20264 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20265 +#endif
20266 +
20267 if (!*poff || ptr < text || ptr >= text_end)
20268 continue;
20269 /* turn DS segment override prefix into lock prefix */
20270 - if (*ptr == 0x3e)
20271 + if (*ktla_ktva(ptr) == 0x3e)
20272 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20273 }
20274 mutex_unlock(&text_mutex);
20275 @@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20276 for (poff = start; poff < end; poff++) {
20277 u8 *ptr = (u8 *)poff + *poff;
20278
20279 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20280 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20281 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20282 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20283 +#endif
20284 +
20285 if (!*poff || ptr < text || ptr >= text_end)
20286 continue;
20287 /* turn lock prefix into DS segment override prefix */
20288 - if (*ptr == 0xf0)
20289 + if (*ktla_ktva(ptr) == 0xf0)
20290 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20291 }
20292 mutex_unlock(&text_mutex);
20293 @@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20294
20295 BUG_ON(p->len > MAX_PATCH_LEN);
20296 /* prep the buffer with the original instructions */
20297 - memcpy(insnbuf, p->instr, p->len);
20298 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20299 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20300 (unsigned long)p->instr, p->len);
20301
20302 @@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20303 if (!uniproc_patched || num_possible_cpus() == 1)
20304 free_init_pages("SMP alternatives",
20305 (unsigned long)__smp_locks,
20306 - (unsigned long)__smp_locks_end);
20307 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20308 #endif
20309
20310 apply_paravirt(__parainstructions, __parainstructions_end);
20311 @@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20312 * instructions. And on the local CPU you need to be protected again NMI or MCE
20313 * handlers seeing an inconsistent instruction while you patch.
20314 */
20315 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20316 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20317 size_t len)
20318 {
20319 unsigned long flags;
20320 local_irq_save(flags);
20321 - memcpy(addr, opcode, len);
20322 +
20323 + pax_open_kernel();
20324 + memcpy(ktla_ktva(addr), opcode, len);
20325 sync_core();
20326 + pax_close_kernel();
20327 +
20328 local_irq_restore(flags);
20329 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20330 that causes hangs on some VIA CPUs. */
20331 @@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20332 */
20333 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20334 {
20335 - unsigned long flags;
20336 - char *vaddr;
20337 + unsigned char *vaddr = ktla_ktva(addr);
20338 struct page *pages[2];
20339 - int i;
20340 + size_t i;
20341
20342 if (!core_kernel_text((unsigned long)addr)) {
20343 - pages[0] = vmalloc_to_page(addr);
20344 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20345 + pages[0] = vmalloc_to_page(vaddr);
20346 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20347 } else {
20348 - pages[0] = virt_to_page(addr);
20349 + pages[0] = virt_to_page(vaddr);
20350 WARN_ON(!PageReserved(pages[0]));
20351 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20352 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20353 }
20354 BUG_ON(!pages[0]);
20355 - local_irq_save(flags);
20356 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20357 - if (pages[1])
20358 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20359 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20360 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20361 - clear_fixmap(FIX_TEXT_POKE0);
20362 - if (pages[1])
20363 - clear_fixmap(FIX_TEXT_POKE1);
20364 - local_flush_tlb();
20365 - sync_core();
20366 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20367 - that causes hangs on some VIA CPUs. */
20368 + text_poke_early(addr, opcode, len);
20369 for (i = 0; i < len; i++)
20370 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20371 - local_irq_restore(flags);
20372 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20373 return addr;
20374 }
20375
20376 @@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20377 if (likely(!bp_patching_in_progress))
20378 return 0;
20379
20380 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20381 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20382 return 0;
20383
20384 /* set up the specified breakpoint handler */
20385 @@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20386 */
20387 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20388 {
20389 - unsigned char int3 = 0xcc;
20390 + const unsigned char int3 = 0xcc;
20391
20392 bp_int3_handler = handler;
20393 bp_int3_addr = (u8 *)addr + sizeof(int3);
20394 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20395 index 7f26c9a..694544e 100644
20396 --- a/arch/x86/kernel/apic/apic.c
20397 +++ b/arch/x86/kernel/apic/apic.c
20398 @@ -198,7 +198,7 @@ int first_system_vector = 0xfe;
20399 /*
20400 * Debug level, exported for io_apic.c
20401 */
20402 -unsigned int apic_verbosity;
20403 +int apic_verbosity;
20404
20405 int pic_mode;
20406
20407 @@ -1992,7 +1992,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20408 apic_write(APIC_ESR, 0);
20409 v = apic_read(APIC_ESR);
20410 ack_APIC_irq();
20411 - atomic_inc(&irq_err_count);
20412 + atomic_inc_unchecked(&irq_err_count);
20413
20414 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20415 smp_processor_id(), v);
20416 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20417 index 2c621a6..fa2b1ae 100644
20418 --- a/arch/x86/kernel/apic/apic_flat_64.c
20419 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20420 @@ -154,7 +154,7 @@ static int flat_probe(void)
20421 return 1;
20422 }
20423
20424 -static struct apic apic_flat = {
20425 +static struct apic apic_flat __read_only = {
20426 .name = "flat",
20427 .probe = flat_probe,
20428 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20429 @@ -268,7 +268,7 @@ static int physflat_probe(void)
20430 return 0;
20431 }
20432
20433 -static struct apic apic_physflat = {
20434 +static struct apic apic_physflat __read_only = {
20435
20436 .name = "physical flat",
20437 .probe = physflat_probe,
20438 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20439 index 191ce75..2db6d63 100644
20440 --- a/arch/x86/kernel/apic/apic_noop.c
20441 +++ b/arch/x86/kernel/apic/apic_noop.c
20442 @@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20443 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20444 }
20445
20446 -struct apic apic_noop = {
20447 +struct apic apic_noop __read_only = {
20448 .name = "noop",
20449 .probe = noop_probe,
20450 .acpi_madt_oem_check = NULL,
20451 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20452 index d50e364..543bee3 100644
20453 --- a/arch/x86/kernel/apic/bigsmp_32.c
20454 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20455 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20456 return dmi_bigsmp;
20457 }
20458
20459 -static struct apic apic_bigsmp = {
20460 +static struct apic apic_bigsmp __read_only = {
20461
20462 .name = "bigsmp",
20463 .probe = probe_bigsmp,
20464 diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20465 index c552247..587a316 100644
20466 --- a/arch/x86/kernel/apic/es7000_32.c
20467 +++ b/arch/x86/kernel/apic/es7000_32.c
20468 @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20469 return ret && es7000_apic_is_cluster();
20470 }
20471
20472 -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20473 -static struct apic __refdata apic_es7000_cluster = {
20474 +static struct apic apic_es7000_cluster __read_only = {
20475
20476 .name = "es7000",
20477 .probe = probe_es7000,
20478 @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20479 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20480 };
20481
20482 -static struct apic __refdata apic_es7000 = {
20483 +static struct apic apic_es7000 __read_only = {
20484
20485 .name = "es7000",
20486 .probe = probe_es7000,
20487 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20488 index 6ad4658..38a7b5c 100644
20489 --- a/arch/x86/kernel/apic/io_apic.c
20490 +++ b/arch/x86/kernel/apic/io_apic.c
20491 @@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20492 }
20493 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20494
20495 -void lock_vector_lock(void)
20496 +void lock_vector_lock(void) __acquires(vector_lock)
20497 {
20498 /* Used to the online set of cpus does not change
20499 * during assign_irq_vector.
20500 @@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20501 raw_spin_lock(&vector_lock);
20502 }
20503
20504 -void unlock_vector_lock(void)
20505 +void unlock_vector_lock(void) __releases(vector_lock)
20506 {
20507 raw_spin_unlock(&vector_lock);
20508 }
20509 @@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20510 ack_APIC_irq();
20511 }
20512
20513 -atomic_t irq_mis_count;
20514 +atomic_unchecked_t irq_mis_count;
20515
20516 #ifdef CONFIG_GENERIC_PENDING_IRQ
20517 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20518 @@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20519 * at the cpu.
20520 */
20521 if (!(v & (1 << (i & 0x1f)))) {
20522 - atomic_inc(&irq_mis_count);
20523 + atomic_inc_unchecked(&irq_mis_count);
20524
20525 eoi_ioapic_irq(irq, cfg);
20526 }
20527 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20528 index 1e42e8f..daacf44 100644
20529 --- a/arch/x86/kernel/apic/numaq_32.c
20530 +++ b/arch/x86/kernel/apic/numaq_32.c
20531 @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20532 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20533 }
20534
20535 -/* Use __refdata to keep false positive warning calm. */
20536 -static struct apic __refdata apic_numaq = {
20537 +static struct apic apic_numaq __read_only = {
20538
20539 .name = "NUMAQ",
20540 .probe = probe_numaq,
20541 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20542 index eb35ef9..f184a21 100644
20543 --- a/arch/x86/kernel/apic/probe_32.c
20544 +++ b/arch/x86/kernel/apic/probe_32.c
20545 @@ -72,7 +72,7 @@ static int probe_default(void)
20546 return 1;
20547 }
20548
20549 -static struct apic apic_default = {
20550 +static struct apic apic_default __read_only = {
20551
20552 .name = "default",
20553 .probe = probe_default,
20554 diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20555 index 00146f9..5e299b8 100644
20556 --- a/arch/x86/kernel/apic/summit_32.c
20557 +++ b/arch/x86/kernel/apic/summit_32.c
20558 @@ -485,7 +485,7 @@ void setup_summit(void)
20559 }
20560 #endif
20561
20562 -static struct apic apic_summit = {
20563 +static struct apic apic_summit __read_only = {
20564
20565 .name = "summit",
20566 .probe = probe_summit,
20567 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20568 index cac85ee..01fa741 100644
20569 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20570 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20571 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20572 return notifier_from_errno(err);
20573 }
20574
20575 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20576 +static struct notifier_block x2apic_cpu_notifier = {
20577 .notifier_call = update_clusterinfo,
20578 };
20579
20580 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20581 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20582 }
20583
20584 -static struct apic apic_x2apic_cluster = {
20585 +static struct apic apic_x2apic_cluster __read_only = {
20586
20587 .name = "cluster x2apic",
20588 .probe = x2apic_cluster_probe,
20589 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20590 index de231e3..1d1b2ee 100644
20591 --- a/arch/x86/kernel/apic/x2apic_phys.c
20592 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20593 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20594 return apic == &apic_x2apic_phys;
20595 }
20596
20597 -static struct apic apic_x2apic_phys = {
20598 +static struct apic apic_x2apic_phys __read_only = {
20599
20600 .name = "physical x2apic",
20601 .probe = x2apic_phys_probe,
20602 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20603 index d263b13..963258b 100644
20604 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
20605 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20606 @@ -350,7 +350,7 @@ static int uv_probe(void)
20607 return apic == &apic_x2apic_uv_x;
20608 }
20609
20610 -static struct apic __refdata apic_x2apic_uv_x = {
20611 +static struct apic apic_x2apic_uv_x __read_only = {
20612
20613 .name = "UV large system",
20614 .probe = uv_probe,
20615 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20616 index 3ab0343..814c4787 100644
20617 --- a/arch/x86/kernel/apm_32.c
20618 +++ b/arch/x86/kernel/apm_32.c
20619 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20620 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20621 * even though they are called in protected mode.
20622 */
20623 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20624 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20625 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20626
20627 static const char driver_version[] = "1.16ac"; /* no spaces */
20628 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20629 BUG_ON(cpu != 0);
20630 gdt = get_cpu_gdt_table(cpu);
20631 save_desc_40 = gdt[0x40 / 8];
20632 +
20633 + pax_open_kernel();
20634 gdt[0x40 / 8] = bad_bios_desc;
20635 + pax_close_kernel();
20636
20637 apm_irq_save(flags);
20638 APM_DO_SAVE_SEGS;
20639 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20640 &call->esi);
20641 APM_DO_RESTORE_SEGS;
20642 apm_irq_restore(flags);
20643 +
20644 + pax_open_kernel();
20645 gdt[0x40 / 8] = save_desc_40;
20646 + pax_close_kernel();
20647 +
20648 put_cpu();
20649
20650 return call->eax & 0xff;
20651 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20652 BUG_ON(cpu != 0);
20653 gdt = get_cpu_gdt_table(cpu);
20654 save_desc_40 = gdt[0x40 / 8];
20655 +
20656 + pax_open_kernel();
20657 gdt[0x40 / 8] = bad_bios_desc;
20658 + pax_close_kernel();
20659
20660 apm_irq_save(flags);
20661 APM_DO_SAVE_SEGS;
20662 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20663 &call->eax);
20664 APM_DO_RESTORE_SEGS;
20665 apm_irq_restore(flags);
20666 +
20667 + pax_open_kernel();
20668 gdt[0x40 / 8] = save_desc_40;
20669 + pax_close_kernel();
20670 +
20671 put_cpu();
20672 return error;
20673 }
20674 @@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20675 * code to that CPU.
20676 */
20677 gdt = get_cpu_gdt_table(0);
20678 +
20679 + pax_open_kernel();
20680 set_desc_base(&gdt[APM_CS >> 3],
20681 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20682 set_desc_base(&gdt[APM_CS_16 >> 3],
20683 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20684 set_desc_base(&gdt[APM_DS >> 3],
20685 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20686 + pax_close_kernel();
20687
20688 proc_create("apm", 0, NULL, &apm_file_ops);
20689
20690 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20691 index 9f6b934..cf5ffb3 100644
20692 --- a/arch/x86/kernel/asm-offsets.c
20693 +++ b/arch/x86/kernel/asm-offsets.c
20694 @@ -32,6 +32,8 @@ void common(void) {
20695 OFFSET(TI_flags, thread_info, flags);
20696 OFFSET(TI_status, thread_info, status);
20697 OFFSET(TI_addr_limit, thread_info, addr_limit);
20698 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20699 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20700
20701 BLANK();
20702 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20703 @@ -52,8 +54,26 @@ void common(void) {
20704 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20705 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20706 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20707 +
20708 +#ifdef CONFIG_PAX_KERNEXEC
20709 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20710 #endif
20711
20712 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20713 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20714 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20715 +#ifdef CONFIG_X86_64
20716 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20717 +#endif
20718 +#endif
20719 +
20720 +#endif
20721 +
20722 + BLANK();
20723 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20724 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20725 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20726 +
20727 #ifdef CONFIG_XEN
20728 BLANK();
20729 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20730 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20731 index e7c798b..2b2019b 100644
20732 --- a/arch/x86/kernel/asm-offsets_64.c
20733 +++ b/arch/x86/kernel/asm-offsets_64.c
20734 @@ -77,6 +77,7 @@ int main(void)
20735 BLANK();
20736 #undef ENTRY
20737
20738 + DEFINE(TSS_size, sizeof(struct tss_struct));
20739 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20740 BLANK();
20741
20742 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20743 index 7fd54f0..0691410 100644
20744 --- a/arch/x86/kernel/cpu/Makefile
20745 +++ b/arch/x86/kernel/cpu/Makefile
20746 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20747 CFLAGS_REMOVE_perf_event.o = -pg
20748 endif
20749
20750 -# Make sure load_percpu_segment has no stackprotector
20751 -nostackp := $(call cc-option, -fno-stack-protector)
20752 -CFLAGS_common.o := $(nostackp)
20753 -
20754 obj-y := intel_cacheinfo.o scattered.o topology.o
20755 obj-y += proc.o capflags.o powerflags.o common.o
20756 obj-y += rdrand.o
20757 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20758 index c67ffa6..f41fbbf 100644
20759 --- a/arch/x86/kernel/cpu/amd.c
20760 +++ b/arch/x86/kernel/cpu/amd.c
20761 @@ -752,7 +752,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20762 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20763 {
20764 /* AMD errata T13 (order #21922) */
20765 - if ((c->x86 == 6)) {
20766 + if (c->x86 == 6) {
20767 /* Duron Rev A0 */
20768 if (c->x86_model == 3 && c->x86_mask == 0)
20769 size = 64;
20770 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20771 index 8e28bf2..bf5c0d2 100644
20772 --- a/arch/x86/kernel/cpu/common.c
20773 +++ b/arch/x86/kernel/cpu/common.c
20774 @@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20775
20776 static const struct cpu_dev *this_cpu = &default_cpu;
20777
20778 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20779 -#ifdef CONFIG_X86_64
20780 - /*
20781 - * We need valid kernel segments for data and code in long mode too
20782 - * IRET will check the segment types kkeil 2000/10/28
20783 - * Also sysret mandates a special GDT layout
20784 - *
20785 - * TLS descriptors are currently at a different place compared to i386.
20786 - * Hopefully nobody expects them at a fixed place (Wine?)
20787 - */
20788 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20789 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20790 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20791 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20792 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20793 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20794 -#else
20795 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20796 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20797 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20798 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20799 - /*
20800 - * Segments used for calling PnP BIOS have byte granularity.
20801 - * They code segments and data segments have fixed 64k limits,
20802 - * the transfer segment sizes are set at run time.
20803 - */
20804 - /* 32-bit code */
20805 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20806 - /* 16-bit code */
20807 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20808 - /* 16-bit data */
20809 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20810 - /* 16-bit data */
20811 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20812 - /* 16-bit data */
20813 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20814 - /*
20815 - * The APM segments have byte granularity and their bases
20816 - * are set at run time. All have 64k limits.
20817 - */
20818 - /* 32-bit code */
20819 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20820 - /* 16-bit code */
20821 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20822 - /* data */
20823 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20824 -
20825 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20826 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20827 - GDT_STACK_CANARY_INIT
20828 -#endif
20829 -} };
20830 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20831 -
20832 static int __init x86_xsave_setup(char *s)
20833 {
20834 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20835 @@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20836 }
20837 }
20838
20839 +#ifdef CONFIG_X86_64
20840 +static __init int setup_disable_pcid(char *arg)
20841 +{
20842 + setup_clear_cpu_cap(X86_FEATURE_PCID);
20843 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20844 +
20845 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20846 + if (clone_pgd_mask != ~(pgdval_t)0UL)
20847 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20848 +#endif
20849 +
20850 + return 1;
20851 +}
20852 +__setup("nopcid", setup_disable_pcid);
20853 +
20854 +static void setup_pcid(struct cpuinfo_x86 *c)
20855 +{
20856 + if (!cpu_has(c, X86_FEATURE_PCID)) {
20857 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
20858 +
20859 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20860 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
20861 + pax_open_kernel();
20862 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20863 + pax_close_kernel();
20864 + printk("PAX: slow and weak UDEREF enabled\n");
20865 + } else
20866 + printk("PAX: UDEREF disabled\n");
20867 +#endif
20868 +
20869 + return;
20870 + }
20871 +
20872 + printk("PAX: PCID detected\n");
20873 + set_in_cr4(X86_CR4_PCIDE);
20874 +
20875 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20876 + pax_open_kernel();
20877 + clone_pgd_mask = ~(pgdval_t)0UL;
20878 + pax_close_kernel();
20879 + if (pax_user_shadow_base)
20880 + printk("PAX: weak UDEREF enabled\n");
20881 + else {
20882 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20883 + printk("PAX: strong UDEREF enabled\n");
20884 + }
20885 +#endif
20886 +
20887 + if (cpu_has(c, X86_FEATURE_INVPCID))
20888 + printk("PAX: INVPCID detected\n");
20889 +}
20890 +#endif
20891 +
20892 /*
20893 * Some CPU features depend on higher CPUID levels, which may not always
20894 * be available due to CPUID level capping or broken virtualization
20895 @@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
20896 {
20897 struct desc_ptr gdt_descr;
20898
20899 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20900 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20901 gdt_descr.size = GDT_SIZE - 1;
20902 load_gdt(&gdt_descr);
20903 /* Reload the per-cpu base */
20904 @@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20905 setup_smep(c);
20906 setup_smap(c);
20907
20908 +#ifdef CONFIG_X86_64
20909 + setup_pcid(c);
20910 +#endif
20911 +
20912 /*
20913 * The vendor-specific functions might have changed features.
20914 * Now we do "generic changes."
20915 @@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20916 /* Filter out anything that depends on CPUID levels we don't have */
20917 filter_cpuid_features(c, true);
20918
20919 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20920 + setup_clear_cpu_cap(X86_FEATURE_SEP);
20921 +#endif
20922 +
20923 /* If the model name is still unset, do table lookup. */
20924 if (!c->x86_model_id[0]) {
20925 const char *p;
20926 @@ -1078,10 +1085,12 @@ static __init int setup_disablecpuid(char *arg)
20927 }
20928 __setup("clearcpuid=", setup_disablecpuid);
20929
20930 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20931 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
20932 +
20933 #ifdef CONFIG_X86_64
20934 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20935 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20936 - (unsigned long) debug_idt_table };
20937 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20938 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20939
20940 DEFINE_PER_CPU_FIRST(union irq_stack_union,
20941 irq_stack_union) __aligned(PAGE_SIZE) __visible;
20942 @@ -1095,7 +1104,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
20943 EXPORT_PER_CPU_SYMBOL(current_task);
20944
20945 DEFINE_PER_CPU(unsigned long, kernel_stack) =
20946 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
20947 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
20948 EXPORT_PER_CPU_SYMBOL(kernel_stack);
20949
20950 DEFINE_PER_CPU(char *, irq_stack_ptr) =
20951 @@ -1245,7 +1254,7 @@ void cpu_init(void)
20952 load_ucode_ap();
20953
20954 cpu = stack_smp_processor_id();
20955 - t = &per_cpu(init_tss, cpu);
20956 + t = init_tss + cpu;
20957 oist = &per_cpu(orig_ist, cpu);
20958
20959 #ifdef CONFIG_NUMA
20960 @@ -1280,7 +1289,6 @@ void cpu_init(void)
20961 wrmsrl(MSR_KERNEL_GS_BASE, 0);
20962 barrier();
20963
20964 - x86_configure_nx();
20965 enable_x2apic();
20966
20967 /*
20968 @@ -1332,7 +1340,7 @@ void cpu_init(void)
20969 {
20970 int cpu = smp_processor_id();
20971 struct task_struct *curr = current;
20972 - struct tss_struct *t = &per_cpu(init_tss, cpu);
20973 + struct tss_struct *t = init_tss + cpu;
20974 struct thread_struct *thread = &curr->thread;
20975
20976 show_ucode_info_early();
20977 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
20978 index 0641113..06f5ba4 100644
20979 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
20980 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
20981 @@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
20982 };
20983
20984 #ifdef CONFIG_AMD_NB
20985 +static struct attribute *default_attrs_amd_nb[] = {
20986 + &type.attr,
20987 + &level.attr,
20988 + &coherency_line_size.attr,
20989 + &physical_line_partition.attr,
20990 + &ways_of_associativity.attr,
20991 + &number_of_sets.attr,
20992 + &size.attr,
20993 + &shared_cpu_map.attr,
20994 + &shared_cpu_list.attr,
20995 + NULL,
20996 + NULL,
20997 + NULL,
20998 + NULL
20999 +};
21000 +
21001 static struct attribute **amd_l3_attrs(void)
21002 {
21003 static struct attribute **attrs;
21004 @@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21005
21006 n = ARRAY_SIZE(default_attrs);
21007
21008 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21009 - n += 2;
21010 -
21011 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21012 - n += 1;
21013 -
21014 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21015 - if (attrs == NULL)
21016 - return attrs = default_attrs;
21017 -
21018 - for (n = 0; default_attrs[n]; n++)
21019 - attrs[n] = default_attrs[n];
21020 + attrs = default_attrs_amd_nb;
21021
21022 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21023 attrs[n++] = &cache_disable_0.attr;
21024 @@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21025 .default_attrs = default_attrs,
21026 };
21027
21028 +#ifdef CONFIG_AMD_NB
21029 +static struct kobj_type ktype_cache_amd_nb = {
21030 + .sysfs_ops = &sysfs_ops,
21031 + .default_attrs = default_attrs_amd_nb,
21032 +};
21033 +#endif
21034 +
21035 static struct kobj_type ktype_percpu_entry = {
21036 .sysfs_ops = &sysfs_ops,
21037 };
21038 @@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21039 return retval;
21040 }
21041
21042 +#ifdef CONFIG_AMD_NB
21043 + amd_l3_attrs();
21044 +#endif
21045 +
21046 for (i = 0; i < num_cache_leaves; i++) {
21047 + struct kobj_type *ktype;
21048 +
21049 this_object = INDEX_KOBJECT_PTR(cpu, i);
21050 this_object->cpu = cpu;
21051 this_object->index = i;
21052
21053 this_leaf = CPUID4_INFO_IDX(cpu, i);
21054
21055 - ktype_cache.default_attrs = default_attrs;
21056 + ktype = &ktype_cache;
21057 #ifdef CONFIG_AMD_NB
21058 if (this_leaf->base.nb)
21059 - ktype_cache.default_attrs = amd_l3_attrs();
21060 + ktype = &ktype_cache_amd_nb;
21061 #endif
21062 retval = kobject_init_and_add(&(this_object->kobj),
21063 - &ktype_cache,
21064 + ktype,
21065 per_cpu(ici_cache_kobject, cpu),
21066 "index%1lu", i);
21067 if (unlikely(retval)) {
21068 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21069 index 4d5419b..95f11bb 100644
21070 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21071 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21072 @@ -45,6 +45,7 @@
21073 #include <asm/processor.h>
21074 #include <asm/mce.h>
21075 #include <asm/msr.h>
21076 +#include <asm/local.h>
21077
21078 #include "mce-internal.h"
21079
21080 @@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21081 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21082 m->cs, m->ip);
21083
21084 - if (m->cs == __KERNEL_CS)
21085 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21086 print_symbol("{%s}", m->ip);
21087 pr_cont("\n");
21088 }
21089 @@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21090
21091 #define PANIC_TIMEOUT 5 /* 5 seconds */
21092
21093 -static atomic_t mce_paniced;
21094 +static atomic_unchecked_t mce_paniced;
21095
21096 static int fake_panic;
21097 -static atomic_t mce_fake_paniced;
21098 +static atomic_unchecked_t mce_fake_paniced;
21099
21100 /* Panic in progress. Enable interrupts and wait for final IPI */
21101 static void wait_for_panic(void)
21102 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21103 /*
21104 * Make sure only one CPU runs in machine check panic
21105 */
21106 - if (atomic_inc_return(&mce_paniced) > 1)
21107 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21108 wait_for_panic();
21109 barrier();
21110
21111 @@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21112 console_verbose();
21113 } else {
21114 /* Don't log too much for fake panic */
21115 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21116 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21117 return;
21118 }
21119 /* First print corrected ones that are still unlogged */
21120 @@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21121 if (!fake_panic) {
21122 if (panic_timeout == 0)
21123 panic_timeout = mca_cfg.panic_timeout;
21124 - panic(msg);
21125 + panic("%s", msg);
21126 } else
21127 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21128 }
21129 @@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21130 * might have been modified by someone else.
21131 */
21132 rmb();
21133 - if (atomic_read(&mce_paniced))
21134 + if (atomic_read_unchecked(&mce_paniced))
21135 wait_for_panic();
21136 if (!mca_cfg.monarch_timeout)
21137 goto out;
21138 @@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21139 }
21140
21141 /* Call the installed machine check handler for this CPU setup. */
21142 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21143 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21144 unexpected_machine_check;
21145
21146 /*
21147 @@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21148 return;
21149 }
21150
21151 + pax_open_kernel();
21152 machine_check_vector = do_machine_check;
21153 + pax_close_kernel();
21154
21155 __mcheck_cpu_init_generic();
21156 __mcheck_cpu_init_vendor(c);
21157 @@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21158 */
21159
21160 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21161 -static int mce_chrdev_open_count; /* #times opened */
21162 +static local_t mce_chrdev_open_count; /* #times opened */
21163 static int mce_chrdev_open_exclu; /* already open exclusive? */
21164
21165 static int mce_chrdev_open(struct inode *inode, struct file *file)
21166 @@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21167 spin_lock(&mce_chrdev_state_lock);
21168
21169 if (mce_chrdev_open_exclu ||
21170 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21171 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21172 spin_unlock(&mce_chrdev_state_lock);
21173
21174 return -EBUSY;
21175 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21176
21177 if (file->f_flags & O_EXCL)
21178 mce_chrdev_open_exclu = 1;
21179 - mce_chrdev_open_count++;
21180 + local_inc(&mce_chrdev_open_count);
21181
21182 spin_unlock(&mce_chrdev_state_lock);
21183
21184 @@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21185 {
21186 spin_lock(&mce_chrdev_state_lock);
21187
21188 - mce_chrdev_open_count--;
21189 + local_dec(&mce_chrdev_open_count);
21190 mce_chrdev_open_exclu = 0;
21191
21192 spin_unlock(&mce_chrdev_state_lock);
21193 @@ -2406,7 +2409,7 @@ static __init void mce_init_banks(void)
21194
21195 for (i = 0; i < mca_cfg.banks; i++) {
21196 struct mce_bank *b = &mce_banks[i];
21197 - struct device_attribute *a = &b->attr;
21198 + device_attribute_no_const *a = &b->attr;
21199
21200 sysfs_attr_init(&a->attr);
21201 a->attr.name = b->attrname;
21202 @@ -2474,7 +2477,7 @@ struct dentry *mce_get_debugfs_dir(void)
21203 static void mce_reset(void)
21204 {
21205 cpu_missing = 0;
21206 - atomic_set(&mce_fake_paniced, 0);
21207 + atomic_set_unchecked(&mce_fake_paniced, 0);
21208 atomic_set(&mce_executing, 0);
21209 atomic_set(&mce_callin, 0);
21210 atomic_set(&global_nwo, 0);
21211 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21212 index a304298..49b6d06 100644
21213 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21214 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21215 @@ -10,6 +10,7 @@
21216 #include <asm/processor.h>
21217 #include <asm/mce.h>
21218 #include <asm/msr.h>
21219 +#include <asm/pgtable.h>
21220
21221 /* By default disabled */
21222 int mce_p5_enabled __read_mostly;
21223 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21224 if (!cpu_has(c, X86_FEATURE_MCE))
21225 return;
21226
21227 + pax_open_kernel();
21228 machine_check_vector = pentium_machine_check;
21229 + pax_close_kernel();
21230 /* Make sure the vector pointer is visible before we enable MCEs: */
21231 wmb();
21232
21233 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21234 index 7dc5564..1273569 100644
21235 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21236 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21237 @@ -9,6 +9,7 @@
21238 #include <asm/processor.h>
21239 #include <asm/mce.h>
21240 #include <asm/msr.h>
21241 +#include <asm/pgtable.h>
21242
21243 /* Machine check handler for WinChip C6: */
21244 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21245 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21246 {
21247 u32 lo, hi;
21248
21249 + pax_open_kernel();
21250 machine_check_vector = winchip_machine_check;
21251 + pax_close_kernel();
21252 /* Make sure the vector pointer is visible before we enable MCEs: */
21253 wmb();
21254
21255 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21256 index 15c9876..0a43909 100644
21257 --- a/arch/x86/kernel/cpu/microcode/core.c
21258 +++ b/arch/x86/kernel/cpu/microcode/core.c
21259 @@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21260 return NOTIFY_OK;
21261 }
21262
21263 -static struct notifier_block __refdata mc_cpu_notifier = {
21264 +static struct notifier_block mc_cpu_notifier = {
21265 .notifier_call = mc_cpu_callback,
21266 };
21267
21268 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21269 index a276fa7..e66810f 100644
21270 --- a/arch/x86/kernel/cpu/microcode/intel.c
21271 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21272 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21273
21274 static int get_ucode_user(void *to, const void *from, size_t n)
21275 {
21276 - return copy_from_user(to, from, n);
21277 + return copy_from_user(to, (const void __force_user *)from, n);
21278 }
21279
21280 static enum ucode_state
21281 request_microcode_user(int cpu, const void __user *buf, size_t size)
21282 {
21283 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21284 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21285 }
21286
21287 static void microcode_fini_cpu(int cpu)
21288 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21289 index f961de9..8a9d332 100644
21290 --- a/arch/x86/kernel/cpu/mtrr/main.c
21291 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21292 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21293 u64 size_or_mask, size_and_mask;
21294 static bool mtrr_aps_delayed_init;
21295
21296 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21297 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21298
21299 const struct mtrr_ops *mtrr_if;
21300
21301 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21302 index df5e41f..816c719 100644
21303 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21304 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21305 @@ -25,7 +25,7 @@ struct mtrr_ops {
21306 int (*validate_add_page)(unsigned long base, unsigned long size,
21307 unsigned int type);
21308 int (*have_wrcomb)(void);
21309 -};
21310 +} __do_const;
21311
21312 extern int generic_get_free_region(unsigned long base, unsigned long size,
21313 int replace_reg);
21314 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21315 index 79f9f84..38ace52 100644
21316 --- a/arch/x86/kernel/cpu/perf_event.c
21317 +++ b/arch/x86/kernel/cpu/perf_event.c
21318 @@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21319 pr_info("no hardware sampling interrupt available.\n");
21320 }
21321
21322 -static struct attribute_group x86_pmu_format_group = {
21323 +static attribute_group_no_const x86_pmu_format_group = {
21324 .name = "format",
21325 .attrs = NULL,
21326 };
21327 @@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21328 NULL,
21329 };
21330
21331 -static struct attribute_group x86_pmu_events_group = {
21332 +static attribute_group_no_const x86_pmu_events_group = {
21333 .name = "events",
21334 .attrs = events_attr,
21335 };
21336 @@ -1971,7 +1971,7 @@ static unsigned long get_segment_base(unsigned int segment)
21337 if (idx > GDT_ENTRIES)
21338 return 0;
21339
21340 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21341 + desc = get_cpu_gdt_table(smp_processor_id());
21342 }
21343
21344 return get_desc_base(desc + idx);
21345 @@ -2061,7 +2061,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21346 break;
21347
21348 perf_callchain_store(entry, frame.return_address);
21349 - fp = frame.next_frame;
21350 + fp = (const void __force_user *)frame.next_frame;
21351 }
21352 }
21353
21354 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21355 index 639d128..e92d7e5 100644
21356 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21357 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21358 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21359 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21360 {
21361 struct attribute **attrs;
21362 - struct attribute_group *attr_group;
21363 + attribute_group_no_const *attr_group;
21364 int i = 0, j;
21365
21366 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21367 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21368 index aa333d9..f9db700 100644
21369 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21370 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21371 @@ -2309,10 +2309,10 @@ __init int intel_pmu_init(void)
21372 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21373
21374 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21375 - u64 capabilities;
21376 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21377
21378 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21379 - x86_pmu.intel_cap.capabilities = capabilities;
21380 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21381 + x86_pmu.intel_cap.capabilities = capabilities;
21382 }
21383
21384 intel_ds_init();
21385 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21386 index 5ad35ad..e0a3960 100644
21387 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21388 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21389 @@ -425,7 +425,7 @@ static struct attribute *rapl_events_cln_attr[] = {
21390 NULL,
21391 };
21392
21393 -static struct attribute_group rapl_pmu_events_group = {
21394 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
21395 .name = "events",
21396 .attrs = NULL, /* patched at runtime */
21397 };
21398 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21399 index 047f540..afdeba0 100644
21400 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21401 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21402 @@ -3326,7 +3326,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21403 static int __init uncore_type_init(struct intel_uncore_type *type)
21404 {
21405 struct intel_uncore_pmu *pmus;
21406 - struct attribute_group *attr_group;
21407 + attribute_group_no_const *attr_group;
21408 struct attribute **attrs;
21409 int i, j;
21410
21411 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21412 index a80ab71..4089da5 100644
21413 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21414 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21415 @@ -498,7 +498,7 @@ struct intel_uncore_box {
21416 struct uncore_event_desc {
21417 struct kobj_attribute attr;
21418 const char *config;
21419 -};
21420 +} __do_const;
21421
21422 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21423 { \
21424 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21425 index 7d9481c..99c7e4b 100644
21426 --- a/arch/x86/kernel/cpuid.c
21427 +++ b/arch/x86/kernel/cpuid.c
21428 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21429 return notifier_from_errno(err);
21430 }
21431
21432 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
21433 +static struct notifier_block cpuid_class_cpu_notifier =
21434 {
21435 .notifier_call = cpuid_class_cpu_callback,
21436 };
21437 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21438 index a57902e..ebaae2a 100644
21439 --- a/arch/x86/kernel/crash.c
21440 +++ b/arch/x86/kernel/crash.c
21441 @@ -57,10 +57,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21442 {
21443 #ifdef CONFIG_X86_32
21444 struct pt_regs fixed_regs;
21445 -#endif
21446
21447 -#ifdef CONFIG_X86_32
21448 - if (!user_mode_vm(regs)) {
21449 + if (!user_mode(regs)) {
21450 crash_fixup_ss_esp(&fixed_regs, regs);
21451 regs = &fixed_regs;
21452 }
21453 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21454 index afa64ad..dce67dd 100644
21455 --- a/arch/x86/kernel/crash_dump_64.c
21456 +++ b/arch/x86/kernel/crash_dump_64.c
21457 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21458 return -ENOMEM;
21459
21460 if (userbuf) {
21461 - if (copy_to_user(buf, vaddr + offset, csize)) {
21462 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21463 iounmap(vaddr);
21464 return -EFAULT;
21465 }
21466 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21467 index f6dfd93..892ade4 100644
21468 --- a/arch/x86/kernel/doublefault.c
21469 +++ b/arch/x86/kernel/doublefault.c
21470 @@ -12,7 +12,7 @@
21471
21472 #define DOUBLEFAULT_STACKSIZE (1024)
21473 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21474 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21475 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21476
21477 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21478
21479 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
21480 unsigned long gdt, tss;
21481
21482 native_store_gdt(&gdt_desc);
21483 - gdt = gdt_desc.address;
21484 + gdt = (unsigned long)gdt_desc.address;
21485
21486 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21487
21488 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21489 /* 0x2 bit is always set */
21490 .flags = X86_EFLAGS_SF | 0x2,
21491 .sp = STACK_START,
21492 - .es = __USER_DS,
21493 + .es = __KERNEL_DS,
21494 .cs = __KERNEL_CS,
21495 .ss = __KERNEL_DS,
21496 - .ds = __USER_DS,
21497 + .ds = __KERNEL_DS,
21498 .fs = __KERNEL_PERCPU,
21499
21500 .__cr3 = __pa_nodebug(swapper_pg_dir),
21501 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21502 index d9c12d3..7858b62 100644
21503 --- a/arch/x86/kernel/dumpstack.c
21504 +++ b/arch/x86/kernel/dumpstack.c
21505 @@ -2,6 +2,9 @@
21506 * Copyright (C) 1991, 1992 Linus Torvalds
21507 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21508 */
21509 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21510 +#define __INCLUDED_BY_HIDESYM 1
21511 +#endif
21512 #include <linux/kallsyms.h>
21513 #include <linux/kprobes.h>
21514 #include <linux/uaccess.h>
21515 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21516 static void
21517 print_ftrace_graph_addr(unsigned long addr, void *data,
21518 const struct stacktrace_ops *ops,
21519 - struct thread_info *tinfo, int *graph)
21520 + struct task_struct *task, int *graph)
21521 {
21522 - struct task_struct *task;
21523 unsigned long ret_addr;
21524 int index;
21525
21526 if (addr != (unsigned long)return_to_handler)
21527 return;
21528
21529 - task = tinfo->task;
21530 index = task->curr_ret_stack;
21531
21532 if (!task->ret_stack || index < *graph)
21533 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21534 static inline void
21535 print_ftrace_graph_addr(unsigned long addr, void *data,
21536 const struct stacktrace_ops *ops,
21537 - struct thread_info *tinfo, int *graph)
21538 + struct task_struct *task, int *graph)
21539 { }
21540 #endif
21541
21542 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21543 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21544 */
21545
21546 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21547 - void *p, unsigned int size, void *end)
21548 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21549 {
21550 - void *t = tinfo;
21551 if (end) {
21552 if (p < end && p >= (end-THREAD_SIZE))
21553 return 1;
21554 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21555 }
21556
21557 unsigned long
21558 -print_context_stack(struct thread_info *tinfo,
21559 +print_context_stack(struct task_struct *task, void *stack_start,
21560 unsigned long *stack, unsigned long bp,
21561 const struct stacktrace_ops *ops, void *data,
21562 unsigned long *end, int *graph)
21563 {
21564 struct stack_frame *frame = (struct stack_frame *)bp;
21565
21566 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21567 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21568 unsigned long addr;
21569
21570 addr = *stack;
21571 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21572 } else {
21573 ops->address(data, addr, 0);
21574 }
21575 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21576 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21577 }
21578 stack++;
21579 }
21580 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21581 EXPORT_SYMBOL_GPL(print_context_stack);
21582
21583 unsigned long
21584 -print_context_stack_bp(struct thread_info *tinfo,
21585 +print_context_stack_bp(struct task_struct *task, void *stack_start,
21586 unsigned long *stack, unsigned long bp,
21587 const struct stacktrace_ops *ops, void *data,
21588 unsigned long *end, int *graph)
21589 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21590 struct stack_frame *frame = (struct stack_frame *)bp;
21591 unsigned long *ret_addr = &frame->return_address;
21592
21593 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21594 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21595 unsigned long addr = *ret_addr;
21596
21597 if (!__kernel_text_address(addr))
21598 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21599 ops->address(data, addr, 1);
21600 frame = frame->next_frame;
21601 ret_addr = &frame->return_address;
21602 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21603 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21604 }
21605
21606 return (unsigned long)frame;
21607 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21608 static void print_trace_address(void *data, unsigned long addr, int reliable)
21609 {
21610 touch_nmi_watchdog();
21611 - printk(data);
21612 + printk("%s", (char *)data);
21613 printk_stack_address(addr, reliable);
21614 }
21615
21616 @@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21617 }
21618 EXPORT_SYMBOL_GPL(oops_begin);
21619
21620 +extern void gr_handle_kernel_exploit(void);
21621 +
21622 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21623 {
21624 if (regs && kexec_should_crash(current))
21625 @@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21626 panic("Fatal exception in interrupt");
21627 if (panic_on_oops)
21628 panic("Fatal exception");
21629 - do_exit(signr);
21630 +
21631 + gr_handle_kernel_exploit();
21632 +
21633 + do_group_exit(signr);
21634 }
21635
21636 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21637 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21638 print_modules();
21639 show_regs(regs);
21640 #ifdef CONFIG_X86_32
21641 - if (user_mode_vm(regs)) {
21642 + if (user_mode(regs)) {
21643 sp = regs->sp;
21644 ss = regs->ss & 0xffff;
21645 } else {
21646 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21647 unsigned long flags = oops_begin();
21648 int sig = SIGSEGV;
21649
21650 - if (!user_mode_vm(regs))
21651 + if (!user_mode(regs))
21652 report_bug(regs->ip, regs);
21653
21654 if (__die(str, regs, err))
21655 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21656 index f2a1770..540657f 100644
21657 --- a/arch/x86/kernel/dumpstack_32.c
21658 +++ b/arch/x86/kernel/dumpstack_32.c
21659 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21660 bp = stack_frame(task, regs);
21661
21662 for (;;) {
21663 - struct thread_info *context;
21664 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21665
21666 - context = (struct thread_info *)
21667 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21668 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21669 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21670
21671 - stack = (unsigned long *)context->previous_esp;
21672 - if (!stack)
21673 + if (stack_start == task_stack_page(task))
21674 break;
21675 + stack = *(unsigned long **)stack_start;
21676 if (ops->stack(data, "IRQ") < 0)
21677 break;
21678 touch_nmi_watchdog();
21679 @@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21680 int i;
21681
21682 show_regs_print_info(KERN_EMERG);
21683 - __show_regs(regs, !user_mode_vm(regs));
21684 + __show_regs(regs, !user_mode(regs));
21685
21686 /*
21687 * When in-kernel, we also print out the stack and code at the
21688 * time of the fault..
21689 */
21690 - if (!user_mode_vm(regs)) {
21691 + if (!user_mode(regs)) {
21692 unsigned int code_prologue = code_bytes * 43 / 64;
21693 unsigned int code_len = code_bytes;
21694 unsigned char c;
21695 u8 *ip;
21696 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21697
21698 pr_emerg("Stack:\n");
21699 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21700
21701 pr_emerg("Code:");
21702
21703 - ip = (u8 *)regs->ip - code_prologue;
21704 + ip = (u8 *)regs->ip - code_prologue + cs_base;
21705 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21706 /* try starting at IP */
21707 - ip = (u8 *)regs->ip;
21708 + ip = (u8 *)regs->ip + cs_base;
21709 code_len = code_len - code_prologue + 1;
21710 }
21711 for (i = 0; i < code_len; i++, ip++) {
21712 @@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21713 pr_cont(" Bad EIP value.");
21714 break;
21715 }
21716 - if (ip == (u8 *)regs->ip)
21717 + if (ip == (u8 *)regs->ip + cs_base)
21718 pr_cont(" <%02x>", c);
21719 else
21720 pr_cont(" %02x", c);
21721 @@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21722 {
21723 unsigned short ud2;
21724
21725 + ip = ktla_ktva(ip);
21726 if (ip < PAGE_OFFSET)
21727 return 0;
21728 if (probe_kernel_address((unsigned short *)ip, ud2))
21729 @@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21730
21731 return ud2 == 0x0b0f;
21732 }
21733 +
21734 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21735 +void pax_check_alloca(unsigned long size)
21736 +{
21737 + unsigned long sp = (unsigned long)&sp, stack_left;
21738 +
21739 + /* all kernel stacks are of the same size */
21740 + stack_left = sp & (THREAD_SIZE - 1);
21741 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21742 +}
21743 +EXPORT_SYMBOL(pax_check_alloca);
21744 +#endif
21745 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21746 index addb207..99635fa 100644
21747 --- a/arch/x86/kernel/dumpstack_64.c
21748 +++ b/arch/x86/kernel/dumpstack_64.c
21749 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21750 unsigned long *irq_stack_end =
21751 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21752 unsigned used = 0;
21753 - struct thread_info *tinfo;
21754 int graph = 0;
21755 unsigned long dummy;
21756 + void *stack_start;
21757
21758 if (!task)
21759 task = current;
21760 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21761 * current stack address. If the stacks consist of nested
21762 * exceptions
21763 */
21764 - tinfo = task_thread_info(task);
21765 for (;;) {
21766 char *id;
21767 unsigned long *estack_end;
21768 +
21769 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21770 &used, &id);
21771
21772 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21773 if (ops->stack(data, id) < 0)
21774 break;
21775
21776 - bp = ops->walk_stack(tinfo, stack, bp, ops,
21777 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21778 data, estack_end, &graph);
21779 ops->stack(data, "<EOE>");
21780 /*
21781 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21782 * second-to-last pointer (index -2 to end) in the
21783 * exception stack:
21784 */
21785 + if ((u16)estack_end[-1] != __KERNEL_DS)
21786 + goto out;
21787 stack = (unsigned long *) estack_end[-2];
21788 continue;
21789 }
21790 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21791 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21792 if (ops->stack(data, "IRQ") < 0)
21793 break;
21794 - bp = ops->walk_stack(tinfo, stack, bp,
21795 + bp = ops->walk_stack(task, irq_stack, stack, bp,
21796 ops, data, irq_stack_end, &graph);
21797 /*
21798 * We link to the next stack (which would be
21799 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21800 /*
21801 * This handles the process stack:
21802 */
21803 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21804 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21805 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21806 +out:
21807 put_cpu();
21808 }
21809 EXPORT_SYMBOL(dump_trace);
21810 @@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21811
21812 return ud2 == 0x0b0f;
21813 }
21814 +
21815 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21816 +void pax_check_alloca(unsigned long size)
21817 +{
21818 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21819 + unsigned cpu, used;
21820 + char *id;
21821 +
21822 + /* check the process stack first */
21823 + stack_start = (unsigned long)task_stack_page(current);
21824 + stack_end = stack_start + THREAD_SIZE;
21825 + if (likely(stack_start <= sp && sp < stack_end)) {
21826 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
21827 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21828 + return;
21829 + }
21830 +
21831 + cpu = get_cpu();
21832 +
21833 + /* check the irq stacks */
21834 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21835 + stack_start = stack_end - IRQ_STACK_SIZE;
21836 + if (stack_start <= sp && sp < stack_end) {
21837 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21838 + put_cpu();
21839 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21840 + return;
21841 + }
21842 +
21843 + /* check the exception stacks */
21844 + used = 0;
21845 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21846 + stack_start = stack_end - EXCEPTION_STKSZ;
21847 + if (stack_end && stack_start <= sp && sp < stack_end) {
21848 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21849 + put_cpu();
21850 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21851 + return;
21852 + }
21853 +
21854 + put_cpu();
21855 +
21856 + /* unknown stack */
21857 + BUG();
21858 +}
21859 +EXPORT_SYMBOL(pax_check_alloca);
21860 +#endif
21861 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21862 index 988c00a..4f673b6 100644
21863 --- a/arch/x86/kernel/e820.c
21864 +++ b/arch/x86/kernel/e820.c
21865 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21866
21867 static void early_panic(char *msg)
21868 {
21869 - early_printk(msg);
21870 - panic(msg);
21871 + early_printk("%s", msg);
21872 + panic("%s", msg);
21873 }
21874
21875 static int userdef __initdata;
21876 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21877 index 01d1c18..8073693 100644
21878 --- a/arch/x86/kernel/early_printk.c
21879 +++ b/arch/x86/kernel/early_printk.c
21880 @@ -7,6 +7,7 @@
21881 #include <linux/pci_regs.h>
21882 #include <linux/pci_ids.h>
21883 #include <linux/errno.h>
21884 +#include <linux/sched.h>
21885 #include <asm/io.h>
21886 #include <asm/processor.h>
21887 #include <asm/fcntl.h>
21888 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21889 index a2a4f46..6cab058 100644
21890 --- a/arch/x86/kernel/entry_32.S
21891 +++ b/arch/x86/kernel/entry_32.S
21892 @@ -177,13 +177,153 @@
21893 /*CFI_REL_OFFSET gs, PT_GS*/
21894 .endm
21895 .macro SET_KERNEL_GS reg
21896 +
21897 +#ifdef CONFIG_CC_STACKPROTECTOR
21898 movl $(__KERNEL_STACK_CANARY), \reg
21899 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21900 + movl $(__USER_DS), \reg
21901 +#else
21902 + xorl \reg, \reg
21903 +#endif
21904 +
21905 movl \reg, %gs
21906 .endm
21907
21908 #endif /* CONFIG_X86_32_LAZY_GS */
21909
21910 -.macro SAVE_ALL
21911 +.macro pax_enter_kernel
21912 +#ifdef CONFIG_PAX_KERNEXEC
21913 + call pax_enter_kernel
21914 +#endif
21915 +.endm
21916 +
21917 +.macro pax_exit_kernel
21918 +#ifdef CONFIG_PAX_KERNEXEC
21919 + call pax_exit_kernel
21920 +#endif
21921 +.endm
21922 +
21923 +#ifdef CONFIG_PAX_KERNEXEC
21924 +ENTRY(pax_enter_kernel)
21925 +#ifdef CONFIG_PARAVIRT
21926 + pushl %eax
21927 + pushl %ecx
21928 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21929 + mov %eax, %esi
21930 +#else
21931 + mov %cr0, %esi
21932 +#endif
21933 + bts $16, %esi
21934 + jnc 1f
21935 + mov %cs, %esi
21936 + cmp $__KERNEL_CS, %esi
21937 + jz 3f
21938 + ljmp $__KERNEL_CS, $3f
21939 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21940 +2:
21941 +#ifdef CONFIG_PARAVIRT
21942 + mov %esi, %eax
21943 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21944 +#else
21945 + mov %esi, %cr0
21946 +#endif
21947 +3:
21948 +#ifdef CONFIG_PARAVIRT
21949 + popl %ecx
21950 + popl %eax
21951 +#endif
21952 + ret
21953 +ENDPROC(pax_enter_kernel)
21954 +
21955 +ENTRY(pax_exit_kernel)
21956 +#ifdef CONFIG_PARAVIRT
21957 + pushl %eax
21958 + pushl %ecx
21959 +#endif
21960 + mov %cs, %esi
21961 + cmp $__KERNEXEC_KERNEL_CS, %esi
21962 + jnz 2f
21963 +#ifdef CONFIG_PARAVIRT
21964 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21965 + mov %eax, %esi
21966 +#else
21967 + mov %cr0, %esi
21968 +#endif
21969 + btr $16, %esi
21970 + ljmp $__KERNEL_CS, $1f
21971 +1:
21972 +#ifdef CONFIG_PARAVIRT
21973 + mov %esi, %eax
21974 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21975 +#else
21976 + mov %esi, %cr0
21977 +#endif
21978 +2:
21979 +#ifdef CONFIG_PARAVIRT
21980 + popl %ecx
21981 + popl %eax
21982 +#endif
21983 + ret
21984 +ENDPROC(pax_exit_kernel)
21985 +#endif
21986 +
21987 + .macro pax_erase_kstack
21988 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21989 + call pax_erase_kstack
21990 +#endif
21991 + .endm
21992 +
21993 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21994 +/*
21995 + * ebp: thread_info
21996 + */
21997 +ENTRY(pax_erase_kstack)
21998 + pushl %edi
21999 + pushl %ecx
22000 + pushl %eax
22001 +
22002 + mov TI_lowest_stack(%ebp), %edi
22003 + mov $-0xBEEF, %eax
22004 + std
22005 +
22006 +1: mov %edi, %ecx
22007 + and $THREAD_SIZE_asm - 1, %ecx
22008 + shr $2, %ecx
22009 + repne scasl
22010 + jecxz 2f
22011 +
22012 + cmp $2*16, %ecx
22013 + jc 2f
22014 +
22015 + mov $2*16, %ecx
22016 + repe scasl
22017 + jecxz 2f
22018 + jne 1b
22019 +
22020 +2: cld
22021 + mov %esp, %ecx
22022 + sub %edi, %ecx
22023 +
22024 + cmp $THREAD_SIZE_asm, %ecx
22025 + jb 3f
22026 + ud2
22027 +3:
22028 +
22029 + shr $2, %ecx
22030 + rep stosl
22031 +
22032 + mov TI_task_thread_sp0(%ebp), %edi
22033 + sub $128, %edi
22034 + mov %edi, TI_lowest_stack(%ebp)
22035 +
22036 + popl %eax
22037 + popl %ecx
22038 + popl %edi
22039 + ret
22040 +ENDPROC(pax_erase_kstack)
22041 +#endif
22042 +
22043 +.macro __SAVE_ALL _DS
22044 cld
22045 PUSH_GS
22046 pushl_cfi %fs
22047 @@ -206,7 +346,7 @@
22048 CFI_REL_OFFSET ecx, 0
22049 pushl_cfi %ebx
22050 CFI_REL_OFFSET ebx, 0
22051 - movl $(__USER_DS), %edx
22052 + movl $\_DS, %edx
22053 movl %edx, %ds
22054 movl %edx, %es
22055 movl $(__KERNEL_PERCPU), %edx
22056 @@ -214,6 +354,15 @@
22057 SET_KERNEL_GS %edx
22058 .endm
22059
22060 +.macro SAVE_ALL
22061 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22062 + __SAVE_ALL __KERNEL_DS
22063 + pax_enter_kernel
22064 +#else
22065 + __SAVE_ALL __USER_DS
22066 +#endif
22067 +.endm
22068 +
22069 .macro RESTORE_INT_REGS
22070 popl_cfi %ebx
22071 CFI_RESTORE ebx
22072 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22073 popfl_cfi
22074 jmp syscall_exit
22075 CFI_ENDPROC
22076 -END(ret_from_fork)
22077 +ENDPROC(ret_from_fork)
22078
22079 ENTRY(ret_from_kernel_thread)
22080 CFI_STARTPROC
22081 @@ -344,7 +493,15 @@ ret_from_intr:
22082 andl $SEGMENT_RPL_MASK, %eax
22083 #endif
22084 cmpl $USER_RPL, %eax
22085 +
22086 +#ifdef CONFIG_PAX_KERNEXEC
22087 + jae resume_userspace
22088 +
22089 + pax_exit_kernel
22090 + jmp resume_kernel
22091 +#else
22092 jb resume_kernel # not returning to v8086 or userspace
22093 +#endif
22094
22095 ENTRY(resume_userspace)
22096 LOCKDEP_SYS_EXIT
22097 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22098 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22099 # int/exception return?
22100 jne work_pending
22101 - jmp restore_all
22102 -END(ret_from_exception)
22103 + jmp restore_all_pax
22104 +ENDPROC(ret_from_exception)
22105
22106 #ifdef CONFIG_PREEMPT
22107 ENTRY(resume_kernel)
22108 @@ -369,7 +526,7 @@ need_resched:
22109 jz restore_all
22110 call preempt_schedule_irq
22111 jmp need_resched
22112 -END(resume_kernel)
22113 +ENDPROC(resume_kernel)
22114 #endif
22115 CFI_ENDPROC
22116 /*
22117 @@ -403,30 +560,45 @@ sysenter_past_esp:
22118 /*CFI_REL_OFFSET cs, 0*/
22119 /*
22120 * Push current_thread_info()->sysenter_return to the stack.
22121 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22122 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22123 */
22124 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22125 + pushl_cfi $0
22126 CFI_REL_OFFSET eip, 0
22127
22128 pushl_cfi %eax
22129 SAVE_ALL
22130 + GET_THREAD_INFO(%ebp)
22131 + movl TI_sysenter_return(%ebp),%ebp
22132 + movl %ebp,PT_EIP(%esp)
22133 ENABLE_INTERRUPTS(CLBR_NONE)
22134
22135 /*
22136 * Load the potential sixth argument from user stack.
22137 * Careful about security.
22138 */
22139 + movl PT_OLDESP(%esp),%ebp
22140 +
22141 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22142 + mov PT_OLDSS(%esp),%ds
22143 +1: movl %ds:(%ebp),%ebp
22144 + push %ss
22145 + pop %ds
22146 +#else
22147 cmpl $__PAGE_OFFSET-3,%ebp
22148 jae syscall_fault
22149 ASM_STAC
22150 1: movl (%ebp),%ebp
22151 ASM_CLAC
22152 +#endif
22153 +
22154 movl %ebp,PT_EBP(%esp)
22155 _ASM_EXTABLE(1b,syscall_fault)
22156
22157 GET_THREAD_INFO(%ebp)
22158
22159 +#ifdef CONFIG_PAX_RANDKSTACK
22160 + pax_erase_kstack
22161 +#endif
22162 +
22163 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22164 jnz sysenter_audit
22165 sysenter_do_call:
22166 @@ -441,12 +613,24 @@ sysenter_do_call:
22167 testl $_TIF_ALLWORK_MASK, %ecx
22168 jne sysexit_audit
22169 sysenter_exit:
22170 +
22171 +#ifdef CONFIG_PAX_RANDKSTACK
22172 + pushl_cfi %eax
22173 + movl %esp, %eax
22174 + call pax_randomize_kstack
22175 + popl_cfi %eax
22176 +#endif
22177 +
22178 + pax_erase_kstack
22179 +
22180 /* if something modifies registers it must also disable sysexit */
22181 movl PT_EIP(%esp), %edx
22182 movl PT_OLDESP(%esp), %ecx
22183 xorl %ebp,%ebp
22184 TRACE_IRQS_ON
22185 1: mov PT_FS(%esp), %fs
22186 +2: mov PT_DS(%esp), %ds
22187 +3: mov PT_ES(%esp), %es
22188 PTGS_TO_GS
22189 ENABLE_INTERRUPTS_SYSEXIT
22190
22191 @@ -463,6 +647,9 @@ sysenter_audit:
22192 movl %eax,%edx /* 2nd arg: syscall number */
22193 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22194 call __audit_syscall_entry
22195 +
22196 + pax_erase_kstack
22197 +
22198 pushl_cfi %ebx
22199 movl PT_EAX(%esp),%eax /* reload syscall number */
22200 jmp sysenter_do_call
22201 @@ -488,10 +675,16 @@ sysexit_audit:
22202
22203 CFI_ENDPROC
22204 .pushsection .fixup,"ax"
22205 -2: movl $0,PT_FS(%esp)
22206 +4: movl $0,PT_FS(%esp)
22207 + jmp 1b
22208 +5: movl $0,PT_DS(%esp)
22209 + jmp 1b
22210 +6: movl $0,PT_ES(%esp)
22211 jmp 1b
22212 .popsection
22213 - _ASM_EXTABLE(1b,2b)
22214 + _ASM_EXTABLE(1b,4b)
22215 + _ASM_EXTABLE(2b,5b)
22216 + _ASM_EXTABLE(3b,6b)
22217 PTGS_TO_GS_EX
22218 ENDPROC(ia32_sysenter_target)
22219
22220 @@ -506,6 +699,11 @@ ENTRY(system_call)
22221 pushl_cfi %eax # save orig_eax
22222 SAVE_ALL
22223 GET_THREAD_INFO(%ebp)
22224 +
22225 +#ifdef CONFIG_PAX_RANDKSTACK
22226 + pax_erase_kstack
22227 +#endif
22228 +
22229 # system call tracing in operation / emulation
22230 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22231 jnz syscall_trace_entry
22232 @@ -524,6 +722,15 @@ syscall_exit:
22233 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22234 jne syscall_exit_work
22235
22236 +restore_all_pax:
22237 +
22238 +#ifdef CONFIG_PAX_RANDKSTACK
22239 + movl %esp, %eax
22240 + call pax_randomize_kstack
22241 +#endif
22242 +
22243 + pax_erase_kstack
22244 +
22245 restore_all:
22246 TRACE_IRQS_IRET
22247 restore_all_notrace:
22248 @@ -580,14 +787,34 @@ ldt_ss:
22249 * compensating for the offset by changing to the ESPFIX segment with
22250 * a base address that matches for the difference.
22251 */
22252 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22253 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22254 mov %esp, %edx /* load kernel esp */
22255 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22256 mov %dx, %ax /* eax: new kernel esp */
22257 sub %eax, %edx /* offset (low word is 0) */
22258 +#ifdef CONFIG_SMP
22259 + movl PER_CPU_VAR(cpu_number), %ebx
22260 + shll $PAGE_SHIFT_asm, %ebx
22261 + addl $cpu_gdt_table, %ebx
22262 +#else
22263 + movl $cpu_gdt_table, %ebx
22264 +#endif
22265 shr $16, %edx
22266 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22267 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22268 +
22269 +#ifdef CONFIG_PAX_KERNEXEC
22270 + mov %cr0, %esi
22271 + btr $16, %esi
22272 + mov %esi, %cr0
22273 +#endif
22274 +
22275 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22276 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22277 +
22278 +#ifdef CONFIG_PAX_KERNEXEC
22279 + bts $16, %esi
22280 + mov %esi, %cr0
22281 +#endif
22282 +
22283 pushl_cfi $__ESPFIX_SS
22284 pushl_cfi %eax /* new kernel esp */
22285 /* Disable interrupts, but do not irqtrace this section: we
22286 @@ -616,20 +843,18 @@ work_resched:
22287 movl TI_flags(%ebp), %ecx
22288 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22289 # than syscall tracing?
22290 - jz restore_all
22291 + jz restore_all_pax
22292 testb $_TIF_NEED_RESCHED, %cl
22293 jnz work_resched
22294
22295 work_notifysig: # deal with pending signals and
22296 # notify-resume requests
22297 + movl %esp, %eax
22298 #ifdef CONFIG_VM86
22299 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22300 - movl %esp, %eax
22301 jne work_notifysig_v86 # returning to kernel-space or
22302 # vm86-space
22303 1:
22304 -#else
22305 - movl %esp, %eax
22306 #endif
22307 TRACE_IRQS_ON
22308 ENABLE_INTERRUPTS(CLBR_NONE)
22309 @@ -650,7 +875,7 @@ work_notifysig_v86:
22310 movl %eax, %esp
22311 jmp 1b
22312 #endif
22313 -END(work_pending)
22314 +ENDPROC(work_pending)
22315
22316 # perform syscall exit tracing
22317 ALIGN
22318 @@ -658,11 +883,14 @@ syscall_trace_entry:
22319 movl $-ENOSYS,PT_EAX(%esp)
22320 movl %esp, %eax
22321 call syscall_trace_enter
22322 +
22323 + pax_erase_kstack
22324 +
22325 /* What it returned is what we'll actually use. */
22326 cmpl $(NR_syscalls), %eax
22327 jnae syscall_call
22328 jmp syscall_exit
22329 -END(syscall_trace_entry)
22330 +ENDPROC(syscall_trace_entry)
22331
22332 # perform syscall exit tracing
22333 ALIGN
22334 @@ -675,21 +903,25 @@ syscall_exit_work:
22335 movl %esp, %eax
22336 call syscall_trace_leave
22337 jmp resume_userspace
22338 -END(syscall_exit_work)
22339 +ENDPROC(syscall_exit_work)
22340 CFI_ENDPROC
22341
22342 RING0_INT_FRAME # can't unwind into user space anyway
22343 syscall_fault:
22344 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22345 + push %ss
22346 + pop %ds
22347 +#endif
22348 ASM_CLAC
22349 GET_THREAD_INFO(%ebp)
22350 movl $-EFAULT,PT_EAX(%esp)
22351 jmp resume_userspace
22352 -END(syscall_fault)
22353 +ENDPROC(syscall_fault)
22354
22355 syscall_badsys:
22356 movl $-ENOSYS,PT_EAX(%esp)
22357 jmp resume_userspace
22358 -END(syscall_badsys)
22359 +ENDPROC(syscall_badsys)
22360 CFI_ENDPROC
22361 /*
22362 * End of kprobes section
22363 @@ -705,8 +937,15 @@ END(syscall_badsys)
22364 * normal stack and adjusts ESP with the matching offset.
22365 */
22366 /* fixup the stack */
22367 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22368 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22369 +#ifdef CONFIG_SMP
22370 + movl PER_CPU_VAR(cpu_number), %ebx
22371 + shll $PAGE_SHIFT_asm, %ebx
22372 + addl $cpu_gdt_table, %ebx
22373 +#else
22374 + movl $cpu_gdt_table, %ebx
22375 +#endif
22376 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22377 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22378 shl $16, %eax
22379 addl %esp, %eax /* the adjusted stack pointer */
22380 pushl_cfi $__KERNEL_DS
22381 @@ -759,7 +998,7 @@ vector=vector+1
22382 .endr
22383 2: jmp common_interrupt
22384 .endr
22385 -END(irq_entries_start)
22386 +ENDPROC(irq_entries_start)
22387
22388 .previous
22389 END(interrupt)
22390 @@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22391 pushl_cfi $do_coprocessor_error
22392 jmp error_code
22393 CFI_ENDPROC
22394 -END(coprocessor_error)
22395 +ENDPROC(coprocessor_error)
22396
22397 ENTRY(simd_coprocessor_error)
22398 RING0_INT_FRAME
22399 @@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22400 .section .altinstructions,"a"
22401 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22402 .previous
22403 -.section .altinstr_replacement,"ax"
22404 +.section .altinstr_replacement,"a"
22405 663: pushl $do_simd_coprocessor_error
22406 664:
22407 .previous
22408 @@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22409 #endif
22410 jmp error_code
22411 CFI_ENDPROC
22412 -END(simd_coprocessor_error)
22413 +ENDPROC(simd_coprocessor_error)
22414
22415 ENTRY(device_not_available)
22416 RING0_INT_FRAME
22417 @@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22418 pushl_cfi $do_device_not_available
22419 jmp error_code
22420 CFI_ENDPROC
22421 -END(device_not_available)
22422 +ENDPROC(device_not_available)
22423
22424 #ifdef CONFIG_PARAVIRT
22425 ENTRY(native_iret)
22426 iret
22427 _ASM_EXTABLE(native_iret, iret_exc)
22428 -END(native_iret)
22429 +ENDPROC(native_iret)
22430
22431 ENTRY(native_irq_enable_sysexit)
22432 sti
22433 sysexit
22434 -END(native_irq_enable_sysexit)
22435 +ENDPROC(native_irq_enable_sysexit)
22436 #endif
22437
22438 ENTRY(overflow)
22439 @@ -872,7 +1111,7 @@ ENTRY(overflow)
22440 pushl_cfi $do_overflow
22441 jmp error_code
22442 CFI_ENDPROC
22443 -END(overflow)
22444 +ENDPROC(overflow)
22445
22446 ENTRY(bounds)
22447 RING0_INT_FRAME
22448 @@ -881,7 +1120,7 @@ ENTRY(bounds)
22449 pushl_cfi $do_bounds
22450 jmp error_code
22451 CFI_ENDPROC
22452 -END(bounds)
22453 +ENDPROC(bounds)
22454
22455 ENTRY(invalid_op)
22456 RING0_INT_FRAME
22457 @@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22458 pushl_cfi $do_invalid_op
22459 jmp error_code
22460 CFI_ENDPROC
22461 -END(invalid_op)
22462 +ENDPROC(invalid_op)
22463
22464 ENTRY(coprocessor_segment_overrun)
22465 RING0_INT_FRAME
22466 @@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22467 pushl_cfi $do_coprocessor_segment_overrun
22468 jmp error_code
22469 CFI_ENDPROC
22470 -END(coprocessor_segment_overrun)
22471 +ENDPROC(coprocessor_segment_overrun)
22472
22473 ENTRY(invalid_TSS)
22474 RING0_EC_FRAME
22475 @@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22476 pushl_cfi $do_invalid_TSS
22477 jmp error_code
22478 CFI_ENDPROC
22479 -END(invalid_TSS)
22480 +ENDPROC(invalid_TSS)
22481
22482 ENTRY(segment_not_present)
22483 RING0_EC_FRAME
22484 @@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22485 pushl_cfi $do_segment_not_present
22486 jmp error_code
22487 CFI_ENDPROC
22488 -END(segment_not_present)
22489 +ENDPROC(segment_not_present)
22490
22491 ENTRY(stack_segment)
22492 RING0_EC_FRAME
22493 @@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22494 pushl_cfi $do_stack_segment
22495 jmp error_code
22496 CFI_ENDPROC
22497 -END(stack_segment)
22498 +ENDPROC(stack_segment)
22499
22500 ENTRY(alignment_check)
22501 RING0_EC_FRAME
22502 @@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22503 pushl_cfi $do_alignment_check
22504 jmp error_code
22505 CFI_ENDPROC
22506 -END(alignment_check)
22507 +ENDPROC(alignment_check)
22508
22509 ENTRY(divide_error)
22510 RING0_INT_FRAME
22511 @@ -940,7 +1179,7 @@ ENTRY(divide_error)
22512 pushl_cfi $do_divide_error
22513 jmp error_code
22514 CFI_ENDPROC
22515 -END(divide_error)
22516 +ENDPROC(divide_error)
22517
22518 #ifdef CONFIG_X86_MCE
22519 ENTRY(machine_check)
22520 @@ -950,7 +1189,7 @@ ENTRY(machine_check)
22521 pushl_cfi machine_check_vector
22522 jmp error_code
22523 CFI_ENDPROC
22524 -END(machine_check)
22525 +ENDPROC(machine_check)
22526 #endif
22527
22528 ENTRY(spurious_interrupt_bug)
22529 @@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22530 pushl_cfi $do_spurious_interrupt_bug
22531 jmp error_code
22532 CFI_ENDPROC
22533 -END(spurious_interrupt_bug)
22534 +ENDPROC(spurious_interrupt_bug)
22535 /*
22536 * End of kprobes section
22537 */
22538 @@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22539
22540 ENTRY(mcount)
22541 ret
22542 -END(mcount)
22543 +ENDPROC(mcount)
22544
22545 ENTRY(ftrace_caller)
22546 cmpl $0, function_trace_stop
22547 @@ -1103,7 +1342,7 @@ ftrace_graph_call:
22548 .globl ftrace_stub
22549 ftrace_stub:
22550 ret
22551 -END(ftrace_caller)
22552 +ENDPROC(ftrace_caller)
22553
22554 ENTRY(ftrace_regs_caller)
22555 pushf /* push flags before compare (in cs location) */
22556 @@ -1207,7 +1446,7 @@ trace:
22557 popl %ecx
22558 popl %eax
22559 jmp ftrace_stub
22560 -END(mcount)
22561 +ENDPROC(mcount)
22562 #endif /* CONFIG_DYNAMIC_FTRACE */
22563 #endif /* CONFIG_FUNCTION_TRACER */
22564
22565 @@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22566 popl %ecx
22567 popl %eax
22568 ret
22569 -END(ftrace_graph_caller)
22570 +ENDPROC(ftrace_graph_caller)
22571
22572 .globl return_to_handler
22573 return_to_handler:
22574 @@ -1291,15 +1530,18 @@ error_code:
22575 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22576 REG_TO_PTGS %ecx
22577 SET_KERNEL_GS %ecx
22578 - movl $(__USER_DS), %ecx
22579 + movl $(__KERNEL_DS), %ecx
22580 movl %ecx, %ds
22581 movl %ecx, %es
22582 +
22583 + pax_enter_kernel
22584 +
22585 TRACE_IRQS_OFF
22586 movl %esp,%eax # pt_regs pointer
22587 call *%edi
22588 jmp ret_from_exception
22589 CFI_ENDPROC
22590 -END(page_fault)
22591 +ENDPROC(page_fault)
22592
22593 /*
22594 * Debug traps and NMI can happen at the one SYSENTER instruction
22595 @@ -1342,7 +1584,7 @@ debug_stack_correct:
22596 call do_debug
22597 jmp ret_from_exception
22598 CFI_ENDPROC
22599 -END(debug)
22600 +ENDPROC(debug)
22601
22602 /*
22603 * NMI is doubly nasty. It can happen _while_ we're handling
22604 @@ -1380,6 +1622,9 @@ nmi_stack_correct:
22605 xorl %edx,%edx # zero error code
22606 movl %esp,%eax # pt_regs pointer
22607 call do_nmi
22608 +
22609 + pax_exit_kernel
22610 +
22611 jmp restore_all_notrace
22612 CFI_ENDPROC
22613
22614 @@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22615 FIXUP_ESPFIX_STACK # %eax == %esp
22616 xorl %edx,%edx # zero error code
22617 call do_nmi
22618 +
22619 + pax_exit_kernel
22620 +
22621 RESTORE_REGS
22622 lss 12+4(%esp), %esp # back to espfix stack
22623 CFI_ADJUST_CFA_OFFSET -24
22624 jmp irq_return
22625 CFI_ENDPROC
22626 -END(nmi)
22627 +ENDPROC(nmi)
22628
22629 ENTRY(int3)
22630 RING0_INT_FRAME
22631 @@ -1434,14 +1682,14 @@ ENTRY(int3)
22632 call do_int3
22633 jmp ret_from_exception
22634 CFI_ENDPROC
22635 -END(int3)
22636 +ENDPROC(int3)
22637
22638 ENTRY(general_protection)
22639 RING0_EC_FRAME
22640 pushl_cfi $do_general_protection
22641 jmp error_code
22642 CFI_ENDPROC
22643 -END(general_protection)
22644 +ENDPROC(general_protection)
22645
22646 #ifdef CONFIG_KVM_GUEST
22647 ENTRY(async_page_fault)
22648 @@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22649 pushl_cfi $do_async_page_fault
22650 jmp error_code
22651 CFI_ENDPROC
22652 -END(async_page_fault)
22653 +ENDPROC(async_page_fault)
22654 #endif
22655
22656 /*
22657 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22658 index 1e96c36..3ff710a 100644
22659 --- a/arch/x86/kernel/entry_64.S
22660 +++ b/arch/x86/kernel/entry_64.S
22661 @@ -59,6 +59,8 @@
22662 #include <asm/context_tracking.h>
22663 #include <asm/smap.h>
22664 #include <linux/err.h>
22665 +#include <asm/pgtable.h>
22666 +#include <asm/alternative-asm.h>
22667
22668 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22669 #include <linux/elf-em.h>
22670 @@ -80,8 +82,9 @@
22671 #ifdef CONFIG_DYNAMIC_FTRACE
22672
22673 ENTRY(function_hook)
22674 + pax_force_retaddr
22675 retq
22676 -END(function_hook)
22677 +ENDPROC(function_hook)
22678
22679 /* skip is set if stack has been adjusted */
22680 .macro ftrace_caller_setup skip=0
22681 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22682 #endif
22683
22684 GLOBAL(ftrace_stub)
22685 + pax_force_retaddr
22686 retq
22687 -END(ftrace_caller)
22688 +ENDPROC(ftrace_caller)
22689
22690 ENTRY(ftrace_regs_caller)
22691 /* Save the current flags before compare (in SS location)*/
22692 @@ -191,7 +195,7 @@ ftrace_restore_flags:
22693 popfq
22694 jmp ftrace_stub
22695
22696 -END(ftrace_regs_caller)
22697 +ENDPROC(ftrace_regs_caller)
22698
22699
22700 #else /* ! CONFIG_DYNAMIC_FTRACE */
22701 @@ -212,6 +216,7 @@ ENTRY(function_hook)
22702 #endif
22703
22704 GLOBAL(ftrace_stub)
22705 + pax_force_retaddr
22706 retq
22707
22708 trace:
22709 @@ -225,12 +230,13 @@ trace:
22710 #endif
22711 subq $MCOUNT_INSN_SIZE, %rdi
22712
22713 + pax_force_fptr ftrace_trace_function
22714 call *ftrace_trace_function
22715
22716 MCOUNT_RESTORE_FRAME
22717
22718 jmp ftrace_stub
22719 -END(function_hook)
22720 +ENDPROC(function_hook)
22721 #endif /* CONFIG_DYNAMIC_FTRACE */
22722 #endif /* CONFIG_FUNCTION_TRACER */
22723
22724 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22725
22726 MCOUNT_RESTORE_FRAME
22727
22728 + pax_force_retaddr
22729 retq
22730 -END(ftrace_graph_caller)
22731 +ENDPROC(ftrace_graph_caller)
22732
22733 GLOBAL(return_to_handler)
22734 subq $24, %rsp
22735 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22736 movq 8(%rsp), %rdx
22737 movq (%rsp), %rax
22738 addq $24, %rsp
22739 + pax_force_fptr %rdi
22740 jmp *%rdi
22741 +ENDPROC(return_to_handler)
22742 #endif
22743
22744
22745 @@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22746 ENDPROC(native_usergs_sysret64)
22747 #endif /* CONFIG_PARAVIRT */
22748
22749 + .macro ljmpq sel, off
22750 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22751 + .byte 0x48; ljmp *1234f(%rip)
22752 + .pushsection .rodata
22753 + .align 16
22754 + 1234: .quad \off; .word \sel
22755 + .popsection
22756 +#else
22757 + pushq $\sel
22758 + pushq $\off
22759 + lretq
22760 +#endif
22761 + .endm
22762 +
22763 + .macro pax_enter_kernel
22764 + pax_set_fptr_mask
22765 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22766 + call pax_enter_kernel
22767 +#endif
22768 + .endm
22769 +
22770 + .macro pax_exit_kernel
22771 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22772 + call pax_exit_kernel
22773 +#endif
22774 +
22775 + .endm
22776 +
22777 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22778 +ENTRY(pax_enter_kernel)
22779 + pushq %rdi
22780 +
22781 +#ifdef CONFIG_PARAVIRT
22782 + PV_SAVE_REGS(CLBR_RDI)
22783 +#endif
22784 +
22785 +#ifdef CONFIG_PAX_KERNEXEC
22786 + GET_CR0_INTO_RDI
22787 + bts $16,%rdi
22788 + jnc 3f
22789 + mov %cs,%edi
22790 + cmp $__KERNEL_CS,%edi
22791 + jnz 2f
22792 +1:
22793 +#endif
22794 +
22795 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22796 + 661: jmp 111f
22797 + .pushsection .altinstr_replacement, "a"
22798 + 662: ASM_NOP2
22799 + .popsection
22800 + .pushsection .altinstructions, "a"
22801 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22802 + .popsection
22803 + GET_CR3_INTO_RDI
22804 + cmp $0,%dil
22805 + jnz 112f
22806 + mov $__KERNEL_DS,%edi
22807 + mov %edi,%ss
22808 + jmp 111f
22809 +112: cmp $1,%dil
22810 + jz 113f
22811 + ud2
22812 +113: sub $4097,%rdi
22813 + bts $63,%rdi
22814 + SET_RDI_INTO_CR3
22815 + mov $__UDEREF_KERNEL_DS,%edi
22816 + mov %edi,%ss
22817 +111:
22818 +#endif
22819 +
22820 +#ifdef CONFIG_PARAVIRT
22821 + PV_RESTORE_REGS(CLBR_RDI)
22822 +#endif
22823 +
22824 + popq %rdi
22825 + pax_force_retaddr
22826 + retq
22827 +
22828 +#ifdef CONFIG_PAX_KERNEXEC
22829 +2: ljmpq __KERNEL_CS,1b
22830 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
22831 +4: SET_RDI_INTO_CR0
22832 + jmp 1b
22833 +#endif
22834 +ENDPROC(pax_enter_kernel)
22835 +
22836 +ENTRY(pax_exit_kernel)
22837 + pushq %rdi
22838 +
22839 +#ifdef CONFIG_PARAVIRT
22840 + PV_SAVE_REGS(CLBR_RDI)
22841 +#endif
22842 +
22843 +#ifdef CONFIG_PAX_KERNEXEC
22844 + mov %cs,%rdi
22845 + cmp $__KERNEXEC_KERNEL_CS,%edi
22846 + jz 2f
22847 + GET_CR0_INTO_RDI
22848 + bts $16,%rdi
22849 + jnc 4f
22850 +1:
22851 +#endif
22852 +
22853 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22854 + 661: jmp 111f
22855 + .pushsection .altinstr_replacement, "a"
22856 + 662: ASM_NOP2
22857 + .popsection
22858 + .pushsection .altinstructions, "a"
22859 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22860 + .popsection
22861 + mov %ss,%edi
22862 + cmp $__UDEREF_KERNEL_DS,%edi
22863 + jnz 111f
22864 + GET_CR3_INTO_RDI
22865 + cmp $0,%dil
22866 + jz 112f
22867 + ud2
22868 +112: add $4097,%rdi
22869 + bts $63,%rdi
22870 + SET_RDI_INTO_CR3
22871 + mov $__KERNEL_DS,%edi
22872 + mov %edi,%ss
22873 +111:
22874 +#endif
22875 +
22876 +#ifdef CONFIG_PARAVIRT
22877 + PV_RESTORE_REGS(CLBR_RDI);
22878 +#endif
22879 +
22880 + popq %rdi
22881 + pax_force_retaddr
22882 + retq
22883 +
22884 +#ifdef CONFIG_PAX_KERNEXEC
22885 +2: GET_CR0_INTO_RDI
22886 + btr $16,%rdi
22887 + jnc 4f
22888 + ljmpq __KERNEL_CS,3f
22889 +3: SET_RDI_INTO_CR0
22890 + jmp 1b
22891 +4: ud2
22892 + jmp 4b
22893 +#endif
22894 +ENDPROC(pax_exit_kernel)
22895 +#endif
22896 +
22897 + .macro pax_enter_kernel_user
22898 + pax_set_fptr_mask
22899 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22900 + call pax_enter_kernel_user
22901 +#endif
22902 + .endm
22903 +
22904 + .macro pax_exit_kernel_user
22905 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22906 + call pax_exit_kernel_user
22907 +#endif
22908 +#ifdef CONFIG_PAX_RANDKSTACK
22909 + pushq %rax
22910 + pushq %r11
22911 + call pax_randomize_kstack
22912 + popq %r11
22913 + popq %rax
22914 +#endif
22915 + .endm
22916 +
22917 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22918 +ENTRY(pax_enter_kernel_user)
22919 + pushq %rdi
22920 + pushq %rbx
22921 +
22922 +#ifdef CONFIG_PARAVIRT
22923 + PV_SAVE_REGS(CLBR_RDI)
22924 +#endif
22925 +
22926 + 661: jmp 111f
22927 + .pushsection .altinstr_replacement, "a"
22928 + 662: ASM_NOP2
22929 + .popsection
22930 + .pushsection .altinstructions, "a"
22931 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22932 + .popsection
22933 + GET_CR3_INTO_RDI
22934 + cmp $1,%dil
22935 + jnz 4f
22936 + sub $4097,%rdi
22937 + bts $63,%rdi
22938 + SET_RDI_INTO_CR3
22939 + jmp 3f
22940 +111:
22941 +
22942 + GET_CR3_INTO_RDI
22943 + mov %rdi,%rbx
22944 + add $__START_KERNEL_map,%rbx
22945 + sub phys_base(%rip),%rbx
22946 +
22947 +#ifdef CONFIG_PARAVIRT
22948 + cmpl $0, pv_info+PARAVIRT_enabled
22949 + jz 1f
22950 + pushq %rdi
22951 + i = 0
22952 + .rept USER_PGD_PTRS
22953 + mov i*8(%rbx),%rsi
22954 + mov $0,%sil
22955 + lea i*8(%rbx),%rdi
22956 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22957 + i = i + 1
22958 + .endr
22959 + popq %rdi
22960 + jmp 2f
22961 +1:
22962 +#endif
22963 +
22964 + i = 0
22965 + .rept USER_PGD_PTRS
22966 + movb $0,i*8(%rbx)
22967 + i = i + 1
22968 + .endr
22969 +
22970 +2: SET_RDI_INTO_CR3
22971 +
22972 +#ifdef CONFIG_PAX_KERNEXEC
22973 + GET_CR0_INTO_RDI
22974 + bts $16,%rdi
22975 + SET_RDI_INTO_CR0
22976 +#endif
22977 +
22978 +3:
22979 +
22980 +#ifdef CONFIG_PARAVIRT
22981 + PV_RESTORE_REGS(CLBR_RDI)
22982 +#endif
22983 +
22984 + popq %rbx
22985 + popq %rdi
22986 + pax_force_retaddr
22987 + retq
22988 +4: ud2
22989 +ENDPROC(pax_enter_kernel_user)
22990 +
22991 +ENTRY(pax_exit_kernel_user)
22992 + pushq %rdi
22993 + pushq %rbx
22994 +
22995 +#ifdef CONFIG_PARAVIRT
22996 + PV_SAVE_REGS(CLBR_RDI)
22997 +#endif
22998 +
22999 + GET_CR3_INTO_RDI
23000 + 661: jmp 1f
23001 + .pushsection .altinstr_replacement, "a"
23002 + 662: ASM_NOP2
23003 + .popsection
23004 + .pushsection .altinstructions, "a"
23005 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23006 + .popsection
23007 + cmp $0,%dil
23008 + jnz 3f
23009 + add $4097,%rdi
23010 + bts $63,%rdi
23011 + SET_RDI_INTO_CR3
23012 + jmp 2f
23013 +1:
23014 +
23015 + mov %rdi,%rbx
23016 +
23017 +#ifdef CONFIG_PAX_KERNEXEC
23018 + GET_CR0_INTO_RDI
23019 + btr $16,%rdi
23020 + jnc 3f
23021 + SET_RDI_INTO_CR0
23022 +#endif
23023 +
23024 + add $__START_KERNEL_map,%rbx
23025 + sub phys_base(%rip),%rbx
23026 +
23027 +#ifdef CONFIG_PARAVIRT
23028 + cmpl $0, pv_info+PARAVIRT_enabled
23029 + jz 1f
23030 + i = 0
23031 + .rept USER_PGD_PTRS
23032 + mov i*8(%rbx),%rsi
23033 + mov $0x67,%sil
23034 + lea i*8(%rbx),%rdi
23035 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23036 + i = i + 1
23037 + .endr
23038 + jmp 2f
23039 +1:
23040 +#endif
23041 +
23042 + i = 0
23043 + .rept USER_PGD_PTRS
23044 + movb $0x67,i*8(%rbx)
23045 + i = i + 1
23046 + .endr
23047 +2:
23048 +
23049 +#ifdef CONFIG_PARAVIRT
23050 + PV_RESTORE_REGS(CLBR_RDI)
23051 +#endif
23052 +
23053 + popq %rbx
23054 + popq %rdi
23055 + pax_force_retaddr
23056 + retq
23057 +3: ud2
23058 +ENDPROC(pax_exit_kernel_user)
23059 +#endif
23060 +
23061 + .macro pax_enter_kernel_nmi
23062 + pax_set_fptr_mask
23063 +
23064 +#ifdef CONFIG_PAX_KERNEXEC
23065 + GET_CR0_INTO_RDI
23066 + bts $16,%rdi
23067 + jc 110f
23068 + SET_RDI_INTO_CR0
23069 + or $2,%ebx
23070 +110:
23071 +#endif
23072 +
23073 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23074 + 661: jmp 111f
23075 + .pushsection .altinstr_replacement, "a"
23076 + 662: ASM_NOP2
23077 + .popsection
23078 + .pushsection .altinstructions, "a"
23079 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23080 + .popsection
23081 + GET_CR3_INTO_RDI
23082 + cmp $0,%dil
23083 + jz 111f
23084 + sub $4097,%rdi
23085 + or $4,%ebx
23086 + bts $63,%rdi
23087 + SET_RDI_INTO_CR3
23088 + mov $__UDEREF_KERNEL_DS,%edi
23089 + mov %edi,%ss
23090 +111:
23091 +#endif
23092 + .endm
23093 +
23094 + .macro pax_exit_kernel_nmi
23095 +#ifdef CONFIG_PAX_KERNEXEC
23096 + btr $1,%ebx
23097 + jnc 110f
23098 + GET_CR0_INTO_RDI
23099 + btr $16,%rdi
23100 + SET_RDI_INTO_CR0
23101 +110:
23102 +#endif
23103 +
23104 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23105 + btr $2,%ebx
23106 + jnc 111f
23107 + GET_CR3_INTO_RDI
23108 + add $4097,%rdi
23109 + bts $63,%rdi
23110 + SET_RDI_INTO_CR3
23111 + mov $__KERNEL_DS,%edi
23112 + mov %edi,%ss
23113 +111:
23114 +#endif
23115 + .endm
23116 +
23117 + .macro pax_erase_kstack
23118 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23119 + call pax_erase_kstack
23120 +#endif
23121 + .endm
23122 +
23123 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23124 +ENTRY(pax_erase_kstack)
23125 + pushq %rdi
23126 + pushq %rcx
23127 + pushq %rax
23128 + pushq %r11
23129 +
23130 + GET_THREAD_INFO(%r11)
23131 + mov TI_lowest_stack(%r11), %rdi
23132 + mov $-0xBEEF, %rax
23133 + std
23134 +
23135 +1: mov %edi, %ecx
23136 + and $THREAD_SIZE_asm - 1, %ecx
23137 + shr $3, %ecx
23138 + repne scasq
23139 + jecxz 2f
23140 +
23141 + cmp $2*8, %ecx
23142 + jc 2f
23143 +
23144 + mov $2*8, %ecx
23145 + repe scasq
23146 + jecxz 2f
23147 + jne 1b
23148 +
23149 +2: cld
23150 + mov %esp, %ecx
23151 + sub %edi, %ecx
23152 +
23153 + cmp $THREAD_SIZE_asm, %rcx
23154 + jb 3f
23155 + ud2
23156 +3:
23157 +
23158 + shr $3, %ecx
23159 + rep stosq
23160 +
23161 + mov TI_task_thread_sp0(%r11), %rdi
23162 + sub $256, %rdi
23163 + mov %rdi, TI_lowest_stack(%r11)
23164 +
23165 + popq %r11
23166 + popq %rax
23167 + popq %rcx
23168 + popq %rdi
23169 + pax_force_retaddr
23170 + ret
23171 +ENDPROC(pax_erase_kstack)
23172 +#endif
23173
23174 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23175 #ifdef CONFIG_TRACE_IRQFLAGS
23176 @@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23177 .endm
23178
23179 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23180 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23181 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23182 jnc 1f
23183 TRACE_IRQS_ON_DEBUG
23184 1:
23185 @@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23186 movq \tmp,R11+\offset(%rsp)
23187 .endm
23188
23189 - .macro FAKE_STACK_FRAME child_rip
23190 - /* push in order ss, rsp, eflags, cs, rip */
23191 - xorl %eax, %eax
23192 - pushq_cfi $__KERNEL_DS /* ss */
23193 - /*CFI_REL_OFFSET ss,0*/
23194 - pushq_cfi %rax /* rsp */
23195 - CFI_REL_OFFSET rsp,0
23196 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23197 - /*CFI_REL_OFFSET rflags,0*/
23198 - pushq_cfi $__KERNEL_CS /* cs */
23199 - /*CFI_REL_OFFSET cs,0*/
23200 - pushq_cfi \child_rip /* rip */
23201 - CFI_REL_OFFSET rip,0
23202 - pushq_cfi %rax /* orig rax */
23203 - .endm
23204 -
23205 - .macro UNFAKE_STACK_FRAME
23206 - addq $8*6, %rsp
23207 - CFI_ADJUST_CFA_OFFSET -(6*8)
23208 - .endm
23209 -
23210 /*
23211 * initial frame state for interrupts (and exceptions without error code)
23212 */
23213 @@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23214 /* save partial stack frame */
23215 .macro SAVE_ARGS_IRQ
23216 cld
23217 - /* start from rbp in pt_regs and jump over */
23218 - movq_cfi rdi, (RDI-RBP)
23219 - movq_cfi rsi, (RSI-RBP)
23220 - movq_cfi rdx, (RDX-RBP)
23221 - movq_cfi rcx, (RCX-RBP)
23222 - movq_cfi rax, (RAX-RBP)
23223 - movq_cfi r8, (R8-RBP)
23224 - movq_cfi r9, (R9-RBP)
23225 - movq_cfi r10, (R10-RBP)
23226 - movq_cfi r11, (R11-RBP)
23227 + /* start from r15 in pt_regs and jump over */
23228 + movq_cfi rdi, RDI
23229 + movq_cfi rsi, RSI
23230 + movq_cfi rdx, RDX
23231 + movq_cfi rcx, RCX
23232 + movq_cfi rax, RAX
23233 + movq_cfi r8, R8
23234 + movq_cfi r9, R9
23235 + movq_cfi r10, R10
23236 + movq_cfi r11, R11
23237 + movq_cfi r12, R12
23238
23239 /* Save rbp so that we can unwind from get_irq_regs() */
23240 - movq_cfi rbp, 0
23241 + movq_cfi rbp, RBP
23242
23243 /* Save previous stack value */
23244 movq %rsp, %rsi
23245
23246 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23247 - testl $3, CS-RBP(%rsi)
23248 + movq %rsp,%rdi /* arg1 for handler */
23249 + testb $3, CS(%rsi)
23250 je 1f
23251 SWAPGS
23252 /*
23253 @@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23254 0x06 /* DW_OP_deref */, \
23255 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23256 0x22 /* DW_OP_plus */
23257 +
23258 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23259 + testb $3, CS(%rdi)
23260 + jnz 1f
23261 + pax_enter_kernel
23262 + jmp 2f
23263 +1: pax_enter_kernel_user
23264 +2:
23265 +#else
23266 + pax_enter_kernel
23267 +#endif
23268 +
23269 /* We entered an interrupt context - irqs are off: */
23270 TRACE_IRQS_OFF
23271 .endm
23272 @@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23273 js 1f /* negative -> in kernel */
23274 SWAPGS
23275 xorl %ebx,%ebx
23276 -1: ret
23277 +1:
23278 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23279 + testb $3, CS+8(%rsp)
23280 + jnz 1f
23281 + pax_enter_kernel
23282 + jmp 2f
23283 +1: pax_enter_kernel_user
23284 +2:
23285 +#else
23286 + pax_enter_kernel
23287 +#endif
23288 + pax_force_retaddr
23289 + ret
23290 CFI_ENDPROC
23291 -END(save_paranoid)
23292 +ENDPROC(save_paranoid)
23293 +
23294 +ENTRY(save_paranoid_nmi)
23295 + XCPT_FRAME 1 RDI+8
23296 + cld
23297 + movq_cfi rdi, RDI+8
23298 + movq_cfi rsi, RSI+8
23299 + movq_cfi rdx, RDX+8
23300 + movq_cfi rcx, RCX+8
23301 + movq_cfi rax, RAX+8
23302 + movq_cfi r8, R8+8
23303 + movq_cfi r9, R9+8
23304 + movq_cfi r10, R10+8
23305 + movq_cfi r11, R11+8
23306 + movq_cfi rbx, RBX+8
23307 + movq_cfi rbp, RBP+8
23308 + movq_cfi r12, R12+8
23309 + movq_cfi r13, R13+8
23310 + movq_cfi r14, R14+8
23311 + movq_cfi r15, R15+8
23312 + movl $1,%ebx
23313 + movl $MSR_GS_BASE,%ecx
23314 + rdmsr
23315 + testl %edx,%edx
23316 + js 1f /* negative -> in kernel */
23317 + SWAPGS
23318 + xorl %ebx,%ebx
23319 +1: pax_enter_kernel_nmi
23320 + pax_force_retaddr
23321 + ret
23322 + CFI_ENDPROC
23323 +ENDPROC(save_paranoid_nmi)
23324 .popsection
23325
23326 /*
23327 @@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23328
23329 RESTORE_REST
23330
23331 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23332 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23333 jz 1f
23334
23335 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23336 @@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23337 jmp ret_from_sys_call # go to the SYSRET fastpath
23338
23339 1:
23340 - subq $REST_SKIP, %rsp # leave space for volatiles
23341 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23342 movq %rbp, %rdi
23343 call *%rbx
23344 movl $0, RAX(%rsp)
23345 RESTORE_REST
23346 jmp int_ret_from_sys_call
23347 CFI_ENDPROC
23348 -END(ret_from_fork)
23349 +ENDPROC(ret_from_fork)
23350
23351 /*
23352 * System call entry. Up to 6 arguments in registers are supported.
23353 @@ -593,7 +1059,7 @@ END(ret_from_fork)
23354 ENTRY(system_call)
23355 CFI_STARTPROC simple
23356 CFI_SIGNAL_FRAME
23357 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23358 + CFI_DEF_CFA rsp,0
23359 CFI_REGISTER rip,rcx
23360 /*CFI_REGISTER rflags,r11*/
23361 SWAPGS_UNSAFE_STACK
23362 @@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23363
23364 movq %rsp,PER_CPU_VAR(old_rsp)
23365 movq PER_CPU_VAR(kernel_stack),%rsp
23366 + SAVE_ARGS 8*6,0
23367 + pax_enter_kernel_user
23368 +
23369 +#ifdef CONFIG_PAX_RANDKSTACK
23370 + pax_erase_kstack
23371 +#endif
23372 +
23373 /*
23374 * No need to follow this irqs off/on section - it's straight
23375 * and short:
23376 */
23377 ENABLE_INTERRUPTS(CLBR_NONE)
23378 - SAVE_ARGS 8,0
23379 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23380 movq %rcx,RIP-ARGOFFSET(%rsp)
23381 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23382 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23383 + GET_THREAD_INFO(%rcx)
23384 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23385 jnz tracesys
23386 system_call_fastpath:
23387 #if __SYSCALL_MASK == ~0
23388 @@ -639,10 +1112,13 @@ sysret_check:
23389 LOCKDEP_SYS_EXIT
23390 DISABLE_INTERRUPTS(CLBR_NONE)
23391 TRACE_IRQS_OFF
23392 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23393 + GET_THREAD_INFO(%rcx)
23394 + movl TI_flags(%rcx),%edx
23395 andl %edi,%edx
23396 jnz sysret_careful
23397 CFI_REMEMBER_STATE
23398 + pax_exit_kernel_user
23399 + pax_erase_kstack
23400 /*
23401 * sysretq will re-enable interrupts:
23402 */
23403 @@ -701,6 +1177,9 @@ auditsys:
23404 movq %rax,%rsi /* 2nd arg: syscall number */
23405 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23406 call __audit_syscall_entry
23407 +
23408 + pax_erase_kstack
23409 +
23410 LOAD_ARGS 0 /* reload call-clobbered registers */
23411 jmp system_call_fastpath
23412
23413 @@ -722,7 +1201,7 @@ sysret_audit:
23414 /* Do syscall tracing */
23415 tracesys:
23416 #ifdef CONFIG_AUDITSYSCALL
23417 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23418 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23419 jz auditsys
23420 #endif
23421 SAVE_REST
23422 @@ -730,12 +1209,15 @@ tracesys:
23423 FIXUP_TOP_OF_STACK %rdi
23424 movq %rsp,%rdi
23425 call syscall_trace_enter
23426 +
23427 + pax_erase_kstack
23428 +
23429 /*
23430 * Reload arg registers from stack in case ptrace changed them.
23431 * We don't reload %rax because syscall_trace_enter() returned
23432 * the value it wants us to use in the table lookup.
23433 */
23434 - LOAD_ARGS ARGOFFSET, 1
23435 + LOAD_ARGS 1
23436 RESTORE_REST
23437 #if __SYSCALL_MASK == ~0
23438 cmpq $__NR_syscall_max,%rax
23439 @@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23440 andl %edi,%edx
23441 jnz int_careful
23442 andl $~TS_COMPAT,TI_status(%rcx)
23443 - jmp retint_swapgs
23444 + pax_exit_kernel_user
23445 + pax_erase_kstack
23446 + jmp retint_swapgs_pax
23447
23448 /* Either reschedule or signal or syscall exit tracking needed. */
23449 /* First do a reschedule test. */
23450 @@ -811,7 +1295,7 @@ int_restore_rest:
23451 TRACE_IRQS_OFF
23452 jmp int_with_check
23453 CFI_ENDPROC
23454 -END(system_call)
23455 +ENDPROC(system_call)
23456
23457 .macro FORK_LIKE func
23458 ENTRY(stub_\func)
23459 @@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23460 DEFAULT_FRAME 0 8 /* offset 8: return address */
23461 call sys_\func
23462 RESTORE_TOP_OF_STACK %r11, 8
23463 - ret $REST_SKIP /* pop extended registers */
23464 + pax_force_retaddr
23465 + ret
23466 CFI_ENDPROC
23467 -END(stub_\func)
23468 +ENDPROC(stub_\func)
23469 .endm
23470
23471 .macro FIXED_FRAME label,func
23472 @@ -836,9 +1321,10 @@ ENTRY(\label)
23473 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23474 call \func
23475 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23476 + pax_force_retaddr
23477 ret
23478 CFI_ENDPROC
23479 -END(\label)
23480 +ENDPROC(\label)
23481 .endm
23482
23483 FORK_LIKE clone
23484 @@ -846,19 +1332,6 @@ END(\label)
23485 FORK_LIKE vfork
23486 FIXED_FRAME stub_iopl, sys_iopl
23487
23488 -ENTRY(ptregscall_common)
23489 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23490 - RESTORE_TOP_OF_STACK %r11, 8
23491 - movq_cfi_restore R15+8, r15
23492 - movq_cfi_restore R14+8, r14
23493 - movq_cfi_restore R13+8, r13
23494 - movq_cfi_restore R12+8, r12
23495 - movq_cfi_restore RBP+8, rbp
23496 - movq_cfi_restore RBX+8, rbx
23497 - ret $REST_SKIP /* pop extended registers */
23498 - CFI_ENDPROC
23499 -END(ptregscall_common)
23500 -
23501 ENTRY(stub_execve)
23502 CFI_STARTPROC
23503 addq $8, %rsp
23504 @@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23505 RESTORE_REST
23506 jmp int_ret_from_sys_call
23507 CFI_ENDPROC
23508 -END(stub_execve)
23509 +ENDPROC(stub_execve)
23510
23511 /*
23512 * sigreturn is special because it needs to restore all registers on return.
23513 @@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23514 RESTORE_REST
23515 jmp int_ret_from_sys_call
23516 CFI_ENDPROC
23517 -END(stub_rt_sigreturn)
23518 +ENDPROC(stub_rt_sigreturn)
23519
23520 #ifdef CONFIG_X86_X32_ABI
23521 ENTRY(stub_x32_rt_sigreturn)
23522 @@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23523 RESTORE_REST
23524 jmp int_ret_from_sys_call
23525 CFI_ENDPROC
23526 -END(stub_x32_rt_sigreturn)
23527 +ENDPROC(stub_x32_rt_sigreturn)
23528
23529 ENTRY(stub_x32_execve)
23530 CFI_STARTPROC
23531 @@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23532 RESTORE_REST
23533 jmp int_ret_from_sys_call
23534 CFI_ENDPROC
23535 -END(stub_x32_execve)
23536 +ENDPROC(stub_x32_execve)
23537
23538 #endif
23539
23540 @@ -952,7 +1425,7 @@ vector=vector+1
23541 2: jmp common_interrupt
23542 .endr
23543 CFI_ENDPROC
23544 -END(irq_entries_start)
23545 +ENDPROC(irq_entries_start)
23546
23547 .previous
23548 END(interrupt)
23549 @@ -969,8 +1442,8 @@ END(interrupt)
23550 /* 0(%rsp): ~(interrupt number) */
23551 .macro interrupt func
23552 /* reserve pt_regs for scratch regs and rbp */
23553 - subq $ORIG_RAX-RBP, %rsp
23554 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23555 + subq $ORIG_RAX, %rsp
23556 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23557 SAVE_ARGS_IRQ
23558 call \func
23559 .endm
23560 @@ -997,14 +1470,14 @@ ret_from_intr:
23561
23562 /* Restore saved previous stack */
23563 popq %rsi
23564 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23565 - leaq ARGOFFSET-RBP(%rsi), %rsp
23566 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23567 + movq %rsi, %rsp
23568 CFI_DEF_CFA_REGISTER rsp
23569 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23570 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23571
23572 exit_intr:
23573 GET_THREAD_INFO(%rcx)
23574 - testl $3,CS-ARGOFFSET(%rsp)
23575 + testb $3,CS-ARGOFFSET(%rsp)
23576 je retint_kernel
23577
23578 /* Interrupt came from user space */
23579 @@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23580 * The iretq could re-enable interrupts:
23581 */
23582 DISABLE_INTERRUPTS(CLBR_ANY)
23583 + pax_exit_kernel_user
23584 +retint_swapgs_pax:
23585 TRACE_IRQS_IRETQ
23586 SWAPGS
23587 jmp restore_args
23588
23589 retint_restore_args: /* return to kernel space */
23590 DISABLE_INTERRUPTS(CLBR_ANY)
23591 + pax_exit_kernel
23592 + pax_force_retaddr (RIP-ARGOFFSET)
23593 /*
23594 * The iretq could re-enable interrupts:
23595 */
23596 @@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23597 #endif
23598
23599 CFI_ENDPROC
23600 -END(common_interrupt)
23601 +ENDPROC(common_interrupt)
23602 /*
23603 * End of kprobes section
23604 */
23605 @@ -1130,7 +1607,7 @@ ENTRY(\sym)
23606 interrupt \do_sym
23607 jmp ret_from_intr
23608 CFI_ENDPROC
23609 -END(\sym)
23610 +ENDPROC(\sym)
23611 .endm
23612
23613 #ifdef CONFIG_TRACING
23614 @@ -1218,7 +1695,7 @@ ENTRY(\sym)
23615 call \do_sym
23616 jmp error_exit /* %ebx: no swapgs flag */
23617 CFI_ENDPROC
23618 -END(\sym)
23619 +ENDPROC(\sym)
23620 .endm
23621
23622 .macro paranoidzeroentry sym do_sym
23623 @@ -1236,10 +1713,10 @@ ENTRY(\sym)
23624 call \do_sym
23625 jmp paranoid_exit /* %ebx: no swapgs flag */
23626 CFI_ENDPROC
23627 -END(\sym)
23628 +ENDPROC(\sym)
23629 .endm
23630
23631 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23632 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23633 .macro paranoidzeroentry_ist sym do_sym ist
23634 ENTRY(\sym)
23635 INTR_FRAME
23636 @@ -1252,12 +1729,18 @@ ENTRY(\sym)
23637 TRACE_IRQS_OFF_DEBUG
23638 movq %rsp,%rdi /* pt_regs pointer */
23639 xorl %esi,%esi /* no error code */
23640 +#ifdef CONFIG_SMP
23641 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23642 + lea init_tss(%r13), %r13
23643 +#else
23644 + lea init_tss(%rip), %r13
23645 +#endif
23646 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23647 call \do_sym
23648 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23649 jmp paranoid_exit /* %ebx: no swapgs flag */
23650 CFI_ENDPROC
23651 -END(\sym)
23652 +ENDPROC(\sym)
23653 .endm
23654
23655 .macro errorentry sym do_sym
23656 @@ -1275,7 +1758,7 @@ ENTRY(\sym)
23657 call \do_sym
23658 jmp error_exit /* %ebx: no swapgs flag */
23659 CFI_ENDPROC
23660 -END(\sym)
23661 +ENDPROC(\sym)
23662 .endm
23663
23664 #ifdef CONFIG_TRACING
23665 @@ -1306,7 +1789,7 @@ ENTRY(\sym)
23666 call \do_sym
23667 jmp paranoid_exit /* %ebx: no swapgs flag */
23668 CFI_ENDPROC
23669 -END(\sym)
23670 +ENDPROC(\sym)
23671 .endm
23672
23673 zeroentry divide_error do_divide_error
23674 @@ -1336,9 +1819,10 @@ gs_change:
23675 2: mfence /* workaround */
23676 SWAPGS
23677 popfq_cfi
23678 + pax_force_retaddr
23679 ret
23680 CFI_ENDPROC
23681 -END(native_load_gs_index)
23682 +ENDPROC(native_load_gs_index)
23683
23684 _ASM_EXTABLE(gs_change,bad_gs)
23685 .section .fixup,"ax"
23686 @@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23687 CFI_DEF_CFA_REGISTER rsp
23688 CFI_ADJUST_CFA_OFFSET -8
23689 decl PER_CPU_VAR(irq_count)
23690 + pax_force_retaddr
23691 ret
23692 CFI_ENDPROC
23693 -END(do_softirq_own_stack)
23694 +ENDPROC(do_softirq_own_stack)
23695
23696 #ifdef CONFIG_XEN
23697 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23698 @@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23699 decl PER_CPU_VAR(irq_count)
23700 jmp error_exit
23701 CFI_ENDPROC
23702 -END(xen_do_hypervisor_callback)
23703 +ENDPROC(xen_do_hypervisor_callback)
23704
23705 /*
23706 * Hypervisor uses this for application faults while it executes.
23707 @@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23708 SAVE_ALL
23709 jmp error_exit
23710 CFI_ENDPROC
23711 -END(xen_failsafe_callback)
23712 +ENDPROC(xen_failsafe_callback)
23713
23714 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23715 xen_hvm_callback_vector xen_evtchn_do_upcall
23716 @@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23717 DEFAULT_FRAME
23718 DISABLE_INTERRUPTS(CLBR_NONE)
23719 TRACE_IRQS_OFF_DEBUG
23720 - testl %ebx,%ebx /* swapgs needed? */
23721 + testl $1,%ebx /* swapgs needed? */
23722 jnz paranoid_restore
23723 - testl $3,CS(%rsp)
23724 + testb $3,CS(%rsp)
23725 jnz paranoid_userspace
23726 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23727 + pax_exit_kernel
23728 + TRACE_IRQS_IRETQ 0
23729 + SWAPGS_UNSAFE_STACK
23730 + RESTORE_ALL 8
23731 + pax_force_retaddr_bts
23732 + jmp irq_return
23733 +#endif
23734 paranoid_swapgs:
23735 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23736 + pax_exit_kernel_user
23737 +#else
23738 + pax_exit_kernel
23739 +#endif
23740 TRACE_IRQS_IRETQ 0
23741 SWAPGS_UNSAFE_STACK
23742 RESTORE_ALL 8
23743 jmp irq_return
23744 paranoid_restore:
23745 + pax_exit_kernel
23746 TRACE_IRQS_IRETQ_DEBUG 0
23747 RESTORE_ALL 8
23748 + pax_force_retaddr_bts
23749 jmp irq_return
23750 paranoid_userspace:
23751 GET_THREAD_INFO(%rcx)
23752 @@ -1557,7 +2057,7 @@ paranoid_schedule:
23753 TRACE_IRQS_OFF
23754 jmp paranoid_userspace
23755 CFI_ENDPROC
23756 -END(paranoid_exit)
23757 +ENDPROC(paranoid_exit)
23758
23759 /*
23760 * Exception entry point. This expects an error code/orig_rax on the stack.
23761 @@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23762 movq_cfi r14, R14+8
23763 movq_cfi r15, R15+8
23764 xorl %ebx,%ebx
23765 - testl $3,CS+8(%rsp)
23766 + testb $3,CS+8(%rsp)
23767 je error_kernelspace
23768 error_swapgs:
23769 SWAPGS
23770 error_sti:
23771 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23772 + testb $3, CS+8(%rsp)
23773 + jnz 1f
23774 + pax_enter_kernel
23775 + jmp 2f
23776 +1: pax_enter_kernel_user
23777 +2:
23778 +#else
23779 + pax_enter_kernel
23780 +#endif
23781 TRACE_IRQS_OFF
23782 + pax_force_retaddr
23783 ret
23784
23785 /*
23786 @@ -1616,7 +2127,7 @@ bstep_iret:
23787 movq %rcx,RIP+8(%rsp)
23788 jmp error_swapgs
23789 CFI_ENDPROC
23790 -END(error_entry)
23791 +ENDPROC(error_entry)
23792
23793
23794 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23795 @@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23796 DISABLE_INTERRUPTS(CLBR_NONE)
23797 TRACE_IRQS_OFF
23798 GET_THREAD_INFO(%rcx)
23799 - testl %eax,%eax
23800 + testl $1,%eax
23801 jne retint_kernel
23802 LOCKDEP_SYS_EXIT_IRQ
23803 movl TI_flags(%rcx),%edx
23804 @@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23805 jnz retint_careful
23806 jmp retint_swapgs
23807 CFI_ENDPROC
23808 -END(error_exit)
23809 +ENDPROC(error_exit)
23810
23811 /*
23812 * Test if a given stack is an NMI stack or not.
23813 @@ -1694,9 +2205,11 @@ ENTRY(nmi)
23814 * If %cs was not the kernel segment, then the NMI triggered in user
23815 * space, which means it is definitely not nested.
23816 */
23817 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23818 + je 1f
23819 cmpl $__KERNEL_CS, 16(%rsp)
23820 jne first_nmi
23821 -
23822 +1:
23823 /*
23824 * Check the special variable on the stack to see if NMIs are
23825 * executing.
23826 @@ -1730,8 +2243,7 @@ nested_nmi:
23827
23828 1:
23829 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23830 - leaq -1*8(%rsp), %rdx
23831 - movq %rdx, %rsp
23832 + subq $8, %rsp
23833 CFI_ADJUST_CFA_OFFSET 1*8
23834 leaq -10*8(%rsp), %rdx
23835 pushq_cfi $__KERNEL_DS
23836 @@ -1749,6 +2261,7 @@ nested_nmi_out:
23837 CFI_RESTORE rdx
23838
23839 /* No need to check faults here */
23840 +# pax_force_retaddr_bts
23841 INTERRUPT_RETURN
23842
23843 CFI_RESTORE_STATE
23844 @@ -1845,13 +2358,13 @@ end_repeat_nmi:
23845 subq $ORIG_RAX-R15, %rsp
23846 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23847 /*
23848 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23849 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23850 * as we should not be calling schedule in NMI context.
23851 * Even with normal interrupts enabled. An NMI should not be
23852 * setting NEED_RESCHED or anything that normal interrupts and
23853 * exceptions might do.
23854 */
23855 - call save_paranoid
23856 + call save_paranoid_nmi
23857 DEFAULT_FRAME 0
23858
23859 /*
23860 @@ -1861,9 +2374,9 @@ end_repeat_nmi:
23861 * NMI itself takes a page fault, the page fault that was preempted
23862 * will read the information from the NMI page fault and not the
23863 * origin fault. Save it off and restore it if it changes.
23864 - * Use the r12 callee-saved register.
23865 + * Use the r13 callee-saved register.
23866 */
23867 - movq %cr2, %r12
23868 + movq %cr2, %r13
23869
23870 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23871 movq %rsp,%rdi
23872 @@ -1872,31 +2385,36 @@ end_repeat_nmi:
23873
23874 /* Did the NMI take a page fault? Restore cr2 if it did */
23875 movq %cr2, %rcx
23876 - cmpq %rcx, %r12
23877 + cmpq %rcx, %r13
23878 je 1f
23879 - movq %r12, %cr2
23880 + movq %r13, %cr2
23881 1:
23882
23883 - testl %ebx,%ebx /* swapgs needed? */
23884 + testl $1,%ebx /* swapgs needed? */
23885 jnz nmi_restore
23886 nmi_swapgs:
23887 SWAPGS_UNSAFE_STACK
23888 nmi_restore:
23889 + pax_exit_kernel_nmi
23890 /* Pop the extra iret frame at once */
23891 RESTORE_ALL 6*8
23892 + testb $3, 8(%rsp)
23893 + jnz 1f
23894 + pax_force_retaddr_bts
23895 +1:
23896
23897 /* Clear the NMI executing stack variable */
23898 movq $0, 5*8(%rsp)
23899 jmp irq_return
23900 CFI_ENDPROC
23901 -END(nmi)
23902 +ENDPROC(nmi)
23903
23904 ENTRY(ignore_sysret)
23905 CFI_STARTPROC
23906 mov $-ENOSYS,%eax
23907 sysret
23908 CFI_ENDPROC
23909 -END(ignore_sysret)
23910 +ENDPROC(ignore_sysret)
23911
23912 /*
23913 * End of kprobes section
23914 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23915 index e625319..b9abb9d 100644
23916 --- a/arch/x86/kernel/ftrace.c
23917 +++ b/arch/x86/kernel/ftrace.c
23918 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23919 {
23920 unsigned char replaced[MCOUNT_INSN_SIZE];
23921
23922 + ip = ktla_ktva(ip);
23923 +
23924 /*
23925 * Note: Due to modules and __init, code can
23926 * disappear and change, we need to protect against faulting
23927 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
23928 unsigned char old[MCOUNT_INSN_SIZE];
23929 int ret;
23930
23931 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
23932 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
23933
23934 ftrace_update_func = ip;
23935 /* Make sure the breakpoints see the ftrace_update_func update */
23936 @@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23937 * kernel identity mapping to modify code.
23938 */
23939 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23940 - ip = (unsigned long)__va(__pa_symbol(ip));
23941 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23942
23943 return probe_kernel_write((void *)ip, val, size);
23944 }
23945 @@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
23946 unsigned char replaced[MCOUNT_INSN_SIZE];
23947 unsigned char brk = BREAKPOINT_INSTRUCTION;
23948
23949 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23950 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23951 return -EFAULT;
23952
23953 /* Make sure it is what we expect it to be */
23954 @@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23955 return ret;
23956
23957 fail_update:
23958 - probe_kernel_write((void *)ip, &old_code[0], 1);
23959 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23960 goto out;
23961 }
23962
23963 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23964 index 85126cc..1bbce17 100644
23965 --- a/arch/x86/kernel/head64.c
23966 +++ b/arch/x86/kernel/head64.c
23967 @@ -67,12 +67,12 @@ again:
23968 pgd = *pgd_p;
23969
23970 /*
23971 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23972 - * critical -- __PAGE_OFFSET would point us back into the dynamic
23973 + * The use of __early_va rather than __va here is critical:
23974 + * __va would point us back into the dynamic
23975 * range and we might end up looping forever...
23976 */
23977 if (pgd)
23978 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23979 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23980 else {
23981 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23982 reset_early_page_tables();
23983 @@ -82,13 +82,13 @@ again:
23984 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
23985 for (i = 0; i < PTRS_PER_PUD; i++)
23986 pud_p[i] = 0;
23987 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23988 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
23989 }
23990 pud_p += pud_index(address);
23991 pud = *pud_p;
23992
23993 if (pud)
23994 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23995 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
23996 else {
23997 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23998 reset_early_page_tables();
23999 @@ -98,7 +98,7 @@ again:
24000 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24001 for (i = 0; i < PTRS_PER_PMD; i++)
24002 pmd_p[i] = 0;
24003 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24004 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24005 }
24006 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24007 pmd_p[pmd_index(address)] = pmd;
24008 @@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
24009 if (console_loglevel == 10)
24010 early_printk("Kernel alive\n");
24011
24012 - clear_page(init_level4_pgt);
24013 /* set init_level4_pgt kernel high mapping*/
24014 init_level4_pgt[511] = early_level4_pgt[511];
24015
24016 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24017 index f36bd42..56ee1534 100644
24018 --- a/arch/x86/kernel/head_32.S
24019 +++ b/arch/x86/kernel/head_32.S
24020 @@ -26,6 +26,12 @@
24021 /* Physical address */
24022 #define pa(X) ((X) - __PAGE_OFFSET)
24023
24024 +#ifdef CONFIG_PAX_KERNEXEC
24025 +#define ta(X) (X)
24026 +#else
24027 +#define ta(X) ((X) - __PAGE_OFFSET)
24028 +#endif
24029 +
24030 /*
24031 * References to members of the new_cpu_data structure.
24032 */
24033 @@ -55,11 +61,7 @@
24034 * and small than max_low_pfn, otherwise will waste some page table entries
24035 */
24036
24037 -#if PTRS_PER_PMD > 1
24038 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24039 -#else
24040 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24041 -#endif
24042 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24043
24044 /* Number of possible pages in the lowmem region */
24045 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24046 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24047 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24048
24049 /*
24050 + * Real beginning of normal "text" segment
24051 + */
24052 +ENTRY(stext)
24053 +ENTRY(_stext)
24054 +
24055 +/*
24056 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24057 * %esi points to the real-mode code as a 32-bit pointer.
24058 * CS and DS must be 4 GB flat segments, but we don't depend on
24059 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24060 * can.
24061 */
24062 __HEAD
24063 +
24064 +#ifdef CONFIG_PAX_KERNEXEC
24065 + jmp startup_32
24066 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24067 +.fill PAGE_SIZE-5,1,0xcc
24068 +#endif
24069 +
24070 ENTRY(startup_32)
24071 movl pa(stack_start),%ecx
24072
24073 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24074 2:
24075 leal -__PAGE_OFFSET(%ecx),%esp
24076
24077 +#ifdef CONFIG_SMP
24078 + movl $pa(cpu_gdt_table),%edi
24079 + movl $__per_cpu_load,%eax
24080 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24081 + rorl $16,%eax
24082 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24083 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24084 + movl $__per_cpu_end - 1,%eax
24085 + subl $__per_cpu_start,%eax
24086 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24087 +#endif
24088 +
24089 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24090 + movl $NR_CPUS,%ecx
24091 + movl $pa(cpu_gdt_table),%edi
24092 +1:
24093 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24094 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24095 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24096 + addl $PAGE_SIZE_asm,%edi
24097 + loop 1b
24098 +#endif
24099 +
24100 +#ifdef CONFIG_PAX_KERNEXEC
24101 + movl $pa(boot_gdt),%edi
24102 + movl $__LOAD_PHYSICAL_ADDR,%eax
24103 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24104 + rorl $16,%eax
24105 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24106 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24107 + rorl $16,%eax
24108 +
24109 + ljmp $(__BOOT_CS),$1f
24110 +1:
24111 +
24112 + movl $NR_CPUS,%ecx
24113 + movl $pa(cpu_gdt_table),%edi
24114 + addl $__PAGE_OFFSET,%eax
24115 +1:
24116 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24117 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24118 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24119 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24120 + rorl $16,%eax
24121 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24122 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24123 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24124 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24125 + rorl $16,%eax
24126 + addl $PAGE_SIZE_asm,%edi
24127 + loop 1b
24128 +#endif
24129 +
24130 /*
24131 * Clear BSS first so that there are no surprises...
24132 */
24133 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24134 movl %eax, pa(max_pfn_mapped)
24135
24136 /* Do early initialization of the fixmap area */
24137 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24138 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24139 +#ifdef CONFIG_COMPAT_VDSO
24140 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24141 +#else
24142 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24143 +#endif
24144 #else /* Not PAE */
24145
24146 page_pde_offset = (__PAGE_OFFSET >> 20);
24147 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24148 movl %eax, pa(max_pfn_mapped)
24149
24150 /* Do early initialization of the fixmap area */
24151 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24152 - movl %eax,pa(initial_page_table+0xffc)
24153 +#ifdef CONFIG_COMPAT_VDSO
24154 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24155 +#else
24156 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24157 +#endif
24158 #endif
24159
24160 #ifdef CONFIG_PARAVIRT
24161 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24162 cmpl $num_subarch_entries, %eax
24163 jae bad_subarch
24164
24165 - movl pa(subarch_entries)(,%eax,4), %eax
24166 - subl $__PAGE_OFFSET, %eax
24167 - jmp *%eax
24168 + jmp *pa(subarch_entries)(,%eax,4)
24169
24170 bad_subarch:
24171 WEAK(lguest_entry)
24172 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24173 __INITDATA
24174
24175 subarch_entries:
24176 - .long default_entry /* normal x86/PC */
24177 - .long lguest_entry /* lguest hypervisor */
24178 - .long xen_entry /* Xen hypervisor */
24179 - .long default_entry /* Moorestown MID */
24180 + .long ta(default_entry) /* normal x86/PC */
24181 + .long ta(lguest_entry) /* lguest hypervisor */
24182 + .long ta(xen_entry) /* Xen hypervisor */
24183 + .long ta(default_entry) /* Moorestown MID */
24184 num_subarch_entries = (. - subarch_entries) / 4
24185 .previous
24186 #else
24187 @@ -354,6 +426,7 @@ default_entry:
24188 movl pa(mmu_cr4_features),%eax
24189 movl %eax,%cr4
24190
24191 +#ifdef CONFIG_X86_PAE
24192 testb $X86_CR4_PAE, %al # check if PAE is enabled
24193 jz enable_paging
24194
24195 @@ -382,6 +455,9 @@ default_entry:
24196 /* Make changes effective */
24197 wrmsr
24198
24199 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24200 +#endif
24201 +
24202 enable_paging:
24203
24204 /*
24205 @@ -449,14 +525,20 @@ is486:
24206 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24207 movl %eax,%ss # after changing gdt.
24208
24209 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24210 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24211 movl %eax,%ds
24212 movl %eax,%es
24213
24214 movl $(__KERNEL_PERCPU), %eax
24215 movl %eax,%fs # set this cpu's percpu
24216
24217 +#ifdef CONFIG_CC_STACKPROTECTOR
24218 movl $(__KERNEL_STACK_CANARY),%eax
24219 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24220 + movl $(__USER_DS),%eax
24221 +#else
24222 + xorl %eax,%eax
24223 +#endif
24224 movl %eax,%gs
24225
24226 xorl %eax,%eax # Clear LDT
24227 @@ -512,8 +594,11 @@ setup_once:
24228 * relocation. Manually set base address in stack canary
24229 * segment descriptor.
24230 */
24231 - movl $gdt_page,%eax
24232 + movl $cpu_gdt_table,%eax
24233 movl $stack_canary,%ecx
24234 +#ifdef CONFIG_SMP
24235 + addl $__per_cpu_load,%ecx
24236 +#endif
24237 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24238 shrl $16, %ecx
24239 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24240 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24241 cmpl $2,(%esp) # X86_TRAP_NMI
24242 je is_nmi # Ignore NMI
24243
24244 - cmpl $2,%ss:early_recursion_flag
24245 + cmpl $1,%ss:early_recursion_flag
24246 je hlt_loop
24247 incl %ss:early_recursion_flag
24248
24249 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24250 pushl (20+6*4)(%esp) /* trapno */
24251 pushl $fault_msg
24252 call printk
24253 -#endif
24254 call dump_stack
24255 +#endif
24256 hlt_loop:
24257 hlt
24258 jmp hlt_loop
24259 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24260 /* This is the default interrupt "handler" :-) */
24261 ALIGN
24262 ignore_int:
24263 - cld
24264 #ifdef CONFIG_PRINTK
24265 + cmpl $2,%ss:early_recursion_flag
24266 + je hlt_loop
24267 + incl %ss:early_recursion_flag
24268 + cld
24269 pushl %eax
24270 pushl %ecx
24271 pushl %edx
24272 @@ -617,9 +705,6 @@ ignore_int:
24273 movl $(__KERNEL_DS),%eax
24274 movl %eax,%ds
24275 movl %eax,%es
24276 - cmpl $2,early_recursion_flag
24277 - je hlt_loop
24278 - incl early_recursion_flag
24279 pushl 16(%esp)
24280 pushl 24(%esp)
24281 pushl 32(%esp)
24282 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24283 /*
24284 * BSS section
24285 */
24286 -__PAGE_ALIGNED_BSS
24287 - .align PAGE_SIZE
24288 #ifdef CONFIG_X86_PAE
24289 +.section .initial_pg_pmd,"a",@progbits
24290 initial_pg_pmd:
24291 .fill 1024*KPMDS,4,0
24292 #else
24293 +.section .initial_page_table,"a",@progbits
24294 ENTRY(initial_page_table)
24295 .fill 1024,4,0
24296 #endif
24297 +.section .initial_pg_fixmap,"a",@progbits
24298 initial_pg_fixmap:
24299 .fill 1024,4,0
24300 +.section .empty_zero_page,"a",@progbits
24301 ENTRY(empty_zero_page)
24302 .fill 4096,1,0
24303 +.section .swapper_pg_dir,"a",@progbits
24304 ENTRY(swapper_pg_dir)
24305 +#ifdef CONFIG_X86_PAE
24306 + .fill 4,8,0
24307 +#else
24308 .fill 1024,4,0
24309 +#endif
24310
24311 /*
24312 * This starts the data section.
24313 */
24314 #ifdef CONFIG_X86_PAE
24315 -__PAGE_ALIGNED_DATA
24316 - /* Page-aligned for the benefit of paravirt? */
24317 - .align PAGE_SIZE
24318 +.section .initial_page_table,"a",@progbits
24319 ENTRY(initial_page_table)
24320 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24321 # if KPMDS == 3
24322 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24323 # error "Kernel PMDs should be 1, 2 or 3"
24324 # endif
24325 .align PAGE_SIZE /* needs to be page-sized too */
24326 +
24327 +#ifdef CONFIG_PAX_PER_CPU_PGD
24328 +ENTRY(cpu_pgd)
24329 + .rept 2*NR_CPUS
24330 + .fill 4,8,0
24331 + .endr
24332 +#endif
24333 +
24334 #endif
24335
24336 .data
24337 .balign 4
24338 ENTRY(stack_start)
24339 - .long init_thread_union+THREAD_SIZE
24340 + .long init_thread_union+THREAD_SIZE-8
24341
24342 __INITRODATA
24343 int_msg:
24344 @@ -727,7 +825,7 @@ fault_msg:
24345 * segment size, and 32-bit linear address value:
24346 */
24347
24348 - .data
24349 +.section .rodata,"a",@progbits
24350 .globl boot_gdt_descr
24351 .globl idt_descr
24352
24353 @@ -736,7 +834,7 @@ fault_msg:
24354 .word 0 # 32 bit align gdt_desc.address
24355 boot_gdt_descr:
24356 .word __BOOT_DS+7
24357 - .long boot_gdt - __PAGE_OFFSET
24358 + .long pa(boot_gdt)
24359
24360 .word 0 # 32-bit align idt_desc.address
24361 idt_descr:
24362 @@ -747,7 +845,7 @@ idt_descr:
24363 .word 0 # 32 bit align gdt_desc.address
24364 ENTRY(early_gdt_descr)
24365 .word GDT_ENTRIES*8-1
24366 - .long gdt_page /* Overwritten for secondary CPUs */
24367 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24368
24369 /*
24370 * The boot_gdt must mirror the equivalent in setup.S and is
24371 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24372 .align L1_CACHE_BYTES
24373 ENTRY(boot_gdt)
24374 .fill GDT_ENTRY_BOOT_CS,8,0
24375 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24376 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24377 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24378 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24379 +
24380 + .align PAGE_SIZE_asm
24381 +ENTRY(cpu_gdt_table)
24382 + .rept NR_CPUS
24383 + .quad 0x0000000000000000 /* NULL descriptor */
24384 + .quad 0x0000000000000000 /* 0x0b reserved */
24385 + .quad 0x0000000000000000 /* 0x13 reserved */
24386 + .quad 0x0000000000000000 /* 0x1b reserved */
24387 +
24388 +#ifdef CONFIG_PAX_KERNEXEC
24389 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24390 +#else
24391 + .quad 0x0000000000000000 /* 0x20 unused */
24392 +#endif
24393 +
24394 + .quad 0x0000000000000000 /* 0x28 unused */
24395 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24396 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24397 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24398 + .quad 0x0000000000000000 /* 0x4b reserved */
24399 + .quad 0x0000000000000000 /* 0x53 reserved */
24400 + .quad 0x0000000000000000 /* 0x5b reserved */
24401 +
24402 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24403 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24404 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24405 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24406 +
24407 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24408 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24409 +
24410 + /*
24411 + * Segments used for calling PnP BIOS have byte granularity.
24412 + * The code segments and data segments have fixed 64k limits,
24413 + * the transfer segment sizes are set at run time.
24414 + */
24415 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24416 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24417 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24418 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24419 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24420 +
24421 + /*
24422 + * The APM segments have byte granularity and their bases
24423 + * are set at run time. All have 64k limits.
24424 + */
24425 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24426 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24427 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24428 +
24429 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24430 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24431 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24432 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24433 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24434 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24435 +
24436 + /* Be sure this is zeroed to avoid false validations in Xen */
24437 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24438 + .endr
24439 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24440 index a468c0a..c7dec74 100644
24441 --- a/arch/x86/kernel/head_64.S
24442 +++ b/arch/x86/kernel/head_64.S
24443 @@ -20,6 +20,8 @@
24444 #include <asm/processor-flags.h>
24445 #include <asm/percpu.h>
24446 #include <asm/nops.h>
24447 +#include <asm/cpufeature.h>
24448 +#include <asm/alternative-asm.h>
24449
24450 #ifdef CONFIG_PARAVIRT
24451 #include <asm/asm-offsets.h>
24452 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24453 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24454 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24455 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24456 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24457 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24458 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24459 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24460 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24461 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24462
24463 .text
24464 __HEAD
24465 @@ -89,11 +97,24 @@ startup_64:
24466 * Fixup the physical addresses in the page table
24467 */
24468 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24469 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24470 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24471 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24472 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24473 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24474
24475 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24476 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24477 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24478 +#ifndef CONFIG_XEN
24479 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24480 +#endif
24481 +
24482 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24483 +
24484 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24485 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24486
24487 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24488 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24489
24490 /*
24491 * Set up the identity mapping for the switchover. These
24492 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24493 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24494 1:
24495
24496 - /* Enable PAE mode and PGE */
24497 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24498 + /* Enable PAE mode and PSE/PGE */
24499 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24500 movq %rcx, %cr4
24501
24502 /* Setup early boot stage 4 level pagetables. */
24503 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24504 movl $MSR_EFER, %ecx
24505 rdmsr
24506 btsl $_EFER_SCE, %eax /* Enable System Call */
24507 - btl $20,%edi /* No Execute supported? */
24508 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24509 jnc 1f
24510 btsl $_EFER_NX, %eax
24511 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24512 +#ifndef CONFIG_EFI
24513 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24514 +#endif
24515 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24516 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24517 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24518 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24519 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24520 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24521 1: wrmsr /* Make changes effective */
24522
24523 /* Setup cr0 */
24524 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24525 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24526 * address given in m16:64.
24527 */
24528 + pax_set_fptr_mask
24529 movq initial_code(%rip),%rax
24530 pushq $0 # fake return address to stop unwinder
24531 pushq $__KERNEL_CS # set correct cs
24532 @@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24533 .quad INIT_PER_CPU_VAR(irq_stack_union)
24534
24535 GLOBAL(stack_start)
24536 - .quad init_thread_union+THREAD_SIZE-8
24537 + .quad init_thread_union+THREAD_SIZE-16
24538 .word 0
24539 __FINITDATA
24540
24541 @@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24542 call dump_stack
24543 #ifdef CONFIG_KALLSYMS
24544 leaq early_idt_ripmsg(%rip),%rdi
24545 - movq 40(%rsp),%rsi # %rip again
24546 + movq 88(%rsp),%rsi # %rip again
24547 call __print_symbol
24548 #endif
24549 #endif /* EARLY_PRINTK */
24550 @@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24551 early_recursion_flag:
24552 .long 0
24553
24554 + .section .rodata,"a",@progbits
24555 #ifdef CONFIG_EARLY_PRINTK
24556 early_idt_msg:
24557 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24558 @@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24559 NEXT_PAGE(early_dynamic_pgts)
24560 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24561
24562 - .data
24563 + .section .rodata,"a",@progbits
24564
24565 -#ifndef CONFIG_XEN
24566 NEXT_PAGE(init_level4_pgt)
24567 - .fill 512,8,0
24568 -#else
24569 -NEXT_PAGE(init_level4_pgt)
24570 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24571 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24572 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24573 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24574 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24575 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24576 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24577 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24578 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24579 .org init_level4_pgt + L4_START_KERNEL*8, 0
24580 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24581 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24582
24583 +#ifdef CONFIG_PAX_PER_CPU_PGD
24584 +NEXT_PAGE(cpu_pgd)
24585 + .rept 2*NR_CPUS
24586 + .fill 512,8,0
24587 + .endr
24588 +#endif
24589 +
24590 NEXT_PAGE(level3_ident_pgt)
24591 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24592 +#ifdef CONFIG_XEN
24593 .fill 511, 8, 0
24594 +#else
24595 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24596 + .fill 510,8,0
24597 +#endif
24598 +
24599 +NEXT_PAGE(level3_vmalloc_start_pgt)
24600 + .fill 512,8,0
24601 +
24602 +NEXT_PAGE(level3_vmalloc_end_pgt)
24603 + .fill 512,8,0
24604 +
24605 +NEXT_PAGE(level3_vmemmap_pgt)
24606 + .fill L3_VMEMMAP_START,8,0
24607 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24608 +
24609 NEXT_PAGE(level2_ident_pgt)
24610 - /* Since I easily can, map the first 1G.
24611 + /* Since I easily can, map the first 2G.
24612 * Don't set NX because code runs from these pages.
24613 */
24614 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24615 -#endif
24616 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24617
24618 NEXT_PAGE(level3_kernel_pgt)
24619 .fill L3_START_KERNEL,8,0
24620 @@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24621 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24622 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24623
24624 +NEXT_PAGE(level2_vmemmap_pgt)
24625 + .fill 512,8,0
24626 +
24627 NEXT_PAGE(level2_kernel_pgt)
24628 /*
24629 * 512 MB kernel mapping. We spend a full page on this pagetable
24630 @@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24631 NEXT_PAGE(level2_fixmap_pgt)
24632 .fill 506,8,0
24633 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24634 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24635 - .fill 5,8,0
24636 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24637 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24638 + .fill 4,8,0
24639
24640 NEXT_PAGE(level1_fixmap_pgt)
24641 .fill 512,8,0
24642
24643 +NEXT_PAGE(level1_vsyscall_pgt)
24644 + .fill 512,8,0
24645 +
24646 #undef PMDS
24647
24648 - .data
24649 + .align PAGE_SIZE
24650 +ENTRY(cpu_gdt_table)
24651 + .rept NR_CPUS
24652 + .quad 0x0000000000000000 /* NULL descriptor */
24653 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24654 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
24655 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
24656 + .quad 0x00cffb000000ffff /* __USER32_CS */
24657 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24658 + .quad 0x00affb000000ffff /* __USER_CS */
24659 +
24660 +#ifdef CONFIG_PAX_KERNEXEC
24661 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24662 +#else
24663 + .quad 0x0 /* unused */
24664 +#endif
24665 +
24666 + .quad 0,0 /* TSS */
24667 + .quad 0,0 /* LDT */
24668 + .quad 0,0,0 /* three TLS descriptors */
24669 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
24670 + /* asm/segment.h:GDT_ENTRIES must match this */
24671 +
24672 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24673 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24674 +#else
24675 + .quad 0x0 /* unused */
24676 +#endif
24677 +
24678 + /* zero the remaining page */
24679 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24680 + .endr
24681 +
24682 .align 16
24683 .globl early_gdt_descr
24684 early_gdt_descr:
24685 .word GDT_ENTRIES*8-1
24686 early_gdt_descr_base:
24687 - .quad INIT_PER_CPU_VAR(gdt_page)
24688 + .quad cpu_gdt_table
24689
24690 ENTRY(phys_base)
24691 /* This must match the first entry in level2_kernel_pgt */
24692 .quad 0x0000000000000000
24693
24694 #include "../../x86/xen/xen-head.S"
24695 -
24696 - __PAGE_ALIGNED_BSS
24697 +
24698 + .section .rodata,"a",@progbits
24699 NEXT_PAGE(empty_zero_page)
24700 .skip PAGE_SIZE
24701 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24702 index 05fd74f..c3548b1 100644
24703 --- a/arch/x86/kernel/i386_ksyms_32.c
24704 +++ b/arch/x86/kernel/i386_ksyms_32.c
24705 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24706 EXPORT_SYMBOL(cmpxchg8b_emu);
24707 #endif
24708
24709 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
24710 +
24711 /* Networking helper routines. */
24712 EXPORT_SYMBOL(csum_partial_copy_generic);
24713 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24714 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24715
24716 EXPORT_SYMBOL(__get_user_1);
24717 EXPORT_SYMBOL(__get_user_2);
24718 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24719 EXPORT_SYMBOL(___preempt_schedule_context);
24720 #endif
24721 #endif
24722 +
24723 +#ifdef CONFIG_PAX_KERNEXEC
24724 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24725 +#endif
24726 +
24727 +#ifdef CONFIG_PAX_PER_CPU_PGD
24728 +EXPORT_SYMBOL(cpu_pgd);
24729 +#endif
24730 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24731 index d5dd808..b6432cf 100644
24732 --- a/arch/x86/kernel/i387.c
24733 +++ b/arch/x86/kernel/i387.c
24734 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24735 static inline bool interrupted_user_mode(void)
24736 {
24737 struct pt_regs *regs = get_irq_regs();
24738 - return regs && user_mode_vm(regs);
24739 + return regs && user_mode(regs);
24740 }
24741
24742 /*
24743 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24744 index 2e977b5..5f2c273 100644
24745 --- a/arch/x86/kernel/i8259.c
24746 +++ b/arch/x86/kernel/i8259.c
24747 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24748 static void make_8259A_irq(unsigned int irq)
24749 {
24750 disable_irq_nosync(irq);
24751 - io_apic_irqs &= ~(1<<irq);
24752 + io_apic_irqs &= ~(1UL<<irq);
24753 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24754 i8259A_chip.name);
24755 enable_irq(irq);
24756 @@ -209,7 +209,7 @@ spurious_8259A_irq:
24757 "spurious 8259A interrupt: IRQ%d.\n", irq);
24758 spurious_irq_mask |= irqmask;
24759 }
24760 - atomic_inc(&irq_err_count);
24761 + atomic_inc_unchecked(&irq_err_count);
24762 /*
24763 * Theoretically we do not have to handle this IRQ,
24764 * but in Linux this does not cause problems and is
24765 @@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24766 /* (slave's support for AEOI in flat mode is to be investigated) */
24767 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24768
24769 + pax_open_kernel();
24770 if (auto_eoi)
24771 /*
24772 * In AEOI mode we just have to mask the interrupt
24773 * when acking.
24774 */
24775 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
24776 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24777 else
24778 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24779 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24780 + pax_close_kernel();
24781
24782 udelay(100); /* wait for 8259A to initialize */
24783
24784 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24785 index a979b5b..1d6db75 100644
24786 --- a/arch/x86/kernel/io_delay.c
24787 +++ b/arch/x86/kernel/io_delay.c
24788 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24789 * Quirk table for systems that misbehave (lock up, etc.) if port
24790 * 0x80 is used:
24791 */
24792 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24793 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24794 {
24795 .callback = dmi_io_delay_0xed_port,
24796 .ident = "Compaq Presario V6000",
24797 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24798 index 4ddaf66..49d5c18 100644
24799 --- a/arch/x86/kernel/ioport.c
24800 +++ b/arch/x86/kernel/ioport.c
24801 @@ -6,6 +6,7 @@
24802 #include <linux/sched.h>
24803 #include <linux/kernel.h>
24804 #include <linux/capability.h>
24805 +#include <linux/security.h>
24806 #include <linux/errno.h>
24807 #include <linux/types.h>
24808 #include <linux/ioport.h>
24809 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24810 return -EINVAL;
24811 if (turn_on && !capable(CAP_SYS_RAWIO))
24812 return -EPERM;
24813 +#ifdef CONFIG_GRKERNSEC_IO
24814 + if (turn_on && grsec_disable_privio) {
24815 + gr_handle_ioperm();
24816 + return -ENODEV;
24817 + }
24818 +#endif
24819
24820 /*
24821 * If it's the first ioperm() call in this thread's lifetime, set the
24822 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24823 * because the ->io_bitmap_max value must match the bitmap
24824 * contents:
24825 */
24826 - tss = &per_cpu(init_tss, get_cpu());
24827 + tss = init_tss + get_cpu();
24828
24829 if (turn_on)
24830 bitmap_clear(t->io_bitmap_ptr, from, num);
24831 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24832 if (level > old) {
24833 if (!capable(CAP_SYS_RAWIO))
24834 return -EPERM;
24835 +#ifdef CONFIG_GRKERNSEC_IO
24836 + if (grsec_disable_privio) {
24837 + gr_handle_iopl();
24838 + return -ENODEV;
24839 + }
24840 +#endif
24841 }
24842 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24843 t->iopl = level << 12;
24844 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24845 index d99f31d..1c0f466 100644
24846 --- a/arch/x86/kernel/irq.c
24847 +++ b/arch/x86/kernel/irq.c
24848 @@ -21,7 +21,7 @@
24849 #define CREATE_TRACE_POINTS
24850 #include <asm/trace/irq_vectors.h>
24851
24852 -atomic_t irq_err_count;
24853 +atomic_unchecked_t irq_err_count;
24854
24855 /* Function pointer for generic interrupt vector handling */
24856 void (*x86_platform_ipi_callback)(void) = NULL;
24857 @@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24858 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24859 seq_printf(p, " Machine check polls\n");
24860 #endif
24861 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24862 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24863 #if defined(CONFIG_X86_IO_APIC)
24864 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24865 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24866 #endif
24867 return 0;
24868 }
24869 @@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24870
24871 u64 arch_irq_stat(void)
24872 {
24873 - u64 sum = atomic_read(&irq_err_count);
24874 + u64 sum = atomic_read_unchecked(&irq_err_count);
24875 return sum;
24876 }
24877
24878 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24879 index d7fcbed..1f747f7 100644
24880 --- a/arch/x86/kernel/irq_32.c
24881 +++ b/arch/x86/kernel/irq_32.c
24882 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24883 __asm__ __volatile__("andl %%esp,%0" :
24884 "=r" (sp) : "0" (THREAD_SIZE - 1));
24885
24886 - return sp < (sizeof(struct thread_info) + STACK_WARN);
24887 + return sp < STACK_WARN;
24888 }
24889
24890 static void print_stack_overflow(void)
24891 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24892 * per-CPU IRQ handling contexts (thread information and stack)
24893 */
24894 union irq_ctx {
24895 - struct thread_info tinfo;
24896 - u32 stack[THREAD_SIZE/sizeof(u32)];
24897 + unsigned long previous_esp;
24898 + u32 stack[THREAD_SIZE/sizeof(u32)];
24899 } __attribute__((aligned(THREAD_SIZE)));
24900
24901 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24902 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24903 static inline int
24904 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24905 {
24906 - union irq_ctx *curctx, *irqctx;
24907 + union irq_ctx *irqctx;
24908 u32 *isp, arg1, arg2;
24909
24910 - curctx = (union irq_ctx *) current_thread_info();
24911 irqctx = __this_cpu_read(hardirq_ctx);
24912
24913 /*
24914 @@ -92,13 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24915 * handler) we can't do that and just have to keep using the
24916 * current stack (which is the irq stack already after all)
24917 */
24918 - if (unlikely(curctx == irqctx))
24919 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24920 return 0;
24921
24922 /* build the stack frame on the IRQ stack */
24923 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24924 - irqctx->tinfo.task = curctx->tinfo.task;
24925 - irqctx->tinfo.previous_esp = current_stack_pointer;
24926 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24927 + irqctx->previous_esp = current_stack_pointer;
24928 +
24929 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24930 + __set_fs(MAKE_MM_SEG(0));
24931 +#endif
24932
24933 if (unlikely(overflow))
24934 call_on_stack(print_stack_overflow, isp);
24935 @@ -110,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24936 : "0" (irq), "1" (desc), "2" (isp),
24937 "D" (desc->handle_irq)
24938 : "memory", "cc", "ecx");
24939 +
24940 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24941 + __set_fs(current_thread_info()->addr_limit);
24942 +#endif
24943 +
24944 return 1;
24945 }
24946
24947 @@ -118,48 +125,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24948 */
24949 void irq_ctx_init(int cpu)
24950 {
24951 - union irq_ctx *irqctx;
24952 -
24953 if (per_cpu(hardirq_ctx, cpu))
24954 return;
24955
24956 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24957 - THREADINFO_GFP,
24958 - THREAD_SIZE_ORDER));
24959 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24960 - irqctx->tinfo.cpu = cpu;
24961 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24962 -
24963 - per_cpu(hardirq_ctx, cpu) = irqctx;
24964 -
24965 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24966 - THREADINFO_GFP,
24967 - THREAD_SIZE_ORDER));
24968 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24969 - irqctx->tinfo.cpu = cpu;
24970 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24971 -
24972 - per_cpu(softirq_ctx, cpu) = irqctx;
24973 -
24974 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24975 - cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24976 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24977 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24978 }
24979
24980 void do_softirq_own_stack(void)
24981 {
24982 - struct thread_info *curctx;
24983 union irq_ctx *irqctx;
24984 u32 *isp;
24985
24986 - curctx = current_thread_info();
24987 irqctx = __this_cpu_read(softirq_ctx);
24988 - irqctx->tinfo.task = curctx->task;
24989 - irqctx->tinfo.previous_esp = current_stack_pointer;
24990 + irqctx->previous_esp = current_stack_pointer;
24991
24992 /* build the stack frame on the softirq stack */
24993 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24994 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24995 +
24996 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24997 + __set_fs(MAKE_MM_SEG(0));
24998 +#endif
24999
25000 call_on_stack(__do_softirq, isp);
25001 +
25002 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25003 + __set_fs(current_thread_info()->addr_limit);
25004 +#endif
25005 +
25006 }
25007
25008 bool handle_irq(unsigned irq, struct pt_regs *regs)
25009 @@ -173,7 +166,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25010 if (unlikely(!desc))
25011 return false;
25012
25013 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25014 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25015 if (unlikely(overflow))
25016 print_stack_overflow();
25017 desc->handle_irq(irq, desc);
25018 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25019 index 4d1c746..232961d 100644
25020 --- a/arch/x86/kernel/irq_64.c
25021 +++ b/arch/x86/kernel/irq_64.c
25022 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25023 u64 estack_top, estack_bottom;
25024 u64 curbase = (u64)task_stack_page(current);
25025
25026 - if (user_mode_vm(regs))
25027 + if (user_mode(regs))
25028 return;
25029
25030 if (regs->sp >= curbase + sizeof(struct thread_info) +
25031 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25032 index 26d5a55..a01160a 100644
25033 --- a/arch/x86/kernel/jump_label.c
25034 +++ b/arch/x86/kernel/jump_label.c
25035 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25036 * Jump label is enabled for the first time.
25037 * So we expect a default_nop...
25038 */
25039 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25040 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25041 != 0))
25042 bug_at((void *)entry->code, __LINE__);
25043 } else {
25044 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25045 * ...otherwise expect an ideal_nop. Otherwise
25046 * something went horribly wrong.
25047 */
25048 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25049 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25050 != 0))
25051 bug_at((void *)entry->code, __LINE__);
25052 }
25053 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25054 * are converting the default nop to the ideal nop.
25055 */
25056 if (init) {
25057 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25058 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25059 bug_at((void *)entry->code, __LINE__);
25060 } else {
25061 code.jump = 0xe9;
25062 code.offset = entry->target -
25063 (entry->code + JUMP_LABEL_NOP_SIZE);
25064 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25065 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25066 bug_at((void *)entry->code, __LINE__);
25067 }
25068 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25069 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25070 index 7ec1d5f..5a7d130 100644
25071 --- a/arch/x86/kernel/kgdb.c
25072 +++ b/arch/x86/kernel/kgdb.c
25073 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25074 #ifdef CONFIG_X86_32
25075 switch (regno) {
25076 case GDB_SS:
25077 - if (!user_mode_vm(regs))
25078 + if (!user_mode(regs))
25079 *(unsigned long *)mem = __KERNEL_DS;
25080 break;
25081 case GDB_SP:
25082 - if (!user_mode_vm(regs))
25083 + if (!user_mode(regs))
25084 *(unsigned long *)mem = kernel_stack_pointer(regs);
25085 break;
25086 case GDB_GS:
25087 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25088 bp->attr.bp_addr = breakinfo[breakno].addr;
25089 bp->attr.bp_len = breakinfo[breakno].len;
25090 bp->attr.bp_type = breakinfo[breakno].type;
25091 - info->address = breakinfo[breakno].addr;
25092 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25093 + info->address = ktla_ktva(breakinfo[breakno].addr);
25094 + else
25095 + info->address = breakinfo[breakno].addr;
25096 info->len = breakinfo[breakno].len;
25097 info->type = breakinfo[breakno].type;
25098 val = arch_install_hw_breakpoint(bp);
25099 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25100 case 'k':
25101 /* clear the trace bit */
25102 linux_regs->flags &= ~X86_EFLAGS_TF;
25103 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25104 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25105
25106 /* set the trace bit if we're stepping */
25107 if (remcomInBuffer[0] == 's') {
25108 linux_regs->flags |= X86_EFLAGS_TF;
25109 - atomic_set(&kgdb_cpu_doing_single_step,
25110 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25111 raw_smp_processor_id());
25112 }
25113
25114 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25115
25116 switch (cmd) {
25117 case DIE_DEBUG:
25118 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25119 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25120 if (user_mode(regs))
25121 return single_step_cont(regs, args);
25122 break;
25123 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25124 #endif /* CONFIG_DEBUG_RODATA */
25125
25126 bpt->type = BP_BREAKPOINT;
25127 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25128 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25129 BREAK_INSTR_SIZE);
25130 if (err)
25131 return err;
25132 - err = probe_kernel_write((char *)bpt->bpt_addr,
25133 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25134 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25135 #ifdef CONFIG_DEBUG_RODATA
25136 if (!err)
25137 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25138 return -EBUSY;
25139 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25140 BREAK_INSTR_SIZE);
25141 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25142 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25143 if (err)
25144 return err;
25145 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25146 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25147 if (mutex_is_locked(&text_mutex))
25148 goto knl_write;
25149 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25150 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25151 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25152 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25153 goto knl_write;
25154 return err;
25155 knl_write:
25156 #endif /* CONFIG_DEBUG_RODATA */
25157 - return probe_kernel_write((char *)bpt->bpt_addr,
25158 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25159 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25160 }
25161
25162 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25163 index 79a3f96..6ba030a 100644
25164 --- a/arch/x86/kernel/kprobes/core.c
25165 +++ b/arch/x86/kernel/kprobes/core.c
25166 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25167 s32 raddr;
25168 } __packed *insn;
25169
25170 - insn = (struct __arch_relative_insn *)from;
25171 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25172 +
25173 + pax_open_kernel();
25174 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25175 insn->op = op;
25176 + pax_close_kernel();
25177 }
25178
25179 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25180 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25181 kprobe_opcode_t opcode;
25182 kprobe_opcode_t *orig_opcodes = opcodes;
25183
25184 - if (search_exception_tables((unsigned long)opcodes))
25185 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25186 return 0; /* Page fault may occur on this address. */
25187
25188 retry:
25189 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25190 * for the first byte, we can recover the original instruction
25191 * from it and kp->opcode.
25192 */
25193 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25194 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25195 buf[0] = kp->opcode;
25196 - return (unsigned long)buf;
25197 + return ktva_ktla((unsigned long)buf);
25198 }
25199
25200 /*
25201 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25202 /* Another subsystem puts a breakpoint, failed to recover */
25203 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25204 return 0;
25205 + pax_open_kernel();
25206 memcpy(dest, insn.kaddr, insn.length);
25207 + pax_close_kernel();
25208
25209 #ifdef CONFIG_X86_64
25210 if (insn_rip_relative(&insn)) {
25211 @@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25212 return 0;
25213 }
25214 disp = (u8 *) dest + insn_offset_displacement(&insn);
25215 + pax_open_kernel();
25216 *(s32 *) disp = (s32) newdisp;
25217 + pax_close_kernel();
25218 }
25219 #endif
25220 return insn.length;
25221 @@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25222 * nor set current_kprobe, because it doesn't use single
25223 * stepping.
25224 */
25225 - regs->ip = (unsigned long)p->ainsn.insn;
25226 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25227 preempt_enable_no_resched();
25228 return;
25229 }
25230 @@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25231 regs->flags &= ~X86_EFLAGS_IF;
25232 /* single step inline if the instruction is an int3 */
25233 if (p->opcode == BREAKPOINT_INSTRUCTION)
25234 - regs->ip = (unsigned long)p->addr;
25235 + regs->ip = ktla_ktva((unsigned long)p->addr);
25236 else
25237 - regs->ip = (unsigned long)p->ainsn.insn;
25238 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25239 }
25240
25241 /*
25242 @@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25243 setup_singlestep(p, regs, kcb, 0);
25244 return 1;
25245 }
25246 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25247 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25248 /*
25249 * The breakpoint instruction was removed right
25250 * after we hit it. Another cpu has removed
25251 @@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25252 " movq %rax, 152(%rsp)\n"
25253 RESTORE_REGS_STRING
25254 " popfq\n"
25255 +#ifdef KERNEXEC_PLUGIN
25256 + " btsq $63,(%rsp)\n"
25257 +#endif
25258 #else
25259 " pushf\n"
25260 SAVE_REGS_STRING
25261 @@ -779,7 +789,7 @@ static void __kprobes
25262 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25263 {
25264 unsigned long *tos = stack_addr(regs);
25265 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25266 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25267 unsigned long orig_ip = (unsigned long)p->addr;
25268 kprobe_opcode_t *insn = p->ainsn.insn;
25269
25270 @@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25271 struct die_args *args = data;
25272 int ret = NOTIFY_DONE;
25273
25274 - if (args->regs && user_mode_vm(args->regs))
25275 + if (args->regs && user_mode(args->regs))
25276 return ret;
25277
25278 switch (val) {
25279 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25280 index 898160b..758cde8 100644
25281 --- a/arch/x86/kernel/kprobes/opt.c
25282 +++ b/arch/x86/kernel/kprobes/opt.c
25283 @@ -79,6 +79,7 @@ found:
25284 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25285 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25286 {
25287 + pax_open_kernel();
25288 #ifdef CONFIG_X86_64
25289 *addr++ = 0x48;
25290 *addr++ = 0xbf;
25291 @@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25292 *addr++ = 0xb8;
25293 #endif
25294 *(unsigned long *)addr = val;
25295 + pax_close_kernel();
25296 }
25297
25298 asm (
25299 @@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25300 * Verify if the address gap is in 2GB range, because this uses
25301 * a relative jump.
25302 */
25303 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25304 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25305 if (abs(rel) > 0x7fffffff)
25306 return -ERANGE;
25307
25308 @@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25309 op->optinsn.size = ret;
25310
25311 /* Copy arch-dep-instance from template */
25312 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25313 + pax_open_kernel();
25314 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25315 + pax_close_kernel();
25316
25317 /* Set probe information */
25318 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25319
25320 /* Set probe function call */
25321 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25322 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25323
25324 /* Set returning jmp instruction at the tail of out-of-line buffer */
25325 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25326 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25327 (u8 *)op->kp.addr + op->optinsn.size);
25328
25329 flush_icache_range((unsigned long) buf,
25330 @@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25331 WARN_ON(kprobe_disabled(&op->kp));
25332
25333 /* Backup instructions which will be replaced by jump address */
25334 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25335 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25336 RELATIVE_ADDR_SIZE);
25337
25338 insn_buf[0] = RELATIVEJUMP_OPCODE;
25339 @@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25340 /* This kprobe is really able to run optimized path. */
25341 op = container_of(p, struct optimized_kprobe, kp);
25342 /* Detour through copied instructions */
25343 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25344 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25345 if (!reenter)
25346 reset_current_kprobe();
25347 preempt_enable_no_resched();
25348 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25349 index c2bedae..25e7ab6 100644
25350 --- a/arch/x86/kernel/ksysfs.c
25351 +++ b/arch/x86/kernel/ksysfs.c
25352 @@ -184,7 +184,7 @@ out:
25353
25354 static struct kobj_attribute type_attr = __ATTR_RO(type);
25355
25356 -static struct bin_attribute data_attr = {
25357 +static bin_attribute_no_const data_attr __read_only = {
25358 .attr = {
25359 .name = "data",
25360 .mode = S_IRUGO,
25361 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25362 index ebc9873..37b8776 100644
25363 --- a/arch/x86/kernel/ldt.c
25364 +++ b/arch/x86/kernel/ldt.c
25365 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25366 if (reload) {
25367 #ifdef CONFIG_SMP
25368 preempt_disable();
25369 - load_LDT(pc);
25370 + load_LDT_nolock(pc);
25371 if (!cpumask_equal(mm_cpumask(current->mm),
25372 cpumask_of(smp_processor_id())))
25373 smp_call_function(flush_ldt, current->mm, 1);
25374 preempt_enable();
25375 #else
25376 - load_LDT(pc);
25377 + load_LDT_nolock(pc);
25378 #endif
25379 }
25380 if (oldsize) {
25381 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25382 return err;
25383
25384 for (i = 0; i < old->size; i++)
25385 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25386 + write_ldt_entry(new->ldt, i, old->ldt + i);
25387 return 0;
25388 }
25389
25390 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25391 retval = copy_ldt(&mm->context, &old_mm->context);
25392 mutex_unlock(&old_mm->context.lock);
25393 }
25394 +
25395 + if (tsk == current) {
25396 + mm->context.vdso = 0;
25397 +
25398 +#ifdef CONFIG_X86_32
25399 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25400 + mm->context.user_cs_base = 0UL;
25401 + mm->context.user_cs_limit = ~0UL;
25402 +
25403 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25404 + cpus_clear(mm->context.cpu_user_cs_mask);
25405 +#endif
25406 +
25407 +#endif
25408 +#endif
25409 +
25410 + }
25411 +
25412 return retval;
25413 }
25414
25415 @@ -229,6 +247,24 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25416 }
25417 }
25418
25419 +#ifdef CONFIG_PAX_SEGMEXEC
25420 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25421 + error = -EINVAL;
25422 + goto out_unlock;
25423 + }
25424 +#endif
25425 +
25426 + /*
25427 + * On x86-64 we do not support 16-bit segments due to
25428 + * IRET leaking the high bits of the kernel stack address.
25429 + */
25430 +#ifdef CONFIG_X86_64
25431 + if (!ldt_info.seg_32bit) {
25432 + error = -EINVAL;
25433 + goto out_unlock;
25434 + }
25435 +#endif
25436 +
25437 fill_ldt(&ldt, &ldt_info);
25438 if (oldmode)
25439 ldt.avl = 0;
25440 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25441 index 1667b1d..16492c5 100644
25442 --- a/arch/x86/kernel/machine_kexec_32.c
25443 +++ b/arch/x86/kernel/machine_kexec_32.c
25444 @@ -25,7 +25,7 @@
25445 #include <asm/cacheflush.h>
25446 #include <asm/debugreg.h>
25447
25448 -static void set_idt(void *newidt, __u16 limit)
25449 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25450 {
25451 struct desc_ptr curidt;
25452
25453 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25454 }
25455
25456
25457 -static void set_gdt(void *newgdt, __u16 limit)
25458 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25459 {
25460 struct desc_ptr curgdt;
25461
25462 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25463 }
25464
25465 control_page = page_address(image->control_code_page);
25466 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25467 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25468
25469 relocate_kernel_ptr = control_page;
25470 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25471 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25472 index 18be189..4a9fe40 100644
25473 --- a/arch/x86/kernel/module.c
25474 +++ b/arch/x86/kernel/module.c
25475 @@ -43,15 +43,60 @@ do { \
25476 } while (0)
25477 #endif
25478
25479 -void *module_alloc(unsigned long size)
25480 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25481 {
25482 - if (PAGE_ALIGN(size) > MODULES_LEN)
25483 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25484 return NULL;
25485 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25486 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25487 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25488 NUMA_NO_NODE, __builtin_return_address(0));
25489 }
25490
25491 +void *module_alloc(unsigned long size)
25492 +{
25493 +
25494 +#ifdef CONFIG_PAX_KERNEXEC
25495 + return __module_alloc(size, PAGE_KERNEL);
25496 +#else
25497 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25498 +#endif
25499 +
25500 +}
25501 +
25502 +#ifdef CONFIG_PAX_KERNEXEC
25503 +#ifdef CONFIG_X86_32
25504 +void *module_alloc_exec(unsigned long size)
25505 +{
25506 + struct vm_struct *area;
25507 +
25508 + if (size == 0)
25509 + return NULL;
25510 +
25511 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25512 + return area ? area->addr : NULL;
25513 +}
25514 +EXPORT_SYMBOL(module_alloc_exec);
25515 +
25516 +void module_free_exec(struct module *mod, void *module_region)
25517 +{
25518 + vunmap(module_region);
25519 +}
25520 +EXPORT_SYMBOL(module_free_exec);
25521 +#else
25522 +void module_free_exec(struct module *mod, void *module_region)
25523 +{
25524 + module_free(mod, module_region);
25525 +}
25526 +EXPORT_SYMBOL(module_free_exec);
25527 +
25528 +void *module_alloc_exec(unsigned long size)
25529 +{
25530 + return __module_alloc(size, PAGE_KERNEL_RX);
25531 +}
25532 +EXPORT_SYMBOL(module_alloc_exec);
25533 +#endif
25534 +#endif
25535 +
25536 #ifdef CONFIG_X86_32
25537 int apply_relocate(Elf32_Shdr *sechdrs,
25538 const char *strtab,
25539 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25540 unsigned int i;
25541 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25542 Elf32_Sym *sym;
25543 - uint32_t *location;
25544 + uint32_t *plocation, location;
25545
25546 DEBUGP("Applying relocate section %u to %u\n",
25547 relsec, sechdrs[relsec].sh_info);
25548 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25549 /* This is where to make the change */
25550 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25551 - + rel[i].r_offset;
25552 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25553 + location = (uint32_t)plocation;
25554 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25555 + plocation = ktla_ktva((void *)plocation);
25556 /* This is the symbol it is referring to. Note that all
25557 undefined symbols have been resolved. */
25558 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25559 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25560 switch (ELF32_R_TYPE(rel[i].r_info)) {
25561 case R_386_32:
25562 /* We add the value into the location given */
25563 - *location += sym->st_value;
25564 + pax_open_kernel();
25565 + *plocation += sym->st_value;
25566 + pax_close_kernel();
25567 break;
25568 case R_386_PC32:
25569 /* Add the value, subtract its position */
25570 - *location += sym->st_value - (uint32_t)location;
25571 + pax_open_kernel();
25572 + *plocation += sym->st_value - location;
25573 + pax_close_kernel();
25574 break;
25575 default:
25576 pr_err("%s: Unknown relocation: %u\n",
25577 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25578 case R_X86_64_NONE:
25579 break;
25580 case R_X86_64_64:
25581 + pax_open_kernel();
25582 *(u64 *)loc = val;
25583 + pax_close_kernel();
25584 break;
25585 case R_X86_64_32:
25586 + pax_open_kernel();
25587 *(u32 *)loc = val;
25588 + pax_close_kernel();
25589 if (val != *(u32 *)loc)
25590 goto overflow;
25591 break;
25592 case R_X86_64_32S:
25593 + pax_open_kernel();
25594 *(s32 *)loc = val;
25595 + pax_close_kernel();
25596 if ((s64)val != *(s32 *)loc)
25597 goto overflow;
25598 break;
25599 case R_X86_64_PC32:
25600 val -= (u64)loc;
25601 + pax_open_kernel();
25602 *(u32 *)loc = val;
25603 + pax_close_kernel();
25604 +
25605 #if 0
25606 if ((s64)val != *(s32 *)loc)
25607 goto overflow;
25608 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25609 index 05266b5..3432443 100644
25610 --- a/arch/x86/kernel/msr.c
25611 +++ b/arch/x86/kernel/msr.c
25612 @@ -37,6 +37,7 @@
25613 #include <linux/notifier.h>
25614 #include <linux/uaccess.h>
25615 #include <linux/gfp.h>
25616 +#include <linux/grsecurity.h>
25617
25618 #include <asm/processor.h>
25619 #include <asm/msr.h>
25620 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25621 int err = 0;
25622 ssize_t bytes = 0;
25623
25624 +#ifdef CONFIG_GRKERNSEC_KMEM
25625 + gr_handle_msr_write();
25626 + return -EPERM;
25627 +#endif
25628 +
25629 if (count % 8)
25630 return -EINVAL; /* Invalid chunk size */
25631
25632 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25633 err = -EBADF;
25634 break;
25635 }
25636 +#ifdef CONFIG_GRKERNSEC_KMEM
25637 + gr_handle_msr_write();
25638 + return -EPERM;
25639 +#endif
25640 if (copy_from_user(&regs, uregs, sizeof regs)) {
25641 err = -EFAULT;
25642 break;
25643 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25644 return notifier_from_errno(err);
25645 }
25646
25647 -static struct notifier_block __refdata msr_class_cpu_notifier = {
25648 +static struct notifier_block msr_class_cpu_notifier = {
25649 .notifier_call = msr_class_cpu_callback,
25650 };
25651
25652 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25653 index 6fcb49c..5b3f4ff 100644
25654 --- a/arch/x86/kernel/nmi.c
25655 +++ b/arch/x86/kernel/nmi.c
25656 @@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25657 return handled;
25658 }
25659
25660 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25661 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25662 {
25663 struct nmi_desc *desc = nmi_to_desc(type);
25664 unsigned long flags;
25665 @@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25666 * event confuses some handlers (kdump uses this flag)
25667 */
25668 if (action->flags & NMI_FLAG_FIRST)
25669 - list_add_rcu(&action->list, &desc->head);
25670 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25671 else
25672 - list_add_tail_rcu(&action->list, &desc->head);
25673 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25674
25675 spin_unlock_irqrestore(&desc->lock, flags);
25676 return 0;
25677 @@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25678 if (!strcmp(n->name, name)) {
25679 WARN(in_nmi(),
25680 "Trying to free NMI (%s) from NMI context!\n", n->name);
25681 - list_del_rcu(&n->list);
25682 + pax_list_del_rcu((struct list_head *)&n->list);
25683 break;
25684 }
25685 }
25686 @@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25687 dotraplinkage notrace __kprobes void
25688 do_nmi(struct pt_regs *regs, long error_code)
25689 {
25690 +
25691 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25692 + if (!user_mode(regs)) {
25693 + unsigned long cs = regs->cs & 0xFFFF;
25694 + unsigned long ip = ktva_ktla(regs->ip);
25695 +
25696 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25697 + regs->ip = ip;
25698 + }
25699 +#endif
25700 +
25701 nmi_nesting_preprocess(regs);
25702
25703 nmi_enter();
25704 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25705 index 6d9582e..f746287 100644
25706 --- a/arch/x86/kernel/nmi_selftest.c
25707 +++ b/arch/x86/kernel/nmi_selftest.c
25708 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25709 {
25710 /* trap all the unknown NMIs we may generate */
25711 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25712 - __initdata);
25713 + __initconst);
25714 }
25715
25716 static void __init cleanup_nmi_testsuite(void)
25717 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25718 unsigned long timeout;
25719
25720 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25721 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25722 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25723 nmi_fail = FAILURE;
25724 return;
25725 }
25726 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25727 index bbb6c73..24a58ef 100644
25728 --- a/arch/x86/kernel/paravirt-spinlocks.c
25729 +++ b/arch/x86/kernel/paravirt-spinlocks.c
25730 @@ -8,7 +8,7 @@
25731
25732 #include <asm/paravirt.h>
25733
25734 -struct pv_lock_ops pv_lock_ops = {
25735 +struct pv_lock_ops pv_lock_ops __read_only = {
25736 #ifdef CONFIG_SMP
25737 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25738 .unlock_kick = paravirt_nop,
25739 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25740 index 1b10af8..0b58cbc 100644
25741 --- a/arch/x86/kernel/paravirt.c
25742 +++ b/arch/x86/kernel/paravirt.c
25743 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25744 {
25745 return x;
25746 }
25747 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25748 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25749 +#endif
25750
25751 void __init default_banner(void)
25752 {
25753 @@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25754 if (opfunc == NULL)
25755 /* If there's no function, patch it with a ud2a (BUG) */
25756 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25757 - else if (opfunc == _paravirt_nop)
25758 + else if (opfunc == (void *)_paravirt_nop)
25759 /* If the operation is a nop, then nop the callsite */
25760 ret = paravirt_patch_nop();
25761
25762 /* identity functions just return their single argument */
25763 - else if (opfunc == _paravirt_ident_32)
25764 + else if (opfunc == (void *)_paravirt_ident_32)
25765 ret = paravirt_patch_ident_32(insnbuf, len);
25766 - else if (opfunc == _paravirt_ident_64)
25767 + else if (opfunc == (void *)_paravirt_ident_64)
25768 ret = paravirt_patch_ident_64(insnbuf, len);
25769 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25770 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25771 + ret = paravirt_patch_ident_64(insnbuf, len);
25772 +#endif
25773
25774 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25775 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25776 @@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25777 if (insn_len > len || start == NULL)
25778 insn_len = len;
25779 else
25780 - memcpy(insnbuf, start, insn_len);
25781 + memcpy(insnbuf, ktla_ktva(start), insn_len);
25782
25783 return insn_len;
25784 }
25785 @@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25786 return this_cpu_read(paravirt_lazy_mode);
25787 }
25788
25789 -struct pv_info pv_info = {
25790 +struct pv_info pv_info __read_only = {
25791 .name = "bare hardware",
25792 .paravirt_enabled = 0,
25793 .kernel_rpl = 0,
25794 @@ -310,16 +317,16 @@ struct pv_info pv_info = {
25795 #endif
25796 };
25797
25798 -struct pv_init_ops pv_init_ops = {
25799 +struct pv_init_ops pv_init_ops __read_only = {
25800 .patch = native_patch,
25801 };
25802
25803 -struct pv_time_ops pv_time_ops = {
25804 +struct pv_time_ops pv_time_ops __read_only = {
25805 .sched_clock = native_sched_clock,
25806 .steal_clock = native_steal_clock,
25807 };
25808
25809 -__visible struct pv_irq_ops pv_irq_ops = {
25810 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
25811 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25812 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25813 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25814 @@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25815 #endif
25816 };
25817
25818 -__visible struct pv_cpu_ops pv_cpu_ops = {
25819 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25820 .cpuid = native_cpuid,
25821 .get_debugreg = native_get_debugreg,
25822 .set_debugreg = native_set_debugreg,
25823 @@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25824 .end_context_switch = paravirt_nop,
25825 };
25826
25827 -struct pv_apic_ops pv_apic_ops = {
25828 +struct pv_apic_ops pv_apic_ops __read_only= {
25829 #ifdef CONFIG_X86_LOCAL_APIC
25830 .startup_ipi_hook = paravirt_nop,
25831 #endif
25832 };
25833
25834 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25835 +#ifdef CONFIG_X86_32
25836 +#ifdef CONFIG_X86_PAE
25837 +/* 64-bit pagetable entries */
25838 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25839 +#else
25840 /* 32-bit pagetable entries */
25841 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25842 +#endif
25843 #else
25844 /* 64-bit pagetable entries */
25845 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25846 #endif
25847
25848 -struct pv_mmu_ops pv_mmu_ops = {
25849 +struct pv_mmu_ops pv_mmu_ops __read_only = {
25850
25851 .read_cr2 = native_read_cr2,
25852 .write_cr2 = native_write_cr2,
25853 @@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25854 .make_pud = PTE_IDENT,
25855
25856 .set_pgd = native_set_pgd,
25857 + .set_pgd_batched = native_set_pgd_batched,
25858 #endif
25859 #endif /* PAGETABLE_LEVELS >= 3 */
25860
25861 @@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25862 },
25863
25864 .set_fixmap = native_set_fixmap,
25865 +
25866 +#ifdef CONFIG_PAX_KERNEXEC
25867 + .pax_open_kernel = native_pax_open_kernel,
25868 + .pax_close_kernel = native_pax_close_kernel,
25869 +#endif
25870 +
25871 };
25872
25873 EXPORT_SYMBOL_GPL(pv_time_ops);
25874 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25875 index 299d493..2ccb0ee 100644
25876 --- a/arch/x86/kernel/pci-calgary_64.c
25877 +++ b/arch/x86/kernel/pci-calgary_64.c
25878 @@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25879 tce_space = be64_to_cpu(readq(target));
25880 tce_space = tce_space & TAR_SW_BITS;
25881
25882 - tce_space = tce_space & (~specified_table_size);
25883 + tce_space = tce_space & (~(unsigned long)specified_table_size);
25884 info->tce_space = (u64 *)__va(tce_space);
25885 }
25886 }
25887 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25888 index 35ccf75..7a15747 100644
25889 --- a/arch/x86/kernel/pci-iommu_table.c
25890 +++ b/arch/x86/kernel/pci-iommu_table.c
25891 @@ -2,7 +2,7 @@
25892 #include <asm/iommu_table.h>
25893 #include <linux/string.h>
25894 #include <linux/kallsyms.h>
25895 -
25896 +#include <linux/sched.h>
25897
25898 #define DEBUG 1
25899
25900 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25901 index 6c483ba..d10ce2f 100644
25902 --- a/arch/x86/kernel/pci-swiotlb.c
25903 +++ b/arch/x86/kernel/pci-swiotlb.c
25904 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25905 void *vaddr, dma_addr_t dma_addr,
25906 struct dma_attrs *attrs)
25907 {
25908 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25909 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25910 }
25911
25912 static struct dma_map_ops swiotlb_dma_ops = {
25913 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25914 index ca7f0d5..8996469 100644
25915 --- a/arch/x86/kernel/preempt.S
25916 +++ b/arch/x86/kernel/preempt.S
25917 @@ -3,12 +3,14 @@
25918 #include <asm/dwarf2.h>
25919 #include <asm/asm.h>
25920 #include <asm/calling.h>
25921 +#include <asm/alternative-asm.h>
25922
25923 ENTRY(___preempt_schedule)
25924 CFI_STARTPROC
25925 SAVE_ALL
25926 call preempt_schedule
25927 RESTORE_ALL
25928 + pax_force_retaddr
25929 ret
25930 CFI_ENDPROC
25931
25932 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
25933 SAVE_ALL
25934 call preempt_schedule_context
25935 RESTORE_ALL
25936 + pax_force_retaddr
25937 ret
25938 CFI_ENDPROC
25939
25940 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25941 index 3fb8d95..254dc51 100644
25942 --- a/arch/x86/kernel/process.c
25943 +++ b/arch/x86/kernel/process.c
25944 @@ -36,7 +36,8 @@
25945 * section. Since TSS's are completely CPU-local, we want them
25946 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25947 */
25948 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25949 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25950 +EXPORT_SYMBOL(init_tss);
25951
25952 #ifdef CONFIG_X86_64
25953 static DEFINE_PER_CPU(unsigned char, is_idle);
25954 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25955 task_xstate_cachep =
25956 kmem_cache_create("task_xstate", xstate_size,
25957 __alignof__(union thread_xstate),
25958 - SLAB_PANIC | SLAB_NOTRACK, NULL);
25959 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25960 }
25961
25962 /*
25963 @@ -105,7 +106,7 @@ void exit_thread(void)
25964 unsigned long *bp = t->io_bitmap_ptr;
25965
25966 if (bp) {
25967 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
25968 + struct tss_struct *tss = init_tss + get_cpu();
25969
25970 t->io_bitmap_ptr = NULL;
25971 clear_thread_flag(TIF_IO_BITMAP);
25972 @@ -125,6 +126,9 @@ void flush_thread(void)
25973 {
25974 struct task_struct *tsk = current;
25975
25976 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
25977 + loadsegment(gs, 0);
25978 +#endif
25979 flush_ptrace_hw_breakpoint(tsk);
25980 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
25981 drop_init_fpu(tsk);
25982 @@ -271,7 +275,7 @@ static void __exit_idle(void)
25983 void exit_idle(void)
25984 {
25985 /* idle loop has pid 0 */
25986 - if (current->pid)
25987 + if (task_pid_nr(current))
25988 return;
25989 __exit_idle();
25990 }
25991 @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
25992 return ret;
25993 }
25994 #endif
25995 -void stop_this_cpu(void *dummy)
25996 +__noreturn void stop_this_cpu(void *dummy)
25997 {
25998 local_irq_disable();
25999 /*
26000 @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26001 }
26002 early_param("idle", idle_setup);
26003
26004 -unsigned long arch_align_stack(unsigned long sp)
26005 +#ifdef CONFIG_PAX_RANDKSTACK
26006 +void pax_randomize_kstack(struct pt_regs *regs)
26007 {
26008 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26009 - sp -= get_random_int() % 8192;
26010 - return sp & ~0xf;
26011 -}
26012 + struct thread_struct *thread = &current->thread;
26013 + unsigned long time;
26014
26015 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26016 -{
26017 - unsigned long range_end = mm->brk + 0x02000000;
26018 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26019 -}
26020 + if (!randomize_va_space)
26021 + return;
26022 +
26023 + if (v8086_mode(regs))
26024 + return;
26025
26026 + rdtscl(time);
26027 +
26028 + /* P4 seems to return a 0 LSB, ignore it */
26029 +#ifdef CONFIG_MPENTIUM4
26030 + time &= 0x3EUL;
26031 + time <<= 2;
26032 +#elif defined(CONFIG_X86_64)
26033 + time &= 0xFUL;
26034 + time <<= 4;
26035 +#else
26036 + time &= 0x1FUL;
26037 + time <<= 3;
26038 +#endif
26039 +
26040 + thread->sp0 ^= time;
26041 + load_sp0(init_tss + smp_processor_id(), thread);
26042 +
26043 +#ifdef CONFIG_X86_64
26044 + this_cpu_write(kernel_stack, thread->sp0);
26045 +#endif
26046 +}
26047 +#endif
26048 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26049 index 0de43e9..056b840 100644
26050 --- a/arch/x86/kernel/process_32.c
26051 +++ b/arch/x86/kernel/process_32.c
26052 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26053 unsigned long thread_saved_pc(struct task_struct *tsk)
26054 {
26055 return ((unsigned long *)tsk->thread.sp)[3];
26056 +//XXX return tsk->thread.eip;
26057 }
26058
26059 void __show_regs(struct pt_regs *regs, int all)
26060 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26061 unsigned long sp;
26062 unsigned short ss, gs;
26063
26064 - if (user_mode_vm(regs)) {
26065 + if (user_mode(regs)) {
26066 sp = regs->sp;
26067 ss = regs->ss & 0xffff;
26068 - gs = get_user_gs(regs);
26069 } else {
26070 sp = kernel_stack_pointer(regs);
26071 savesegment(ss, ss);
26072 - savesegment(gs, gs);
26073 }
26074 + gs = get_user_gs(regs);
26075
26076 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26077 (u16)regs->cs, regs->ip, regs->flags,
26078 - smp_processor_id());
26079 + raw_smp_processor_id());
26080 print_symbol("EIP is at %s\n", regs->ip);
26081
26082 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26083 @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26084 int copy_thread(unsigned long clone_flags, unsigned long sp,
26085 unsigned long arg, struct task_struct *p)
26086 {
26087 - struct pt_regs *childregs = task_pt_regs(p);
26088 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26089 struct task_struct *tsk;
26090 int err;
26091
26092 p->thread.sp = (unsigned long) childregs;
26093 p->thread.sp0 = (unsigned long) (childregs+1);
26094 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26095
26096 if (unlikely(p->flags & PF_KTHREAD)) {
26097 /* kernel thread */
26098 memset(childregs, 0, sizeof(struct pt_regs));
26099 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26100 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26101 - childregs->ds = __USER_DS;
26102 - childregs->es = __USER_DS;
26103 + savesegment(gs, childregs->gs);
26104 + childregs->ds = __KERNEL_DS;
26105 + childregs->es = __KERNEL_DS;
26106 childregs->fs = __KERNEL_PERCPU;
26107 childregs->bx = sp; /* function */
26108 childregs->bp = arg;
26109 @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26110 struct thread_struct *prev = &prev_p->thread,
26111 *next = &next_p->thread;
26112 int cpu = smp_processor_id();
26113 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26114 + struct tss_struct *tss = init_tss + cpu;
26115 fpu_switch_t fpu;
26116
26117 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26118 @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26119 */
26120 lazy_save_gs(prev->gs);
26121
26122 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26123 + __set_fs(task_thread_info(next_p)->addr_limit);
26124 +#endif
26125 +
26126 /*
26127 * Load the per-thread Thread-Local Storage descriptor.
26128 */
26129 @@ -314,6 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26130 */
26131 arch_end_context_switch(next_p);
26132
26133 + this_cpu_write(current_task, next_p);
26134 + this_cpu_write(current_tinfo, &next_p->tinfo);
26135 +
26136 /*
26137 * Restore %gs if needed (which is common)
26138 */
26139 @@ -322,8 +330,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26140
26141 switch_fpu_finish(next_p, fpu);
26142
26143 - this_cpu_write(current_task, next_p);
26144 -
26145 return prev_p;
26146 }
26147
26148 @@ -353,4 +359,3 @@ unsigned long get_wchan(struct task_struct *p)
26149 } while (count++ < 16);
26150 return 0;
26151 }
26152 -
26153 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26154 index 9c0280f..5bbb1c0 100644
26155 --- a/arch/x86/kernel/process_64.c
26156 +++ b/arch/x86/kernel/process_64.c
26157 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26158 struct pt_regs *childregs;
26159 struct task_struct *me = current;
26160
26161 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26162 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26163 childregs = task_pt_regs(p);
26164 p->thread.sp = (unsigned long) childregs;
26165 p->thread.usersp = me->thread.usersp;
26166 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26167 set_tsk_thread_flag(p, TIF_FORK);
26168 p->thread.fpu_counter = 0;
26169 p->thread.io_bitmap_ptr = NULL;
26170 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26171 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26172 savesegment(es, p->thread.es);
26173 savesegment(ds, p->thread.ds);
26174 + savesegment(ss, p->thread.ss);
26175 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26176 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26177
26178 if (unlikely(p->flags & PF_KTHREAD)) {
26179 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26180 struct thread_struct *prev = &prev_p->thread;
26181 struct thread_struct *next = &next_p->thread;
26182 int cpu = smp_processor_id();
26183 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26184 + struct tss_struct *tss = init_tss + cpu;
26185 unsigned fsindex, gsindex;
26186 fpu_switch_t fpu;
26187
26188 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26189 if (unlikely(next->ds | prev->ds))
26190 loadsegment(ds, next->ds);
26191
26192 + savesegment(ss, prev->ss);
26193 + if (unlikely(next->ss != prev->ss))
26194 + loadsegment(ss, next->ss);
26195
26196 /* We must save %fs and %gs before load_TLS() because
26197 * %fs and %gs may be cleared by load_TLS().
26198 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26199 prev->usersp = this_cpu_read(old_rsp);
26200 this_cpu_write(old_rsp, next->usersp);
26201 this_cpu_write(current_task, next_p);
26202 + this_cpu_write(current_tinfo, &next_p->tinfo);
26203
26204 /*
26205 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26206 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26207 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26208 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26209
26210 - this_cpu_write(kernel_stack,
26211 - (unsigned long)task_stack_page(next_p) +
26212 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26213 + this_cpu_write(kernel_stack, next->sp0);
26214
26215 /*
26216 * Now maybe reload the debug registers and handle I/O bitmaps
26217 @@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26218 if (!p || p == current || p->state == TASK_RUNNING)
26219 return 0;
26220 stack = (unsigned long)task_stack_page(p);
26221 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26222 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26223 return 0;
26224 fp = *(u64 *)(p->thread.sp);
26225 do {
26226 - if (fp < (unsigned long)stack ||
26227 - fp >= (unsigned long)stack+THREAD_SIZE)
26228 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26229 return 0;
26230 ip = *(u64 *)(fp+8);
26231 if (!in_sched_functions(ip))
26232 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26233 index 7461f50..1334029 100644
26234 --- a/arch/x86/kernel/ptrace.c
26235 +++ b/arch/x86/kernel/ptrace.c
26236 @@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26237 {
26238 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26239 unsigned long sp = (unsigned long)&regs->sp;
26240 - struct thread_info *tinfo;
26241
26242 - if (context == (sp & ~(THREAD_SIZE - 1)))
26243 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26244 return sp;
26245
26246 - tinfo = (struct thread_info *)context;
26247 - if (tinfo->previous_esp)
26248 - return tinfo->previous_esp;
26249 + sp = *(unsigned long *)context;
26250 + if (sp)
26251 + return sp;
26252
26253 return (unsigned long)regs;
26254 }
26255 @@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26256 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26257 {
26258 int i;
26259 - int dr7 = 0;
26260 + unsigned long dr7 = 0;
26261 struct arch_hw_breakpoint *info;
26262
26263 for (i = 0; i < HBP_NUM; i++) {
26264 @@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26265 unsigned long addr, unsigned long data)
26266 {
26267 int ret;
26268 - unsigned long __user *datap = (unsigned long __user *)data;
26269 + unsigned long __user *datap = (__force unsigned long __user *)data;
26270
26271 switch (request) {
26272 /* read the word at location addr in the USER area. */
26273 @@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26274 if ((int) addr < 0)
26275 return -EIO;
26276 ret = do_get_thread_area(child, addr,
26277 - (struct user_desc __user *)data);
26278 + (__force struct user_desc __user *) data);
26279 break;
26280
26281 case PTRACE_SET_THREAD_AREA:
26282 if ((int) addr < 0)
26283 return -EIO;
26284 ret = do_set_thread_area(child, addr,
26285 - (struct user_desc __user *)data, 0);
26286 + (__force struct user_desc __user *) data, 0);
26287 break;
26288 #endif
26289
26290 @@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26291
26292 #ifdef CONFIG_X86_64
26293
26294 -static struct user_regset x86_64_regsets[] __read_mostly = {
26295 +static user_regset_no_const x86_64_regsets[] __read_only = {
26296 [REGSET_GENERAL] = {
26297 .core_note_type = NT_PRSTATUS,
26298 .n = sizeof(struct user_regs_struct) / sizeof(long),
26299 @@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26300 #endif /* CONFIG_X86_64 */
26301
26302 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26303 -static struct user_regset x86_32_regsets[] __read_mostly = {
26304 +static user_regset_no_const x86_32_regsets[] __read_only = {
26305 [REGSET_GENERAL] = {
26306 .core_note_type = NT_PRSTATUS,
26307 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26308 @@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26309 */
26310 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26311
26312 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26313 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26314 {
26315 #ifdef CONFIG_X86_64
26316 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26317 @@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26318 memset(info, 0, sizeof(*info));
26319 info->si_signo = SIGTRAP;
26320 info->si_code = si_code;
26321 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26322 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26323 }
26324
26325 void user_single_step_siginfo(struct task_struct *tsk,
26326 @@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26327 # define IS_IA32 0
26328 #endif
26329
26330 +#ifdef CONFIG_GRKERNSEC_SETXID
26331 +extern void gr_delayed_cred_worker(void);
26332 +#endif
26333 +
26334 /*
26335 * We must return the syscall number to actually look up in the table.
26336 * This can be -1L to skip running any syscall at all.
26337 @@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26338
26339 user_exit();
26340
26341 +#ifdef CONFIG_GRKERNSEC_SETXID
26342 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26343 + gr_delayed_cred_worker();
26344 +#endif
26345 +
26346 /*
26347 * If we stepped into a sysenter/syscall insn, it trapped in
26348 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26349 @@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26350 */
26351 user_exit();
26352
26353 +#ifdef CONFIG_GRKERNSEC_SETXID
26354 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26355 + gr_delayed_cred_worker();
26356 +#endif
26357 +
26358 audit_syscall_exit(regs);
26359
26360 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26361 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26362 index 2f355d2..e75ed0a 100644
26363 --- a/arch/x86/kernel/pvclock.c
26364 +++ b/arch/x86/kernel/pvclock.c
26365 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26366 reset_hung_task_detector();
26367 }
26368
26369 -static atomic64_t last_value = ATOMIC64_INIT(0);
26370 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26371
26372 void pvclock_resume(void)
26373 {
26374 - atomic64_set(&last_value, 0);
26375 + atomic64_set_unchecked(&last_value, 0);
26376 }
26377
26378 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26379 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26380 * updating at the same time, and one of them could be slightly behind,
26381 * making the assumption that last_value always go forward fail to hold.
26382 */
26383 - last = atomic64_read(&last_value);
26384 + last = atomic64_read_unchecked(&last_value);
26385 do {
26386 if (ret < last)
26387 return last;
26388 - last = atomic64_cmpxchg(&last_value, last, ret);
26389 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26390 } while (unlikely(last != ret));
26391
26392 return ret;
26393 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26394 index c752cb4..866c432 100644
26395 --- a/arch/x86/kernel/reboot.c
26396 +++ b/arch/x86/kernel/reboot.c
26397 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26398
26399 void __noreturn machine_real_restart(unsigned int type)
26400 {
26401 +
26402 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26403 + struct desc_struct *gdt;
26404 +#endif
26405 +
26406 local_irq_disable();
26407
26408 /*
26409 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26410
26411 /* Jump to the identity-mapped low memory code */
26412 #ifdef CONFIG_X86_32
26413 - asm volatile("jmpl *%0" : :
26414 +
26415 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26416 + gdt = get_cpu_gdt_table(smp_processor_id());
26417 + pax_open_kernel();
26418 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26419 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26420 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26421 + loadsegment(ds, __KERNEL_DS);
26422 + loadsegment(es, __KERNEL_DS);
26423 + loadsegment(ss, __KERNEL_DS);
26424 +#endif
26425 +#ifdef CONFIG_PAX_KERNEXEC
26426 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26427 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26428 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26429 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26430 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26431 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26432 +#endif
26433 + pax_close_kernel();
26434 +#endif
26435 +
26436 + asm volatile("ljmpl *%0" : :
26437 "rm" (real_mode_header->machine_real_restart_asm),
26438 "a" (type));
26439 #else
26440 @@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26441 * try to force a triple fault and then cycle between hitting the keyboard
26442 * controller and doing that
26443 */
26444 -static void native_machine_emergency_restart(void)
26445 +static void __noreturn native_machine_emergency_restart(void)
26446 {
26447 int i;
26448 int attempt = 0;
26449 @@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26450 #endif
26451 }
26452
26453 -static void __machine_emergency_restart(int emergency)
26454 +static void __noreturn __machine_emergency_restart(int emergency)
26455 {
26456 reboot_emergency = emergency;
26457 machine_ops.emergency_restart();
26458 }
26459
26460 -static void native_machine_restart(char *__unused)
26461 +static void __noreturn native_machine_restart(char *__unused)
26462 {
26463 pr_notice("machine restart\n");
26464
26465 @@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26466 __machine_emergency_restart(0);
26467 }
26468
26469 -static void native_machine_halt(void)
26470 +static void __noreturn native_machine_halt(void)
26471 {
26472 /* Stop other cpus and apics */
26473 machine_shutdown();
26474 @@ -618,7 +645,7 @@ static void native_machine_halt(void)
26475 stop_this_cpu(NULL);
26476 }
26477
26478 -static void native_machine_power_off(void)
26479 +static void __noreturn native_machine_power_off(void)
26480 {
26481 if (pm_power_off) {
26482 if (!reboot_force)
26483 @@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26484 }
26485 /* A fallback in case there is no PM info available */
26486 tboot_shutdown(TB_SHUTDOWN_HALT);
26487 + unreachable();
26488 }
26489
26490 -struct machine_ops machine_ops = {
26491 +struct machine_ops machine_ops __read_only = {
26492 .power_off = native_machine_power_off,
26493 .shutdown = native_machine_shutdown,
26494 .emergency_restart = native_machine_emergency_restart,
26495 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26496 index c8e41e9..64049ef 100644
26497 --- a/arch/x86/kernel/reboot_fixups_32.c
26498 +++ b/arch/x86/kernel/reboot_fixups_32.c
26499 @@ -57,7 +57,7 @@ struct device_fixup {
26500 unsigned int vendor;
26501 unsigned int device;
26502 void (*reboot_fixup)(struct pci_dev *);
26503 -};
26504 +} __do_const;
26505
26506 /*
26507 * PCI ids solely used for fixups_table go here
26508 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26509 index 3fd2c69..a444264 100644
26510 --- a/arch/x86/kernel/relocate_kernel_64.S
26511 +++ b/arch/x86/kernel/relocate_kernel_64.S
26512 @@ -96,8 +96,7 @@ relocate_kernel:
26513
26514 /* jump to identity mapped page */
26515 addq $(identity_mapped - relocate_kernel), %r8
26516 - pushq %r8
26517 - ret
26518 + jmp *%r8
26519
26520 identity_mapped:
26521 /* set return address to 0 if not preserving context */
26522 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26523 index ce72964..be8aea7 100644
26524 --- a/arch/x86/kernel/setup.c
26525 +++ b/arch/x86/kernel/setup.c
26526 @@ -110,6 +110,7 @@
26527 #include <asm/mce.h>
26528 #include <asm/alternative.h>
26529 #include <asm/prom.h>
26530 +#include <asm/boot.h>
26531
26532 /*
26533 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26534 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26535 #endif
26536
26537
26538 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26539 -__visible unsigned long mmu_cr4_features;
26540 +#ifdef CONFIG_X86_64
26541 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26542 +#elif defined(CONFIG_X86_PAE)
26543 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26544 #else
26545 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26546 +__visible unsigned long mmu_cr4_features __read_only;
26547 #endif
26548
26549 +void set_in_cr4(unsigned long mask)
26550 +{
26551 + unsigned long cr4 = read_cr4();
26552 +
26553 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26554 + return;
26555 +
26556 + pax_open_kernel();
26557 + mmu_cr4_features |= mask;
26558 + pax_close_kernel();
26559 +
26560 + if (trampoline_cr4_features)
26561 + *trampoline_cr4_features = mmu_cr4_features;
26562 + cr4 |= mask;
26563 + write_cr4(cr4);
26564 +}
26565 +EXPORT_SYMBOL(set_in_cr4);
26566 +
26567 +void clear_in_cr4(unsigned long mask)
26568 +{
26569 + unsigned long cr4 = read_cr4();
26570 +
26571 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26572 + return;
26573 +
26574 + pax_open_kernel();
26575 + mmu_cr4_features &= ~mask;
26576 + pax_close_kernel();
26577 +
26578 + if (trampoline_cr4_features)
26579 + *trampoline_cr4_features = mmu_cr4_features;
26580 + cr4 &= ~mask;
26581 + write_cr4(cr4);
26582 +}
26583 +EXPORT_SYMBOL(clear_in_cr4);
26584 +
26585 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26586 int bootloader_type, bootloader_version;
26587
26588 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
26589 * area (640->1Mb) as ram even though it is not.
26590 * take them out.
26591 */
26592 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26593 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26594
26595 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26596 }
26597 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
26598 /* called before trim_bios_range() to spare extra sanitize */
26599 static void __init e820_add_kernel_range(void)
26600 {
26601 - u64 start = __pa_symbol(_text);
26602 + u64 start = __pa_symbol(ktla_ktva(_text));
26603 u64 size = __pa_symbol(_end) - start;
26604
26605 /*
26606 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
26607
26608 void __init setup_arch(char **cmdline_p)
26609 {
26610 +#ifdef CONFIG_X86_32
26611 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26612 +#else
26613 memblock_reserve(__pa_symbol(_text),
26614 (unsigned long)__bss_stop - (unsigned long)_text);
26615 +#endif
26616
26617 early_reserve_initrd();
26618
26619 @@ -947,14 +990,14 @@ void __init setup_arch(char **cmdline_p)
26620
26621 if (!boot_params.hdr.root_flags)
26622 root_mountflags &= ~MS_RDONLY;
26623 - init_mm.start_code = (unsigned long) _text;
26624 - init_mm.end_code = (unsigned long) _etext;
26625 + init_mm.start_code = ktla_ktva((unsigned long) _text);
26626 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
26627 init_mm.end_data = (unsigned long) _edata;
26628 init_mm.brk = _brk_end;
26629
26630 - code_resource.start = __pa_symbol(_text);
26631 - code_resource.end = __pa_symbol(_etext)-1;
26632 - data_resource.start = __pa_symbol(_etext);
26633 + code_resource.start = __pa_symbol(ktla_ktva(_text));
26634 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26635 + data_resource.start = __pa_symbol(_sdata);
26636 data_resource.end = __pa_symbol(_edata)-1;
26637 bss_resource.start = __pa_symbol(__bss_start);
26638 bss_resource.end = __pa_symbol(__bss_stop)-1;
26639 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26640 index 5cdff03..80fa283 100644
26641 --- a/arch/x86/kernel/setup_percpu.c
26642 +++ b/arch/x86/kernel/setup_percpu.c
26643 @@ -21,19 +21,17 @@
26644 #include <asm/cpu.h>
26645 #include <asm/stackprotector.h>
26646
26647 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26648 +#ifdef CONFIG_SMP
26649 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26650 EXPORT_PER_CPU_SYMBOL(cpu_number);
26651 +#endif
26652
26653 -#ifdef CONFIG_X86_64
26654 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26655 -#else
26656 -#define BOOT_PERCPU_OFFSET 0
26657 -#endif
26658
26659 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26660 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26661
26662 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26663 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26664 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26665 };
26666 EXPORT_SYMBOL(__per_cpu_offset);
26667 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26668 {
26669 #ifdef CONFIG_NEED_MULTIPLE_NODES
26670 pg_data_t *last = NULL;
26671 - unsigned int cpu;
26672 + int cpu;
26673
26674 for_each_possible_cpu(cpu) {
26675 int node = early_cpu_to_node(cpu);
26676 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26677 {
26678 #ifdef CONFIG_X86_32
26679 struct desc_struct gdt;
26680 + unsigned long base = per_cpu_offset(cpu);
26681
26682 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26683 - 0x2 | DESCTYPE_S, 0x8);
26684 - gdt.s = 1;
26685 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26686 + 0x83 | DESCTYPE_S, 0xC);
26687 write_gdt_entry(get_cpu_gdt_table(cpu),
26688 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26689 #endif
26690 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26691 /* alrighty, percpu areas up and running */
26692 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26693 for_each_possible_cpu(cpu) {
26694 +#ifdef CONFIG_CC_STACKPROTECTOR
26695 +#ifdef CONFIG_X86_32
26696 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
26697 +#endif
26698 +#endif
26699 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26700 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26701 per_cpu(cpu_number, cpu) = cpu;
26702 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26703 */
26704 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26705 #endif
26706 +#ifdef CONFIG_CC_STACKPROTECTOR
26707 +#ifdef CONFIG_X86_32
26708 + if (!cpu)
26709 + per_cpu(stack_canary.canary, cpu) = canary;
26710 +#endif
26711 +#endif
26712 /*
26713 * Up to this point, the boot CPU has been using .init.data
26714 * area. Reload any changed state for the boot CPU.
26715 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26716 index 9e5de68..16c53cb 100644
26717 --- a/arch/x86/kernel/signal.c
26718 +++ b/arch/x86/kernel/signal.c
26719 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26720 * Align the stack pointer according to the i386 ABI,
26721 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26722 */
26723 - sp = ((sp + 4) & -16ul) - 4;
26724 + sp = ((sp - 12) & -16ul) - 4;
26725 #else /* !CONFIG_X86_32 */
26726 sp = round_down(sp, 16) - 8;
26727 #endif
26728 @@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26729 }
26730
26731 if (current->mm->context.vdso)
26732 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26733 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26734 else
26735 - restorer = &frame->retcode;
26736 + restorer = (void __user *)&frame->retcode;
26737 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26738 restorer = ksig->ka.sa.sa_restorer;
26739
26740 @@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26741 * reasons and because gdb uses it as a signature to notice
26742 * signal handler stack frames.
26743 */
26744 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26745 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26746
26747 if (err)
26748 return -EFAULT;
26749 @@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26750 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26751
26752 /* Set up to return from userspace. */
26753 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26754 + if (current->mm->context.vdso)
26755 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26756 + else
26757 + restorer = (void __user *)&frame->retcode;
26758 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26759 restorer = ksig->ka.sa.sa_restorer;
26760 put_user_ex(restorer, &frame->pretcode);
26761 @@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26762 * reasons and because gdb uses it as a signature to notice
26763 * signal handler stack frames.
26764 */
26765 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26766 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26767 } put_user_catch(err);
26768
26769 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26770 @@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26771 {
26772 int usig = signr_convert(ksig->sig);
26773 sigset_t *set = sigmask_to_save();
26774 - compat_sigset_t *cset = (compat_sigset_t *) set;
26775 + sigset_t sigcopy;
26776 + compat_sigset_t *cset;
26777 +
26778 + sigcopy = *set;
26779 +
26780 + cset = (compat_sigset_t *) &sigcopy;
26781
26782 /* Set up the stack frame */
26783 if (is_ia32_frame()) {
26784 @@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26785 } else if (is_x32_frame()) {
26786 return x32_setup_rt_frame(ksig, cset, regs);
26787 } else {
26788 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
26789 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26790 }
26791 }
26792
26793 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26794 index 7c3a5a6..f0a8961 100644
26795 --- a/arch/x86/kernel/smp.c
26796 +++ b/arch/x86/kernel/smp.c
26797 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26798
26799 __setup("nonmi_ipi", nonmi_ipi_setup);
26800
26801 -struct smp_ops smp_ops = {
26802 +struct smp_ops smp_ops __read_only = {
26803 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26804 .smp_prepare_cpus = native_smp_prepare_cpus,
26805 .smp_cpus_done = native_smp_cpus_done,
26806 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26807 index a32da80..30c97f1 100644
26808 --- a/arch/x86/kernel/smpboot.c
26809 +++ b/arch/x86/kernel/smpboot.c
26810 @@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26811
26812 enable_start_cpu0 = 0;
26813
26814 -#ifdef CONFIG_X86_32
26815 - /* switch away from the initial page table */
26816 - load_cr3(swapper_pg_dir);
26817 - __flush_tlb_all();
26818 -#endif
26819 -
26820 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26821 barrier();
26822 +
26823 + /* switch away from the initial page table */
26824 +#ifdef CONFIG_PAX_PER_CPU_PGD
26825 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26826 + __flush_tlb_all();
26827 +#elif defined(CONFIG_X86_32)
26828 + load_cr3(swapper_pg_dir);
26829 + __flush_tlb_all();
26830 +#endif
26831 +
26832 /*
26833 * Check TSC synchronization with the BP:
26834 */
26835 @@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26836 alternatives_enable_smp();
26837
26838 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26839 - (THREAD_SIZE + task_stack_page(idle))) - 1);
26840 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
26841 per_cpu(current_task, cpu) = idle;
26842 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26843
26844 #ifdef CONFIG_X86_32
26845 /* Stack for startup_32 can be just as for start_secondary onwards */
26846 @@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26847 #else
26848 clear_tsk_thread_flag(idle, TIF_FORK);
26849 initial_gs = per_cpu_offset(cpu);
26850 - per_cpu(kernel_stack, cpu) =
26851 - (unsigned long)task_stack_page(idle) -
26852 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26853 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26854 #endif
26855 +
26856 + pax_open_kernel();
26857 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26858 + pax_close_kernel();
26859 +
26860 initial_code = (unsigned long)start_secondary;
26861 stack_start = idle->thread.sp;
26862
26863 @@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26864 /* the FPU context is blank, nobody can own it */
26865 __cpu_disable_lazy_restore(cpu);
26866
26867 +#ifdef CONFIG_PAX_PER_CPU_PGD
26868 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26869 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26870 + KERNEL_PGD_PTRS);
26871 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26872 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26873 + KERNEL_PGD_PTRS);
26874 +#endif
26875 +
26876 err = do_boot_cpu(apicid, cpu, tidle);
26877 if (err) {
26878 pr_debug("do_boot_cpu failed %d\n", err);
26879 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26880 index 9b4d51d..5d28b58 100644
26881 --- a/arch/x86/kernel/step.c
26882 +++ b/arch/x86/kernel/step.c
26883 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26884 struct desc_struct *desc;
26885 unsigned long base;
26886
26887 - seg &= ~7UL;
26888 + seg >>= 3;
26889
26890 mutex_lock(&child->mm->context.lock);
26891 - if (unlikely((seg >> 3) >= child->mm->context.size))
26892 + if (unlikely(seg >= child->mm->context.size))
26893 addr = -1L; /* bogus selector, access would fault */
26894 else {
26895 desc = child->mm->context.ldt + seg;
26896 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26897 addr += base;
26898 }
26899 mutex_unlock(&child->mm->context.lock);
26900 - }
26901 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26902 + addr = ktla_ktva(addr);
26903
26904 return addr;
26905 }
26906 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26907 unsigned char opcode[15];
26908 unsigned long addr = convert_ip_to_linear(child, regs);
26909
26910 + if (addr == -EINVAL)
26911 + return 0;
26912 +
26913 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26914 for (i = 0; i < copied; i++) {
26915 switch (opcode[i]) {
26916 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26917 new file mode 100644
26918 index 0000000..5877189
26919 --- /dev/null
26920 +++ b/arch/x86/kernel/sys_i386_32.c
26921 @@ -0,0 +1,189 @@
26922 +/*
26923 + * This file contains various random system calls that
26924 + * have a non-standard calling sequence on the Linux/i386
26925 + * platform.
26926 + */
26927 +
26928 +#include <linux/errno.h>
26929 +#include <linux/sched.h>
26930 +#include <linux/mm.h>
26931 +#include <linux/fs.h>
26932 +#include <linux/smp.h>
26933 +#include <linux/sem.h>
26934 +#include <linux/msg.h>
26935 +#include <linux/shm.h>
26936 +#include <linux/stat.h>
26937 +#include <linux/syscalls.h>
26938 +#include <linux/mman.h>
26939 +#include <linux/file.h>
26940 +#include <linux/utsname.h>
26941 +#include <linux/ipc.h>
26942 +#include <linux/elf.h>
26943 +
26944 +#include <linux/uaccess.h>
26945 +#include <linux/unistd.h>
26946 +
26947 +#include <asm/syscalls.h>
26948 +
26949 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26950 +{
26951 + unsigned long pax_task_size = TASK_SIZE;
26952 +
26953 +#ifdef CONFIG_PAX_SEGMEXEC
26954 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26955 + pax_task_size = SEGMEXEC_TASK_SIZE;
26956 +#endif
26957 +
26958 + if (flags & MAP_FIXED)
26959 + if (len > pax_task_size || addr > pax_task_size - len)
26960 + return -EINVAL;
26961 +
26962 + return 0;
26963 +}
26964 +
26965 +/*
26966 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
26967 + */
26968 +static unsigned long get_align_mask(void)
26969 +{
26970 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
26971 + return 0;
26972 +
26973 + if (!(current->flags & PF_RANDOMIZE))
26974 + return 0;
26975 +
26976 + return va_align.mask;
26977 +}
26978 +
26979 +unsigned long
26980 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
26981 + unsigned long len, unsigned long pgoff, unsigned long flags)
26982 +{
26983 + struct mm_struct *mm = current->mm;
26984 + struct vm_area_struct *vma;
26985 + unsigned long pax_task_size = TASK_SIZE;
26986 + struct vm_unmapped_area_info info;
26987 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26988 +
26989 +#ifdef CONFIG_PAX_SEGMEXEC
26990 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26991 + pax_task_size = SEGMEXEC_TASK_SIZE;
26992 +#endif
26993 +
26994 + pax_task_size -= PAGE_SIZE;
26995 +
26996 + if (len > pax_task_size)
26997 + return -ENOMEM;
26998 +
26999 + if (flags & MAP_FIXED)
27000 + return addr;
27001 +
27002 +#ifdef CONFIG_PAX_RANDMMAP
27003 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27004 +#endif
27005 +
27006 + if (addr) {
27007 + addr = PAGE_ALIGN(addr);
27008 + if (pax_task_size - len >= addr) {
27009 + vma = find_vma(mm, addr);
27010 + if (check_heap_stack_gap(vma, addr, len, offset))
27011 + return addr;
27012 + }
27013 + }
27014 +
27015 + info.flags = 0;
27016 + info.length = len;
27017 + info.align_mask = filp ? get_align_mask() : 0;
27018 + info.align_offset = pgoff << PAGE_SHIFT;
27019 + info.threadstack_offset = offset;
27020 +
27021 +#ifdef CONFIG_PAX_PAGEEXEC
27022 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27023 + info.low_limit = 0x00110000UL;
27024 + info.high_limit = mm->start_code;
27025 +
27026 +#ifdef CONFIG_PAX_RANDMMAP
27027 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27028 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27029 +#endif
27030 +
27031 + if (info.low_limit < info.high_limit) {
27032 + addr = vm_unmapped_area(&info);
27033 + if (!IS_ERR_VALUE(addr))
27034 + return addr;
27035 + }
27036 + } else
27037 +#endif
27038 +
27039 + info.low_limit = mm->mmap_base;
27040 + info.high_limit = pax_task_size;
27041 +
27042 + return vm_unmapped_area(&info);
27043 +}
27044 +
27045 +unsigned long
27046 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27047 + const unsigned long len, const unsigned long pgoff,
27048 + const unsigned long flags)
27049 +{
27050 + struct vm_area_struct *vma;
27051 + struct mm_struct *mm = current->mm;
27052 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27053 + struct vm_unmapped_area_info info;
27054 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27055 +
27056 +#ifdef CONFIG_PAX_SEGMEXEC
27057 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27058 + pax_task_size = SEGMEXEC_TASK_SIZE;
27059 +#endif
27060 +
27061 + pax_task_size -= PAGE_SIZE;
27062 +
27063 + /* requested length too big for entire address space */
27064 + if (len > pax_task_size)
27065 + return -ENOMEM;
27066 +
27067 + if (flags & MAP_FIXED)
27068 + return addr;
27069 +
27070 +#ifdef CONFIG_PAX_PAGEEXEC
27071 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27072 + goto bottomup;
27073 +#endif
27074 +
27075 +#ifdef CONFIG_PAX_RANDMMAP
27076 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27077 +#endif
27078 +
27079 + /* requesting a specific address */
27080 + if (addr) {
27081 + addr = PAGE_ALIGN(addr);
27082 + if (pax_task_size - len >= addr) {
27083 + vma = find_vma(mm, addr);
27084 + if (check_heap_stack_gap(vma, addr, len, offset))
27085 + return addr;
27086 + }
27087 + }
27088 +
27089 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27090 + info.length = len;
27091 + info.low_limit = PAGE_SIZE;
27092 + info.high_limit = mm->mmap_base;
27093 + info.align_mask = filp ? get_align_mask() : 0;
27094 + info.align_offset = pgoff << PAGE_SHIFT;
27095 + info.threadstack_offset = offset;
27096 +
27097 + addr = vm_unmapped_area(&info);
27098 + if (!(addr & ~PAGE_MASK))
27099 + return addr;
27100 + VM_BUG_ON(addr != -ENOMEM);
27101 +
27102 +bottomup:
27103 + /*
27104 + * A failed mmap() very likely causes application failure,
27105 + * so fall back to the bottom-up function here. This scenario
27106 + * can happen with large stack limits and large mmap()
27107 + * allocations.
27108 + */
27109 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27110 +}
27111 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27112 index 30277e2..5664a29 100644
27113 --- a/arch/x86/kernel/sys_x86_64.c
27114 +++ b/arch/x86/kernel/sys_x86_64.c
27115 @@ -81,8 +81,8 @@ out:
27116 return error;
27117 }
27118
27119 -static void find_start_end(unsigned long flags, unsigned long *begin,
27120 - unsigned long *end)
27121 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27122 + unsigned long *begin, unsigned long *end)
27123 {
27124 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27125 unsigned long new_begin;
27126 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27127 *begin = new_begin;
27128 }
27129 } else {
27130 - *begin = current->mm->mmap_legacy_base;
27131 + *begin = mm->mmap_legacy_base;
27132 *end = TASK_SIZE;
27133 }
27134 }
27135 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27136 struct vm_area_struct *vma;
27137 struct vm_unmapped_area_info info;
27138 unsigned long begin, end;
27139 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27140
27141 if (flags & MAP_FIXED)
27142 return addr;
27143
27144 - find_start_end(flags, &begin, &end);
27145 + find_start_end(mm, flags, &begin, &end);
27146
27147 if (len > end)
27148 return -ENOMEM;
27149
27150 +#ifdef CONFIG_PAX_RANDMMAP
27151 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27152 +#endif
27153 +
27154 if (addr) {
27155 addr = PAGE_ALIGN(addr);
27156 vma = find_vma(mm, addr);
27157 - if (end - len >= addr &&
27158 - (!vma || addr + len <= vma->vm_start))
27159 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27160 return addr;
27161 }
27162
27163 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27164 info.high_limit = end;
27165 info.align_mask = filp ? get_align_mask() : 0;
27166 info.align_offset = pgoff << PAGE_SHIFT;
27167 + info.threadstack_offset = offset;
27168 return vm_unmapped_area(&info);
27169 }
27170
27171 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27172 struct mm_struct *mm = current->mm;
27173 unsigned long addr = addr0;
27174 struct vm_unmapped_area_info info;
27175 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27176
27177 /* requested length too big for entire address space */
27178 if (len > TASK_SIZE)
27179 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27180 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27181 goto bottomup;
27182
27183 +#ifdef CONFIG_PAX_RANDMMAP
27184 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27185 +#endif
27186 +
27187 /* requesting a specific address */
27188 if (addr) {
27189 addr = PAGE_ALIGN(addr);
27190 vma = find_vma(mm, addr);
27191 - if (TASK_SIZE - len >= addr &&
27192 - (!vma || addr + len <= vma->vm_start))
27193 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27194 return addr;
27195 }
27196
27197 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27198 info.high_limit = mm->mmap_base;
27199 info.align_mask = filp ? get_align_mask() : 0;
27200 info.align_offset = pgoff << PAGE_SHIFT;
27201 + info.threadstack_offset = offset;
27202 addr = vm_unmapped_area(&info);
27203 if (!(addr & ~PAGE_MASK))
27204 return addr;
27205 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27206 index 91a4496..bb87552 100644
27207 --- a/arch/x86/kernel/tboot.c
27208 +++ b/arch/x86/kernel/tboot.c
27209 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27210
27211 void tboot_shutdown(u32 shutdown_type)
27212 {
27213 - void (*shutdown)(void);
27214 + void (* __noreturn shutdown)(void);
27215
27216 if (!tboot_enabled())
27217 return;
27218 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27219
27220 switch_to_tboot_pt();
27221
27222 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27223 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27224 shutdown();
27225
27226 /* should not reach here */
27227 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27228 return -ENODEV;
27229 }
27230
27231 -static atomic_t ap_wfs_count;
27232 +static atomic_unchecked_t ap_wfs_count;
27233
27234 static int tboot_wait_for_aps(int num_aps)
27235 {
27236 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27237 {
27238 switch (action) {
27239 case CPU_DYING:
27240 - atomic_inc(&ap_wfs_count);
27241 + atomic_inc_unchecked(&ap_wfs_count);
27242 if (num_online_cpus() == 1)
27243 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27244 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27245 return NOTIFY_BAD;
27246 break;
27247 }
27248 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27249
27250 tboot_create_trampoline();
27251
27252 - atomic_set(&ap_wfs_count, 0);
27253 + atomic_set_unchecked(&ap_wfs_count, 0);
27254 register_hotcpu_notifier(&tboot_cpu_notifier);
27255
27256 #ifdef CONFIG_DEBUG_FS
27257 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27258 index 24d3c91..d06b473 100644
27259 --- a/arch/x86/kernel/time.c
27260 +++ b/arch/x86/kernel/time.c
27261 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27262 {
27263 unsigned long pc = instruction_pointer(regs);
27264
27265 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27266 + if (!user_mode(regs) && in_lock_functions(pc)) {
27267 #ifdef CONFIG_FRAME_POINTER
27268 - return *(unsigned long *)(regs->bp + sizeof(long));
27269 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27270 #else
27271 unsigned long *sp =
27272 (unsigned long *)kernel_stack_pointer(regs);
27273 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27274 * or above a saved flags. Eflags has bits 22-31 zero,
27275 * kernel addresses don't.
27276 */
27277 +
27278 +#ifdef CONFIG_PAX_KERNEXEC
27279 + return ktla_ktva(sp[0]);
27280 +#else
27281 if (sp[0] >> 22)
27282 return sp[0];
27283 if (sp[1] >> 22)
27284 return sp[1];
27285 #endif
27286 +
27287 +#endif
27288 }
27289 return pc;
27290 }
27291 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27292 index f7fec09..9991981 100644
27293 --- a/arch/x86/kernel/tls.c
27294 +++ b/arch/x86/kernel/tls.c
27295 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27296 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27297 return -EINVAL;
27298
27299 +#ifdef CONFIG_PAX_SEGMEXEC
27300 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27301 + return -EINVAL;
27302 +#endif
27303 +
27304 set_tls_desc(p, idx, &info, 1);
27305
27306 return 0;
27307 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27308
27309 if (kbuf)
27310 info = kbuf;
27311 - else if (__copy_from_user(infobuf, ubuf, count))
27312 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27313 return -EFAULT;
27314 else
27315 info = infobuf;
27316 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27317 index 1c113db..287b42e 100644
27318 --- a/arch/x86/kernel/tracepoint.c
27319 +++ b/arch/x86/kernel/tracepoint.c
27320 @@ -9,11 +9,11 @@
27321 #include <linux/atomic.h>
27322
27323 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27324 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27325 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27326 (unsigned long) trace_idt_table };
27327
27328 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27329 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27330 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27331
27332 static int trace_irq_vector_refcount;
27333 static DEFINE_MUTEX(irq_vector_mutex);
27334 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27335 index 57409f6..8a7aa05 100644
27336 --- a/arch/x86/kernel/traps.c
27337 +++ b/arch/x86/kernel/traps.c
27338 @@ -66,7 +66,7 @@
27339 #include <asm/proto.h>
27340
27341 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27342 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27343 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27344 #else
27345 #include <asm/processor-flags.h>
27346 #include <asm/setup.h>
27347 @@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27348 #endif
27349
27350 /* Must be page-aligned because the real IDT is used in a fixmap. */
27351 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27352 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27353
27354 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27355 EXPORT_SYMBOL_GPL(used_vectors);
27356 @@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27357 }
27358
27359 static int __kprobes
27360 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27361 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27362 struct pt_regs *regs, long error_code)
27363 {
27364 #ifdef CONFIG_X86_32
27365 - if (regs->flags & X86_VM_MASK) {
27366 + if (v8086_mode(regs)) {
27367 /*
27368 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27369 * On nmi (interrupt 2), do_trap should not be called.
27370 @@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27371 return -1;
27372 }
27373 #endif
27374 - if (!user_mode(regs)) {
27375 + if (!user_mode_novm(regs)) {
27376 if (!fixup_exception(regs)) {
27377 tsk->thread.error_code = error_code;
27378 tsk->thread.trap_nr = trapnr;
27379 +
27380 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27381 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27382 + str = "PAX: suspicious stack segment fault";
27383 +#endif
27384 +
27385 die(str, regs, error_code);
27386 }
27387 +
27388 +#ifdef CONFIG_PAX_REFCOUNT
27389 + if (trapnr == 4)
27390 + pax_report_refcount_overflow(regs);
27391 +#endif
27392 +
27393 return 0;
27394 }
27395
27396 @@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27397 }
27398
27399 static void __kprobes
27400 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27401 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27402 long error_code, siginfo_t *info)
27403 {
27404 struct task_struct *tsk = current;
27405 @@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27406 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27407 printk_ratelimit()) {
27408 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27409 - tsk->comm, tsk->pid, str,
27410 + tsk->comm, task_pid_nr(tsk), str,
27411 regs->ip, regs->sp, error_code);
27412 print_vma_addr(" in ", regs->ip);
27413 pr_cont("\n");
27414 @@ -273,7 +285,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27415 conditional_sti(regs);
27416
27417 #ifdef CONFIG_X86_32
27418 - if (regs->flags & X86_VM_MASK) {
27419 + if (v8086_mode(regs)) {
27420 local_irq_enable();
27421 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27422 goto exit;
27423 @@ -281,18 +293,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27424 #endif
27425
27426 tsk = current;
27427 - if (!user_mode(regs)) {
27428 + if (!user_mode_novm(regs)) {
27429 if (fixup_exception(regs))
27430 goto exit;
27431
27432 tsk->thread.error_code = error_code;
27433 tsk->thread.trap_nr = X86_TRAP_GP;
27434 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27435 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27436 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27437 +
27438 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27439 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27440 + die("PAX: suspicious general protection fault", regs, error_code);
27441 + else
27442 +#endif
27443 +
27444 die("general protection fault", regs, error_code);
27445 + }
27446 goto exit;
27447 }
27448
27449 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27450 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27451 + struct mm_struct *mm = tsk->mm;
27452 + unsigned long limit;
27453 +
27454 + down_write(&mm->mmap_sem);
27455 + limit = mm->context.user_cs_limit;
27456 + if (limit < TASK_SIZE) {
27457 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27458 + up_write(&mm->mmap_sem);
27459 + return;
27460 + }
27461 + up_write(&mm->mmap_sem);
27462 + }
27463 +#endif
27464 +
27465 tsk->thread.error_code = error_code;
27466 tsk->thread.trap_nr = X86_TRAP_GP;
27467
27468 @@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27469 /* It's safe to allow irq's after DR6 has been saved */
27470 preempt_conditional_sti(regs);
27471
27472 - if (regs->flags & X86_VM_MASK) {
27473 + if (v8086_mode(regs)) {
27474 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27475 X86_TRAP_DB);
27476 preempt_conditional_cli(regs);
27477 @@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27478 * We already checked v86 mode above, so we can check for kernel mode
27479 * by just checking the CPL of CS.
27480 */
27481 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
27482 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27483 tsk->thread.debugreg6 &= ~DR_STEP;
27484 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27485 regs->flags &= ~X86_EFLAGS_TF;
27486 @@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27487 return;
27488 conditional_sti(regs);
27489
27490 - if (!user_mode_vm(regs))
27491 + if (!user_mode(regs))
27492 {
27493 if (!fixup_exception(regs)) {
27494 task->thread.error_code = error_code;
27495 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27496 index cfbe99f..a6e8fa7 100644
27497 --- a/arch/x86/kernel/tsc.c
27498 +++ b/arch/x86/kernel/tsc.c
27499 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27500 */
27501 smp_wmb();
27502
27503 - ACCESS_ONCE(c2n->head) = data;
27504 + ACCESS_ONCE_RW(c2n->head) = data;
27505 }
27506
27507 /*
27508 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27509 index 2ed8459..7cf329f 100644
27510 --- a/arch/x86/kernel/uprobes.c
27511 +++ b/arch/x86/kernel/uprobes.c
27512 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27513 int ret = NOTIFY_DONE;
27514
27515 /* We are only interested in userspace traps */
27516 - if (regs && !user_mode_vm(regs))
27517 + if (regs && !user_mode(regs))
27518 return NOTIFY_DONE;
27519
27520 switch (val) {
27521 @@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27522
27523 if (ncopied != rasize) {
27524 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27525 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27526 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27527
27528 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27529 }
27530 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27531 index b9242ba..50c5edd 100644
27532 --- a/arch/x86/kernel/verify_cpu.S
27533 +++ b/arch/x86/kernel/verify_cpu.S
27534 @@ -20,6 +20,7 @@
27535 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27536 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27537 * arch/x86/kernel/head_32.S: processor startup
27538 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27539 *
27540 * verify_cpu, returns the status of longmode and SSE in register %eax.
27541 * 0: Success 1: Failure
27542 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27543 index e8edcf5..27f9344 100644
27544 --- a/arch/x86/kernel/vm86_32.c
27545 +++ b/arch/x86/kernel/vm86_32.c
27546 @@ -44,6 +44,7 @@
27547 #include <linux/ptrace.h>
27548 #include <linux/audit.h>
27549 #include <linux/stddef.h>
27550 +#include <linux/grsecurity.h>
27551
27552 #include <asm/uaccess.h>
27553 #include <asm/io.h>
27554 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27555 do_exit(SIGSEGV);
27556 }
27557
27558 - tss = &per_cpu(init_tss, get_cpu());
27559 + tss = init_tss + get_cpu();
27560 current->thread.sp0 = current->thread.saved_sp0;
27561 current->thread.sysenter_cs = __KERNEL_CS;
27562 load_sp0(tss, &current->thread);
27563 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27564
27565 if (tsk->thread.saved_sp0)
27566 return -EPERM;
27567 +
27568 +#ifdef CONFIG_GRKERNSEC_VM86
27569 + if (!capable(CAP_SYS_RAWIO)) {
27570 + gr_handle_vm86();
27571 + return -EPERM;
27572 + }
27573 +#endif
27574 +
27575 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27576 offsetof(struct kernel_vm86_struct, vm86plus) -
27577 sizeof(info.regs));
27578 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27579 int tmp;
27580 struct vm86plus_struct __user *v86;
27581
27582 +#ifdef CONFIG_GRKERNSEC_VM86
27583 + if (!capable(CAP_SYS_RAWIO)) {
27584 + gr_handle_vm86();
27585 + return -EPERM;
27586 + }
27587 +#endif
27588 +
27589 tsk = current;
27590 switch (cmd) {
27591 case VM86_REQUEST_IRQ:
27592 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27593 tsk->thread.saved_fs = info->regs32->fs;
27594 tsk->thread.saved_gs = get_user_gs(info->regs32);
27595
27596 - tss = &per_cpu(init_tss, get_cpu());
27597 + tss = init_tss + get_cpu();
27598 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27599 if (cpu_has_sep)
27600 tsk->thread.sysenter_cs = 0;
27601 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27602 goto cannot_handle;
27603 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27604 goto cannot_handle;
27605 - intr_ptr = (unsigned long __user *) (i << 2);
27606 + intr_ptr = (__force unsigned long __user *) (i << 2);
27607 if (get_user(segoffs, intr_ptr))
27608 goto cannot_handle;
27609 if ((segoffs >> 16) == BIOSSEG)
27610 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27611 index da6b35a..977e9cf 100644
27612 --- a/arch/x86/kernel/vmlinux.lds.S
27613 +++ b/arch/x86/kernel/vmlinux.lds.S
27614 @@ -26,6 +26,13 @@
27615 #include <asm/page_types.h>
27616 #include <asm/cache.h>
27617 #include <asm/boot.h>
27618 +#include <asm/segment.h>
27619 +
27620 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27621 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27622 +#else
27623 +#define __KERNEL_TEXT_OFFSET 0
27624 +#endif
27625
27626 #undef i386 /* in case the preprocessor is a 32bit one */
27627
27628 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27629
27630 PHDRS {
27631 text PT_LOAD FLAGS(5); /* R_E */
27632 +#ifdef CONFIG_X86_32
27633 + module PT_LOAD FLAGS(5); /* R_E */
27634 +#endif
27635 +#ifdef CONFIG_XEN
27636 + rodata PT_LOAD FLAGS(5); /* R_E */
27637 +#else
27638 + rodata PT_LOAD FLAGS(4); /* R__ */
27639 +#endif
27640 data PT_LOAD FLAGS(6); /* RW_ */
27641 -#ifdef CONFIG_X86_64
27642 + init.begin PT_LOAD FLAGS(6); /* RW_ */
27643 #ifdef CONFIG_SMP
27644 percpu PT_LOAD FLAGS(6); /* RW_ */
27645 #endif
27646 + text.init PT_LOAD FLAGS(5); /* R_E */
27647 + text.exit PT_LOAD FLAGS(5); /* R_E */
27648 init PT_LOAD FLAGS(7); /* RWE */
27649 -#endif
27650 note PT_NOTE FLAGS(0); /* ___ */
27651 }
27652
27653 SECTIONS
27654 {
27655 #ifdef CONFIG_X86_32
27656 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27657 - phys_startup_32 = startup_32 - LOAD_OFFSET;
27658 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27659 #else
27660 - . = __START_KERNEL;
27661 - phys_startup_64 = startup_64 - LOAD_OFFSET;
27662 + . = __START_KERNEL;
27663 #endif
27664
27665 /* Text and read-only data */
27666 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
27667 - _text = .;
27668 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27669 /* bootstrapping code */
27670 +#ifdef CONFIG_X86_32
27671 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27672 +#else
27673 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27674 +#endif
27675 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27676 + _text = .;
27677 HEAD_TEXT
27678 . = ALIGN(8);
27679 _stext = .;
27680 @@ -104,13 +124,47 @@ SECTIONS
27681 IRQENTRY_TEXT
27682 *(.fixup)
27683 *(.gnu.warning)
27684 - /* End of text section */
27685 - _etext = .;
27686 } :text = 0x9090
27687
27688 - NOTES :text :note
27689 + . += __KERNEL_TEXT_OFFSET;
27690
27691 - EXCEPTION_TABLE(16) :text = 0x9090
27692 +#ifdef CONFIG_X86_32
27693 + . = ALIGN(PAGE_SIZE);
27694 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27695 +
27696 +#ifdef CONFIG_PAX_KERNEXEC
27697 + MODULES_EXEC_VADDR = .;
27698 + BYTE(0)
27699 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27700 + . = ALIGN(HPAGE_SIZE) - 1;
27701 + MODULES_EXEC_END = .;
27702 +#endif
27703 +
27704 + } :module
27705 +#endif
27706 +
27707 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27708 + /* End of text section */
27709 + BYTE(0)
27710 + _etext = . - __KERNEL_TEXT_OFFSET;
27711 + }
27712 +
27713 +#ifdef CONFIG_X86_32
27714 + . = ALIGN(PAGE_SIZE);
27715 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27716 + . = ALIGN(PAGE_SIZE);
27717 + *(.empty_zero_page)
27718 + *(.initial_pg_fixmap)
27719 + *(.initial_pg_pmd)
27720 + *(.initial_page_table)
27721 + *(.swapper_pg_dir)
27722 + } :rodata
27723 +#endif
27724 +
27725 + . = ALIGN(PAGE_SIZE);
27726 + NOTES :rodata :note
27727 +
27728 + EXCEPTION_TABLE(16) :rodata
27729
27730 #if defined(CONFIG_DEBUG_RODATA)
27731 /* .text should occupy whole number of pages */
27732 @@ -122,16 +176,20 @@ SECTIONS
27733
27734 /* Data */
27735 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27736 +
27737 +#ifdef CONFIG_PAX_KERNEXEC
27738 + . = ALIGN(HPAGE_SIZE);
27739 +#else
27740 + . = ALIGN(PAGE_SIZE);
27741 +#endif
27742 +
27743 /* Start of data section */
27744 _sdata = .;
27745
27746 /* init_task */
27747 INIT_TASK_DATA(THREAD_SIZE)
27748
27749 -#ifdef CONFIG_X86_32
27750 - /* 32 bit has nosave before _edata */
27751 NOSAVE_DATA
27752 -#endif
27753
27754 PAGE_ALIGNED_DATA(PAGE_SIZE)
27755
27756 @@ -172,12 +230,19 @@ SECTIONS
27757 #endif /* CONFIG_X86_64 */
27758
27759 /* Init code and data - will be freed after init */
27760 - . = ALIGN(PAGE_SIZE);
27761 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27762 + BYTE(0)
27763 +
27764 +#ifdef CONFIG_PAX_KERNEXEC
27765 + . = ALIGN(HPAGE_SIZE);
27766 +#else
27767 + . = ALIGN(PAGE_SIZE);
27768 +#endif
27769 +
27770 __init_begin = .; /* paired with __init_end */
27771 - }
27772 + } :init.begin
27773
27774 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27775 +#ifdef CONFIG_SMP
27776 /*
27777 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27778 * output PHDR, so the next output section - .init.text - should
27779 @@ -186,12 +251,27 @@ SECTIONS
27780 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27781 #endif
27782
27783 - INIT_TEXT_SECTION(PAGE_SIZE)
27784 -#ifdef CONFIG_X86_64
27785 - :init
27786 -#endif
27787 + . = ALIGN(PAGE_SIZE);
27788 + init_begin = .;
27789 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27790 + VMLINUX_SYMBOL(_sinittext) = .;
27791 + INIT_TEXT
27792 + VMLINUX_SYMBOL(_einittext) = .;
27793 + . = ALIGN(PAGE_SIZE);
27794 + } :text.init
27795
27796 - INIT_DATA_SECTION(16)
27797 + /*
27798 + * .exit.text is discard at runtime, not link time, to deal with
27799 + * references from .altinstructions and .eh_frame
27800 + */
27801 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27802 + EXIT_TEXT
27803 + . = ALIGN(16);
27804 + } :text.exit
27805 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27806 +
27807 + . = ALIGN(PAGE_SIZE);
27808 + INIT_DATA_SECTION(16) :init
27809
27810 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27811 __x86_cpu_dev_start = .;
27812 @@ -262,19 +342,12 @@ SECTIONS
27813 }
27814
27815 . = ALIGN(8);
27816 - /*
27817 - * .exit.text is discard at runtime, not link time, to deal with
27818 - * references from .altinstructions and .eh_frame
27819 - */
27820 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27821 - EXIT_TEXT
27822 - }
27823
27824 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27825 EXIT_DATA
27826 }
27827
27828 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27829 +#ifndef CONFIG_SMP
27830 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27831 #endif
27832
27833 @@ -293,16 +366,10 @@ SECTIONS
27834 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27835 __smp_locks = .;
27836 *(.smp_locks)
27837 - . = ALIGN(PAGE_SIZE);
27838 __smp_locks_end = .;
27839 + . = ALIGN(PAGE_SIZE);
27840 }
27841
27842 -#ifdef CONFIG_X86_64
27843 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27844 - NOSAVE_DATA
27845 - }
27846 -#endif
27847 -
27848 /* BSS */
27849 . = ALIGN(PAGE_SIZE);
27850 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27851 @@ -318,6 +385,7 @@ SECTIONS
27852 __brk_base = .;
27853 . += 64 * 1024; /* 64k alignment slop space */
27854 *(.brk_reservation) /* areas brk users have reserved */
27855 + . = ALIGN(HPAGE_SIZE);
27856 __brk_limit = .;
27857 }
27858
27859 @@ -344,13 +412,12 @@ SECTIONS
27860 * for the boot processor.
27861 */
27862 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27863 -INIT_PER_CPU(gdt_page);
27864 INIT_PER_CPU(irq_stack_union);
27865
27866 /*
27867 * Build-time check on the image size:
27868 */
27869 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27870 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27871 "kernel image bigger than KERNEL_IMAGE_SIZE");
27872
27873 #ifdef CONFIG_SMP
27874 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27875 index 1f96f93..d5c8f7a 100644
27876 --- a/arch/x86/kernel/vsyscall_64.c
27877 +++ b/arch/x86/kernel/vsyscall_64.c
27878 @@ -56,15 +56,13 @@
27879 DEFINE_VVAR(int, vgetcpu_mode);
27880 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27881
27882 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27883 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27884
27885 static int __init vsyscall_setup(char *str)
27886 {
27887 if (str) {
27888 if (!strcmp("emulate", str))
27889 vsyscall_mode = EMULATE;
27890 - else if (!strcmp("native", str))
27891 - vsyscall_mode = NATIVE;
27892 else if (!strcmp("none", str))
27893 vsyscall_mode = NONE;
27894 else
27895 @@ -323,8 +321,7 @@ do_ret:
27896 return true;
27897
27898 sigsegv:
27899 - force_sig(SIGSEGV, current);
27900 - return true;
27901 + do_group_exit(SIGKILL);
27902 }
27903
27904 /*
27905 @@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27906 extern char __vvar_page;
27907 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27908
27909 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27910 - vsyscall_mode == NATIVE
27911 - ? PAGE_KERNEL_VSYSCALL
27912 - : PAGE_KERNEL_VVAR);
27913 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27914 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27915 (unsigned long)VSYSCALL_START);
27916
27917 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27918 index 04068192..4d75aa6 100644
27919 --- a/arch/x86/kernel/x8664_ksyms_64.c
27920 +++ b/arch/x86/kernel/x8664_ksyms_64.c
27921 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27922 EXPORT_SYMBOL(copy_user_generic_unrolled);
27923 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27924 EXPORT_SYMBOL(__copy_user_nocache);
27925 -EXPORT_SYMBOL(_copy_from_user);
27926 -EXPORT_SYMBOL(_copy_to_user);
27927
27928 EXPORT_SYMBOL(copy_page);
27929 EXPORT_SYMBOL(clear_page);
27930 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
27931 EXPORT_SYMBOL(___preempt_schedule_context);
27932 #endif
27933 #endif
27934 +
27935 +#ifdef CONFIG_PAX_PER_CPU_PGD
27936 +EXPORT_SYMBOL(cpu_pgd);
27937 +#endif
27938 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27939 index e48b674..a451dd9 100644
27940 --- a/arch/x86/kernel/x86_init.c
27941 +++ b/arch/x86/kernel/x86_init.c
27942 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27943 static void default_nmi_init(void) { };
27944 static int default_i8042_detect(void) { return 1; };
27945
27946 -struct x86_platform_ops x86_platform = {
27947 +struct x86_platform_ops x86_platform __read_only = {
27948 .calibrate_tsc = native_calibrate_tsc,
27949 .get_wallclock = mach_get_cmos_time,
27950 .set_wallclock = mach_set_rtc_mmss,
27951 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27952 EXPORT_SYMBOL_GPL(x86_platform);
27953
27954 #if defined(CONFIG_PCI_MSI)
27955 -struct x86_msi_ops x86_msi = {
27956 +struct x86_msi_ops x86_msi __read_only = {
27957 .setup_msi_irqs = native_setup_msi_irqs,
27958 .compose_msi_msg = native_compose_msi_msg,
27959 .teardown_msi_irq = native_teardown_msi_irq,
27960 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
27961 }
27962 #endif
27963
27964 -struct x86_io_apic_ops x86_io_apic_ops = {
27965 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27966 .init = native_io_apic_init_mappings,
27967 .read = native_io_apic_read,
27968 .write = native_io_apic_write,
27969 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27970 index a4b451c..8dfe1ad 100644
27971 --- a/arch/x86/kernel/xsave.c
27972 +++ b/arch/x86/kernel/xsave.c
27973 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27974
27975 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
27976 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
27977 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27978 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27979
27980 if (!use_xsave())
27981 return err;
27982
27983 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
27984 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
27985
27986 /*
27987 * Read the xstate_bv which we copied (directly from the cpu or
27988 * from the state in task struct) to the user buffers.
27989 */
27990 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27991 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27992
27993 /*
27994 * For legacy compatible, we always set FP/SSE bits in the bit
27995 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27996 */
27997 xstate_bv |= XSTATE_FPSSE;
27998
27999 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28000 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28001
28002 return err;
28003 }
28004 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28005 {
28006 int err;
28007
28008 + buf = (struct xsave_struct __user *)____m(buf);
28009 if (use_xsave())
28010 err = xsave_user(buf);
28011 else if (use_fxsr())
28012 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28013 */
28014 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28015 {
28016 + buf = (void __user *)____m(buf);
28017 if (use_xsave()) {
28018 if ((unsigned long)buf % 64 || fx_only) {
28019 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28020 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28021 index c697625..a032162 100644
28022 --- a/arch/x86/kvm/cpuid.c
28023 +++ b/arch/x86/kvm/cpuid.c
28024 @@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28025 struct kvm_cpuid2 *cpuid,
28026 struct kvm_cpuid_entry2 __user *entries)
28027 {
28028 - int r;
28029 + int r, i;
28030
28031 r = -E2BIG;
28032 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28033 goto out;
28034 r = -EFAULT;
28035 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28036 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28037 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28038 goto out;
28039 + for (i = 0; i < cpuid->nent; ++i) {
28040 + struct kvm_cpuid_entry2 cpuid_entry;
28041 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28042 + goto out;
28043 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28044 + }
28045 vcpu->arch.cpuid_nent = cpuid->nent;
28046 kvm_apic_set_version(vcpu);
28047 kvm_x86_ops->cpuid_update(vcpu);
28048 @@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28049 struct kvm_cpuid2 *cpuid,
28050 struct kvm_cpuid_entry2 __user *entries)
28051 {
28052 - int r;
28053 + int r, i;
28054
28055 r = -E2BIG;
28056 if (cpuid->nent < vcpu->arch.cpuid_nent)
28057 goto out;
28058 r = -EFAULT;
28059 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28060 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28061 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28062 goto out;
28063 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28064 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28065 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28066 + goto out;
28067 + }
28068 return 0;
28069
28070 out:
28071 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28072 index 9736529..ab4f54c 100644
28073 --- a/arch/x86/kvm/lapic.c
28074 +++ b/arch/x86/kvm/lapic.c
28075 @@ -55,7 +55,7 @@
28076 #define APIC_BUS_CYCLE_NS 1
28077
28078 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28079 -#define apic_debug(fmt, arg...)
28080 +#define apic_debug(fmt, arg...) do {} while (0)
28081
28082 #define APIC_LVT_NUM 6
28083 /* 14 is the version for Xeon and Pentium 8.4.8*/
28084 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28085 index cba218a..1cc1bed 100644
28086 --- a/arch/x86/kvm/paging_tmpl.h
28087 +++ b/arch/x86/kvm/paging_tmpl.h
28088 @@ -331,7 +331,7 @@ retry_walk:
28089 if (unlikely(kvm_is_error_hva(host_addr)))
28090 goto error;
28091
28092 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28093 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28094 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28095 goto error;
28096 walker->ptep_user[walker->level - 1] = ptep_user;
28097 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28098 index 2de1bc0..22251ee 100644
28099 --- a/arch/x86/kvm/svm.c
28100 +++ b/arch/x86/kvm/svm.c
28101 @@ -3508,7 +3508,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28102 int cpu = raw_smp_processor_id();
28103
28104 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28105 +
28106 + pax_open_kernel();
28107 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28108 + pax_close_kernel();
28109 +
28110 load_TR_desc();
28111 }
28112
28113 @@ -3911,6 +3915,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28114 #endif
28115 #endif
28116
28117 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28118 + __set_fs(current_thread_info()->addr_limit);
28119 +#endif
28120 +
28121 reload_tss(vcpu);
28122
28123 local_irq_disable();
28124 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28125 index 3927528..fc19971 100644
28126 --- a/arch/x86/kvm/vmx.c
28127 +++ b/arch/x86/kvm/vmx.c
28128 @@ -1320,12 +1320,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28129 #endif
28130 }
28131
28132 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28133 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28134 {
28135 vmcs_writel(field, vmcs_readl(field) & ~mask);
28136 }
28137
28138 -static void vmcs_set_bits(unsigned long field, u32 mask)
28139 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28140 {
28141 vmcs_writel(field, vmcs_readl(field) | mask);
28142 }
28143 @@ -1585,7 +1585,11 @@ static void reload_tss(void)
28144 struct desc_struct *descs;
28145
28146 descs = (void *)gdt->address;
28147 +
28148 + pax_open_kernel();
28149 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28150 + pax_close_kernel();
28151 +
28152 load_TR_desc();
28153 }
28154
28155 @@ -1809,6 +1813,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28156 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28157 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28158
28159 +#ifdef CONFIG_PAX_PER_CPU_PGD
28160 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28161 +#endif
28162 +
28163 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28164 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28165 vmx->loaded_vmcs->cpu = cpu;
28166 @@ -2098,7 +2106,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28167 * reads and returns guest's timestamp counter "register"
28168 * guest_tsc = host_tsc + tsc_offset -- 21.3
28169 */
28170 -static u64 guest_read_tsc(void)
28171 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28172 {
28173 u64 host_tsc, tsc_offset;
28174
28175 @@ -3024,8 +3032,11 @@ static __init int hardware_setup(void)
28176 if (!cpu_has_vmx_flexpriority())
28177 flexpriority_enabled = 0;
28178
28179 - if (!cpu_has_vmx_tpr_shadow())
28180 - kvm_x86_ops->update_cr8_intercept = NULL;
28181 + if (!cpu_has_vmx_tpr_shadow()) {
28182 + pax_open_kernel();
28183 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28184 + pax_close_kernel();
28185 + }
28186
28187 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28188 kvm_disable_largepages();
28189 @@ -3036,13 +3047,15 @@ static __init int hardware_setup(void)
28190 if (!cpu_has_vmx_apicv())
28191 enable_apicv = 0;
28192
28193 + pax_open_kernel();
28194 if (enable_apicv)
28195 - kvm_x86_ops->update_cr8_intercept = NULL;
28196 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28197 else {
28198 - kvm_x86_ops->hwapic_irr_update = NULL;
28199 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28200 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28201 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28202 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28203 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28204 }
28205 + pax_close_kernel();
28206
28207 if (nested)
28208 nested_vmx_setup_ctls_msrs();
28209 @@ -4165,7 +4178,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28210
28211 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28212 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28213 +
28214 +#ifndef CONFIG_PAX_PER_CPU_PGD
28215 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28216 +#endif
28217
28218 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28219 #ifdef CONFIG_X86_64
28220 @@ -4187,7 +4203,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28221 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28222 vmx->host_idt_base = dt.address;
28223
28224 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28225 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28226
28227 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28228 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28229 @@ -7265,6 +7281,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28230 "jmp 2f \n\t"
28231 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28232 "2: "
28233 +
28234 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28235 + "ljmp %[cs],$3f\n\t"
28236 + "3: "
28237 +#endif
28238 +
28239 /* Save guest registers, load host registers, keep flags */
28240 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28241 "pop %0 \n\t"
28242 @@ -7317,6 +7339,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28243 #endif
28244 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28245 [wordsize]"i"(sizeof(ulong))
28246 +
28247 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28248 + ,[cs]"i"(__KERNEL_CS)
28249 +#endif
28250 +
28251 : "cc", "memory"
28252 #ifdef CONFIG_X86_64
28253 , "rax", "rbx", "rdi", "rsi"
28254 @@ -7330,7 +7357,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28255 if (debugctlmsr)
28256 update_debugctlmsr(debugctlmsr);
28257
28258 -#ifndef CONFIG_X86_64
28259 +#ifdef CONFIG_X86_32
28260 /*
28261 * The sysexit path does not restore ds/es, so we must set them to
28262 * a reasonable value ourselves.
28263 @@ -7339,8 +7366,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28264 * may be executed in interrupt context, which saves and restore segments
28265 * around it, nullifying its effect.
28266 */
28267 - loadsegment(ds, __USER_DS);
28268 - loadsegment(es, __USER_DS);
28269 + loadsegment(ds, __KERNEL_DS);
28270 + loadsegment(es, __KERNEL_DS);
28271 + loadsegment(ss, __KERNEL_DS);
28272 +
28273 +#ifdef CONFIG_PAX_KERNEXEC
28274 + loadsegment(fs, __KERNEL_PERCPU);
28275 +#endif
28276 +
28277 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28278 + __set_fs(current_thread_info()->addr_limit);
28279 +#endif
28280 +
28281 #endif
28282
28283 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28284 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28285 index 2b85784..ad70e19 100644
28286 --- a/arch/x86/kvm/x86.c
28287 +++ b/arch/x86/kvm/x86.c
28288 @@ -1777,8 +1777,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28289 {
28290 struct kvm *kvm = vcpu->kvm;
28291 int lm = is_long_mode(vcpu);
28292 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28293 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28294 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28295 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28296 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28297 : kvm->arch.xen_hvm_config.blob_size_32;
28298 u32 page_num = data & ~PAGE_MASK;
28299 @@ -2689,6 +2689,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28300 if (n < msr_list.nmsrs)
28301 goto out;
28302 r = -EFAULT;
28303 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28304 + goto out;
28305 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28306 num_msrs_to_save * sizeof(u32)))
28307 goto out;
28308 @@ -5503,7 +5505,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28309 };
28310 #endif
28311
28312 -int kvm_arch_init(void *opaque)
28313 +int kvm_arch_init(const void *opaque)
28314 {
28315 int r;
28316 struct kvm_x86_ops *ops = opaque;
28317 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28318 index ad1fb5f..fe30b66 100644
28319 --- a/arch/x86/lguest/boot.c
28320 +++ b/arch/x86/lguest/boot.c
28321 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28322 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28323 * Launcher to reboot us.
28324 */
28325 -static void lguest_restart(char *reason)
28326 +static __noreturn void lguest_restart(char *reason)
28327 {
28328 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28329 + BUG();
28330 }
28331
28332 /*G:050
28333 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28334 index 00933d5..3a64af9 100644
28335 --- a/arch/x86/lib/atomic64_386_32.S
28336 +++ b/arch/x86/lib/atomic64_386_32.S
28337 @@ -48,6 +48,10 @@ BEGIN(read)
28338 movl (v), %eax
28339 movl 4(v), %edx
28340 RET_ENDP
28341 +BEGIN(read_unchecked)
28342 + movl (v), %eax
28343 + movl 4(v), %edx
28344 +RET_ENDP
28345 #undef v
28346
28347 #define v %esi
28348 @@ -55,6 +59,10 @@ BEGIN(set)
28349 movl %ebx, (v)
28350 movl %ecx, 4(v)
28351 RET_ENDP
28352 +BEGIN(set_unchecked)
28353 + movl %ebx, (v)
28354 + movl %ecx, 4(v)
28355 +RET_ENDP
28356 #undef v
28357
28358 #define v %esi
28359 @@ -70,6 +78,20 @@ RET_ENDP
28360 BEGIN(add)
28361 addl %eax, (v)
28362 adcl %edx, 4(v)
28363 +
28364 +#ifdef CONFIG_PAX_REFCOUNT
28365 + jno 0f
28366 + subl %eax, (v)
28367 + sbbl %edx, 4(v)
28368 + int $4
28369 +0:
28370 + _ASM_EXTABLE(0b, 0b)
28371 +#endif
28372 +
28373 +RET_ENDP
28374 +BEGIN(add_unchecked)
28375 + addl %eax, (v)
28376 + adcl %edx, 4(v)
28377 RET_ENDP
28378 #undef v
28379
28380 @@ -77,6 +99,24 @@ RET_ENDP
28381 BEGIN(add_return)
28382 addl (v), %eax
28383 adcl 4(v), %edx
28384 +
28385 +#ifdef CONFIG_PAX_REFCOUNT
28386 + into
28387 +1234:
28388 + _ASM_EXTABLE(1234b, 2f)
28389 +#endif
28390 +
28391 + movl %eax, (v)
28392 + movl %edx, 4(v)
28393 +
28394 +#ifdef CONFIG_PAX_REFCOUNT
28395 +2:
28396 +#endif
28397 +
28398 +RET_ENDP
28399 +BEGIN(add_return_unchecked)
28400 + addl (v), %eax
28401 + adcl 4(v), %edx
28402 movl %eax, (v)
28403 movl %edx, 4(v)
28404 RET_ENDP
28405 @@ -86,6 +126,20 @@ RET_ENDP
28406 BEGIN(sub)
28407 subl %eax, (v)
28408 sbbl %edx, 4(v)
28409 +
28410 +#ifdef CONFIG_PAX_REFCOUNT
28411 + jno 0f
28412 + addl %eax, (v)
28413 + adcl %edx, 4(v)
28414 + int $4
28415 +0:
28416 + _ASM_EXTABLE(0b, 0b)
28417 +#endif
28418 +
28419 +RET_ENDP
28420 +BEGIN(sub_unchecked)
28421 + subl %eax, (v)
28422 + sbbl %edx, 4(v)
28423 RET_ENDP
28424 #undef v
28425
28426 @@ -96,6 +150,27 @@ BEGIN(sub_return)
28427 sbbl $0, %edx
28428 addl (v), %eax
28429 adcl 4(v), %edx
28430 +
28431 +#ifdef CONFIG_PAX_REFCOUNT
28432 + into
28433 +1234:
28434 + _ASM_EXTABLE(1234b, 2f)
28435 +#endif
28436 +
28437 + movl %eax, (v)
28438 + movl %edx, 4(v)
28439 +
28440 +#ifdef CONFIG_PAX_REFCOUNT
28441 +2:
28442 +#endif
28443 +
28444 +RET_ENDP
28445 +BEGIN(sub_return_unchecked)
28446 + negl %edx
28447 + negl %eax
28448 + sbbl $0, %edx
28449 + addl (v), %eax
28450 + adcl 4(v), %edx
28451 movl %eax, (v)
28452 movl %edx, 4(v)
28453 RET_ENDP
28454 @@ -105,6 +180,20 @@ RET_ENDP
28455 BEGIN(inc)
28456 addl $1, (v)
28457 adcl $0, 4(v)
28458 +
28459 +#ifdef CONFIG_PAX_REFCOUNT
28460 + jno 0f
28461 + subl $1, (v)
28462 + sbbl $0, 4(v)
28463 + int $4
28464 +0:
28465 + _ASM_EXTABLE(0b, 0b)
28466 +#endif
28467 +
28468 +RET_ENDP
28469 +BEGIN(inc_unchecked)
28470 + addl $1, (v)
28471 + adcl $0, 4(v)
28472 RET_ENDP
28473 #undef v
28474
28475 @@ -114,6 +203,26 @@ BEGIN(inc_return)
28476 movl 4(v), %edx
28477 addl $1, %eax
28478 adcl $0, %edx
28479 +
28480 +#ifdef CONFIG_PAX_REFCOUNT
28481 + into
28482 +1234:
28483 + _ASM_EXTABLE(1234b, 2f)
28484 +#endif
28485 +
28486 + movl %eax, (v)
28487 + movl %edx, 4(v)
28488 +
28489 +#ifdef CONFIG_PAX_REFCOUNT
28490 +2:
28491 +#endif
28492 +
28493 +RET_ENDP
28494 +BEGIN(inc_return_unchecked)
28495 + movl (v), %eax
28496 + movl 4(v), %edx
28497 + addl $1, %eax
28498 + adcl $0, %edx
28499 movl %eax, (v)
28500 movl %edx, 4(v)
28501 RET_ENDP
28502 @@ -123,6 +232,20 @@ RET_ENDP
28503 BEGIN(dec)
28504 subl $1, (v)
28505 sbbl $0, 4(v)
28506 +
28507 +#ifdef CONFIG_PAX_REFCOUNT
28508 + jno 0f
28509 + addl $1, (v)
28510 + adcl $0, 4(v)
28511 + int $4
28512 +0:
28513 + _ASM_EXTABLE(0b, 0b)
28514 +#endif
28515 +
28516 +RET_ENDP
28517 +BEGIN(dec_unchecked)
28518 + subl $1, (v)
28519 + sbbl $0, 4(v)
28520 RET_ENDP
28521 #undef v
28522
28523 @@ -132,6 +255,26 @@ BEGIN(dec_return)
28524 movl 4(v), %edx
28525 subl $1, %eax
28526 sbbl $0, %edx
28527 +
28528 +#ifdef CONFIG_PAX_REFCOUNT
28529 + into
28530 +1234:
28531 + _ASM_EXTABLE(1234b, 2f)
28532 +#endif
28533 +
28534 + movl %eax, (v)
28535 + movl %edx, 4(v)
28536 +
28537 +#ifdef CONFIG_PAX_REFCOUNT
28538 +2:
28539 +#endif
28540 +
28541 +RET_ENDP
28542 +BEGIN(dec_return_unchecked)
28543 + movl (v), %eax
28544 + movl 4(v), %edx
28545 + subl $1, %eax
28546 + sbbl $0, %edx
28547 movl %eax, (v)
28548 movl %edx, 4(v)
28549 RET_ENDP
28550 @@ -143,6 +286,13 @@ BEGIN(add_unless)
28551 adcl %edx, %edi
28552 addl (v), %eax
28553 adcl 4(v), %edx
28554 +
28555 +#ifdef CONFIG_PAX_REFCOUNT
28556 + into
28557 +1234:
28558 + _ASM_EXTABLE(1234b, 2f)
28559 +#endif
28560 +
28561 cmpl %eax, %ecx
28562 je 3f
28563 1:
28564 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28565 1:
28566 addl $1, %eax
28567 adcl $0, %edx
28568 +
28569 +#ifdef CONFIG_PAX_REFCOUNT
28570 + into
28571 +1234:
28572 + _ASM_EXTABLE(1234b, 2f)
28573 +#endif
28574 +
28575 movl %eax, (v)
28576 movl %edx, 4(v)
28577 movl $1, %eax
28578 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28579 movl 4(v), %edx
28580 subl $1, %eax
28581 sbbl $0, %edx
28582 +
28583 +#ifdef CONFIG_PAX_REFCOUNT
28584 + into
28585 +1234:
28586 + _ASM_EXTABLE(1234b, 1f)
28587 +#endif
28588 +
28589 js 1f
28590 movl %eax, (v)
28591 movl %edx, 4(v)
28592 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28593 index f5cc9eb..51fa319 100644
28594 --- a/arch/x86/lib/atomic64_cx8_32.S
28595 +++ b/arch/x86/lib/atomic64_cx8_32.S
28596 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28597 CFI_STARTPROC
28598
28599 read64 %ecx
28600 + pax_force_retaddr
28601 ret
28602 CFI_ENDPROC
28603 ENDPROC(atomic64_read_cx8)
28604
28605 +ENTRY(atomic64_read_unchecked_cx8)
28606 + CFI_STARTPROC
28607 +
28608 + read64 %ecx
28609 + pax_force_retaddr
28610 + ret
28611 + CFI_ENDPROC
28612 +ENDPROC(atomic64_read_unchecked_cx8)
28613 +
28614 ENTRY(atomic64_set_cx8)
28615 CFI_STARTPROC
28616
28617 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28618 cmpxchg8b (%esi)
28619 jne 1b
28620
28621 + pax_force_retaddr
28622 ret
28623 CFI_ENDPROC
28624 ENDPROC(atomic64_set_cx8)
28625
28626 +ENTRY(atomic64_set_unchecked_cx8)
28627 + CFI_STARTPROC
28628 +
28629 +1:
28630 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
28631 + * are atomic on 586 and newer */
28632 + cmpxchg8b (%esi)
28633 + jne 1b
28634 +
28635 + pax_force_retaddr
28636 + ret
28637 + CFI_ENDPROC
28638 +ENDPROC(atomic64_set_unchecked_cx8)
28639 +
28640 ENTRY(atomic64_xchg_cx8)
28641 CFI_STARTPROC
28642
28643 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28644 cmpxchg8b (%esi)
28645 jne 1b
28646
28647 + pax_force_retaddr
28648 ret
28649 CFI_ENDPROC
28650 ENDPROC(atomic64_xchg_cx8)
28651
28652 -.macro addsub_return func ins insc
28653 -ENTRY(atomic64_\func\()_return_cx8)
28654 +.macro addsub_return func ins insc unchecked=""
28655 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28656 CFI_STARTPROC
28657 SAVE ebp
28658 SAVE ebx
28659 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28660 movl %edx, %ecx
28661 \ins\()l %esi, %ebx
28662 \insc\()l %edi, %ecx
28663 +
28664 +.ifb \unchecked
28665 +#ifdef CONFIG_PAX_REFCOUNT
28666 + into
28667 +2:
28668 + _ASM_EXTABLE(2b, 3f)
28669 +#endif
28670 +.endif
28671 +
28672 LOCK_PREFIX
28673 cmpxchg8b (%ebp)
28674 jne 1b
28675 -
28676 -10:
28677 movl %ebx, %eax
28678 movl %ecx, %edx
28679 +
28680 +.ifb \unchecked
28681 +#ifdef CONFIG_PAX_REFCOUNT
28682 +3:
28683 +#endif
28684 +.endif
28685 +
28686 RESTORE edi
28687 RESTORE esi
28688 RESTORE ebx
28689 RESTORE ebp
28690 + pax_force_retaddr
28691 ret
28692 CFI_ENDPROC
28693 -ENDPROC(atomic64_\func\()_return_cx8)
28694 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28695 .endm
28696
28697 addsub_return add add adc
28698 addsub_return sub sub sbb
28699 +addsub_return add add adc _unchecked
28700 +addsub_return sub sub sbb _unchecked
28701
28702 -.macro incdec_return func ins insc
28703 -ENTRY(atomic64_\func\()_return_cx8)
28704 +.macro incdec_return func ins insc unchecked=""
28705 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28706 CFI_STARTPROC
28707 SAVE ebx
28708
28709 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28710 movl %edx, %ecx
28711 \ins\()l $1, %ebx
28712 \insc\()l $0, %ecx
28713 +
28714 +.ifb \unchecked
28715 +#ifdef CONFIG_PAX_REFCOUNT
28716 + into
28717 +2:
28718 + _ASM_EXTABLE(2b, 3f)
28719 +#endif
28720 +.endif
28721 +
28722 LOCK_PREFIX
28723 cmpxchg8b (%esi)
28724 jne 1b
28725
28726 -10:
28727 movl %ebx, %eax
28728 movl %ecx, %edx
28729 +
28730 +.ifb \unchecked
28731 +#ifdef CONFIG_PAX_REFCOUNT
28732 +3:
28733 +#endif
28734 +.endif
28735 +
28736 RESTORE ebx
28737 + pax_force_retaddr
28738 ret
28739 CFI_ENDPROC
28740 -ENDPROC(atomic64_\func\()_return_cx8)
28741 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28742 .endm
28743
28744 incdec_return inc add adc
28745 incdec_return dec sub sbb
28746 +incdec_return inc add adc _unchecked
28747 +incdec_return dec sub sbb _unchecked
28748
28749 ENTRY(atomic64_dec_if_positive_cx8)
28750 CFI_STARTPROC
28751 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28752 movl %edx, %ecx
28753 subl $1, %ebx
28754 sbb $0, %ecx
28755 +
28756 +#ifdef CONFIG_PAX_REFCOUNT
28757 + into
28758 +1234:
28759 + _ASM_EXTABLE(1234b, 2f)
28760 +#endif
28761 +
28762 js 2f
28763 LOCK_PREFIX
28764 cmpxchg8b (%esi)
28765 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28766 movl %ebx, %eax
28767 movl %ecx, %edx
28768 RESTORE ebx
28769 + pax_force_retaddr
28770 ret
28771 CFI_ENDPROC
28772 ENDPROC(atomic64_dec_if_positive_cx8)
28773 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28774 movl %edx, %ecx
28775 addl %ebp, %ebx
28776 adcl %edi, %ecx
28777 +
28778 +#ifdef CONFIG_PAX_REFCOUNT
28779 + into
28780 +1234:
28781 + _ASM_EXTABLE(1234b, 3f)
28782 +#endif
28783 +
28784 LOCK_PREFIX
28785 cmpxchg8b (%esi)
28786 jne 1b
28787 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28788 CFI_ADJUST_CFA_OFFSET -8
28789 RESTORE ebx
28790 RESTORE ebp
28791 + pax_force_retaddr
28792 ret
28793 4:
28794 cmpl %edx, 4(%esp)
28795 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28796 xorl %ecx, %ecx
28797 addl $1, %ebx
28798 adcl %edx, %ecx
28799 +
28800 +#ifdef CONFIG_PAX_REFCOUNT
28801 + into
28802 +1234:
28803 + _ASM_EXTABLE(1234b, 3f)
28804 +#endif
28805 +
28806 LOCK_PREFIX
28807 cmpxchg8b (%esi)
28808 jne 1b
28809 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28810 movl $1, %eax
28811 3:
28812 RESTORE ebx
28813 + pax_force_retaddr
28814 ret
28815 CFI_ENDPROC
28816 ENDPROC(atomic64_inc_not_zero_cx8)
28817 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28818 index e78b8ee..7e173a8 100644
28819 --- a/arch/x86/lib/checksum_32.S
28820 +++ b/arch/x86/lib/checksum_32.S
28821 @@ -29,7 +29,8 @@
28822 #include <asm/dwarf2.h>
28823 #include <asm/errno.h>
28824 #include <asm/asm.h>
28825 -
28826 +#include <asm/segment.h>
28827 +
28828 /*
28829 * computes a partial checksum, e.g. for TCP/UDP fragments
28830 */
28831 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28832
28833 #define ARGBASE 16
28834 #define FP 12
28835 -
28836 -ENTRY(csum_partial_copy_generic)
28837 +
28838 +ENTRY(csum_partial_copy_generic_to_user)
28839 CFI_STARTPROC
28840 +
28841 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28842 + pushl_cfi %gs
28843 + popl_cfi %es
28844 + jmp csum_partial_copy_generic
28845 +#endif
28846 +
28847 +ENTRY(csum_partial_copy_generic_from_user)
28848 +
28849 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28850 + pushl_cfi %gs
28851 + popl_cfi %ds
28852 +#endif
28853 +
28854 +ENTRY(csum_partial_copy_generic)
28855 subl $4,%esp
28856 CFI_ADJUST_CFA_OFFSET 4
28857 pushl_cfi %edi
28858 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28859 jmp 4f
28860 SRC(1: movw (%esi), %bx )
28861 addl $2, %esi
28862 -DST( movw %bx, (%edi) )
28863 +DST( movw %bx, %es:(%edi) )
28864 addl $2, %edi
28865 addw %bx, %ax
28866 adcl $0, %eax
28867 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28868 SRC(1: movl (%esi), %ebx )
28869 SRC( movl 4(%esi), %edx )
28870 adcl %ebx, %eax
28871 -DST( movl %ebx, (%edi) )
28872 +DST( movl %ebx, %es:(%edi) )
28873 adcl %edx, %eax
28874 -DST( movl %edx, 4(%edi) )
28875 +DST( movl %edx, %es:4(%edi) )
28876
28877 SRC( movl 8(%esi), %ebx )
28878 SRC( movl 12(%esi), %edx )
28879 adcl %ebx, %eax
28880 -DST( movl %ebx, 8(%edi) )
28881 +DST( movl %ebx, %es:8(%edi) )
28882 adcl %edx, %eax
28883 -DST( movl %edx, 12(%edi) )
28884 +DST( movl %edx, %es:12(%edi) )
28885
28886 SRC( movl 16(%esi), %ebx )
28887 SRC( movl 20(%esi), %edx )
28888 adcl %ebx, %eax
28889 -DST( movl %ebx, 16(%edi) )
28890 +DST( movl %ebx, %es:16(%edi) )
28891 adcl %edx, %eax
28892 -DST( movl %edx, 20(%edi) )
28893 +DST( movl %edx, %es:20(%edi) )
28894
28895 SRC( movl 24(%esi), %ebx )
28896 SRC( movl 28(%esi), %edx )
28897 adcl %ebx, %eax
28898 -DST( movl %ebx, 24(%edi) )
28899 +DST( movl %ebx, %es:24(%edi) )
28900 adcl %edx, %eax
28901 -DST( movl %edx, 28(%edi) )
28902 +DST( movl %edx, %es:28(%edi) )
28903
28904 lea 32(%esi), %esi
28905 lea 32(%edi), %edi
28906 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28907 shrl $2, %edx # This clears CF
28908 SRC(3: movl (%esi), %ebx )
28909 adcl %ebx, %eax
28910 -DST( movl %ebx, (%edi) )
28911 +DST( movl %ebx, %es:(%edi) )
28912 lea 4(%esi), %esi
28913 lea 4(%edi), %edi
28914 dec %edx
28915 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28916 jb 5f
28917 SRC( movw (%esi), %cx )
28918 leal 2(%esi), %esi
28919 -DST( movw %cx, (%edi) )
28920 +DST( movw %cx, %es:(%edi) )
28921 leal 2(%edi), %edi
28922 je 6f
28923 shll $16,%ecx
28924 SRC(5: movb (%esi), %cl )
28925 -DST( movb %cl, (%edi) )
28926 +DST( movb %cl, %es:(%edi) )
28927 6: addl %ecx, %eax
28928 adcl $0, %eax
28929 7:
28930 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28931
28932 6001:
28933 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28934 - movl $-EFAULT, (%ebx)
28935 + movl $-EFAULT, %ss:(%ebx)
28936
28937 # zero the complete destination - computing the rest
28938 # is too much work
28939 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28940
28941 6002:
28942 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28943 - movl $-EFAULT,(%ebx)
28944 + movl $-EFAULT,%ss:(%ebx)
28945 jmp 5000b
28946
28947 .previous
28948
28949 + pushl_cfi %ss
28950 + popl_cfi %ds
28951 + pushl_cfi %ss
28952 + popl_cfi %es
28953 popl_cfi %ebx
28954 CFI_RESTORE ebx
28955 popl_cfi %esi
28956 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28957 popl_cfi %ecx # equivalent to addl $4,%esp
28958 ret
28959 CFI_ENDPROC
28960 -ENDPROC(csum_partial_copy_generic)
28961 +ENDPROC(csum_partial_copy_generic_to_user)
28962
28963 #else
28964
28965 /* Version for PentiumII/PPro */
28966
28967 #define ROUND1(x) \
28968 + nop; nop; nop; \
28969 SRC(movl x(%esi), %ebx ) ; \
28970 addl %ebx, %eax ; \
28971 - DST(movl %ebx, x(%edi) ) ;
28972 + DST(movl %ebx, %es:x(%edi)) ;
28973
28974 #define ROUND(x) \
28975 + nop; nop; nop; \
28976 SRC(movl x(%esi), %ebx ) ; \
28977 adcl %ebx, %eax ; \
28978 - DST(movl %ebx, x(%edi) ) ;
28979 + DST(movl %ebx, %es:x(%edi)) ;
28980
28981 #define ARGBASE 12
28982 -
28983 -ENTRY(csum_partial_copy_generic)
28984 +
28985 +ENTRY(csum_partial_copy_generic_to_user)
28986 CFI_STARTPROC
28987 +
28988 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28989 + pushl_cfi %gs
28990 + popl_cfi %es
28991 + jmp csum_partial_copy_generic
28992 +#endif
28993 +
28994 +ENTRY(csum_partial_copy_generic_from_user)
28995 +
28996 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28997 + pushl_cfi %gs
28998 + popl_cfi %ds
28999 +#endif
29000 +
29001 +ENTRY(csum_partial_copy_generic)
29002 pushl_cfi %ebx
29003 CFI_REL_OFFSET ebx, 0
29004 pushl_cfi %edi
29005 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29006 subl %ebx, %edi
29007 lea -1(%esi),%edx
29008 andl $-32,%edx
29009 - lea 3f(%ebx,%ebx), %ebx
29010 + lea 3f(%ebx,%ebx,2), %ebx
29011 testl %esi, %esi
29012 jmp *%ebx
29013 1: addl $64,%esi
29014 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29015 jb 5f
29016 SRC( movw (%esi), %dx )
29017 leal 2(%esi), %esi
29018 -DST( movw %dx, (%edi) )
29019 +DST( movw %dx, %es:(%edi) )
29020 leal 2(%edi), %edi
29021 je 6f
29022 shll $16,%edx
29023 5:
29024 SRC( movb (%esi), %dl )
29025 -DST( movb %dl, (%edi) )
29026 +DST( movb %dl, %es:(%edi) )
29027 6: addl %edx, %eax
29028 adcl $0, %eax
29029 7:
29030 .section .fixup, "ax"
29031 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29032 - movl $-EFAULT, (%ebx)
29033 + movl $-EFAULT, %ss:(%ebx)
29034 # zero the complete destination (computing the rest is too much work)
29035 movl ARGBASE+8(%esp),%edi # dst
29036 movl ARGBASE+12(%esp),%ecx # len
29037 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29038 rep; stosb
29039 jmp 7b
29040 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29041 - movl $-EFAULT, (%ebx)
29042 + movl $-EFAULT, %ss:(%ebx)
29043 jmp 7b
29044 .previous
29045
29046 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29047 + pushl_cfi %ss
29048 + popl_cfi %ds
29049 + pushl_cfi %ss
29050 + popl_cfi %es
29051 +#endif
29052 +
29053 popl_cfi %esi
29054 CFI_RESTORE esi
29055 popl_cfi %edi
29056 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29057 CFI_RESTORE ebx
29058 ret
29059 CFI_ENDPROC
29060 -ENDPROC(csum_partial_copy_generic)
29061 +ENDPROC(csum_partial_copy_generic_to_user)
29062
29063 #undef ROUND
29064 #undef ROUND1
29065 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29066 index f2145cf..cea889d 100644
29067 --- a/arch/x86/lib/clear_page_64.S
29068 +++ b/arch/x86/lib/clear_page_64.S
29069 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29070 movl $4096/8,%ecx
29071 xorl %eax,%eax
29072 rep stosq
29073 + pax_force_retaddr
29074 ret
29075 CFI_ENDPROC
29076 ENDPROC(clear_page_c)
29077 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29078 movl $4096,%ecx
29079 xorl %eax,%eax
29080 rep stosb
29081 + pax_force_retaddr
29082 ret
29083 CFI_ENDPROC
29084 ENDPROC(clear_page_c_e)
29085 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29086 leaq 64(%rdi),%rdi
29087 jnz .Lloop
29088 nop
29089 + pax_force_retaddr
29090 ret
29091 CFI_ENDPROC
29092 .Lclear_page_end:
29093 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29094
29095 #include <asm/cpufeature.h>
29096
29097 - .section .altinstr_replacement,"ax"
29098 + .section .altinstr_replacement,"a"
29099 1: .byte 0xeb /* jmp <disp8> */
29100 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29101 2: .byte 0xeb /* jmp <disp8> */
29102 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29103 index 1e572c5..2a162cd 100644
29104 --- a/arch/x86/lib/cmpxchg16b_emu.S
29105 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29106 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29107
29108 popf
29109 mov $1, %al
29110 + pax_force_retaddr
29111 ret
29112
29113 not_same:
29114 popf
29115 xor %al,%al
29116 + pax_force_retaddr
29117 ret
29118
29119 CFI_ENDPROC
29120 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29121 index 176cca6..e0d658e 100644
29122 --- a/arch/x86/lib/copy_page_64.S
29123 +++ b/arch/x86/lib/copy_page_64.S
29124 @@ -9,6 +9,7 @@ copy_page_rep:
29125 CFI_STARTPROC
29126 movl $4096/8, %ecx
29127 rep movsq
29128 + pax_force_retaddr
29129 ret
29130 CFI_ENDPROC
29131 ENDPROC(copy_page_rep)
29132 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29133 CFI_ADJUST_CFA_OFFSET 2*8
29134 movq %rbx, (%rsp)
29135 CFI_REL_OFFSET rbx, 0
29136 - movq %r12, 1*8(%rsp)
29137 - CFI_REL_OFFSET r12, 1*8
29138 + movq %r13, 1*8(%rsp)
29139 + CFI_REL_OFFSET r13, 1*8
29140
29141 movl $(4096/64)-5, %ecx
29142 .p2align 4
29143 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29144 movq 0x8*4(%rsi), %r9
29145 movq 0x8*5(%rsi), %r10
29146 movq 0x8*6(%rsi), %r11
29147 - movq 0x8*7(%rsi), %r12
29148 + movq 0x8*7(%rsi), %r13
29149
29150 prefetcht0 5*64(%rsi)
29151
29152 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29153 movq %r9, 0x8*4(%rdi)
29154 movq %r10, 0x8*5(%rdi)
29155 movq %r11, 0x8*6(%rdi)
29156 - movq %r12, 0x8*7(%rdi)
29157 + movq %r13, 0x8*7(%rdi)
29158
29159 leaq 64 (%rsi), %rsi
29160 leaq 64 (%rdi), %rdi
29161 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29162 movq 0x8*4(%rsi), %r9
29163 movq 0x8*5(%rsi), %r10
29164 movq 0x8*6(%rsi), %r11
29165 - movq 0x8*7(%rsi), %r12
29166 + movq 0x8*7(%rsi), %r13
29167
29168 movq %rax, 0x8*0(%rdi)
29169 movq %rbx, 0x8*1(%rdi)
29170 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29171 movq %r9, 0x8*4(%rdi)
29172 movq %r10, 0x8*5(%rdi)
29173 movq %r11, 0x8*6(%rdi)
29174 - movq %r12, 0x8*7(%rdi)
29175 + movq %r13, 0x8*7(%rdi)
29176
29177 leaq 64(%rdi), %rdi
29178 leaq 64(%rsi), %rsi
29179 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29180
29181 movq (%rsp), %rbx
29182 CFI_RESTORE rbx
29183 - movq 1*8(%rsp), %r12
29184 - CFI_RESTORE r12
29185 + movq 1*8(%rsp), %r13
29186 + CFI_RESTORE r13
29187 addq $2*8, %rsp
29188 CFI_ADJUST_CFA_OFFSET -2*8
29189 + pax_force_retaddr
29190 ret
29191 .Lcopy_page_end:
29192 CFI_ENDPROC
29193 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29194
29195 #include <asm/cpufeature.h>
29196
29197 - .section .altinstr_replacement,"ax"
29198 + .section .altinstr_replacement,"a"
29199 1: .byte 0xeb /* jmp <disp8> */
29200 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29201 2:
29202 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29203 index dee945d..a84067b 100644
29204 --- a/arch/x86/lib/copy_user_64.S
29205 +++ b/arch/x86/lib/copy_user_64.S
29206 @@ -18,31 +18,7 @@
29207 #include <asm/alternative-asm.h>
29208 #include <asm/asm.h>
29209 #include <asm/smap.h>
29210 -
29211 -/*
29212 - * By placing feature2 after feature1 in altinstructions section, we logically
29213 - * implement:
29214 - * If CPU has feature2, jmp to alt2 is used
29215 - * else if CPU has feature1, jmp to alt1 is used
29216 - * else jmp to orig is used.
29217 - */
29218 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29219 -0:
29220 - .byte 0xe9 /* 32bit jump */
29221 - .long \orig-1f /* by default jump to orig */
29222 -1:
29223 - .section .altinstr_replacement,"ax"
29224 -2: .byte 0xe9 /* near jump with 32bit immediate */
29225 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29226 -3: .byte 0xe9 /* near jump with 32bit immediate */
29227 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29228 - .previous
29229 -
29230 - .section .altinstructions,"a"
29231 - altinstruction_entry 0b,2b,\feature1,5,5
29232 - altinstruction_entry 0b,3b,\feature2,5,5
29233 - .previous
29234 - .endm
29235 +#include <asm/pgtable.h>
29236
29237 .macro ALIGN_DESTINATION
29238 #ifdef FIX_ALIGNMENT
29239 @@ -70,52 +46,6 @@
29240 #endif
29241 .endm
29242
29243 -/* Standard copy_to_user with segment limit checking */
29244 -ENTRY(_copy_to_user)
29245 - CFI_STARTPROC
29246 - GET_THREAD_INFO(%rax)
29247 - movq %rdi,%rcx
29248 - addq %rdx,%rcx
29249 - jc bad_to_user
29250 - cmpq TI_addr_limit(%rax),%rcx
29251 - ja bad_to_user
29252 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29253 - copy_user_generic_unrolled,copy_user_generic_string, \
29254 - copy_user_enhanced_fast_string
29255 - CFI_ENDPROC
29256 -ENDPROC(_copy_to_user)
29257 -
29258 -/* Standard copy_from_user with segment limit checking */
29259 -ENTRY(_copy_from_user)
29260 - CFI_STARTPROC
29261 - GET_THREAD_INFO(%rax)
29262 - movq %rsi,%rcx
29263 - addq %rdx,%rcx
29264 - jc bad_from_user
29265 - cmpq TI_addr_limit(%rax),%rcx
29266 - ja bad_from_user
29267 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29268 - copy_user_generic_unrolled,copy_user_generic_string, \
29269 - copy_user_enhanced_fast_string
29270 - CFI_ENDPROC
29271 -ENDPROC(_copy_from_user)
29272 -
29273 - .section .fixup,"ax"
29274 - /* must zero dest */
29275 -ENTRY(bad_from_user)
29276 -bad_from_user:
29277 - CFI_STARTPROC
29278 - movl %edx,%ecx
29279 - xorl %eax,%eax
29280 - rep
29281 - stosb
29282 -bad_to_user:
29283 - movl %edx,%eax
29284 - ret
29285 - CFI_ENDPROC
29286 -ENDPROC(bad_from_user)
29287 - .previous
29288 -
29289 /*
29290 * copy_user_generic_unrolled - memory copy with exception handling.
29291 * This version is for CPUs like P4 that don't have efficient micro
29292 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29293 */
29294 ENTRY(copy_user_generic_unrolled)
29295 CFI_STARTPROC
29296 + ASM_PAX_OPEN_USERLAND
29297 ASM_STAC
29298 cmpl $8,%edx
29299 jb 20f /* less then 8 bytes, go to byte copy loop */
29300 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29301 jnz 21b
29302 23: xor %eax,%eax
29303 ASM_CLAC
29304 + ASM_PAX_CLOSE_USERLAND
29305 + pax_force_retaddr
29306 ret
29307
29308 .section .fixup,"ax"
29309 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29310 */
29311 ENTRY(copy_user_generic_string)
29312 CFI_STARTPROC
29313 + ASM_PAX_OPEN_USERLAND
29314 ASM_STAC
29315 cmpl $8,%edx
29316 jb 2f /* less than 8 bytes, go to byte copy loop */
29317 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29318 movsb
29319 xorl %eax,%eax
29320 ASM_CLAC
29321 + ASM_PAX_CLOSE_USERLAND
29322 + pax_force_retaddr
29323 ret
29324
29325 .section .fixup,"ax"
29326 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29327 */
29328 ENTRY(copy_user_enhanced_fast_string)
29329 CFI_STARTPROC
29330 + ASM_PAX_OPEN_USERLAND
29331 ASM_STAC
29332 movl %edx,%ecx
29333 1: rep
29334 movsb
29335 xorl %eax,%eax
29336 ASM_CLAC
29337 + ASM_PAX_CLOSE_USERLAND
29338 + pax_force_retaddr
29339 ret
29340
29341 .section .fixup,"ax"
29342 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29343 index 6a4f43c..c70fb52 100644
29344 --- a/arch/x86/lib/copy_user_nocache_64.S
29345 +++ b/arch/x86/lib/copy_user_nocache_64.S
29346 @@ -8,6 +8,7 @@
29347
29348 #include <linux/linkage.h>
29349 #include <asm/dwarf2.h>
29350 +#include <asm/alternative-asm.h>
29351
29352 #define FIX_ALIGNMENT 1
29353
29354 @@ -16,6 +17,7 @@
29355 #include <asm/thread_info.h>
29356 #include <asm/asm.h>
29357 #include <asm/smap.h>
29358 +#include <asm/pgtable.h>
29359
29360 .macro ALIGN_DESTINATION
29361 #ifdef FIX_ALIGNMENT
29362 @@ -49,6 +51,16 @@
29363 */
29364 ENTRY(__copy_user_nocache)
29365 CFI_STARTPROC
29366 +
29367 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29368 + mov pax_user_shadow_base,%rcx
29369 + cmp %rcx,%rsi
29370 + jae 1f
29371 + add %rcx,%rsi
29372 +1:
29373 +#endif
29374 +
29375 + ASM_PAX_OPEN_USERLAND
29376 ASM_STAC
29377 cmpl $8,%edx
29378 jb 20f /* less then 8 bytes, go to byte copy loop */
29379 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29380 jnz 21b
29381 23: xorl %eax,%eax
29382 ASM_CLAC
29383 + ASM_PAX_CLOSE_USERLAND
29384 sfence
29385 + pax_force_retaddr
29386 ret
29387
29388 .section .fixup,"ax"
29389 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29390 index 2419d5f..fe52d0e 100644
29391 --- a/arch/x86/lib/csum-copy_64.S
29392 +++ b/arch/x86/lib/csum-copy_64.S
29393 @@ -9,6 +9,7 @@
29394 #include <asm/dwarf2.h>
29395 #include <asm/errno.h>
29396 #include <asm/asm.h>
29397 +#include <asm/alternative-asm.h>
29398
29399 /*
29400 * Checksum copy with exception handling.
29401 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29402 CFI_ADJUST_CFA_OFFSET 7*8
29403 movq %rbx, 2*8(%rsp)
29404 CFI_REL_OFFSET rbx, 2*8
29405 - movq %r12, 3*8(%rsp)
29406 - CFI_REL_OFFSET r12, 3*8
29407 + movq %r15, 3*8(%rsp)
29408 + CFI_REL_OFFSET r15, 3*8
29409 movq %r14, 4*8(%rsp)
29410 CFI_REL_OFFSET r14, 4*8
29411 movq %r13, 5*8(%rsp)
29412 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29413 movl %edx, %ecx
29414
29415 xorl %r9d, %r9d
29416 - movq %rcx, %r12
29417 + movq %rcx, %r15
29418
29419 - shrq $6, %r12
29420 + shrq $6, %r15
29421 jz .Lhandle_tail /* < 64 */
29422
29423 clc
29424
29425 /* main loop. clear in 64 byte blocks */
29426 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29427 - /* r11: temp3, rdx: temp4, r12 loopcnt */
29428 + /* r11: temp3, rdx: temp4, r15 loopcnt */
29429 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29430 .p2align 4
29431 .Lloop:
29432 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29433 adcq %r14, %rax
29434 adcq %r13, %rax
29435
29436 - decl %r12d
29437 + decl %r15d
29438
29439 dest
29440 movq %rbx, (%rsi)
29441 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29442 .Lende:
29443 movq 2*8(%rsp), %rbx
29444 CFI_RESTORE rbx
29445 - movq 3*8(%rsp), %r12
29446 - CFI_RESTORE r12
29447 + movq 3*8(%rsp), %r15
29448 + CFI_RESTORE r15
29449 movq 4*8(%rsp), %r14
29450 CFI_RESTORE r14
29451 movq 5*8(%rsp), %r13
29452 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29453 CFI_RESTORE rbp
29454 addq $7*8, %rsp
29455 CFI_ADJUST_CFA_OFFSET -7*8
29456 + pax_force_retaddr
29457 ret
29458 CFI_RESTORE_STATE
29459
29460 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29461 index 7609e0e..b449b98 100644
29462 --- a/arch/x86/lib/csum-wrappers_64.c
29463 +++ b/arch/x86/lib/csum-wrappers_64.c
29464 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29465 len -= 2;
29466 }
29467 }
29468 + pax_open_userland();
29469 stac();
29470 - isum = csum_partial_copy_generic((__force const void *)src,
29471 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29472 dst, len, isum, errp, NULL);
29473 clac();
29474 + pax_close_userland();
29475 if (unlikely(*errp))
29476 goto out_err;
29477
29478 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29479 }
29480
29481 *errp = 0;
29482 + pax_open_userland();
29483 stac();
29484 - ret = csum_partial_copy_generic(src, (void __force *)dst,
29485 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29486 len, isum, NULL, errp);
29487 clac();
29488 + pax_close_userland();
29489 return ret;
29490 }
29491 EXPORT_SYMBOL(csum_partial_copy_to_user);
29492 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29493 index a451235..1daa956 100644
29494 --- a/arch/x86/lib/getuser.S
29495 +++ b/arch/x86/lib/getuser.S
29496 @@ -33,17 +33,40 @@
29497 #include <asm/thread_info.h>
29498 #include <asm/asm.h>
29499 #include <asm/smap.h>
29500 +#include <asm/segment.h>
29501 +#include <asm/pgtable.h>
29502 +#include <asm/alternative-asm.h>
29503 +
29504 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29505 +#define __copyuser_seg gs;
29506 +#else
29507 +#define __copyuser_seg
29508 +#endif
29509
29510 .text
29511 ENTRY(__get_user_1)
29512 CFI_STARTPROC
29513 +
29514 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29515 GET_THREAD_INFO(%_ASM_DX)
29516 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29517 jae bad_get_user
29518 ASM_STAC
29519 -1: movzbl (%_ASM_AX),%edx
29520 +
29521 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29522 + mov pax_user_shadow_base,%_ASM_DX
29523 + cmp %_ASM_DX,%_ASM_AX
29524 + jae 1234f
29525 + add %_ASM_DX,%_ASM_AX
29526 +1234:
29527 +#endif
29528 +
29529 +#endif
29530 +
29531 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
29532 xor %eax,%eax
29533 ASM_CLAC
29534 + pax_force_retaddr
29535 ret
29536 CFI_ENDPROC
29537 ENDPROC(__get_user_1)
29538 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29539 ENTRY(__get_user_2)
29540 CFI_STARTPROC
29541 add $1,%_ASM_AX
29542 +
29543 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29544 jc bad_get_user
29545 GET_THREAD_INFO(%_ASM_DX)
29546 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29547 jae bad_get_user
29548 ASM_STAC
29549 -2: movzwl -1(%_ASM_AX),%edx
29550 +
29551 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29552 + mov pax_user_shadow_base,%_ASM_DX
29553 + cmp %_ASM_DX,%_ASM_AX
29554 + jae 1234f
29555 + add %_ASM_DX,%_ASM_AX
29556 +1234:
29557 +#endif
29558 +
29559 +#endif
29560 +
29561 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29562 xor %eax,%eax
29563 ASM_CLAC
29564 + pax_force_retaddr
29565 ret
29566 CFI_ENDPROC
29567 ENDPROC(__get_user_2)
29568 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29569 ENTRY(__get_user_4)
29570 CFI_STARTPROC
29571 add $3,%_ASM_AX
29572 +
29573 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29574 jc bad_get_user
29575 GET_THREAD_INFO(%_ASM_DX)
29576 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29577 jae bad_get_user
29578 ASM_STAC
29579 -3: movl -3(%_ASM_AX),%edx
29580 +
29581 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29582 + mov pax_user_shadow_base,%_ASM_DX
29583 + cmp %_ASM_DX,%_ASM_AX
29584 + jae 1234f
29585 + add %_ASM_DX,%_ASM_AX
29586 +1234:
29587 +#endif
29588 +
29589 +#endif
29590 +
29591 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
29592 xor %eax,%eax
29593 ASM_CLAC
29594 + pax_force_retaddr
29595 ret
29596 CFI_ENDPROC
29597 ENDPROC(__get_user_4)
29598 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29599 GET_THREAD_INFO(%_ASM_DX)
29600 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29601 jae bad_get_user
29602 +
29603 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29604 + mov pax_user_shadow_base,%_ASM_DX
29605 + cmp %_ASM_DX,%_ASM_AX
29606 + jae 1234f
29607 + add %_ASM_DX,%_ASM_AX
29608 +1234:
29609 +#endif
29610 +
29611 ASM_STAC
29612 4: movq -7(%_ASM_AX),%rdx
29613 xor %eax,%eax
29614 ASM_CLAC
29615 + pax_force_retaddr
29616 ret
29617 #else
29618 add $7,%_ASM_AX
29619 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29620 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29621 jae bad_get_user_8
29622 ASM_STAC
29623 -4: movl -7(%_ASM_AX),%edx
29624 -5: movl -3(%_ASM_AX),%ecx
29625 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
29626 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29627 xor %eax,%eax
29628 ASM_CLAC
29629 + pax_force_retaddr
29630 ret
29631 #endif
29632 CFI_ENDPROC
29633 @@ -113,6 +175,7 @@ bad_get_user:
29634 xor %edx,%edx
29635 mov $(-EFAULT),%_ASM_AX
29636 ASM_CLAC
29637 + pax_force_retaddr
29638 ret
29639 CFI_ENDPROC
29640 END(bad_get_user)
29641 @@ -124,6 +187,7 @@ bad_get_user_8:
29642 xor %ecx,%ecx
29643 mov $(-EFAULT),%_ASM_AX
29644 ASM_CLAC
29645 + pax_force_retaddr
29646 ret
29647 CFI_ENDPROC
29648 END(bad_get_user_8)
29649 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29650 index 54fcffe..7be149e 100644
29651 --- a/arch/x86/lib/insn.c
29652 +++ b/arch/x86/lib/insn.c
29653 @@ -20,8 +20,10 @@
29654
29655 #ifdef __KERNEL__
29656 #include <linux/string.h>
29657 +#include <asm/pgtable_types.h>
29658 #else
29659 #include <string.h>
29660 +#define ktla_ktva(addr) addr
29661 #endif
29662 #include <asm/inat.h>
29663 #include <asm/insn.h>
29664 @@ -53,8 +55,8 @@
29665 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29666 {
29667 memset(insn, 0, sizeof(*insn));
29668 - insn->kaddr = kaddr;
29669 - insn->next_byte = kaddr;
29670 + insn->kaddr = ktla_ktva(kaddr);
29671 + insn->next_byte = ktla_ktva(kaddr);
29672 insn->x86_64 = x86_64 ? 1 : 0;
29673 insn->opnd_bytes = 4;
29674 if (x86_64)
29675 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29676 index 05a95e7..326f2fa 100644
29677 --- a/arch/x86/lib/iomap_copy_64.S
29678 +++ b/arch/x86/lib/iomap_copy_64.S
29679 @@ -17,6 +17,7 @@
29680
29681 #include <linux/linkage.h>
29682 #include <asm/dwarf2.h>
29683 +#include <asm/alternative-asm.h>
29684
29685 /*
29686 * override generic version in lib/iomap_copy.c
29687 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29688 CFI_STARTPROC
29689 movl %edx,%ecx
29690 rep movsd
29691 + pax_force_retaddr
29692 ret
29693 CFI_ENDPROC
29694 ENDPROC(__iowrite32_copy)
29695 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29696 index 56313a3..0db417e 100644
29697 --- a/arch/x86/lib/memcpy_64.S
29698 +++ b/arch/x86/lib/memcpy_64.S
29699 @@ -24,7 +24,7 @@
29700 * This gets patched over the unrolled variant (below) via the
29701 * alternative instructions framework:
29702 */
29703 - .section .altinstr_replacement, "ax", @progbits
29704 + .section .altinstr_replacement, "a", @progbits
29705 .Lmemcpy_c:
29706 movq %rdi, %rax
29707 movq %rdx, %rcx
29708 @@ -33,6 +33,7 @@
29709 rep movsq
29710 movl %edx, %ecx
29711 rep movsb
29712 + pax_force_retaddr
29713 ret
29714 .Lmemcpy_e:
29715 .previous
29716 @@ -44,11 +45,12 @@
29717 * This gets patched over the unrolled variant (below) via the
29718 * alternative instructions framework:
29719 */
29720 - .section .altinstr_replacement, "ax", @progbits
29721 + .section .altinstr_replacement, "a", @progbits
29722 .Lmemcpy_c_e:
29723 movq %rdi, %rax
29724 movq %rdx, %rcx
29725 rep movsb
29726 + pax_force_retaddr
29727 ret
29728 .Lmemcpy_e_e:
29729 .previous
29730 @@ -136,6 +138,7 @@ ENTRY(memcpy)
29731 movq %r9, 1*8(%rdi)
29732 movq %r10, -2*8(%rdi, %rdx)
29733 movq %r11, -1*8(%rdi, %rdx)
29734 + pax_force_retaddr
29735 retq
29736 .p2align 4
29737 .Lless_16bytes:
29738 @@ -148,6 +151,7 @@ ENTRY(memcpy)
29739 movq -1*8(%rsi, %rdx), %r9
29740 movq %r8, 0*8(%rdi)
29741 movq %r9, -1*8(%rdi, %rdx)
29742 + pax_force_retaddr
29743 retq
29744 .p2align 4
29745 .Lless_8bytes:
29746 @@ -161,6 +165,7 @@ ENTRY(memcpy)
29747 movl -4(%rsi, %rdx), %r8d
29748 movl %ecx, (%rdi)
29749 movl %r8d, -4(%rdi, %rdx)
29750 + pax_force_retaddr
29751 retq
29752 .p2align 4
29753 .Lless_3bytes:
29754 @@ -179,6 +184,7 @@ ENTRY(memcpy)
29755 movb %cl, (%rdi)
29756
29757 .Lend:
29758 + pax_force_retaddr
29759 retq
29760 CFI_ENDPROC
29761 ENDPROC(memcpy)
29762 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29763 index 65268a6..dd1de11 100644
29764 --- a/arch/x86/lib/memmove_64.S
29765 +++ b/arch/x86/lib/memmove_64.S
29766 @@ -202,14 +202,16 @@ ENTRY(memmove)
29767 movb (%rsi), %r11b
29768 movb %r11b, (%rdi)
29769 13:
29770 + pax_force_retaddr
29771 retq
29772 CFI_ENDPROC
29773
29774 - .section .altinstr_replacement,"ax"
29775 + .section .altinstr_replacement,"a"
29776 .Lmemmove_begin_forward_efs:
29777 /* Forward moving data. */
29778 movq %rdx, %rcx
29779 rep movsb
29780 + pax_force_retaddr
29781 retq
29782 .Lmemmove_end_forward_efs:
29783 .previous
29784 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29785 index 2dcb380..2eb79fe 100644
29786 --- a/arch/x86/lib/memset_64.S
29787 +++ b/arch/x86/lib/memset_64.S
29788 @@ -16,7 +16,7 @@
29789 *
29790 * rax original destination
29791 */
29792 - .section .altinstr_replacement, "ax", @progbits
29793 + .section .altinstr_replacement, "a", @progbits
29794 .Lmemset_c:
29795 movq %rdi,%r9
29796 movq %rdx,%rcx
29797 @@ -30,6 +30,7 @@
29798 movl %edx,%ecx
29799 rep stosb
29800 movq %r9,%rax
29801 + pax_force_retaddr
29802 ret
29803 .Lmemset_e:
29804 .previous
29805 @@ -45,13 +46,14 @@
29806 *
29807 * rax original destination
29808 */
29809 - .section .altinstr_replacement, "ax", @progbits
29810 + .section .altinstr_replacement, "a", @progbits
29811 .Lmemset_c_e:
29812 movq %rdi,%r9
29813 movb %sil,%al
29814 movq %rdx,%rcx
29815 rep stosb
29816 movq %r9,%rax
29817 + pax_force_retaddr
29818 ret
29819 .Lmemset_e_e:
29820 .previous
29821 @@ -118,6 +120,7 @@ ENTRY(__memset)
29822
29823 .Lende:
29824 movq %r10,%rax
29825 + pax_force_retaddr
29826 ret
29827
29828 CFI_RESTORE_STATE
29829 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29830 index c9f2d9b..e7fd2c0 100644
29831 --- a/arch/x86/lib/mmx_32.c
29832 +++ b/arch/x86/lib/mmx_32.c
29833 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29834 {
29835 void *p;
29836 int i;
29837 + unsigned long cr0;
29838
29839 if (unlikely(in_interrupt()))
29840 return __memcpy(to, from, len);
29841 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29842 kernel_fpu_begin();
29843
29844 __asm__ __volatile__ (
29845 - "1: prefetch (%0)\n" /* This set is 28 bytes */
29846 - " prefetch 64(%0)\n"
29847 - " prefetch 128(%0)\n"
29848 - " prefetch 192(%0)\n"
29849 - " prefetch 256(%0)\n"
29850 + "1: prefetch (%1)\n" /* This set is 28 bytes */
29851 + " prefetch 64(%1)\n"
29852 + " prefetch 128(%1)\n"
29853 + " prefetch 192(%1)\n"
29854 + " prefetch 256(%1)\n"
29855 "2: \n"
29856 ".section .fixup, \"ax\"\n"
29857 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29858 + "3: \n"
29859 +
29860 +#ifdef CONFIG_PAX_KERNEXEC
29861 + " movl %%cr0, %0\n"
29862 + " movl %0, %%eax\n"
29863 + " andl $0xFFFEFFFF, %%eax\n"
29864 + " movl %%eax, %%cr0\n"
29865 +#endif
29866 +
29867 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29868 +
29869 +#ifdef CONFIG_PAX_KERNEXEC
29870 + " movl %0, %%cr0\n"
29871 +#endif
29872 +
29873 " jmp 2b\n"
29874 ".previous\n"
29875 _ASM_EXTABLE(1b, 3b)
29876 - : : "r" (from));
29877 + : "=&r" (cr0) : "r" (from) : "ax");
29878
29879 for ( ; i > 5; i--) {
29880 __asm__ __volatile__ (
29881 - "1: prefetch 320(%0)\n"
29882 - "2: movq (%0), %%mm0\n"
29883 - " movq 8(%0), %%mm1\n"
29884 - " movq 16(%0), %%mm2\n"
29885 - " movq 24(%0), %%mm3\n"
29886 - " movq %%mm0, (%1)\n"
29887 - " movq %%mm1, 8(%1)\n"
29888 - " movq %%mm2, 16(%1)\n"
29889 - " movq %%mm3, 24(%1)\n"
29890 - " movq 32(%0), %%mm0\n"
29891 - " movq 40(%0), %%mm1\n"
29892 - " movq 48(%0), %%mm2\n"
29893 - " movq 56(%0), %%mm3\n"
29894 - " movq %%mm0, 32(%1)\n"
29895 - " movq %%mm1, 40(%1)\n"
29896 - " movq %%mm2, 48(%1)\n"
29897 - " movq %%mm3, 56(%1)\n"
29898 + "1: prefetch 320(%1)\n"
29899 + "2: movq (%1), %%mm0\n"
29900 + " movq 8(%1), %%mm1\n"
29901 + " movq 16(%1), %%mm2\n"
29902 + " movq 24(%1), %%mm3\n"
29903 + " movq %%mm0, (%2)\n"
29904 + " movq %%mm1, 8(%2)\n"
29905 + " movq %%mm2, 16(%2)\n"
29906 + " movq %%mm3, 24(%2)\n"
29907 + " movq 32(%1), %%mm0\n"
29908 + " movq 40(%1), %%mm1\n"
29909 + " movq 48(%1), %%mm2\n"
29910 + " movq 56(%1), %%mm3\n"
29911 + " movq %%mm0, 32(%2)\n"
29912 + " movq %%mm1, 40(%2)\n"
29913 + " movq %%mm2, 48(%2)\n"
29914 + " movq %%mm3, 56(%2)\n"
29915 ".section .fixup, \"ax\"\n"
29916 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29917 + "3:\n"
29918 +
29919 +#ifdef CONFIG_PAX_KERNEXEC
29920 + " movl %%cr0, %0\n"
29921 + " movl %0, %%eax\n"
29922 + " andl $0xFFFEFFFF, %%eax\n"
29923 + " movl %%eax, %%cr0\n"
29924 +#endif
29925 +
29926 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29927 +
29928 +#ifdef CONFIG_PAX_KERNEXEC
29929 + " movl %0, %%cr0\n"
29930 +#endif
29931 +
29932 " jmp 2b\n"
29933 ".previous\n"
29934 _ASM_EXTABLE(1b, 3b)
29935 - : : "r" (from), "r" (to) : "memory");
29936 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29937
29938 from += 64;
29939 to += 64;
29940 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29941 static void fast_copy_page(void *to, void *from)
29942 {
29943 int i;
29944 + unsigned long cr0;
29945
29946 kernel_fpu_begin();
29947
29948 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29949 * but that is for later. -AV
29950 */
29951 __asm__ __volatile__(
29952 - "1: prefetch (%0)\n"
29953 - " prefetch 64(%0)\n"
29954 - " prefetch 128(%0)\n"
29955 - " prefetch 192(%0)\n"
29956 - " prefetch 256(%0)\n"
29957 + "1: prefetch (%1)\n"
29958 + " prefetch 64(%1)\n"
29959 + " prefetch 128(%1)\n"
29960 + " prefetch 192(%1)\n"
29961 + " prefetch 256(%1)\n"
29962 "2: \n"
29963 ".section .fixup, \"ax\"\n"
29964 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29965 + "3: \n"
29966 +
29967 +#ifdef CONFIG_PAX_KERNEXEC
29968 + " movl %%cr0, %0\n"
29969 + " movl %0, %%eax\n"
29970 + " andl $0xFFFEFFFF, %%eax\n"
29971 + " movl %%eax, %%cr0\n"
29972 +#endif
29973 +
29974 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29975 +
29976 +#ifdef CONFIG_PAX_KERNEXEC
29977 + " movl %0, %%cr0\n"
29978 +#endif
29979 +
29980 " jmp 2b\n"
29981 ".previous\n"
29982 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
29983 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29984
29985 for (i = 0; i < (4096-320)/64; i++) {
29986 __asm__ __volatile__ (
29987 - "1: prefetch 320(%0)\n"
29988 - "2: movq (%0), %%mm0\n"
29989 - " movntq %%mm0, (%1)\n"
29990 - " movq 8(%0), %%mm1\n"
29991 - " movntq %%mm1, 8(%1)\n"
29992 - " movq 16(%0), %%mm2\n"
29993 - " movntq %%mm2, 16(%1)\n"
29994 - " movq 24(%0), %%mm3\n"
29995 - " movntq %%mm3, 24(%1)\n"
29996 - " movq 32(%0), %%mm4\n"
29997 - " movntq %%mm4, 32(%1)\n"
29998 - " movq 40(%0), %%mm5\n"
29999 - " movntq %%mm5, 40(%1)\n"
30000 - " movq 48(%0), %%mm6\n"
30001 - " movntq %%mm6, 48(%1)\n"
30002 - " movq 56(%0), %%mm7\n"
30003 - " movntq %%mm7, 56(%1)\n"
30004 + "1: prefetch 320(%1)\n"
30005 + "2: movq (%1), %%mm0\n"
30006 + " movntq %%mm0, (%2)\n"
30007 + " movq 8(%1), %%mm1\n"
30008 + " movntq %%mm1, 8(%2)\n"
30009 + " movq 16(%1), %%mm2\n"
30010 + " movntq %%mm2, 16(%2)\n"
30011 + " movq 24(%1), %%mm3\n"
30012 + " movntq %%mm3, 24(%2)\n"
30013 + " movq 32(%1), %%mm4\n"
30014 + " movntq %%mm4, 32(%2)\n"
30015 + " movq 40(%1), %%mm5\n"
30016 + " movntq %%mm5, 40(%2)\n"
30017 + " movq 48(%1), %%mm6\n"
30018 + " movntq %%mm6, 48(%2)\n"
30019 + " movq 56(%1), %%mm7\n"
30020 + " movntq %%mm7, 56(%2)\n"
30021 ".section .fixup, \"ax\"\n"
30022 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30023 + "3:\n"
30024 +
30025 +#ifdef CONFIG_PAX_KERNEXEC
30026 + " movl %%cr0, %0\n"
30027 + " movl %0, %%eax\n"
30028 + " andl $0xFFFEFFFF, %%eax\n"
30029 + " movl %%eax, %%cr0\n"
30030 +#endif
30031 +
30032 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30033 +
30034 +#ifdef CONFIG_PAX_KERNEXEC
30035 + " movl %0, %%cr0\n"
30036 +#endif
30037 +
30038 " jmp 2b\n"
30039 ".previous\n"
30040 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30041 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30042
30043 from += 64;
30044 to += 64;
30045 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30046 static void fast_copy_page(void *to, void *from)
30047 {
30048 int i;
30049 + unsigned long cr0;
30050
30051 kernel_fpu_begin();
30052
30053 __asm__ __volatile__ (
30054 - "1: prefetch (%0)\n"
30055 - " prefetch 64(%0)\n"
30056 - " prefetch 128(%0)\n"
30057 - " prefetch 192(%0)\n"
30058 - " prefetch 256(%0)\n"
30059 + "1: prefetch (%1)\n"
30060 + " prefetch 64(%1)\n"
30061 + " prefetch 128(%1)\n"
30062 + " prefetch 192(%1)\n"
30063 + " prefetch 256(%1)\n"
30064 "2: \n"
30065 ".section .fixup, \"ax\"\n"
30066 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30067 + "3: \n"
30068 +
30069 +#ifdef CONFIG_PAX_KERNEXEC
30070 + " movl %%cr0, %0\n"
30071 + " movl %0, %%eax\n"
30072 + " andl $0xFFFEFFFF, %%eax\n"
30073 + " movl %%eax, %%cr0\n"
30074 +#endif
30075 +
30076 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30077 +
30078 +#ifdef CONFIG_PAX_KERNEXEC
30079 + " movl %0, %%cr0\n"
30080 +#endif
30081 +
30082 " jmp 2b\n"
30083 ".previous\n"
30084 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30085 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30086
30087 for (i = 0; i < 4096/64; i++) {
30088 __asm__ __volatile__ (
30089 - "1: prefetch 320(%0)\n"
30090 - "2: movq (%0), %%mm0\n"
30091 - " movq 8(%0), %%mm1\n"
30092 - " movq 16(%0), %%mm2\n"
30093 - " movq 24(%0), %%mm3\n"
30094 - " movq %%mm0, (%1)\n"
30095 - " movq %%mm1, 8(%1)\n"
30096 - " movq %%mm2, 16(%1)\n"
30097 - " movq %%mm3, 24(%1)\n"
30098 - " movq 32(%0), %%mm0\n"
30099 - " movq 40(%0), %%mm1\n"
30100 - " movq 48(%0), %%mm2\n"
30101 - " movq 56(%0), %%mm3\n"
30102 - " movq %%mm0, 32(%1)\n"
30103 - " movq %%mm1, 40(%1)\n"
30104 - " movq %%mm2, 48(%1)\n"
30105 - " movq %%mm3, 56(%1)\n"
30106 + "1: prefetch 320(%1)\n"
30107 + "2: movq (%1), %%mm0\n"
30108 + " movq 8(%1), %%mm1\n"
30109 + " movq 16(%1), %%mm2\n"
30110 + " movq 24(%1), %%mm3\n"
30111 + " movq %%mm0, (%2)\n"
30112 + " movq %%mm1, 8(%2)\n"
30113 + " movq %%mm2, 16(%2)\n"
30114 + " movq %%mm3, 24(%2)\n"
30115 + " movq 32(%1), %%mm0\n"
30116 + " movq 40(%1), %%mm1\n"
30117 + " movq 48(%1), %%mm2\n"
30118 + " movq 56(%1), %%mm3\n"
30119 + " movq %%mm0, 32(%2)\n"
30120 + " movq %%mm1, 40(%2)\n"
30121 + " movq %%mm2, 48(%2)\n"
30122 + " movq %%mm3, 56(%2)\n"
30123 ".section .fixup, \"ax\"\n"
30124 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30125 + "3:\n"
30126 +
30127 +#ifdef CONFIG_PAX_KERNEXEC
30128 + " movl %%cr0, %0\n"
30129 + " movl %0, %%eax\n"
30130 + " andl $0xFFFEFFFF, %%eax\n"
30131 + " movl %%eax, %%cr0\n"
30132 +#endif
30133 +
30134 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30135 +
30136 +#ifdef CONFIG_PAX_KERNEXEC
30137 + " movl %0, %%cr0\n"
30138 +#endif
30139 +
30140 " jmp 2b\n"
30141 ".previous\n"
30142 _ASM_EXTABLE(1b, 3b)
30143 - : : "r" (from), "r" (to) : "memory");
30144 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30145
30146 from += 64;
30147 to += 64;
30148 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30149 index f6d13ee..d789440 100644
30150 --- a/arch/x86/lib/msr-reg.S
30151 +++ b/arch/x86/lib/msr-reg.S
30152 @@ -3,6 +3,7 @@
30153 #include <asm/dwarf2.h>
30154 #include <asm/asm.h>
30155 #include <asm/msr.h>
30156 +#include <asm/alternative-asm.h>
30157
30158 #ifdef CONFIG_X86_64
30159 /*
30160 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30161 movl %edi, 28(%r10)
30162 popq_cfi %rbp
30163 popq_cfi %rbx
30164 + pax_force_retaddr
30165 ret
30166 3:
30167 CFI_RESTORE_STATE
30168 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30169 index fc6ba17..d4d989d 100644
30170 --- a/arch/x86/lib/putuser.S
30171 +++ b/arch/x86/lib/putuser.S
30172 @@ -16,7 +16,9 @@
30173 #include <asm/errno.h>
30174 #include <asm/asm.h>
30175 #include <asm/smap.h>
30176 -
30177 +#include <asm/segment.h>
30178 +#include <asm/pgtable.h>
30179 +#include <asm/alternative-asm.h>
30180
30181 /*
30182 * __put_user_X
30183 @@ -30,57 +32,125 @@
30184 * as they get called from within inline assembly.
30185 */
30186
30187 -#define ENTER CFI_STARTPROC ; \
30188 - GET_THREAD_INFO(%_ASM_BX)
30189 -#define EXIT ASM_CLAC ; \
30190 - ret ; \
30191 +#define ENTER CFI_STARTPROC
30192 +#define EXIT ASM_CLAC ; \
30193 + pax_force_retaddr ; \
30194 + ret ; \
30195 CFI_ENDPROC
30196
30197 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30198 +#define _DEST %_ASM_CX,%_ASM_BX
30199 +#else
30200 +#define _DEST %_ASM_CX
30201 +#endif
30202 +
30203 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30204 +#define __copyuser_seg gs;
30205 +#else
30206 +#define __copyuser_seg
30207 +#endif
30208 +
30209 .text
30210 ENTRY(__put_user_1)
30211 ENTER
30212 +
30213 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30214 + GET_THREAD_INFO(%_ASM_BX)
30215 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30216 jae bad_put_user
30217 ASM_STAC
30218 -1: movb %al,(%_ASM_CX)
30219 +
30220 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30221 + mov pax_user_shadow_base,%_ASM_BX
30222 + cmp %_ASM_BX,%_ASM_CX
30223 + jb 1234f
30224 + xor %ebx,%ebx
30225 +1234:
30226 +#endif
30227 +
30228 +#endif
30229 +
30230 +1: __copyuser_seg movb %al,(_DEST)
30231 xor %eax,%eax
30232 EXIT
30233 ENDPROC(__put_user_1)
30234
30235 ENTRY(__put_user_2)
30236 ENTER
30237 +
30238 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30239 + GET_THREAD_INFO(%_ASM_BX)
30240 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30241 sub $1,%_ASM_BX
30242 cmp %_ASM_BX,%_ASM_CX
30243 jae bad_put_user
30244 ASM_STAC
30245 -2: movw %ax,(%_ASM_CX)
30246 +
30247 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30248 + mov pax_user_shadow_base,%_ASM_BX
30249 + cmp %_ASM_BX,%_ASM_CX
30250 + jb 1234f
30251 + xor %ebx,%ebx
30252 +1234:
30253 +#endif
30254 +
30255 +#endif
30256 +
30257 +2: __copyuser_seg movw %ax,(_DEST)
30258 xor %eax,%eax
30259 EXIT
30260 ENDPROC(__put_user_2)
30261
30262 ENTRY(__put_user_4)
30263 ENTER
30264 +
30265 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30266 + GET_THREAD_INFO(%_ASM_BX)
30267 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30268 sub $3,%_ASM_BX
30269 cmp %_ASM_BX,%_ASM_CX
30270 jae bad_put_user
30271 ASM_STAC
30272 -3: movl %eax,(%_ASM_CX)
30273 +
30274 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30275 + mov pax_user_shadow_base,%_ASM_BX
30276 + cmp %_ASM_BX,%_ASM_CX
30277 + jb 1234f
30278 + xor %ebx,%ebx
30279 +1234:
30280 +#endif
30281 +
30282 +#endif
30283 +
30284 +3: __copyuser_seg movl %eax,(_DEST)
30285 xor %eax,%eax
30286 EXIT
30287 ENDPROC(__put_user_4)
30288
30289 ENTRY(__put_user_8)
30290 ENTER
30291 +
30292 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30293 + GET_THREAD_INFO(%_ASM_BX)
30294 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30295 sub $7,%_ASM_BX
30296 cmp %_ASM_BX,%_ASM_CX
30297 jae bad_put_user
30298 ASM_STAC
30299 -4: mov %_ASM_AX,(%_ASM_CX)
30300 +
30301 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30302 + mov pax_user_shadow_base,%_ASM_BX
30303 + cmp %_ASM_BX,%_ASM_CX
30304 + jb 1234f
30305 + xor %ebx,%ebx
30306 +1234:
30307 +#endif
30308 +
30309 +#endif
30310 +
30311 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
30312 #ifdef CONFIG_X86_32
30313 -5: movl %edx,4(%_ASM_CX)
30314 +5: __copyuser_seg movl %edx,4(_DEST)
30315 #endif
30316 xor %eax,%eax
30317 EXIT
30318 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30319 index 1cad221..de671ee 100644
30320 --- a/arch/x86/lib/rwlock.S
30321 +++ b/arch/x86/lib/rwlock.S
30322 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30323 FRAME
30324 0: LOCK_PREFIX
30325 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30326 +
30327 +#ifdef CONFIG_PAX_REFCOUNT
30328 + jno 1234f
30329 + LOCK_PREFIX
30330 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30331 + int $4
30332 +1234:
30333 + _ASM_EXTABLE(1234b, 1234b)
30334 +#endif
30335 +
30336 1: rep; nop
30337 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30338 jne 1b
30339 LOCK_PREFIX
30340 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30341 +
30342 +#ifdef CONFIG_PAX_REFCOUNT
30343 + jno 1234f
30344 + LOCK_PREFIX
30345 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30346 + int $4
30347 +1234:
30348 + _ASM_EXTABLE(1234b, 1234b)
30349 +#endif
30350 +
30351 jnz 0b
30352 ENDFRAME
30353 + pax_force_retaddr
30354 ret
30355 CFI_ENDPROC
30356 END(__write_lock_failed)
30357 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30358 FRAME
30359 0: LOCK_PREFIX
30360 READ_LOCK_SIZE(inc) (%__lock_ptr)
30361 +
30362 +#ifdef CONFIG_PAX_REFCOUNT
30363 + jno 1234f
30364 + LOCK_PREFIX
30365 + READ_LOCK_SIZE(dec) (%__lock_ptr)
30366 + int $4
30367 +1234:
30368 + _ASM_EXTABLE(1234b, 1234b)
30369 +#endif
30370 +
30371 1: rep; nop
30372 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30373 js 1b
30374 LOCK_PREFIX
30375 READ_LOCK_SIZE(dec) (%__lock_ptr)
30376 +
30377 +#ifdef CONFIG_PAX_REFCOUNT
30378 + jno 1234f
30379 + LOCK_PREFIX
30380 + READ_LOCK_SIZE(inc) (%__lock_ptr)
30381 + int $4
30382 +1234:
30383 + _ASM_EXTABLE(1234b, 1234b)
30384 +#endif
30385 +
30386 js 0b
30387 ENDFRAME
30388 + pax_force_retaddr
30389 ret
30390 CFI_ENDPROC
30391 END(__read_lock_failed)
30392 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30393 index 5dff5f0..cadebf4 100644
30394 --- a/arch/x86/lib/rwsem.S
30395 +++ b/arch/x86/lib/rwsem.S
30396 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30397 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30398 CFI_RESTORE __ASM_REG(dx)
30399 restore_common_regs
30400 + pax_force_retaddr
30401 ret
30402 CFI_ENDPROC
30403 ENDPROC(call_rwsem_down_read_failed)
30404 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30405 movq %rax,%rdi
30406 call rwsem_down_write_failed
30407 restore_common_regs
30408 + pax_force_retaddr
30409 ret
30410 CFI_ENDPROC
30411 ENDPROC(call_rwsem_down_write_failed)
30412 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30413 movq %rax,%rdi
30414 call rwsem_wake
30415 restore_common_regs
30416 -1: ret
30417 +1: pax_force_retaddr
30418 + ret
30419 CFI_ENDPROC
30420 ENDPROC(call_rwsem_wake)
30421
30422 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30423 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30424 CFI_RESTORE __ASM_REG(dx)
30425 restore_common_regs
30426 + pax_force_retaddr
30427 ret
30428 CFI_ENDPROC
30429 ENDPROC(call_rwsem_downgrade_wake)
30430 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30431 index a63efd6..8149fbe 100644
30432 --- a/arch/x86/lib/thunk_64.S
30433 +++ b/arch/x86/lib/thunk_64.S
30434 @@ -8,6 +8,7 @@
30435 #include <linux/linkage.h>
30436 #include <asm/dwarf2.h>
30437 #include <asm/calling.h>
30438 +#include <asm/alternative-asm.h>
30439
30440 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30441 .macro THUNK name, func, put_ret_addr_in_rdi=0
30442 @@ -15,11 +16,11 @@
30443 \name:
30444 CFI_STARTPROC
30445
30446 - /* this one pushes 9 elems, the next one would be %rIP */
30447 - SAVE_ARGS
30448 + /* this one pushes 15+1 elems, the next one would be %rIP */
30449 + SAVE_ARGS 8
30450
30451 .if \put_ret_addr_in_rdi
30452 - movq_cfi_restore 9*8, rdi
30453 + movq_cfi_restore RIP, rdi
30454 .endif
30455
30456 call \func
30457 @@ -38,8 +39,9 @@
30458
30459 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30460 CFI_STARTPROC
30461 - SAVE_ARGS
30462 + SAVE_ARGS 8
30463 restore:
30464 - RESTORE_ARGS
30465 + RESTORE_ARGS 1,8
30466 + pax_force_retaddr
30467 ret
30468 CFI_ENDPROC
30469 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30470 index e2f5e21..4b22130 100644
30471 --- a/arch/x86/lib/usercopy_32.c
30472 +++ b/arch/x86/lib/usercopy_32.c
30473 @@ -42,11 +42,13 @@ do { \
30474 int __d0; \
30475 might_fault(); \
30476 __asm__ __volatile__( \
30477 + __COPYUSER_SET_ES \
30478 ASM_STAC "\n" \
30479 "0: rep; stosl\n" \
30480 " movl %2,%0\n" \
30481 "1: rep; stosb\n" \
30482 "2: " ASM_CLAC "\n" \
30483 + __COPYUSER_RESTORE_ES \
30484 ".section .fixup,\"ax\"\n" \
30485 "3: lea 0(%2,%0,4),%0\n" \
30486 " jmp 2b\n" \
30487 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30488
30489 #ifdef CONFIG_X86_INTEL_USERCOPY
30490 static unsigned long
30491 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
30492 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30493 {
30494 int d0, d1;
30495 __asm__ __volatile__(
30496 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30497 " .align 2,0x90\n"
30498 "3: movl 0(%4), %%eax\n"
30499 "4: movl 4(%4), %%edx\n"
30500 - "5: movl %%eax, 0(%3)\n"
30501 - "6: movl %%edx, 4(%3)\n"
30502 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30503 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30504 "7: movl 8(%4), %%eax\n"
30505 "8: movl 12(%4),%%edx\n"
30506 - "9: movl %%eax, 8(%3)\n"
30507 - "10: movl %%edx, 12(%3)\n"
30508 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30509 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30510 "11: movl 16(%4), %%eax\n"
30511 "12: movl 20(%4), %%edx\n"
30512 - "13: movl %%eax, 16(%3)\n"
30513 - "14: movl %%edx, 20(%3)\n"
30514 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30515 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30516 "15: movl 24(%4), %%eax\n"
30517 "16: movl 28(%4), %%edx\n"
30518 - "17: movl %%eax, 24(%3)\n"
30519 - "18: movl %%edx, 28(%3)\n"
30520 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30521 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30522 "19: movl 32(%4), %%eax\n"
30523 "20: movl 36(%4), %%edx\n"
30524 - "21: movl %%eax, 32(%3)\n"
30525 - "22: movl %%edx, 36(%3)\n"
30526 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30527 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30528 "23: movl 40(%4), %%eax\n"
30529 "24: movl 44(%4), %%edx\n"
30530 - "25: movl %%eax, 40(%3)\n"
30531 - "26: movl %%edx, 44(%3)\n"
30532 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30533 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30534 "27: movl 48(%4), %%eax\n"
30535 "28: movl 52(%4), %%edx\n"
30536 - "29: movl %%eax, 48(%3)\n"
30537 - "30: movl %%edx, 52(%3)\n"
30538 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30539 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30540 "31: movl 56(%4), %%eax\n"
30541 "32: movl 60(%4), %%edx\n"
30542 - "33: movl %%eax, 56(%3)\n"
30543 - "34: movl %%edx, 60(%3)\n"
30544 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30545 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30546 " addl $-64, %0\n"
30547 " addl $64, %4\n"
30548 " addl $64, %3\n"
30549 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30550 " shrl $2, %0\n"
30551 " andl $3, %%eax\n"
30552 " cld\n"
30553 + __COPYUSER_SET_ES
30554 "99: rep; movsl\n"
30555 "36: movl %%eax, %0\n"
30556 "37: rep; movsb\n"
30557 "100:\n"
30558 + __COPYUSER_RESTORE_ES
30559 + ".section .fixup,\"ax\"\n"
30560 + "101: lea 0(%%eax,%0,4),%0\n"
30561 + " jmp 100b\n"
30562 + ".previous\n"
30563 + _ASM_EXTABLE(1b,100b)
30564 + _ASM_EXTABLE(2b,100b)
30565 + _ASM_EXTABLE(3b,100b)
30566 + _ASM_EXTABLE(4b,100b)
30567 + _ASM_EXTABLE(5b,100b)
30568 + _ASM_EXTABLE(6b,100b)
30569 + _ASM_EXTABLE(7b,100b)
30570 + _ASM_EXTABLE(8b,100b)
30571 + _ASM_EXTABLE(9b,100b)
30572 + _ASM_EXTABLE(10b,100b)
30573 + _ASM_EXTABLE(11b,100b)
30574 + _ASM_EXTABLE(12b,100b)
30575 + _ASM_EXTABLE(13b,100b)
30576 + _ASM_EXTABLE(14b,100b)
30577 + _ASM_EXTABLE(15b,100b)
30578 + _ASM_EXTABLE(16b,100b)
30579 + _ASM_EXTABLE(17b,100b)
30580 + _ASM_EXTABLE(18b,100b)
30581 + _ASM_EXTABLE(19b,100b)
30582 + _ASM_EXTABLE(20b,100b)
30583 + _ASM_EXTABLE(21b,100b)
30584 + _ASM_EXTABLE(22b,100b)
30585 + _ASM_EXTABLE(23b,100b)
30586 + _ASM_EXTABLE(24b,100b)
30587 + _ASM_EXTABLE(25b,100b)
30588 + _ASM_EXTABLE(26b,100b)
30589 + _ASM_EXTABLE(27b,100b)
30590 + _ASM_EXTABLE(28b,100b)
30591 + _ASM_EXTABLE(29b,100b)
30592 + _ASM_EXTABLE(30b,100b)
30593 + _ASM_EXTABLE(31b,100b)
30594 + _ASM_EXTABLE(32b,100b)
30595 + _ASM_EXTABLE(33b,100b)
30596 + _ASM_EXTABLE(34b,100b)
30597 + _ASM_EXTABLE(35b,100b)
30598 + _ASM_EXTABLE(36b,100b)
30599 + _ASM_EXTABLE(37b,100b)
30600 + _ASM_EXTABLE(99b,101b)
30601 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
30602 + : "1"(to), "2"(from), "0"(size)
30603 + : "eax", "edx", "memory");
30604 + return size;
30605 +}
30606 +
30607 +static unsigned long
30608 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30609 +{
30610 + int d0, d1;
30611 + __asm__ __volatile__(
30612 + " .align 2,0x90\n"
30613 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30614 + " cmpl $67, %0\n"
30615 + " jbe 3f\n"
30616 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30617 + " .align 2,0x90\n"
30618 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30619 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30620 + "5: movl %%eax, 0(%3)\n"
30621 + "6: movl %%edx, 4(%3)\n"
30622 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30623 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30624 + "9: movl %%eax, 8(%3)\n"
30625 + "10: movl %%edx, 12(%3)\n"
30626 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30627 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30628 + "13: movl %%eax, 16(%3)\n"
30629 + "14: movl %%edx, 20(%3)\n"
30630 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30631 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30632 + "17: movl %%eax, 24(%3)\n"
30633 + "18: movl %%edx, 28(%3)\n"
30634 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30635 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30636 + "21: movl %%eax, 32(%3)\n"
30637 + "22: movl %%edx, 36(%3)\n"
30638 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30639 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30640 + "25: movl %%eax, 40(%3)\n"
30641 + "26: movl %%edx, 44(%3)\n"
30642 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30643 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30644 + "29: movl %%eax, 48(%3)\n"
30645 + "30: movl %%edx, 52(%3)\n"
30646 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30647 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30648 + "33: movl %%eax, 56(%3)\n"
30649 + "34: movl %%edx, 60(%3)\n"
30650 + " addl $-64, %0\n"
30651 + " addl $64, %4\n"
30652 + " addl $64, %3\n"
30653 + " cmpl $63, %0\n"
30654 + " ja 1b\n"
30655 + "35: movl %0, %%eax\n"
30656 + " shrl $2, %0\n"
30657 + " andl $3, %%eax\n"
30658 + " cld\n"
30659 + "99: rep; "__copyuser_seg" movsl\n"
30660 + "36: movl %%eax, %0\n"
30661 + "37: rep; "__copyuser_seg" movsb\n"
30662 + "100:\n"
30663 ".section .fixup,\"ax\"\n"
30664 "101: lea 0(%%eax,%0,4),%0\n"
30665 " jmp 100b\n"
30666 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30667 int d0, d1;
30668 __asm__ __volatile__(
30669 " .align 2,0x90\n"
30670 - "0: movl 32(%4), %%eax\n"
30671 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30672 " cmpl $67, %0\n"
30673 " jbe 2f\n"
30674 - "1: movl 64(%4), %%eax\n"
30675 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30676 " .align 2,0x90\n"
30677 - "2: movl 0(%4), %%eax\n"
30678 - "21: movl 4(%4), %%edx\n"
30679 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30680 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30681 " movl %%eax, 0(%3)\n"
30682 " movl %%edx, 4(%3)\n"
30683 - "3: movl 8(%4), %%eax\n"
30684 - "31: movl 12(%4),%%edx\n"
30685 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30686 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30687 " movl %%eax, 8(%3)\n"
30688 " movl %%edx, 12(%3)\n"
30689 - "4: movl 16(%4), %%eax\n"
30690 - "41: movl 20(%4), %%edx\n"
30691 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30692 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30693 " movl %%eax, 16(%3)\n"
30694 " movl %%edx, 20(%3)\n"
30695 - "10: movl 24(%4), %%eax\n"
30696 - "51: movl 28(%4), %%edx\n"
30697 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30698 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30699 " movl %%eax, 24(%3)\n"
30700 " movl %%edx, 28(%3)\n"
30701 - "11: movl 32(%4), %%eax\n"
30702 - "61: movl 36(%4), %%edx\n"
30703 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30704 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30705 " movl %%eax, 32(%3)\n"
30706 " movl %%edx, 36(%3)\n"
30707 - "12: movl 40(%4), %%eax\n"
30708 - "71: movl 44(%4), %%edx\n"
30709 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30710 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30711 " movl %%eax, 40(%3)\n"
30712 " movl %%edx, 44(%3)\n"
30713 - "13: movl 48(%4), %%eax\n"
30714 - "81: movl 52(%4), %%edx\n"
30715 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30716 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30717 " movl %%eax, 48(%3)\n"
30718 " movl %%edx, 52(%3)\n"
30719 - "14: movl 56(%4), %%eax\n"
30720 - "91: movl 60(%4), %%edx\n"
30721 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30722 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30723 " movl %%eax, 56(%3)\n"
30724 " movl %%edx, 60(%3)\n"
30725 " addl $-64, %0\n"
30726 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30727 " shrl $2, %0\n"
30728 " andl $3, %%eax\n"
30729 " cld\n"
30730 - "6: rep; movsl\n"
30731 + "6: rep; "__copyuser_seg" movsl\n"
30732 " movl %%eax,%0\n"
30733 - "7: rep; movsb\n"
30734 + "7: rep; "__copyuser_seg" movsb\n"
30735 "8:\n"
30736 ".section .fixup,\"ax\"\n"
30737 "9: lea 0(%%eax,%0,4),%0\n"
30738 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30739
30740 __asm__ __volatile__(
30741 " .align 2,0x90\n"
30742 - "0: movl 32(%4), %%eax\n"
30743 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30744 " cmpl $67, %0\n"
30745 " jbe 2f\n"
30746 - "1: movl 64(%4), %%eax\n"
30747 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30748 " .align 2,0x90\n"
30749 - "2: movl 0(%4), %%eax\n"
30750 - "21: movl 4(%4), %%edx\n"
30751 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30752 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30753 " movnti %%eax, 0(%3)\n"
30754 " movnti %%edx, 4(%3)\n"
30755 - "3: movl 8(%4), %%eax\n"
30756 - "31: movl 12(%4),%%edx\n"
30757 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30758 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30759 " movnti %%eax, 8(%3)\n"
30760 " movnti %%edx, 12(%3)\n"
30761 - "4: movl 16(%4), %%eax\n"
30762 - "41: movl 20(%4), %%edx\n"
30763 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30764 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30765 " movnti %%eax, 16(%3)\n"
30766 " movnti %%edx, 20(%3)\n"
30767 - "10: movl 24(%4), %%eax\n"
30768 - "51: movl 28(%4), %%edx\n"
30769 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30770 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30771 " movnti %%eax, 24(%3)\n"
30772 " movnti %%edx, 28(%3)\n"
30773 - "11: movl 32(%4), %%eax\n"
30774 - "61: movl 36(%4), %%edx\n"
30775 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30776 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30777 " movnti %%eax, 32(%3)\n"
30778 " movnti %%edx, 36(%3)\n"
30779 - "12: movl 40(%4), %%eax\n"
30780 - "71: movl 44(%4), %%edx\n"
30781 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30782 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30783 " movnti %%eax, 40(%3)\n"
30784 " movnti %%edx, 44(%3)\n"
30785 - "13: movl 48(%4), %%eax\n"
30786 - "81: movl 52(%4), %%edx\n"
30787 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30788 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30789 " movnti %%eax, 48(%3)\n"
30790 " movnti %%edx, 52(%3)\n"
30791 - "14: movl 56(%4), %%eax\n"
30792 - "91: movl 60(%4), %%edx\n"
30793 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30794 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30795 " movnti %%eax, 56(%3)\n"
30796 " movnti %%edx, 60(%3)\n"
30797 " addl $-64, %0\n"
30798 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30799 " shrl $2, %0\n"
30800 " andl $3, %%eax\n"
30801 " cld\n"
30802 - "6: rep; movsl\n"
30803 + "6: rep; "__copyuser_seg" movsl\n"
30804 " movl %%eax,%0\n"
30805 - "7: rep; movsb\n"
30806 + "7: rep; "__copyuser_seg" movsb\n"
30807 "8:\n"
30808 ".section .fixup,\"ax\"\n"
30809 "9: lea 0(%%eax,%0,4),%0\n"
30810 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30811
30812 __asm__ __volatile__(
30813 " .align 2,0x90\n"
30814 - "0: movl 32(%4), %%eax\n"
30815 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30816 " cmpl $67, %0\n"
30817 " jbe 2f\n"
30818 - "1: movl 64(%4), %%eax\n"
30819 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30820 " .align 2,0x90\n"
30821 - "2: movl 0(%4), %%eax\n"
30822 - "21: movl 4(%4), %%edx\n"
30823 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30824 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30825 " movnti %%eax, 0(%3)\n"
30826 " movnti %%edx, 4(%3)\n"
30827 - "3: movl 8(%4), %%eax\n"
30828 - "31: movl 12(%4),%%edx\n"
30829 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30830 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30831 " movnti %%eax, 8(%3)\n"
30832 " movnti %%edx, 12(%3)\n"
30833 - "4: movl 16(%4), %%eax\n"
30834 - "41: movl 20(%4), %%edx\n"
30835 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30836 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30837 " movnti %%eax, 16(%3)\n"
30838 " movnti %%edx, 20(%3)\n"
30839 - "10: movl 24(%4), %%eax\n"
30840 - "51: movl 28(%4), %%edx\n"
30841 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30842 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30843 " movnti %%eax, 24(%3)\n"
30844 " movnti %%edx, 28(%3)\n"
30845 - "11: movl 32(%4), %%eax\n"
30846 - "61: movl 36(%4), %%edx\n"
30847 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30848 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30849 " movnti %%eax, 32(%3)\n"
30850 " movnti %%edx, 36(%3)\n"
30851 - "12: movl 40(%4), %%eax\n"
30852 - "71: movl 44(%4), %%edx\n"
30853 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30854 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30855 " movnti %%eax, 40(%3)\n"
30856 " movnti %%edx, 44(%3)\n"
30857 - "13: movl 48(%4), %%eax\n"
30858 - "81: movl 52(%4), %%edx\n"
30859 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30860 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30861 " movnti %%eax, 48(%3)\n"
30862 " movnti %%edx, 52(%3)\n"
30863 - "14: movl 56(%4), %%eax\n"
30864 - "91: movl 60(%4), %%edx\n"
30865 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30866 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30867 " movnti %%eax, 56(%3)\n"
30868 " movnti %%edx, 60(%3)\n"
30869 " addl $-64, %0\n"
30870 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30871 " shrl $2, %0\n"
30872 " andl $3, %%eax\n"
30873 " cld\n"
30874 - "6: rep; movsl\n"
30875 + "6: rep; "__copyuser_seg" movsl\n"
30876 " movl %%eax,%0\n"
30877 - "7: rep; movsb\n"
30878 + "7: rep; "__copyuser_seg" movsb\n"
30879 "8:\n"
30880 ".section .fixup,\"ax\"\n"
30881 "9: lea 0(%%eax,%0,4),%0\n"
30882 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30883 */
30884 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30885 unsigned long size);
30886 -unsigned long __copy_user_intel(void __user *to, const void *from,
30887 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30888 + unsigned long size);
30889 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30890 unsigned long size);
30891 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30892 const void __user *from, unsigned long size);
30893 #endif /* CONFIG_X86_INTEL_USERCOPY */
30894
30895 /* Generic arbitrary sized copy. */
30896 -#define __copy_user(to, from, size) \
30897 +#define __copy_user(to, from, size, prefix, set, restore) \
30898 do { \
30899 int __d0, __d1, __d2; \
30900 __asm__ __volatile__( \
30901 + set \
30902 " cmp $7,%0\n" \
30903 " jbe 1f\n" \
30904 " movl %1,%0\n" \
30905 " negl %0\n" \
30906 " andl $7,%0\n" \
30907 " subl %0,%3\n" \
30908 - "4: rep; movsb\n" \
30909 + "4: rep; "prefix"movsb\n" \
30910 " movl %3,%0\n" \
30911 " shrl $2,%0\n" \
30912 " andl $3,%3\n" \
30913 " .align 2,0x90\n" \
30914 - "0: rep; movsl\n" \
30915 + "0: rep; "prefix"movsl\n" \
30916 " movl %3,%0\n" \
30917 - "1: rep; movsb\n" \
30918 + "1: rep; "prefix"movsb\n" \
30919 "2:\n" \
30920 + restore \
30921 ".section .fixup,\"ax\"\n" \
30922 "5: addl %3,%0\n" \
30923 " jmp 2b\n" \
30924 @@ -538,14 +650,14 @@ do { \
30925 " negl %0\n" \
30926 " andl $7,%0\n" \
30927 " subl %0,%3\n" \
30928 - "4: rep; movsb\n" \
30929 + "4: rep; "__copyuser_seg"movsb\n" \
30930 " movl %3,%0\n" \
30931 " shrl $2,%0\n" \
30932 " andl $3,%3\n" \
30933 " .align 2,0x90\n" \
30934 - "0: rep; movsl\n" \
30935 + "0: rep; "__copyuser_seg"movsl\n" \
30936 " movl %3,%0\n" \
30937 - "1: rep; movsb\n" \
30938 + "1: rep; "__copyuser_seg"movsb\n" \
30939 "2:\n" \
30940 ".section .fixup,\"ax\"\n" \
30941 "5: addl %3,%0\n" \
30942 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30943 {
30944 stac();
30945 if (movsl_is_ok(to, from, n))
30946 - __copy_user(to, from, n);
30947 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30948 else
30949 - n = __copy_user_intel(to, from, n);
30950 + n = __generic_copy_to_user_intel(to, from, n);
30951 clac();
30952 return n;
30953 }
30954 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30955 {
30956 stac();
30957 if (movsl_is_ok(to, from, n))
30958 - __copy_user(to, from, n);
30959 + __copy_user(to, from, n, __copyuser_seg, "", "");
30960 else
30961 - n = __copy_user_intel((void __user *)to,
30962 - (const void *)from, n);
30963 + n = __generic_copy_from_user_intel(to, from, n);
30964 clac();
30965 return n;
30966 }
30967 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30968 if (n > 64 && cpu_has_xmm2)
30969 n = __copy_user_intel_nocache(to, from, n);
30970 else
30971 - __copy_user(to, from, n);
30972 + __copy_user(to, from, n, __copyuser_seg, "", "");
30973 #else
30974 - __copy_user(to, from, n);
30975 + __copy_user(to, from, n, __copyuser_seg, "", "");
30976 #endif
30977 clac();
30978 return n;
30979 }
30980 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30981
30982 -/**
30983 - * copy_to_user: - Copy a block of data into user space.
30984 - * @to: Destination address, in user space.
30985 - * @from: Source address, in kernel space.
30986 - * @n: Number of bytes to copy.
30987 - *
30988 - * Context: User context only. This function may sleep.
30989 - *
30990 - * Copy data from kernel space to user space.
30991 - *
30992 - * Returns number of bytes that could not be copied.
30993 - * On success, this will be zero.
30994 - */
30995 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
30996 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30997 +void __set_fs(mm_segment_t x)
30998 {
30999 - if (access_ok(VERIFY_WRITE, to, n))
31000 - n = __copy_to_user(to, from, n);
31001 - return n;
31002 + switch (x.seg) {
31003 + case 0:
31004 + loadsegment(gs, 0);
31005 + break;
31006 + case TASK_SIZE_MAX:
31007 + loadsegment(gs, __USER_DS);
31008 + break;
31009 + case -1UL:
31010 + loadsegment(gs, __KERNEL_DS);
31011 + break;
31012 + default:
31013 + BUG();
31014 + }
31015 }
31016 -EXPORT_SYMBOL(_copy_to_user);
31017 +EXPORT_SYMBOL(__set_fs);
31018
31019 -/**
31020 - * copy_from_user: - Copy a block of data from user space.
31021 - * @to: Destination address, in kernel space.
31022 - * @from: Source address, in user space.
31023 - * @n: Number of bytes to copy.
31024 - *
31025 - * Context: User context only. This function may sleep.
31026 - *
31027 - * Copy data from user space to kernel space.
31028 - *
31029 - * Returns number of bytes that could not be copied.
31030 - * On success, this will be zero.
31031 - *
31032 - * If some data could not be copied, this function will pad the copied
31033 - * data to the requested size using zero bytes.
31034 - */
31035 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31036 +void set_fs(mm_segment_t x)
31037 {
31038 - if (access_ok(VERIFY_READ, from, n))
31039 - n = __copy_from_user(to, from, n);
31040 - else
31041 - memset(to, 0, n);
31042 - return n;
31043 + current_thread_info()->addr_limit = x;
31044 + __set_fs(x);
31045 }
31046 -EXPORT_SYMBOL(_copy_from_user);
31047 +EXPORT_SYMBOL(set_fs);
31048 +#endif
31049 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31050 index c905e89..01ab928 100644
31051 --- a/arch/x86/lib/usercopy_64.c
31052 +++ b/arch/x86/lib/usercopy_64.c
31053 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31054 might_fault();
31055 /* no memory constraint because it doesn't change any memory gcc knows
31056 about */
31057 + pax_open_userland();
31058 stac();
31059 asm volatile(
31060 " testq %[size8],%[size8]\n"
31061 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31062 _ASM_EXTABLE(0b,3b)
31063 _ASM_EXTABLE(1b,2b)
31064 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31065 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31066 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31067 [zero] "r" (0UL), [eight] "r" (8UL));
31068 clac();
31069 + pax_close_userland();
31070 return size;
31071 }
31072 EXPORT_SYMBOL(__clear_user);
31073 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31074 }
31075 EXPORT_SYMBOL(clear_user);
31076
31077 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31078 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31079 {
31080 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31081 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31082 - }
31083 - return len;
31084 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31085 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31086 + return len;
31087 }
31088 EXPORT_SYMBOL(copy_in_user);
31089
31090 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31091 * it is not necessary to optimize tail handling.
31092 */
31093 __visible unsigned long
31094 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31095 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31096 {
31097 char c;
31098 unsigned zero_len;
31099
31100 + clac();
31101 + pax_close_userland();
31102 for (; len; --len, to++) {
31103 if (__get_user_nocheck(c, from++, sizeof(char)))
31104 break;
31105 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31106 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31107 if (__put_user_nocheck(c, to++, sizeof(char)))
31108 break;
31109 - clac();
31110 return len;
31111 }
31112 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31113 index 6a19ad9..1c48f9a 100644
31114 --- a/arch/x86/mm/Makefile
31115 +++ b/arch/x86/mm/Makefile
31116 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31117 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31118
31119 obj-$(CONFIG_MEMTEST) += memtest.o
31120 +
31121 +quote:="
31122 +obj-$(CONFIG_X86_64) += uderef_64.o
31123 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31124 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31125 index 903ec1e..c4166b2 100644
31126 --- a/arch/x86/mm/extable.c
31127 +++ b/arch/x86/mm/extable.c
31128 @@ -6,12 +6,24 @@
31129 static inline unsigned long
31130 ex_insn_addr(const struct exception_table_entry *x)
31131 {
31132 - return (unsigned long)&x->insn + x->insn;
31133 + unsigned long reloc = 0;
31134 +
31135 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31136 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31137 +#endif
31138 +
31139 + return (unsigned long)&x->insn + x->insn + reloc;
31140 }
31141 static inline unsigned long
31142 ex_fixup_addr(const struct exception_table_entry *x)
31143 {
31144 - return (unsigned long)&x->fixup + x->fixup;
31145 + unsigned long reloc = 0;
31146 +
31147 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31148 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31149 +#endif
31150 +
31151 + return (unsigned long)&x->fixup + x->fixup + reloc;
31152 }
31153
31154 int fixup_exception(struct pt_regs *regs)
31155 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31156 unsigned long new_ip;
31157
31158 #ifdef CONFIG_PNPBIOS
31159 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31160 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31161 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31162 extern u32 pnp_bios_is_utter_crap;
31163 pnp_bios_is_utter_crap = 1;
31164 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31165 i += 4;
31166 p->fixup -= i;
31167 i += 4;
31168 +
31169 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31170 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31171 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31172 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31173 +#endif
31174 +
31175 }
31176 }
31177
31178 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31179 index a10c8c7..35a5abb 100644
31180 --- a/arch/x86/mm/fault.c
31181 +++ b/arch/x86/mm/fault.c
31182 @@ -14,11 +14,18 @@
31183 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31184 #include <linux/prefetch.h> /* prefetchw */
31185 #include <linux/context_tracking.h> /* exception_enter(), ... */
31186 +#include <linux/unistd.h>
31187 +#include <linux/compiler.h>
31188
31189 #include <asm/traps.h> /* dotraplinkage, ... */
31190 #include <asm/pgalloc.h> /* pgd_*(), ... */
31191 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31192 #include <asm/fixmap.h> /* VSYSCALL_START */
31193 +#include <asm/tlbflush.h>
31194 +
31195 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31196 +#include <asm/stacktrace.h>
31197 +#endif
31198
31199 #define CREATE_TRACE_POINTS
31200 #include <asm/trace/exceptions.h>
31201 @@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31202 int ret = 0;
31203
31204 /* kprobe_running() needs smp_processor_id() */
31205 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31206 + if (kprobes_built_in() && !user_mode(regs)) {
31207 preempt_disable();
31208 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31209 ret = 1;
31210 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31211 return !instr_lo || (instr_lo>>1) == 1;
31212 case 0x00:
31213 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31214 - if (probe_kernel_address(instr, opcode))
31215 + if (user_mode(regs)) {
31216 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31217 + return 0;
31218 + } else if (probe_kernel_address(instr, opcode))
31219 return 0;
31220
31221 *prefetch = (instr_lo == 0xF) &&
31222 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31223 while (instr < max_instr) {
31224 unsigned char opcode;
31225
31226 - if (probe_kernel_address(instr, opcode))
31227 + if (user_mode(regs)) {
31228 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31229 + break;
31230 + } else if (probe_kernel_address(instr, opcode))
31231 break;
31232
31233 instr++;
31234 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31235 force_sig_info(si_signo, &info, tsk);
31236 }
31237
31238 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31239 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31240 +#endif
31241 +
31242 +#ifdef CONFIG_PAX_EMUTRAMP
31243 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31244 +#endif
31245 +
31246 +#ifdef CONFIG_PAX_PAGEEXEC
31247 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31248 +{
31249 + pgd_t *pgd;
31250 + pud_t *pud;
31251 + pmd_t *pmd;
31252 +
31253 + pgd = pgd_offset(mm, address);
31254 + if (!pgd_present(*pgd))
31255 + return NULL;
31256 + pud = pud_offset(pgd, address);
31257 + if (!pud_present(*pud))
31258 + return NULL;
31259 + pmd = pmd_offset(pud, address);
31260 + if (!pmd_present(*pmd))
31261 + return NULL;
31262 + return pmd;
31263 +}
31264 +#endif
31265 +
31266 DEFINE_SPINLOCK(pgd_lock);
31267 LIST_HEAD(pgd_list);
31268
31269 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31270 for (address = VMALLOC_START & PMD_MASK;
31271 address >= TASK_SIZE && address < FIXADDR_TOP;
31272 address += PMD_SIZE) {
31273 +
31274 +#ifdef CONFIG_PAX_PER_CPU_PGD
31275 + unsigned long cpu;
31276 +#else
31277 struct page *page;
31278 +#endif
31279
31280 spin_lock(&pgd_lock);
31281 +
31282 +#ifdef CONFIG_PAX_PER_CPU_PGD
31283 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31284 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31285 + pmd_t *ret;
31286 +
31287 + ret = vmalloc_sync_one(pgd, address);
31288 + if (!ret)
31289 + break;
31290 + pgd = get_cpu_pgd(cpu, kernel);
31291 +#else
31292 list_for_each_entry(page, &pgd_list, lru) {
31293 + pgd_t *pgd;
31294 spinlock_t *pgt_lock;
31295 pmd_t *ret;
31296
31297 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31298 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31299
31300 spin_lock(pgt_lock);
31301 - ret = vmalloc_sync_one(page_address(page), address);
31302 + pgd = page_address(page);
31303 +#endif
31304 +
31305 + ret = vmalloc_sync_one(pgd, address);
31306 +
31307 +#ifndef CONFIG_PAX_PER_CPU_PGD
31308 spin_unlock(pgt_lock);
31309 +#endif
31310
31311 if (!ret)
31312 break;
31313 @@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31314 * an interrupt in the middle of a task switch..
31315 */
31316 pgd_paddr = read_cr3();
31317 +
31318 +#ifdef CONFIG_PAX_PER_CPU_PGD
31319 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31320 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31321 +#endif
31322 +
31323 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31324 if (!pmd_k)
31325 return -1;
31326 @@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31327 * happen within a race in page table update. In the later
31328 * case just flush:
31329 */
31330 - pgd = pgd_offset(current->active_mm, address);
31331 +
31332 pgd_ref = pgd_offset_k(address);
31333 if (pgd_none(*pgd_ref))
31334 return -1;
31335
31336 +#ifdef CONFIG_PAX_PER_CPU_PGD
31337 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31338 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31339 + if (pgd_none(*pgd)) {
31340 + set_pgd(pgd, *pgd_ref);
31341 + arch_flush_lazy_mmu_mode();
31342 + } else {
31343 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31344 + }
31345 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31346 +#else
31347 + pgd = pgd_offset(current->active_mm, address);
31348 +#endif
31349 +
31350 if (pgd_none(*pgd)) {
31351 set_pgd(pgd, *pgd_ref);
31352 arch_flush_lazy_mmu_mode();
31353 @@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31354 static int is_errata100(struct pt_regs *regs, unsigned long address)
31355 {
31356 #ifdef CONFIG_X86_64
31357 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31358 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31359 return 1;
31360 #endif
31361 return 0;
31362 @@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31363 }
31364
31365 static const char nx_warning[] = KERN_CRIT
31366 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31367 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31368
31369 static void
31370 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31371 @@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31372 if (!oops_may_print())
31373 return;
31374
31375 - if (error_code & PF_INSTR) {
31376 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31377 unsigned int level;
31378
31379 pte_t *pte = lookup_address(address, &level);
31380
31381 if (pte && pte_present(*pte) && !pte_exec(*pte))
31382 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31383 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31384 }
31385
31386 +#ifdef CONFIG_PAX_KERNEXEC
31387 + if (init_mm.start_code <= address && address < init_mm.end_code) {
31388 + if (current->signal->curr_ip)
31389 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31390 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
31391 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31392 + else
31393 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31394 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31395 + }
31396 +#endif
31397 +
31398 printk(KERN_ALERT "BUG: unable to handle kernel ");
31399 if (address < PAGE_SIZE)
31400 printk(KERN_CONT "NULL pointer dereference");
31401 @@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31402 return;
31403 }
31404 #endif
31405 +
31406 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31407 + if (pax_is_fetch_fault(regs, error_code, address)) {
31408 +
31409 +#ifdef CONFIG_PAX_EMUTRAMP
31410 + switch (pax_handle_fetch_fault(regs)) {
31411 + case 2:
31412 + return;
31413 + }
31414 +#endif
31415 +
31416 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31417 + do_group_exit(SIGKILL);
31418 + }
31419 +#endif
31420 +
31421 /* Kernel addresses are always protection faults: */
31422 if (address >= TASK_SIZE)
31423 error_code |= PF_PROT;
31424 @@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31425 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31426 printk(KERN_ERR
31427 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31428 - tsk->comm, tsk->pid, address);
31429 + tsk->comm, task_pid_nr(tsk), address);
31430 code = BUS_MCEERR_AR;
31431 }
31432 #endif
31433 @@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31434 return 1;
31435 }
31436
31437 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31438 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31439 +{
31440 + pte_t *pte;
31441 + pmd_t *pmd;
31442 + spinlock_t *ptl;
31443 + unsigned char pte_mask;
31444 +
31445 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31446 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
31447 + return 0;
31448 +
31449 + /* PaX: it's our fault, let's handle it if we can */
31450 +
31451 + /* PaX: take a look at read faults before acquiring any locks */
31452 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31453 + /* instruction fetch attempt from a protected page in user mode */
31454 + up_read(&mm->mmap_sem);
31455 +
31456 +#ifdef CONFIG_PAX_EMUTRAMP
31457 + switch (pax_handle_fetch_fault(regs)) {
31458 + case 2:
31459 + return 1;
31460 + }
31461 +#endif
31462 +
31463 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31464 + do_group_exit(SIGKILL);
31465 + }
31466 +
31467 + pmd = pax_get_pmd(mm, address);
31468 + if (unlikely(!pmd))
31469 + return 0;
31470 +
31471 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31472 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31473 + pte_unmap_unlock(pte, ptl);
31474 + return 0;
31475 + }
31476 +
31477 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31478 + /* write attempt to a protected page in user mode */
31479 + pte_unmap_unlock(pte, ptl);
31480 + return 0;
31481 + }
31482 +
31483 +#ifdef CONFIG_SMP
31484 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31485 +#else
31486 + if (likely(address > get_limit(regs->cs)))
31487 +#endif
31488 + {
31489 + set_pte(pte, pte_mkread(*pte));
31490 + __flush_tlb_one(address);
31491 + pte_unmap_unlock(pte, ptl);
31492 + up_read(&mm->mmap_sem);
31493 + return 1;
31494 + }
31495 +
31496 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31497 +
31498 + /*
31499 + * PaX: fill DTLB with user rights and retry
31500 + */
31501 + __asm__ __volatile__ (
31502 + "orb %2,(%1)\n"
31503 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31504 +/*
31505 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31506 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31507 + * page fault when examined during a TLB load attempt. this is true not only
31508 + * for PTEs holding a non-present entry but also present entries that will
31509 + * raise a page fault (such as those set up by PaX, or the copy-on-write
31510 + * mechanism). in effect it means that we do *not* need to flush the TLBs
31511 + * for our target pages since their PTEs are simply not in the TLBs at all.
31512 +
31513 + * the best thing in omitting it is that we gain around 15-20% speed in the
31514 + * fast path of the page fault handler and can get rid of tracing since we
31515 + * can no longer flush unintended entries.
31516 + */
31517 + "invlpg (%0)\n"
31518 +#endif
31519 + __copyuser_seg"testb $0,(%0)\n"
31520 + "xorb %3,(%1)\n"
31521 + :
31522 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31523 + : "memory", "cc");
31524 + pte_unmap_unlock(pte, ptl);
31525 + up_read(&mm->mmap_sem);
31526 + return 1;
31527 +}
31528 +#endif
31529 +
31530 /*
31531 * Handle a spurious fault caused by a stale TLB entry.
31532 *
31533 @@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31534 static inline int
31535 access_error(unsigned long error_code, struct vm_area_struct *vma)
31536 {
31537 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31538 + return 1;
31539 +
31540 if (error_code & PF_WRITE) {
31541 /* write, present and write, not present: */
31542 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31543 @@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31544 if (error_code & PF_USER)
31545 return false;
31546
31547 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31548 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31549 return false;
31550
31551 return true;
31552 @@ -1038,6 +1246,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31553 tsk = current;
31554 mm = tsk->mm;
31555
31556 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31557 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31558 + if (!search_exception_tables(regs->ip)) {
31559 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31560 + bad_area_nosemaphore(regs, error_code, address);
31561 + return;
31562 + }
31563 + if (address < pax_user_shadow_base) {
31564 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31565 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31566 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31567 + } else
31568 + address -= pax_user_shadow_base;
31569 + }
31570 +#endif
31571 +
31572 /*
31573 * Detect and handle instructions that would cause a page fault for
31574 * both a tracked kernel page and a userspace page.
31575 @@ -1115,7 +1339,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31576 * User-mode registers count as a user access even for any
31577 * potential system fault or CPU buglet:
31578 */
31579 - if (user_mode_vm(regs)) {
31580 + if (user_mode(regs)) {
31581 local_irq_enable();
31582 error_code |= PF_USER;
31583 flags |= FAULT_FLAG_USER;
31584 @@ -1162,6 +1386,11 @@ retry:
31585 might_sleep();
31586 }
31587
31588 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31589 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31590 + return;
31591 +#endif
31592 +
31593 vma = find_vma(mm, address);
31594 if (unlikely(!vma)) {
31595 bad_area(regs, error_code, address);
31596 @@ -1173,18 +1402,24 @@ retry:
31597 bad_area(regs, error_code, address);
31598 return;
31599 }
31600 - if (error_code & PF_USER) {
31601 - /*
31602 - * Accessing the stack below %sp is always a bug.
31603 - * The large cushion allows instructions like enter
31604 - * and pusha to work. ("enter $65535, $31" pushes
31605 - * 32 pointers and then decrements %sp by 65535.)
31606 - */
31607 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31608 - bad_area(regs, error_code, address);
31609 - return;
31610 - }
31611 + /*
31612 + * Accessing the stack below %sp is always a bug.
31613 + * The large cushion allows instructions like enter
31614 + * and pusha to work. ("enter $65535, $31" pushes
31615 + * 32 pointers and then decrements %sp by 65535.)
31616 + */
31617 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31618 + bad_area(regs, error_code, address);
31619 + return;
31620 }
31621 +
31622 +#ifdef CONFIG_PAX_SEGMEXEC
31623 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31624 + bad_area(regs, error_code, address);
31625 + return;
31626 + }
31627 +#endif
31628 +
31629 if (unlikely(expand_stack(vma, address))) {
31630 bad_area(regs, error_code, address);
31631 return;
31632 @@ -1296,3 +1531,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31633 exception_exit(prev_state);
31634 }
31635 #endif /* CONFIG_TRACING */
31636 +
31637 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31638 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31639 +{
31640 + struct mm_struct *mm = current->mm;
31641 + unsigned long ip = regs->ip;
31642 +
31643 + if (v8086_mode(regs))
31644 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31645 +
31646 +#ifdef CONFIG_PAX_PAGEEXEC
31647 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31648 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31649 + return true;
31650 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31651 + return true;
31652 + return false;
31653 + }
31654 +#endif
31655 +
31656 +#ifdef CONFIG_PAX_SEGMEXEC
31657 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31658 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31659 + return true;
31660 + return false;
31661 + }
31662 +#endif
31663 +
31664 + return false;
31665 +}
31666 +#endif
31667 +
31668 +#ifdef CONFIG_PAX_EMUTRAMP
31669 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31670 +{
31671 + int err;
31672 +
31673 + do { /* PaX: libffi trampoline emulation */
31674 + unsigned char mov, jmp;
31675 + unsigned int addr1, addr2;
31676 +
31677 +#ifdef CONFIG_X86_64
31678 + if ((regs->ip + 9) >> 32)
31679 + break;
31680 +#endif
31681 +
31682 + err = get_user(mov, (unsigned char __user *)regs->ip);
31683 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31684 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31685 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31686 +
31687 + if (err)
31688 + break;
31689 +
31690 + if (mov == 0xB8 && jmp == 0xE9) {
31691 + regs->ax = addr1;
31692 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31693 + return 2;
31694 + }
31695 + } while (0);
31696 +
31697 + do { /* PaX: gcc trampoline emulation #1 */
31698 + unsigned char mov1, mov2;
31699 + unsigned short jmp;
31700 + unsigned int addr1, addr2;
31701 +
31702 +#ifdef CONFIG_X86_64
31703 + if ((regs->ip + 11) >> 32)
31704 + break;
31705 +#endif
31706 +
31707 + err = get_user(mov1, (unsigned char __user *)regs->ip);
31708 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31709 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31710 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31711 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31712 +
31713 + if (err)
31714 + break;
31715 +
31716 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31717 + regs->cx = addr1;
31718 + regs->ax = addr2;
31719 + regs->ip = addr2;
31720 + return 2;
31721 + }
31722 + } while (0);
31723 +
31724 + do { /* PaX: gcc trampoline emulation #2 */
31725 + unsigned char mov, jmp;
31726 + unsigned int addr1, addr2;
31727 +
31728 +#ifdef CONFIG_X86_64
31729 + if ((regs->ip + 9) >> 32)
31730 + break;
31731 +#endif
31732 +
31733 + err = get_user(mov, (unsigned char __user *)regs->ip);
31734 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31735 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31736 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31737 +
31738 + if (err)
31739 + break;
31740 +
31741 + if (mov == 0xB9 && jmp == 0xE9) {
31742 + regs->cx = addr1;
31743 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31744 + return 2;
31745 + }
31746 + } while (0);
31747 +
31748 + return 1; /* PaX in action */
31749 +}
31750 +
31751 +#ifdef CONFIG_X86_64
31752 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31753 +{
31754 + int err;
31755 +
31756 + do { /* PaX: libffi trampoline emulation */
31757 + unsigned short mov1, mov2, jmp1;
31758 + unsigned char stcclc, jmp2;
31759 + unsigned long addr1, addr2;
31760 +
31761 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31762 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31763 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31764 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31765 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31766 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31767 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31768 +
31769 + if (err)
31770 + break;
31771 +
31772 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31773 + regs->r11 = addr1;
31774 + regs->r10 = addr2;
31775 + if (stcclc == 0xF8)
31776 + regs->flags &= ~X86_EFLAGS_CF;
31777 + else
31778 + regs->flags |= X86_EFLAGS_CF;
31779 + regs->ip = addr1;
31780 + return 2;
31781 + }
31782 + } while (0);
31783 +
31784 + do { /* PaX: gcc trampoline emulation #1 */
31785 + unsigned short mov1, mov2, jmp1;
31786 + unsigned char jmp2;
31787 + unsigned int addr1;
31788 + unsigned long addr2;
31789 +
31790 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31791 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31792 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31793 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31794 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31795 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31796 +
31797 + if (err)
31798 + break;
31799 +
31800 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31801 + regs->r11 = addr1;
31802 + regs->r10 = addr2;
31803 + regs->ip = addr1;
31804 + return 2;
31805 + }
31806 + } while (0);
31807 +
31808 + do { /* PaX: gcc trampoline emulation #2 */
31809 + unsigned short mov1, mov2, jmp1;
31810 + unsigned char jmp2;
31811 + unsigned long addr1, addr2;
31812 +
31813 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31814 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31815 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31816 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31817 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31818 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31819 +
31820 + if (err)
31821 + break;
31822 +
31823 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31824 + regs->r11 = addr1;
31825 + regs->r10 = addr2;
31826 + regs->ip = addr1;
31827 + return 2;
31828 + }
31829 + } while (0);
31830 +
31831 + return 1; /* PaX in action */
31832 +}
31833 +#endif
31834 +
31835 +/*
31836 + * PaX: decide what to do with offenders (regs->ip = fault address)
31837 + *
31838 + * returns 1 when task should be killed
31839 + * 2 when gcc trampoline was detected
31840 + */
31841 +static int pax_handle_fetch_fault(struct pt_regs *regs)
31842 +{
31843 + if (v8086_mode(regs))
31844 + return 1;
31845 +
31846 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31847 + return 1;
31848 +
31849 +#ifdef CONFIG_X86_32
31850 + return pax_handle_fetch_fault_32(regs);
31851 +#else
31852 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31853 + return pax_handle_fetch_fault_32(regs);
31854 + else
31855 + return pax_handle_fetch_fault_64(regs);
31856 +#endif
31857 +}
31858 +#endif
31859 +
31860 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31861 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31862 +{
31863 + long i;
31864 +
31865 + printk(KERN_ERR "PAX: bytes at PC: ");
31866 + for (i = 0; i < 20; i++) {
31867 + unsigned char c;
31868 + if (get_user(c, (unsigned char __force_user *)pc+i))
31869 + printk(KERN_CONT "?? ");
31870 + else
31871 + printk(KERN_CONT "%02x ", c);
31872 + }
31873 + printk("\n");
31874 +
31875 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31876 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
31877 + unsigned long c;
31878 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
31879 +#ifdef CONFIG_X86_32
31880 + printk(KERN_CONT "???????? ");
31881 +#else
31882 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31883 + printk(KERN_CONT "???????? ???????? ");
31884 + else
31885 + printk(KERN_CONT "???????????????? ");
31886 +#endif
31887 + } else {
31888 +#ifdef CONFIG_X86_64
31889 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31890 + printk(KERN_CONT "%08x ", (unsigned int)c);
31891 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31892 + } else
31893 +#endif
31894 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31895 + }
31896 + }
31897 + printk("\n");
31898 +}
31899 +#endif
31900 +
31901 +/**
31902 + * probe_kernel_write(): safely attempt to write to a location
31903 + * @dst: address to write to
31904 + * @src: pointer to the data that shall be written
31905 + * @size: size of the data chunk
31906 + *
31907 + * Safely write to address @dst from the buffer at @src. If a kernel fault
31908 + * happens, handle that and return -EFAULT.
31909 + */
31910 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31911 +{
31912 + long ret;
31913 + mm_segment_t old_fs = get_fs();
31914 +
31915 + set_fs(KERNEL_DS);
31916 + pagefault_disable();
31917 + pax_open_kernel();
31918 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31919 + pax_close_kernel();
31920 + pagefault_enable();
31921 + set_fs(old_fs);
31922 +
31923 + return ret ? -EFAULT : 0;
31924 +}
31925 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31926 index 207d9aef..69030980 100644
31927 --- a/arch/x86/mm/gup.c
31928 +++ b/arch/x86/mm/gup.c
31929 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31930 addr = start;
31931 len = (unsigned long) nr_pages << PAGE_SHIFT;
31932 end = start + len;
31933 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31934 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31935 (void __user *)start, len)))
31936 return 0;
31937
31938 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31939 goto slow_irqon;
31940 #endif
31941
31942 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31943 + (void __user *)start, len)))
31944 + return 0;
31945 +
31946 /*
31947 * XXX: batch / limit 'nr', to avoid large irq off latency
31948 * needs some instrumenting to determine the common sizes used by
31949 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31950 index 4500142..53a363c 100644
31951 --- a/arch/x86/mm/highmem_32.c
31952 +++ b/arch/x86/mm/highmem_32.c
31953 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31954 idx = type + KM_TYPE_NR*smp_processor_id();
31955 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31956 BUG_ON(!pte_none(*(kmap_pte-idx)));
31957 +
31958 + pax_open_kernel();
31959 set_pte(kmap_pte-idx, mk_pte(page, prot));
31960 + pax_close_kernel();
31961 +
31962 arch_flush_lazy_mmu_mode();
31963
31964 return (void *)vaddr;
31965 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31966 index 8c9f647..57cb402 100644
31967 --- a/arch/x86/mm/hugetlbpage.c
31968 +++ b/arch/x86/mm/hugetlbpage.c
31969 @@ -90,23 +90,24 @@ int pmd_huge_support(void)
31970 #ifdef CONFIG_HUGETLB_PAGE
31971 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31972 unsigned long addr, unsigned long len,
31973 - unsigned long pgoff, unsigned long flags)
31974 + unsigned long pgoff, unsigned long flags, unsigned long offset)
31975 {
31976 struct hstate *h = hstate_file(file);
31977 struct vm_unmapped_area_info info;
31978 -
31979 +
31980 info.flags = 0;
31981 info.length = len;
31982 info.low_limit = current->mm->mmap_legacy_base;
31983 info.high_limit = TASK_SIZE;
31984 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31985 info.align_offset = 0;
31986 + info.threadstack_offset = offset;
31987 return vm_unmapped_area(&info);
31988 }
31989
31990 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31991 unsigned long addr0, unsigned long len,
31992 - unsigned long pgoff, unsigned long flags)
31993 + unsigned long pgoff, unsigned long flags, unsigned long offset)
31994 {
31995 struct hstate *h = hstate_file(file);
31996 struct vm_unmapped_area_info info;
31997 @@ -118,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31998 info.high_limit = current->mm->mmap_base;
31999 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32000 info.align_offset = 0;
32001 + info.threadstack_offset = offset;
32002 addr = vm_unmapped_area(&info);
32003
32004 /*
32005 @@ -130,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32006 VM_BUG_ON(addr != -ENOMEM);
32007 info.flags = 0;
32008 info.low_limit = TASK_UNMAPPED_BASE;
32009 +
32010 +#ifdef CONFIG_PAX_RANDMMAP
32011 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32012 + info.low_limit += current->mm->delta_mmap;
32013 +#endif
32014 +
32015 info.high_limit = TASK_SIZE;
32016 addr = vm_unmapped_area(&info);
32017 }
32018 @@ -144,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32019 struct hstate *h = hstate_file(file);
32020 struct mm_struct *mm = current->mm;
32021 struct vm_area_struct *vma;
32022 + unsigned long pax_task_size = TASK_SIZE;
32023 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32024
32025 if (len & ~huge_page_mask(h))
32026 return -EINVAL;
32027 - if (len > TASK_SIZE)
32028 +
32029 +#ifdef CONFIG_PAX_SEGMEXEC
32030 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32031 + pax_task_size = SEGMEXEC_TASK_SIZE;
32032 +#endif
32033 +
32034 + pax_task_size -= PAGE_SIZE;
32035 +
32036 + if (len > pax_task_size)
32037 return -ENOMEM;
32038
32039 if (flags & MAP_FIXED) {
32040 @@ -156,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32041 return addr;
32042 }
32043
32044 +#ifdef CONFIG_PAX_RANDMMAP
32045 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32046 +#endif
32047 +
32048 if (addr) {
32049 addr = ALIGN(addr, huge_page_size(h));
32050 vma = find_vma(mm, addr);
32051 - if (TASK_SIZE - len >= addr &&
32052 - (!vma || addr + len <= vma->vm_start))
32053 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32054 return addr;
32055 }
32056 if (mm->get_unmapped_area == arch_get_unmapped_area)
32057 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32058 - pgoff, flags);
32059 + pgoff, flags, offset);
32060 else
32061 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32062 - pgoff, flags);
32063 + pgoff, flags, offset);
32064 }
32065 #endif /* CONFIG_HUGETLB_PAGE */
32066
32067 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32068 index f971306..e83e0f6 100644
32069 --- a/arch/x86/mm/init.c
32070 +++ b/arch/x86/mm/init.c
32071 @@ -4,6 +4,7 @@
32072 #include <linux/swap.h>
32073 #include <linux/memblock.h>
32074 #include <linux/bootmem.h> /* for max_low_pfn */
32075 +#include <linux/tboot.h>
32076
32077 #include <asm/cacheflush.h>
32078 #include <asm/e820.h>
32079 @@ -17,6 +18,8 @@
32080 #include <asm/proto.h>
32081 #include <asm/dma.h> /* for MAX_DMA_PFN */
32082 #include <asm/microcode.h>
32083 +#include <asm/desc.h>
32084 +#include <asm/bios_ebda.h>
32085
32086 #include "mm_internal.h"
32087
32088 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32089 early_ioremap_page_table_range_init();
32090 #endif
32091
32092 +#ifdef CONFIG_PAX_PER_CPU_PGD
32093 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32094 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32095 + KERNEL_PGD_PTRS);
32096 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32097 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32098 + KERNEL_PGD_PTRS);
32099 + load_cr3(get_cpu_pgd(0, kernel));
32100 +#else
32101 load_cr3(swapper_pg_dir);
32102 +#endif
32103 +
32104 __flush_tlb_all();
32105
32106 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32107 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32108 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32109 * mmio resources as well as potential bios/acpi data regions.
32110 */
32111 +
32112 +#ifdef CONFIG_GRKERNSEC_KMEM
32113 +static unsigned int ebda_start __read_only;
32114 +static unsigned int ebda_end __read_only;
32115 +#endif
32116 +
32117 int devmem_is_allowed(unsigned long pagenr)
32118 {
32119 - if (pagenr < 256)
32120 +#ifdef CONFIG_GRKERNSEC_KMEM
32121 + /* allow BDA */
32122 + if (!pagenr)
32123 return 1;
32124 + /* allow EBDA */
32125 + if (pagenr >= ebda_start && pagenr < ebda_end)
32126 + return 1;
32127 + /* if tboot is in use, allow access to its hardcoded serial log range */
32128 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32129 + return 1;
32130 +#else
32131 + if (!pagenr)
32132 + return 1;
32133 +#ifdef CONFIG_VM86
32134 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32135 + return 1;
32136 +#endif
32137 +#endif
32138 +
32139 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32140 + return 1;
32141 +#ifdef CONFIG_GRKERNSEC_KMEM
32142 + /* throw out everything else below 1MB */
32143 + if (pagenr <= 256)
32144 + return 0;
32145 +#endif
32146 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32147 return 0;
32148 if (!page_is_ram(pagenr))
32149 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32150 #endif
32151 }
32152
32153 +#ifdef CONFIG_GRKERNSEC_KMEM
32154 +static inline void gr_init_ebda(void)
32155 +{
32156 + unsigned int ebda_addr;
32157 + unsigned int ebda_size = 0;
32158 +
32159 + ebda_addr = get_bios_ebda();
32160 + if (ebda_addr) {
32161 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32162 + ebda_size <<= 10;
32163 + }
32164 + if (ebda_addr && ebda_size) {
32165 + ebda_start = ebda_addr >> PAGE_SHIFT;
32166 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32167 + } else {
32168 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32169 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32170 + }
32171 +}
32172 +#else
32173 +static inline void gr_init_ebda(void) { }
32174 +#endif
32175 +
32176 void free_initmem(void)
32177 {
32178 +#ifdef CONFIG_PAX_KERNEXEC
32179 +#ifdef CONFIG_X86_32
32180 + /* PaX: limit KERNEL_CS to actual size */
32181 + unsigned long addr, limit;
32182 + struct desc_struct d;
32183 + int cpu;
32184 +#else
32185 + pgd_t *pgd;
32186 + pud_t *pud;
32187 + pmd_t *pmd;
32188 + unsigned long addr, end;
32189 +#endif
32190 +#endif
32191 +
32192 + gr_init_ebda();
32193 +
32194 +#ifdef CONFIG_PAX_KERNEXEC
32195 +#ifdef CONFIG_X86_32
32196 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32197 + limit = (limit - 1UL) >> PAGE_SHIFT;
32198 +
32199 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32200 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32201 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32202 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32203 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32204 + }
32205 +
32206 + /* PaX: make KERNEL_CS read-only */
32207 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32208 + if (!paravirt_enabled())
32209 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32210 +/*
32211 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32212 + pgd = pgd_offset_k(addr);
32213 + pud = pud_offset(pgd, addr);
32214 + pmd = pmd_offset(pud, addr);
32215 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32216 + }
32217 +*/
32218 +#ifdef CONFIG_X86_PAE
32219 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32220 +/*
32221 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32222 + pgd = pgd_offset_k(addr);
32223 + pud = pud_offset(pgd, addr);
32224 + pmd = pmd_offset(pud, addr);
32225 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32226 + }
32227 +*/
32228 +#endif
32229 +
32230 +#ifdef CONFIG_MODULES
32231 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32232 +#endif
32233 +
32234 +#else
32235 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32236 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32237 + pgd = pgd_offset_k(addr);
32238 + pud = pud_offset(pgd, addr);
32239 + pmd = pmd_offset(pud, addr);
32240 + if (!pmd_present(*pmd))
32241 + continue;
32242 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32243 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32244 + else
32245 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32246 + }
32247 +
32248 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32249 + end = addr + KERNEL_IMAGE_SIZE;
32250 + for (; addr < end; addr += PMD_SIZE) {
32251 + pgd = pgd_offset_k(addr);
32252 + pud = pud_offset(pgd, addr);
32253 + pmd = pmd_offset(pud, addr);
32254 + if (!pmd_present(*pmd))
32255 + continue;
32256 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32257 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32258 + }
32259 +#endif
32260 +
32261 + flush_tlb_all();
32262 +#endif
32263 +
32264 free_init_pages("unused kernel",
32265 (unsigned long)(&__init_begin),
32266 (unsigned long)(&__init_end));
32267 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32268 index e395048..cd38278 100644
32269 --- a/arch/x86/mm/init_32.c
32270 +++ b/arch/x86/mm/init_32.c
32271 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32272 bool __read_mostly __vmalloc_start_set = false;
32273
32274 /*
32275 - * Creates a middle page table and puts a pointer to it in the
32276 - * given global directory entry. This only returns the gd entry
32277 - * in non-PAE compilation mode, since the middle layer is folded.
32278 - */
32279 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32280 -{
32281 - pud_t *pud;
32282 - pmd_t *pmd_table;
32283 -
32284 -#ifdef CONFIG_X86_PAE
32285 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32286 - pmd_table = (pmd_t *)alloc_low_page();
32287 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32288 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32289 - pud = pud_offset(pgd, 0);
32290 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32291 -
32292 - return pmd_table;
32293 - }
32294 -#endif
32295 - pud = pud_offset(pgd, 0);
32296 - pmd_table = pmd_offset(pud, 0);
32297 -
32298 - return pmd_table;
32299 -}
32300 -
32301 -/*
32302 * Create a page table and place a pointer to it in a middle page
32303 * directory entry:
32304 */
32305 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32306 pte_t *page_table = (pte_t *)alloc_low_page();
32307
32308 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32309 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32310 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32311 +#else
32312 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32313 +#endif
32314 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32315 }
32316
32317 return pte_offset_kernel(pmd, 0);
32318 }
32319
32320 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32321 +{
32322 + pud_t *pud;
32323 + pmd_t *pmd_table;
32324 +
32325 + pud = pud_offset(pgd, 0);
32326 + pmd_table = pmd_offset(pud, 0);
32327 +
32328 + return pmd_table;
32329 +}
32330 +
32331 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32332 {
32333 int pgd_idx = pgd_index(vaddr);
32334 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32335 int pgd_idx, pmd_idx;
32336 unsigned long vaddr;
32337 pgd_t *pgd;
32338 + pud_t *pud;
32339 pmd_t *pmd;
32340 pte_t *pte = NULL;
32341 unsigned long count = page_table_range_init_count(start, end);
32342 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32343 pgd = pgd_base + pgd_idx;
32344
32345 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32346 - pmd = one_md_table_init(pgd);
32347 - pmd = pmd + pmd_index(vaddr);
32348 + pud = pud_offset(pgd, vaddr);
32349 + pmd = pmd_offset(pud, vaddr);
32350 +
32351 +#ifdef CONFIG_X86_PAE
32352 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32353 +#endif
32354 +
32355 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32356 pmd++, pmd_idx++) {
32357 pte = page_table_kmap_check(one_page_table_init(pmd),
32358 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32359 }
32360 }
32361
32362 -static inline int is_kernel_text(unsigned long addr)
32363 +static inline int is_kernel_text(unsigned long start, unsigned long end)
32364 {
32365 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32366 - return 1;
32367 - return 0;
32368 + if ((start >= ktla_ktva((unsigned long)_etext) ||
32369 + end <= ktla_ktva((unsigned long)_stext)) &&
32370 + (start >= ktla_ktva((unsigned long)_einittext) ||
32371 + end <= ktla_ktva((unsigned long)_sinittext)) &&
32372 +
32373 +#ifdef CONFIG_ACPI_SLEEP
32374 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32375 +#endif
32376 +
32377 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32378 + return 0;
32379 + return 1;
32380 }
32381
32382 /*
32383 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32384 unsigned long last_map_addr = end;
32385 unsigned long start_pfn, end_pfn;
32386 pgd_t *pgd_base = swapper_pg_dir;
32387 - int pgd_idx, pmd_idx, pte_ofs;
32388 + unsigned int pgd_idx, pmd_idx, pte_ofs;
32389 unsigned long pfn;
32390 pgd_t *pgd;
32391 + pud_t *pud;
32392 pmd_t *pmd;
32393 pte_t *pte;
32394 unsigned pages_2m, pages_4k;
32395 @@ -291,8 +295,13 @@ repeat:
32396 pfn = start_pfn;
32397 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32398 pgd = pgd_base + pgd_idx;
32399 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32400 - pmd = one_md_table_init(pgd);
32401 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32402 + pud = pud_offset(pgd, 0);
32403 + pmd = pmd_offset(pud, 0);
32404 +
32405 +#ifdef CONFIG_X86_PAE
32406 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32407 +#endif
32408
32409 if (pfn >= end_pfn)
32410 continue;
32411 @@ -304,14 +313,13 @@ repeat:
32412 #endif
32413 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32414 pmd++, pmd_idx++) {
32415 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32416 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32417
32418 /*
32419 * Map with big pages if possible, otherwise
32420 * create normal page tables:
32421 */
32422 if (use_pse) {
32423 - unsigned int addr2;
32424 pgprot_t prot = PAGE_KERNEL_LARGE;
32425 /*
32426 * first pass will use the same initial
32427 @@ -322,11 +330,7 @@ repeat:
32428 _PAGE_PSE);
32429
32430 pfn &= PMD_MASK >> PAGE_SHIFT;
32431 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32432 - PAGE_OFFSET + PAGE_SIZE-1;
32433 -
32434 - if (is_kernel_text(addr) ||
32435 - is_kernel_text(addr2))
32436 + if (is_kernel_text(address, address + PMD_SIZE))
32437 prot = PAGE_KERNEL_LARGE_EXEC;
32438
32439 pages_2m++;
32440 @@ -343,7 +347,7 @@ repeat:
32441 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32442 pte += pte_ofs;
32443 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32444 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32445 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32446 pgprot_t prot = PAGE_KERNEL;
32447 /*
32448 * first pass will use the same initial
32449 @@ -351,7 +355,7 @@ repeat:
32450 */
32451 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32452
32453 - if (is_kernel_text(addr))
32454 + if (is_kernel_text(address, address + PAGE_SIZE))
32455 prot = PAGE_KERNEL_EXEC;
32456
32457 pages_4k++;
32458 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32459
32460 pud = pud_offset(pgd, va);
32461 pmd = pmd_offset(pud, va);
32462 - if (!pmd_present(*pmd))
32463 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32464 break;
32465
32466 /* should not be large page here */
32467 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32468
32469 static void __init pagetable_init(void)
32470 {
32471 - pgd_t *pgd_base = swapper_pg_dir;
32472 -
32473 - permanent_kmaps_init(pgd_base);
32474 + permanent_kmaps_init(swapper_pg_dir);
32475 }
32476
32477 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32478 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32479 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32480
32481 /* user-defined highmem size */
32482 @@ -787,10 +789,10 @@ void __init mem_init(void)
32483 ((unsigned long)&__init_end -
32484 (unsigned long)&__init_begin) >> 10,
32485
32486 - (unsigned long)&_etext, (unsigned long)&_edata,
32487 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32488 + (unsigned long)&_sdata, (unsigned long)&_edata,
32489 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32490
32491 - (unsigned long)&_text, (unsigned long)&_etext,
32492 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32493 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32494
32495 /*
32496 @@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32497 if (!kernel_set_to_readonly)
32498 return;
32499
32500 + start = ktla_ktva(start);
32501 pr_debug("Set kernel text: %lx - %lx for read write\n",
32502 start, start+size);
32503
32504 @@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32505 if (!kernel_set_to_readonly)
32506 return;
32507
32508 + start = ktla_ktva(start);
32509 pr_debug("Set kernel text: %lx - %lx for read only\n",
32510 start, start+size);
32511
32512 @@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32513 unsigned long start = PFN_ALIGN(_text);
32514 unsigned long size = PFN_ALIGN(_etext) - start;
32515
32516 + start = ktla_ktva(start);
32517 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32518 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32519 size >> 10);
32520 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32521 index f35c66c..84b95ef 100644
32522 --- a/arch/x86/mm/init_64.c
32523 +++ b/arch/x86/mm/init_64.c
32524 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32525 * around without checking the pgd every time.
32526 */
32527
32528 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32529 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32530 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32531
32532 int force_personality32;
32533 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32534
32535 for (address = start; address <= end; address += PGDIR_SIZE) {
32536 const pgd_t *pgd_ref = pgd_offset_k(address);
32537 +
32538 +#ifdef CONFIG_PAX_PER_CPU_PGD
32539 + unsigned long cpu;
32540 +#else
32541 struct page *page;
32542 +#endif
32543
32544 if (pgd_none(*pgd_ref))
32545 continue;
32546
32547 spin_lock(&pgd_lock);
32548 +
32549 +#ifdef CONFIG_PAX_PER_CPU_PGD
32550 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32551 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32552 +
32553 + if (pgd_none(*pgd))
32554 + set_pgd(pgd, *pgd_ref);
32555 + else
32556 + BUG_ON(pgd_page_vaddr(*pgd)
32557 + != pgd_page_vaddr(*pgd_ref));
32558 + pgd = pgd_offset_cpu(cpu, kernel, address);
32559 +#else
32560 list_for_each_entry(page, &pgd_list, lru) {
32561 pgd_t *pgd;
32562 spinlock_t *pgt_lock;
32563 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32564 /* the pgt_lock only for Xen */
32565 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32566 spin_lock(pgt_lock);
32567 +#endif
32568
32569 if (pgd_none(*pgd))
32570 set_pgd(pgd, *pgd_ref);
32571 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32572 BUG_ON(pgd_page_vaddr(*pgd)
32573 != pgd_page_vaddr(*pgd_ref));
32574
32575 +#ifndef CONFIG_PAX_PER_CPU_PGD
32576 spin_unlock(pgt_lock);
32577 +#endif
32578 +
32579 }
32580 spin_unlock(&pgd_lock);
32581 }
32582 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32583 {
32584 if (pgd_none(*pgd)) {
32585 pud_t *pud = (pud_t *)spp_getpage();
32586 - pgd_populate(&init_mm, pgd, pud);
32587 + pgd_populate_kernel(&init_mm, pgd, pud);
32588 if (pud != pud_offset(pgd, 0))
32589 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32590 pud, pud_offset(pgd, 0));
32591 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32592 {
32593 if (pud_none(*pud)) {
32594 pmd_t *pmd = (pmd_t *) spp_getpage();
32595 - pud_populate(&init_mm, pud, pmd);
32596 + pud_populate_kernel(&init_mm, pud, pmd);
32597 if (pmd != pmd_offset(pud, 0))
32598 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32599 pmd, pmd_offset(pud, 0));
32600 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32601 pmd = fill_pmd(pud, vaddr);
32602 pte = fill_pte(pmd, vaddr);
32603
32604 + pax_open_kernel();
32605 set_pte(pte, new_pte);
32606 + pax_close_kernel();
32607
32608 /*
32609 * It's enough to flush this one mapping.
32610 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32611 pgd = pgd_offset_k((unsigned long)__va(phys));
32612 if (pgd_none(*pgd)) {
32613 pud = (pud_t *) spp_getpage();
32614 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32615 - _PAGE_USER));
32616 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32617 }
32618 pud = pud_offset(pgd, (unsigned long)__va(phys));
32619 if (pud_none(*pud)) {
32620 pmd = (pmd_t *) spp_getpage();
32621 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32622 - _PAGE_USER));
32623 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32624 }
32625 pmd = pmd_offset(pud, phys);
32626 BUG_ON(!pmd_none(*pmd));
32627 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32628 prot);
32629
32630 spin_lock(&init_mm.page_table_lock);
32631 - pud_populate(&init_mm, pud, pmd);
32632 + pud_populate_kernel(&init_mm, pud, pmd);
32633 spin_unlock(&init_mm.page_table_lock);
32634 }
32635 __flush_tlb_all();
32636 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32637 page_size_mask);
32638
32639 spin_lock(&init_mm.page_table_lock);
32640 - pgd_populate(&init_mm, pgd, pud);
32641 + pgd_populate_kernel(&init_mm, pgd, pud);
32642 spin_unlock(&init_mm.page_table_lock);
32643 pgd_changed = true;
32644 }
32645 @@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32646 static struct vm_area_struct gate_vma = {
32647 .vm_start = VSYSCALL_START,
32648 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32649 - .vm_page_prot = PAGE_READONLY_EXEC,
32650 - .vm_flags = VM_READ | VM_EXEC
32651 + .vm_page_prot = PAGE_READONLY,
32652 + .vm_flags = VM_READ
32653 };
32654
32655 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32656 @@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32657
32658 const char *arch_vma_name(struct vm_area_struct *vma)
32659 {
32660 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32661 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32662 return "[vdso]";
32663 if (vma == &gate_vma)
32664 return "[vsyscall]";
32665 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32666 index 7b179b4..6bd17777 100644
32667 --- a/arch/x86/mm/iomap_32.c
32668 +++ b/arch/x86/mm/iomap_32.c
32669 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32670 type = kmap_atomic_idx_push();
32671 idx = type + KM_TYPE_NR * smp_processor_id();
32672 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32673 +
32674 + pax_open_kernel();
32675 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32676 + pax_close_kernel();
32677 +
32678 arch_flush_lazy_mmu_mode();
32679
32680 return (void *)vaddr;
32681 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32682 index 799580c..72f9fe0 100644
32683 --- a/arch/x86/mm/ioremap.c
32684 +++ b/arch/x86/mm/ioremap.c
32685 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32686 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32687 int is_ram = page_is_ram(pfn);
32688
32689 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32690 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32691 return NULL;
32692 WARN_ON_ONCE(is_ram);
32693 }
32694 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32695 *
32696 * Caller must ensure there is only one unmapping for the same pointer.
32697 */
32698 -void iounmap(volatile void __iomem *addr)
32699 +void iounmap(const volatile void __iomem *addr)
32700 {
32701 struct vm_struct *p, *o;
32702
32703 @@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32704
32705 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32706 if (page_is_ram(start >> PAGE_SHIFT))
32707 +#ifdef CONFIG_HIGHMEM
32708 + if ((start >> PAGE_SHIFT) < max_low_pfn)
32709 +#endif
32710 return __va(phys);
32711
32712 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32713 @@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32714 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32715 {
32716 if (page_is_ram(phys >> PAGE_SHIFT))
32717 +#ifdef CONFIG_HIGHMEM
32718 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
32719 +#endif
32720 return;
32721
32722 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32723 @@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32724 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32725
32726 static __initdata int after_paging_init;
32727 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32728 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32729
32730 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32731 {
32732 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32733 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32734
32735 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32736 - memset(bm_pte, 0, sizeof(bm_pte));
32737 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
32738 + pmd_populate_user(&init_mm, pmd, bm_pte);
32739
32740 /*
32741 * The boot-ioremap range spans multiple pmds, for which
32742 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32743 index d87dd6d..bf3fa66 100644
32744 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
32745 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32746 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32747 * memory (e.g. tracked pages)? For now, we need this to avoid
32748 * invoking kmemcheck for PnP BIOS calls.
32749 */
32750 - if (regs->flags & X86_VM_MASK)
32751 + if (v8086_mode(regs))
32752 return false;
32753 - if (regs->cs != __KERNEL_CS)
32754 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32755 return false;
32756
32757 pte = kmemcheck_pte_lookup(address);
32758 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32759 index 25e7e13..1964579 100644
32760 --- a/arch/x86/mm/mmap.c
32761 +++ b/arch/x86/mm/mmap.c
32762 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32763 * Leave an at least ~128 MB hole with possible stack randomization.
32764 */
32765 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32766 -#define MAX_GAP (TASK_SIZE/6*5)
32767 +#define MAX_GAP (pax_task_size/6*5)
32768
32769 static int mmap_is_legacy(void)
32770 {
32771 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32772 return rnd << PAGE_SHIFT;
32773 }
32774
32775 -static unsigned long mmap_base(void)
32776 +static unsigned long mmap_base(struct mm_struct *mm)
32777 {
32778 unsigned long gap = rlimit(RLIMIT_STACK);
32779 + unsigned long pax_task_size = TASK_SIZE;
32780 +
32781 +#ifdef CONFIG_PAX_SEGMEXEC
32782 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32783 + pax_task_size = SEGMEXEC_TASK_SIZE;
32784 +#endif
32785
32786 if (gap < MIN_GAP)
32787 gap = MIN_GAP;
32788 else if (gap > MAX_GAP)
32789 gap = MAX_GAP;
32790
32791 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32792 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32793 }
32794
32795 /*
32796 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32797 * does, but not when emulating X86_32
32798 */
32799 -static unsigned long mmap_legacy_base(void)
32800 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
32801 {
32802 - if (mmap_is_ia32())
32803 + if (mmap_is_ia32()) {
32804 +
32805 +#ifdef CONFIG_PAX_SEGMEXEC
32806 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32807 + return SEGMEXEC_TASK_UNMAPPED_BASE;
32808 + else
32809 +#endif
32810 +
32811 return TASK_UNMAPPED_BASE;
32812 - else
32813 + } else
32814 return TASK_UNMAPPED_BASE + mmap_rnd();
32815 }
32816
32817 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32818 */
32819 void arch_pick_mmap_layout(struct mm_struct *mm)
32820 {
32821 - mm->mmap_legacy_base = mmap_legacy_base();
32822 - mm->mmap_base = mmap_base();
32823 + mm->mmap_legacy_base = mmap_legacy_base(mm);
32824 + mm->mmap_base = mmap_base(mm);
32825 +
32826 +#ifdef CONFIG_PAX_RANDMMAP
32827 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
32828 + mm->mmap_legacy_base += mm->delta_mmap;
32829 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32830 + }
32831 +#endif
32832
32833 if (mmap_is_legacy()) {
32834 mm->mmap_base = mm->mmap_legacy_base;
32835 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32836 index 0057a7a..95c7edd 100644
32837 --- a/arch/x86/mm/mmio-mod.c
32838 +++ b/arch/x86/mm/mmio-mod.c
32839 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32840 break;
32841 default:
32842 {
32843 - unsigned char *ip = (unsigned char *)instptr;
32844 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32845 my_trace->opcode = MMIO_UNKNOWN_OP;
32846 my_trace->width = 0;
32847 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32848 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32849 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32850 void __iomem *addr)
32851 {
32852 - static atomic_t next_id;
32853 + static atomic_unchecked_t next_id;
32854 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32855 /* These are page-unaligned. */
32856 struct mmiotrace_map map = {
32857 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32858 .private = trace
32859 },
32860 .phys = offset,
32861 - .id = atomic_inc_return(&next_id)
32862 + .id = atomic_inc_return_unchecked(&next_id)
32863 };
32864 map.map_id = trace->id;
32865
32866 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32867 ioremap_trace_core(offset, size, addr);
32868 }
32869
32870 -static void iounmap_trace_core(volatile void __iomem *addr)
32871 +static void iounmap_trace_core(const volatile void __iomem *addr)
32872 {
32873 struct mmiotrace_map map = {
32874 .phys = 0,
32875 @@ -328,7 +328,7 @@ not_enabled:
32876 }
32877 }
32878
32879 -void mmiotrace_iounmap(volatile void __iomem *addr)
32880 +void mmiotrace_iounmap(const volatile void __iomem *addr)
32881 {
32882 might_sleep();
32883 if (is_enabled()) /* recheck and proper locking in *_core() */
32884 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32885 index 27aa0455..0eb1406 100644
32886 --- a/arch/x86/mm/numa.c
32887 +++ b/arch/x86/mm/numa.c
32888 @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32889 return true;
32890 }
32891
32892 -static int __init numa_register_memblks(struct numa_meminfo *mi)
32893 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32894 {
32895 unsigned long uninitialized_var(pfn_align);
32896 int i, nid;
32897 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32898 index 461bc82..4e091a3 100644
32899 --- a/arch/x86/mm/pageattr-test.c
32900 +++ b/arch/x86/mm/pageattr-test.c
32901 @@ -35,7 +35,7 @@ enum {
32902
32903 static int pte_testbit(pte_t pte)
32904 {
32905 - return pte_flags(pte) & _PAGE_UNUSED1;
32906 + return pte_flags(pte) & _PAGE_CPA_TEST;
32907 }
32908
32909 struct split_state {
32910 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32911 index a348868..3c64310 100644
32912 --- a/arch/x86/mm/pageattr.c
32913 +++ b/arch/x86/mm/pageattr.c
32914 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32915 */
32916 #ifdef CONFIG_PCI_BIOS
32917 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32918 - pgprot_val(forbidden) |= _PAGE_NX;
32919 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32920 #endif
32921
32922 /*
32923 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32924 * Does not cover __inittext since that is gone later on. On
32925 * 64bit we do not enforce !NX on the low mapping
32926 */
32927 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
32928 - pgprot_val(forbidden) |= _PAGE_NX;
32929 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32930 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32931
32932 +#ifdef CONFIG_DEBUG_RODATA
32933 /*
32934 * The .rodata section needs to be read-only. Using the pfn
32935 * catches all aliases.
32936 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32937 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32938 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32939 pgprot_val(forbidden) |= _PAGE_RW;
32940 +#endif
32941
32942 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32943 /*
32944 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32945 }
32946 #endif
32947
32948 +#ifdef CONFIG_PAX_KERNEXEC
32949 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32950 + pgprot_val(forbidden) |= _PAGE_RW;
32951 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32952 + }
32953 +#endif
32954 +
32955 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32956
32957 return prot;
32958 @@ -416,23 +425,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32959 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32960 {
32961 /* change init_mm */
32962 + pax_open_kernel();
32963 set_pte_atomic(kpte, pte);
32964 +
32965 #ifdef CONFIG_X86_32
32966 if (!SHARED_KERNEL_PMD) {
32967 +
32968 +#ifdef CONFIG_PAX_PER_CPU_PGD
32969 + unsigned long cpu;
32970 +#else
32971 struct page *page;
32972 +#endif
32973
32974 +#ifdef CONFIG_PAX_PER_CPU_PGD
32975 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32976 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
32977 +#else
32978 list_for_each_entry(page, &pgd_list, lru) {
32979 - pgd_t *pgd;
32980 + pgd_t *pgd = (pgd_t *)page_address(page);
32981 +#endif
32982 +
32983 pud_t *pud;
32984 pmd_t *pmd;
32985
32986 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
32987 + pgd += pgd_index(address);
32988 pud = pud_offset(pgd, address);
32989 pmd = pmd_offset(pud, address);
32990 set_pte_atomic((pte_t *)pmd, pte);
32991 }
32992 }
32993 #endif
32994 + pax_close_kernel();
32995 }
32996
32997 static int
32998 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
32999 index 6574388..87e9bef 100644
33000 --- a/arch/x86/mm/pat.c
33001 +++ b/arch/x86/mm/pat.c
33002 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33003
33004 if (!entry) {
33005 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33006 - current->comm, current->pid, start, end - 1);
33007 + current->comm, task_pid_nr(current), start, end - 1);
33008 return -EINVAL;
33009 }
33010
33011 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33012
33013 while (cursor < to) {
33014 if (!devmem_is_allowed(pfn)) {
33015 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33016 - current->comm, from, to - 1);
33017 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33018 + current->comm, from, to - 1, cursor);
33019 return 0;
33020 }
33021 cursor += PAGE_SIZE;
33022 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33023 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33024 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33025 "for [mem %#010Lx-%#010Lx]\n",
33026 - current->comm, current->pid,
33027 + current->comm, task_pid_nr(current),
33028 cattr_name(flags),
33029 base, (unsigned long long)(base + size-1));
33030 return -EINVAL;
33031 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33032 flags = lookup_memtype(paddr);
33033 if (want_flags != flags) {
33034 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33035 - current->comm, current->pid,
33036 + current->comm, task_pid_nr(current),
33037 cattr_name(want_flags),
33038 (unsigned long long)paddr,
33039 (unsigned long long)(paddr + size - 1),
33040 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33041 free_memtype(paddr, paddr + size);
33042 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33043 " for [mem %#010Lx-%#010Lx], got %s\n",
33044 - current->comm, current->pid,
33045 + current->comm, task_pid_nr(current),
33046 cattr_name(want_flags),
33047 (unsigned long long)paddr,
33048 (unsigned long long)(paddr + size - 1),
33049 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33050 index 415f6c4..d319983 100644
33051 --- a/arch/x86/mm/pat_rbtree.c
33052 +++ b/arch/x86/mm/pat_rbtree.c
33053 @@ -160,7 +160,7 @@ success:
33054
33055 failure:
33056 printk(KERN_INFO "%s:%d conflicting memory types "
33057 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33058 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33059 end, cattr_name(found_type), cattr_name(match->type));
33060 return -EBUSY;
33061 }
33062 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33063 index 9f0614d..92ae64a 100644
33064 --- a/arch/x86/mm/pf_in.c
33065 +++ b/arch/x86/mm/pf_in.c
33066 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33067 int i;
33068 enum reason_type rv = OTHERS;
33069
33070 - p = (unsigned char *)ins_addr;
33071 + p = (unsigned char *)ktla_ktva(ins_addr);
33072 p += skip_prefix(p, &prf);
33073 p += get_opcode(p, &opcode);
33074
33075 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33076 struct prefix_bits prf;
33077 int i;
33078
33079 - p = (unsigned char *)ins_addr;
33080 + p = (unsigned char *)ktla_ktva(ins_addr);
33081 p += skip_prefix(p, &prf);
33082 p += get_opcode(p, &opcode);
33083
33084 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33085 struct prefix_bits prf;
33086 int i;
33087
33088 - p = (unsigned char *)ins_addr;
33089 + p = (unsigned char *)ktla_ktva(ins_addr);
33090 p += skip_prefix(p, &prf);
33091 p += get_opcode(p, &opcode);
33092
33093 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33094 struct prefix_bits prf;
33095 int i;
33096
33097 - p = (unsigned char *)ins_addr;
33098 + p = (unsigned char *)ktla_ktva(ins_addr);
33099 p += skip_prefix(p, &prf);
33100 p += get_opcode(p, &opcode);
33101 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33102 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33103 struct prefix_bits prf;
33104 int i;
33105
33106 - p = (unsigned char *)ins_addr;
33107 + p = (unsigned char *)ktla_ktva(ins_addr);
33108 p += skip_prefix(p, &prf);
33109 p += get_opcode(p, &opcode);
33110 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33111 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33112 index c96314a..433b127 100644
33113 --- a/arch/x86/mm/pgtable.c
33114 +++ b/arch/x86/mm/pgtable.c
33115 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33116 list_del(&page->lru);
33117 }
33118
33119 -#define UNSHARED_PTRS_PER_PGD \
33120 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33121 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33122 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33123
33124 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33125 +{
33126 + unsigned int count = USER_PGD_PTRS;
33127
33128 + if (!pax_user_shadow_base)
33129 + return;
33130 +
33131 + while (count--)
33132 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33133 +}
33134 +#endif
33135 +
33136 +#ifdef CONFIG_PAX_PER_CPU_PGD
33137 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33138 +{
33139 + unsigned int count = USER_PGD_PTRS;
33140 +
33141 + while (count--) {
33142 + pgd_t pgd;
33143 +
33144 +#ifdef CONFIG_X86_64
33145 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33146 +#else
33147 + pgd = *src++;
33148 +#endif
33149 +
33150 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33151 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33152 +#endif
33153 +
33154 + *dst++ = pgd;
33155 + }
33156 +
33157 +}
33158 +#endif
33159 +
33160 +#ifdef CONFIG_X86_64
33161 +#define pxd_t pud_t
33162 +#define pyd_t pgd_t
33163 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33164 +#define pgtable_pxd_page_ctor(page) true
33165 +#define pgtable_pxd_page_dtor(page)
33166 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33167 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33168 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33169 +#define PYD_SIZE PGDIR_SIZE
33170 +#else
33171 +#define pxd_t pmd_t
33172 +#define pyd_t pud_t
33173 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33174 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33175 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33176 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33177 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33178 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33179 +#define PYD_SIZE PUD_SIZE
33180 +#endif
33181 +
33182 +#ifdef CONFIG_PAX_PER_CPU_PGD
33183 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33184 +static inline void pgd_dtor(pgd_t *pgd) {}
33185 +#else
33186 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33187 {
33188 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33189 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33190 pgd_list_del(pgd);
33191 spin_unlock(&pgd_lock);
33192 }
33193 +#endif
33194
33195 /*
33196 * List of all pgd's needed for non-PAE so it can invalidate entries
33197 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33198 * -- nyc
33199 */
33200
33201 -#ifdef CONFIG_X86_PAE
33202 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33203 /*
33204 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33205 * updating the top-level pagetable entries to guarantee the
33206 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33207 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33208 * and initialize the kernel pmds here.
33209 */
33210 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33211 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33212
33213 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33214 {
33215 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33216 */
33217 flush_tlb_mm(mm);
33218 }
33219 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33220 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33221 #else /* !CONFIG_X86_PAE */
33222
33223 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33224 -#define PREALLOCATED_PMDS 0
33225 +#define PREALLOCATED_PXDS 0
33226
33227 #endif /* CONFIG_X86_PAE */
33228
33229 -static void free_pmds(pmd_t *pmds[])
33230 +static void free_pxds(pxd_t *pxds[])
33231 {
33232 int i;
33233
33234 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33235 - if (pmds[i]) {
33236 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33237 - free_page((unsigned long)pmds[i]);
33238 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33239 + if (pxds[i]) {
33240 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33241 + free_page((unsigned long)pxds[i]);
33242 }
33243 }
33244
33245 -static int preallocate_pmds(pmd_t *pmds[])
33246 +static int preallocate_pxds(pxd_t *pxds[])
33247 {
33248 int i;
33249 bool failed = false;
33250
33251 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33252 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33253 - if (!pmd)
33254 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33255 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33256 + if (!pxd)
33257 failed = true;
33258 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33259 - free_page((unsigned long)pmd);
33260 - pmd = NULL;
33261 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33262 + free_page((unsigned long)pxd);
33263 + pxd = NULL;
33264 failed = true;
33265 }
33266 - pmds[i] = pmd;
33267 + pxds[i] = pxd;
33268 }
33269
33270 if (failed) {
33271 - free_pmds(pmds);
33272 + free_pxds(pxds);
33273 return -ENOMEM;
33274 }
33275
33276 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33277 * preallocate which never got a corresponding vma will need to be
33278 * freed manually.
33279 */
33280 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33281 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33282 {
33283 int i;
33284
33285 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33286 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33287 pgd_t pgd = pgdp[i];
33288
33289 if (pgd_val(pgd) != 0) {
33290 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33291 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33292
33293 - pgdp[i] = native_make_pgd(0);
33294 + set_pgd(pgdp + i, native_make_pgd(0));
33295
33296 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33297 - pmd_free(mm, pmd);
33298 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33299 + pxd_free(mm, pxd);
33300 }
33301 }
33302 }
33303
33304 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33305 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33306 {
33307 - pud_t *pud;
33308 + pyd_t *pyd;
33309 int i;
33310
33311 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33312 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33313 return;
33314
33315 - pud = pud_offset(pgd, 0);
33316 -
33317 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33318 - pmd_t *pmd = pmds[i];
33319 +#ifdef CONFIG_X86_64
33320 + pyd = pyd_offset(mm, 0L);
33321 +#else
33322 + pyd = pyd_offset(pgd, 0L);
33323 +#endif
33324
33325 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33326 + pxd_t *pxd = pxds[i];
33327 if (i >= KERNEL_PGD_BOUNDARY)
33328 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33329 - sizeof(pmd_t) * PTRS_PER_PMD);
33330 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33331 + sizeof(pxd_t) * PTRS_PER_PMD);
33332
33333 - pud_populate(mm, pud, pmd);
33334 + pyd_populate(mm, pyd, pxd);
33335 }
33336 }
33337
33338 pgd_t *pgd_alloc(struct mm_struct *mm)
33339 {
33340 pgd_t *pgd;
33341 - pmd_t *pmds[PREALLOCATED_PMDS];
33342 + pxd_t *pxds[PREALLOCATED_PXDS];
33343
33344 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33345
33346 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33347
33348 mm->pgd = pgd;
33349
33350 - if (preallocate_pmds(pmds) != 0)
33351 + if (preallocate_pxds(pxds) != 0)
33352 goto out_free_pgd;
33353
33354 if (paravirt_pgd_alloc(mm) != 0)
33355 - goto out_free_pmds;
33356 + goto out_free_pxds;
33357
33358 /*
33359 * Make sure that pre-populating the pmds is atomic with
33360 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33361 spin_lock(&pgd_lock);
33362
33363 pgd_ctor(mm, pgd);
33364 - pgd_prepopulate_pmd(mm, pgd, pmds);
33365 + pgd_prepopulate_pxd(mm, pgd, pxds);
33366
33367 spin_unlock(&pgd_lock);
33368
33369 return pgd;
33370
33371 -out_free_pmds:
33372 - free_pmds(pmds);
33373 +out_free_pxds:
33374 + free_pxds(pxds);
33375 out_free_pgd:
33376 free_page((unsigned long)pgd);
33377 out:
33378 @@ -313,7 +380,7 @@ out:
33379
33380 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33381 {
33382 - pgd_mop_up_pmds(mm, pgd);
33383 + pgd_mop_up_pxds(mm, pgd);
33384 pgd_dtor(pgd);
33385 paravirt_pgd_free(mm, pgd);
33386 free_page((unsigned long)pgd);
33387 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33388 index a69bcb8..19068ab 100644
33389 --- a/arch/x86/mm/pgtable_32.c
33390 +++ b/arch/x86/mm/pgtable_32.c
33391 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33392 return;
33393 }
33394 pte = pte_offset_kernel(pmd, vaddr);
33395 +
33396 + pax_open_kernel();
33397 if (pte_val(pteval))
33398 set_pte_at(&init_mm, vaddr, pte, pteval);
33399 else
33400 pte_clear(&init_mm, vaddr, pte);
33401 + pax_close_kernel();
33402
33403 /*
33404 * It's enough to flush this one mapping.
33405 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33406 index e666cbb..61788c45 100644
33407 --- a/arch/x86/mm/physaddr.c
33408 +++ b/arch/x86/mm/physaddr.c
33409 @@ -10,7 +10,7 @@
33410 #ifdef CONFIG_X86_64
33411
33412 #ifdef CONFIG_DEBUG_VIRTUAL
33413 -unsigned long __phys_addr(unsigned long x)
33414 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33415 {
33416 unsigned long y = x - __START_KERNEL_map;
33417
33418 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33419 #else
33420
33421 #ifdef CONFIG_DEBUG_VIRTUAL
33422 -unsigned long __phys_addr(unsigned long x)
33423 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33424 {
33425 unsigned long phys_addr = x - PAGE_OFFSET;
33426 /* VMALLOC_* aren't constants */
33427 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33428 index 90555bf..f5f1828 100644
33429 --- a/arch/x86/mm/setup_nx.c
33430 +++ b/arch/x86/mm/setup_nx.c
33431 @@ -5,8 +5,10 @@
33432 #include <asm/pgtable.h>
33433 #include <asm/proto.h>
33434
33435 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33436 static int disable_nx;
33437
33438 +#ifndef CONFIG_PAX_PAGEEXEC
33439 /*
33440 * noexec = on|off
33441 *
33442 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33443 return 0;
33444 }
33445 early_param("noexec", noexec_setup);
33446 +#endif
33447 +
33448 +#endif
33449
33450 void x86_configure_nx(void)
33451 {
33452 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33453 if (cpu_has_nx && !disable_nx)
33454 __supported_pte_mask |= _PAGE_NX;
33455 else
33456 +#endif
33457 __supported_pte_mask &= ~_PAGE_NX;
33458 }
33459
33460 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33461 index dd8dda1..9e9b0f6 100644
33462 --- a/arch/x86/mm/tlb.c
33463 +++ b/arch/x86/mm/tlb.c
33464 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
33465 BUG();
33466 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33467 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33468 +
33469 +#ifndef CONFIG_PAX_PER_CPU_PGD
33470 load_cr3(swapper_pg_dir);
33471 +#endif
33472 +
33473 }
33474 }
33475 EXPORT_SYMBOL_GPL(leave_mm);
33476 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33477 new file mode 100644
33478 index 0000000..dace51c
33479 --- /dev/null
33480 +++ b/arch/x86/mm/uderef_64.c
33481 @@ -0,0 +1,37 @@
33482 +#include <linux/mm.h>
33483 +#include <asm/pgtable.h>
33484 +#include <asm/uaccess.h>
33485 +
33486 +#ifdef CONFIG_PAX_MEMORY_UDEREF
33487 +/* PaX: due to the special call convention these functions must
33488 + * - remain leaf functions under all configurations,
33489 + * - never be called directly, only dereferenced from the wrappers.
33490 + */
33491 +void __pax_open_userland(void)
33492 +{
33493 + unsigned int cpu;
33494 +
33495 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33496 + return;
33497 +
33498 + cpu = raw_get_cpu();
33499 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33500 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33501 + raw_put_cpu_no_resched();
33502 +}
33503 +EXPORT_SYMBOL(__pax_open_userland);
33504 +
33505 +void __pax_close_userland(void)
33506 +{
33507 + unsigned int cpu;
33508 +
33509 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33510 + return;
33511 +
33512 + cpu = raw_get_cpu();
33513 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33514 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33515 + raw_put_cpu_no_resched();
33516 +}
33517 +EXPORT_SYMBOL(__pax_close_userland);
33518 +#endif
33519 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33520 index 0149575..f746de8 100644
33521 --- a/arch/x86/net/bpf_jit.S
33522 +++ b/arch/x86/net/bpf_jit.S
33523 @@ -9,6 +9,7 @@
33524 */
33525 #include <linux/linkage.h>
33526 #include <asm/dwarf2.h>
33527 +#include <asm/alternative-asm.h>
33528
33529 /*
33530 * Calling convention :
33531 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33532 jle bpf_slow_path_word
33533 mov (SKBDATA,%rsi),%eax
33534 bswap %eax /* ntohl() */
33535 + pax_force_retaddr
33536 ret
33537
33538 sk_load_half:
33539 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33540 jle bpf_slow_path_half
33541 movzwl (SKBDATA,%rsi),%eax
33542 rol $8,%ax # ntohs()
33543 + pax_force_retaddr
33544 ret
33545
33546 sk_load_byte:
33547 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33548 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33549 jle bpf_slow_path_byte
33550 movzbl (SKBDATA,%rsi),%eax
33551 + pax_force_retaddr
33552 ret
33553
33554 /**
33555 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33556 movzbl (SKBDATA,%rsi),%ebx
33557 and $15,%bl
33558 shl $2,%bl
33559 + pax_force_retaddr
33560 ret
33561
33562 /* rsi contains offset and can be scratched */
33563 @@ -109,6 +114,7 @@ bpf_slow_path_word:
33564 js bpf_error
33565 mov -12(%rbp),%eax
33566 bswap %eax
33567 + pax_force_retaddr
33568 ret
33569
33570 bpf_slow_path_half:
33571 @@ -117,12 +123,14 @@ bpf_slow_path_half:
33572 mov -12(%rbp),%ax
33573 rol $8,%ax
33574 movzwl %ax,%eax
33575 + pax_force_retaddr
33576 ret
33577
33578 bpf_slow_path_byte:
33579 bpf_slow_path_common(1)
33580 js bpf_error
33581 movzbl -12(%rbp),%eax
33582 + pax_force_retaddr
33583 ret
33584
33585 bpf_slow_path_byte_msh:
33586 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33587 and $15,%al
33588 shl $2,%al
33589 xchg %eax,%ebx
33590 + pax_force_retaddr
33591 ret
33592
33593 #define sk_negative_common(SIZE) \
33594 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33595 sk_negative_common(4)
33596 mov (%rax), %eax
33597 bswap %eax
33598 + pax_force_retaddr
33599 ret
33600
33601 bpf_slow_path_half_neg:
33602 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33603 mov (%rax),%ax
33604 rol $8,%ax
33605 movzwl %ax,%eax
33606 + pax_force_retaddr
33607 ret
33608
33609 bpf_slow_path_byte_neg:
33610 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33611 .globl sk_load_byte_negative_offset
33612 sk_negative_common(1)
33613 movzbl (%rax), %eax
33614 + pax_force_retaddr
33615 ret
33616
33617 bpf_slow_path_byte_msh_neg:
33618 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33619 and $15,%al
33620 shl $2,%al
33621 xchg %eax,%ebx
33622 + pax_force_retaddr
33623 ret
33624
33625 bpf_error:
33626 @@ -197,4 +210,5 @@ bpf_error:
33627 xor %eax,%eax
33628 mov -8(%rbp),%rbx
33629 leaveq
33630 + pax_force_retaddr
33631 ret
33632 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33633 index 4ed75dd..3cf24f0b 100644
33634 --- a/arch/x86/net/bpf_jit_comp.c
33635 +++ b/arch/x86/net/bpf_jit_comp.c
33636 @@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33637 return ptr + len;
33638 }
33639
33640 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33641 +#define MAX_INSTR_CODE_SIZE 96
33642 +#else
33643 +#define MAX_INSTR_CODE_SIZE 64
33644 +#endif
33645 +
33646 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33647
33648 #define EMIT1(b1) EMIT(b1, 1)
33649 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33650 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33651 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33652 +
33653 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33654 +/* original constant will appear in ecx */
33655 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
33656 +do { \
33657 + /* mov ecx, randkey */ \
33658 + EMIT1(0xb9); \
33659 + EMIT(_key, 4); \
33660 + /* xor ecx, randkey ^ off */ \
33661 + EMIT2(0x81, 0xf1); \
33662 + EMIT((_key) ^ (_off), 4); \
33663 +} while (0)
33664 +
33665 +#define EMIT1_off32(b1, _off) \
33666 +do { \
33667 + switch (b1) { \
33668 + case 0x05: /* add eax, imm32 */ \
33669 + case 0x2d: /* sub eax, imm32 */ \
33670 + case 0x25: /* and eax, imm32 */ \
33671 + case 0x0d: /* or eax, imm32 */ \
33672 + case 0xb8: /* mov eax, imm32 */ \
33673 + case 0x35: /* xor eax, imm32 */ \
33674 + case 0x3d: /* cmp eax, imm32 */ \
33675 + case 0xa9: /* test eax, imm32 */ \
33676 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33677 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33678 + break; \
33679 + case 0xbb: /* mov ebx, imm32 */ \
33680 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33681 + /* mov ebx, ecx */ \
33682 + EMIT2(0x89, 0xcb); \
33683 + break; \
33684 + case 0xbe: /* mov esi, imm32 */ \
33685 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33686 + /* mov esi, ecx */ \
33687 + EMIT2(0x89, 0xce); \
33688 + break; \
33689 + case 0xe8: /* call rel imm32, always to known funcs */ \
33690 + EMIT1(b1); \
33691 + EMIT(_off, 4); \
33692 + break; \
33693 + case 0xe9: /* jmp rel imm32 */ \
33694 + EMIT1(b1); \
33695 + EMIT(_off, 4); \
33696 + /* prevent fall-through, we're not called if off = 0 */ \
33697 + EMIT(0xcccccccc, 4); \
33698 + EMIT(0xcccccccc, 4); \
33699 + break; \
33700 + default: \
33701 + BUILD_BUG(); \
33702 + } \
33703 +} while (0)
33704 +
33705 +#define EMIT2_off32(b1, b2, _off) \
33706 +do { \
33707 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33708 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33709 + EMIT(randkey, 4); \
33710 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33711 + EMIT((_off) - randkey, 4); \
33712 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33713 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33714 + /* imul eax, ecx */ \
33715 + EMIT3(0x0f, 0xaf, 0xc1); \
33716 + } else { \
33717 + BUILD_BUG(); \
33718 + } \
33719 +} while (0)
33720 +#else
33721 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33722 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33723 +#endif
33724
33725 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33726 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33727 @@ -91,6 +168,24 @@ do { \
33728 #define X86_JBE 0x76
33729 #define X86_JA 0x77
33730
33731 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33732 +#define APPEND_FLOW_VERIFY() \
33733 +do { \
33734 + /* mov ecx, randkey */ \
33735 + EMIT1(0xb9); \
33736 + EMIT(randkey, 4); \
33737 + /* cmp ecx, randkey */ \
33738 + EMIT2(0x81, 0xf9); \
33739 + EMIT(randkey, 4); \
33740 + /* jz after 8 int 3s */ \
33741 + EMIT2(0x74, 0x08); \
33742 + EMIT(0xcccccccc, 4); \
33743 + EMIT(0xcccccccc, 4); \
33744 +} while (0)
33745 +#else
33746 +#define APPEND_FLOW_VERIFY() do { } while (0)
33747 +#endif
33748 +
33749 #define EMIT_COND_JMP(op, offset) \
33750 do { \
33751 if (is_near(offset)) \
33752 @@ -98,6 +193,7 @@ do { \
33753 else { \
33754 EMIT2(0x0f, op + 0x10); \
33755 EMIT(offset, 4); /* jxx .+off32 */ \
33756 + APPEND_FLOW_VERIFY(); \
33757 } \
33758 } while (0)
33759
33760 @@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33761 return -1;
33762 }
33763
33764 -struct bpf_binary_header {
33765 - unsigned int pages;
33766 - /* Note : for security reasons, bpf code will follow a randomly
33767 - * sized amount of int3 instructions
33768 - */
33769 - u8 image[];
33770 -};
33771 -
33772 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33773 +/* Note : for security reasons, bpf code will follow a randomly
33774 + * sized amount of int3 instructions
33775 + */
33776 +static u8 *bpf_alloc_binary(unsigned int proglen,
33777 u8 **image_ptr)
33778 {
33779 unsigned int sz, hole;
33780 - struct bpf_binary_header *header;
33781 + u8 *header;
33782
33783 /* Most of BPF filters are really small,
33784 * but if some of them fill a page, allow at least
33785 * 128 extra bytes to insert a random section of int3
33786 */
33787 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33788 - header = module_alloc(sz);
33789 + sz = round_up(proglen + 128, PAGE_SIZE);
33790 + header = module_alloc_exec(sz);
33791 if (!header)
33792 return NULL;
33793
33794 + pax_open_kernel();
33795 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33796 + pax_close_kernel();
33797
33798 - header->pages = sz / PAGE_SIZE;
33799 - hole = sz - (proglen + sizeof(*header));
33800 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33801
33802 /* insert a random number of int3 instructions before BPF code */
33803 - *image_ptr = &header->image[prandom_u32() % hole];
33804 + *image_ptr = &header[prandom_u32() % hole];
33805 return header;
33806 }
33807
33808 void bpf_jit_compile(struct sk_filter *fp)
33809 {
33810 - u8 temp[64];
33811 + u8 temp[MAX_INSTR_CODE_SIZE];
33812 u8 *prog;
33813 unsigned int proglen, oldproglen = 0;
33814 int ilen, i;
33815 int t_offset, f_offset;
33816 u8 t_op, f_op, seen = 0, pass;
33817 u8 *image = NULL;
33818 - struct bpf_binary_header *header = NULL;
33819 + u8 *header = NULL;
33820 u8 *func;
33821 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33822 unsigned int cleanup_addr; /* epilogue code offset */
33823 unsigned int *addrs;
33824 const struct sock_filter *filter = fp->insns;
33825 int flen = fp->len;
33826 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33827 + unsigned int randkey;
33828 +#endif
33829
33830 if (!bpf_jit_enable)
33831 return;
33832 @@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33833 return;
33834
33835 /* Before first pass, make a rough estimation of addrs[]
33836 - * each bpf instruction is translated to less than 64 bytes
33837 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33838 */
33839 for (proglen = 0, i = 0; i < flen; i++) {
33840 - proglen += 64;
33841 + proglen += MAX_INSTR_CODE_SIZE;
33842 addrs[i] = proglen;
33843 }
33844 cleanup_addr = proglen; /* epilogue address */
33845 @@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33846 for (i = 0; i < flen; i++) {
33847 unsigned int K = filter[i].k;
33848
33849 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33850 + randkey = prandom_u32();
33851 +#endif
33852 +
33853 switch (filter[i].code) {
33854 case BPF_S_ALU_ADD_X: /* A += X; */
33855 seen |= SEEN_XREG;
33856 @@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33857 case BPF_S_ALU_MUL_K: /* A *= K */
33858 if (is_imm8(K))
33859 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33860 - else {
33861 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33862 - EMIT(K, 4);
33863 - }
33864 + else
33865 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33866 break;
33867 case BPF_S_ALU_DIV_X: /* A /= X; */
33868 seen |= SEEN_XREG;
33869 @@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33870 break;
33871 }
33872 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33873 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33874 + DILUTE_CONST_SEQUENCE(K, randkey);
33875 +#else
33876 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33877 +#endif
33878 EMIT2(0xf7, 0xf1); /* div %ecx */
33879 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33880 break;
33881 @@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33882 if (K == 1)
33883 break;
33884 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33885 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33886 + DILUTE_CONST_SEQUENCE(K, randkey);
33887 +#else
33888 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33889 +#endif
33890 EMIT2(0xf7, 0xf1); /* div %ecx */
33891 break;
33892 case BPF_S_ALU_AND_X:
33893 @@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33894 if (is_imm8(K)) {
33895 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33896 } else {
33897 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33898 - EMIT(K, 4);
33899 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33900 }
33901 } else {
33902 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33903 @@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33904 if (unlikely(proglen + ilen > oldproglen)) {
33905 pr_err("bpb_jit_compile fatal error\n");
33906 kfree(addrs);
33907 - module_free(NULL, header);
33908 + module_free_exec(NULL, image);
33909 return;
33910 }
33911 + pax_open_kernel();
33912 memcpy(image + proglen, temp, ilen);
33913 + pax_close_kernel();
33914 }
33915 proglen += ilen;
33916 addrs[i] = proglen;
33917 @@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33918
33919 if (image) {
33920 bpf_flush_icache(header, image + proglen);
33921 - set_memory_ro((unsigned long)header, header->pages);
33922 fp->bpf_func = (void *)image;
33923 }
33924 out:
33925 @@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33926 {
33927 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33928 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33929 - struct bpf_binary_header *header = (void *)addr;
33930
33931 - set_memory_rw(addr, header->pages);
33932 - module_free(NULL, header);
33933 + set_memory_rw(addr, 1);
33934 + module_free_exec(NULL, (void *)addr);
33935 kfree(fp);
33936 }
33937
33938 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33939 index 5d04be5..2beeaa2 100644
33940 --- a/arch/x86/oprofile/backtrace.c
33941 +++ b/arch/x86/oprofile/backtrace.c
33942 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33943 struct stack_frame_ia32 *fp;
33944 unsigned long bytes;
33945
33946 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33947 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33948 if (bytes != 0)
33949 return NULL;
33950
33951 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33952 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33953
33954 oprofile_add_trace(bufhead[0].return_address);
33955
33956 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33957 struct stack_frame bufhead[2];
33958 unsigned long bytes;
33959
33960 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33961 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33962 if (bytes != 0)
33963 return NULL;
33964
33965 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33966 {
33967 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33968
33969 - if (!user_mode_vm(regs)) {
33970 + if (!user_mode(regs)) {
33971 unsigned long stack = kernel_stack_pointer(regs);
33972 if (depth)
33973 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33974 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33975 index 6890d84..1dad1f1 100644
33976 --- a/arch/x86/oprofile/nmi_int.c
33977 +++ b/arch/x86/oprofile/nmi_int.c
33978 @@ -23,6 +23,7 @@
33979 #include <asm/nmi.h>
33980 #include <asm/msr.h>
33981 #include <asm/apic.h>
33982 +#include <asm/pgtable.h>
33983
33984 #include "op_counter.h"
33985 #include "op_x86_model.h"
33986 @@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
33987 if (ret)
33988 return ret;
33989
33990 - if (!model->num_virt_counters)
33991 - model->num_virt_counters = model->num_counters;
33992 + if (!model->num_virt_counters) {
33993 + pax_open_kernel();
33994 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
33995 + pax_close_kernel();
33996 + }
33997
33998 mux_init(ops);
33999
34000 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34001 index 50d86c0..7985318 100644
34002 --- a/arch/x86/oprofile/op_model_amd.c
34003 +++ b/arch/x86/oprofile/op_model_amd.c
34004 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34005 num_counters = AMD64_NUM_COUNTERS;
34006 }
34007
34008 - op_amd_spec.num_counters = num_counters;
34009 - op_amd_spec.num_controls = num_counters;
34010 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34011 + pax_open_kernel();
34012 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34013 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34014 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34015 + pax_close_kernel();
34016
34017 return 0;
34018 }
34019 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34020 index d90528e..0127e2b 100644
34021 --- a/arch/x86/oprofile/op_model_ppro.c
34022 +++ b/arch/x86/oprofile/op_model_ppro.c
34023 @@ -19,6 +19,7 @@
34024 #include <asm/msr.h>
34025 #include <asm/apic.h>
34026 #include <asm/nmi.h>
34027 +#include <asm/pgtable.h>
34028
34029 #include "op_x86_model.h"
34030 #include "op_counter.h"
34031 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34032
34033 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34034
34035 - op_arch_perfmon_spec.num_counters = num_counters;
34036 - op_arch_perfmon_spec.num_controls = num_counters;
34037 + pax_open_kernel();
34038 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34039 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34040 + pax_close_kernel();
34041 }
34042
34043 static int arch_perfmon_init(struct oprofile_operations *ignore)
34044 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34045 index 71e8a67..6a313bb 100644
34046 --- a/arch/x86/oprofile/op_x86_model.h
34047 +++ b/arch/x86/oprofile/op_x86_model.h
34048 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34049 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34050 struct op_msrs const * const msrs);
34051 #endif
34052 -};
34053 +} __do_const;
34054
34055 struct op_counter_config;
34056
34057 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34058 index 84b9d67..260e5ff 100644
34059 --- a/arch/x86/pci/intel_mid_pci.c
34060 +++ b/arch/x86/pci/intel_mid_pci.c
34061 @@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34062 pr_info("Intel MID platform detected, using MID PCI ops\n");
34063 pci_mmcfg_late_init();
34064 pcibios_enable_irq = intel_mid_pci_irq_enable;
34065 - pci_root_ops = intel_mid_pci_ops;
34066 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34067 pci_soc_mode = 1;
34068 /* Continue with standard init */
34069 return 1;
34070 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34071 index 372e9b8..e775a6c 100644
34072 --- a/arch/x86/pci/irq.c
34073 +++ b/arch/x86/pci/irq.c
34074 @@ -50,7 +50,7 @@ struct irq_router {
34075 struct irq_router_handler {
34076 u16 vendor;
34077 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34078 -};
34079 +} __do_const;
34080
34081 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34082 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34083 @@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34084 return 0;
34085 }
34086
34087 -static __initdata struct irq_router_handler pirq_routers[] = {
34088 +static __initconst const struct irq_router_handler pirq_routers[] = {
34089 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34090 { PCI_VENDOR_ID_AL, ali_router_probe },
34091 { PCI_VENDOR_ID_ITE, ite_router_probe },
34092 @@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34093 static void __init pirq_find_router(struct irq_router *r)
34094 {
34095 struct irq_routing_table *rt = pirq_table;
34096 - struct irq_router_handler *h;
34097 + const struct irq_router_handler *h;
34098
34099 #ifdef CONFIG_PCI_BIOS
34100 if (!rt->signature) {
34101 @@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34102 return 0;
34103 }
34104
34105 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34106 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34107 {
34108 .callback = fix_broken_hp_bios_irq9,
34109 .ident = "HP Pavilion N5400 Series Laptop",
34110 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34111 index c77b24a..c979855 100644
34112 --- a/arch/x86/pci/pcbios.c
34113 +++ b/arch/x86/pci/pcbios.c
34114 @@ -79,7 +79,7 @@ union bios32 {
34115 static struct {
34116 unsigned long address;
34117 unsigned short segment;
34118 -} bios32_indirect = { 0, __KERNEL_CS };
34119 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34120
34121 /*
34122 * Returns the entry point for the given service, NULL on error
34123 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34124 unsigned long length; /* %ecx */
34125 unsigned long entry; /* %edx */
34126 unsigned long flags;
34127 + struct desc_struct d, *gdt;
34128
34129 local_irq_save(flags);
34130 - __asm__("lcall *(%%edi); cld"
34131 +
34132 + gdt = get_cpu_gdt_table(smp_processor_id());
34133 +
34134 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34135 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34136 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34137 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34138 +
34139 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34140 : "=a" (return_code),
34141 "=b" (address),
34142 "=c" (length),
34143 "=d" (entry)
34144 : "0" (service),
34145 "1" (0),
34146 - "D" (&bios32_indirect));
34147 + "D" (&bios32_indirect),
34148 + "r"(__PCIBIOS_DS)
34149 + : "memory");
34150 +
34151 + pax_open_kernel();
34152 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34153 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34154 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34155 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34156 + pax_close_kernel();
34157 +
34158 local_irq_restore(flags);
34159
34160 switch (return_code) {
34161 - case 0:
34162 - return address + entry;
34163 - case 0x80: /* Not present */
34164 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34165 - return 0;
34166 - default: /* Shouldn't happen */
34167 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34168 - service, return_code);
34169 + case 0: {
34170 + int cpu;
34171 + unsigned char flags;
34172 +
34173 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34174 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34175 + printk(KERN_WARNING "bios32_service: not valid\n");
34176 return 0;
34177 + }
34178 + address = address + PAGE_OFFSET;
34179 + length += 16UL; /* some BIOSs underreport this... */
34180 + flags = 4;
34181 + if (length >= 64*1024*1024) {
34182 + length >>= PAGE_SHIFT;
34183 + flags |= 8;
34184 + }
34185 +
34186 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34187 + gdt = get_cpu_gdt_table(cpu);
34188 + pack_descriptor(&d, address, length, 0x9b, flags);
34189 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34190 + pack_descriptor(&d, address, length, 0x93, flags);
34191 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34192 + }
34193 + return entry;
34194 + }
34195 + case 0x80: /* Not present */
34196 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34197 + return 0;
34198 + default: /* Shouldn't happen */
34199 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34200 + service, return_code);
34201 + return 0;
34202 }
34203 }
34204
34205 static struct {
34206 unsigned long address;
34207 unsigned short segment;
34208 -} pci_indirect = { 0, __KERNEL_CS };
34209 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34210
34211 -static int pci_bios_present;
34212 +static int pci_bios_present __read_only;
34213
34214 static int check_pcibios(void)
34215 {
34216 @@ -131,11 +174,13 @@ static int check_pcibios(void)
34217 unsigned long flags, pcibios_entry;
34218
34219 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34220 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34221 + pci_indirect.address = pcibios_entry;
34222
34223 local_irq_save(flags);
34224 - __asm__(
34225 - "lcall *(%%edi); cld\n\t"
34226 + __asm__("movw %w6, %%ds\n\t"
34227 + "lcall *%%ss:(%%edi); cld\n\t"
34228 + "push %%ss\n\t"
34229 + "pop %%ds\n\t"
34230 "jc 1f\n\t"
34231 "xor %%ah, %%ah\n"
34232 "1:"
34233 @@ -144,7 +189,8 @@ static int check_pcibios(void)
34234 "=b" (ebx),
34235 "=c" (ecx)
34236 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34237 - "D" (&pci_indirect)
34238 + "D" (&pci_indirect),
34239 + "r" (__PCIBIOS_DS)
34240 : "memory");
34241 local_irq_restore(flags);
34242
34243 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34244
34245 switch (len) {
34246 case 1:
34247 - __asm__("lcall *(%%esi); cld\n\t"
34248 + __asm__("movw %w6, %%ds\n\t"
34249 + "lcall *%%ss:(%%esi); cld\n\t"
34250 + "push %%ss\n\t"
34251 + "pop %%ds\n\t"
34252 "jc 1f\n\t"
34253 "xor %%ah, %%ah\n"
34254 "1:"
34255 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34256 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34257 "b" (bx),
34258 "D" ((long)reg),
34259 - "S" (&pci_indirect));
34260 + "S" (&pci_indirect),
34261 + "r" (__PCIBIOS_DS));
34262 /*
34263 * Zero-extend the result beyond 8 bits, do not trust the
34264 * BIOS having done it:
34265 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34266 *value &= 0xff;
34267 break;
34268 case 2:
34269 - __asm__("lcall *(%%esi); cld\n\t"
34270 + __asm__("movw %w6, %%ds\n\t"
34271 + "lcall *%%ss:(%%esi); cld\n\t"
34272 + "push %%ss\n\t"
34273 + "pop %%ds\n\t"
34274 "jc 1f\n\t"
34275 "xor %%ah, %%ah\n"
34276 "1:"
34277 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34278 : "1" (PCIBIOS_READ_CONFIG_WORD),
34279 "b" (bx),
34280 "D" ((long)reg),
34281 - "S" (&pci_indirect));
34282 + "S" (&pci_indirect),
34283 + "r" (__PCIBIOS_DS));
34284 /*
34285 * Zero-extend the result beyond 16 bits, do not trust the
34286 * BIOS having done it:
34287 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34288 *value &= 0xffff;
34289 break;
34290 case 4:
34291 - __asm__("lcall *(%%esi); cld\n\t"
34292 + __asm__("movw %w6, %%ds\n\t"
34293 + "lcall *%%ss:(%%esi); cld\n\t"
34294 + "push %%ss\n\t"
34295 + "pop %%ds\n\t"
34296 "jc 1f\n\t"
34297 "xor %%ah, %%ah\n"
34298 "1:"
34299 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34300 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34301 "b" (bx),
34302 "D" ((long)reg),
34303 - "S" (&pci_indirect));
34304 + "S" (&pci_indirect),
34305 + "r" (__PCIBIOS_DS));
34306 break;
34307 }
34308
34309 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34310
34311 switch (len) {
34312 case 1:
34313 - __asm__("lcall *(%%esi); cld\n\t"
34314 + __asm__("movw %w6, %%ds\n\t"
34315 + "lcall *%%ss:(%%esi); cld\n\t"
34316 + "push %%ss\n\t"
34317 + "pop %%ds\n\t"
34318 "jc 1f\n\t"
34319 "xor %%ah, %%ah\n"
34320 "1:"
34321 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34322 "c" (value),
34323 "b" (bx),
34324 "D" ((long)reg),
34325 - "S" (&pci_indirect));
34326 + "S" (&pci_indirect),
34327 + "r" (__PCIBIOS_DS));
34328 break;
34329 case 2:
34330 - __asm__("lcall *(%%esi); cld\n\t"
34331 + __asm__("movw %w6, %%ds\n\t"
34332 + "lcall *%%ss:(%%esi); cld\n\t"
34333 + "push %%ss\n\t"
34334 + "pop %%ds\n\t"
34335 "jc 1f\n\t"
34336 "xor %%ah, %%ah\n"
34337 "1:"
34338 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34339 "c" (value),
34340 "b" (bx),
34341 "D" ((long)reg),
34342 - "S" (&pci_indirect));
34343 + "S" (&pci_indirect),
34344 + "r" (__PCIBIOS_DS));
34345 break;
34346 case 4:
34347 - __asm__("lcall *(%%esi); cld\n\t"
34348 + __asm__("movw %w6, %%ds\n\t"
34349 + "lcall *%%ss:(%%esi); cld\n\t"
34350 + "push %%ss\n\t"
34351 + "pop %%ds\n\t"
34352 "jc 1f\n\t"
34353 "xor %%ah, %%ah\n"
34354 "1:"
34355 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34356 "c" (value),
34357 "b" (bx),
34358 "D" ((long)reg),
34359 - "S" (&pci_indirect));
34360 + "S" (&pci_indirect),
34361 + "r" (__PCIBIOS_DS));
34362 break;
34363 }
34364
34365 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34366
34367 DBG("PCI: Fetching IRQ routing table... ");
34368 __asm__("push %%es\n\t"
34369 + "movw %w8, %%ds\n\t"
34370 "push %%ds\n\t"
34371 "pop %%es\n\t"
34372 - "lcall *(%%esi); cld\n\t"
34373 + "lcall *%%ss:(%%esi); cld\n\t"
34374 "pop %%es\n\t"
34375 + "push %%ss\n\t"
34376 + "pop %%ds\n"
34377 "jc 1f\n\t"
34378 "xor %%ah, %%ah\n"
34379 "1:"
34380 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34381 "1" (0),
34382 "D" ((long) &opt),
34383 "S" (&pci_indirect),
34384 - "m" (opt)
34385 + "m" (opt),
34386 + "r" (__PCIBIOS_DS)
34387 : "memory");
34388 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34389 if (ret & 0xff00)
34390 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34391 {
34392 int ret;
34393
34394 - __asm__("lcall *(%%esi); cld\n\t"
34395 + __asm__("movw %w5, %%ds\n\t"
34396 + "lcall *%%ss:(%%esi); cld\n\t"
34397 + "push %%ss\n\t"
34398 + "pop %%ds\n"
34399 "jc 1f\n\t"
34400 "xor %%ah, %%ah\n"
34401 "1:"
34402 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34403 : "0" (PCIBIOS_SET_PCI_HW_INT),
34404 "b" ((dev->bus->number << 8) | dev->devfn),
34405 "c" ((irq << 8) | (pin + 10)),
34406 - "S" (&pci_indirect));
34407 + "S" (&pci_indirect),
34408 + "r" (__PCIBIOS_DS));
34409 return !(ret & 0xff00);
34410 }
34411 EXPORT_SYMBOL(pcibios_set_irq_routing);
34412 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34413 index 9ee3491..872192f 100644
34414 --- a/arch/x86/platform/efi/efi_32.c
34415 +++ b/arch/x86/platform/efi/efi_32.c
34416 @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34417 {
34418 struct desc_ptr gdt_descr;
34419
34420 +#ifdef CONFIG_PAX_KERNEXEC
34421 + struct desc_struct d;
34422 +#endif
34423 +
34424 local_irq_save(efi_rt_eflags);
34425
34426 load_cr3(initial_page_table);
34427 __flush_tlb_all();
34428
34429 +#ifdef CONFIG_PAX_KERNEXEC
34430 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34431 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34432 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34433 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34434 +#endif
34435 +
34436 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34437 gdt_descr.size = GDT_SIZE - 1;
34438 load_gdt(&gdt_descr);
34439 @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34440 {
34441 struct desc_ptr gdt_descr;
34442
34443 +#ifdef CONFIG_PAX_KERNEXEC
34444 + struct desc_struct d;
34445 +
34446 + memset(&d, 0, sizeof d);
34447 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34448 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34449 +#endif
34450 +
34451 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34452 gdt_descr.size = GDT_SIZE - 1;
34453 load_gdt(&gdt_descr);
34454
34455 +#ifdef CONFIG_PAX_PER_CPU_PGD
34456 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34457 +#else
34458 load_cr3(swapper_pg_dir);
34459 +#endif
34460 +
34461 __flush_tlb_all();
34462
34463 local_irq_restore(efi_rt_eflags);
34464 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34465 index 666b74a..673d88f 100644
34466 --- a/arch/x86/platform/efi/efi_64.c
34467 +++ b/arch/x86/platform/efi/efi_64.c
34468 @@ -97,6 +97,11 @@ void __init efi_call_phys_prelog(void)
34469 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34470 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34471 }
34472 +
34473 +#ifdef CONFIG_PAX_PER_CPU_PGD
34474 + load_cr3(swapper_pg_dir);
34475 +#endif
34476 +
34477 __flush_tlb_all();
34478 }
34479
34480 @@ -114,6 +119,11 @@ void __init efi_call_phys_epilog(void)
34481 for (pgd = 0; pgd < n_pgds; pgd++)
34482 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34483 kfree(save_pgd);
34484 +
34485 +#ifdef CONFIG_PAX_PER_CPU_PGD
34486 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34487 +#endif
34488 +
34489 __flush_tlb_all();
34490 local_irq_restore(efi_flags);
34491 early_code_mapping_set_exec(0);
34492 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34493 index fbe66e6..eae5e38 100644
34494 --- a/arch/x86/platform/efi/efi_stub_32.S
34495 +++ b/arch/x86/platform/efi/efi_stub_32.S
34496 @@ -6,7 +6,9 @@
34497 */
34498
34499 #include <linux/linkage.h>
34500 +#include <linux/init.h>
34501 #include <asm/page_types.h>
34502 +#include <asm/segment.h>
34503
34504 /*
34505 * efi_call_phys(void *, ...) is a function with variable parameters.
34506 @@ -20,7 +22,7 @@
34507 * service functions will comply with gcc calling convention, too.
34508 */
34509
34510 -.text
34511 +__INIT
34512 ENTRY(efi_call_phys)
34513 /*
34514 * 0. The function can only be called in Linux kernel. So CS has been
34515 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34516 * The mapping of lower virtual memory has been created in prelog and
34517 * epilog.
34518 */
34519 - movl $1f, %edx
34520 - subl $__PAGE_OFFSET, %edx
34521 - jmp *%edx
34522 +#ifdef CONFIG_PAX_KERNEXEC
34523 + movl $(__KERNEXEC_EFI_DS), %edx
34524 + mov %edx, %ds
34525 + mov %edx, %es
34526 + mov %edx, %ss
34527 + addl $2f,(1f)
34528 + ljmp *(1f)
34529 +
34530 +__INITDATA
34531 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34532 +.previous
34533 +
34534 +2:
34535 + subl $2b,(1b)
34536 +#else
34537 + jmp 1f-__PAGE_OFFSET
34538 1:
34539 +#endif
34540
34541 /*
34542 * 2. Now on the top of stack is the return
34543 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34544 * parameter 2, ..., param n. To make things easy, we save the return
34545 * address of efi_call_phys in a global variable.
34546 */
34547 - popl %edx
34548 - movl %edx, saved_return_addr
34549 - /* get the function pointer into ECX*/
34550 - popl %ecx
34551 - movl %ecx, efi_rt_function_ptr
34552 - movl $2f, %edx
34553 - subl $__PAGE_OFFSET, %edx
34554 - pushl %edx
34555 + popl (saved_return_addr)
34556 + popl (efi_rt_function_ptr)
34557
34558 /*
34559 * 3. Clear PG bit in %CR0.
34560 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34561 /*
34562 * 5. Call the physical function.
34563 */
34564 - jmp *%ecx
34565 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34566
34567 -2:
34568 /*
34569 * 6. After EFI runtime service returns, control will return to
34570 * following instruction. We'd better readjust stack pointer first.
34571 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34572 movl %cr0, %edx
34573 orl $0x80000000, %edx
34574 movl %edx, %cr0
34575 - jmp 1f
34576 -1:
34577 +
34578 /*
34579 * 8. Now restore the virtual mode from flat mode by
34580 * adding EIP with PAGE_OFFSET.
34581 */
34582 - movl $1f, %edx
34583 - jmp *%edx
34584 +#ifdef CONFIG_PAX_KERNEXEC
34585 + movl $(__KERNEL_DS), %edx
34586 + mov %edx, %ds
34587 + mov %edx, %es
34588 + mov %edx, %ss
34589 + ljmp $(__KERNEL_CS),$1f
34590 +#else
34591 + jmp 1f+__PAGE_OFFSET
34592 +#endif
34593 1:
34594
34595 /*
34596 * 9. Balance the stack. And because EAX contain the return value,
34597 * we'd better not clobber it.
34598 */
34599 - leal efi_rt_function_ptr, %edx
34600 - movl (%edx), %ecx
34601 - pushl %ecx
34602 + pushl (efi_rt_function_ptr)
34603
34604 /*
34605 - * 10. Push the saved return address onto the stack and return.
34606 + * 10. Return to the saved return address.
34607 */
34608 - leal saved_return_addr, %edx
34609 - movl (%edx), %ecx
34610 - pushl %ecx
34611 - ret
34612 + jmpl *(saved_return_addr)
34613 ENDPROC(efi_call_phys)
34614 .previous
34615
34616 -.data
34617 +__INITDATA
34618 saved_return_addr:
34619 .long 0
34620 efi_rt_function_ptr:
34621 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34622 index 88073b1..1cc2f53 100644
34623 --- a/arch/x86/platform/efi/efi_stub_64.S
34624 +++ b/arch/x86/platform/efi/efi_stub_64.S
34625 @@ -7,6 +7,7 @@
34626 */
34627
34628 #include <linux/linkage.h>
34629 +#include <asm/alternative-asm.h>
34630
34631 #define SAVE_XMM \
34632 mov %rsp, %rax; \
34633 @@ -77,6 +78,7 @@ ENTRY(efi_call0)
34634 RESTORE_PGT
34635 addq $32, %rsp
34636 RESTORE_XMM
34637 + pax_force_retaddr 0, 1
34638 ret
34639 ENDPROC(efi_call0)
34640
34641 @@ -89,6 +91,7 @@ ENTRY(efi_call1)
34642 RESTORE_PGT
34643 addq $32, %rsp
34644 RESTORE_XMM
34645 + pax_force_retaddr 0, 1
34646 ret
34647 ENDPROC(efi_call1)
34648
34649 @@ -101,6 +104,7 @@ ENTRY(efi_call2)
34650 RESTORE_PGT
34651 addq $32, %rsp
34652 RESTORE_XMM
34653 + pax_force_retaddr 0, 1
34654 ret
34655 ENDPROC(efi_call2)
34656
34657 @@ -114,6 +118,7 @@ ENTRY(efi_call3)
34658 RESTORE_PGT
34659 addq $32, %rsp
34660 RESTORE_XMM
34661 + pax_force_retaddr 0, 1
34662 ret
34663 ENDPROC(efi_call3)
34664
34665 @@ -128,6 +133,7 @@ ENTRY(efi_call4)
34666 RESTORE_PGT
34667 addq $32, %rsp
34668 RESTORE_XMM
34669 + pax_force_retaddr 0, 1
34670 ret
34671 ENDPROC(efi_call4)
34672
34673 @@ -143,6 +149,7 @@ ENTRY(efi_call5)
34674 RESTORE_PGT
34675 addq $48, %rsp
34676 RESTORE_XMM
34677 + pax_force_retaddr 0, 1
34678 ret
34679 ENDPROC(efi_call5)
34680
34681 @@ -161,6 +168,7 @@ ENTRY(efi_call6)
34682 RESTORE_PGT
34683 addq $48, %rsp
34684 RESTORE_XMM
34685 + pax_force_retaddr 0, 1
34686 ret
34687 ENDPROC(efi_call6)
34688
34689 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34690 index 1bbedc4..eb795b5 100644
34691 --- a/arch/x86/platform/intel-mid/intel-mid.c
34692 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34693 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34694 {
34695 };
34696
34697 -static void intel_mid_reboot(void)
34698 +static void __noreturn intel_mid_reboot(void)
34699 {
34700 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34701 + BUG();
34702 }
34703
34704 static unsigned long __init intel_mid_calibrate_tsc(void)
34705 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34706 index d6ee929..3637cb5 100644
34707 --- a/arch/x86/platform/olpc/olpc_dt.c
34708 +++ b/arch/x86/platform/olpc/olpc_dt.c
34709 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34710 return res;
34711 }
34712
34713 -static struct of_pdt_ops prom_olpc_ops __initdata = {
34714 +static struct of_pdt_ops prom_olpc_ops __initconst = {
34715 .nextprop = olpc_dt_nextprop,
34716 .getproplen = olpc_dt_getproplen,
34717 .getproperty = olpc_dt_getproperty,
34718 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34719 index 424f4c9..f2a2988 100644
34720 --- a/arch/x86/power/cpu.c
34721 +++ b/arch/x86/power/cpu.c
34722 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
34723 static void fix_processor_context(void)
34724 {
34725 int cpu = smp_processor_id();
34726 - struct tss_struct *t = &per_cpu(init_tss, cpu);
34727 -#ifdef CONFIG_X86_64
34728 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
34729 - tss_desc tss;
34730 -#endif
34731 + struct tss_struct *t = init_tss + cpu;
34732 +
34733 set_tss_desc(cpu, t); /*
34734 * This just modifies memory; should not be
34735 * necessary. But... This is necessary, because
34736 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
34737 */
34738
34739 #ifdef CONFIG_X86_64
34740 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34741 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34742 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34743 -
34744 syscall_init(); /* This sets MSR_*STAR and related */
34745 #endif
34746 load_TR_desc(); /* This does ltr */
34747 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34748 index bad628a..a102610 100644
34749 --- a/arch/x86/realmode/init.c
34750 +++ b/arch/x86/realmode/init.c
34751 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
34752 __va(real_mode_header->trampoline_header);
34753
34754 #ifdef CONFIG_X86_32
34755 - trampoline_header->start = __pa_symbol(startup_32_smp);
34756 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34757 +
34758 +#ifdef CONFIG_PAX_KERNEXEC
34759 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34760 +#endif
34761 +
34762 + trampoline_header->boot_cs = __BOOT_CS;
34763 trampoline_header->gdt_limit = __BOOT_DS + 7;
34764 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34765 #else
34766 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
34767 *trampoline_cr4_features = read_cr4();
34768
34769 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34770 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34771 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34772 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34773 #endif
34774 }
34775 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34776 index 3497f14..cc73b92 100644
34777 --- a/arch/x86/realmode/rm/Makefile
34778 +++ b/arch/x86/realmode/rm/Makefile
34779 @@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
34780
34781 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
34782 -I$(srctree)/arch/x86/boot
34783 +ifdef CONSTIFY_PLUGIN
34784 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34785 +endif
34786 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34787 GCOV_PROFILE := n
34788 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34789 index a28221d..93c40f1 100644
34790 --- a/arch/x86/realmode/rm/header.S
34791 +++ b/arch/x86/realmode/rm/header.S
34792 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34793 #endif
34794 /* APM/BIOS reboot */
34795 .long pa_machine_real_restart_asm
34796 -#ifdef CONFIG_X86_64
34797 +#ifdef CONFIG_X86_32
34798 + .long __KERNEL_CS
34799 +#else
34800 .long __KERNEL32_CS
34801 #endif
34802 END(real_mode_header)
34803 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34804 index 48ddd76..c26749f 100644
34805 --- a/arch/x86/realmode/rm/trampoline_32.S
34806 +++ b/arch/x86/realmode/rm/trampoline_32.S
34807 @@ -24,6 +24,12 @@
34808 #include <asm/page_types.h>
34809 #include "realmode.h"
34810
34811 +#ifdef CONFIG_PAX_KERNEXEC
34812 +#define ta(X) (X)
34813 +#else
34814 +#define ta(X) (pa_ ## X)
34815 +#endif
34816 +
34817 .text
34818 .code16
34819
34820 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
34821
34822 cli # We should be safe anyway
34823
34824 - movl tr_start, %eax # where we need to go
34825 -
34826 movl $0xA5A5A5A5, trampoline_status
34827 # write marker for master knows we're running
34828
34829 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
34830 movw $1, %dx # protected mode (PE) bit
34831 lmsw %dx # into protected mode
34832
34833 - ljmpl $__BOOT_CS, $pa_startup_32
34834 + ljmpl *(trampoline_header)
34835
34836 .section ".text32","ax"
34837 .code32
34838 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34839 .balign 8
34840 GLOBAL(trampoline_header)
34841 tr_start: .space 4
34842 - tr_gdt_pad: .space 2
34843 + tr_boot_cs: .space 2
34844 tr_gdt: .space 6
34845 END(trampoline_header)
34846
34847 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34848 index dac7b20..72dbaca 100644
34849 --- a/arch/x86/realmode/rm/trampoline_64.S
34850 +++ b/arch/x86/realmode/rm/trampoline_64.S
34851 @@ -93,6 +93,7 @@ ENTRY(startup_32)
34852 movl %edx, %gs
34853
34854 movl pa_tr_cr4, %eax
34855 + andl $~X86_CR4_PCIDE, %eax
34856 movl %eax, %cr4 # Enable PAE mode
34857
34858 # Setup trampoline 4 level pagetables
34859 @@ -106,7 +107,7 @@ ENTRY(startup_32)
34860 wrmsr
34861
34862 # Enable paging and in turn activate Long Mode
34863 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34864 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
34865 movl %eax, %cr0
34866
34867 /*
34868 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34869 index e812034..c747134 100644
34870 --- a/arch/x86/tools/Makefile
34871 +++ b/arch/x86/tools/Makefile
34872 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34873
34874 $(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
34875
34876 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34877 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34878 hostprogs-y += relocs
34879 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34880 relocs: $(obj)/relocs
34881 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34882 index cfbdbdb..1aa763c 100644
34883 --- a/arch/x86/tools/relocs.c
34884 +++ b/arch/x86/tools/relocs.c
34885 @@ -1,5 +1,7 @@
34886 /* This is included from relocs_32/64.c */
34887
34888 +#include "../../../include/generated/autoconf.h"
34889 +
34890 #define ElfW(type) _ElfW(ELF_BITS, type)
34891 #define _ElfW(bits, type) __ElfW(bits, type)
34892 #define __ElfW(bits, type) Elf##bits##_##type
34893 @@ -11,6 +13,7 @@
34894 #define Elf_Sym ElfW(Sym)
34895
34896 static Elf_Ehdr ehdr;
34897 +static Elf_Phdr *phdr;
34898
34899 struct relocs {
34900 uint32_t *offset;
34901 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34902 }
34903 }
34904
34905 +static void read_phdrs(FILE *fp)
34906 +{
34907 + unsigned int i;
34908 +
34909 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34910 + if (!phdr) {
34911 + die("Unable to allocate %d program headers\n",
34912 + ehdr.e_phnum);
34913 + }
34914 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34915 + die("Seek to %d failed: %s\n",
34916 + ehdr.e_phoff, strerror(errno));
34917 + }
34918 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34919 + die("Cannot read ELF program headers: %s\n",
34920 + strerror(errno));
34921 + }
34922 + for(i = 0; i < ehdr.e_phnum; i++) {
34923 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34924 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34925 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34926 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34927 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34928 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34929 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34930 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34931 + }
34932 +
34933 +}
34934 +
34935 static void read_shdrs(FILE *fp)
34936 {
34937 - int i;
34938 + unsigned int i;
34939 Elf_Shdr shdr;
34940
34941 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34942 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34943
34944 static void read_strtabs(FILE *fp)
34945 {
34946 - int i;
34947 + unsigned int i;
34948 for (i = 0; i < ehdr.e_shnum; i++) {
34949 struct section *sec = &secs[i];
34950 if (sec->shdr.sh_type != SHT_STRTAB) {
34951 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34952
34953 static void read_symtabs(FILE *fp)
34954 {
34955 - int i,j;
34956 + unsigned int i,j;
34957 for (i = 0; i < ehdr.e_shnum; i++) {
34958 struct section *sec = &secs[i];
34959 if (sec->shdr.sh_type != SHT_SYMTAB) {
34960 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34961 }
34962
34963
34964 -static void read_relocs(FILE *fp)
34965 +static void read_relocs(FILE *fp, int use_real_mode)
34966 {
34967 - int i,j;
34968 + unsigned int i,j;
34969 + uint32_t base;
34970 +
34971 for (i = 0; i < ehdr.e_shnum; i++) {
34972 struct section *sec = &secs[i];
34973 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34974 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34975 die("Cannot read symbol table: %s\n",
34976 strerror(errno));
34977 }
34978 + base = 0;
34979 +
34980 +#ifdef CONFIG_X86_32
34981 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
34982 + if (phdr[j].p_type != PT_LOAD )
34983 + continue;
34984 + 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)
34985 + continue;
34986 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
34987 + break;
34988 + }
34989 +#endif
34990 +
34991 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
34992 Elf_Rel *rel = &sec->reltab[j];
34993 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
34994 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
34995 rel->r_info = elf_xword_to_cpu(rel->r_info);
34996 #if (SHT_REL_TYPE == SHT_RELA)
34997 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
34998 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
34999
35000 static void print_absolute_symbols(void)
35001 {
35002 - int i;
35003 + unsigned int i;
35004 const char *format;
35005
35006 if (ELF_BITS == 64)
35007 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35008 for (i = 0; i < ehdr.e_shnum; i++) {
35009 struct section *sec = &secs[i];
35010 char *sym_strtab;
35011 - int j;
35012 + unsigned int j;
35013
35014 if (sec->shdr.sh_type != SHT_SYMTAB) {
35015 continue;
35016 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35017
35018 static void print_absolute_relocs(void)
35019 {
35020 - int i, printed = 0;
35021 + unsigned int i, printed = 0;
35022 const char *format;
35023
35024 if (ELF_BITS == 64)
35025 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35026 struct section *sec_applies, *sec_symtab;
35027 char *sym_strtab;
35028 Elf_Sym *sh_symtab;
35029 - int j;
35030 + unsigned int j;
35031 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35032 continue;
35033 }
35034 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35035 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35036 Elf_Sym *sym, const char *symname))
35037 {
35038 - int i;
35039 + unsigned int i;
35040 /* Walk through the relocations */
35041 for (i = 0; i < ehdr.e_shnum; i++) {
35042 char *sym_strtab;
35043 Elf_Sym *sh_symtab;
35044 struct section *sec_applies, *sec_symtab;
35045 - int j;
35046 + unsigned int j;
35047 struct section *sec = &secs[i];
35048
35049 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35050 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35051 {
35052 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35053 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35054 + char *sym_strtab = sec->link->link->strtab;
35055 +
35056 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35057 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35058 + return 0;
35059 +
35060 +#ifdef CONFIG_PAX_KERNEXEC
35061 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35062 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35063 + return 0;
35064 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35065 + return 0;
35066 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35067 + return 0;
35068 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35069 + return 0;
35070 +#endif
35071
35072 switch (r_type) {
35073 case R_386_NONE:
35074 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35075
35076 static void emit_relocs(int as_text, int use_real_mode)
35077 {
35078 - int i;
35079 + unsigned int i;
35080 int (*write_reloc)(uint32_t, FILE *) = write32;
35081 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35082 const char *symname);
35083 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35084 {
35085 regex_init(use_real_mode);
35086 read_ehdr(fp);
35087 + read_phdrs(fp);
35088 read_shdrs(fp);
35089 read_strtabs(fp);
35090 read_symtabs(fp);
35091 - read_relocs(fp);
35092 + read_relocs(fp, use_real_mode);
35093 if (ELF_BITS == 64)
35094 percpu_init();
35095 if (show_absolute_syms) {
35096 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35097 index 80ffa5b..a33bd15 100644
35098 --- a/arch/x86/um/tls_32.c
35099 +++ b/arch/x86/um/tls_32.c
35100 @@ -260,7 +260,7 @@ out:
35101 if (unlikely(task == current &&
35102 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35103 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35104 - "without flushed TLS.", current->pid);
35105 + "without flushed TLS.", task_pid_nr(current));
35106 }
35107
35108 return 0;
35109 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35110 index fd14be1..e3c79c0 100644
35111 --- a/arch/x86/vdso/Makefile
35112 +++ b/arch/x86/vdso/Makefile
35113 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35114 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35115 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35116
35117 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35118 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35119 GCOV_PROFILE := n
35120
35121 #
35122 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35123 index d6bfb87..876ee18 100644
35124 --- a/arch/x86/vdso/vdso32-setup.c
35125 +++ b/arch/x86/vdso/vdso32-setup.c
35126 @@ -25,6 +25,7 @@
35127 #include <asm/tlbflush.h>
35128 #include <asm/vdso.h>
35129 #include <asm/proto.h>
35130 +#include <asm/mman.h>
35131
35132 enum {
35133 VDSO_DISABLED = 0,
35134 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
35135 void enable_sep_cpu(void)
35136 {
35137 int cpu = get_cpu();
35138 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
35139 + struct tss_struct *tss = init_tss + cpu;
35140
35141 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35142 put_cpu();
35143 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
35144 gate_vma.vm_start = FIXADDR_USER_START;
35145 gate_vma.vm_end = FIXADDR_USER_END;
35146 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35147 - gate_vma.vm_page_prot = __P101;
35148 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35149
35150 return 0;
35151 }
35152 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35153 if (compat)
35154 addr = VDSO_HIGH_BASE;
35155 else {
35156 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35157 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35158 if (IS_ERR_VALUE(addr)) {
35159 ret = addr;
35160 goto up_fail;
35161 }
35162 }
35163
35164 - current->mm->context.vdso = (void *)addr;
35165 + current->mm->context.vdso = addr;
35166
35167 if (compat_uses_vma || !compat) {
35168 /*
35169 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35170 }
35171
35172 current_thread_info()->sysenter_return =
35173 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35174 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35175
35176 up_fail:
35177 if (ret)
35178 - current->mm->context.vdso = NULL;
35179 + current->mm->context.vdso = 0;
35180
35181 up_write(&mm->mmap_sem);
35182
35183 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
35184
35185 const char *arch_vma_name(struct vm_area_struct *vma)
35186 {
35187 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35188 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35189 return "[vdso]";
35190 +
35191 +#ifdef CONFIG_PAX_SEGMEXEC
35192 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35193 + return "[vdso]";
35194 +#endif
35195 +
35196 return NULL;
35197 }
35198
35199 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35200 * Check to see if the corresponding task was created in compat vdso
35201 * mode.
35202 */
35203 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35204 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35205 return &gate_vma;
35206 return NULL;
35207 }
35208 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35209 index 431e875..cbb23f3 100644
35210 --- a/arch/x86/vdso/vma.c
35211 +++ b/arch/x86/vdso/vma.c
35212 @@ -16,8 +16,6 @@
35213 #include <asm/vdso.h>
35214 #include <asm/page.h>
35215
35216 -unsigned int __read_mostly vdso_enabled = 1;
35217 -
35218 extern char vdso_start[], vdso_end[];
35219 extern unsigned short vdso_sync_cpuid;
35220
35221 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35222 * unaligned here as a result of stack start randomization.
35223 */
35224 addr = PAGE_ALIGN(addr);
35225 - addr = align_vdso_addr(addr);
35226
35227 return addr;
35228 }
35229 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35230 unsigned size)
35231 {
35232 struct mm_struct *mm = current->mm;
35233 - unsigned long addr;
35234 + unsigned long addr = 0;
35235 int ret;
35236
35237 - if (!vdso_enabled)
35238 - return 0;
35239 -
35240 down_write(&mm->mmap_sem);
35241 +
35242 +#ifdef CONFIG_PAX_RANDMMAP
35243 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35244 +#endif
35245 +
35246 addr = vdso_addr(mm->start_stack, size);
35247 + addr = align_vdso_addr(addr);
35248 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35249 if (IS_ERR_VALUE(addr)) {
35250 ret = addr;
35251 goto up_fail;
35252 }
35253
35254 - current->mm->context.vdso = (void *)addr;
35255 + mm->context.vdso = addr;
35256
35257 ret = install_special_mapping(mm, addr, size,
35258 VM_READ|VM_EXEC|
35259 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35260 pages);
35261 - if (ret) {
35262 - current->mm->context.vdso = NULL;
35263 - goto up_fail;
35264 - }
35265 + if (ret)
35266 + mm->context.vdso = 0;
35267
35268 up_fail:
35269 up_write(&mm->mmap_sem);
35270 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35271 vdsox32_size);
35272 }
35273 #endif
35274 -
35275 -static __init int vdso_setup(char *s)
35276 -{
35277 - vdso_enabled = simple_strtoul(s, NULL, 0);
35278 - return 0;
35279 -}
35280 -__setup("vdso=", vdso_setup);
35281 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35282 index 01b9026..1e476df 100644
35283 --- a/arch/x86/xen/Kconfig
35284 +++ b/arch/x86/xen/Kconfig
35285 @@ -9,6 +9,7 @@ config XEN
35286 select XEN_HAVE_PVMMU
35287 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35288 depends on X86_TSC
35289 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35290 help
35291 This is the Linux Xen port. Enabling this will allow the
35292 kernel to boot in a paravirtualized environment under the
35293 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35294 index 201d09a..e4723e5 100644
35295 --- a/arch/x86/xen/enlighten.c
35296 +++ b/arch/x86/xen/enlighten.c
35297 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35298
35299 struct shared_info xen_dummy_shared_info;
35300
35301 -void *xen_initial_gdt;
35302 -
35303 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35304 __read_mostly int xen_have_vector_callback;
35305 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35306 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35307 {
35308 unsigned long va = dtr->address;
35309 unsigned int size = dtr->size + 1;
35310 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35311 - unsigned long frames[pages];
35312 + unsigned long frames[65536 / PAGE_SIZE];
35313 int f;
35314
35315 /*
35316 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35317 {
35318 unsigned long va = dtr->address;
35319 unsigned int size = dtr->size + 1;
35320 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35321 - unsigned long frames[pages];
35322 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35323 int f;
35324
35325 /*
35326 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35327 * 8-byte entries, or 16 4k pages..
35328 */
35329
35330 - BUG_ON(size > 65536);
35331 + BUG_ON(size > GDT_SIZE);
35332 BUG_ON(va & ~PAGE_MASK);
35333
35334 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35335 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35336 return 0;
35337 }
35338
35339 -static void set_xen_basic_apic_ops(void)
35340 +static void __init set_xen_basic_apic_ops(void)
35341 {
35342 apic->read = xen_apic_read;
35343 apic->write = xen_apic_write;
35344 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35345 #endif
35346 };
35347
35348 -static void xen_reboot(int reason)
35349 +static __noreturn void xen_reboot(int reason)
35350 {
35351 struct sched_shutdown r = { .reason = reason };
35352
35353 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35354 - BUG();
35355 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35356 + BUG();
35357 }
35358
35359 -static void xen_restart(char *msg)
35360 +static __noreturn void xen_restart(char *msg)
35361 {
35362 xen_reboot(SHUTDOWN_reboot);
35363 }
35364
35365 -static void xen_emergency_restart(void)
35366 +static __noreturn void xen_emergency_restart(void)
35367 {
35368 xen_reboot(SHUTDOWN_reboot);
35369 }
35370
35371 -static void xen_machine_halt(void)
35372 +static __noreturn void xen_machine_halt(void)
35373 {
35374 xen_reboot(SHUTDOWN_poweroff);
35375 }
35376
35377 -static void xen_machine_power_off(void)
35378 +static __noreturn void xen_machine_power_off(void)
35379 {
35380 if (pm_power_off)
35381 pm_power_off();
35382 @@ -1564,7 +1560,17 @@ asmlinkage void __init xen_start_kernel(void)
35383 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35384
35385 /* Work out if we support NX */
35386 - x86_configure_nx();
35387 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35388 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35389 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35390 + unsigned l, h;
35391 +
35392 + __supported_pte_mask |= _PAGE_NX;
35393 + rdmsr(MSR_EFER, l, h);
35394 + l |= EFER_NX;
35395 + wrmsr(MSR_EFER, l, h);
35396 + }
35397 +#endif
35398
35399 /* Get mfn list */
35400 xen_build_dynamic_phys_to_machine();
35401 @@ -1592,13 +1598,6 @@ asmlinkage void __init xen_start_kernel(void)
35402
35403 machine_ops = xen_machine_ops;
35404
35405 - /*
35406 - * The only reliable way to retain the initial address of the
35407 - * percpu gdt_page is to remember it here, so we can go and
35408 - * mark it RW later, when the initial percpu area is freed.
35409 - */
35410 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35411 -
35412 xen_smp_init();
35413
35414 #ifdef CONFIG_ACPI_NUMA
35415 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35416 index 2423ef0..4f6fb5b 100644
35417 --- a/arch/x86/xen/mmu.c
35418 +++ b/arch/x86/xen/mmu.c
35419 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35420 return val;
35421 }
35422
35423 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35424 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35425 {
35426 if (val & _PAGE_PRESENT) {
35427 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35428 @@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35429 /* L3_k[510] -> level2_kernel_pgt
35430 * L3_i[511] -> level2_fixmap_pgt */
35431 convert_pfn_mfn(level3_kernel_pgt);
35432 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35433 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35434 + convert_pfn_mfn(level3_vmemmap_pgt);
35435 }
35436 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35437 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35438 @@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35439 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35440 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35441 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35442 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35443 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35444 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35445 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35446 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35447 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35448 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35449 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35450
35451 @@ -2123,6 +2130,7 @@ static void __init xen_post_allocator_init(void)
35452 pv_mmu_ops.set_pud = xen_set_pud;
35453 #if PAGETABLE_LEVELS == 4
35454 pv_mmu_ops.set_pgd = xen_set_pgd;
35455 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35456 #endif
35457
35458 /* This will work as long as patching hasn't happened yet
35459 @@ -2201,6 +2209,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35460 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35461 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35462 .set_pgd = xen_set_pgd_hyper,
35463 + .set_pgd_batched = xen_set_pgd_hyper,
35464
35465 .alloc_pud = xen_alloc_pmd_init,
35466 .release_pud = xen_release_pmd_init,
35467 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35468 index a18eadd..2e2f10e 100644
35469 --- a/arch/x86/xen/smp.c
35470 +++ b/arch/x86/xen/smp.c
35471 @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35472
35473 if (xen_pv_domain()) {
35474 if (!xen_feature(XENFEAT_writable_page_tables))
35475 - /* We've switched to the "real" per-cpu gdt, so make
35476 - * sure the old memory can be recycled. */
35477 - make_lowmem_page_readwrite(xen_initial_gdt);
35478 -
35479 #ifdef CONFIG_X86_32
35480 /*
35481 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35482 * expects __USER_DS
35483 */
35484 - loadsegment(ds, __USER_DS);
35485 - loadsegment(es, __USER_DS);
35486 + loadsegment(ds, __KERNEL_DS);
35487 + loadsegment(es, __KERNEL_DS);
35488 #endif
35489
35490 xen_filter_cpu_maps();
35491 @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35492 #ifdef CONFIG_X86_32
35493 /* Note: PVH is not yet supported on x86_32. */
35494 ctxt->user_regs.fs = __KERNEL_PERCPU;
35495 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35496 + savesegment(gs, ctxt->user_regs.gs);
35497 #endif
35498 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35499
35500 @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35501 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35502 ctxt->flags = VGCF_IN_KERNEL;
35503 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35504 - ctxt->user_regs.ds = __USER_DS;
35505 - ctxt->user_regs.es = __USER_DS;
35506 + ctxt->user_regs.ds = __KERNEL_DS;
35507 + ctxt->user_regs.es = __KERNEL_DS;
35508 ctxt->user_regs.ss = __KERNEL_DS;
35509
35510 xen_copy_trap_info(ctxt->trap_ctxt);
35511 @@ -437,13 +433,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35512 int rc;
35513
35514 per_cpu(current_task, cpu) = idle;
35515 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35516 #ifdef CONFIG_X86_32
35517 irq_ctx_init(cpu);
35518 #else
35519 clear_tsk_thread_flag(idle, TIF_FORK);
35520 - per_cpu(kernel_stack, cpu) =
35521 - (unsigned long)task_stack_page(idle) -
35522 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35523 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35524 #endif
35525 xen_setup_runstate_info(cpu);
35526 xen_setup_timer(cpu);
35527 @@ -719,7 +714,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35528
35529 void __init xen_smp_init(void)
35530 {
35531 - smp_ops = xen_smp_ops;
35532 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35533 xen_fill_possible_map();
35534 }
35535
35536 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35537 index 33ca6e4..0ded929 100644
35538 --- a/arch/x86/xen/xen-asm_32.S
35539 +++ b/arch/x86/xen/xen-asm_32.S
35540 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
35541 ESP_OFFSET=4 # bytes pushed onto stack
35542
35543 /*
35544 - * Store vcpu_info pointer for easy access. Do it this way to
35545 - * avoid having to reload %fs
35546 + * Store vcpu_info pointer for easy access.
35547 */
35548 #ifdef CONFIG_SMP
35549 - GET_THREAD_INFO(%eax)
35550 - movl %ss:TI_cpu(%eax), %eax
35551 - movl %ss:__per_cpu_offset(,%eax,4), %eax
35552 - mov %ss:xen_vcpu(%eax), %eax
35553 + push %fs
35554 + mov $(__KERNEL_PERCPU), %eax
35555 + mov %eax, %fs
35556 + mov PER_CPU_VAR(xen_vcpu), %eax
35557 + pop %fs
35558 #else
35559 movl %ss:xen_vcpu, %eax
35560 #endif
35561 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35562 index 485b695..fda3e7c 100644
35563 --- a/arch/x86/xen/xen-head.S
35564 +++ b/arch/x86/xen/xen-head.S
35565 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
35566 #ifdef CONFIG_X86_32
35567 mov %esi,xen_start_info
35568 mov $init_thread_union+THREAD_SIZE,%esp
35569 +#ifdef CONFIG_SMP
35570 + movl $cpu_gdt_table,%edi
35571 + movl $__per_cpu_load,%eax
35572 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35573 + rorl $16,%eax
35574 + movb %al,__KERNEL_PERCPU + 4(%edi)
35575 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35576 + movl $__per_cpu_end - 1,%eax
35577 + subl $__per_cpu_start,%eax
35578 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35579 +#endif
35580 #else
35581 mov %rsi,xen_start_info
35582 mov $init_thread_union+THREAD_SIZE,%rsp
35583 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35584 index 1cb6f4c..9981524 100644
35585 --- a/arch/x86/xen/xen-ops.h
35586 +++ b/arch/x86/xen/xen-ops.h
35587 @@ -10,8 +10,6 @@
35588 extern const char xen_hypervisor_callback[];
35589 extern const char xen_failsafe_callback[];
35590
35591 -extern void *xen_initial_gdt;
35592 -
35593 struct trap_info;
35594 void xen_copy_trap_info(struct trap_info *traps);
35595
35596 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35597 index 525bd3d..ef888b1 100644
35598 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35599 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35600 @@ -119,9 +119,9 @@
35601 ----------------------------------------------------------------------*/
35602
35603 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35604 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35605 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35606 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35607 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35608
35609 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35610 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35611 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35612 index 2f33760..835e50a 100644
35613 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35614 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35615 @@ -11,6 +11,7 @@
35616 #ifndef _XTENSA_CORE_H
35617 #define _XTENSA_CORE_H
35618
35619 +#include <linux/const.h>
35620
35621 /****************************************************************************
35622 Parameters Useful for Any Code, USER or PRIVILEGED
35623 @@ -112,9 +113,9 @@
35624 ----------------------------------------------------------------------*/
35625
35626 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35627 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35628 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35629 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35630 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35631
35632 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35633 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35634 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35635 index af00795..2bb8105 100644
35636 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35637 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35638 @@ -11,6 +11,7 @@
35639 #ifndef _XTENSA_CORE_CONFIGURATION_H
35640 #define _XTENSA_CORE_CONFIGURATION_H
35641
35642 +#include <linux/const.h>
35643
35644 /****************************************************************************
35645 Parameters Useful for Any Code, USER or PRIVILEGED
35646 @@ -118,9 +119,9 @@
35647 ----------------------------------------------------------------------*/
35648
35649 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35650 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35651 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35652 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35653 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35654
35655 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35656 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35657 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35658 index 4e491d9..c8e18e4 100644
35659 --- a/block/blk-cgroup.c
35660 +++ b/block/blk-cgroup.c
35661 @@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35662 static struct cgroup_subsys_state *
35663 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35664 {
35665 - static atomic64_t id_seq = ATOMIC64_INIT(0);
35666 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35667 struct blkcg *blkcg;
35668
35669 if (!parent_css) {
35670 @@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35671
35672 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35673 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35674 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35675 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35676 done:
35677 spin_lock_init(&blkcg->lock);
35678 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35679 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35680 index 1855bf5..af12b06 100644
35681 --- a/block/blk-iopoll.c
35682 +++ b/block/blk-iopoll.c
35683 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35684 }
35685 EXPORT_SYMBOL(blk_iopoll_complete);
35686
35687 -static void blk_iopoll_softirq(struct softirq_action *h)
35688 +static __latent_entropy void blk_iopoll_softirq(void)
35689 {
35690 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35691 int rearm = 0, budget = blk_iopoll_budget;
35692 diff --git a/block/blk-map.c b/block/blk-map.c
35693 index ae4ae10..c470b8d 100644
35694 --- a/block/blk-map.c
35695 +++ b/block/blk-map.c
35696 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35697 if (!len || !kbuf)
35698 return -EINVAL;
35699
35700 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35701 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35702 if (do_copy)
35703 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35704 else
35705 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35706 index 57790c1..5e988dd 100644
35707 --- a/block/blk-softirq.c
35708 +++ b/block/blk-softirq.c
35709 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35710 * Softirq action handler - move entries to local list and loop over them
35711 * while passing them to the queue registered handler.
35712 */
35713 -static void blk_done_softirq(struct softirq_action *h)
35714 +static __latent_entropy void blk_done_softirq(void)
35715 {
35716 struct list_head *cpu_list, local_list;
35717
35718 diff --git a/block/bsg.c b/block/bsg.c
35719 index 420a5a9..23834aa 100644
35720 --- a/block/bsg.c
35721 +++ b/block/bsg.c
35722 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35723 struct sg_io_v4 *hdr, struct bsg_device *bd,
35724 fmode_t has_write_perm)
35725 {
35726 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35727 + unsigned char *cmdptr;
35728 +
35729 if (hdr->request_len > BLK_MAX_CDB) {
35730 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35731 if (!rq->cmd)
35732 return -ENOMEM;
35733 - }
35734 + cmdptr = rq->cmd;
35735 + } else
35736 + cmdptr = tmpcmd;
35737
35738 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35739 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35740 hdr->request_len))
35741 return -EFAULT;
35742
35743 + if (cmdptr != rq->cmd)
35744 + memcpy(rq->cmd, cmdptr, hdr->request_len);
35745 +
35746 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35747 if (blk_verify_command(rq->cmd, has_write_perm))
35748 return -EPERM;
35749 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35750 index fbd5a67..f24fd95 100644
35751 --- a/block/compat_ioctl.c
35752 +++ b/block/compat_ioctl.c
35753 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35754 cgc = compat_alloc_user_space(sizeof(*cgc));
35755 cgc32 = compat_ptr(arg);
35756
35757 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35758 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35759 get_user(data, &cgc32->buffer) ||
35760 put_user(compat_ptr(data), &cgc->buffer) ||
35761 copy_in_user(&cgc->buflen, &cgc32->buflen,
35762 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35763 err |= __get_user(f->spec1, &uf->spec1);
35764 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35765 err |= __get_user(name, &uf->name);
35766 - f->name = compat_ptr(name);
35767 + f->name = (void __force_kernel *)compat_ptr(name);
35768 if (err) {
35769 err = -EFAULT;
35770 goto out;
35771 diff --git a/block/genhd.c b/block/genhd.c
35772 index 791f419..89f21c4 100644
35773 --- a/block/genhd.c
35774 +++ b/block/genhd.c
35775 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35776
35777 /*
35778 * Register device numbers dev..(dev+range-1)
35779 - * range must be nonzero
35780 + * Noop if @range is zero.
35781 * The hash chain is sorted on range, so that subranges can override.
35782 */
35783 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35784 struct kobject *(*probe)(dev_t, int *, void *),
35785 int (*lock)(dev_t, void *), void *data)
35786 {
35787 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
35788 + if (range)
35789 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
35790 }
35791
35792 EXPORT_SYMBOL(blk_register_region);
35793
35794 +/* undo blk_register_region(), noop if @range is zero */
35795 void blk_unregister_region(dev_t devt, unsigned long range)
35796 {
35797 - kobj_unmap(bdev_map, devt, range);
35798 + if (range)
35799 + kobj_unmap(bdev_map, devt, range);
35800 }
35801
35802 EXPORT_SYMBOL(blk_unregister_region);
35803 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35804 index dc51f46..d5446a8 100644
35805 --- a/block/partitions/efi.c
35806 +++ b/block/partitions/efi.c
35807 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35808 if (!gpt)
35809 return NULL;
35810
35811 + if (!le32_to_cpu(gpt->num_partition_entries))
35812 + return NULL;
35813 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35814 + if (!pte)
35815 + return NULL;
35816 +
35817 count = le32_to_cpu(gpt->num_partition_entries) *
35818 le32_to_cpu(gpt->sizeof_partition_entry);
35819 - if (!count)
35820 - return NULL;
35821 - pte = kmalloc(count, GFP_KERNEL);
35822 - if (!pte)
35823 - return NULL;
35824 -
35825 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35826 (u8 *) pte, count) < count) {
35827 kfree(pte);
35828 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35829 index 2648797..92ed21f 100644
35830 --- a/block/scsi_ioctl.c
35831 +++ b/block/scsi_ioctl.c
35832 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35833 return put_user(0, p);
35834 }
35835
35836 -static int sg_get_timeout(struct request_queue *q)
35837 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35838 {
35839 return jiffies_to_clock_t(q->sg_timeout);
35840 }
35841 @@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35842 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35843 struct sg_io_hdr *hdr, fmode_t mode)
35844 {
35845 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35846 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35847 + unsigned char *cmdptr;
35848 +
35849 + if (rq->cmd != rq->__cmd)
35850 + cmdptr = rq->cmd;
35851 + else
35852 + cmdptr = tmpcmd;
35853 +
35854 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35855 return -EFAULT;
35856 +
35857 + if (cmdptr != rq->cmd)
35858 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35859 +
35860 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35861 return -EPERM;
35862
35863 @@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35864 int err;
35865 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35866 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35867 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35868 + unsigned char *cmdptr;
35869
35870 if (!sic)
35871 return -EINVAL;
35872 @@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35873 */
35874 err = -EFAULT;
35875 rq->cmd_len = cmdlen;
35876 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
35877 +
35878 + if (rq->cmd != rq->__cmd)
35879 + cmdptr = rq->cmd;
35880 + else
35881 + cmdptr = tmpcmd;
35882 +
35883 + if (copy_from_user(cmdptr, sic->data, cmdlen))
35884 goto error;
35885
35886 + if (rq->cmd != cmdptr)
35887 + memcpy(rq->cmd, cmdptr, cmdlen);
35888 +
35889 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35890 goto error;
35891
35892 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35893 index 7bdd61b..afec999 100644
35894 --- a/crypto/cryptd.c
35895 +++ b/crypto/cryptd.c
35896 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35897
35898 struct cryptd_blkcipher_request_ctx {
35899 crypto_completion_t complete;
35900 -};
35901 +} __no_const;
35902
35903 struct cryptd_hash_ctx {
35904 struct crypto_shash *child;
35905 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35906
35907 struct cryptd_aead_request_ctx {
35908 crypto_completion_t complete;
35909 -};
35910 +} __no_const;
35911
35912 static void cryptd_queue_worker(struct work_struct *work);
35913
35914 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35915 index 309d345..1632720 100644
35916 --- a/crypto/pcrypt.c
35917 +++ b/crypto/pcrypt.c
35918 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35919 int ret;
35920
35921 pinst->kobj.kset = pcrypt_kset;
35922 - ret = kobject_add(&pinst->kobj, NULL, name);
35923 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35924 if (!ret)
35925 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35926
35927 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35928 index 15dddc1..b61cf0c 100644
35929 --- a/drivers/acpi/acpica/hwxfsleep.c
35930 +++ b/drivers/acpi/acpica/hwxfsleep.c
35931 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35932 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35933
35934 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35935 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35936 - acpi_hw_extended_sleep},
35937 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35938 - acpi_hw_extended_wake_prep},
35939 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35940 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35941 + .extended_function = acpi_hw_extended_sleep},
35942 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35943 + .extended_function = acpi_hw_extended_wake_prep},
35944 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35945 + .extended_function = acpi_hw_extended_wake}
35946 };
35947
35948 /*
35949 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35950 index e5bcd91..74f050d 100644
35951 --- a/drivers/acpi/apei/apei-internal.h
35952 +++ b/drivers/acpi/apei/apei-internal.h
35953 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35954 struct apei_exec_ins_type {
35955 u32 flags;
35956 apei_exec_ins_func_t run;
35957 -};
35958 +} __do_const;
35959
35960 struct apei_exec_context {
35961 u32 ip;
35962 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35963 index dab7cb7..f0d2994 100644
35964 --- a/drivers/acpi/apei/ghes.c
35965 +++ b/drivers/acpi/apei/ghes.c
35966 @@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
35967 const struct acpi_hest_generic *generic,
35968 const struct acpi_generic_status *estatus)
35969 {
35970 - static atomic_t seqno;
35971 + static atomic_unchecked_t seqno;
35972 unsigned int curr_seqno;
35973 char pfx_seq[64];
35974
35975 @@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
35976 else
35977 pfx = KERN_ERR;
35978 }
35979 - curr_seqno = atomic_inc_return(&seqno);
35980 + curr_seqno = atomic_inc_return_unchecked(&seqno);
35981 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
35982 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
35983 pfx_seq, generic->header.source_id);
35984 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
35985 index a83e3c6..c3d617f 100644
35986 --- a/drivers/acpi/bgrt.c
35987 +++ b/drivers/acpi/bgrt.c
35988 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
35989 if (!bgrt_image)
35990 return -ENODEV;
35991
35992 - bin_attr_image.private = bgrt_image;
35993 - bin_attr_image.size = bgrt_image_size;
35994 + pax_open_kernel();
35995 + *(void **)&bin_attr_image.private = bgrt_image;
35996 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
35997 + pax_close_kernel();
35998
35999 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36000 if (!bgrt_kobj)
36001 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36002 index afec452..c5d8b96 100644
36003 --- a/drivers/acpi/blacklist.c
36004 +++ b/drivers/acpi/blacklist.c
36005 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36006 u32 is_critical_error;
36007 };
36008
36009 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36010 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36011
36012 /*
36013 * POLICY: If *anything* doesn't work, put it on the blacklist.
36014 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36015 return 0;
36016 }
36017
36018 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36019 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36020 {
36021 .callback = dmi_disable_osi_vista,
36022 .ident = "Fujitsu Siemens",
36023 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36024 index c68e724..e863008 100644
36025 --- a/drivers/acpi/custom_method.c
36026 +++ b/drivers/acpi/custom_method.c
36027 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36028 struct acpi_table_header table;
36029 acpi_status status;
36030
36031 +#ifdef CONFIG_GRKERNSEC_KMEM
36032 + return -EPERM;
36033 +#endif
36034 +
36035 if (!(*ppos)) {
36036 /* parse the table header to get the table length */
36037 if (count <= sizeof(struct acpi_table_header))
36038 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36039 index 3dca36d..abaf070 100644
36040 --- a/drivers/acpi/processor_idle.c
36041 +++ b/drivers/acpi/processor_idle.c
36042 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36043 {
36044 int i, count = CPUIDLE_DRIVER_STATE_START;
36045 struct acpi_processor_cx *cx;
36046 - struct cpuidle_state *state;
36047 + cpuidle_state_no_const *state;
36048 struct cpuidle_driver *drv = &acpi_idle_driver;
36049
36050 if (!pr->flags.power_setup_done)
36051 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36052 index 91a32ce..d77fcaf 100644
36053 --- a/drivers/acpi/sysfs.c
36054 +++ b/drivers/acpi/sysfs.c
36055 @@ -425,11 +425,11 @@ static u32 num_counters;
36056 static struct attribute **all_attrs;
36057 static u32 acpi_gpe_count;
36058
36059 -static struct attribute_group interrupt_stats_attr_group = {
36060 +static attribute_group_no_const interrupt_stats_attr_group = {
36061 .name = "interrupts",
36062 };
36063
36064 -static struct kobj_attribute *counter_attrs;
36065 +static kobj_attribute_no_const *counter_attrs;
36066
36067 static void delete_gpe_attr_array(void)
36068 {
36069 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36070 index 36605ab..6ef6d4b 100644
36071 --- a/drivers/ata/libahci.c
36072 +++ b/drivers/ata/libahci.c
36073 @@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36074 }
36075 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36076
36077 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36078 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36079 struct ata_taskfile *tf, int is_cmd, u16 flags,
36080 unsigned long timeout_msec)
36081 {
36082 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36083 index 8cb2522..a815e54 100644
36084 --- a/drivers/ata/libata-core.c
36085 +++ b/drivers/ata/libata-core.c
36086 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36087 static void ata_dev_xfermask(struct ata_device *dev);
36088 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36089
36090 -atomic_t ata_print_id = ATOMIC_INIT(0);
36091 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36092
36093 struct ata_force_param {
36094 const char *name;
36095 @@ -4851,7 +4851,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36096 struct ata_port *ap;
36097 unsigned int tag;
36098
36099 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36100 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36101 ap = qc->ap;
36102
36103 qc->flags = 0;
36104 @@ -4867,7 +4867,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36105 struct ata_port *ap;
36106 struct ata_link *link;
36107
36108 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36109 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36110 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36111 ap = qc->ap;
36112 link = qc->dev->link;
36113 @@ -5986,6 +5986,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36114 return;
36115
36116 spin_lock(&lock);
36117 + pax_open_kernel();
36118
36119 for (cur = ops->inherits; cur; cur = cur->inherits) {
36120 void **inherit = (void **)cur;
36121 @@ -5999,8 +6000,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36122 if (IS_ERR(*pp))
36123 *pp = NULL;
36124
36125 - ops->inherits = NULL;
36126 + *(struct ata_port_operations **)&ops->inherits = NULL;
36127
36128 + pax_close_kernel();
36129 spin_unlock(&lock);
36130 }
36131
36132 @@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36133
36134 /* give ports names and add SCSI hosts */
36135 for (i = 0; i < host->n_ports; i++) {
36136 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36137 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36138 host->ports[i]->local_port_no = i + 1;
36139 }
36140
36141 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36142 index ef8567d..8bdbd03 100644
36143 --- a/drivers/ata/libata-scsi.c
36144 +++ b/drivers/ata/libata-scsi.c
36145 @@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36146
36147 if (rc)
36148 return rc;
36149 - ap->print_id = atomic_inc_return(&ata_print_id);
36150 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36151 return 0;
36152 }
36153 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36154 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36155 index 45b5ab3..98446b8 100644
36156 --- a/drivers/ata/libata.h
36157 +++ b/drivers/ata/libata.h
36158 @@ -53,7 +53,7 @@ enum {
36159 ATA_DNXFER_QUIET = (1 << 31),
36160 };
36161
36162 -extern atomic_t ata_print_id;
36163 +extern atomic_unchecked_t ata_print_id;
36164 extern int atapi_passthru16;
36165 extern int libata_fua;
36166 extern int libata_noacpi;
36167 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36168 index 73492dd..ca2bff5 100644
36169 --- a/drivers/ata/pata_arasan_cf.c
36170 +++ b/drivers/ata/pata_arasan_cf.c
36171 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36172 /* Handle platform specific quirks */
36173 if (quirk) {
36174 if (quirk & CF_BROKEN_PIO) {
36175 - ap->ops->set_piomode = NULL;
36176 + pax_open_kernel();
36177 + *(void **)&ap->ops->set_piomode = NULL;
36178 + pax_close_kernel();
36179 ap->pio_mask = 0;
36180 }
36181 if (quirk & CF_BROKEN_MWDMA)
36182 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36183 index f9b983a..887b9d8 100644
36184 --- a/drivers/atm/adummy.c
36185 +++ b/drivers/atm/adummy.c
36186 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36187 vcc->pop(vcc, skb);
36188 else
36189 dev_kfree_skb_any(skb);
36190 - atomic_inc(&vcc->stats->tx);
36191 + atomic_inc_unchecked(&vcc->stats->tx);
36192
36193 return 0;
36194 }
36195 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36196 index 62a7607..cc4be104 100644
36197 --- a/drivers/atm/ambassador.c
36198 +++ b/drivers/atm/ambassador.c
36199 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36200 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36201
36202 // VC layer stats
36203 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36204 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36205
36206 // free the descriptor
36207 kfree (tx_descr);
36208 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36209 dump_skb ("<<<", vc, skb);
36210
36211 // VC layer stats
36212 - atomic_inc(&atm_vcc->stats->rx);
36213 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36214 __net_timestamp(skb);
36215 // end of our responsibility
36216 atm_vcc->push (atm_vcc, skb);
36217 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36218 } else {
36219 PRINTK (KERN_INFO, "dropped over-size frame");
36220 // should we count this?
36221 - atomic_inc(&atm_vcc->stats->rx_drop);
36222 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36223 }
36224
36225 } else {
36226 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36227 }
36228
36229 if (check_area (skb->data, skb->len)) {
36230 - atomic_inc(&atm_vcc->stats->tx_err);
36231 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36232 return -ENOMEM; // ?
36233 }
36234
36235 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36236 index 0e3f8f9..765a7a5 100644
36237 --- a/drivers/atm/atmtcp.c
36238 +++ b/drivers/atm/atmtcp.c
36239 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36240 if (vcc->pop) vcc->pop(vcc,skb);
36241 else dev_kfree_skb(skb);
36242 if (dev_data) return 0;
36243 - atomic_inc(&vcc->stats->tx_err);
36244 + atomic_inc_unchecked(&vcc->stats->tx_err);
36245 return -ENOLINK;
36246 }
36247 size = skb->len+sizeof(struct atmtcp_hdr);
36248 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36249 if (!new_skb) {
36250 if (vcc->pop) vcc->pop(vcc,skb);
36251 else dev_kfree_skb(skb);
36252 - atomic_inc(&vcc->stats->tx_err);
36253 + atomic_inc_unchecked(&vcc->stats->tx_err);
36254 return -ENOBUFS;
36255 }
36256 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36257 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36258 if (vcc->pop) vcc->pop(vcc,skb);
36259 else dev_kfree_skb(skb);
36260 out_vcc->push(out_vcc,new_skb);
36261 - atomic_inc(&vcc->stats->tx);
36262 - atomic_inc(&out_vcc->stats->rx);
36263 + atomic_inc_unchecked(&vcc->stats->tx);
36264 + atomic_inc_unchecked(&out_vcc->stats->rx);
36265 return 0;
36266 }
36267
36268 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36269 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36270 read_unlock(&vcc_sklist_lock);
36271 if (!out_vcc) {
36272 - atomic_inc(&vcc->stats->tx_err);
36273 + atomic_inc_unchecked(&vcc->stats->tx_err);
36274 goto done;
36275 }
36276 skb_pull(skb,sizeof(struct atmtcp_hdr));
36277 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36278 __net_timestamp(new_skb);
36279 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36280 out_vcc->push(out_vcc,new_skb);
36281 - atomic_inc(&vcc->stats->tx);
36282 - atomic_inc(&out_vcc->stats->rx);
36283 + atomic_inc_unchecked(&vcc->stats->tx);
36284 + atomic_inc_unchecked(&out_vcc->stats->rx);
36285 done:
36286 if (vcc->pop) vcc->pop(vcc,skb);
36287 else dev_kfree_skb(skb);
36288 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36289 index b1955ba..b179940 100644
36290 --- a/drivers/atm/eni.c
36291 +++ b/drivers/atm/eni.c
36292 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36293 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36294 vcc->dev->number);
36295 length = 0;
36296 - atomic_inc(&vcc->stats->rx_err);
36297 + atomic_inc_unchecked(&vcc->stats->rx_err);
36298 }
36299 else {
36300 length = ATM_CELL_SIZE-1; /* no HEC */
36301 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36302 size);
36303 }
36304 eff = length = 0;
36305 - atomic_inc(&vcc->stats->rx_err);
36306 + atomic_inc_unchecked(&vcc->stats->rx_err);
36307 }
36308 else {
36309 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36310 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36311 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36312 vcc->dev->number,vcc->vci,length,size << 2,descr);
36313 length = eff = 0;
36314 - atomic_inc(&vcc->stats->rx_err);
36315 + atomic_inc_unchecked(&vcc->stats->rx_err);
36316 }
36317 }
36318 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36319 @@ -767,7 +767,7 @@ rx_dequeued++;
36320 vcc->push(vcc,skb);
36321 pushed++;
36322 }
36323 - atomic_inc(&vcc->stats->rx);
36324 + atomic_inc_unchecked(&vcc->stats->rx);
36325 }
36326 wake_up(&eni_dev->rx_wait);
36327 }
36328 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36329 PCI_DMA_TODEVICE);
36330 if (vcc->pop) vcc->pop(vcc,skb);
36331 else dev_kfree_skb_irq(skb);
36332 - atomic_inc(&vcc->stats->tx);
36333 + atomic_inc_unchecked(&vcc->stats->tx);
36334 wake_up(&eni_dev->tx_wait);
36335 dma_complete++;
36336 }
36337 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36338 index b41c948..a002b17 100644
36339 --- a/drivers/atm/firestream.c
36340 +++ b/drivers/atm/firestream.c
36341 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36342 }
36343 }
36344
36345 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36346 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36347
36348 fs_dprintk (FS_DEBUG_TXMEM, "i");
36349 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36350 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36351 #endif
36352 skb_put (skb, qe->p1 & 0xffff);
36353 ATM_SKB(skb)->vcc = atm_vcc;
36354 - atomic_inc(&atm_vcc->stats->rx);
36355 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36356 __net_timestamp(skb);
36357 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36358 atm_vcc->push (atm_vcc, skb);
36359 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36360 kfree (pe);
36361 }
36362 if (atm_vcc)
36363 - atomic_inc(&atm_vcc->stats->rx_drop);
36364 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36365 break;
36366 case 0x1f: /* Reassembly abort: no buffers. */
36367 /* Silently increment error counter. */
36368 if (atm_vcc)
36369 - atomic_inc(&atm_vcc->stats->rx_drop);
36370 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36371 break;
36372 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36373 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36374 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36375 index 204814e..cede831 100644
36376 --- a/drivers/atm/fore200e.c
36377 +++ b/drivers/atm/fore200e.c
36378 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36379 #endif
36380 /* check error condition */
36381 if (*entry->status & STATUS_ERROR)
36382 - atomic_inc(&vcc->stats->tx_err);
36383 + atomic_inc_unchecked(&vcc->stats->tx_err);
36384 else
36385 - atomic_inc(&vcc->stats->tx);
36386 + atomic_inc_unchecked(&vcc->stats->tx);
36387 }
36388 }
36389
36390 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36391 if (skb == NULL) {
36392 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36393
36394 - atomic_inc(&vcc->stats->rx_drop);
36395 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36396 return -ENOMEM;
36397 }
36398
36399 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36400
36401 dev_kfree_skb_any(skb);
36402
36403 - atomic_inc(&vcc->stats->rx_drop);
36404 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36405 return -ENOMEM;
36406 }
36407
36408 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36409
36410 vcc->push(vcc, skb);
36411 - atomic_inc(&vcc->stats->rx);
36412 + atomic_inc_unchecked(&vcc->stats->rx);
36413
36414 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36415
36416 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36417 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36418 fore200e->atm_dev->number,
36419 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36420 - atomic_inc(&vcc->stats->rx_err);
36421 + atomic_inc_unchecked(&vcc->stats->rx_err);
36422 }
36423 }
36424
36425 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36426 goto retry_here;
36427 }
36428
36429 - atomic_inc(&vcc->stats->tx_err);
36430 + atomic_inc_unchecked(&vcc->stats->tx_err);
36431
36432 fore200e->tx_sat++;
36433 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36434 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36435 index aa6be26..f70a785 100644
36436 --- a/drivers/atm/he.c
36437 +++ b/drivers/atm/he.c
36438 @@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36439
36440 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36441 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36442 - atomic_inc(&vcc->stats->rx_drop);
36443 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36444 goto return_host_buffers;
36445 }
36446
36447 @@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36448 RBRQ_LEN_ERR(he_dev->rbrq_head)
36449 ? "LEN_ERR" : "",
36450 vcc->vpi, vcc->vci);
36451 - atomic_inc(&vcc->stats->rx_err);
36452 + atomic_inc_unchecked(&vcc->stats->rx_err);
36453 goto return_host_buffers;
36454 }
36455
36456 @@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36457 vcc->push(vcc, skb);
36458 spin_lock(&he_dev->global_lock);
36459
36460 - atomic_inc(&vcc->stats->rx);
36461 + atomic_inc_unchecked(&vcc->stats->rx);
36462
36463 return_host_buffers:
36464 ++pdus_assembled;
36465 @@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36466 tpd->vcc->pop(tpd->vcc, tpd->skb);
36467 else
36468 dev_kfree_skb_any(tpd->skb);
36469 - atomic_inc(&tpd->vcc->stats->tx_err);
36470 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36471 }
36472 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36473 return;
36474 @@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36475 vcc->pop(vcc, skb);
36476 else
36477 dev_kfree_skb_any(skb);
36478 - atomic_inc(&vcc->stats->tx_err);
36479 + atomic_inc_unchecked(&vcc->stats->tx_err);
36480 return -EINVAL;
36481 }
36482
36483 @@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36484 vcc->pop(vcc, skb);
36485 else
36486 dev_kfree_skb_any(skb);
36487 - atomic_inc(&vcc->stats->tx_err);
36488 + atomic_inc_unchecked(&vcc->stats->tx_err);
36489 return -EINVAL;
36490 }
36491 #endif
36492 @@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36493 vcc->pop(vcc, skb);
36494 else
36495 dev_kfree_skb_any(skb);
36496 - atomic_inc(&vcc->stats->tx_err);
36497 + atomic_inc_unchecked(&vcc->stats->tx_err);
36498 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36499 return -ENOMEM;
36500 }
36501 @@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36502 vcc->pop(vcc, skb);
36503 else
36504 dev_kfree_skb_any(skb);
36505 - atomic_inc(&vcc->stats->tx_err);
36506 + atomic_inc_unchecked(&vcc->stats->tx_err);
36507 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36508 return -ENOMEM;
36509 }
36510 @@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36511 __enqueue_tpd(he_dev, tpd, cid);
36512 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36513
36514 - atomic_inc(&vcc->stats->tx);
36515 + atomic_inc_unchecked(&vcc->stats->tx);
36516
36517 return 0;
36518 }
36519 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36520 index 1dc0519..1aadaf7 100644
36521 --- a/drivers/atm/horizon.c
36522 +++ b/drivers/atm/horizon.c
36523 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36524 {
36525 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36526 // VC layer stats
36527 - atomic_inc(&vcc->stats->rx);
36528 + atomic_inc_unchecked(&vcc->stats->rx);
36529 __net_timestamp(skb);
36530 // end of our responsibility
36531 vcc->push (vcc, skb);
36532 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36533 dev->tx_iovec = NULL;
36534
36535 // VC layer stats
36536 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36537 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36538
36539 // free the skb
36540 hrz_kfree_skb (skb);
36541 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36542 index 1bdf104..9dc44b1 100644
36543 --- a/drivers/atm/idt77252.c
36544 +++ b/drivers/atm/idt77252.c
36545 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36546 else
36547 dev_kfree_skb(skb);
36548
36549 - atomic_inc(&vcc->stats->tx);
36550 + atomic_inc_unchecked(&vcc->stats->tx);
36551 }
36552
36553 atomic_dec(&scq->used);
36554 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36555 if ((sb = dev_alloc_skb(64)) == NULL) {
36556 printk("%s: Can't allocate buffers for aal0.\n",
36557 card->name);
36558 - atomic_add(i, &vcc->stats->rx_drop);
36559 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36560 break;
36561 }
36562 if (!atm_charge(vcc, sb->truesize)) {
36563 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36564 card->name);
36565 - atomic_add(i - 1, &vcc->stats->rx_drop);
36566 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36567 dev_kfree_skb(sb);
36568 break;
36569 }
36570 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36571 ATM_SKB(sb)->vcc = vcc;
36572 __net_timestamp(sb);
36573 vcc->push(vcc, sb);
36574 - atomic_inc(&vcc->stats->rx);
36575 + atomic_inc_unchecked(&vcc->stats->rx);
36576
36577 cell += ATM_CELL_PAYLOAD;
36578 }
36579 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36580 "(CDC: %08x)\n",
36581 card->name, len, rpp->len, readl(SAR_REG_CDC));
36582 recycle_rx_pool_skb(card, rpp);
36583 - atomic_inc(&vcc->stats->rx_err);
36584 + atomic_inc_unchecked(&vcc->stats->rx_err);
36585 return;
36586 }
36587 if (stat & SAR_RSQE_CRC) {
36588 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36589 recycle_rx_pool_skb(card, rpp);
36590 - atomic_inc(&vcc->stats->rx_err);
36591 + atomic_inc_unchecked(&vcc->stats->rx_err);
36592 return;
36593 }
36594 if (skb_queue_len(&rpp->queue) > 1) {
36595 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36596 RXPRINTK("%s: Can't alloc RX skb.\n",
36597 card->name);
36598 recycle_rx_pool_skb(card, rpp);
36599 - atomic_inc(&vcc->stats->rx_err);
36600 + atomic_inc_unchecked(&vcc->stats->rx_err);
36601 return;
36602 }
36603 if (!atm_charge(vcc, skb->truesize)) {
36604 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36605 __net_timestamp(skb);
36606
36607 vcc->push(vcc, skb);
36608 - atomic_inc(&vcc->stats->rx);
36609 + atomic_inc_unchecked(&vcc->stats->rx);
36610
36611 return;
36612 }
36613 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36614 __net_timestamp(skb);
36615
36616 vcc->push(vcc, skb);
36617 - atomic_inc(&vcc->stats->rx);
36618 + atomic_inc_unchecked(&vcc->stats->rx);
36619
36620 if (skb->truesize > SAR_FB_SIZE_3)
36621 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36622 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36623 if (vcc->qos.aal != ATM_AAL0) {
36624 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36625 card->name, vpi, vci);
36626 - atomic_inc(&vcc->stats->rx_drop);
36627 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36628 goto drop;
36629 }
36630
36631 if ((sb = dev_alloc_skb(64)) == NULL) {
36632 printk("%s: Can't allocate buffers for AAL0.\n",
36633 card->name);
36634 - atomic_inc(&vcc->stats->rx_err);
36635 + atomic_inc_unchecked(&vcc->stats->rx_err);
36636 goto drop;
36637 }
36638
36639 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36640 ATM_SKB(sb)->vcc = vcc;
36641 __net_timestamp(sb);
36642 vcc->push(vcc, sb);
36643 - atomic_inc(&vcc->stats->rx);
36644 + atomic_inc_unchecked(&vcc->stats->rx);
36645
36646 drop:
36647 skb_pull(queue, 64);
36648 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36649
36650 if (vc == NULL) {
36651 printk("%s: NULL connection in send().\n", card->name);
36652 - atomic_inc(&vcc->stats->tx_err);
36653 + atomic_inc_unchecked(&vcc->stats->tx_err);
36654 dev_kfree_skb(skb);
36655 return -EINVAL;
36656 }
36657 if (!test_bit(VCF_TX, &vc->flags)) {
36658 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36659 - atomic_inc(&vcc->stats->tx_err);
36660 + atomic_inc_unchecked(&vcc->stats->tx_err);
36661 dev_kfree_skb(skb);
36662 return -EINVAL;
36663 }
36664 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36665 break;
36666 default:
36667 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36668 - atomic_inc(&vcc->stats->tx_err);
36669 + atomic_inc_unchecked(&vcc->stats->tx_err);
36670 dev_kfree_skb(skb);
36671 return -EINVAL;
36672 }
36673
36674 if (skb_shinfo(skb)->nr_frags != 0) {
36675 printk("%s: No scatter-gather yet.\n", card->name);
36676 - atomic_inc(&vcc->stats->tx_err);
36677 + atomic_inc_unchecked(&vcc->stats->tx_err);
36678 dev_kfree_skb(skb);
36679 return -EINVAL;
36680 }
36681 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36682
36683 err = queue_skb(card, vc, skb, oam);
36684 if (err) {
36685 - atomic_inc(&vcc->stats->tx_err);
36686 + atomic_inc_unchecked(&vcc->stats->tx_err);
36687 dev_kfree_skb(skb);
36688 return err;
36689 }
36690 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36691 skb = dev_alloc_skb(64);
36692 if (!skb) {
36693 printk("%s: Out of memory in send_oam().\n", card->name);
36694 - atomic_inc(&vcc->stats->tx_err);
36695 + atomic_inc_unchecked(&vcc->stats->tx_err);
36696 return -ENOMEM;
36697 }
36698 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36699 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36700 index 4217f29..88f547a 100644
36701 --- a/drivers/atm/iphase.c
36702 +++ b/drivers/atm/iphase.c
36703 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36704 status = (u_short) (buf_desc_ptr->desc_mode);
36705 if (status & (RX_CER | RX_PTE | RX_OFL))
36706 {
36707 - atomic_inc(&vcc->stats->rx_err);
36708 + atomic_inc_unchecked(&vcc->stats->rx_err);
36709 IF_ERR(printk("IA: bad packet, dropping it");)
36710 if (status & RX_CER) {
36711 IF_ERR(printk(" cause: packet CRC error\n");)
36712 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36713 len = dma_addr - buf_addr;
36714 if (len > iadev->rx_buf_sz) {
36715 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36716 - atomic_inc(&vcc->stats->rx_err);
36717 + atomic_inc_unchecked(&vcc->stats->rx_err);
36718 goto out_free_desc;
36719 }
36720
36721 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36722 ia_vcc = INPH_IA_VCC(vcc);
36723 if (ia_vcc == NULL)
36724 {
36725 - atomic_inc(&vcc->stats->rx_err);
36726 + atomic_inc_unchecked(&vcc->stats->rx_err);
36727 atm_return(vcc, skb->truesize);
36728 dev_kfree_skb_any(skb);
36729 goto INCR_DLE;
36730 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36731 if ((length > iadev->rx_buf_sz) || (length >
36732 (skb->len - sizeof(struct cpcs_trailer))))
36733 {
36734 - atomic_inc(&vcc->stats->rx_err);
36735 + atomic_inc_unchecked(&vcc->stats->rx_err);
36736 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36737 length, skb->len);)
36738 atm_return(vcc, skb->truesize);
36739 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36740
36741 IF_RX(printk("rx_dle_intr: skb push");)
36742 vcc->push(vcc,skb);
36743 - atomic_inc(&vcc->stats->rx);
36744 + atomic_inc_unchecked(&vcc->stats->rx);
36745 iadev->rx_pkt_cnt++;
36746 }
36747 INCR_DLE:
36748 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36749 {
36750 struct k_sonet_stats *stats;
36751 stats = &PRIV(_ia_dev[board])->sonet_stats;
36752 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36753 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36754 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36755 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36756 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36757 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36758 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36759 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36760 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36761 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36762 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36763 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36764 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36765 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36766 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36767 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36768 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36769 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36770 }
36771 ia_cmds.status = 0;
36772 break;
36773 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36774 if ((desc == 0) || (desc > iadev->num_tx_desc))
36775 {
36776 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36777 - atomic_inc(&vcc->stats->tx);
36778 + atomic_inc_unchecked(&vcc->stats->tx);
36779 if (vcc->pop)
36780 vcc->pop(vcc, skb);
36781 else
36782 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36783 ATM_DESC(skb) = vcc->vci;
36784 skb_queue_tail(&iadev->tx_dma_q, skb);
36785
36786 - atomic_inc(&vcc->stats->tx);
36787 + atomic_inc_unchecked(&vcc->stats->tx);
36788 iadev->tx_pkt_cnt++;
36789 /* Increment transaction counter */
36790 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36791
36792 #if 0
36793 /* add flow control logic */
36794 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36795 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36796 if (iavcc->vc_desc_cnt > 10) {
36797 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36798 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36799 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36800 index fa7d701..1e404c7 100644
36801 --- a/drivers/atm/lanai.c
36802 +++ b/drivers/atm/lanai.c
36803 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36804 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36805 lanai_endtx(lanai, lvcc);
36806 lanai_free_skb(lvcc->tx.atmvcc, skb);
36807 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36808 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36809 }
36810
36811 /* Try to fill the buffer - don't call unless there is backlog */
36812 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36813 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36814 __net_timestamp(skb);
36815 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36816 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36817 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36818 out:
36819 lvcc->rx.buf.ptr = end;
36820 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36821 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36822 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36823 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36824 lanai->stats.service_rxnotaal5++;
36825 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36826 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36827 return 0;
36828 }
36829 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36830 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36831 int bytes;
36832 read_unlock(&vcc_sklist_lock);
36833 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36834 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36835 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36836 lvcc->stats.x.aal5.service_trash++;
36837 bytes = (SERVICE_GET_END(s) * 16) -
36838 (((unsigned long) lvcc->rx.buf.ptr) -
36839 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36840 }
36841 if (s & SERVICE_STREAM) {
36842 read_unlock(&vcc_sklist_lock);
36843 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36844 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36845 lvcc->stats.x.aal5.service_stream++;
36846 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36847 "PDU on VCI %d!\n", lanai->number, vci);
36848 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36849 return 0;
36850 }
36851 DPRINTK("got rx crc error on vci %d\n", vci);
36852 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36853 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36854 lvcc->stats.x.aal5.service_rxcrc++;
36855 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36856 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36857 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36858 index 9587e95..b45c5cb 100644
36859 --- a/drivers/atm/nicstar.c
36860 +++ b/drivers/atm/nicstar.c
36861 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36862 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36863 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36864 card->index);
36865 - atomic_inc(&vcc->stats->tx_err);
36866 + atomic_inc_unchecked(&vcc->stats->tx_err);
36867 dev_kfree_skb_any(skb);
36868 return -EINVAL;
36869 }
36870 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36871 if (!vc->tx) {
36872 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36873 card->index);
36874 - atomic_inc(&vcc->stats->tx_err);
36875 + atomic_inc_unchecked(&vcc->stats->tx_err);
36876 dev_kfree_skb_any(skb);
36877 return -EINVAL;
36878 }
36879 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36880 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36881 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36882 card->index);
36883 - atomic_inc(&vcc->stats->tx_err);
36884 + atomic_inc_unchecked(&vcc->stats->tx_err);
36885 dev_kfree_skb_any(skb);
36886 return -EINVAL;
36887 }
36888
36889 if (skb_shinfo(skb)->nr_frags != 0) {
36890 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36891 - atomic_inc(&vcc->stats->tx_err);
36892 + atomic_inc_unchecked(&vcc->stats->tx_err);
36893 dev_kfree_skb_any(skb);
36894 return -EINVAL;
36895 }
36896 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36897 }
36898
36899 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36900 - atomic_inc(&vcc->stats->tx_err);
36901 + atomic_inc_unchecked(&vcc->stats->tx_err);
36902 dev_kfree_skb_any(skb);
36903 return -EIO;
36904 }
36905 - atomic_inc(&vcc->stats->tx);
36906 + atomic_inc_unchecked(&vcc->stats->tx);
36907
36908 return 0;
36909 }
36910 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36911 printk
36912 ("nicstar%d: Can't allocate buffers for aal0.\n",
36913 card->index);
36914 - atomic_add(i, &vcc->stats->rx_drop);
36915 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36916 break;
36917 }
36918 if (!atm_charge(vcc, sb->truesize)) {
36919 RXPRINTK
36920 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36921 card->index);
36922 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36923 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36924 dev_kfree_skb_any(sb);
36925 break;
36926 }
36927 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36928 ATM_SKB(sb)->vcc = vcc;
36929 __net_timestamp(sb);
36930 vcc->push(vcc, sb);
36931 - atomic_inc(&vcc->stats->rx);
36932 + atomic_inc_unchecked(&vcc->stats->rx);
36933 cell += ATM_CELL_PAYLOAD;
36934 }
36935
36936 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36937 if (iovb == NULL) {
36938 printk("nicstar%d: Out of iovec buffers.\n",
36939 card->index);
36940 - atomic_inc(&vcc->stats->rx_drop);
36941 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36942 recycle_rx_buf(card, skb);
36943 return;
36944 }
36945 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36946 small or large buffer itself. */
36947 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36948 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36949 - atomic_inc(&vcc->stats->rx_err);
36950 + atomic_inc_unchecked(&vcc->stats->rx_err);
36951 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36952 NS_MAX_IOVECS);
36953 NS_PRV_IOVCNT(iovb) = 0;
36954 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36955 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36956 card->index);
36957 which_list(card, skb);
36958 - atomic_inc(&vcc->stats->rx_err);
36959 + atomic_inc_unchecked(&vcc->stats->rx_err);
36960 recycle_rx_buf(card, skb);
36961 vc->rx_iov = NULL;
36962 recycle_iov_buf(card, iovb);
36963 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36964 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36965 card->index);
36966 which_list(card, skb);
36967 - atomic_inc(&vcc->stats->rx_err);
36968 + atomic_inc_unchecked(&vcc->stats->rx_err);
36969 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36970 NS_PRV_IOVCNT(iovb));
36971 vc->rx_iov = NULL;
36972 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36973 printk(" - PDU size mismatch.\n");
36974 else
36975 printk(".\n");
36976 - atomic_inc(&vcc->stats->rx_err);
36977 + atomic_inc_unchecked(&vcc->stats->rx_err);
36978 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36979 NS_PRV_IOVCNT(iovb));
36980 vc->rx_iov = NULL;
36981 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36982 /* skb points to a small buffer */
36983 if (!atm_charge(vcc, skb->truesize)) {
36984 push_rxbufs(card, skb);
36985 - atomic_inc(&vcc->stats->rx_drop);
36986 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36987 } else {
36988 skb_put(skb, len);
36989 dequeue_sm_buf(card, skb);
36990 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36991 ATM_SKB(skb)->vcc = vcc;
36992 __net_timestamp(skb);
36993 vcc->push(vcc, skb);
36994 - atomic_inc(&vcc->stats->rx);
36995 + atomic_inc_unchecked(&vcc->stats->rx);
36996 }
36997 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
36998 struct sk_buff *sb;
36999 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37000 if (len <= NS_SMBUFSIZE) {
37001 if (!atm_charge(vcc, sb->truesize)) {
37002 push_rxbufs(card, sb);
37003 - atomic_inc(&vcc->stats->rx_drop);
37004 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37005 } else {
37006 skb_put(sb, len);
37007 dequeue_sm_buf(card, sb);
37008 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37009 ATM_SKB(sb)->vcc = vcc;
37010 __net_timestamp(sb);
37011 vcc->push(vcc, sb);
37012 - atomic_inc(&vcc->stats->rx);
37013 + atomic_inc_unchecked(&vcc->stats->rx);
37014 }
37015
37016 push_rxbufs(card, skb);
37017 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37018
37019 if (!atm_charge(vcc, skb->truesize)) {
37020 push_rxbufs(card, skb);
37021 - atomic_inc(&vcc->stats->rx_drop);
37022 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37023 } else {
37024 dequeue_lg_buf(card, skb);
37025 #ifdef NS_USE_DESTRUCTORS
37026 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37027 ATM_SKB(skb)->vcc = vcc;
37028 __net_timestamp(skb);
37029 vcc->push(vcc, skb);
37030 - atomic_inc(&vcc->stats->rx);
37031 + atomic_inc_unchecked(&vcc->stats->rx);
37032 }
37033
37034 push_rxbufs(card, sb);
37035 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37036 printk
37037 ("nicstar%d: Out of huge buffers.\n",
37038 card->index);
37039 - atomic_inc(&vcc->stats->rx_drop);
37040 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37041 recycle_iovec_rx_bufs(card,
37042 (struct iovec *)
37043 iovb->data,
37044 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37045 card->hbpool.count++;
37046 } else
37047 dev_kfree_skb_any(hb);
37048 - atomic_inc(&vcc->stats->rx_drop);
37049 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37050 } else {
37051 /* Copy the small buffer to the huge buffer */
37052 sb = (struct sk_buff *)iov->iov_base;
37053 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37054 #endif /* NS_USE_DESTRUCTORS */
37055 __net_timestamp(hb);
37056 vcc->push(vcc, hb);
37057 - atomic_inc(&vcc->stats->rx);
37058 + atomic_inc_unchecked(&vcc->stats->rx);
37059 }
37060 }
37061
37062 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37063 index e3fb496..d9646bf 100644
37064 --- a/drivers/atm/solos-pci.c
37065 +++ b/drivers/atm/solos-pci.c
37066 @@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37067 }
37068 atm_charge(vcc, skb->truesize);
37069 vcc->push(vcc, skb);
37070 - atomic_inc(&vcc->stats->rx);
37071 + atomic_inc_unchecked(&vcc->stats->rx);
37072 break;
37073
37074 case PKT_STATUS:
37075 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37076 vcc = SKB_CB(oldskb)->vcc;
37077
37078 if (vcc) {
37079 - atomic_inc(&vcc->stats->tx);
37080 + atomic_inc_unchecked(&vcc->stats->tx);
37081 solos_pop(vcc, oldskb);
37082 } else {
37083 dev_kfree_skb_irq(oldskb);
37084 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37085 index 0215934..ce9f5b1 100644
37086 --- a/drivers/atm/suni.c
37087 +++ b/drivers/atm/suni.c
37088 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37089
37090
37091 #define ADD_LIMITED(s,v) \
37092 - atomic_add((v),&stats->s); \
37093 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37094 + atomic_add_unchecked((v),&stats->s); \
37095 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37096
37097
37098 static void suni_hz(unsigned long from_timer)
37099 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37100 index 5120a96..e2572bd 100644
37101 --- a/drivers/atm/uPD98402.c
37102 +++ b/drivers/atm/uPD98402.c
37103 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37104 struct sonet_stats tmp;
37105 int error = 0;
37106
37107 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37108 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37109 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37110 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37111 if (zero && !error) {
37112 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37113
37114
37115 #define ADD_LIMITED(s,v) \
37116 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37117 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37118 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37119 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37120 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37121 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37122
37123
37124 static void stat_event(struct atm_dev *dev)
37125 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37126 if (reason & uPD98402_INT_PFM) stat_event(dev);
37127 if (reason & uPD98402_INT_PCO) {
37128 (void) GET(PCOCR); /* clear interrupt cause */
37129 - atomic_add(GET(HECCT),
37130 + atomic_add_unchecked(GET(HECCT),
37131 &PRIV(dev)->sonet_stats.uncorr_hcs);
37132 }
37133 if ((reason & uPD98402_INT_RFO) &&
37134 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37135 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37136 uPD98402_INT_LOS),PIMR); /* enable them */
37137 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37138 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37139 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37140 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37141 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37142 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37143 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37144 return 0;
37145 }
37146
37147 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37148 index 969c3c2..9b72956 100644
37149 --- a/drivers/atm/zatm.c
37150 +++ b/drivers/atm/zatm.c
37151 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37152 }
37153 if (!size) {
37154 dev_kfree_skb_irq(skb);
37155 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37156 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37157 continue;
37158 }
37159 if (!atm_charge(vcc,skb->truesize)) {
37160 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37161 skb->len = size;
37162 ATM_SKB(skb)->vcc = vcc;
37163 vcc->push(vcc,skb);
37164 - atomic_inc(&vcc->stats->rx);
37165 + atomic_inc_unchecked(&vcc->stats->rx);
37166 }
37167 zout(pos & 0xffff,MTA(mbx));
37168 #if 0 /* probably a stupid idea */
37169 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37170 skb_queue_head(&zatm_vcc->backlog,skb);
37171 break;
37172 }
37173 - atomic_inc(&vcc->stats->tx);
37174 + atomic_inc_unchecked(&vcc->stats->tx);
37175 wake_up(&zatm_vcc->tx_wait);
37176 }
37177
37178 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37179 index 59dc808..f10c74e 100644
37180 --- a/drivers/base/bus.c
37181 +++ b/drivers/base/bus.c
37182 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37183 return -EINVAL;
37184
37185 mutex_lock(&subsys->p->mutex);
37186 - list_add_tail(&sif->node, &subsys->p->interfaces);
37187 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37188 if (sif->add_dev) {
37189 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37190 while ((dev = subsys_dev_iter_next(&iter)))
37191 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37192 subsys = sif->subsys;
37193
37194 mutex_lock(&subsys->p->mutex);
37195 - list_del_init(&sif->node);
37196 + pax_list_del_init((struct list_head *)&sif->node);
37197 if (sif->remove_dev) {
37198 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37199 while ((dev = subsys_dev_iter_next(&iter)))
37200 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37201 index 25798db..15f130e 100644
37202 --- a/drivers/base/devtmpfs.c
37203 +++ b/drivers/base/devtmpfs.c
37204 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37205 if (!thread)
37206 return 0;
37207
37208 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37209 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37210 if (err)
37211 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37212 else
37213 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37214 *err = sys_unshare(CLONE_NEWNS);
37215 if (*err)
37216 goto out;
37217 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37218 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37219 if (*err)
37220 goto out;
37221 - sys_chdir("/.."); /* will traverse into overmounted root */
37222 - sys_chroot(".");
37223 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37224 + sys_chroot((char __force_user *)".");
37225 complete(&setup_done);
37226 while (1) {
37227 spin_lock(&req_lock);
37228 diff --git a/drivers/base/node.c b/drivers/base/node.c
37229 index bc9f43b..29703b8 100644
37230 --- a/drivers/base/node.c
37231 +++ b/drivers/base/node.c
37232 @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37233 struct node_attr {
37234 struct device_attribute attr;
37235 enum node_states state;
37236 -};
37237 +} __do_const;
37238
37239 static ssize_t show_node_state(struct device *dev,
37240 struct device_attribute *attr, char *buf)
37241 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37242 index bfb8955..4ebff34 100644
37243 --- a/drivers/base/power/domain.c
37244 +++ b/drivers/base/power/domain.c
37245 @@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37246
37247 if (dev->power.subsys_data->domain_data) {
37248 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37249 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
37250 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37251 if (clear_td)
37252 - gpd_data->td = (struct gpd_timing_data){ 0 };
37253 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37254
37255 if (--gpd_data->refcount == 0) {
37256 dev->power.subsys_data->domain_data = NULL;
37257 @@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37258 {
37259 struct cpuidle_driver *cpuidle_drv;
37260 struct gpd_cpu_data *cpu_data;
37261 - struct cpuidle_state *idle_state;
37262 + cpuidle_state_no_const *idle_state;
37263 int ret = 0;
37264
37265 if (IS_ERR_OR_NULL(genpd) || state < 0)
37266 @@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37267 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37268 {
37269 struct gpd_cpu_data *cpu_data;
37270 - struct cpuidle_state *idle_state;
37271 + cpuidle_state_no_const *idle_state;
37272 int ret = 0;
37273
37274 if (IS_ERR_OR_NULL(genpd))
37275 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37276 index 03e089a..0e9560c 100644
37277 --- a/drivers/base/power/sysfs.c
37278 +++ b/drivers/base/power/sysfs.c
37279 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37280 return -EIO;
37281 }
37282 }
37283 - return sprintf(buf, p);
37284 + return sprintf(buf, "%s", p);
37285 }
37286
37287 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37288 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37289 index 2d56f41..8830f19 100644
37290 --- a/drivers/base/power/wakeup.c
37291 +++ b/drivers/base/power/wakeup.c
37292 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37293 * They need to be modified together atomically, so it's better to use one
37294 * atomic variable to hold them both.
37295 */
37296 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37297 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37298
37299 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37300 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37301
37302 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37303 {
37304 - unsigned int comb = atomic_read(&combined_event_count);
37305 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37306
37307 *cnt = (comb >> IN_PROGRESS_BITS);
37308 *inpr = comb & MAX_IN_PROGRESS;
37309 @@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37310 ws->start_prevent_time = ws->last_time;
37311
37312 /* Increment the counter of events in progress. */
37313 - cec = atomic_inc_return(&combined_event_count);
37314 + cec = atomic_inc_return_unchecked(&combined_event_count);
37315
37316 trace_wakeup_source_activate(ws->name, cec);
37317 }
37318 @@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37319 * Increment the counter of registered wakeup events and decrement the
37320 * couter of wakeup events in progress simultaneously.
37321 */
37322 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37323 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37324 trace_wakeup_source_deactivate(ws->name, cec);
37325
37326 split_counters(&cnt, &inpr);
37327 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37328 index e8d11b6..7b1b36f 100644
37329 --- a/drivers/base/syscore.c
37330 +++ b/drivers/base/syscore.c
37331 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37332 void register_syscore_ops(struct syscore_ops *ops)
37333 {
37334 mutex_lock(&syscore_ops_lock);
37335 - list_add_tail(&ops->node, &syscore_ops_list);
37336 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37337 mutex_unlock(&syscore_ops_lock);
37338 }
37339 EXPORT_SYMBOL_GPL(register_syscore_ops);
37340 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37341 void unregister_syscore_ops(struct syscore_ops *ops)
37342 {
37343 mutex_lock(&syscore_ops_lock);
37344 - list_del(&ops->node);
37345 + pax_list_del((struct list_head *)&ops->node);
37346 mutex_unlock(&syscore_ops_lock);
37347 }
37348 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37349 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37350 index 036e8ab..6221dec 100644
37351 --- a/drivers/block/cciss.c
37352 +++ b/drivers/block/cciss.c
37353 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37354 while (!list_empty(&h->reqQ)) {
37355 c = list_entry(h->reqQ.next, CommandList_struct, list);
37356 /* can't do anything if fifo is full */
37357 - if ((h->access.fifo_full(h))) {
37358 + if ((h->access->fifo_full(h))) {
37359 dev_warn(&h->pdev->dev, "fifo full\n");
37360 break;
37361 }
37362 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37363 h->Qdepth--;
37364
37365 /* Tell the controller execute command */
37366 - h->access.submit_command(h, c);
37367 + h->access->submit_command(h, c);
37368
37369 /* Put job onto the completed Q */
37370 addQ(&h->cmpQ, c);
37371 @@ -3447,17 +3447,17 @@ startio:
37372
37373 static inline unsigned long get_next_completion(ctlr_info_t *h)
37374 {
37375 - return h->access.command_completed(h);
37376 + return h->access->command_completed(h);
37377 }
37378
37379 static inline int interrupt_pending(ctlr_info_t *h)
37380 {
37381 - return h->access.intr_pending(h);
37382 + return h->access->intr_pending(h);
37383 }
37384
37385 static inline long interrupt_not_for_us(ctlr_info_t *h)
37386 {
37387 - return ((h->access.intr_pending(h) == 0) ||
37388 + return ((h->access->intr_pending(h) == 0) ||
37389 (h->interrupts_enabled == 0));
37390 }
37391
37392 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37393 u32 a;
37394
37395 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37396 - return h->access.command_completed(h);
37397 + return h->access->command_completed(h);
37398
37399 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37400 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37401 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37402 trans_support & CFGTBL_Trans_use_short_tags);
37403
37404 /* Change the access methods to the performant access methods */
37405 - h->access = SA5_performant_access;
37406 + h->access = &SA5_performant_access;
37407 h->transMethod = CFGTBL_Trans_Performant;
37408
37409 return;
37410 @@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37411 if (prod_index < 0)
37412 return -ENODEV;
37413 h->product_name = products[prod_index].product_name;
37414 - h->access = *(products[prod_index].access);
37415 + h->access = products[prod_index].access;
37416
37417 if (cciss_board_disabled(h)) {
37418 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37419 @@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37420 }
37421
37422 /* make sure the board interrupts are off */
37423 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37424 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37425 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37426 if (rc)
37427 goto clean2;
37428 @@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37429 * fake ones to scoop up any residual completions.
37430 */
37431 spin_lock_irqsave(&h->lock, flags);
37432 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37433 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37434 spin_unlock_irqrestore(&h->lock, flags);
37435 free_irq(h->intr[h->intr_mode], h);
37436 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37437 @@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37438 dev_info(&h->pdev->dev, "Board READY.\n");
37439 dev_info(&h->pdev->dev,
37440 "Waiting for stale completions to drain.\n");
37441 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37442 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37443 msleep(10000);
37444 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37445 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37446
37447 rc = controller_reset_failed(h->cfgtable);
37448 if (rc)
37449 @@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37450 cciss_scsi_setup(h);
37451
37452 /* Turn the interrupts on so we can service requests */
37453 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37454 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37455
37456 /* Get the firmware version */
37457 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37458 @@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37459 kfree(flush_buf);
37460 if (return_code != IO_OK)
37461 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37462 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37463 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37464 free_irq(h->intr[h->intr_mode], h);
37465 }
37466
37467 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37468 index 7fda30e..2f27946 100644
37469 --- a/drivers/block/cciss.h
37470 +++ b/drivers/block/cciss.h
37471 @@ -101,7 +101,7 @@ struct ctlr_info
37472 /* information about each logical volume */
37473 drive_info_struct *drv[CISS_MAX_LUN];
37474
37475 - struct access_method access;
37476 + struct access_method *access;
37477
37478 /* queue and queue Info */
37479 struct list_head reqQ;
37480 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37481 }
37482
37483 static struct access_method SA5_access = {
37484 - SA5_submit_command,
37485 - SA5_intr_mask,
37486 - SA5_fifo_full,
37487 - SA5_intr_pending,
37488 - SA5_completed,
37489 + .submit_command = SA5_submit_command,
37490 + .set_intr_mask = SA5_intr_mask,
37491 + .fifo_full = SA5_fifo_full,
37492 + .intr_pending = SA5_intr_pending,
37493 + .command_completed = SA5_completed,
37494 };
37495
37496 static struct access_method SA5B_access = {
37497 - SA5_submit_command,
37498 - SA5B_intr_mask,
37499 - SA5_fifo_full,
37500 - SA5B_intr_pending,
37501 - SA5_completed,
37502 + .submit_command = SA5_submit_command,
37503 + .set_intr_mask = SA5B_intr_mask,
37504 + .fifo_full = SA5_fifo_full,
37505 + .intr_pending = SA5B_intr_pending,
37506 + .command_completed = SA5_completed,
37507 };
37508
37509 static struct access_method SA5_performant_access = {
37510 - SA5_submit_command,
37511 - SA5_performant_intr_mask,
37512 - SA5_fifo_full,
37513 - SA5_performant_intr_pending,
37514 - SA5_performant_completed,
37515 + .submit_command = SA5_submit_command,
37516 + .set_intr_mask = SA5_performant_intr_mask,
37517 + .fifo_full = SA5_fifo_full,
37518 + .intr_pending = SA5_performant_intr_pending,
37519 + .command_completed = SA5_performant_completed,
37520 };
37521
37522 struct board_type {
37523 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37524 index 2b94403..fd6ad1f 100644
37525 --- a/drivers/block/cpqarray.c
37526 +++ b/drivers/block/cpqarray.c
37527 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37528 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37529 goto Enomem4;
37530 }
37531 - hba[i]->access.set_intr_mask(hba[i], 0);
37532 + hba[i]->access->set_intr_mask(hba[i], 0);
37533 if (request_irq(hba[i]->intr, do_ida_intr,
37534 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37535 {
37536 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37537 add_timer(&hba[i]->timer);
37538
37539 /* Enable IRQ now that spinlock and rate limit timer are set up */
37540 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37541 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37542
37543 for(j=0; j<NWD; j++) {
37544 struct gendisk *disk = ida_gendisk[i][j];
37545 @@ -694,7 +694,7 @@ DBGINFO(
37546 for(i=0; i<NR_PRODUCTS; i++) {
37547 if (board_id == products[i].board_id) {
37548 c->product_name = products[i].product_name;
37549 - c->access = *(products[i].access);
37550 + c->access = products[i].access;
37551 break;
37552 }
37553 }
37554 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37555 hba[ctlr]->intr = intr;
37556 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37557 hba[ctlr]->product_name = products[j].product_name;
37558 - hba[ctlr]->access = *(products[j].access);
37559 + hba[ctlr]->access = products[j].access;
37560 hba[ctlr]->ctlr = ctlr;
37561 hba[ctlr]->board_id = board_id;
37562 hba[ctlr]->pci_dev = NULL; /* not PCI */
37563 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37564
37565 while((c = h->reqQ) != NULL) {
37566 /* Can't do anything if we're busy */
37567 - if (h->access.fifo_full(h) == 0)
37568 + if (h->access->fifo_full(h) == 0)
37569 return;
37570
37571 /* Get the first entry from the request Q */
37572 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37573 h->Qdepth--;
37574
37575 /* Tell the controller to do our bidding */
37576 - h->access.submit_command(h, c);
37577 + h->access->submit_command(h, c);
37578
37579 /* Get onto the completion Q */
37580 addQ(&h->cmpQ, c);
37581 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37582 unsigned long flags;
37583 __u32 a,a1;
37584
37585 - istat = h->access.intr_pending(h);
37586 + istat = h->access->intr_pending(h);
37587 /* Is this interrupt for us? */
37588 if (istat == 0)
37589 return IRQ_NONE;
37590 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37591 */
37592 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37593 if (istat & FIFO_NOT_EMPTY) {
37594 - while((a = h->access.command_completed(h))) {
37595 + while((a = h->access->command_completed(h))) {
37596 a1 = a; a &= ~3;
37597 if ((c = h->cmpQ) == NULL)
37598 {
37599 @@ -1448,11 +1448,11 @@ static int sendcmd(
37600 /*
37601 * Disable interrupt
37602 */
37603 - info_p->access.set_intr_mask(info_p, 0);
37604 + info_p->access->set_intr_mask(info_p, 0);
37605 /* Make sure there is room in the command FIFO */
37606 /* Actually it should be completely empty at this time. */
37607 for (i = 200000; i > 0; i--) {
37608 - temp = info_p->access.fifo_full(info_p);
37609 + temp = info_p->access->fifo_full(info_p);
37610 if (temp != 0) {
37611 break;
37612 }
37613 @@ -1465,7 +1465,7 @@ DBG(
37614 /*
37615 * Send the cmd
37616 */
37617 - info_p->access.submit_command(info_p, c);
37618 + info_p->access->submit_command(info_p, c);
37619 complete = pollcomplete(ctlr);
37620
37621 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37622 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37623 * we check the new geometry. Then turn interrupts back on when
37624 * we're done.
37625 */
37626 - host->access.set_intr_mask(host, 0);
37627 + host->access->set_intr_mask(host, 0);
37628 getgeometry(ctlr);
37629 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37630 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37631
37632 for(i=0; i<NWD; i++) {
37633 struct gendisk *disk = ida_gendisk[ctlr][i];
37634 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37635 /* Wait (up to 2 seconds) for a command to complete */
37636
37637 for (i = 200000; i > 0; i--) {
37638 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
37639 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
37640 if (done == 0) {
37641 udelay(10); /* a short fixed delay */
37642 } else
37643 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37644 index be73e9d..7fbf140 100644
37645 --- a/drivers/block/cpqarray.h
37646 +++ b/drivers/block/cpqarray.h
37647 @@ -99,7 +99,7 @@ struct ctlr_info {
37648 drv_info_t drv[NWD];
37649 struct proc_dir_entry *proc;
37650
37651 - struct access_method access;
37652 + struct access_method *access;
37653
37654 cmdlist_t *reqQ;
37655 cmdlist_t *cmpQ;
37656 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37657 index 0e06f0c..c47b81d 100644
37658 --- a/drivers/block/drbd/drbd_int.h
37659 +++ b/drivers/block/drbd/drbd_int.h
37660 @@ -582,7 +582,7 @@ struct drbd_epoch {
37661 struct drbd_tconn *tconn;
37662 struct list_head list;
37663 unsigned int barrier_nr;
37664 - atomic_t epoch_size; /* increased on every request added. */
37665 + atomic_unchecked_t epoch_size; /* increased on every request added. */
37666 atomic_t active; /* increased on every req. added, and dec on every finished. */
37667 unsigned long flags;
37668 };
37669 @@ -1022,7 +1022,7 @@ struct drbd_conf {
37670 unsigned int al_tr_number;
37671 int al_tr_cycle;
37672 wait_queue_head_t seq_wait;
37673 - atomic_t packet_seq;
37674 + atomic_unchecked_t packet_seq;
37675 unsigned int peer_seq;
37676 spinlock_t peer_seq_lock;
37677 unsigned int minor;
37678 @@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37679 char __user *uoptval;
37680 int err;
37681
37682 - uoptval = (char __user __force *)optval;
37683 + uoptval = (char __force_user *)optval;
37684
37685 set_fs(KERNEL_DS);
37686 if (level == SOL_SOCKET)
37687 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37688 index 89c497c..9c736ae 100644
37689 --- a/drivers/block/drbd/drbd_interval.c
37690 +++ b/drivers/block/drbd/drbd_interval.c
37691 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37692 }
37693
37694 static const struct rb_augment_callbacks augment_callbacks = {
37695 - augment_propagate,
37696 - augment_copy,
37697 - augment_rotate,
37698 + .propagate = augment_propagate,
37699 + .copy = augment_copy,
37700 + .rotate = augment_rotate,
37701 };
37702
37703 /**
37704 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37705 index 929468e..7d934eb 100644
37706 --- a/drivers/block/drbd/drbd_main.c
37707 +++ b/drivers/block/drbd/drbd_main.c
37708 @@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37709 p->sector = sector;
37710 p->block_id = block_id;
37711 p->blksize = blksize;
37712 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37713 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37714 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37715 }
37716
37717 @@ -1622,7 +1622,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37718 return -EIO;
37719 p->sector = cpu_to_be64(req->i.sector);
37720 p->block_id = (unsigned long)req;
37721 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37722 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37723 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37724 if (mdev->state.conn >= C_SYNC_SOURCE &&
37725 mdev->state.conn <= C_PAUSED_SYNC_T)
37726 @@ -2577,8 +2577,8 @@ void conn_destroy(struct kref *kref)
37727 {
37728 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37729
37730 - if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37731 - conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37732 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37733 + conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37734 kfree(tconn->current_epoch);
37735
37736 idr_destroy(&tconn->volumes);
37737 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37738 index c706d50..5e1b472 100644
37739 --- a/drivers/block/drbd/drbd_nl.c
37740 +++ b/drivers/block/drbd/drbd_nl.c
37741 @@ -3440,7 +3440,7 @@ out:
37742
37743 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37744 {
37745 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37746 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37747 struct sk_buff *msg;
37748 struct drbd_genlmsghdr *d_out;
37749 unsigned seq;
37750 @@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37751 return;
37752 }
37753
37754 - seq = atomic_inc_return(&drbd_genl_seq);
37755 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37756 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37757 if (!msg)
37758 goto failed;
37759 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37760 index d073305..4998fea 100644
37761 --- a/drivers/block/drbd/drbd_receiver.c
37762 +++ b/drivers/block/drbd/drbd_receiver.c
37763 @@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37764 {
37765 int err;
37766
37767 - atomic_set(&mdev->packet_seq, 0);
37768 + atomic_set_unchecked(&mdev->packet_seq, 0);
37769 mdev->peer_seq = 0;
37770
37771 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37772 @@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37773 do {
37774 next_epoch = NULL;
37775
37776 - epoch_size = atomic_read(&epoch->epoch_size);
37777 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37778
37779 switch (ev & ~EV_CLEANUP) {
37780 case EV_PUT:
37781 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37782 rv = FE_DESTROYED;
37783 } else {
37784 epoch->flags = 0;
37785 - atomic_set(&epoch->epoch_size, 0);
37786 + atomic_set_unchecked(&epoch->epoch_size, 0);
37787 /* atomic_set(&epoch->active, 0); is already zero */
37788 if (rv == FE_STILL_LIVE)
37789 rv = FE_RECYCLED;
37790 @@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37791 conn_wait_active_ee_empty(tconn);
37792 drbd_flush(tconn);
37793
37794 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37795 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37796 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37797 if (epoch)
37798 break;
37799 @@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37800 }
37801
37802 epoch->flags = 0;
37803 - atomic_set(&epoch->epoch_size, 0);
37804 + atomic_set_unchecked(&epoch->epoch_size, 0);
37805 atomic_set(&epoch->active, 0);
37806
37807 spin_lock(&tconn->epoch_lock);
37808 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37809 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37810 list_add(&epoch->list, &tconn->current_epoch->list);
37811 tconn->current_epoch = epoch;
37812 tconn->epochs++;
37813 @@ -2164,7 +2164,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37814
37815 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37816 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37817 - atomic_inc(&tconn->current_epoch->epoch_size);
37818 + atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37819 err2 = drbd_drain_block(mdev, pi->size);
37820 if (!err)
37821 err = err2;
37822 @@ -2198,7 +2198,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37823
37824 spin_lock(&tconn->epoch_lock);
37825 peer_req->epoch = tconn->current_epoch;
37826 - atomic_inc(&peer_req->epoch->epoch_size);
37827 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37828 atomic_inc(&peer_req->epoch->active);
37829 spin_unlock(&tconn->epoch_lock);
37830
37831 @@ -4345,7 +4345,7 @@ struct data_cmd {
37832 int expect_payload;
37833 size_t pkt_size;
37834 int (*fn)(struct drbd_tconn *, struct packet_info *);
37835 -};
37836 +} __do_const;
37837
37838 static struct data_cmd drbd_cmd_handler[] = {
37839 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37840 @@ -4465,7 +4465,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37841 if (!list_empty(&tconn->current_epoch->list))
37842 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37843 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37844 - atomic_set(&tconn->current_epoch->epoch_size, 0);
37845 + atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37846 tconn->send.seen_any_write_yet = false;
37847
37848 conn_info(tconn, "Connection closed\n");
37849 @@ -5221,7 +5221,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37850 struct asender_cmd {
37851 size_t pkt_size;
37852 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37853 -};
37854 +} __do_const;
37855
37856 static struct asender_cmd asender_tbl[] = {
37857 [P_PING] = { 0, got_Ping },
37858 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37859 index 66e8c3b..9b68dd9 100644
37860 --- a/drivers/block/loop.c
37861 +++ b/drivers/block/loop.c
37862 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37863
37864 file_start_write(file);
37865 set_fs(get_ds());
37866 - bw = file->f_op->write(file, buf, len, &pos);
37867 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37868 set_fs(old_fs);
37869 file_end_write(file);
37870 if (likely(bw == len))
37871 diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37872 index 091b9ea..f5428f8 100644
37873 --- a/drivers/block/null_blk.c
37874 +++ b/drivers/block/null_blk.c
37875 @@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37876 return 0;
37877 }
37878
37879 -static struct blk_mq_ops null_mq_ops = {
37880 - .queue_rq = null_queue_rq,
37881 - .map_queue = blk_mq_map_queue,
37882 +static struct blk_mq_ops null_mq_single_ops = {
37883 + .queue_rq = null_queue_rq,
37884 + .map_queue = blk_mq_map_queue,
37885 .init_hctx = null_init_hctx,
37886 .complete = null_softirq_done_fn,
37887 + .alloc_hctx = blk_mq_alloc_single_hw_queue,
37888 + .free_hctx = blk_mq_free_single_hw_queue,
37889 +};
37890 +
37891 +static struct blk_mq_ops null_mq_per_node_ops = {
37892 + .queue_rq = null_queue_rq,
37893 + .map_queue = blk_mq_map_queue,
37894 + .init_hctx = null_init_hctx,
37895 + .alloc_hctx = null_alloc_hctx,
37896 + .free_hctx = null_free_hctx,
37897 };
37898
37899 static struct blk_mq_reg null_mq_reg = {
37900 - .ops = &null_mq_ops,
37901 + .ops = &null_mq_single_ops,
37902 .queue_depth = 64,
37903 .cmd_size = sizeof(struct nullb_cmd),
37904 .flags = BLK_MQ_F_SHOULD_MERGE,
37905 @@ -521,13 +531,8 @@ static int null_add_dev(void)
37906 null_mq_reg.queue_depth = hw_queue_depth;
37907 null_mq_reg.nr_hw_queues = submit_queues;
37908
37909 - if (use_per_node_hctx) {
37910 - null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
37911 - null_mq_reg.ops->free_hctx = null_free_hctx;
37912 - } else {
37913 - null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
37914 - null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
37915 - }
37916 + if (use_per_node_hctx)
37917 + null_mq_reg.ops = &null_mq_per_node_ops;
37918
37919 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
37920 } else if (queue_mode == NULL_Q_BIO) {
37921 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37922 index a2af73d..c0b8f61 100644
37923 --- a/drivers/block/pktcdvd.c
37924 +++ b/drivers/block/pktcdvd.c
37925 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37926
37927 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37928 {
37929 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37930 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37931 }
37932
37933 /*
37934 @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37935 return -EROFS;
37936 }
37937 pd->settings.fp = ti.fp;
37938 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37939 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37940
37941 if (ti.nwa_v) {
37942 pd->nwa = be32_to_cpu(ti.next_writable);
37943 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37944 index e5565fb..71be10b4 100644
37945 --- a/drivers/block/smart1,2.h
37946 +++ b/drivers/block/smart1,2.h
37947 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37948 }
37949
37950 static struct access_method smart4_access = {
37951 - smart4_submit_command,
37952 - smart4_intr_mask,
37953 - smart4_fifo_full,
37954 - smart4_intr_pending,
37955 - smart4_completed,
37956 + .submit_command = smart4_submit_command,
37957 + .set_intr_mask = smart4_intr_mask,
37958 + .fifo_full = smart4_fifo_full,
37959 + .intr_pending = smart4_intr_pending,
37960 + .command_completed = smart4_completed,
37961 };
37962
37963 /*
37964 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
37965 }
37966
37967 static struct access_method smart2_access = {
37968 - smart2_submit_command,
37969 - smart2_intr_mask,
37970 - smart2_fifo_full,
37971 - smart2_intr_pending,
37972 - smart2_completed,
37973 + .submit_command = smart2_submit_command,
37974 + .set_intr_mask = smart2_intr_mask,
37975 + .fifo_full = smart2_fifo_full,
37976 + .intr_pending = smart2_intr_pending,
37977 + .command_completed = smart2_completed,
37978 };
37979
37980 /*
37981 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
37982 }
37983
37984 static struct access_method smart2e_access = {
37985 - smart2e_submit_command,
37986 - smart2e_intr_mask,
37987 - smart2e_fifo_full,
37988 - smart2e_intr_pending,
37989 - smart2e_completed,
37990 + .submit_command = smart2e_submit_command,
37991 + .set_intr_mask = smart2e_intr_mask,
37992 + .fifo_full = smart2e_fifo_full,
37993 + .intr_pending = smart2e_intr_pending,
37994 + .command_completed = smart2e_completed,
37995 };
37996
37997 /*
37998 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
37999 }
38000
38001 static struct access_method smart1_access = {
38002 - smart1_submit_command,
38003 - smart1_intr_mask,
38004 - smart1_fifo_full,
38005 - smart1_intr_pending,
38006 - smart1_completed,
38007 + .submit_command = smart1_submit_command,
38008 + .set_intr_mask = smart1_intr_mask,
38009 + .fifo_full = smart1_fifo_full,
38010 + .intr_pending = smart1_intr_pending,
38011 + .command_completed = smart1_completed,
38012 };
38013 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38014 index f038dba..bb74c08 100644
38015 --- a/drivers/bluetooth/btwilink.c
38016 +++ b/drivers/bluetooth/btwilink.c
38017 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38018
38019 static int bt_ti_probe(struct platform_device *pdev)
38020 {
38021 - static struct ti_st *hst;
38022 + struct ti_st *hst;
38023 struct hci_dev *hdev;
38024 int err;
38025
38026 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38027 index 8a3aff7..d7538c2 100644
38028 --- a/drivers/cdrom/cdrom.c
38029 +++ b/drivers/cdrom/cdrom.c
38030 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38031 ENSURE(reset, CDC_RESET);
38032 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38033 cdi->mc_flags = 0;
38034 - cdo->n_minors = 0;
38035 cdi->options = CDO_USE_FFLAGS;
38036
38037 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38038 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38039 else
38040 cdi->cdda_method = CDDA_OLD;
38041
38042 - if (!cdo->generic_packet)
38043 - cdo->generic_packet = cdrom_dummy_generic_packet;
38044 + if (!cdo->generic_packet) {
38045 + pax_open_kernel();
38046 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38047 + pax_close_kernel();
38048 + }
38049
38050 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38051 mutex_lock(&cdrom_mutex);
38052 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38053 if (cdi->exit)
38054 cdi->exit(cdi);
38055
38056 - cdi->ops->n_minors--;
38057 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38058 }
38059
38060 @@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38061 */
38062 nr = nframes;
38063 do {
38064 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38065 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38066 if (cgc.buffer)
38067 break;
38068
38069 @@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38070 struct cdrom_device_info *cdi;
38071 int ret;
38072
38073 - ret = scnprintf(info + *pos, max_size - *pos, header);
38074 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38075 if (!ret)
38076 return 1;
38077
38078 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38079 index 51e75ad..39c4c76 100644
38080 --- a/drivers/cdrom/gdrom.c
38081 +++ b/drivers/cdrom/gdrom.c
38082 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38083 .audio_ioctl = gdrom_audio_ioctl,
38084 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38085 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38086 - .n_minors = 1,
38087 };
38088
38089 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38090 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38091 index 1386749..5430258 100644
38092 --- a/drivers/char/Kconfig
38093 +++ b/drivers/char/Kconfig
38094 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38095
38096 config DEVKMEM
38097 bool "/dev/kmem virtual device support"
38098 - default y
38099 + default n
38100 + depends on !GRKERNSEC_KMEM
38101 help
38102 Say Y here if you want to support the /dev/kmem device. The
38103 /dev/kmem device is rarely used, but can be used for certain
38104 @@ -577,6 +578,7 @@ config DEVPORT
38105 bool
38106 depends on !M68K
38107 depends on ISA || PCI
38108 + depends on !GRKERNSEC_KMEM
38109 default y
38110
38111 source "drivers/s390/char/Kconfig"
38112 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38113 index a48e05b..6bac831 100644
38114 --- a/drivers/char/agp/compat_ioctl.c
38115 +++ b/drivers/char/agp/compat_ioctl.c
38116 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38117 return -ENOMEM;
38118 }
38119
38120 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38121 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38122 sizeof(*usegment) * ureserve.seg_count)) {
38123 kfree(usegment);
38124 kfree(ksegment);
38125 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38126 index 1b19239..b87b143 100644
38127 --- a/drivers/char/agp/frontend.c
38128 +++ b/drivers/char/agp/frontend.c
38129 @@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38130 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38131 return -EFAULT;
38132
38133 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38134 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38135 return -EFAULT;
38136
38137 client = agp_find_client_by_pid(reserve.pid);
38138 @@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38139 if (segment == NULL)
38140 return -ENOMEM;
38141
38142 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38143 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38144 sizeof(struct agp_segment) * reserve.seg_count)) {
38145 kfree(segment);
38146 return -EFAULT;
38147 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38148 index 4f94375..413694e 100644
38149 --- a/drivers/char/genrtc.c
38150 +++ b/drivers/char/genrtc.c
38151 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38152 switch (cmd) {
38153
38154 case RTC_PLL_GET:
38155 + memset(&pll, 0, sizeof(pll));
38156 if (get_rtc_pll(&pll))
38157 return -EINVAL;
38158 else
38159 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38160 index d5d4cd8..22d561d 100644
38161 --- a/drivers/char/hpet.c
38162 +++ b/drivers/char/hpet.c
38163 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38164 }
38165
38166 static int
38167 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38168 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38169 struct hpet_info *info)
38170 {
38171 struct hpet_timer __iomem *timer;
38172 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38173 index 86fe45c..c0ea948 100644
38174 --- a/drivers/char/hw_random/intel-rng.c
38175 +++ b/drivers/char/hw_random/intel-rng.c
38176 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38177
38178 if (no_fwh_detect)
38179 return -ENODEV;
38180 - printk(warning);
38181 + printk("%s", warning);
38182 return -EBUSY;
38183 }
38184
38185 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38186 index ec4e10f..f2a763b 100644
38187 --- a/drivers/char/ipmi/ipmi_msghandler.c
38188 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38189 @@ -420,7 +420,7 @@ struct ipmi_smi {
38190 struct proc_dir_entry *proc_dir;
38191 char proc_dir_name[10];
38192
38193 - atomic_t stats[IPMI_NUM_STATS];
38194 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38195
38196 /*
38197 * run_to_completion duplicate of smb_info, smi_info
38198 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38199
38200
38201 #define ipmi_inc_stat(intf, stat) \
38202 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38203 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38204 #define ipmi_get_stat(intf, stat) \
38205 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38206 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38207
38208 static int is_lan_addr(struct ipmi_addr *addr)
38209 {
38210 @@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38211 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38212 init_waitqueue_head(&intf->waitq);
38213 for (i = 0; i < IPMI_NUM_STATS; i++)
38214 - atomic_set(&intf->stats[i], 0);
38215 + atomic_set_unchecked(&intf->stats[i], 0);
38216
38217 intf->proc_dir = NULL;
38218
38219 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38220 index 03f4189..e79f5e0 100644
38221 --- a/drivers/char/ipmi/ipmi_si_intf.c
38222 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38223 @@ -280,7 +280,7 @@ struct smi_info {
38224 unsigned char slave_addr;
38225
38226 /* Counters and things for the proc filesystem. */
38227 - atomic_t stats[SI_NUM_STATS];
38228 + atomic_unchecked_t stats[SI_NUM_STATS];
38229
38230 struct task_struct *thread;
38231
38232 @@ -289,9 +289,9 @@ struct smi_info {
38233 };
38234
38235 #define smi_inc_stat(smi, stat) \
38236 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38237 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38238 #define smi_get_stat(smi, stat) \
38239 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38240 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38241
38242 #define SI_MAX_PARMS 4
38243
38244 @@ -3339,7 +3339,7 @@ static int try_smi_init(struct smi_info *new_smi)
38245 atomic_set(&new_smi->req_events, 0);
38246 new_smi->run_to_completion = 0;
38247 for (i = 0; i < SI_NUM_STATS; i++)
38248 - atomic_set(&new_smi->stats[i], 0);
38249 + atomic_set_unchecked(&new_smi->stats[i], 0);
38250
38251 new_smi->interrupt_disabled = 1;
38252 atomic_set(&new_smi->stop_operation, 0);
38253 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38254 index 92c5937..1be4e4d 100644
38255 --- a/drivers/char/mem.c
38256 +++ b/drivers/char/mem.c
38257 @@ -18,6 +18,7 @@
38258 #include <linux/raw.h>
38259 #include <linux/tty.h>
38260 #include <linux/capability.h>
38261 +#include <linux/security.h>
38262 #include <linux/ptrace.h>
38263 #include <linux/device.h>
38264 #include <linux/highmem.h>
38265 @@ -36,6 +37,10 @@
38266
38267 #define DEVPORT_MINOR 4
38268
38269 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38270 +extern const struct file_operations grsec_fops;
38271 +#endif
38272 +
38273 static inline unsigned long size_inside_page(unsigned long start,
38274 unsigned long size)
38275 {
38276 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38277
38278 while (cursor < to) {
38279 if (!devmem_is_allowed(pfn)) {
38280 +#ifdef CONFIG_GRKERNSEC_KMEM
38281 + gr_handle_mem_readwrite(from, to);
38282 +#else
38283 printk(KERN_INFO
38284 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38285 current->comm, from, to);
38286 +#endif
38287 return 0;
38288 }
38289 cursor += PAGE_SIZE;
38290 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38291 }
38292 return 1;
38293 }
38294 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38295 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38296 +{
38297 + return 0;
38298 +}
38299 #else
38300 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38301 {
38302 @@ -119,6 +133,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38303
38304 while (count > 0) {
38305 unsigned long remaining;
38306 + char *temp;
38307
38308 sz = size_inside_page(p, count);
38309
38310 @@ -134,7 +149,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38311 if (!ptr)
38312 return -EFAULT;
38313
38314 - remaining = copy_to_user(buf, ptr, sz);
38315 +#ifdef CONFIG_PAX_USERCOPY
38316 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38317 + if (!temp) {
38318 + unxlate_dev_mem_ptr(p, ptr);
38319 + return -ENOMEM;
38320 + }
38321 + memcpy(temp, ptr, sz);
38322 +#else
38323 + temp = ptr;
38324 +#endif
38325 +
38326 + remaining = copy_to_user(buf, temp, sz);
38327 +
38328 +#ifdef CONFIG_PAX_USERCOPY
38329 + kfree(temp);
38330 +#endif
38331 +
38332 unxlate_dev_mem_ptr(p, ptr);
38333 if (remaining)
38334 return -EFAULT;
38335 @@ -363,9 +394,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38336 size_t count, loff_t *ppos)
38337 {
38338 unsigned long p = *ppos;
38339 - ssize_t low_count, read, sz;
38340 + ssize_t low_count, read, sz, err = 0;
38341 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38342 - int err = 0;
38343
38344 read = 0;
38345 if (p < (unsigned long) high_memory) {
38346 @@ -387,6 +417,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38347 }
38348 #endif
38349 while (low_count > 0) {
38350 + char *temp;
38351 +
38352 sz = size_inside_page(p, low_count);
38353
38354 /*
38355 @@ -396,7 +428,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38356 */
38357 kbuf = xlate_dev_kmem_ptr((char *)p);
38358
38359 - if (copy_to_user(buf, kbuf, sz))
38360 +#ifdef CONFIG_PAX_USERCOPY
38361 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38362 + if (!temp)
38363 + return -ENOMEM;
38364 + memcpy(temp, kbuf, sz);
38365 +#else
38366 + temp = kbuf;
38367 +#endif
38368 +
38369 + err = copy_to_user(buf, temp, sz);
38370 +
38371 +#ifdef CONFIG_PAX_USERCOPY
38372 + kfree(temp);
38373 +#endif
38374 +
38375 + if (err)
38376 return -EFAULT;
38377 buf += sz;
38378 p += sz;
38379 @@ -821,6 +868,9 @@ static const struct memdev {
38380 #ifdef CONFIG_PRINTK
38381 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38382 #endif
38383 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38384 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38385 +#endif
38386 };
38387
38388 static int memory_open(struct inode *inode, struct file *filp)
38389 @@ -892,7 +942,7 @@ static int __init chr_dev_init(void)
38390 continue;
38391
38392 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38393 - NULL, devlist[minor].name);
38394 + NULL, "%s", devlist[minor].name);
38395 }
38396
38397 return tty_init();
38398 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38399 index 9df78e2..01ba9ae 100644
38400 --- a/drivers/char/nvram.c
38401 +++ b/drivers/char/nvram.c
38402 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38403
38404 spin_unlock_irq(&rtc_lock);
38405
38406 - if (copy_to_user(buf, contents, tmp - contents))
38407 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38408 return -EFAULT;
38409
38410 *ppos = i;
38411 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38412 index 8320abd..ec48108 100644
38413 --- a/drivers/char/pcmcia/synclink_cs.c
38414 +++ b/drivers/char/pcmcia/synclink_cs.c
38415 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38416
38417 if (debug_level >= DEBUG_LEVEL_INFO)
38418 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38419 - __FILE__, __LINE__, info->device_name, port->count);
38420 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38421
38422 - WARN_ON(!port->count);
38423 + WARN_ON(!atomic_read(&port->count));
38424
38425 if (tty_port_close_start(port, tty, filp) == 0)
38426 goto cleanup;
38427 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38428 cleanup:
38429 if (debug_level >= DEBUG_LEVEL_INFO)
38430 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38431 - tty->driver->name, port->count);
38432 + tty->driver->name, atomic_read(&port->count));
38433 }
38434
38435 /* Wait until the transmitter is empty.
38436 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38437
38438 if (debug_level >= DEBUG_LEVEL_INFO)
38439 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38440 - __FILE__, __LINE__, tty->driver->name, port->count);
38441 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38442
38443 /* If port is closing, signal caller to try again */
38444 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38445 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38446 goto cleanup;
38447 }
38448 spin_lock(&port->lock);
38449 - port->count++;
38450 + atomic_inc(&port->count);
38451 spin_unlock(&port->lock);
38452 spin_unlock_irqrestore(&info->netlock, flags);
38453
38454 - if (port->count == 1) {
38455 + if (atomic_read(&port->count) == 1) {
38456 /* 1st open on this device, init hardware */
38457 retval = startup(info, tty);
38458 if (retval < 0)
38459 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38460 unsigned short new_crctype;
38461
38462 /* return error if TTY interface open */
38463 - if (info->port.count)
38464 + if (atomic_read(&info->port.count))
38465 return -EBUSY;
38466
38467 switch (encoding)
38468 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38469
38470 /* arbitrate between network and tty opens */
38471 spin_lock_irqsave(&info->netlock, flags);
38472 - if (info->port.count != 0 || info->netcount != 0) {
38473 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38474 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38475 spin_unlock_irqrestore(&info->netlock, flags);
38476 return -EBUSY;
38477 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38478 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38479
38480 /* return error if TTY interface open */
38481 - if (info->port.count)
38482 + if (atomic_read(&info->port.count))
38483 return -EBUSY;
38484
38485 if (cmd != SIOCWANDEV)
38486 diff --git a/drivers/char/random.c b/drivers/char/random.c
38487 index 429b75b..a7f4145 100644
38488 --- a/drivers/char/random.c
38489 +++ b/drivers/char/random.c
38490 @@ -270,10 +270,17 @@
38491 /*
38492 * Configuration information
38493 */
38494 +#ifdef CONFIG_GRKERNSEC_RANDNET
38495 +#define INPUT_POOL_SHIFT 14
38496 +#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38497 +#define OUTPUT_POOL_SHIFT 12
38498 +#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38499 +#else
38500 #define INPUT_POOL_SHIFT 12
38501 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38502 #define OUTPUT_POOL_SHIFT 10
38503 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38504 +#endif
38505 #define SEC_XFER_SIZE 512
38506 #define EXTRACT_SIZE 10
38507
38508 @@ -284,9 +291,6 @@
38509 /*
38510 * To allow fractional bits to be tracked, the entropy_count field is
38511 * denominated in units of 1/8th bits.
38512 - *
38513 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38514 - * credit_entropy_bits() needs to be 64 bits wide.
38515 */
38516 #define ENTROPY_SHIFT 3
38517 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38518 @@ -361,12 +365,19 @@ static struct poolinfo {
38519 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38520 int tap1, tap2, tap3, tap4, tap5;
38521 } poolinfo_table[] = {
38522 +#ifdef CONFIG_GRKERNSEC_RANDNET
38523 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38524 + { S(512), 411, 308, 208, 104, 1 },
38525 + /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38526 + { S(128), 104, 76, 51, 25, 1 },
38527 +#else
38528 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38529 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38530 { S(128), 104, 76, 51, 25, 1 },
38531 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38532 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38533 { S(32), 26, 19, 14, 7, 1 },
38534 +#endif
38535 #if 0
38536 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38537 { S(2048), 1638, 1231, 819, 411, 1 },
38538 @@ -433,9 +444,9 @@ struct entropy_store {
38539 };
38540
38541 static void push_to_pool(struct work_struct *work);
38542 -static __u32 input_pool_data[INPUT_POOL_WORDS];
38543 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38544 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38545 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38546 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38547 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38548
38549 static struct entropy_store input_pool = {
38550 .poolinfo = &poolinfo_table[0],
38551 @@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38552 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38553 }
38554
38555 - ACCESS_ONCE(r->input_rotate) = input_rotate;
38556 - ACCESS_ONCE(r->add_ptr) = i;
38557 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38558 + ACCESS_ONCE_RW(r->add_ptr) = i;
38559 smp_wmb();
38560
38561 if (out)
38562 @@ -632,7 +643,7 @@ retry:
38563 /* The +2 corresponds to the /4 in the denominator */
38564
38565 do {
38566 - unsigned int anfrac = min(pnfrac, pool_size/2);
38567 + u64 anfrac = min(pnfrac, pool_size/2);
38568 unsigned int add =
38569 ((pool_size - entropy_count)*anfrac*3) >> s;
38570
38571 @@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38572
38573 extract_buf(r, tmp);
38574 i = min_t(int, nbytes, EXTRACT_SIZE);
38575 - if (copy_to_user(buf, tmp, i)) {
38576 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38577 ret = -EFAULT;
38578 break;
38579 }
38580 @@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
38581 #include <linux/sysctl.h>
38582
38583 static int min_read_thresh = 8, min_write_thresh;
38584 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
38585 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
38586 static int max_write_thresh = INPUT_POOL_WORDS * 32;
38587 static char sysctl_bootid[16];
38588
38589 @@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
38590 static int proc_do_uuid(struct ctl_table *table, int write,
38591 void __user *buffer, size_t *lenp, loff_t *ppos)
38592 {
38593 - struct ctl_table fake_table;
38594 + ctl_table_no_const fake_table;
38595 unsigned char buf[64], tmp_uuid[16], *uuid;
38596
38597 uuid = table->data;
38598 @@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38599 static int proc_do_entropy(ctl_table *table, int write,
38600 void __user *buffer, size_t *lenp, loff_t *ppos)
38601 {
38602 - ctl_table fake_table;
38603 + ctl_table_no_const fake_table;
38604 int entropy_count;
38605
38606 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38607 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38608 index 7cc1fe22..b602d6b 100644
38609 --- a/drivers/char/sonypi.c
38610 +++ b/drivers/char/sonypi.c
38611 @@ -54,6 +54,7 @@
38612
38613 #include <asm/uaccess.h>
38614 #include <asm/io.h>
38615 +#include <asm/local.h>
38616
38617 #include <linux/sonypi.h>
38618
38619 @@ -490,7 +491,7 @@ static struct sonypi_device {
38620 spinlock_t fifo_lock;
38621 wait_queue_head_t fifo_proc_list;
38622 struct fasync_struct *fifo_async;
38623 - int open_count;
38624 + local_t open_count;
38625 int model;
38626 struct input_dev *input_jog_dev;
38627 struct input_dev *input_key_dev;
38628 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38629 static int sonypi_misc_release(struct inode *inode, struct file *file)
38630 {
38631 mutex_lock(&sonypi_device.lock);
38632 - sonypi_device.open_count--;
38633 + local_dec(&sonypi_device.open_count);
38634 mutex_unlock(&sonypi_device.lock);
38635 return 0;
38636 }
38637 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38638 {
38639 mutex_lock(&sonypi_device.lock);
38640 /* Flush input queue on first open */
38641 - if (!sonypi_device.open_count)
38642 + if (!local_read(&sonypi_device.open_count))
38643 kfifo_reset(&sonypi_device.fifo);
38644 - sonypi_device.open_count++;
38645 + local_inc(&sonypi_device.open_count);
38646 mutex_unlock(&sonypi_device.lock);
38647
38648 return 0;
38649 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38650 index b9a57fa..5bb9e38 100644
38651 --- a/drivers/char/tpm/tpm_acpi.c
38652 +++ b/drivers/char/tpm/tpm_acpi.c
38653 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38654 virt = acpi_os_map_memory(start, len);
38655 if (!virt) {
38656 kfree(log->bios_event_log);
38657 + log->bios_event_log = NULL;
38658 printk("%s: ERROR - Unable to map memory\n", __func__);
38659 return -EIO;
38660 }
38661
38662 - memcpy_fromio(log->bios_event_log, virt, len);
38663 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38664
38665 acpi_os_unmap_memory(virt, len);
38666 return 0;
38667 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38668 index 59f7cb2..bac8b6d 100644
38669 --- a/drivers/char/tpm/tpm_eventlog.c
38670 +++ b/drivers/char/tpm/tpm_eventlog.c
38671 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38672 event = addr;
38673
38674 if ((event->event_type == 0 && event->event_size == 0) ||
38675 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38676 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38677 return NULL;
38678
38679 return addr;
38680 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38681 return NULL;
38682
38683 if ((event->event_type == 0 && event->event_size == 0) ||
38684 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38685 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38686 return NULL;
38687
38688 (*pos)++;
38689 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38690 int i;
38691
38692 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38693 - seq_putc(m, data[i]);
38694 + if (!seq_putc(m, data[i]))
38695 + return -EFAULT;
38696
38697 return 0;
38698 }
38699 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38700 index 6928d09..ff6abe8 100644
38701 --- a/drivers/char/virtio_console.c
38702 +++ b/drivers/char/virtio_console.c
38703 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38704 if (to_user) {
38705 ssize_t ret;
38706
38707 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38708 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38709 if (ret)
38710 return -EFAULT;
38711 } else {
38712 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38713 if (!port_has_data(port) && !port->host_connected)
38714 return 0;
38715
38716 - return fill_readbuf(port, ubuf, count, true);
38717 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38718 }
38719
38720 static int wait_port_writable(struct port *port, bool nonblock)
38721 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38722 index 57a078e..c17cde8 100644
38723 --- a/drivers/clk/clk-composite.c
38724 +++ b/drivers/clk/clk-composite.c
38725 @@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38726 struct clk *clk;
38727 struct clk_init_data init;
38728 struct clk_composite *composite;
38729 - struct clk_ops *clk_composite_ops;
38730 + clk_ops_no_const *clk_composite_ops;
38731
38732 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38733 if (!composite) {
38734 diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38735 index 5983a26..65d5f46 100644
38736 --- a/drivers/clk/socfpga/clk.c
38737 +++ b/drivers/clk/socfpga/clk.c
38738 @@ -22,6 +22,7 @@
38739 #include <linux/clk-provider.h>
38740 #include <linux/io.h>
38741 #include <linux/of.h>
38742 +#include <asm/pgtable.h>
38743
38744 /* Clock Manager offsets */
38745 #define CLKMGR_CTRL 0x0
38746 @@ -150,8 +151,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38747 streq(clk_name, "periph_pll") ||
38748 streq(clk_name, "sdram_pll")) {
38749 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38750 - clk_pll_ops.enable = clk_gate_ops.enable;
38751 - clk_pll_ops.disable = clk_gate_ops.disable;
38752 + pax_open_kernel();
38753 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38754 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38755 + pax_close_kernel();
38756 }
38757
38758 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38759 @@ -242,7 +245,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38760 return parent_rate / div;
38761 }
38762
38763 -static struct clk_ops gateclk_ops = {
38764 +static clk_ops_no_const gateclk_ops __read_only = {
38765 .recalc_rate = socfpga_clk_recalc_rate,
38766 .get_parent = socfpga_clk_get_parent,
38767 .set_parent = socfpga_clk_set_parent,
38768 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38769 index 18448a7..d5fad43 100644
38770 --- a/drivers/cpufreq/acpi-cpufreq.c
38771 +++ b/drivers/cpufreq/acpi-cpufreq.c
38772 @@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38773 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38774 per_cpu(acfreq_data, cpu) = data;
38775
38776 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38777 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38778 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38779 + pax_open_kernel();
38780 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38781 + pax_close_kernel();
38782 + }
38783
38784 result = acpi_processor_register_performance(data->acpi_data, cpu);
38785 if (result)
38786 @@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38787 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38788 break;
38789 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38790 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38791 + pax_open_kernel();
38792 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38793 + pax_close_kernel();
38794 break;
38795 default:
38796 break;
38797 @@ -905,8 +910,10 @@ static void __init acpi_cpufreq_boost_init(void)
38798 if (!msrs)
38799 return;
38800
38801 - acpi_cpufreq_driver.boost_supported = true;
38802 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
38803 + pax_open_kernel();
38804 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
38805 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
38806 + pax_close_kernel();
38807 get_online_cpus();
38808
38809 /* Force all MSRs to the same value */
38810 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38811 index 199b52b..e3503bb 100644
38812 --- a/drivers/cpufreq/cpufreq.c
38813 +++ b/drivers/cpufreq/cpufreq.c
38814 @@ -1970,7 +1970,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38815 #endif
38816
38817 mutex_lock(&cpufreq_governor_mutex);
38818 - list_del(&governor->governor_list);
38819 + pax_list_del(&governor->governor_list);
38820 mutex_unlock(&cpufreq_governor_mutex);
38821 return;
38822 }
38823 @@ -2200,7 +2200,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38824 return NOTIFY_OK;
38825 }
38826
38827 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
38828 +static struct notifier_block cpufreq_cpu_notifier = {
38829 .notifier_call = cpufreq_cpu_callback,
38830 };
38831
38832 @@ -2240,13 +2240,17 @@ int cpufreq_boost_trigger_state(int state)
38833 return 0;
38834
38835 write_lock_irqsave(&cpufreq_driver_lock, flags);
38836 - cpufreq_driver->boost_enabled = state;
38837 + pax_open_kernel();
38838 + *(bool *)&cpufreq_driver->boost_enabled = state;
38839 + pax_close_kernel();
38840 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
38841
38842 ret = cpufreq_driver->set_boost(state);
38843 if (ret) {
38844 write_lock_irqsave(&cpufreq_driver_lock, flags);
38845 - cpufreq_driver->boost_enabled = !state;
38846 + pax_open_kernel();
38847 + *(bool *)&cpufreq_driver->boost_enabled = !state;
38848 + pax_close_kernel();
38849 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
38850
38851 pr_err("%s: Cannot %s BOOST\n", __func__,
38852 @@ -2300,8 +2304,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38853
38854 pr_debug("trying to register driver %s\n", driver_data->name);
38855
38856 - if (driver_data->setpolicy)
38857 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
38858 + if (driver_data->setpolicy) {
38859 + pax_open_kernel();
38860 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38861 + pax_close_kernel();
38862 + }
38863
38864 write_lock_irqsave(&cpufreq_driver_lock, flags);
38865 if (cpufreq_driver) {
38866 @@ -2316,8 +2323,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38867 * Check if driver provides function to enable boost -
38868 * if not, use cpufreq_boost_set_sw as default
38869 */
38870 - if (!cpufreq_driver->set_boost)
38871 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
38872 + if (!cpufreq_driver->set_boost) {
38873 + pax_open_kernel();
38874 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
38875 + pax_close_kernel();
38876 + }
38877
38878 ret = cpufreq_sysfs_create_file(&boost.attr);
38879 if (ret) {
38880 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38881 index ba43991..23858ffb 100644
38882 --- a/drivers/cpufreq/cpufreq_governor.c
38883 +++ b/drivers/cpufreq/cpufreq_governor.c
38884 @@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38885 struct dbs_data *dbs_data;
38886 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38887 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38888 - struct od_ops *od_ops = NULL;
38889 + const struct od_ops *od_ops = NULL;
38890 struct od_dbs_tuners *od_tuners = NULL;
38891 struct cs_dbs_tuners *cs_tuners = NULL;
38892 struct cpu_dbs_common_info *cpu_cdbs;
38893 @@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38894
38895 if ((cdata->governor == GOV_CONSERVATIVE) &&
38896 (!policy->governor->initialized)) {
38897 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38898 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38899
38900 cpufreq_register_notifier(cs_ops->notifier_block,
38901 CPUFREQ_TRANSITION_NOTIFIER);
38902 @@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38903
38904 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38905 (policy->governor->initialized == 1)) {
38906 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38907 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38908
38909 cpufreq_unregister_notifier(cs_ops->notifier_block,
38910 CPUFREQ_TRANSITION_NOTIFIER);
38911 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38912 index bfb9ae1..e1d3a7e 100644
38913 --- a/drivers/cpufreq/cpufreq_governor.h
38914 +++ b/drivers/cpufreq/cpufreq_governor.h
38915 @@ -205,7 +205,7 @@ struct common_dbs_data {
38916 void (*exit)(struct dbs_data *dbs_data);
38917
38918 /* Governor specific ops, see below */
38919 - void *gov_ops;
38920 + const void *gov_ops;
38921 };
38922
38923 /* Governor Per policy data */
38924 @@ -225,7 +225,7 @@ struct od_ops {
38925 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38926 unsigned int freq_next, unsigned int relation);
38927 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38928 -};
38929 +} __no_const;
38930
38931 struct cs_ops {
38932 struct notifier_block *notifier_block;
38933 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38934 index 18d4091..434be15 100644
38935 --- a/drivers/cpufreq/cpufreq_ondemand.c
38936 +++ b/drivers/cpufreq/cpufreq_ondemand.c
38937 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
38938
38939 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38940
38941 -static struct od_ops od_ops = {
38942 +static struct od_ops od_ops __read_only = {
38943 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38944 .powersave_bias_target = generic_powersave_bias_target,
38945 .freq_increase = dbs_freq_increase,
38946 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38947 (struct cpufreq_policy *, unsigned int, unsigned int),
38948 unsigned int powersave_bias)
38949 {
38950 - od_ops.powersave_bias_target = f;
38951 + pax_open_kernel();
38952 + *(void **)&od_ops.powersave_bias_target = f;
38953 + pax_close_kernel();
38954 od_set_powersave_bias(powersave_bias);
38955 }
38956 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38957
38958 void od_unregister_powersave_bias_handler(void)
38959 {
38960 - od_ops.powersave_bias_target = generic_powersave_bias_target;
38961 + pax_open_kernel();
38962 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38963 + pax_close_kernel();
38964 od_set_powersave_bias(0);
38965 }
38966 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38967 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
38968 index 2cd36b9..8f07fae 100644
38969 --- a/drivers/cpufreq/intel_pstate.c
38970 +++ b/drivers/cpufreq/intel_pstate.c
38971 @@ -124,10 +124,10 @@ struct pstate_funcs {
38972 struct cpu_defaults {
38973 struct pstate_adjust_policy pid_policy;
38974 struct pstate_funcs funcs;
38975 -};
38976 +} __do_const;
38977
38978 static struct pstate_adjust_policy pid_params;
38979 -static struct pstate_funcs pstate_funcs;
38980 +static struct pstate_funcs *pstate_funcs;
38981
38982 struct perf_limits {
38983 int no_turbo;
38984 @@ -518,7 +518,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
38985
38986 cpu->pstate.current_pstate = pstate;
38987
38988 - pstate_funcs.set(cpu, pstate);
38989 + pstate_funcs->set(cpu, pstate);
38990 }
38991
38992 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
38993 @@ -540,12 +540,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
38994 {
38995 sprintf(cpu->name, "Intel 2nd generation core");
38996
38997 - cpu->pstate.min_pstate = pstate_funcs.get_min();
38998 - cpu->pstate.max_pstate = pstate_funcs.get_max();
38999 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39000 + cpu->pstate.min_pstate = pstate_funcs->get_min();
39001 + cpu->pstate.max_pstate = pstate_funcs->get_max();
39002 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39003
39004 - if (pstate_funcs.get_vid)
39005 - pstate_funcs.get_vid(cpu);
39006 + if (pstate_funcs->get_vid)
39007 + pstate_funcs->get_vid(cpu);
39008
39009 /*
39010 * goto max pstate so we don't slow up boot if we are built-in if we are
39011 @@ -832,9 +832,9 @@ static int intel_pstate_msrs_not_valid(void)
39012 rdmsrl(MSR_IA32_APERF, aperf);
39013 rdmsrl(MSR_IA32_MPERF, mperf);
39014
39015 - if (!pstate_funcs.get_max() ||
39016 - !pstate_funcs.get_min() ||
39017 - !pstate_funcs.get_turbo())
39018 + if (!pstate_funcs->get_max() ||
39019 + !pstate_funcs->get_min() ||
39020 + !pstate_funcs->get_turbo())
39021 return -ENODEV;
39022
39023 rdmsrl(MSR_IA32_APERF, tmp);
39024 @@ -848,7 +848,7 @@ static int intel_pstate_msrs_not_valid(void)
39025 return 0;
39026 }
39027
39028 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39029 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39030 {
39031 pid_params.sample_rate_ms = policy->sample_rate_ms;
39032 pid_params.p_gain_pct = policy->p_gain_pct;
39033 @@ -860,11 +860,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39034
39035 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39036 {
39037 - pstate_funcs.get_max = funcs->get_max;
39038 - pstate_funcs.get_min = funcs->get_min;
39039 - pstate_funcs.get_turbo = funcs->get_turbo;
39040 - pstate_funcs.set = funcs->set;
39041 - pstate_funcs.get_vid = funcs->get_vid;
39042 + pstate_funcs = funcs;
39043 }
39044
39045 #if IS_ENABLED(CONFIG_ACPI)
39046 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39047 index 3d1cba9..0ab21d2 100644
39048 --- a/drivers/cpufreq/p4-clockmod.c
39049 +++ b/drivers/cpufreq/p4-clockmod.c
39050 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39051 case 0x0F: /* Core Duo */
39052 case 0x16: /* Celeron Core */
39053 case 0x1C: /* Atom */
39054 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39055 + pax_open_kernel();
39056 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39057 + pax_close_kernel();
39058 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39059 case 0x0D: /* Pentium M (Dothan) */
39060 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39061 + pax_open_kernel();
39062 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39063 + pax_close_kernel();
39064 /* fall through */
39065 case 0x09: /* Pentium M (Banias) */
39066 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39067 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39068
39069 /* on P-4s, the TSC runs with constant frequency independent whether
39070 * throttling is active or not. */
39071 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39072 + pax_open_kernel();
39073 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39074 + pax_close_kernel();
39075
39076 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39077 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39078 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39079 index 724ffbd..ad83692 100644
39080 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39081 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39082 @@ -18,14 +18,12 @@
39083 #include <asm/head.h>
39084 #include <asm/timer.h>
39085
39086 -static struct cpufreq_driver *cpufreq_us3_driver;
39087 -
39088 struct us3_freq_percpu_info {
39089 struct cpufreq_frequency_table table[4];
39090 };
39091
39092 /* Indexed by cpu number. */
39093 -static struct us3_freq_percpu_info *us3_freq_table;
39094 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39095
39096 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39097 * in the Safari config register.
39098 @@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39099
39100 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39101 {
39102 - if (cpufreq_us3_driver) {
39103 - cpufreq_frequency_table_put_attr(policy->cpu);
39104 - us3_freq_target(policy, 0);
39105 - }
39106 + cpufreq_frequency_table_put_attr(policy->cpu);
39107 + us3_freq_target(policy, 0);
39108
39109 return 0;
39110 }
39111
39112 +static int __init us3_freq_init(void);
39113 +static void __exit us3_freq_exit(void);
39114 +
39115 +static struct cpufreq_driver cpufreq_us3_driver = {
39116 + .init = us3_freq_cpu_init,
39117 + .verify = cpufreq_generic_frequency_table_verify,
39118 + .target_index = us3_freq_target,
39119 + .get = us3_freq_get,
39120 + .exit = us3_freq_cpu_exit,
39121 + .owner = THIS_MODULE,
39122 + .name = "UltraSPARC-III",
39123 +
39124 +};
39125 +
39126 static int __init us3_freq_init(void)
39127 {
39128 unsigned long manuf, impl, ver;
39129 @@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
39130 (impl == CHEETAH_IMPL ||
39131 impl == CHEETAH_PLUS_IMPL ||
39132 impl == JAGUAR_IMPL ||
39133 - impl == PANTHER_IMPL)) {
39134 - struct cpufreq_driver *driver;
39135 -
39136 - ret = -ENOMEM;
39137 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39138 - if (!driver)
39139 - goto err_out;
39140 -
39141 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39142 - GFP_KERNEL);
39143 - if (!us3_freq_table)
39144 - goto err_out;
39145 -
39146 - driver->init = us3_freq_cpu_init;
39147 - driver->verify = cpufreq_generic_frequency_table_verify;
39148 - driver->target_index = us3_freq_target;
39149 - driver->get = us3_freq_get;
39150 - driver->exit = us3_freq_cpu_exit;
39151 - strcpy(driver->name, "UltraSPARC-III");
39152 -
39153 - cpufreq_us3_driver = driver;
39154 - ret = cpufreq_register_driver(driver);
39155 - if (ret)
39156 - goto err_out;
39157 -
39158 - return 0;
39159 -
39160 -err_out:
39161 - if (driver) {
39162 - kfree(driver);
39163 - cpufreq_us3_driver = NULL;
39164 - }
39165 - kfree(us3_freq_table);
39166 - us3_freq_table = NULL;
39167 - return ret;
39168 - }
39169 + impl == PANTHER_IMPL))
39170 + return cpufreq_register_driver(&cpufreq_us3_driver);
39171
39172 return -ENODEV;
39173 }
39174
39175 static void __exit us3_freq_exit(void)
39176 {
39177 - if (cpufreq_us3_driver) {
39178 - cpufreq_unregister_driver(cpufreq_us3_driver);
39179 - kfree(cpufreq_us3_driver);
39180 - cpufreq_us3_driver = NULL;
39181 - kfree(us3_freq_table);
39182 - us3_freq_table = NULL;
39183 - }
39184 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39185 }
39186
39187 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39188 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39189 index 4e1daca..e707b61 100644
39190 --- a/drivers/cpufreq/speedstep-centrino.c
39191 +++ b/drivers/cpufreq/speedstep-centrino.c
39192 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39193 !cpu_has(cpu, X86_FEATURE_EST))
39194 return -ENODEV;
39195
39196 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39197 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39198 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39199 + pax_open_kernel();
39200 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39201 + pax_close_kernel();
39202 + }
39203
39204 if (policy->cpu != 0)
39205 return -ENODEV;
39206 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39207 index 06dbe7c..c2c8671 100644
39208 --- a/drivers/cpuidle/driver.c
39209 +++ b/drivers/cpuidle/driver.c
39210 @@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39211
39212 static void poll_idle_init(struct cpuidle_driver *drv)
39213 {
39214 - struct cpuidle_state *state = &drv->states[0];
39215 + cpuidle_state_no_const *state = &drv->states[0];
39216
39217 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39218 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39219 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39220 index ca89412..a7b9c49 100644
39221 --- a/drivers/cpuidle/governor.c
39222 +++ b/drivers/cpuidle/governor.c
39223 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39224 mutex_lock(&cpuidle_lock);
39225 if (__cpuidle_find_governor(gov->name) == NULL) {
39226 ret = 0;
39227 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39228 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39229 if (!cpuidle_curr_governor ||
39230 cpuidle_curr_governor->rating < gov->rating)
39231 cpuidle_switch_governor(gov);
39232 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39233 index e918b6d..f87ea80 100644
39234 --- a/drivers/cpuidle/sysfs.c
39235 +++ b/drivers/cpuidle/sysfs.c
39236 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39237 NULL
39238 };
39239
39240 -static struct attribute_group cpuidle_attr_group = {
39241 +static attribute_group_no_const cpuidle_attr_group = {
39242 .attrs = cpuidle_default_attrs,
39243 .name = "cpuidle",
39244 };
39245 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39246 index 12fea3e..1e28f47 100644
39247 --- a/drivers/crypto/hifn_795x.c
39248 +++ b/drivers/crypto/hifn_795x.c
39249 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39250 MODULE_PARM_DESC(hifn_pll_ref,
39251 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39252
39253 -static atomic_t hifn_dev_number;
39254 +static atomic_unchecked_t hifn_dev_number;
39255
39256 #define ACRYPTO_OP_DECRYPT 0
39257 #define ACRYPTO_OP_ENCRYPT 1
39258 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39259 goto err_out_disable_pci_device;
39260
39261 snprintf(name, sizeof(name), "hifn%d",
39262 - atomic_inc_return(&hifn_dev_number)-1);
39263 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39264
39265 err = pci_request_regions(pdev, name);
39266 if (err)
39267 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39268 index a0b2f7e..1b6f028 100644
39269 --- a/drivers/devfreq/devfreq.c
39270 +++ b/drivers/devfreq/devfreq.c
39271 @@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39272 goto err_out;
39273 }
39274
39275 - list_add(&governor->node, &devfreq_governor_list);
39276 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39277
39278 list_for_each_entry(devfreq, &devfreq_list, node) {
39279 int ret = 0;
39280 @@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39281 }
39282 }
39283
39284 - list_del(&governor->node);
39285 + pax_list_del((struct list_head *)&governor->node);
39286 err_out:
39287 mutex_unlock(&devfreq_list_lock);
39288
39289 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39290 index 0d765c0..60b7480 100644
39291 --- a/drivers/dma/sh/shdmac.c
39292 +++ b/drivers/dma/sh/shdmac.c
39293 @@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39294 return ret;
39295 }
39296
39297 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39298 +static struct notifier_block sh_dmae_nmi_notifier = {
39299 .notifier_call = sh_dmae_nmi_handler,
39300
39301 /* Run before NMI debug handler and KGDB */
39302 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39303 index 592af5f..bb1d583 100644
39304 --- a/drivers/edac/edac_device.c
39305 +++ b/drivers/edac/edac_device.c
39306 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39307 */
39308 int edac_device_alloc_index(void)
39309 {
39310 - static atomic_t device_indexes = ATOMIC_INIT(0);
39311 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39312
39313 - return atomic_inc_return(&device_indexes) - 1;
39314 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39315 }
39316 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39317
39318 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39319 index b335c6a..db65b44 100644
39320 --- a/drivers/edac/edac_mc_sysfs.c
39321 +++ b/drivers/edac/edac_mc_sysfs.c
39322 @@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39323 struct dev_ch_attribute {
39324 struct device_attribute attr;
39325 int channel;
39326 -};
39327 +} __do_const;
39328
39329 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39330 struct dev_ch_attribute dev_attr_legacy_##_name = \
39331 @@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39332 }
39333
39334 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39335 + pax_open_kernel();
39336 if (mci->get_sdram_scrub_rate) {
39337 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39338 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39339 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39340 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39341 }
39342 if (mci->set_sdram_scrub_rate) {
39343 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39344 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39345 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39346 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39347 }
39348 + pax_close_kernel();
39349 err = device_create_file(&mci->dev,
39350 &dev_attr_sdram_scrub_rate);
39351 if (err) {
39352 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39353 index 2cf44b4d..6dd2dc7 100644
39354 --- a/drivers/edac/edac_pci.c
39355 +++ b/drivers/edac/edac_pci.c
39356 @@ -29,7 +29,7 @@
39357
39358 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39359 static LIST_HEAD(edac_pci_list);
39360 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39361 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39362
39363 /*
39364 * edac_pci_alloc_ctl_info
39365 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39366 */
39367 int edac_pci_alloc_index(void)
39368 {
39369 - return atomic_inc_return(&pci_indexes) - 1;
39370 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39371 }
39372 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39373
39374 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39375 index e8658e4..22746d6 100644
39376 --- a/drivers/edac/edac_pci_sysfs.c
39377 +++ b/drivers/edac/edac_pci_sysfs.c
39378 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39379 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39380 static int edac_pci_poll_msec = 1000; /* one second workq period */
39381
39382 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39383 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39384 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39385 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39386
39387 static struct kobject *edac_pci_top_main_kobj;
39388 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39389 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39390 void *value;
39391 ssize_t(*show) (void *, char *);
39392 ssize_t(*store) (void *, const char *, size_t);
39393 -};
39394 +} __do_const;
39395
39396 /* Set of show/store abstract level functions for PCI Parity object */
39397 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39398 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39399 edac_printk(KERN_CRIT, EDAC_PCI,
39400 "Signaled System Error on %s\n",
39401 pci_name(dev));
39402 - atomic_inc(&pci_nonparity_count);
39403 + atomic_inc_unchecked(&pci_nonparity_count);
39404 }
39405
39406 if (status & (PCI_STATUS_PARITY)) {
39407 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39408 "Master Data Parity Error on %s\n",
39409 pci_name(dev));
39410
39411 - atomic_inc(&pci_parity_count);
39412 + atomic_inc_unchecked(&pci_parity_count);
39413 }
39414
39415 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39416 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39417 "Detected Parity Error on %s\n",
39418 pci_name(dev));
39419
39420 - atomic_inc(&pci_parity_count);
39421 + atomic_inc_unchecked(&pci_parity_count);
39422 }
39423 }
39424
39425 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39426 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39427 "Signaled System Error on %s\n",
39428 pci_name(dev));
39429 - atomic_inc(&pci_nonparity_count);
39430 + atomic_inc_unchecked(&pci_nonparity_count);
39431 }
39432
39433 if (status & (PCI_STATUS_PARITY)) {
39434 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39435 "Master Data Parity Error on "
39436 "%s\n", pci_name(dev));
39437
39438 - atomic_inc(&pci_parity_count);
39439 + atomic_inc_unchecked(&pci_parity_count);
39440 }
39441
39442 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39443 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39444 "Detected Parity Error on %s\n",
39445 pci_name(dev));
39446
39447 - atomic_inc(&pci_parity_count);
39448 + atomic_inc_unchecked(&pci_parity_count);
39449 }
39450 }
39451 }
39452 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39453 if (!check_pci_errors)
39454 return;
39455
39456 - before_count = atomic_read(&pci_parity_count);
39457 + before_count = atomic_read_unchecked(&pci_parity_count);
39458
39459 /* scan all PCI devices looking for a Parity Error on devices and
39460 * bridges.
39461 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39462 /* Only if operator has selected panic on PCI Error */
39463 if (edac_pci_get_panic_on_pe()) {
39464 /* If the count is different 'after' from 'before' */
39465 - if (before_count != atomic_read(&pci_parity_count))
39466 + if (before_count != atomic_read_unchecked(&pci_parity_count))
39467 panic("EDAC: PCI Parity Error");
39468 }
39469 }
39470 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39471 index 51b7e3a..aa8a3e8 100644
39472 --- a/drivers/edac/mce_amd.h
39473 +++ b/drivers/edac/mce_amd.h
39474 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
39475 bool (*mc0_mce)(u16, u8);
39476 bool (*mc1_mce)(u16, u8);
39477 bool (*mc2_mce)(u16, u8);
39478 -};
39479 +} __no_const;
39480
39481 void amd_report_gart_errors(bool);
39482 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39483 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39484 index 57ea7f4..af06b76 100644
39485 --- a/drivers/firewire/core-card.c
39486 +++ b/drivers/firewire/core-card.c
39487 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39488 const struct fw_card_driver *driver,
39489 struct device *device)
39490 {
39491 - static atomic_t index = ATOMIC_INIT(-1);
39492 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
39493
39494 - card->index = atomic_inc_return(&index);
39495 + card->index = atomic_inc_return_unchecked(&index);
39496 card->driver = driver;
39497 card->device = device;
39498 card->current_tlabel = 0;
39499 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39500
39501 void fw_core_remove_card(struct fw_card *card)
39502 {
39503 - struct fw_card_driver dummy_driver = dummy_driver_template;
39504 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
39505
39506 card->driver->update_phy_reg(card, 4,
39507 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39508 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39509 index 2c6d5e1..a2cca6b 100644
39510 --- a/drivers/firewire/core-device.c
39511 +++ b/drivers/firewire/core-device.c
39512 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39513 struct config_rom_attribute {
39514 struct device_attribute attr;
39515 u32 key;
39516 -};
39517 +} __do_const;
39518
39519 static ssize_t show_immediate(struct device *dev,
39520 struct device_attribute *dattr, char *buf)
39521 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39522 index eb6935c..3cc2bfa 100644
39523 --- a/drivers/firewire/core-transaction.c
39524 +++ b/drivers/firewire/core-transaction.c
39525 @@ -38,6 +38,7 @@
39526 #include <linux/timer.h>
39527 #include <linux/types.h>
39528 #include <linux/workqueue.h>
39529 +#include <linux/sched.h>
39530
39531 #include <asm/byteorder.h>
39532
39533 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39534 index c98764a..551b520 100644
39535 --- a/drivers/firewire/core.h
39536 +++ b/drivers/firewire/core.h
39537 @@ -111,6 +111,7 @@ struct fw_card_driver {
39538
39539 int (*stop_iso)(struct fw_iso_context *ctx);
39540 };
39541 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39542
39543 void fw_card_initialize(struct fw_card *card,
39544 const struct fw_card_driver *driver, struct device *device);
39545 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39546 index 8db6632..9bbc8ca 100644
39547 --- a/drivers/firewire/ohci.c
39548 +++ b/drivers/firewire/ohci.c
39549 @@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
39550 be32_to_cpu(ohci->next_header));
39551 }
39552
39553 +#ifndef CONFIG_GRKERNSEC
39554 if (param_remote_dma) {
39555 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39556 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39557 }
39558 +#endif
39559
39560 spin_unlock_irq(&ohci->lock);
39561
39562 @@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39563 unsigned long flags;
39564 int n, ret = 0;
39565
39566 +#ifndef CONFIG_GRKERNSEC
39567 if (param_remote_dma)
39568 return 0;
39569 +#endif
39570
39571 /*
39572 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39573 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39574 index 94a58a0..f5eba42 100644
39575 --- a/drivers/firmware/dmi-id.c
39576 +++ b/drivers/firmware/dmi-id.c
39577 @@ -16,7 +16,7 @@
39578 struct dmi_device_attribute{
39579 struct device_attribute dev_attr;
39580 int field;
39581 -};
39582 +} __do_const;
39583 #define to_dmi_dev_attr(_dev_attr) \
39584 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39585
39586 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39587 index 17afc51..0ef90cd 100644
39588 --- a/drivers/firmware/dmi_scan.c
39589 +++ b/drivers/firmware/dmi_scan.c
39590 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39591 if (buf == NULL)
39592 return -1;
39593
39594 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39595 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39596
39597 dmi_unmap(buf);
39598 return 0;
39599 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39600 index 1491dd4..aa910db 100644
39601 --- a/drivers/firmware/efi/cper.c
39602 +++ b/drivers/firmware/efi/cper.c
39603 @@ -41,12 +41,12 @@
39604 */
39605 u64 cper_next_record_id(void)
39606 {
39607 - static atomic64_t seq;
39608 + static atomic64_unchecked_t seq;
39609
39610 - if (!atomic64_read(&seq))
39611 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
39612 + if (!atomic64_read_unchecked(&seq))
39613 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39614
39615 - return atomic64_inc_return(&seq);
39616 + return atomic64_inc_return_unchecked(&seq);
39617 }
39618 EXPORT_SYMBOL_GPL(cper_next_record_id);
39619
39620 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39621 index 4753bac..02861a2 100644
39622 --- a/drivers/firmware/efi/efi.c
39623 +++ b/drivers/firmware/efi/efi.c
39624 @@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
39625 };
39626
39627 static struct efivars generic_efivars;
39628 -static struct efivar_operations generic_ops;
39629 +static efivar_operations_no_const generic_ops __read_only;
39630
39631 static int generic_ops_register(void)
39632 {
39633 - generic_ops.get_variable = efi.get_variable;
39634 - generic_ops.set_variable = efi.set_variable;
39635 - generic_ops.get_next_variable = efi.get_next_variable;
39636 - generic_ops.query_variable_store = efi_query_variable_store;
39637 + pax_open_kernel();
39638 + *(void **)&generic_ops.get_variable = efi.get_variable;
39639 + *(void **)&generic_ops.set_variable = efi.set_variable;
39640 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39641 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39642 + pax_close_kernel();
39643
39644 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39645 }
39646 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39647 index 3dc2482..7bd2f61 100644
39648 --- a/drivers/firmware/efi/efivars.c
39649 +++ b/drivers/firmware/efi/efivars.c
39650 @@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39651 static int
39652 create_efivars_bin_attributes(void)
39653 {
39654 - struct bin_attribute *attr;
39655 + bin_attribute_no_const *attr;
39656 int error;
39657
39658 /* new_var */
39659 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39660 index 2a90ba6..07f3733 100644
39661 --- a/drivers/firmware/google/memconsole.c
39662 +++ b/drivers/firmware/google/memconsole.c
39663 @@ -147,7 +147,9 @@ static int __init memconsole_init(void)
39664 if (!found_memconsole())
39665 return -ENODEV;
39666
39667 - memconsole_bin_attr.size = memconsole_length;
39668 + pax_open_kernel();
39669 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39670 + pax_close_kernel();
39671
39672 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39673
39674 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39675 index 1e98a98..b444372 100644
39676 --- a/drivers/gpio/gpio-em.c
39677 +++ b/drivers/gpio/gpio-em.c
39678 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
39679 struct em_gio_priv *p;
39680 struct resource *io[2], *irq[2];
39681 struct gpio_chip *gpio_chip;
39682 - struct irq_chip *irq_chip;
39683 + irq_chip_no_const *irq_chip;
39684 const char *name = dev_name(&pdev->dev);
39685 int ret;
39686
39687 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39688 index f5bf3c3..7baaa59 100644
39689 --- a/drivers/gpio/gpio-ich.c
39690 +++ b/drivers/gpio/gpio-ich.c
39691 @@ -71,7 +71,7 @@ struct ichx_desc {
39692 /* Some chipsets have quirks, let these use their own request/get */
39693 int (*request)(struct gpio_chip *chip, unsigned offset);
39694 int (*get)(struct gpio_chip *chip, unsigned offset);
39695 -};
39696 +} __do_const;
39697
39698 static struct {
39699 spinlock_t lock;
39700 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39701 index ca76ce7..68b384b 100644
39702 --- a/drivers/gpio/gpio-rcar.c
39703 +++ b/drivers/gpio/gpio-rcar.c
39704 @@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39705 struct gpio_rcar_priv *p;
39706 struct resource *io, *irq;
39707 struct gpio_chip *gpio_chip;
39708 - struct irq_chip *irq_chip;
39709 + irq_chip_no_const *irq_chip;
39710 const char *name = dev_name(&pdev->dev);
39711 int ret;
39712
39713 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39714 index 9902732..64b62dd 100644
39715 --- a/drivers/gpio/gpio-vr41xx.c
39716 +++ b/drivers/gpio/gpio-vr41xx.c
39717 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39718 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39719 maskl, pendl, maskh, pendh);
39720
39721 - atomic_inc(&irq_err_count);
39722 + atomic_inc_unchecked(&irq_err_count);
39723
39724 return -EINVAL;
39725 }
39726 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39727 index 3b7d32d..05c2f74 100644
39728 --- a/drivers/gpu/drm/drm_crtc.c
39729 +++ b/drivers/gpu/drm/drm_crtc.c
39730 @@ -3123,7 +3123,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39731 goto done;
39732 }
39733
39734 - if (copy_to_user(&enum_ptr[copied].name,
39735 + if (copy_to_user(enum_ptr[copied].name,
39736 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39737 ret = -EFAULT;
39738 goto done;
39739 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39740 index 345be03..158368d 100644
39741 --- a/drivers/gpu/drm/drm_drv.c
39742 +++ b/drivers/gpu/drm/drm_drv.c
39743 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39744 /**
39745 * Copy and IOCTL return string to user space
39746 */
39747 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39748 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39749 {
39750 int len;
39751
39752 @@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39753 struct drm_file *file_priv = filp->private_data;
39754 struct drm_device *dev;
39755 const struct drm_ioctl_desc *ioctl = NULL;
39756 - drm_ioctl_t *func;
39757 + drm_ioctl_no_const_t func;
39758 unsigned int nr = DRM_IOCTL_NR(cmd);
39759 int retcode = -EINVAL;
39760 char stack_kdata[128];
39761 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39762 index 7f2af9a..1561914 100644
39763 --- a/drivers/gpu/drm/drm_fops.c
39764 +++ b/drivers/gpu/drm/drm_fops.c
39765 @@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39766 if (drm_device_is_unplugged(dev))
39767 return -ENODEV;
39768
39769 - if (!dev->open_count++)
39770 + if (local_inc_return(&dev->open_count) == 1)
39771 need_setup = 1;
39772 mutex_lock(&dev->struct_mutex);
39773 old_imapping = inode->i_mapping;
39774 @@ -127,7 +127,7 @@ err_undo:
39775 iput(container_of(dev->dev_mapping, struct inode, i_data));
39776 dev->dev_mapping = old_mapping;
39777 mutex_unlock(&dev->struct_mutex);
39778 - dev->open_count--;
39779 + local_dec(&dev->open_count);
39780 return retcode;
39781 }
39782 EXPORT_SYMBOL(drm_open);
39783 @@ -463,7 +463,7 @@ int drm_release(struct inode *inode, struct file *filp)
39784
39785 mutex_lock(&drm_global_mutex);
39786
39787 - DRM_DEBUG("open_count = %d\n", dev->open_count);
39788 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39789
39790 if (dev->driver->preclose)
39791 dev->driver->preclose(dev, file_priv);
39792 @@ -472,10 +472,10 @@ int drm_release(struct inode *inode, struct file *filp)
39793 * Begin inline drm_release
39794 */
39795
39796 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39797 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39798 task_pid_nr(current),
39799 (long)old_encode_dev(file_priv->minor->device),
39800 - dev->open_count);
39801 + local_read(&dev->open_count));
39802
39803 /* Release any auth tokens that might point to this file_priv,
39804 (do that under the drm_global_mutex) */
39805 @@ -573,7 +573,7 @@ int drm_release(struct inode *inode, struct file *filp)
39806 * End inline drm_release
39807 */
39808
39809 - if (!--dev->open_count) {
39810 + if (local_dec_and_test(&dev->open_count)) {
39811 retcode = drm_lastclose(dev);
39812 if (drm_device_is_unplugged(dev))
39813 drm_put_dev(dev);
39814 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39815 index 3d2e91c..d31c4c9 100644
39816 --- a/drivers/gpu/drm/drm_global.c
39817 +++ b/drivers/gpu/drm/drm_global.c
39818 @@ -36,7 +36,7 @@
39819 struct drm_global_item {
39820 struct mutex mutex;
39821 void *object;
39822 - int refcount;
39823 + atomic_t refcount;
39824 };
39825
39826 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39827 @@ -49,7 +49,7 @@ void drm_global_init(void)
39828 struct drm_global_item *item = &glob[i];
39829 mutex_init(&item->mutex);
39830 item->object = NULL;
39831 - item->refcount = 0;
39832 + atomic_set(&item->refcount, 0);
39833 }
39834 }
39835
39836 @@ -59,7 +59,7 @@ void drm_global_release(void)
39837 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39838 struct drm_global_item *item = &glob[i];
39839 BUG_ON(item->object != NULL);
39840 - BUG_ON(item->refcount != 0);
39841 + BUG_ON(atomic_read(&item->refcount) != 0);
39842 }
39843 }
39844
39845 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39846 struct drm_global_item *item = &glob[ref->global_type];
39847
39848 mutex_lock(&item->mutex);
39849 - if (item->refcount == 0) {
39850 + if (atomic_read(&item->refcount) == 0) {
39851 item->object = kzalloc(ref->size, GFP_KERNEL);
39852 if (unlikely(item->object == NULL)) {
39853 ret = -ENOMEM;
39854 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39855 goto out_err;
39856
39857 }
39858 - ++item->refcount;
39859 + atomic_inc(&item->refcount);
39860 ref->object = item->object;
39861 mutex_unlock(&item->mutex);
39862 return 0;
39863 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39864 struct drm_global_item *item = &glob[ref->global_type];
39865
39866 mutex_lock(&item->mutex);
39867 - BUG_ON(item->refcount == 0);
39868 + BUG_ON(atomic_read(&item->refcount) == 0);
39869 BUG_ON(ref->object != item->object);
39870 - if (--item->refcount == 0) {
39871 + if (atomic_dec_and_test(&item->refcount)) {
39872 ref->release(ref);
39873 item->object = NULL;
39874 }
39875 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39876 index 7473035..a48b9c5 100644
39877 --- a/drivers/gpu/drm/drm_info.c
39878 +++ b/drivers/gpu/drm/drm_info.c
39879 @@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
39880 struct drm_local_map *map;
39881 struct drm_map_list *r_list;
39882
39883 - /* Hardcoded from _DRM_FRAME_BUFFER,
39884 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39885 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39886 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39887 + static const char * const types[] = {
39888 + [_DRM_FRAME_BUFFER] = "FB",
39889 + [_DRM_REGISTERS] = "REG",
39890 + [_DRM_SHM] = "SHM",
39891 + [_DRM_AGP] = "AGP",
39892 + [_DRM_SCATTER_GATHER] = "SG",
39893 + [_DRM_CONSISTENT] = "PCI"};
39894 const char *type;
39895 int i;
39896
39897 @@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39898 map = r_list->map;
39899 if (!map)
39900 continue;
39901 - if (map->type < 0 || map->type > 5)
39902 + if (map->type >= ARRAY_SIZE(types))
39903 type = "??";
39904 else
39905 type = types[map->type];
39906 @@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39907 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39908 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39909 vma->vm_flags & VM_IO ? 'i' : '-',
39910 +#ifdef CONFIG_GRKERNSEC_HIDESYM
39911 + 0);
39912 +#else
39913 vma->vm_pgoff);
39914 +#endif
39915
39916 #if defined(__i386__)
39917 pgprot = pgprot_val(vma->vm_page_prot);
39918 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39919 index 2f4c4343..dd12cd2 100644
39920 --- a/drivers/gpu/drm/drm_ioc32.c
39921 +++ b/drivers/gpu/drm/drm_ioc32.c
39922 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39923 request = compat_alloc_user_space(nbytes);
39924 if (!access_ok(VERIFY_WRITE, request, nbytes))
39925 return -EFAULT;
39926 - list = (struct drm_buf_desc *) (request + 1);
39927 + list = (struct drm_buf_desc __user *) (request + 1);
39928
39929 if (__put_user(count, &request->count)
39930 || __put_user(list, &request->list))
39931 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39932 request = compat_alloc_user_space(nbytes);
39933 if (!access_ok(VERIFY_WRITE, request, nbytes))
39934 return -EFAULT;
39935 - list = (struct drm_buf_pub *) (request + 1);
39936 + list = (struct drm_buf_pub __user *) (request + 1);
39937
39938 if (__put_user(count, &request->count)
39939 || __put_user(list, &request->list))
39940 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
39941 return 0;
39942 }
39943
39944 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
39945 +drm_ioctl_compat_t drm_compat_ioctls[] = {
39946 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
39947 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
39948 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
39949 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
39950 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39951 {
39952 unsigned int nr = DRM_IOCTL_NR(cmd);
39953 - drm_ioctl_compat_t *fn;
39954 int ret;
39955
39956 /* Assume that ioctls without an explicit compat routine will just
39957 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39958 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
39959 return drm_ioctl(filp, cmd, arg);
39960
39961 - fn = drm_compat_ioctls[nr];
39962 -
39963 - if (fn != NULL)
39964 - ret = (*fn) (filp, cmd, arg);
39965 + if (drm_compat_ioctls[nr] != NULL)
39966 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
39967 else
39968 ret = drm_ioctl(filp, cmd, arg);
39969
39970 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39971 index 98a33c580..8fd1c2b 100644
39972 --- a/drivers/gpu/drm/drm_stub.c
39973 +++ b/drivers/gpu/drm/drm_stub.c
39974 @@ -409,7 +409,7 @@ void drm_unplug_dev(struct drm_device *dev)
39975
39976 drm_device_set_unplugged(dev);
39977
39978 - if (dev->open_count == 0) {
39979 + if (local_read(&dev->open_count) == 0) {
39980 drm_put_dev(dev);
39981 }
39982 mutex_unlock(&drm_global_mutex);
39983 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
39984 index c22c309..ae758c3 100644
39985 --- a/drivers/gpu/drm/drm_sysfs.c
39986 +++ b/drivers/gpu/drm/drm_sysfs.c
39987 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
39988 */
39989 int drm_sysfs_device_add(struct drm_minor *minor)
39990 {
39991 - char *minor_str;
39992 + const char *minor_str;
39993 int r;
39994
39995 if (minor->type == DRM_MINOR_CONTROL)
39996 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
39997 index d4d16ed..8fb0b51 100644
39998 --- a/drivers/gpu/drm/i810/i810_drv.h
39999 +++ b/drivers/gpu/drm/i810/i810_drv.h
40000 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40001 int page_flipping;
40002
40003 wait_queue_head_t irq_queue;
40004 - atomic_t irq_received;
40005 - atomic_t irq_emitted;
40006 + atomic_unchecked_t irq_received;
40007 + atomic_unchecked_t irq_emitted;
40008
40009 int front_offset;
40010 } drm_i810_private_t;
40011 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40012 index b2b46c5..feb9fe7 100644
40013 --- a/drivers/gpu/drm/i915/i915_debugfs.c
40014 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
40015 @@ -713,7 +713,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40016 I915_READ(GTIMR));
40017 }
40018 seq_printf(m, "Interrupts received: %d\n",
40019 - atomic_read(&dev_priv->irq_received));
40020 + atomic_read_unchecked(&dev_priv->irq_received));
40021 for_each_ring(ring, dev_priv, i) {
40022 if (INTEL_INFO(dev)->gen >= 6) {
40023 seq_printf(m,
40024 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40025 index 15a74f9..4278889 100644
40026 --- a/drivers/gpu/drm/i915/i915_dma.c
40027 +++ b/drivers/gpu/drm/i915/i915_dma.c
40028 @@ -1273,7 +1273,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40029 bool can_switch;
40030
40031 spin_lock(&dev->count_lock);
40032 - can_switch = (dev->open_count == 0);
40033 + can_switch = (local_read(&dev->open_count) == 0);
40034 spin_unlock(&dev->count_lock);
40035 return can_switch;
40036 }
40037 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40038 index df77e20..d3fda9f 100644
40039 --- a/drivers/gpu/drm/i915/i915_drv.h
40040 +++ b/drivers/gpu/drm/i915/i915_drv.h
40041 @@ -1361,7 +1361,7 @@ typedef struct drm_i915_private {
40042 drm_dma_handle_t *status_page_dmah;
40043 struct resource mch_res;
40044
40045 - atomic_t irq_received;
40046 + atomic_unchecked_t irq_received;
40047
40048 /* protects the irq masks */
40049 spinlock_t irq_lock;
40050 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40051 index d269ecf..6d857bc 100644
40052 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40053 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40054 @@ -860,9 +860,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40055
40056 static int
40057 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40058 - int count)
40059 + unsigned int count)
40060 {
40061 - int i;
40062 + unsigned int i;
40063 unsigned relocs_total = 0;
40064 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40065
40066 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40067 index 3c59584..500f2e9 100644
40068 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40069 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40070 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40071 (unsigned long)request);
40072 }
40073
40074 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40075 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40076 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40077 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40078 [DRM_I915_GETPARAM] = compat_i915_getparam,
40079 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40080 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40081 {
40082 unsigned int nr = DRM_IOCTL_NR(cmd);
40083 - drm_ioctl_compat_t *fn = NULL;
40084 int ret;
40085
40086 if (nr < DRM_COMMAND_BASE)
40087 return drm_compat_ioctl(filp, cmd, arg);
40088
40089 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40090 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40091 -
40092 - if (fn != NULL)
40093 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40094 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40095 ret = (*fn) (filp, cmd, arg);
40096 - else
40097 + } else
40098 ret = drm_ioctl(filp, cmd, arg);
40099
40100 return ret;
40101 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40102 index d554169..f4426bb 100644
40103 --- a/drivers/gpu/drm/i915/i915_irq.c
40104 +++ b/drivers/gpu/drm/i915/i915_irq.c
40105 @@ -1438,7 +1438,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40106 int pipe;
40107 u32 pipe_stats[I915_MAX_PIPES];
40108
40109 - atomic_inc(&dev_priv->irq_received);
40110 + atomic_inc_unchecked(&dev_priv->irq_received);
40111
40112 while (true) {
40113 iir = I915_READ(VLV_IIR);
40114 @@ -1751,7 +1751,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40115 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40116 irqreturn_t ret = IRQ_NONE;
40117
40118 - atomic_inc(&dev_priv->irq_received);
40119 + atomic_inc_unchecked(&dev_priv->irq_received);
40120
40121 /* We get interrupts on unclaimed registers, so check for this before we
40122 * do any I915_{READ,WRITE}. */
40123 @@ -1821,7 +1821,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40124 uint32_t tmp = 0;
40125 enum pipe pipe;
40126
40127 - atomic_inc(&dev_priv->irq_received);
40128 + atomic_inc_unchecked(&dev_priv->irq_received);
40129
40130 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40131 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40132 @@ -2645,7 +2645,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40133 {
40134 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40135
40136 - atomic_set(&dev_priv->irq_received, 0);
40137 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40138
40139 I915_WRITE(HWSTAM, 0xeffe);
40140
40141 @@ -2663,7 +2663,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40142 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40143 int pipe;
40144
40145 - atomic_set(&dev_priv->irq_received, 0);
40146 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40147
40148 /* VLV magic */
40149 I915_WRITE(VLV_IMR, 0);
40150 @@ -2694,7 +2694,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40151 struct drm_i915_private *dev_priv = dev->dev_private;
40152 int pipe;
40153
40154 - atomic_set(&dev_priv->irq_received, 0);
40155 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40156
40157 I915_WRITE(GEN8_MASTER_IRQ, 0);
40158 POSTING_READ(GEN8_MASTER_IRQ);
40159 @@ -3018,7 +3018,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40160 if (!dev_priv)
40161 return;
40162
40163 - atomic_set(&dev_priv->irq_received, 0);
40164 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40165
40166 I915_WRITE(GEN8_MASTER_IRQ, 0);
40167
40168 @@ -3112,7 +3112,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40169 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40170 int pipe;
40171
40172 - atomic_set(&dev_priv->irq_received, 0);
40173 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40174
40175 for_each_pipe(pipe)
40176 I915_WRITE(PIPESTAT(pipe), 0);
40177 @@ -3198,7 +3198,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40178 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40179 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40180
40181 - atomic_inc(&dev_priv->irq_received);
40182 + atomic_inc_unchecked(&dev_priv->irq_received);
40183
40184 iir = I915_READ16(IIR);
40185 if (iir == 0)
40186 @@ -3277,7 +3277,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40187 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40188 int pipe;
40189
40190 - atomic_set(&dev_priv->irq_received, 0);
40191 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40192
40193 if (I915_HAS_HOTPLUG(dev)) {
40194 I915_WRITE(PORT_HOTPLUG_EN, 0);
40195 @@ -3384,7 +3384,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40196 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40197 int pipe, ret = IRQ_NONE;
40198
40199 - atomic_inc(&dev_priv->irq_received);
40200 + atomic_inc_unchecked(&dev_priv->irq_received);
40201
40202 iir = I915_READ(IIR);
40203 do {
40204 @@ -3511,7 +3511,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40205 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40206 int pipe;
40207
40208 - atomic_set(&dev_priv->irq_received, 0);
40209 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40210
40211 I915_WRITE(PORT_HOTPLUG_EN, 0);
40212 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40213 @@ -3627,7 +3627,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40214 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40215 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40216
40217 - atomic_inc(&dev_priv->irq_received);
40218 + atomic_inc_unchecked(&dev_priv->irq_received);
40219
40220 iir = I915_READ(IIR);
40221
40222 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40223 index 9b8a7c7..60f6003 100644
40224 --- a/drivers/gpu/drm/i915/intel_display.c
40225 +++ b/drivers/gpu/drm/i915/intel_display.c
40226 @@ -10776,13 +10776,13 @@ struct intel_quirk {
40227 int subsystem_vendor;
40228 int subsystem_device;
40229 void (*hook)(struct drm_device *dev);
40230 -};
40231 +} __do_const;
40232
40233 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40234 struct intel_dmi_quirk {
40235 void (*hook)(struct drm_device *dev);
40236 const struct dmi_system_id (*dmi_id_list)[];
40237 -};
40238 +} __do_const;
40239
40240 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40241 {
40242 @@ -10790,18 +10790,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40243 return 1;
40244 }
40245
40246 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40247 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40248 {
40249 - .dmi_id_list = &(const struct dmi_system_id[]) {
40250 - {
40251 - .callback = intel_dmi_reverse_brightness,
40252 - .ident = "NCR Corporation",
40253 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40254 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40255 - },
40256 - },
40257 - { } /* terminating entry */
40258 + .callback = intel_dmi_reverse_brightness,
40259 + .ident = "NCR Corporation",
40260 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40261 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40262 },
40263 + },
40264 + { } /* terminating entry */
40265 +};
40266 +
40267 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40268 + {
40269 + .dmi_id_list = &intel_dmi_quirks_table,
40270 .hook = quirk_invert_brightness,
40271 },
40272 };
40273 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40274 index fe45321..836fdca 100644
40275 --- a/drivers/gpu/drm/mga/mga_drv.h
40276 +++ b/drivers/gpu/drm/mga/mga_drv.h
40277 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40278 u32 clear_cmd;
40279 u32 maccess;
40280
40281 - atomic_t vbl_received; /**< Number of vblanks received. */
40282 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40283 wait_queue_head_t fence_queue;
40284 - atomic_t last_fence_retired;
40285 + atomic_unchecked_t last_fence_retired;
40286 u32 next_fence_to_post;
40287
40288 unsigned int fb_cpp;
40289 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40290 index 86b4bb8..ae237ad 100644
40291 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40292 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40293 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40294 return 0;
40295 }
40296
40297 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40298 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40299 [DRM_MGA_INIT] = compat_mga_init,
40300 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40301 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40302 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40303 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40304 {
40305 unsigned int nr = DRM_IOCTL_NR(cmd);
40306 - drm_ioctl_compat_t *fn = NULL;
40307 int ret;
40308
40309 if (nr < DRM_COMMAND_BASE)
40310 return drm_compat_ioctl(filp, cmd, arg);
40311
40312 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40313 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40314 -
40315 - if (fn != NULL)
40316 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40317 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40318 ret = (*fn) (filp, cmd, arg);
40319 - else
40320 + } else
40321 ret = drm_ioctl(filp, cmd, arg);
40322
40323 return ret;
40324 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40325 index 1b071b8..de8601a 100644
40326 --- a/drivers/gpu/drm/mga/mga_irq.c
40327 +++ b/drivers/gpu/drm/mga/mga_irq.c
40328 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40329 if (crtc != 0)
40330 return 0;
40331
40332 - return atomic_read(&dev_priv->vbl_received);
40333 + return atomic_read_unchecked(&dev_priv->vbl_received);
40334 }
40335
40336
40337 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40338 /* VBLANK interrupt */
40339 if (status & MGA_VLINEPEN) {
40340 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40341 - atomic_inc(&dev_priv->vbl_received);
40342 + atomic_inc_unchecked(&dev_priv->vbl_received);
40343 drm_handle_vblank(dev, 0);
40344 handled = 1;
40345 }
40346 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40347 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40348 MGA_WRITE(MGA_PRIMEND, prim_end);
40349
40350 - atomic_inc(&dev_priv->last_fence_retired);
40351 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40352 wake_up(&dev_priv->fence_queue);
40353 handled = 1;
40354 }
40355 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40356 * using fences.
40357 */
40358 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40359 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40360 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40361 - *sequence) <= (1 << 23)));
40362
40363 *sequence = cur_fence;
40364 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40365 index 4c3feaa..26391ce 100644
40366 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40367 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40368 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40369 struct bit_table {
40370 const char id;
40371 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40372 -};
40373 +} __no_const;
40374
40375 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40376
40377 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40378 index 23ca7a5..b6c955d 100644
40379 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40380 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40381 @@ -97,7 +97,6 @@ struct nouveau_drm {
40382 struct drm_global_reference mem_global_ref;
40383 struct ttm_bo_global_ref bo_global_ref;
40384 struct ttm_bo_device bdev;
40385 - atomic_t validate_sequence;
40386 int (*move)(struct nouveau_channel *,
40387 struct ttm_buffer_object *,
40388 struct ttm_mem_reg *, struct ttm_mem_reg *);
40389 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40390 index c1a7e5a..38b8539 100644
40391 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40392 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40393 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40394 unsigned long arg)
40395 {
40396 unsigned int nr = DRM_IOCTL_NR(cmd);
40397 - drm_ioctl_compat_t *fn = NULL;
40398 + drm_ioctl_compat_t fn = NULL;
40399 int ret;
40400
40401 if (nr < DRM_COMMAND_BASE)
40402 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40403 index d45d50d..72a5dd2 100644
40404 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40405 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40406 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40407 }
40408
40409 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40410 - nouveau_vram_manager_init,
40411 - nouveau_vram_manager_fini,
40412 - nouveau_vram_manager_new,
40413 - nouveau_vram_manager_del,
40414 - nouveau_vram_manager_debug
40415 + .init = nouveau_vram_manager_init,
40416 + .takedown = nouveau_vram_manager_fini,
40417 + .get_node = nouveau_vram_manager_new,
40418 + .put_node = nouveau_vram_manager_del,
40419 + .debug = nouveau_vram_manager_debug
40420 };
40421
40422 static int
40423 @@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40424 }
40425
40426 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40427 - nouveau_gart_manager_init,
40428 - nouveau_gart_manager_fini,
40429 - nouveau_gart_manager_new,
40430 - nouveau_gart_manager_del,
40431 - nouveau_gart_manager_debug
40432 + .init = nouveau_gart_manager_init,
40433 + .takedown = nouveau_gart_manager_fini,
40434 + .get_node = nouveau_gart_manager_new,
40435 + .put_node = nouveau_gart_manager_del,
40436 + .debug = nouveau_gart_manager_debug
40437 };
40438
40439 #include <core/subdev/vm/nv04.h>
40440 @@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40441 }
40442
40443 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40444 - nv04_gart_manager_init,
40445 - nv04_gart_manager_fini,
40446 - nv04_gart_manager_new,
40447 - nv04_gart_manager_del,
40448 - nv04_gart_manager_debug
40449 + .init = nv04_gart_manager_init,
40450 + .takedown = nv04_gart_manager_fini,
40451 + .get_node = nv04_gart_manager_new,
40452 + .put_node = nv04_gart_manager_del,
40453 + .debug = nv04_gart_manager_debug
40454 };
40455
40456 int
40457 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40458 index 471347e..5adc6b9 100644
40459 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40460 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40461 @@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40462 bool can_switch;
40463
40464 spin_lock(&dev->count_lock);
40465 - can_switch = (dev->open_count == 0);
40466 + can_switch = (local_read(&dev->open_count) == 0);
40467 spin_unlock(&dev->count_lock);
40468 return can_switch;
40469 }
40470 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40471 index eb89653..613cf71 100644
40472 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40473 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40474 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40475 int ret;
40476
40477 mutex_lock(&qdev->async_io_mutex);
40478 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40479 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40480 if (qdev->last_sent_io_cmd > irq_num) {
40481 if (intr)
40482 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40483 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40484 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40485 else
40486 ret = wait_event_timeout(qdev->io_cmd_event,
40487 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40488 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40489 /* 0 is timeout, just bail the "hw" has gone away */
40490 if (ret <= 0)
40491 goto out;
40492 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40493 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40494 }
40495 outb(val, addr);
40496 qdev->last_sent_io_cmd = irq_num + 1;
40497 if (intr)
40498 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40499 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40500 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40501 else
40502 ret = wait_event_timeout(qdev->io_cmd_event,
40503 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40504 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40505 out:
40506 if (ret > 0)
40507 ret = 0;
40508 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40509 index c3c2bbd..bc3c0fb 100644
40510 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40511 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40512 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40513 struct drm_info_node *node = (struct drm_info_node *) m->private;
40514 struct qxl_device *qdev = node->minor->dev->dev_private;
40515
40516 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40517 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40518 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40519 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40520 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40521 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40522 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40523 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40524 seq_printf(m, "%d\n", qdev->irq_received_error);
40525 return 0;
40526 }
40527 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40528 index 36ed40b..0397633 100644
40529 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40530 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40531 @@ -290,10 +290,10 @@ struct qxl_device {
40532 unsigned int last_sent_io_cmd;
40533
40534 /* interrupt handling */
40535 - atomic_t irq_received;
40536 - atomic_t irq_received_display;
40537 - atomic_t irq_received_cursor;
40538 - atomic_t irq_received_io_cmd;
40539 + atomic_unchecked_t irq_received;
40540 + atomic_unchecked_t irq_received_display;
40541 + atomic_unchecked_t irq_received_cursor;
40542 + atomic_unchecked_t irq_received_io_cmd;
40543 unsigned irq_received_error;
40544 wait_queue_head_t display_event;
40545 wait_queue_head_t cursor_event;
40546 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40547 index 0bb86e6..d41416d 100644
40548 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40549 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40550 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40551
40552 /* TODO copy slow path code from i915 */
40553 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40554 - 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);
40555 + 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);
40556
40557 {
40558 struct qxl_drawable *draw = fb_cmd;
40559 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40560 struct drm_qxl_reloc reloc;
40561
40562 if (copy_from_user(&reloc,
40563 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40564 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40565 sizeof(reloc))) {
40566 ret = -EFAULT;
40567 goto out_free_bos;
40568 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40569
40570 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40571
40572 - struct drm_qxl_command *commands =
40573 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40574 + struct drm_qxl_command __user *commands =
40575 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40576
40577 - if (copy_from_user(&user_cmd, &commands[cmd_num],
40578 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40579 sizeof(user_cmd)))
40580 return -EFAULT;
40581
40582 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40583 index 28f84b4..fb3e224 100644
40584 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40585 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40586 @@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40587
40588 pending = xchg(&qdev->ram_header->int_pending, 0);
40589
40590 - atomic_inc(&qdev->irq_received);
40591 + atomic_inc_unchecked(&qdev->irq_received);
40592
40593 if (pending & QXL_INTERRUPT_DISPLAY) {
40594 - atomic_inc(&qdev->irq_received_display);
40595 + atomic_inc_unchecked(&qdev->irq_received_display);
40596 wake_up_all(&qdev->display_event);
40597 qxl_queue_garbage_collect(qdev, false);
40598 }
40599 if (pending & QXL_INTERRUPT_CURSOR) {
40600 - atomic_inc(&qdev->irq_received_cursor);
40601 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40602 wake_up_all(&qdev->cursor_event);
40603 }
40604 if (pending & QXL_INTERRUPT_IO_CMD) {
40605 - atomic_inc(&qdev->irq_received_io_cmd);
40606 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40607 wake_up_all(&qdev->io_cmd_event);
40608 }
40609 if (pending & QXL_INTERRUPT_ERROR) {
40610 @@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40611 init_waitqueue_head(&qdev->io_cmd_event);
40612 INIT_WORK(&qdev->client_monitors_config_work,
40613 qxl_client_monitors_config_work_func);
40614 - atomic_set(&qdev->irq_received, 0);
40615 - atomic_set(&qdev->irq_received_display, 0);
40616 - atomic_set(&qdev->irq_received_cursor, 0);
40617 - atomic_set(&qdev->irq_received_io_cmd, 0);
40618 + atomic_set_unchecked(&qdev->irq_received, 0);
40619 + atomic_set_unchecked(&qdev->irq_received_display, 0);
40620 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40621 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40622 qdev->irq_received_error = 0;
40623 ret = drm_irq_install(qdev->ddev);
40624 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40625 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40626 index c7e7e65..7dddd4d 100644
40627 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
40628 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40629 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40630 }
40631 }
40632
40633 -static struct vm_operations_struct qxl_ttm_vm_ops;
40634 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40635 static const struct vm_operations_struct *ttm_vm_ops;
40636
40637 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40638 @@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40639 return r;
40640 if (unlikely(ttm_vm_ops == NULL)) {
40641 ttm_vm_ops = vma->vm_ops;
40642 + pax_open_kernel();
40643 qxl_ttm_vm_ops = *ttm_vm_ops;
40644 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40645 + pax_close_kernel();
40646 }
40647 vma->vm_ops = &qxl_ttm_vm_ops;
40648 return 0;
40649 @@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40650 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40651 {
40652 #if defined(CONFIG_DEBUG_FS)
40653 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40654 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40655 - unsigned i;
40656 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40657 + {
40658 + .name = "qxl_mem_mm",
40659 + .show = &qxl_mm_dump_table,
40660 + },
40661 + {
40662 + .name = "qxl_surf_mm",
40663 + .show = &qxl_mm_dump_table,
40664 + }
40665 + };
40666
40667 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40668 - if (i == 0)
40669 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40670 - else
40671 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40672 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40673 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40674 - qxl_mem_types_list[i].driver_features = 0;
40675 - if (i == 0)
40676 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40677 - else
40678 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40679 + pax_open_kernel();
40680 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40681 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40682 + pax_close_kernel();
40683
40684 - }
40685 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40686 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40687 #else
40688 return 0;
40689 #endif
40690 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40691 index 59459fe..be26b31 100644
40692 --- a/drivers/gpu/drm/r128/r128_cce.c
40693 +++ b/drivers/gpu/drm/r128/r128_cce.c
40694 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40695
40696 /* GH: Simple idle check.
40697 */
40698 - atomic_set(&dev_priv->idle_count, 0);
40699 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40700
40701 /* We don't support anything other than bus-mastering ring mode,
40702 * but the ring can be in either AGP or PCI space for the ring
40703 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40704 index 5bf3f5f..7000661 100644
40705 --- a/drivers/gpu/drm/r128/r128_drv.h
40706 +++ b/drivers/gpu/drm/r128/r128_drv.h
40707 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40708 int is_pci;
40709 unsigned long cce_buffers_offset;
40710
40711 - atomic_t idle_count;
40712 + atomic_unchecked_t idle_count;
40713
40714 int page_flipping;
40715 int current_page;
40716 u32 crtc_offset;
40717 u32 crtc_offset_cntl;
40718
40719 - atomic_t vbl_received;
40720 + atomic_unchecked_t vbl_received;
40721
40722 u32 color_fmt;
40723 unsigned int front_offset;
40724 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40725 index b0d0fd3..a6fbbe4 100644
40726 --- a/drivers/gpu/drm/r128/r128_ioc32.c
40727 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
40728 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40729 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40730 }
40731
40732 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
40733 +drm_ioctl_compat_t r128_compat_ioctls[] = {
40734 [DRM_R128_INIT] = compat_r128_init,
40735 [DRM_R128_DEPTH] = compat_r128_depth,
40736 [DRM_R128_STIPPLE] = compat_r128_stipple,
40737 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40738 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40739 {
40740 unsigned int nr = DRM_IOCTL_NR(cmd);
40741 - drm_ioctl_compat_t *fn = NULL;
40742 int ret;
40743
40744 if (nr < DRM_COMMAND_BASE)
40745 return drm_compat_ioctl(filp, cmd, arg);
40746
40747 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40748 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40749 -
40750 - if (fn != NULL)
40751 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40752 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40753 ret = (*fn) (filp, cmd, arg);
40754 - else
40755 + } else
40756 ret = drm_ioctl(filp, cmd, arg);
40757
40758 return ret;
40759 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40760 index c2ae496..30b5993 100644
40761 --- a/drivers/gpu/drm/r128/r128_irq.c
40762 +++ b/drivers/gpu/drm/r128/r128_irq.c
40763 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40764 if (crtc != 0)
40765 return 0;
40766
40767 - return atomic_read(&dev_priv->vbl_received);
40768 + return atomic_read_unchecked(&dev_priv->vbl_received);
40769 }
40770
40771 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40772 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40773 /* VBLANK interrupt */
40774 if (status & R128_CRTC_VBLANK_INT) {
40775 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40776 - atomic_inc(&dev_priv->vbl_received);
40777 + atomic_inc_unchecked(&dev_priv->vbl_received);
40778 drm_handle_vblank(dev, 0);
40779 return IRQ_HANDLED;
40780 }
40781 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40782 index e806dac..f81d32f 100644
40783 --- a/drivers/gpu/drm/r128/r128_state.c
40784 +++ b/drivers/gpu/drm/r128/r128_state.c
40785 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40786
40787 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40788 {
40789 - if (atomic_read(&dev_priv->idle_count) == 0)
40790 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40791 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40792 else
40793 - atomic_set(&dev_priv->idle_count, 0);
40794 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40795 }
40796
40797 #endif
40798 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40799 index 4a85bb6..aaea819 100644
40800 --- a/drivers/gpu/drm/radeon/mkregtable.c
40801 +++ b/drivers/gpu/drm/radeon/mkregtable.c
40802 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40803 regex_t mask_rex;
40804 regmatch_t match[4];
40805 char buf[1024];
40806 - size_t end;
40807 + long end;
40808 int len;
40809 int done = 0;
40810 int r;
40811 unsigned o;
40812 struct offset *offset;
40813 char last_reg_s[10];
40814 - int last_reg;
40815 + unsigned long last_reg;
40816
40817 if (regcomp
40818 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40819 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40820 index 044bc98..50ced9b 100644
40821 --- a/drivers/gpu/drm/radeon/radeon_device.c
40822 +++ b/drivers/gpu/drm/radeon/radeon_device.c
40823 @@ -1125,7 +1125,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40824 bool can_switch;
40825
40826 spin_lock(&dev->count_lock);
40827 - can_switch = (dev->open_count == 0);
40828 + can_switch = (local_read(&dev->open_count) == 0);
40829 spin_unlock(&dev->count_lock);
40830 return can_switch;
40831 }
40832 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40833 index dafd812..1bf20c7 100644
40834 --- a/drivers/gpu/drm/radeon/radeon_drv.h
40835 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
40836 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40837
40838 /* SW interrupt */
40839 wait_queue_head_t swi_queue;
40840 - atomic_t swi_emitted;
40841 + atomic_unchecked_t swi_emitted;
40842 int vblank_crtc;
40843 uint32_t irq_enable_reg;
40844 uint32_t r500_disp_irq_reg;
40845 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40846 index bdb0f93..5ff558f 100644
40847 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40848 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40849 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40850 request = compat_alloc_user_space(sizeof(*request));
40851 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40852 || __put_user(req32.param, &request->param)
40853 - || __put_user((void __user *)(unsigned long)req32.value,
40854 + || __put_user((unsigned long)req32.value,
40855 &request->value))
40856 return -EFAULT;
40857
40858 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40859 #define compat_radeon_cp_setparam NULL
40860 #endif /* X86_64 || IA64 */
40861
40862 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40863 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40864 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40865 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40866 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40867 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40868 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40869 {
40870 unsigned int nr = DRM_IOCTL_NR(cmd);
40871 - drm_ioctl_compat_t *fn = NULL;
40872 int ret;
40873
40874 if (nr < DRM_COMMAND_BASE)
40875 return drm_compat_ioctl(filp, cmd, arg);
40876
40877 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40878 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40879 -
40880 - if (fn != NULL)
40881 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40882 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40883 ret = (*fn) (filp, cmd, arg);
40884 - else
40885 + } else
40886 ret = drm_ioctl(filp, cmd, arg);
40887
40888 return ret;
40889 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40890 index 244b19b..c19226d 100644
40891 --- a/drivers/gpu/drm/radeon/radeon_irq.c
40892 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
40893 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40894 unsigned int ret;
40895 RING_LOCALS;
40896
40897 - atomic_inc(&dev_priv->swi_emitted);
40898 - ret = atomic_read(&dev_priv->swi_emitted);
40899 + atomic_inc_unchecked(&dev_priv->swi_emitted);
40900 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40901
40902 BEGIN_RING(4);
40903 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40904 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40905 drm_radeon_private_t *dev_priv =
40906 (drm_radeon_private_t *) dev->dev_private;
40907
40908 - atomic_set(&dev_priv->swi_emitted, 0);
40909 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40910 init_waitqueue_head(&dev_priv->swi_queue);
40911
40912 dev->max_vblank_count = 0x001fffff;
40913 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40914 index 956ab7f..fbd36d8 100644
40915 --- a/drivers/gpu/drm/radeon/radeon_state.c
40916 +++ b/drivers/gpu/drm/radeon/radeon_state.c
40917 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40918 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40919 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40920
40921 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
40922 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
40923 sarea_priv->nbox * sizeof(depth_boxes[0])))
40924 return -EFAULT;
40925
40926 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40927 {
40928 drm_radeon_private_t *dev_priv = dev->dev_private;
40929 drm_radeon_getparam_t *param = data;
40930 - int value;
40931 + int value = 0;
40932
40933 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40934
40935 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40936 index 040a2a1..eae4e54 100644
40937 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
40938 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40939 @@ -790,7 +790,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40940 man->size = size >> PAGE_SHIFT;
40941 }
40942
40943 -static struct vm_operations_struct radeon_ttm_vm_ops;
40944 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40945 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40946
40947 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40948 @@ -831,8 +831,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40949 }
40950 if (unlikely(ttm_vm_ops == NULL)) {
40951 ttm_vm_ops = vma->vm_ops;
40952 + pax_open_kernel();
40953 radeon_ttm_vm_ops = *ttm_vm_ops;
40954 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
40955 + pax_close_kernel();
40956 }
40957 vma->vm_ops = &radeon_ttm_vm_ops;
40958 return 0;
40959 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
40960 index 9336006..ce78aa7 100644
40961 --- a/drivers/gpu/drm/tegra/dc.c
40962 +++ b/drivers/gpu/drm/tegra/dc.c
40963 @@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
40964 }
40965
40966 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
40967 - dc->debugfs_files[i].data = dc;
40968 + *(void **)&dc->debugfs_files[i].data = dc;
40969
40970 err = drm_debugfs_create_files(dc->debugfs_files,
40971 ARRAY_SIZE(debugfs_files),
40972 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
40973 index 6928015..c9853e7 100644
40974 --- a/drivers/gpu/drm/tegra/hdmi.c
40975 +++ b/drivers/gpu/drm/tegra/hdmi.c
40976 @@ -59,7 +59,7 @@ struct tegra_hdmi {
40977 bool stereo;
40978 bool dvi;
40979
40980 - struct drm_info_list *debugfs_files;
40981 + drm_info_list_no_const *debugfs_files;
40982 struct drm_minor *minor;
40983 struct dentry *debugfs;
40984 };
40985 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
40986 index c58eba33..83c2728 100644
40987 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
40988 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
40989 @@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
40990 }
40991
40992 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
40993 - ttm_bo_man_init,
40994 - ttm_bo_man_takedown,
40995 - ttm_bo_man_get_node,
40996 - ttm_bo_man_put_node,
40997 - ttm_bo_man_debug
40998 + .init = ttm_bo_man_init,
40999 + .takedown = ttm_bo_man_takedown,
41000 + .get_node = ttm_bo_man_get_node,
41001 + .put_node = ttm_bo_man_put_node,
41002 + .debug = ttm_bo_man_debug
41003 };
41004 EXPORT_SYMBOL(ttm_bo_manager_func);
41005 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41006 index dbc2def..0a9f710 100644
41007 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41008 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41009 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41010 zone->glob = glob;
41011 glob->zone_kernel = zone;
41012 ret = kobject_init_and_add(
41013 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41014 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41015 if (unlikely(ret != 0)) {
41016 kobject_put(&zone->kobj);
41017 return ret;
41018 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41019 zone->glob = glob;
41020 glob->zone_dma32 = zone;
41021 ret = kobject_init_and_add(
41022 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41023 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41024 if (unlikely(ret != 0)) {
41025 kobject_put(&zone->kobj);
41026 return ret;
41027 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41028 index 863bef9..cba15cf 100644
41029 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41030 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41031 @@ -391,9 +391,9 @@ out:
41032 static unsigned long
41033 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41034 {
41035 - static atomic_t start_pool = ATOMIC_INIT(0);
41036 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41037 unsigned i;
41038 - unsigned pool_offset = atomic_add_return(1, &start_pool);
41039 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41040 struct ttm_page_pool *pool;
41041 int shrink_pages = sc->nr_to_scan;
41042 unsigned long freed = 0;
41043 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41044 index dbadd49..1b7457b 100644
41045 --- a/drivers/gpu/drm/udl/udl_fb.c
41046 +++ b/drivers/gpu/drm/udl/udl_fb.c
41047 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41048 fb_deferred_io_cleanup(info);
41049 kfree(info->fbdefio);
41050 info->fbdefio = NULL;
41051 - info->fbops->fb_mmap = udl_fb_mmap;
41052 }
41053
41054 pr_warn("released /dev/fb%d user=%d count=%d\n",
41055 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41056 index ad02732..144f5ed 100644
41057 --- a/drivers/gpu/drm/via/via_drv.h
41058 +++ b/drivers/gpu/drm/via/via_drv.h
41059 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41060 typedef uint32_t maskarray_t[5];
41061
41062 typedef struct drm_via_irq {
41063 - atomic_t irq_received;
41064 + atomic_unchecked_t irq_received;
41065 uint32_t pending_mask;
41066 uint32_t enable_mask;
41067 wait_queue_head_t irq_queue;
41068 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
41069 struct timeval last_vblank;
41070 int last_vblank_valid;
41071 unsigned usec_per_vblank;
41072 - atomic_t vbl_received;
41073 + atomic_unchecked_t vbl_received;
41074 drm_via_state_t hc_state;
41075 char pci_buf[VIA_PCI_BUF_SIZE];
41076 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41077 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41078 index 1319433..a993b0c 100644
41079 --- a/drivers/gpu/drm/via/via_irq.c
41080 +++ b/drivers/gpu/drm/via/via_irq.c
41081 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41082 if (crtc != 0)
41083 return 0;
41084
41085 - return atomic_read(&dev_priv->vbl_received);
41086 + return atomic_read_unchecked(&dev_priv->vbl_received);
41087 }
41088
41089 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41090 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41091
41092 status = VIA_READ(VIA_REG_INTERRUPT);
41093 if (status & VIA_IRQ_VBLANK_PENDING) {
41094 - atomic_inc(&dev_priv->vbl_received);
41095 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41096 + atomic_inc_unchecked(&dev_priv->vbl_received);
41097 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41098 do_gettimeofday(&cur_vblank);
41099 if (dev_priv->last_vblank_valid) {
41100 dev_priv->usec_per_vblank =
41101 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41102 dev_priv->last_vblank = cur_vblank;
41103 dev_priv->last_vblank_valid = 1;
41104 }
41105 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41106 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41107 DRM_DEBUG("US per vblank is: %u\n",
41108 dev_priv->usec_per_vblank);
41109 }
41110 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41111
41112 for (i = 0; i < dev_priv->num_irqs; ++i) {
41113 if (status & cur_irq->pending_mask) {
41114 - atomic_inc(&cur_irq->irq_received);
41115 + atomic_inc_unchecked(&cur_irq->irq_received);
41116 wake_up(&cur_irq->irq_queue);
41117 handled = 1;
41118 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41119 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41120 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41121 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41122 masks[irq][4]));
41123 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41124 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41125 } else {
41126 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41127 (((cur_irq_sequence =
41128 - atomic_read(&cur_irq->irq_received)) -
41129 + atomic_read_unchecked(&cur_irq->irq_received)) -
41130 *sequence) <= (1 << 23)));
41131 }
41132 *sequence = cur_irq_sequence;
41133 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41134 }
41135
41136 for (i = 0; i < dev_priv->num_irqs; ++i) {
41137 - atomic_set(&cur_irq->irq_received, 0);
41138 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41139 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41140 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41141 init_waitqueue_head(&cur_irq->irq_queue);
41142 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41143 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41144 case VIA_IRQ_RELATIVE:
41145 irqwait->request.sequence +=
41146 - atomic_read(&cur_irq->irq_received);
41147 + atomic_read_unchecked(&cur_irq->irq_received);
41148 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41149 case VIA_IRQ_ABSOLUTE:
41150 break;
41151 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41152 index 0783155..b29e18e 100644
41153 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41154 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41155 @@ -437,7 +437,7 @@ struct vmw_private {
41156 * Fencing and IRQs.
41157 */
41158
41159 - atomic_t marker_seq;
41160 + atomic_unchecked_t marker_seq;
41161 wait_queue_head_t fence_queue;
41162 wait_queue_head_t fifo_queue;
41163 int fence_queue_waiters; /* Protected by hw_mutex */
41164 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41165 index 6ccd993..618d592 100644
41166 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41167 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41168 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41169 (unsigned int) min,
41170 (unsigned int) fifo->capabilities);
41171
41172 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41173 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41174 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41175 vmw_marker_queue_init(&fifo->marker_queue);
41176 return vmw_fifo_send_fence(dev_priv, &dummy);
41177 @@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41178 if (reserveable)
41179 iowrite32(bytes, fifo_mem +
41180 SVGA_FIFO_RESERVED);
41181 - return fifo_mem + (next_cmd >> 2);
41182 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41183 } else {
41184 need_bounce = true;
41185 }
41186 @@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41187
41188 fm = vmw_fifo_reserve(dev_priv, bytes);
41189 if (unlikely(fm == NULL)) {
41190 - *seqno = atomic_read(&dev_priv->marker_seq);
41191 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41192 ret = -ENOMEM;
41193 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41194 false, 3*HZ);
41195 @@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41196 }
41197
41198 do {
41199 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41200 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41201 } while (*seqno == 0);
41202
41203 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41204 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41205 index b1273e8..9c274fd 100644
41206 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41207 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41208 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41209 }
41210
41211 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41212 - vmw_gmrid_man_init,
41213 - vmw_gmrid_man_takedown,
41214 - vmw_gmrid_man_get_node,
41215 - vmw_gmrid_man_put_node,
41216 - vmw_gmrid_man_debug
41217 + .init = vmw_gmrid_man_init,
41218 + .takedown = vmw_gmrid_man_takedown,
41219 + .get_node = vmw_gmrid_man_get_node,
41220 + .put_node = vmw_gmrid_man_put_node,
41221 + .debug = vmw_gmrid_man_debug
41222 };
41223 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41224 index 47b7094..698ba09 100644
41225 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41226 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41227 @@ -236,7 +236,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41228 int ret;
41229
41230 num_clips = arg->num_clips;
41231 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41232 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41233
41234 if (unlikely(num_clips == 0))
41235 return 0;
41236 @@ -320,7 +320,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41237 int ret;
41238
41239 num_clips = arg->num_clips;
41240 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41241 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41242
41243 if (unlikely(num_clips == 0))
41244 return 0;
41245 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41246 index 0c42376..6febe77 100644
41247 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41248 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41249 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41250 * emitted. Then the fence is stale and signaled.
41251 */
41252
41253 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41254 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41255 > VMW_FENCE_WRAP);
41256
41257 return ret;
41258 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41259
41260 if (fifo_idle)
41261 down_read(&fifo_state->rwsem);
41262 - signal_seq = atomic_read(&dev_priv->marker_seq);
41263 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41264 ret = 0;
41265
41266 for (;;) {
41267 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41268 index 8a8725c2..afed796 100644
41269 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41270 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41271 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41272 while (!vmw_lag_lt(queue, us)) {
41273 spin_lock(&queue->lock);
41274 if (list_empty(&queue->head))
41275 - seqno = atomic_read(&dev_priv->marker_seq);
41276 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41277 else {
41278 marker = list_first_entry(&queue->head,
41279 struct vmw_marker, head);
41280 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41281 index ec0ae2d..dc0780b 100644
41282 --- a/drivers/gpu/vga/vga_switcheroo.c
41283 +++ b/drivers/gpu/vga/vga_switcheroo.c
41284 @@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41285
41286 /* this version is for the case where the power switch is separate
41287 to the device being powered down. */
41288 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41289 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41290 {
41291 /* copy over all the bus versions */
41292 if (dev->bus && dev->bus->pm) {
41293 @@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41294 return ret;
41295 }
41296
41297 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41298 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41299 {
41300 /* copy over all the bus versions */
41301 if (dev->bus && dev->bus->pm) {
41302 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41303 index cc32a6f..02a4b1c 100644
41304 --- a/drivers/hid/hid-core.c
41305 +++ b/drivers/hid/hid-core.c
41306 @@ -2421,7 +2421,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41307
41308 int hid_add_device(struct hid_device *hdev)
41309 {
41310 - static atomic_t id = ATOMIC_INIT(0);
41311 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41312 int ret;
41313
41314 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41315 @@ -2455,7 +2455,7 @@ int hid_add_device(struct hid_device *hdev)
41316 /* XXX hack, any other cleaner solution after the driver core
41317 * is converted to allow more than 20 bytes as the device name? */
41318 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41319 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41320 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41321
41322 hid_debug_register(hdev, dev_name(&hdev->dev));
41323 ret = device_add(&hdev->dev);
41324 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41325 index c13fb5b..55a3802 100644
41326 --- a/drivers/hid/hid-wiimote-debug.c
41327 +++ b/drivers/hid/hid-wiimote-debug.c
41328 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41329 else if (size == 0)
41330 return -EIO;
41331
41332 - if (copy_to_user(u, buf, size))
41333 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
41334 return -EFAULT;
41335
41336 *off += size;
41337 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41338 index cedc6da..2c3da2a 100644
41339 --- a/drivers/hid/uhid.c
41340 +++ b/drivers/hid/uhid.c
41341 @@ -47,7 +47,7 @@ struct uhid_device {
41342 struct mutex report_lock;
41343 wait_queue_head_t report_wait;
41344 atomic_t report_done;
41345 - atomic_t report_id;
41346 + atomic_unchecked_t report_id;
41347 struct uhid_event report_buf;
41348 };
41349
41350 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41351
41352 spin_lock_irqsave(&uhid->qlock, flags);
41353 ev->type = UHID_FEATURE;
41354 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41355 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41356 ev->u.feature.rnum = rnum;
41357 ev->u.feature.rtype = report_type;
41358
41359 @@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41360 spin_lock_irqsave(&uhid->qlock, flags);
41361
41362 /* id for old report; drop it silently */
41363 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41364 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41365 goto unlock;
41366 if (atomic_read(&uhid->report_done))
41367 goto unlock;
41368 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41369 index 69ea36f..8dbf4bb 100644
41370 --- a/drivers/hv/channel.c
41371 +++ b/drivers/hv/channel.c
41372 @@ -364,8 +364,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41373 int ret = 0;
41374 int t;
41375
41376 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41377 - atomic_inc(&vmbus_connection.next_gpadl_handle);
41378 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41379 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41380
41381 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41382 if (ret)
41383 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41384 index bcb4950..61dba6c 100644
41385 --- a/drivers/hv/hv.c
41386 +++ b/drivers/hv/hv.c
41387 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41388 u64 output_address = (output) ? virt_to_phys(output) : 0;
41389 u32 output_address_hi = output_address >> 32;
41390 u32 output_address_lo = output_address & 0xFFFFFFFF;
41391 - void *hypercall_page = hv_context.hypercall_page;
41392 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41393
41394 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41395 "=a"(hv_status_lo) : "d" (control_hi),
41396 @@ -154,7 +154,7 @@ int hv_init(void)
41397 /* See if the hypercall page is already set */
41398 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41399
41400 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41401 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41402
41403 if (!virtaddr)
41404 goto cleanup;
41405 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41406 index 7e17a54..a50a33d 100644
41407 --- a/drivers/hv/hv_balloon.c
41408 +++ b/drivers/hv/hv_balloon.c
41409 @@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41410
41411 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41412 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41413 -static atomic_t trans_id = ATOMIC_INIT(0);
41414 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41415
41416 static int dm_ring_size = (5 * PAGE_SIZE);
41417
41418 @@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
41419 pr_info("Memory hot add failed\n");
41420
41421 dm->state = DM_INITIALIZED;
41422 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41423 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41424 vmbus_sendpacket(dm->dev->channel, &resp,
41425 sizeof(struct dm_hot_add_response),
41426 (unsigned long)NULL,
41427 @@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
41428 memset(&status, 0, sizeof(struct dm_status));
41429 status.hdr.type = DM_STATUS_REPORT;
41430 status.hdr.size = sizeof(struct dm_status);
41431 - status.hdr.trans_id = atomic_inc_return(&trans_id);
41432 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41433
41434 /*
41435 * The host expects the guest to report free memory.
41436 @@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
41437 * send the status. This can happen if we were interrupted
41438 * after we picked our transaction ID.
41439 */
41440 - if (status.hdr.trans_id != atomic_read(&trans_id))
41441 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41442 return;
41443
41444 vmbus_sendpacket(dm->dev->channel, &status,
41445 @@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
41446 */
41447
41448 do {
41449 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41450 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41451 ret = vmbus_sendpacket(dm_device.dev->channel,
41452 bl_resp,
41453 bl_resp->hdr.size,
41454 @@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41455
41456 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41457 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41458 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41459 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41460 resp.hdr.size = sizeof(struct dm_unballoon_response);
41461
41462 vmbus_sendpacket(dm_device.dev->channel, &resp,
41463 @@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41464 memset(&version_req, 0, sizeof(struct dm_version_request));
41465 version_req.hdr.type = DM_VERSION_REQUEST;
41466 version_req.hdr.size = sizeof(struct dm_version_request);
41467 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41468 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41469 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41470 version_req.is_last_attempt = 1;
41471
41472 @@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
41473 memset(&version_req, 0, sizeof(struct dm_version_request));
41474 version_req.hdr.type = DM_VERSION_REQUEST;
41475 version_req.hdr.size = sizeof(struct dm_version_request);
41476 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41477 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41478 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41479 version_req.is_last_attempt = 0;
41480
41481 @@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
41482 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41483 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41484 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41485 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41486 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41487
41488 cap_msg.caps.cap_bits.balloon = 1;
41489 cap_msg.caps.cap_bits.hot_add = 1;
41490 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41491 index e055176..c22ff1f 100644
41492 --- a/drivers/hv/hyperv_vmbus.h
41493 +++ b/drivers/hv/hyperv_vmbus.h
41494 @@ -602,7 +602,7 @@ enum vmbus_connect_state {
41495 struct vmbus_connection {
41496 enum vmbus_connect_state conn_state;
41497
41498 - atomic_t next_gpadl_handle;
41499 + atomic_unchecked_t next_gpadl_handle;
41500
41501 /*
41502 * Represents channel interrupts. Each bit position represents a
41503 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41504 index 077bb1b..d433d74 100644
41505 --- a/drivers/hv/vmbus_drv.c
41506 +++ b/drivers/hv/vmbus_drv.c
41507 @@ -844,10 +844,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41508 {
41509 int ret = 0;
41510
41511 - static atomic_t device_num = ATOMIC_INIT(0);
41512 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41513
41514 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41515 - atomic_inc_return(&device_num));
41516 + atomic_inc_return_unchecked(&device_num));
41517
41518 child_device_obj->device.bus = &hv_bus;
41519 child_device_obj->device.parent = &hv_acpi_dev->dev;
41520 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41521 index 579bdf9..75118b5 100644
41522 --- a/drivers/hwmon/acpi_power_meter.c
41523 +++ b/drivers/hwmon/acpi_power_meter.c
41524 @@ -116,7 +116,7 @@ struct sensor_template {
41525 struct device_attribute *devattr,
41526 const char *buf, size_t count);
41527 int index;
41528 -};
41529 +} __do_const;
41530
41531 /* Averaging interval */
41532 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41533 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41534 struct sensor_template *attrs)
41535 {
41536 struct device *dev = &resource->acpi_dev->dev;
41537 - struct sensor_device_attribute *sensors =
41538 + sensor_device_attribute_no_const *sensors =
41539 &resource->sensors[resource->num_sensors];
41540 int res = 0;
41541
41542 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41543 index 3288f13..71cfb4e 100644
41544 --- a/drivers/hwmon/applesmc.c
41545 +++ b/drivers/hwmon/applesmc.c
41546 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41547 {
41548 struct applesmc_node_group *grp;
41549 struct applesmc_dev_attr *node;
41550 - struct attribute *attr;
41551 + attribute_no_const *attr;
41552 int ret, i;
41553
41554 for (grp = groups; grp->format; grp++) {
41555 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41556 index ae208f6..48b6c5b 100644
41557 --- a/drivers/hwmon/asus_atk0110.c
41558 +++ b/drivers/hwmon/asus_atk0110.c
41559 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41560 struct atk_sensor_data {
41561 struct list_head list;
41562 struct atk_data *data;
41563 - struct device_attribute label_attr;
41564 - struct device_attribute input_attr;
41565 - struct device_attribute limit1_attr;
41566 - struct device_attribute limit2_attr;
41567 + device_attribute_no_const label_attr;
41568 + device_attribute_no_const input_attr;
41569 + device_attribute_no_const limit1_attr;
41570 + device_attribute_no_const limit2_attr;
41571 char label_attr_name[ATTR_NAME_SIZE];
41572 char input_attr_name[ATTR_NAME_SIZE];
41573 char limit1_attr_name[ATTR_NAME_SIZE];
41574 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
41575 static struct device_attribute atk_name_attr =
41576 __ATTR(name, 0444, atk_name_show, NULL);
41577
41578 -static void atk_init_attribute(struct device_attribute *attr, char *name,
41579 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41580 sysfs_show_func show)
41581 {
41582 sysfs_attr_init(&attr->attr);
41583 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41584 index bbb0b0d..9fe1332 100644
41585 --- a/drivers/hwmon/coretemp.c
41586 +++ b/drivers/hwmon/coretemp.c
41587 @@ -823,7 +823,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41588 return NOTIFY_OK;
41589 }
41590
41591 -static struct notifier_block coretemp_cpu_notifier __refdata = {
41592 +static struct notifier_block coretemp_cpu_notifier = {
41593 .notifier_call = coretemp_cpu_callback,
41594 };
41595
41596 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41597 index 632f1dc..57e6a58 100644
41598 --- a/drivers/hwmon/ibmaem.c
41599 +++ b/drivers/hwmon/ibmaem.c
41600 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41601 struct aem_rw_sensor_template *rw)
41602 {
41603 struct device *dev = &data->pdev->dev;
41604 - struct sensor_device_attribute *sensors = data->sensors;
41605 + sensor_device_attribute_no_const *sensors = data->sensors;
41606 int err;
41607
41608 /* Set up read-only sensors */
41609 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41610 index 708081b..fe2d4ab 100644
41611 --- a/drivers/hwmon/iio_hwmon.c
41612 +++ b/drivers/hwmon/iio_hwmon.c
41613 @@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41614 {
41615 struct device *dev = &pdev->dev;
41616 struct iio_hwmon_state *st;
41617 - struct sensor_device_attribute *a;
41618 + sensor_device_attribute_no_const *a;
41619 int ret, i;
41620 int in_i = 1, temp_i = 1, curr_i = 1;
41621 enum iio_chan_type type;
41622 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41623 index 38d5a63..cf2c2ea 100644
41624 --- a/drivers/hwmon/nct6775.c
41625 +++ b/drivers/hwmon/nct6775.c
41626 @@ -944,10 +944,10 @@ static struct attribute_group *
41627 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41628 int repeat)
41629 {
41630 - struct attribute_group *group;
41631 + attribute_group_no_const *group;
41632 struct sensor_device_attr_u *su;
41633 - struct sensor_device_attribute *a;
41634 - struct sensor_device_attribute_2 *a2;
41635 + sensor_device_attribute_no_const *a;
41636 + sensor_device_attribute_2_no_const *a2;
41637 struct attribute **attrs;
41638 struct sensor_device_template **t;
41639 int i, count;
41640 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41641 index 291d11f..3f0dbbd 100644
41642 --- a/drivers/hwmon/pmbus/pmbus_core.c
41643 +++ b/drivers/hwmon/pmbus/pmbus_core.c
41644 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41645 return 0;
41646 }
41647
41648 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41649 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41650 const char *name,
41651 umode_t mode,
41652 ssize_t (*show)(struct device *dev,
41653 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41654 dev_attr->store = store;
41655 }
41656
41657 -static void pmbus_attr_init(struct sensor_device_attribute *a,
41658 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41659 const char *name,
41660 umode_t mode,
41661 ssize_t (*show)(struct device *dev,
41662 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41663 u16 reg, u8 mask)
41664 {
41665 struct pmbus_boolean *boolean;
41666 - struct sensor_device_attribute *a;
41667 + sensor_device_attribute_no_const *a;
41668
41669 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41670 if (!boolean)
41671 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41672 bool update, bool readonly)
41673 {
41674 struct pmbus_sensor *sensor;
41675 - struct device_attribute *a;
41676 + device_attribute_no_const *a;
41677
41678 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41679 if (!sensor)
41680 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41681 const char *lstring, int index)
41682 {
41683 struct pmbus_label *label;
41684 - struct device_attribute *a;
41685 + device_attribute_no_const *a;
41686
41687 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41688 if (!label)
41689 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41690 index 97cd45a..ac54d8b 100644
41691 --- a/drivers/hwmon/sht15.c
41692 +++ b/drivers/hwmon/sht15.c
41693 @@ -169,7 +169,7 @@ struct sht15_data {
41694 int supply_uv;
41695 bool supply_uv_valid;
41696 struct work_struct update_supply_work;
41697 - atomic_t interrupt_handled;
41698 + atomic_unchecked_t interrupt_handled;
41699 };
41700
41701 /**
41702 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41703 ret = gpio_direction_input(data->pdata->gpio_data);
41704 if (ret)
41705 return ret;
41706 - atomic_set(&data->interrupt_handled, 0);
41707 + atomic_set_unchecked(&data->interrupt_handled, 0);
41708
41709 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41710 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41711 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41712 /* Only relevant if the interrupt hasn't occurred. */
41713 - if (!atomic_read(&data->interrupt_handled))
41714 + if (!atomic_read_unchecked(&data->interrupt_handled))
41715 schedule_work(&data->read_work);
41716 }
41717 ret = wait_event_timeout(data->wait_queue,
41718 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41719
41720 /* First disable the interrupt */
41721 disable_irq_nosync(irq);
41722 - atomic_inc(&data->interrupt_handled);
41723 + atomic_inc_unchecked(&data->interrupt_handled);
41724 /* Then schedule a reading work struct */
41725 if (data->state != SHT15_READING_NOTHING)
41726 schedule_work(&data->read_work);
41727 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41728 * If not, then start the interrupt again - care here as could
41729 * have gone low in meantime so verify it hasn't!
41730 */
41731 - atomic_set(&data->interrupt_handled, 0);
41732 + atomic_set_unchecked(&data->interrupt_handled, 0);
41733 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41734 /* If still not occurred or another handler was scheduled */
41735 if (gpio_get_value(data->pdata->gpio_data)
41736 - || atomic_read(&data->interrupt_handled))
41737 + || atomic_read_unchecked(&data->interrupt_handled))
41738 return;
41739 }
41740
41741 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41742 index 38944e9..ae9e5ed 100644
41743 --- a/drivers/hwmon/via-cputemp.c
41744 +++ b/drivers/hwmon/via-cputemp.c
41745 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41746 return NOTIFY_OK;
41747 }
41748
41749 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41750 +static struct notifier_block via_cputemp_cpu_notifier = {
41751 .notifier_call = via_cputemp_cpu_callback,
41752 };
41753
41754 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41755 index 41fc683..a39cfea 100644
41756 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
41757 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41758 @@ -43,7 +43,7 @@
41759 extern struct i2c_adapter amd756_smbus;
41760
41761 static struct i2c_adapter *s4882_adapter;
41762 -static struct i2c_algorithm *s4882_algo;
41763 +static i2c_algorithm_no_const *s4882_algo;
41764
41765 /* Wrapper access functions for multiplexed SMBus */
41766 static DEFINE_MUTEX(amd756_lock);
41767 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41768 index 721f7eb..0fd2a09 100644
41769 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
41770 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41771 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41772 /* usb layer */
41773
41774 /* Send command to device, and get response. */
41775 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41776 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41777 {
41778 int ret = 0;
41779 int actual;
41780 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41781 index b170bdf..3c76427 100644
41782 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41783 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41784 @@ -41,7 +41,7 @@
41785 extern struct i2c_adapter *nforce2_smbus;
41786
41787 static struct i2c_adapter *s4985_adapter;
41788 -static struct i2c_algorithm *s4985_algo;
41789 +static i2c_algorithm_no_const *s4985_algo;
41790
41791 /* Wrapper access functions for multiplexed SMBus */
41792 static DEFINE_MUTEX(nforce2_lock);
41793 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41794 index 80b47e8..1a6040d9 100644
41795 --- a/drivers/i2c/i2c-dev.c
41796 +++ b/drivers/i2c/i2c-dev.c
41797 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41798 break;
41799 }
41800
41801 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41802 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41803 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41804 if (IS_ERR(rdwr_pa[i].buf)) {
41805 res = PTR_ERR(rdwr_pa[i].buf);
41806 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41807 index 0b510ba..4fbb5085 100644
41808 --- a/drivers/ide/ide-cd.c
41809 +++ b/drivers/ide/ide-cd.c
41810 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41811 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41812 if ((unsigned long)buf & alignment
41813 || blk_rq_bytes(rq) & q->dma_pad_mask
41814 - || object_is_on_stack(buf))
41815 + || object_starts_on_stack(buf))
41816 drive->dma = 0;
41817 }
41818 }
41819 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41820 index acc911a..8700c3c 100644
41821 --- a/drivers/iio/industrialio-core.c
41822 +++ b/drivers/iio/industrialio-core.c
41823 @@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41824 }
41825
41826 static
41827 -int __iio_device_attr_init(struct device_attribute *dev_attr,
41828 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41829 const char *postfix,
41830 struct iio_chan_spec const *chan,
41831 ssize_t (*readfunc)(struct device *dev,
41832 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41833 index 0601b9d..e9dc455 100644
41834 --- a/drivers/infiniband/core/cm.c
41835 +++ b/drivers/infiniband/core/cm.c
41836 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41837
41838 struct cm_counter_group {
41839 struct kobject obj;
41840 - atomic_long_t counter[CM_ATTR_COUNT];
41841 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41842 };
41843
41844 struct cm_counter_attribute {
41845 @@ -1415,7 +1415,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41846 struct ib_mad_send_buf *msg = NULL;
41847 int ret;
41848
41849 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41850 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41851 counter[CM_REQ_COUNTER]);
41852
41853 /* Quick state check to discard duplicate REQs. */
41854 @@ -1802,7 +1802,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41855 if (!cm_id_priv)
41856 return;
41857
41858 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41859 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41860 counter[CM_REP_COUNTER]);
41861 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41862 if (ret)
41863 @@ -1969,7 +1969,7 @@ static int cm_rtu_handler(struct cm_work *work)
41864 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41865 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41866 spin_unlock_irq(&cm_id_priv->lock);
41867 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41868 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41869 counter[CM_RTU_COUNTER]);
41870 goto out;
41871 }
41872 @@ -2152,7 +2152,7 @@ static int cm_dreq_handler(struct cm_work *work)
41873 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41874 dreq_msg->local_comm_id);
41875 if (!cm_id_priv) {
41876 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41877 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41878 counter[CM_DREQ_COUNTER]);
41879 cm_issue_drep(work->port, work->mad_recv_wc);
41880 return -EINVAL;
41881 @@ -2177,7 +2177,7 @@ static int cm_dreq_handler(struct cm_work *work)
41882 case IB_CM_MRA_REP_RCVD:
41883 break;
41884 case IB_CM_TIMEWAIT:
41885 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41886 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41887 counter[CM_DREQ_COUNTER]);
41888 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41889 goto unlock;
41890 @@ -2191,7 +2191,7 @@ static int cm_dreq_handler(struct cm_work *work)
41891 cm_free_msg(msg);
41892 goto deref;
41893 case IB_CM_DREQ_RCVD:
41894 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41895 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41896 counter[CM_DREQ_COUNTER]);
41897 goto unlock;
41898 default:
41899 @@ -2558,7 +2558,7 @@ static int cm_mra_handler(struct cm_work *work)
41900 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41901 cm_id_priv->msg, timeout)) {
41902 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41903 - atomic_long_inc(&work->port->
41904 + atomic_long_inc_unchecked(&work->port->
41905 counter_group[CM_RECV_DUPLICATES].
41906 counter[CM_MRA_COUNTER]);
41907 goto out;
41908 @@ -2567,7 +2567,7 @@ static int cm_mra_handler(struct cm_work *work)
41909 break;
41910 case IB_CM_MRA_REQ_RCVD:
41911 case IB_CM_MRA_REP_RCVD:
41912 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41913 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41914 counter[CM_MRA_COUNTER]);
41915 /* fall through */
41916 default:
41917 @@ -2729,7 +2729,7 @@ static int cm_lap_handler(struct cm_work *work)
41918 case IB_CM_LAP_IDLE:
41919 break;
41920 case IB_CM_MRA_LAP_SENT:
41921 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41922 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41923 counter[CM_LAP_COUNTER]);
41924 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41925 goto unlock;
41926 @@ -2745,7 +2745,7 @@ static int cm_lap_handler(struct cm_work *work)
41927 cm_free_msg(msg);
41928 goto deref;
41929 case IB_CM_LAP_RCVD:
41930 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41931 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41932 counter[CM_LAP_COUNTER]);
41933 goto unlock;
41934 default:
41935 @@ -3029,7 +3029,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
41936 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
41937 if (cur_cm_id_priv) {
41938 spin_unlock_irq(&cm.lock);
41939 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41940 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41941 counter[CM_SIDR_REQ_COUNTER]);
41942 goto out; /* Duplicate message. */
41943 }
41944 @@ -3241,10 +3241,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
41945 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
41946 msg->retries = 1;
41947
41948 - atomic_long_add(1 + msg->retries,
41949 + atomic_long_add_unchecked(1 + msg->retries,
41950 &port->counter_group[CM_XMIT].counter[attr_index]);
41951 if (msg->retries)
41952 - atomic_long_add(msg->retries,
41953 + atomic_long_add_unchecked(msg->retries,
41954 &port->counter_group[CM_XMIT_RETRIES].
41955 counter[attr_index]);
41956
41957 @@ -3454,7 +3454,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
41958 }
41959
41960 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
41961 - atomic_long_inc(&port->counter_group[CM_RECV].
41962 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
41963 counter[attr_id - CM_ATTR_ID_OFFSET]);
41964
41965 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
41966 @@ -3685,7 +3685,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
41967 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
41968
41969 return sprintf(buf, "%ld\n",
41970 - atomic_long_read(&group->counter[cm_attr->index]));
41971 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
41972 }
41973
41974 static const struct sysfs_ops cm_counter_ops = {
41975 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
41976 index 9f5ad7c..588cd84 100644
41977 --- a/drivers/infiniband/core/fmr_pool.c
41978 +++ b/drivers/infiniband/core/fmr_pool.c
41979 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
41980
41981 struct task_struct *thread;
41982
41983 - atomic_t req_ser;
41984 - atomic_t flush_ser;
41985 + atomic_unchecked_t req_ser;
41986 + atomic_unchecked_t flush_ser;
41987
41988 wait_queue_head_t force_wait;
41989 };
41990 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41991 struct ib_fmr_pool *pool = pool_ptr;
41992
41993 do {
41994 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
41995 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
41996 ib_fmr_batch_release(pool);
41997
41998 - atomic_inc(&pool->flush_ser);
41999 + atomic_inc_unchecked(&pool->flush_ser);
42000 wake_up_interruptible(&pool->force_wait);
42001
42002 if (pool->flush_function)
42003 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42004 }
42005
42006 set_current_state(TASK_INTERRUPTIBLE);
42007 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42008 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42009 !kthread_should_stop())
42010 schedule();
42011 __set_current_state(TASK_RUNNING);
42012 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42013 pool->dirty_watermark = params->dirty_watermark;
42014 pool->dirty_len = 0;
42015 spin_lock_init(&pool->pool_lock);
42016 - atomic_set(&pool->req_ser, 0);
42017 - atomic_set(&pool->flush_ser, 0);
42018 + atomic_set_unchecked(&pool->req_ser, 0);
42019 + atomic_set_unchecked(&pool->flush_ser, 0);
42020 init_waitqueue_head(&pool->force_wait);
42021
42022 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42023 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42024 }
42025 spin_unlock_irq(&pool->pool_lock);
42026
42027 - serial = atomic_inc_return(&pool->req_ser);
42028 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42029 wake_up_process(pool->thread);
42030
42031 if (wait_event_interruptible(pool->force_wait,
42032 - atomic_read(&pool->flush_ser) - serial >= 0))
42033 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42034 return -EINTR;
42035
42036 return 0;
42037 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42038 } else {
42039 list_add_tail(&fmr->list, &pool->dirty_list);
42040 if (++pool->dirty_len >= pool->dirty_watermark) {
42041 - atomic_inc(&pool->req_ser);
42042 + atomic_inc_unchecked(&pool->req_ser);
42043 wake_up_process(pool->thread);
42044 }
42045 }
42046 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42047 index 41b1195..27971a0 100644
42048 --- a/drivers/infiniband/hw/cxgb4/mem.c
42049 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42050 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42051 int err;
42052 struct fw_ri_tpte tpt;
42053 u32 stag_idx;
42054 - static atomic_t key;
42055 + static atomic_unchecked_t key;
42056
42057 if (c4iw_fatal_error(rdev))
42058 return -EIO;
42059 @@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42060 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42061 rdev->stats.stag.max = rdev->stats.stag.cur;
42062 mutex_unlock(&rdev->stats.lock);
42063 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42064 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42065 }
42066 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42067 __func__, stag_state, type, pdid, stag_idx);
42068 diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42069 index 644c2c7..ecf0879 100644
42070 --- a/drivers/infiniband/hw/ipath/ipath_dma.c
42071 +++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42072 @@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42073 }
42074
42075 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42076 - ipath_mapping_error,
42077 - ipath_dma_map_single,
42078 - ipath_dma_unmap_single,
42079 - ipath_dma_map_page,
42080 - ipath_dma_unmap_page,
42081 - ipath_map_sg,
42082 - ipath_unmap_sg,
42083 - ipath_sg_dma_address,
42084 - ipath_sg_dma_len,
42085 - ipath_sync_single_for_cpu,
42086 - ipath_sync_single_for_device,
42087 - ipath_dma_alloc_coherent,
42088 - ipath_dma_free_coherent
42089 + .mapping_error = ipath_mapping_error,
42090 + .map_single = ipath_dma_map_single,
42091 + .unmap_single = ipath_dma_unmap_single,
42092 + .map_page = ipath_dma_map_page,
42093 + .unmap_page = ipath_dma_unmap_page,
42094 + .map_sg = ipath_map_sg,
42095 + .unmap_sg = ipath_unmap_sg,
42096 + .dma_address = ipath_sg_dma_address,
42097 + .dma_len = ipath_sg_dma_len,
42098 + .sync_single_for_cpu = ipath_sync_single_for_cpu,
42099 + .sync_single_for_device = ipath_sync_single_for_device,
42100 + .alloc_coherent = ipath_dma_alloc_coherent,
42101 + .free_coherent = ipath_dma_free_coherent
42102 };
42103 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42104 index 79b3dbc..96e5fcc 100644
42105 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42106 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42107 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42108 struct ib_atomic_eth *ateth;
42109 struct ipath_ack_entry *e;
42110 u64 vaddr;
42111 - atomic64_t *maddr;
42112 + atomic64_unchecked_t *maddr;
42113 u64 sdata;
42114 u32 rkey;
42115 u8 next;
42116 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42117 IB_ACCESS_REMOTE_ATOMIC)))
42118 goto nack_acc_unlck;
42119 /* Perform atomic OP and save result. */
42120 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42121 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42122 sdata = be64_to_cpu(ateth->swap_data);
42123 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42124 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42125 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42126 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42127 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42128 be64_to_cpu(ateth->compare_data),
42129 sdata);
42130 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42131 index 1f95bba..9530f87 100644
42132 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42133 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42134 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42135 unsigned long flags;
42136 struct ib_wc wc;
42137 u64 sdata;
42138 - atomic64_t *maddr;
42139 + atomic64_unchecked_t *maddr;
42140 enum ib_wc_status send_status;
42141
42142 /*
42143 @@ -382,11 +382,11 @@ again:
42144 IB_ACCESS_REMOTE_ATOMIC)))
42145 goto acc_err;
42146 /* Perform atomic OP and save result. */
42147 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42148 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42149 sdata = wqe->wr.wr.atomic.compare_add;
42150 *(u64 *) sqp->s_sge.sge.vaddr =
42151 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42152 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42153 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42154 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42155 sdata, wqe->wr.wr.atomic.swap);
42156 goto send_comp;
42157 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42158 index f2a3f48..673ec79 100644
42159 --- a/drivers/infiniband/hw/mlx4/mad.c
42160 +++ b/drivers/infiniband/hw/mlx4/mad.c
42161 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42162
42163 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42164 {
42165 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42166 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42167 cpu_to_be64(0xff00000000000000LL);
42168 }
42169
42170 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42171 index 25b2cdf..099ff97 100644
42172 --- a/drivers/infiniband/hw/mlx4/mcg.c
42173 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42174 @@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42175 {
42176 char name[20];
42177
42178 - atomic_set(&ctx->tid, 0);
42179 + atomic_set_unchecked(&ctx->tid, 0);
42180 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42181 ctx->mcg_wq = create_singlethread_workqueue(name);
42182 if (!ctx->mcg_wq)
42183 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42184 index a230683..3723f2d 100644
42185 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42186 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42187 @@ -408,7 +408,7 @@ struct mlx4_ib_demux_ctx {
42188 struct list_head mcg_mgid0_list;
42189 struct workqueue_struct *mcg_wq;
42190 struct mlx4_ib_demux_pv_ctx **tun;
42191 - atomic_t tid;
42192 + atomic_unchecked_t tid;
42193 int flushing; /* flushing the work queue */
42194 };
42195
42196 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42197 index 9d3e5c1..6f166df 100644
42198 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42199 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42200 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42201 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42202 }
42203
42204 -int mthca_QUERY_FW(struct mthca_dev *dev)
42205 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42206 {
42207 struct mthca_mailbox *mailbox;
42208 u32 *outbox;
42209 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42210 CMD_TIME_CLASS_B);
42211 }
42212
42213 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42214 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42215 int num_mtt)
42216 {
42217 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42218 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42219 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42220 }
42221
42222 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42223 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42224 int eq_num)
42225 {
42226 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42227 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42228 CMD_TIME_CLASS_B);
42229 }
42230
42231 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42232 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42233 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42234 void *in_mad, void *response_mad)
42235 {
42236 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42237 index 87897b9..7e79542 100644
42238 --- a/drivers/infiniband/hw/mthca/mthca_main.c
42239 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
42240 @@ -692,7 +692,7 @@ err_close:
42241 return err;
42242 }
42243
42244 -static int mthca_setup_hca(struct mthca_dev *dev)
42245 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42246 {
42247 int err;
42248
42249 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42250 index ed9a989..6aa5dc2 100644
42251 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
42252 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42253 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42254 * through the bitmaps)
42255 */
42256
42257 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42258 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42259 {
42260 int o;
42261 int m;
42262 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42263 return key;
42264 }
42265
42266 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42267 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42268 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42269 {
42270 struct mthca_mailbox *mailbox;
42271 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42272 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42273 }
42274
42275 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42276 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42277 u64 *buffer_list, int buffer_size_shift,
42278 int list_len, u64 iova, u64 total_size,
42279 u32 access, struct mthca_mr *mr)
42280 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42281 index 5b71d43..35a9e14 100644
42282 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
42283 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42284 @@ -763,7 +763,7 @@ unlock:
42285 return 0;
42286 }
42287
42288 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42289 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42290 {
42291 struct mthca_dev *dev = to_mdev(ibcq->device);
42292 struct mthca_cq *cq = to_mcq(ibcq);
42293 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42294 index 353c7b0..c6ce921 100644
42295 --- a/drivers/infiniband/hw/nes/nes.c
42296 +++ b/drivers/infiniband/hw/nes/nes.c
42297 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42298 LIST_HEAD(nes_adapter_list);
42299 static LIST_HEAD(nes_dev_list);
42300
42301 -atomic_t qps_destroyed;
42302 +atomic_unchecked_t qps_destroyed;
42303
42304 static unsigned int ee_flsh_adapter;
42305 static unsigned int sysfs_nonidx_addr;
42306 @@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42307 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42308 struct nes_adapter *nesadapter = nesdev->nesadapter;
42309
42310 - atomic_inc(&qps_destroyed);
42311 + atomic_inc_unchecked(&qps_destroyed);
42312
42313 /* Free the control structures */
42314
42315 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42316 index 33cc589..3bd6538 100644
42317 --- a/drivers/infiniband/hw/nes/nes.h
42318 +++ b/drivers/infiniband/hw/nes/nes.h
42319 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42320 extern unsigned int wqm_quanta;
42321 extern struct list_head nes_adapter_list;
42322
42323 -extern atomic_t cm_connects;
42324 -extern atomic_t cm_accepts;
42325 -extern atomic_t cm_disconnects;
42326 -extern atomic_t cm_closes;
42327 -extern atomic_t cm_connecteds;
42328 -extern atomic_t cm_connect_reqs;
42329 -extern atomic_t cm_rejects;
42330 -extern atomic_t mod_qp_timouts;
42331 -extern atomic_t qps_created;
42332 -extern atomic_t qps_destroyed;
42333 -extern atomic_t sw_qps_destroyed;
42334 +extern atomic_unchecked_t cm_connects;
42335 +extern atomic_unchecked_t cm_accepts;
42336 +extern atomic_unchecked_t cm_disconnects;
42337 +extern atomic_unchecked_t cm_closes;
42338 +extern atomic_unchecked_t cm_connecteds;
42339 +extern atomic_unchecked_t cm_connect_reqs;
42340 +extern atomic_unchecked_t cm_rejects;
42341 +extern atomic_unchecked_t mod_qp_timouts;
42342 +extern atomic_unchecked_t qps_created;
42343 +extern atomic_unchecked_t qps_destroyed;
42344 +extern atomic_unchecked_t sw_qps_destroyed;
42345 extern u32 mh_detected;
42346 extern u32 mh_pauses_sent;
42347 extern u32 cm_packets_sent;
42348 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42349 extern u32 cm_packets_received;
42350 extern u32 cm_packets_dropped;
42351 extern u32 cm_packets_retrans;
42352 -extern atomic_t cm_listens_created;
42353 -extern atomic_t cm_listens_destroyed;
42354 +extern atomic_unchecked_t cm_listens_created;
42355 +extern atomic_unchecked_t cm_listens_destroyed;
42356 extern u32 cm_backlog_drops;
42357 -extern atomic_t cm_loopbacks;
42358 -extern atomic_t cm_nodes_created;
42359 -extern atomic_t cm_nodes_destroyed;
42360 -extern atomic_t cm_accel_dropped_pkts;
42361 -extern atomic_t cm_resets_recvd;
42362 -extern atomic_t pau_qps_created;
42363 -extern atomic_t pau_qps_destroyed;
42364 +extern atomic_unchecked_t cm_loopbacks;
42365 +extern atomic_unchecked_t cm_nodes_created;
42366 +extern atomic_unchecked_t cm_nodes_destroyed;
42367 +extern atomic_unchecked_t cm_accel_dropped_pkts;
42368 +extern atomic_unchecked_t cm_resets_recvd;
42369 +extern atomic_unchecked_t pau_qps_created;
42370 +extern atomic_unchecked_t pau_qps_destroyed;
42371
42372 extern u32 int_mod_timer_init;
42373 extern u32 int_mod_cq_depth_256;
42374 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42375 index 9c9f2f5..2559190 100644
42376 --- a/drivers/infiniband/hw/nes/nes_cm.c
42377 +++ b/drivers/infiniband/hw/nes/nes_cm.c
42378 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42379 u32 cm_packets_retrans;
42380 u32 cm_packets_created;
42381 u32 cm_packets_received;
42382 -atomic_t cm_listens_created;
42383 -atomic_t cm_listens_destroyed;
42384 +atomic_unchecked_t cm_listens_created;
42385 +atomic_unchecked_t cm_listens_destroyed;
42386 u32 cm_backlog_drops;
42387 -atomic_t cm_loopbacks;
42388 -atomic_t cm_nodes_created;
42389 -atomic_t cm_nodes_destroyed;
42390 -atomic_t cm_accel_dropped_pkts;
42391 -atomic_t cm_resets_recvd;
42392 +atomic_unchecked_t cm_loopbacks;
42393 +atomic_unchecked_t cm_nodes_created;
42394 +atomic_unchecked_t cm_nodes_destroyed;
42395 +atomic_unchecked_t cm_accel_dropped_pkts;
42396 +atomic_unchecked_t cm_resets_recvd;
42397
42398 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42399 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42400 @@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42401 /* instance of function pointers for client API */
42402 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42403 static struct nes_cm_ops nes_cm_api = {
42404 - mini_cm_accelerated,
42405 - mini_cm_listen,
42406 - mini_cm_del_listen,
42407 - mini_cm_connect,
42408 - mini_cm_close,
42409 - mini_cm_accept,
42410 - mini_cm_reject,
42411 - mini_cm_recv_pkt,
42412 - mini_cm_dealloc_core,
42413 - mini_cm_get,
42414 - mini_cm_set
42415 + .accelerated = mini_cm_accelerated,
42416 + .listen = mini_cm_listen,
42417 + .stop_listener = mini_cm_del_listen,
42418 + .connect = mini_cm_connect,
42419 + .close = mini_cm_close,
42420 + .accept = mini_cm_accept,
42421 + .reject = mini_cm_reject,
42422 + .recv_pkt = mini_cm_recv_pkt,
42423 + .destroy_cm_core = mini_cm_dealloc_core,
42424 + .get = mini_cm_get,
42425 + .set = mini_cm_set
42426 };
42427
42428 static struct nes_cm_core *g_cm_core;
42429
42430 -atomic_t cm_connects;
42431 -atomic_t cm_accepts;
42432 -atomic_t cm_disconnects;
42433 -atomic_t cm_closes;
42434 -atomic_t cm_connecteds;
42435 -atomic_t cm_connect_reqs;
42436 -atomic_t cm_rejects;
42437 +atomic_unchecked_t cm_connects;
42438 +atomic_unchecked_t cm_accepts;
42439 +atomic_unchecked_t cm_disconnects;
42440 +atomic_unchecked_t cm_closes;
42441 +atomic_unchecked_t cm_connecteds;
42442 +atomic_unchecked_t cm_connect_reqs;
42443 +atomic_unchecked_t cm_rejects;
42444
42445 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42446 {
42447 @@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42448 kfree(listener);
42449 listener = NULL;
42450 ret = 0;
42451 - atomic_inc(&cm_listens_destroyed);
42452 + atomic_inc_unchecked(&cm_listens_destroyed);
42453 } else {
42454 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42455 }
42456 @@ -1465,7 +1465,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42457 cm_node->rem_mac);
42458
42459 add_hte_node(cm_core, cm_node);
42460 - atomic_inc(&cm_nodes_created);
42461 + atomic_inc_unchecked(&cm_nodes_created);
42462
42463 return cm_node;
42464 }
42465 @@ -1523,7 +1523,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42466 }
42467
42468 atomic_dec(&cm_core->node_cnt);
42469 - atomic_inc(&cm_nodes_destroyed);
42470 + atomic_inc_unchecked(&cm_nodes_destroyed);
42471 nesqp = cm_node->nesqp;
42472 if (nesqp) {
42473 nesqp->cm_node = NULL;
42474 @@ -1587,7 +1587,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42475
42476 static void drop_packet(struct sk_buff *skb)
42477 {
42478 - atomic_inc(&cm_accel_dropped_pkts);
42479 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42480 dev_kfree_skb_any(skb);
42481 }
42482
42483 @@ -1650,7 +1650,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42484 {
42485
42486 int reset = 0; /* whether to send reset in case of err.. */
42487 - atomic_inc(&cm_resets_recvd);
42488 + atomic_inc_unchecked(&cm_resets_recvd);
42489 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42490 " refcnt=%d\n", cm_node, cm_node->state,
42491 atomic_read(&cm_node->ref_count));
42492 @@ -2291,7 +2291,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42493 rem_ref_cm_node(cm_node->cm_core, cm_node);
42494 return NULL;
42495 }
42496 - atomic_inc(&cm_loopbacks);
42497 + atomic_inc_unchecked(&cm_loopbacks);
42498 loopbackremotenode->loopbackpartner = cm_node;
42499 loopbackremotenode->tcp_cntxt.rcv_wscale =
42500 NES_CM_DEFAULT_RCV_WND_SCALE;
42501 @@ -2566,7 +2566,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42502 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42503 else {
42504 rem_ref_cm_node(cm_core, cm_node);
42505 - atomic_inc(&cm_accel_dropped_pkts);
42506 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42507 dev_kfree_skb_any(skb);
42508 }
42509 break;
42510 @@ -2874,7 +2874,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42511
42512 if ((cm_id) && (cm_id->event_handler)) {
42513 if (issue_disconn) {
42514 - atomic_inc(&cm_disconnects);
42515 + atomic_inc_unchecked(&cm_disconnects);
42516 cm_event.event = IW_CM_EVENT_DISCONNECT;
42517 cm_event.status = disconn_status;
42518 cm_event.local_addr = cm_id->local_addr;
42519 @@ -2896,7 +2896,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42520 }
42521
42522 if (issue_close) {
42523 - atomic_inc(&cm_closes);
42524 + atomic_inc_unchecked(&cm_closes);
42525 nes_disconnect(nesqp, 1);
42526
42527 cm_id->provider_data = nesqp;
42528 @@ -3034,7 +3034,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42529
42530 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42531 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42532 - atomic_inc(&cm_accepts);
42533 + atomic_inc_unchecked(&cm_accepts);
42534
42535 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42536 netdev_refcnt_read(nesvnic->netdev));
42537 @@ -3223,7 +3223,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42538 struct nes_cm_core *cm_core;
42539 u8 *start_buff;
42540
42541 - atomic_inc(&cm_rejects);
42542 + atomic_inc_unchecked(&cm_rejects);
42543 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42544 loopback = cm_node->loopbackpartner;
42545 cm_core = cm_node->cm_core;
42546 @@ -3285,7 +3285,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42547 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42548 ntohs(laddr->sin_port));
42549
42550 - atomic_inc(&cm_connects);
42551 + atomic_inc_unchecked(&cm_connects);
42552 nesqp->active_conn = 1;
42553
42554 /* cache the cm_id in the qp */
42555 @@ -3397,7 +3397,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42556 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42557 return err;
42558 }
42559 - atomic_inc(&cm_listens_created);
42560 + atomic_inc_unchecked(&cm_listens_created);
42561 }
42562
42563 cm_id->add_ref(cm_id);
42564 @@ -3504,7 +3504,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42565
42566 if (nesqp->destroyed)
42567 return;
42568 - atomic_inc(&cm_connecteds);
42569 + atomic_inc_unchecked(&cm_connecteds);
42570 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42571 " local port 0x%04X. jiffies = %lu.\n",
42572 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42573 @@ -3685,7 +3685,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42574
42575 cm_id->add_ref(cm_id);
42576 ret = cm_id->event_handler(cm_id, &cm_event);
42577 - atomic_inc(&cm_closes);
42578 + atomic_inc_unchecked(&cm_closes);
42579 cm_event.event = IW_CM_EVENT_CLOSE;
42580 cm_event.status = 0;
42581 cm_event.provider_data = cm_id->provider_data;
42582 @@ -3725,7 +3725,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42583 return;
42584 cm_id = cm_node->cm_id;
42585
42586 - atomic_inc(&cm_connect_reqs);
42587 + atomic_inc_unchecked(&cm_connect_reqs);
42588 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42589 cm_node, cm_id, jiffies);
42590
42591 @@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42592 return;
42593 cm_id = cm_node->cm_id;
42594
42595 - atomic_inc(&cm_connect_reqs);
42596 + atomic_inc_unchecked(&cm_connect_reqs);
42597 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42598 cm_node, cm_id, jiffies);
42599
42600 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42601 index 4166452..fc952c3 100644
42602 --- a/drivers/infiniband/hw/nes/nes_mgt.c
42603 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
42604 @@ -40,8 +40,8 @@
42605 #include "nes.h"
42606 #include "nes_mgt.h"
42607
42608 -atomic_t pau_qps_created;
42609 -atomic_t pau_qps_destroyed;
42610 +atomic_unchecked_t pau_qps_created;
42611 +atomic_unchecked_t pau_qps_destroyed;
42612
42613 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42614 {
42615 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42616 {
42617 struct sk_buff *skb;
42618 unsigned long flags;
42619 - atomic_inc(&pau_qps_destroyed);
42620 + atomic_inc_unchecked(&pau_qps_destroyed);
42621
42622 /* Free packets that have not yet been forwarded */
42623 /* Lock is acquired by skb_dequeue when removing the skb */
42624 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42625 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42626 skb_queue_head_init(&nesqp->pau_list);
42627 spin_lock_init(&nesqp->pau_lock);
42628 - atomic_inc(&pau_qps_created);
42629 + atomic_inc_unchecked(&pau_qps_created);
42630 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42631 }
42632
42633 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42634 index 49eb511..a774366 100644
42635 --- a/drivers/infiniband/hw/nes/nes_nic.c
42636 +++ b/drivers/infiniband/hw/nes/nes_nic.c
42637 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42638 target_stat_values[++index] = mh_detected;
42639 target_stat_values[++index] = mh_pauses_sent;
42640 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42641 - target_stat_values[++index] = atomic_read(&cm_connects);
42642 - target_stat_values[++index] = atomic_read(&cm_accepts);
42643 - target_stat_values[++index] = atomic_read(&cm_disconnects);
42644 - target_stat_values[++index] = atomic_read(&cm_connecteds);
42645 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42646 - target_stat_values[++index] = atomic_read(&cm_rejects);
42647 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42648 - target_stat_values[++index] = atomic_read(&qps_created);
42649 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42650 - target_stat_values[++index] = atomic_read(&qps_destroyed);
42651 - target_stat_values[++index] = atomic_read(&cm_closes);
42652 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42653 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42654 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42655 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42656 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42657 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42658 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42659 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42660 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42661 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42662 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42663 target_stat_values[++index] = cm_packets_sent;
42664 target_stat_values[++index] = cm_packets_bounced;
42665 target_stat_values[++index] = cm_packets_created;
42666 target_stat_values[++index] = cm_packets_received;
42667 target_stat_values[++index] = cm_packets_dropped;
42668 target_stat_values[++index] = cm_packets_retrans;
42669 - target_stat_values[++index] = atomic_read(&cm_listens_created);
42670 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42671 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42672 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42673 target_stat_values[++index] = cm_backlog_drops;
42674 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
42675 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
42676 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42677 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42678 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42679 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42680 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42681 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42682 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42683 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42684 target_stat_values[++index] = nesadapter->free_4kpbl;
42685 target_stat_values[++index] = nesadapter->free_256pbl;
42686 target_stat_values[++index] = int_mod_timer_init;
42687 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42688 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42689 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42690 - target_stat_values[++index] = atomic_read(&pau_qps_created);
42691 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42692 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42693 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42694 }
42695
42696 /**
42697 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42698 index 8308e36..ae0d3b5 100644
42699 --- a/drivers/infiniband/hw/nes/nes_verbs.c
42700 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
42701 @@ -46,9 +46,9 @@
42702
42703 #include <rdma/ib_umem.h>
42704
42705 -atomic_t mod_qp_timouts;
42706 -atomic_t qps_created;
42707 -atomic_t sw_qps_destroyed;
42708 +atomic_unchecked_t mod_qp_timouts;
42709 +atomic_unchecked_t qps_created;
42710 +atomic_unchecked_t sw_qps_destroyed;
42711
42712 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42713
42714 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42715 if (init_attr->create_flags)
42716 return ERR_PTR(-EINVAL);
42717
42718 - atomic_inc(&qps_created);
42719 + atomic_inc_unchecked(&qps_created);
42720 switch (init_attr->qp_type) {
42721 case IB_QPT_RC:
42722 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42723 @@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42724 struct iw_cm_event cm_event;
42725 int ret = 0;
42726
42727 - atomic_inc(&sw_qps_destroyed);
42728 + atomic_inc_unchecked(&sw_qps_destroyed);
42729 nesqp->destroyed = 1;
42730
42731 /* Blow away the connection if it exists. */
42732 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42733 index 1946101..09766d2 100644
42734 --- a/drivers/infiniband/hw/qib/qib.h
42735 +++ b/drivers/infiniband/hw/qib/qib.h
42736 @@ -52,6 +52,7 @@
42737 #include <linux/kref.h>
42738 #include <linux/sched.h>
42739 #include <linux/kthread.h>
42740 +#include <linux/slab.h>
42741
42742 #include "qib_common.h"
42743 #include "qib_verbs.h"
42744 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42745 index 24c41ba..102d71f 100644
42746 --- a/drivers/input/gameport/gameport.c
42747 +++ b/drivers/input/gameport/gameport.c
42748 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42749 */
42750 static void gameport_init_port(struct gameport *gameport)
42751 {
42752 - static atomic_t gameport_no = ATOMIC_INIT(0);
42753 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42754
42755 __module_get(THIS_MODULE);
42756
42757 mutex_init(&gameport->drv_mutex);
42758 device_initialize(&gameport->dev);
42759 dev_set_name(&gameport->dev, "gameport%lu",
42760 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
42761 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42762 gameport->dev.bus = &gameport_bus;
42763 gameport->dev.release = gameport_release_port;
42764 if (gameport->parent)
42765 diff --git a/drivers/input/input.c b/drivers/input/input.c
42766 index 1c4c0db..6f7abe3 100644
42767 --- a/drivers/input/input.c
42768 +++ b/drivers/input/input.c
42769 @@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
42770 */
42771 struct input_dev *input_allocate_device(void)
42772 {
42773 - static atomic_t input_no = ATOMIC_INIT(0);
42774 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42775 struct input_dev *dev;
42776
42777 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42778 @@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
42779 INIT_LIST_HEAD(&dev->node);
42780
42781 dev_set_name(&dev->dev, "input%ld",
42782 - (unsigned long) atomic_inc_return(&input_no) - 1);
42783 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42784
42785 __module_get(THIS_MODULE);
42786 }
42787 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42788 index 4a95b22..874c182 100644
42789 --- a/drivers/input/joystick/sidewinder.c
42790 +++ b/drivers/input/joystick/sidewinder.c
42791 @@ -30,6 +30,7 @@
42792 #include <linux/kernel.h>
42793 #include <linux/module.h>
42794 #include <linux/slab.h>
42795 +#include <linux/sched.h>
42796 #include <linux/input.h>
42797 #include <linux/gameport.h>
42798 #include <linux/jiffies.h>
42799 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42800 index 603fe0d..f63decc 100644
42801 --- a/drivers/input/joystick/xpad.c
42802 +++ b/drivers/input/joystick/xpad.c
42803 @@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42804
42805 static int xpad_led_probe(struct usb_xpad *xpad)
42806 {
42807 - static atomic_t led_seq = ATOMIC_INIT(0);
42808 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42809 long led_no;
42810 struct xpad_led *led;
42811 struct led_classdev *led_cdev;
42812 @@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42813 if (!led)
42814 return -ENOMEM;
42815
42816 - led_no = (long)atomic_inc_return(&led_seq) - 1;
42817 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42818
42819 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42820 led->xpad = xpad;
42821 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42822 index e204f26..8459f15 100644
42823 --- a/drivers/input/misc/ims-pcu.c
42824 +++ b/drivers/input/misc/ims-pcu.c
42825 @@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42826
42827 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42828 {
42829 - static atomic_t device_no = ATOMIC_INIT(0);
42830 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42831
42832 const struct ims_pcu_device_info *info;
42833 u8 device_id;
42834 @@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42835 }
42836
42837 /* Device appears to be operable, complete initialization */
42838 - pcu->device_no = atomic_inc_return(&device_no) - 1;
42839 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42840
42841 error = ims_pcu_setup_backlight(pcu);
42842 if (error)
42843 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42844 index 2f0b39d..7370f13 100644
42845 --- a/drivers/input/mouse/psmouse.h
42846 +++ b/drivers/input/mouse/psmouse.h
42847 @@ -116,7 +116,7 @@ struct psmouse_attribute {
42848 ssize_t (*set)(struct psmouse *psmouse, void *data,
42849 const char *buf, size_t count);
42850 bool protect;
42851 -};
42852 +} __do_const;
42853 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42854
42855 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42856 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42857 index b604564..3f14ae4 100644
42858 --- a/drivers/input/mousedev.c
42859 +++ b/drivers/input/mousedev.c
42860 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42861
42862 spin_unlock_irq(&client->packet_lock);
42863
42864 - if (copy_to_user(buffer, data, count))
42865 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
42866 return -EFAULT;
42867
42868 return count;
42869 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42870 index 8f4c4ab..5fc8a45 100644
42871 --- a/drivers/input/serio/serio.c
42872 +++ b/drivers/input/serio/serio.c
42873 @@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
42874 */
42875 static void serio_init_port(struct serio *serio)
42876 {
42877 - static atomic_t serio_no = ATOMIC_INIT(0);
42878 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42879
42880 __module_get(THIS_MODULE);
42881
42882 @@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
42883 mutex_init(&serio->drv_mutex);
42884 device_initialize(&serio->dev);
42885 dev_set_name(&serio->dev, "serio%ld",
42886 - (long)atomic_inc_return(&serio_no) - 1);
42887 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
42888 serio->dev.bus = &serio_bus;
42889 serio->dev.release = serio_release_port;
42890 serio->dev.groups = serio_device_attr_groups;
42891 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42892 index c9a02fe..0debc75 100644
42893 --- a/drivers/input/serio/serio_raw.c
42894 +++ b/drivers/input/serio/serio_raw.c
42895 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42896
42897 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42898 {
42899 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
42900 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42901 struct serio_raw *serio_raw;
42902 int err;
42903
42904 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42905 }
42906
42907 snprintf(serio_raw->name, sizeof(serio_raw->name),
42908 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42909 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42910 kref_init(&serio_raw->kref);
42911 INIT_LIST_HEAD(&serio_raw->client_list);
42912 init_waitqueue_head(&serio_raw->wait);
42913 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42914 index e5555fc..937986d 100644
42915 --- a/drivers/iommu/iommu.c
42916 +++ b/drivers/iommu/iommu.c
42917 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42918 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42919 {
42920 bus_register_notifier(bus, &iommu_bus_nb);
42921 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42922 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42923 }
42924
42925 /**
42926 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42927 index 228632c9..edfe331 100644
42928 --- a/drivers/iommu/irq_remapping.c
42929 +++ b/drivers/iommu/irq_remapping.c
42930 @@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42931 void panic_if_irq_remap(const char *msg)
42932 {
42933 if (irq_remapping_enabled)
42934 - panic(msg);
42935 + panic("%s", msg);
42936 }
42937
42938 static void ir_ack_apic_edge(struct irq_data *data)
42939 @@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
42940
42941 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
42942 {
42943 - chip->irq_print_chip = ir_print_prefix;
42944 - chip->irq_ack = ir_ack_apic_edge;
42945 - chip->irq_eoi = ir_ack_apic_level;
42946 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42947 + pax_open_kernel();
42948 + *(void **)&chip->irq_print_chip = ir_print_prefix;
42949 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
42950 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
42951 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42952 + pax_close_kernel();
42953 }
42954
42955 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
42956 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
42957 index 341c601..e5f407e 100644
42958 --- a/drivers/irqchip/irq-gic.c
42959 +++ b/drivers/irqchip/irq-gic.c
42960 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
42961 * Supported arch specific GIC irq extension.
42962 * Default make them NULL.
42963 */
42964 -struct irq_chip gic_arch_extn = {
42965 +irq_chip_no_const gic_arch_extn = {
42966 .irq_eoi = NULL,
42967 .irq_mask = NULL,
42968 .irq_unmask = NULL,
42969 @@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
42970 chained_irq_exit(chip, desc);
42971 }
42972
42973 -static struct irq_chip gic_chip = {
42974 +static irq_chip_no_const gic_chip __read_only = {
42975 .name = "GIC",
42976 .irq_mask = gic_mask_irq,
42977 .irq_unmask = gic_unmask_irq,
42978 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
42979 index ac6f72b..81150f2 100644
42980 --- a/drivers/isdn/capi/capi.c
42981 +++ b/drivers/isdn/capi/capi.c
42982 @@ -81,8 +81,8 @@ struct capiminor {
42983
42984 struct capi20_appl *ap;
42985 u32 ncci;
42986 - atomic_t datahandle;
42987 - atomic_t msgid;
42988 + atomic_unchecked_t datahandle;
42989 + atomic_unchecked_t msgid;
42990
42991 struct tty_port port;
42992 int ttyinstop;
42993 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
42994 capimsg_setu16(s, 2, mp->ap->applid);
42995 capimsg_setu8 (s, 4, CAPI_DATA_B3);
42996 capimsg_setu8 (s, 5, CAPI_RESP);
42997 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
42998 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
42999 capimsg_setu32(s, 8, mp->ncci);
43000 capimsg_setu16(s, 12, datahandle);
43001 }
43002 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43003 mp->outbytes -= len;
43004 spin_unlock_bh(&mp->outlock);
43005
43006 - datahandle = atomic_inc_return(&mp->datahandle);
43007 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43008 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43009 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43010 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43011 capimsg_setu16(skb->data, 2, mp->ap->applid);
43012 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43013 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43014 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43015 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43016 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43017 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43018 capimsg_setu16(skb->data, 16, len); /* Data length */
43019 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43020 index c44950d..10ac276 100644
43021 --- a/drivers/isdn/gigaset/bas-gigaset.c
43022 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43023 @@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43024
43025
43026 static const struct gigaset_ops gigops = {
43027 - gigaset_write_cmd,
43028 - gigaset_write_room,
43029 - gigaset_chars_in_buffer,
43030 - gigaset_brkchars,
43031 - gigaset_init_bchannel,
43032 - gigaset_close_bchannel,
43033 - gigaset_initbcshw,
43034 - gigaset_freebcshw,
43035 - gigaset_reinitbcshw,
43036 - gigaset_initcshw,
43037 - gigaset_freecshw,
43038 - gigaset_set_modem_ctrl,
43039 - gigaset_baud_rate,
43040 - gigaset_set_line_ctrl,
43041 - gigaset_isoc_send_skb,
43042 - gigaset_isoc_input,
43043 + .write_cmd = gigaset_write_cmd,
43044 + .write_room = gigaset_write_room,
43045 + .chars_in_buffer = gigaset_chars_in_buffer,
43046 + .brkchars = gigaset_brkchars,
43047 + .init_bchannel = gigaset_init_bchannel,
43048 + .close_bchannel = gigaset_close_bchannel,
43049 + .initbcshw = gigaset_initbcshw,
43050 + .freebcshw = gigaset_freebcshw,
43051 + .reinitbcshw = gigaset_reinitbcshw,
43052 + .initcshw = gigaset_initcshw,
43053 + .freecshw = gigaset_freecshw,
43054 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43055 + .baud_rate = gigaset_baud_rate,
43056 + .set_line_ctrl = gigaset_set_line_ctrl,
43057 + .send_skb = gigaset_isoc_send_skb,
43058 + .handle_input = gigaset_isoc_input,
43059 };
43060
43061 /* bas_gigaset_init
43062 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43063 index 600c79b..3752bab 100644
43064 --- a/drivers/isdn/gigaset/interface.c
43065 +++ b/drivers/isdn/gigaset/interface.c
43066 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43067 }
43068 tty->driver_data = cs;
43069
43070 - ++cs->port.count;
43071 + atomic_inc(&cs->port.count);
43072
43073 - if (cs->port.count == 1) {
43074 + if (atomic_read(&cs->port.count) == 1) {
43075 tty_port_tty_set(&cs->port, tty);
43076 cs->port.low_latency = 1;
43077 }
43078 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43079
43080 if (!cs->connected)
43081 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43082 - else if (!cs->port.count)
43083 + else if (!atomic_read(&cs->port.count))
43084 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43085 - else if (!--cs->port.count)
43086 + else if (!atomic_dec_return(&cs->port.count))
43087 tty_port_tty_set(&cs->port, NULL);
43088
43089 mutex_unlock(&cs->mutex);
43090 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43091 index 8c91fd5..14f13ce 100644
43092 --- a/drivers/isdn/gigaset/ser-gigaset.c
43093 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43094 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43095 }
43096
43097 static const struct gigaset_ops ops = {
43098 - gigaset_write_cmd,
43099 - gigaset_write_room,
43100 - gigaset_chars_in_buffer,
43101 - gigaset_brkchars,
43102 - gigaset_init_bchannel,
43103 - gigaset_close_bchannel,
43104 - gigaset_initbcshw,
43105 - gigaset_freebcshw,
43106 - gigaset_reinitbcshw,
43107 - gigaset_initcshw,
43108 - gigaset_freecshw,
43109 - gigaset_set_modem_ctrl,
43110 - gigaset_baud_rate,
43111 - gigaset_set_line_ctrl,
43112 - gigaset_m10x_send_skb, /* asyncdata.c */
43113 - gigaset_m10x_input, /* asyncdata.c */
43114 + .write_cmd = gigaset_write_cmd,
43115 + .write_room = gigaset_write_room,
43116 + .chars_in_buffer = gigaset_chars_in_buffer,
43117 + .brkchars = gigaset_brkchars,
43118 + .init_bchannel = gigaset_init_bchannel,
43119 + .close_bchannel = gigaset_close_bchannel,
43120 + .initbcshw = gigaset_initbcshw,
43121 + .freebcshw = gigaset_freebcshw,
43122 + .reinitbcshw = gigaset_reinitbcshw,
43123 + .initcshw = gigaset_initcshw,
43124 + .freecshw = gigaset_freecshw,
43125 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43126 + .baud_rate = gigaset_baud_rate,
43127 + .set_line_ctrl = gigaset_set_line_ctrl,
43128 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43129 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
43130 };
43131
43132
43133 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43134 index d0a41cb..b953e50 100644
43135 --- a/drivers/isdn/gigaset/usb-gigaset.c
43136 +++ b/drivers/isdn/gigaset/usb-gigaset.c
43137 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43138 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43139 memcpy(cs->hw.usb->bchars, buf, 6);
43140 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43141 - 0, 0, &buf, 6, 2000);
43142 + 0, 0, buf, 6, 2000);
43143 }
43144
43145 static void gigaset_freebcshw(struct bc_state *bcs)
43146 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43147 }
43148
43149 static const struct gigaset_ops ops = {
43150 - gigaset_write_cmd,
43151 - gigaset_write_room,
43152 - gigaset_chars_in_buffer,
43153 - gigaset_brkchars,
43154 - gigaset_init_bchannel,
43155 - gigaset_close_bchannel,
43156 - gigaset_initbcshw,
43157 - gigaset_freebcshw,
43158 - gigaset_reinitbcshw,
43159 - gigaset_initcshw,
43160 - gigaset_freecshw,
43161 - gigaset_set_modem_ctrl,
43162 - gigaset_baud_rate,
43163 - gigaset_set_line_ctrl,
43164 - gigaset_m10x_send_skb,
43165 - gigaset_m10x_input,
43166 + .write_cmd = gigaset_write_cmd,
43167 + .write_room = gigaset_write_room,
43168 + .chars_in_buffer = gigaset_chars_in_buffer,
43169 + .brkchars = gigaset_brkchars,
43170 + .init_bchannel = gigaset_init_bchannel,
43171 + .close_bchannel = gigaset_close_bchannel,
43172 + .initbcshw = gigaset_initbcshw,
43173 + .freebcshw = gigaset_freebcshw,
43174 + .reinitbcshw = gigaset_reinitbcshw,
43175 + .initcshw = gigaset_initcshw,
43176 + .freecshw = gigaset_freecshw,
43177 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43178 + .baud_rate = gigaset_baud_rate,
43179 + .set_line_ctrl = gigaset_set_line_ctrl,
43180 + .send_skb = gigaset_m10x_send_skb,
43181 + .handle_input = gigaset_m10x_input,
43182 };
43183
43184 /*
43185 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43186 index 4d9b195..455075c 100644
43187 --- a/drivers/isdn/hardware/avm/b1.c
43188 +++ b/drivers/isdn/hardware/avm/b1.c
43189 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43190 }
43191 if (left) {
43192 if (t4file->user) {
43193 - if (copy_from_user(buf, dp, left))
43194 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43195 return -EFAULT;
43196 } else {
43197 memcpy(buf, dp, left);
43198 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43199 }
43200 if (left) {
43201 if (config->user) {
43202 - if (copy_from_user(buf, dp, left))
43203 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43204 return -EFAULT;
43205 } else {
43206 memcpy(buf, dp, left);
43207 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43208 index 9bb12ba..d4262f7 100644
43209 --- a/drivers/isdn/i4l/isdn_common.c
43210 +++ b/drivers/isdn/i4l/isdn_common.c
43211 @@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43212 } else
43213 return -EINVAL;
43214 case IIOCDBGVAR:
43215 + if (!capable(CAP_SYS_RAWIO))
43216 + return -EPERM;
43217 if (arg) {
43218 if (copy_to_user(argp, &dev, sizeof(ulong)))
43219 return -EFAULT;
43220 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43221 index 91d5730..336523e 100644
43222 --- a/drivers/isdn/i4l/isdn_concap.c
43223 +++ b/drivers/isdn/i4l/isdn_concap.c
43224 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43225 }
43226
43227 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43228 - &isdn_concap_dl_data_req,
43229 - &isdn_concap_dl_connect_req,
43230 - &isdn_concap_dl_disconn_req
43231 + .data_req = &isdn_concap_dl_data_req,
43232 + .connect_req = &isdn_concap_dl_connect_req,
43233 + .disconn_req = &isdn_concap_dl_disconn_req
43234 };
43235
43236 /* The following should better go into a dedicated source file such that
43237 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43238 index 3c5f249..5fac4d0 100644
43239 --- a/drivers/isdn/i4l/isdn_tty.c
43240 +++ b/drivers/isdn/i4l/isdn_tty.c
43241 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43242
43243 #ifdef ISDN_DEBUG_MODEM_OPEN
43244 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43245 - port->count);
43246 + atomic_read(&port->count));
43247 #endif
43248 - port->count++;
43249 + atomic_inc(&port->count);
43250 port->tty = tty;
43251 /*
43252 * Start up serial port
43253 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43254 #endif
43255 return;
43256 }
43257 - if ((tty->count == 1) && (port->count != 1)) {
43258 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43259 /*
43260 * Uh, oh. tty->count is 1, which means that the tty
43261 * structure will be freed. Info->count should always
43262 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43263 * serial port won't be shutdown.
43264 */
43265 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43266 - "info->count is %d\n", port->count);
43267 - port->count = 1;
43268 + "info->count is %d\n", atomic_read(&port->count));
43269 + atomic_set(&port->count, 1);
43270 }
43271 - if (--port->count < 0) {
43272 + if (atomic_dec_return(&port->count) < 0) {
43273 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43274 - info->line, port->count);
43275 - port->count = 0;
43276 + info->line, atomic_read(&port->count));
43277 + atomic_set(&port->count, 0);
43278 }
43279 - if (port->count) {
43280 + if (atomic_read(&port->count)) {
43281 #ifdef ISDN_DEBUG_MODEM_OPEN
43282 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43283 #endif
43284 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43285 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43286 return;
43287 isdn_tty_shutdown(info);
43288 - port->count = 0;
43289 + atomic_set(&port->count, 0);
43290 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43291 port->tty = NULL;
43292 wake_up_interruptible(&port->open_wait);
43293 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43294 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43295 modem_info *info = &dev->mdm.info[i];
43296
43297 - if (info->port.count == 0)
43298 + if (atomic_read(&info->port.count) == 0)
43299 continue;
43300 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43301 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43302 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43303 index e2d4e58..40cd045 100644
43304 --- a/drivers/isdn/i4l/isdn_x25iface.c
43305 +++ b/drivers/isdn/i4l/isdn_x25iface.c
43306 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43307
43308
43309 static struct concap_proto_ops ix25_pops = {
43310 - &isdn_x25iface_proto_new,
43311 - &isdn_x25iface_proto_del,
43312 - &isdn_x25iface_proto_restart,
43313 - &isdn_x25iface_proto_close,
43314 - &isdn_x25iface_xmit,
43315 - &isdn_x25iface_receive,
43316 - &isdn_x25iface_connect_ind,
43317 - &isdn_x25iface_disconn_ind
43318 + .proto_new = &isdn_x25iface_proto_new,
43319 + .proto_del = &isdn_x25iface_proto_del,
43320 + .restart = &isdn_x25iface_proto_restart,
43321 + .close = &isdn_x25iface_proto_close,
43322 + .encap_and_xmit = &isdn_x25iface_xmit,
43323 + .data_ind = &isdn_x25iface_receive,
43324 + .connect_ind = &isdn_x25iface_connect_ind,
43325 + .disconn_ind = &isdn_x25iface_disconn_ind
43326 };
43327
43328 /* error message helper function */
43329 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43330 index 53d487f..f020f41 100644
43331 --- a/drivers/isdn/icn/icn.c
43332 +++ b/drivers/isdn/icn/icn.c
43333 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43334 if (count > len)
43335 count = len;
43336 if (user) {
43337 - if (copy_from_user(msg, buf, count))
43338 + if (count > sizeof msg || copy_from_user(msg, buf, count))
43339 return -EFAULT;
43340 } else
43341 memcpy(msg, buf, count);
43342 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43343 index a4f05c5..1433bc5 100644
43344 --- a/drivers/isdn/mISDN/dsp_cmx.c
43345 +++ b/drivers/isdn/mISDN/dsp_cmx.c
43346 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43347 static u16 dsp_count; /* last sample count */
43348 static int dsp_count_valid; /* if we have last sample count */
43349
43350 -void
43351 +void __intentional_overflow(-1)
43352 dsp_cmx_send(void *arg)
43353 {
43354 struct dsp_conf *conf;
43355 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43356 index d93e245..e7ece6b 100644
43357 --- a/drivers/leds/leds-clevo-mail.c
43358 +++ b/drivers/leds/leds-clevo-mail.c
43359 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43360 * detected as working, but in reality it is not) as low as
43361 * possible.
43362 */
43363 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43364 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43365 {
43366 .callback = clevo_mail_led_dmi_callback,
43367 .ident = "Clevo D410J",
43368 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43369 index 5b8f938..b73d657 100644
43370 --- a/drivers/leds/leds-ss4200.c
43371 +++ b/drivers/leds/leds-ss4200.c
43372 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43373 * detected as working, but in reality it is not) as low as
43374 * possible.
43375 */
43376 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
43377 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
43378 {
43379 .callback = ss4200_led_dmi_callback,
43380 .ident = "Intel SS4200-E",
43381 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43382 index 0bf1e4e..b4bf44e 100644
43383 --- a/drivers/lguest/core.c
43384 +++ b/drivers/lguest/core.c
43385 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
43386 * The end address needs +1 because __get_vm_area allocates an
43387 * extra guard page, so we need space for that.
43388 */
43389 +
43390 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43391 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43392 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43393 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43394 +#else
43395 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43396 VM_ALLOC, switcher_addr, switcher_addr
43397 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43398 +#endif
43399 +
43400 if (!switcher_vma) {
43401 err = -ENOMEM;
43402 printk("lguest: could not map switcher pages high\n");
43403 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
43404 * Now the Switcher is mapped at the right address, we can't fail!
43405 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43406 */
43407 - memcpy(switcher_vma->addr, start_switcher_text,
43408 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43409 end_switcher_text - start_switcher_text);
43410
43411 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43412 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43413 index bfb39bb..08a603b 100644
43414 --- a/drivers/lguest/page_tables.c
43415 +++ b/drivers/lguest/page_tables.c
43416 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43417 /*:*/
43418
43419 #ifdef CONFIG_X86_PAE
43420 -static void release_pmd(pmd_t *spmd)
43421 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43422 {
43423 /* If the entry's not present, there's nothing to release. */
43424 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43425 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43426 index 922a1ac..9dd0c2a 100644
43427 --- a/drivers/lguest/x86/core.c
43428 +++ b/drivers/lguest/x86/core.c
43429 @@ -59,7 +59,7 @@ static struct {
43430 /* Offset from where switcher.S was compiled to where we've copied it */
43431 static unsigned long switcher_offset(void)
43432 {
43433 - return switcher_addr - (unsigned long)start_switcher_text;
43434 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43435 }
43436
43437 /* This cpu's struct lguest_pages (after the Switcher text page) */
43438 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43439 * These copies are pretty cheap, so we do them unconditionally: */
43440 /* Save the current Host top-level page directory.
43441 */
43442 +
43443 +#ifdef CONFIG_PAX_PER_CPU_PGD
43444 + pages->state.host_cr3 = read_cr3();
43445 +#else
43446 pages->state.host_cr3 = __pa(current->mm->pgd);
43447 +#endif
43448 +
43449 /*
43450 * Set up the Guest's page tables to see this CPU's pages (and no
43451 * other CPU's pages).
43452 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43453 * compiled-in switcher code and the high-mapped copy we just made.
43454 */
43455 for (i = 0; i < IDT_ENTRIES; i++)
43456 - default_idt_entries[i] += switcher_offset();
43457 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43458
43459 /*
43460 * Set up the Switcher's per-cpu areas.
43461 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43462 * it will be undisturbed when we switch. To change %cs and jump we
43463 * need this structure to feed to Intel's "lcall" instruction.
43464 */
43465 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43466 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43467 lguest_entry.segment = LGUEST_CS;
43468
43469 /*
43470 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43471 index 40634b0..4f5855e 100644
43472 --- a/drivers/lguest/x86/switcher_32.S
43473 +++ b/drivers/lguest/x86/switcher_32.S
43474 @@ -87,6 +87,7 @@
43475 #include <asm/page.h>
43476 #include <asm/segment.h>
43477 #include <asm/lguest.h>
43478 +#include <asm/processor-flags.h>
43479
43480 // We mark the start of the code to copy
43481 // It's placed in .text tho it's never run here
43482 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43483 // Changes type when we load it: damn Intel!
43484 // For after we switch over our page tables
43485 // That entry will be read-only: we'd crash.
43486 +
43487 +#ifdef CONFIG_PAX_KERNEXEC
43488 + mov %cr0, %edx
43489 + xor $X86_CR0_WP, %edx
43490 + mov %edx, %cr0
43491 +#endif
43492 +
43493 movl $(GDT_ENTRY_TSS*8), %edx
43494 ltr %dx
43495
43496 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43497 // Let's clear it again for our return.
43498 // The GDT descriptor of the Host
43499 // Points to the table after two "size" bytes
43500 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43501 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43502 // Clear "used" from type field (byte 5, bit 2)
43503 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43504 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43505 +
43506 +#ifdef CONFIG_PAX_KERNEXEC
43507 + mov %cr0, %eax
43508 + xor $X86_CR0_WP, %eax
43509 + mov %eax, %cr0
43510 +#endif
43511
43512 // Once our page table's switched, the Guest is live!
43513 // The Host fades as we run this final step.
43514 @@ -295,13 +309,12 @@ deliver_to_host:
43515 // I consulted gcc, and it gave
43516 // These instructions, which I gladly credit:
43517 leal (%edx,%ebx,8), %eax
43518 - movzwl (%eax),%edx
43519 - movl 4(%eax), %eax
43520 - xorw %ax, %ax
43521 - orl %eax, %edx
43522 + movl 4(%eax), %edx
43523 + movw (%eax), %dx
43524 // Now the address of the handler's in %edx
43525 // We call it now: its "iret" drops us home.
43526 - jmp *%edx
43527 + ljmp $__KERNEL_CS, $1f
43528 +1: jmp *%edx
43529
43530 // Every interrupt can come to us here
43531 // But we must truly tell each apart.
43532 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43533 index 7ef7461..5a09dac 100644
43534 --- a/drivers/md/bcache/closure.h
43535 +++ b/drivers/md/bcache/closure.h
43536 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
43537 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43538 struct workqueue_struct *wq)
43539 {
43540 - BUG_ON(object_is_on_stack(cl));
43541 + BUG_ON(object_starts_on_stack(cl));
43542 closure_set_ip(cl);
43543 cl->fn = fn;
43544 cl->wq = wq;
43545 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43546 index 4195a01..42527ac 100644
43547 --- a/drivers/md/bitmap.c
43548 +++ b/drivers/md/bitmap.c
43549 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43550 chunk_kb ? "KB" : "B");
43551 if (bitmap->storage.file) {
43552 seq_printf(seq, ", file: ");
43553 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43554 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43555 }
43556
43557 seq_printf(seq, "\n");
43558 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43559 index 5152142..623d141 100644
43560 --- a/drivers/md/dm-ioctl.c
43561 +++ b/drivers/md/dm-ioctl.c
43562 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43563 cmd == DM_LIST_VERSIONS_CMD)
43564 return 0;
43565
43566 - if ((cmd == DM_DEV_CREATE_CMD)) {
43567 + if (cmd == DM_DEV_CREATE_CMD) {
43568 if (!*param->name) {
43569 DMWARN("name not supplied when creating device");
43570 return -EINVAL;
43571 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43572 index 7dfdb5c..4caada6 100644
43573 --- a/drivers/md/dm-raid1.c
43574 +++ b/drivers/md/dm-raid1.c
43575 @@ -40,7 +40,7 @@ enum dm_raid1_error {
43576
43577 struct mirror {
43578 struct mirror_set *ms;
43579 - atomic_t error_count;
43580 + atomic_unchecked_t error_count;
43581 unsigned long error_type;
43582 struct dm_dev *dev;
43583 sector_t offset;
43584 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43585 struct mirror *m;
43586
43587 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43588 - if (!atomic_read(&m->error_count))
43589 + if (!atomic_read_unchecked(&m->error_count))
43590 return m;
43591
43592 return NULL;
43593 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43594 * simple way to tell if a device has encountered
43595 * errors.
43596 */
43597 - atomic_inc(&m->error_count);
43598 + atomic_inc_unchecked(&m->error_count);
43599
43600 if (test_and_set_bit(error_type, &m->error_type))
43601 return;
43602 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43603 struct mirror *m = get_default_mirror(ms);
43604
43605 do {
43606 - if (likely(!atomic_read(&m->error_count)))
43607 + if (likely(!atomic_read_unchecked(&m->error_count)))
43608 return m;
43609
43610 if (m-- == ms->mirror)
43611 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43612 {
43613 struct mirror *default_mirror = get_default_mirror(m->ms);
43614
43615 - return !atomic_read(&default_mirror->error_count);
43616 + return !atomic_read_unchecked(&default_mirror->error_count);
43617 }
43618
43619 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43620 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43621 */
43622 if (likely(region_in_sync(ms, region, 1)))
43623 m = choose_mirror(ms, bio->bi_iter.bi_sector);
43624 - else if (m && atomic_read(&m->error_count))
43625 + else if (m && atomic_read_unchecked(&m->error_count))
43626 m = NULL;
43627
43628 if (likely(m))
43629 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43630 }
43631
43632 ms->mirror[mirror].ms = ms;
43633 - atomic_set(&(ms->mirror[mirror].error_count), 0);
43634 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43635 ms->mirror[mirror].error_type = 0;
43636 ms->mirror[mirror].offset = offset;
43637
43638 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
43639 */
43640 static char device_status_char(struct mirror *m)
43641 {
43642 - if (!atomic_read(&(m->error_count)))
43643 + if (!atomic_read_unchecked(&(m->error_count)))
43644 return 'A';
43645
43646 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43647 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43648 index 28a9012..9c0f6a5 100644
43649 --- a/drivers/md/dm-stats.c
43650 +++ b/drivers/md/dm-stats.c
43651 @@ -382,7 +382,7 @@ do_sync_free:
43652 synchronize_rcu_expedited();
43653 dm_stat_free(&s->rcu_head);
43654 } else {
43655 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43656 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43657 call_rcu(&s->rcu_head, dm_stat_free);
43658 }
43659 return 0;
43660 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43661 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43662 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43663 ));
43664 - ACCESS_ONCE(last->last_sector) = end_sector;
43665 - ACCESS_ONCE(last->last_rw) = bi_rw;
43666 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
43667 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43668 }
43669
43670 rcu_read_lock();
43671 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43672 index d1600d2..4c3af3a 100644
43673 --- a/drivers/md/dm-stripe.c
43674 +++ b/drivers/md/dm-stripe.c
43675 @@ -21,7 +21,7 @@ struct stripe {
43676 struct dm_dev *dev;
43677 sector_t physical_start;
43678
43679 - atomic_t error_count;
43680 + atomic_unchecked_t error_count;
43681 };
43682
43683 struct stripe_c {
43684 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43685 kfree(sc);
43686 return r;
43687 }
43688 - atomic_set(&(sc->stripe[i].error_count), 0);
43689 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43690 }
43691
43692 ti->private = sc;
43693 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43694 DMEMIT("%d ", sc->stripes);
43695 for (i = 0; i < sc->stripes; i++) {
43696 DMEMIT("%s ", sc->stripe[i].dev->name);
43697 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43698 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43699 'D' : 'A';
43700 }
43701 buffer[i] = '\0';
43702 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43703 */
43704 for (i = 0; i < sc->stripes; i++)
43705 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43706 - atomic_inc(&(sc->stripe[i].error_count));
43707 - if (atomic_read(&(sc->stripe[i].error_count)) <
43708 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
43709 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43710 DM_IO_ERROR_THRESHOLD)
43711 schedule_work(&sc->trigger_event);
43712 }
43713 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43714 index 6a7f2b8..fea0bde 100644
43715 --- a/drivers/md/dm-table.c
43716 +++ b/drivers/md/dm-table.c
43717 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43718 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43719 struct mapped_device *md)
43720 {
43721 - static char *_claim_ptr = "I belong to device-mapper";
43722 + static char _claim_ptr[] = "I belong to device-mapper";
43723 struct block_device *bdev;
43724
43725 int r;
43726 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43727 if (!dev_size)
43728 return 0;
43729
43730 - if ((start >= dev_size) || (start + len > dev_size)) {
43731 + if ((start >= dev_size) || (len > dev_size - start)) {
43732 DMWARN("%s: %s too small for target: "
43733 "start=%llu, len=%llu, dev_size=%llu",
43734 dm_device_name(ti->table->md), bdevname(bdev, b),
43735 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43736 index fb9efc8..81e8986 100644
43737 --- a/drivers/md/dm-thin-metadata.c
43738 +++ b/drivers/md/dm-thin-metadata.c
43739 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43740 {
43741 pmd->info.tm = pmd->tm;
43742 pmd->info.levels = 2;
43743 - pmd->info.value_type.context = pmd->data_sm;
43744 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43745 pmd->info.value_type.size = sizeof(__le64);
43746 pmd->info.value_type.inc = data_block_inc;
43747 pmd->info.value_type.dec = data_block_dec;
43748 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43749
43750 pmd->bl_info.tm = pmd->tm;
43751 pmd->bl_info.levels = 1;
43752 - pmd->bl_info.value_type.context = pmd->data_sm;
43753 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43754 pmd->bl_info.value_type.size = sizeof(__le64);
43755 pmd->bl_info.value_type.inc = data_block_inc;
43756 pmd->bl_info.value_type.dec = data_block_dec;
43757 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43758 index 8c53b09..f1fb2b0 100644
43759 --- a/drivers/md/dm.c
43760 +++ b/drivers/md/dm.c
43761 @@ -185,9 +185,9 @@ struct mapped_device {
43762 /*
43763 * Event handling.
43764 */
43765 - atomic_t event_nr;
43766 + atomic_unchecked_t event_nr;
43767 wait_queue_head_t eventq;
43768 - atomic_t uevent_seq;
43769 + atomic_unchecked_t uevent_seq;
43770 struct list_head uevent_list;
43771 spinlock_t uevent_lock; /* Protect access to uevent_list */
43772
43773 @@ -1888,8 +1888,8 @@ static struct mapped_device *alloc_dev(int minor)
43774 spin_lock_init(&md->deferred_lock);
43775 atomic_set(&md->holders, 1);
43776 atomic_set(&md->open_count, 0);
43777 - atomic_set(&md->event_nr, 0);
43778 - atomic_set(&md->uevent_seq, 0);
43779 + atomic_set_unchecked(&md->event_nr, 0);
43780 + atomic_set_unchecked(&md->uevent_seq, 0);
43781 INIT_LIST_HEAD(&md->uevent_list);
43782 spin_lock_init(&md->uevent_lock);
43783
43784 @@ -2043,7 +2043,7 @@ static void event_callback(void *context)
43785
43786 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43787
43788 - atomic_inc(&md->event_nr);
43789 + atomic_inc_unchecked(&md->event_nr);
43790 wake_up(&md->eventq);
43791 }
43792
43793 @@ -2736,18 +2736,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43794
43795 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43796 {
43797 - return atomic_add_return(1, &md->uevent_seq);
43798 + return atomic_add_return_unchecked(1, &md->uevent_seq);
43799 }
43800
43801 uint32_t dm_get_event_nr(struct mapped_device *md)
43802 {
43803 - return atomic_read(&md->event_nr);
43804 + return atomic_read_unchecked(&md->event_nr);
43805 }
43806
43807 int dm_wait_event(struct mapped_device *md, int event_nr)
43808 {
43809 return wait_event_interruptible(md->eventq,
43810 - (event_nr != atomic_read(&md->event_nr)));
43811 + (event_nr != atomic_read_unchecked(&md->event_nr)));
43812 }
43813
43814 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43815 diff --git a/drivers/md/md.c b/drivers/md/md.c
43816 index 4ad5cc4..0f19664 100644
43817 --- a/drivers/md/md.c
43818 +++ b/drivers/md/md.c
43819 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43820 * start build, activate spare
43821 */
43822 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43823 -static atomic_t md_event_count;
43824 +static atomic_unchecked_t md_event_count;
43825 void md_new_event(struct mddev *mddev)
43826 {
43827 - atomic_inc(&md_event_count);
43828 + atomic_inc_unchecked(&md_event_count);
43829 wake_up(&md_event_waiters);
43830 }
43831 EXPORT_SYMBOL_GPL(md_new_event);
43832 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43833 */
43834 static void md_new_event_inintr(struct mddev *mddev)
43835 {
43836 - atomic_inc(&md_event_count);
43837 + atomic_inc_unchecked(&md_event_count);
43838 wake_up(&md_event_waiters);
43839 }
43840
43841 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43842 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43843 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43844 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43845 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43846 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43847
43848 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43849 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43850 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43851 else
43852 sb->resync_offset = cpu_to_le64(0);
43853
43854 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43855 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43856
43857 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43858 sb->size = cpu_to_le64(mddev->dev_sectors);
43859 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43860 static ssize_t
43861 errors_show(struct md_rdev *rdev, char *page)
43862 {
43863 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43864 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43865 }
43866
43867 static ssize_t
43868 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43869 char *e;
43870 unsigned long n = simple_strtoul(buf, &e, 10);
43871 if (*buf && (*e == 0 || *e == '\n')) {
43872 - atomic_set(&rdev->corrected_errors, n);
43873 + atomic_set_unchecked(&rdev->corrected_errors, n);
43874 return len;
43875 }
43876 return -EINVAL;
43877 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
43878 rdev->sb_loaded = 0;
43879 rdev->bb_page = NULL;
43880 atomic_set(&rdev->nr_pending, 0);
43881 - atomic_set(&rdev->read_errors, 0);
43882 - atomic_set(&rdev->corrected_errors, 0);
43883 + atomic_set_unchecked(&rdev->read_errors, 0);
43884 + atomic_set_unchecked(&rdev->corrected_errors, 0);
43885
43886 INIT_LIST_HEAD(&rdev->same_set);
43887 init_waitqueue_head(&rdev->blocked_wait);
43888 @@ -7075,7 +7075,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43889
43890 spin_unlock(&pers_lock);
43891 seq_printf(seq, "\n");
43892 - seq->poll_event = atomic_read(&md_event_count);
43893 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43894 return 0;
43895 }
43896 if (v == (void*)2) {
43897 @@ -7178,7 +7178,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43898 return error;
43899
43900 seq = file->private_data;
43901 - seq->poll_event = atomic_read(&md_event_count);
43902 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43903 return error;
43904 }
43905
43906 @@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43907 /* always allow read */
43908 mask = POLLIN | POLLRDNORM;
43909
43910 - if (seq->poll_event != atomic_read(&md_event_count))
43911 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43912 mask |= POLLERR | POLLPRI;
43913 return mask;
43914 }
43915 @@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43916 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43917 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43918 (int)part_stat_read(&disk->part0, sectors[1]) -
43919 - atomic_read(&disk->sync_io);
43920 + atomic_read_unchecked(&disk->sync_io);
43921 /* sync IO will cause sync_io to increase before the disk_stats
43922 * as sync_io is counted when a request starts, and
43923 * disk_stats is counted when it completes.
43924 diff --git a/drivers/md/md.h b/drivers/md/md.h
43925 index 07bba96..2d6788c 100644
43926 --- a/drivers/md/md.h
43927 +++ b/drivers/md/md.h
43928 @@ -94,13 +94,13 @@ struct md_rdev {
43929 * only maintained for arrays that
43930 * support hot removal
43931 */
43932 - atomic_t read_errors; /* number of consecutive read errors that
43933 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
43934 * we have tried to ignore.
43935 */
43936 struct timespec last_read_error; /* monotonic time since our
43937 * last read error
43938 */
43939 - atomic_t corrected_errors; /* number of corrected read errors,
43940 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
43941 * for reporting to userspace and storing
43942 * in superblock.
43943 */
43944 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
43945
43946 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
43947 {
43948 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43949 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43950 }
43951
43952 struct md_personality
43953 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
43954 index 786b689..ea8c956 100644
43955 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
43956 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
43957 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
43958 * Flick into a mode where all blocks get allocated in the new area.
43959 */
43960 smm->begin = old_len;
43961 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
43962 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
43963
43964 /*
43965 * Extend.
43966 @@ -710,7 +710,7 @@ out:
43967 /*
43968 * Switch back to normal behaviour.
43969 */
43970 - memcpy(sm, &ops, sizeof(*sm));
43971 + memcpy((void *)sm, &ops, sizeof(*sm));
43972 return r;
43973 }
43974
43975 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
43976 index 3e6d115..ffecdeb 100644
43977 --- a/drivers/md/persistent-data/dm-space-map.h
43978 +++ b/drivers/md/persistent-data/dm-space-map.h
43979 @@ -71,6 +71,7 @@ struct dm_space_map {
43980 dm_sm_threshold_fn fn,
43981 void *context);
43982 };
43983 +typedef struct dm_space_map __no_const dm_space_map_no_const;
43984
43985 /*----------------------------------------------------------------*/
43986
43987 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
43988 index 4a6ca1c..e952750 100644
43989 --- a/drivers/md/raid1.c
43990 +++ b/drivers/md/raid1.c
43991 @@ -1922,7 +1922,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
43992 if (r1_sync_page_io(rdev, sect, s,
43993 bio->bi_io_vec[idx].bv_page,
43994 READ) != 0)
43995 - atomic_add(s, &rdev->corrected_errors);
43996 + atomic_add_unchecked(s, &rdev->corrected_errors);
43997 }
43998 sectors -= s;
43999 sect += s;
44000 @@ -2156,7 +2156,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44001 test_bit(In_sync, &rdev->flags)) {
44002 if (r1_sync_page_io(rdev, sect, s,
44003 conf->tmppage, READ)) {
44004 - atomic_add(s, &rdev->corrected_errors);
44005 + atomic_add_unchecked(s, &rdev->corrected_errors);
44006 printk(KERN_INFO
44007 "md/raid1:%s: read error corrected "
44008 "(%d sectors at %llu on %s)\n",
44009 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44010 index 33fc408..fc61709 100644
44011 --- a/drivers/md/raid10.c
44012 +++ b/drivers/md/raid10.c
44013 @@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
44014 /* The write handler will notice the lack of
44015 * R10BIO_Uptodate and record any errors etc
44016 */
44017 - atomic_add(r10_bio->sectors,
44018 + atomic_add_unchecked(r10_bio->sectors,
44019 &conf->mirrors[d].rdev->corrected_errors);
44020
44021 /* for reconstruct, we always reschedule after a read.
44022 @@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44023 {
44024 struct timespec cur_time_mon;
44025 unsigned long hours_since_last;
44026 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44027 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44028
44029 ktime_get_ts(&cur_time_mon);
44030
44031 @@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44032 * overflowing the shift of read_errors by hours_since_last.
44033 */
44034 if (hours_since_last >= 8 * sizeof(read_errors))
44035 - atomic_set(&rdev->read_errors, 0);
44036 + atomic_set_unchecked(&rdev->read_errors, 0);
44037 else
44038 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44039 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44040 }
44041
44042 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44043 @@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44044 return;
44045
44046 check_decay_read_errors(mddev, rdev);
44047 - atomic_inc(&rdev->read_errors);
44048 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44049 + atomic_inc_unchecked(&rdev->read_errors);
44050 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44051 char b[BDEVNAME_SIZE];
44052 bdevname(rdev->bdev, b);
44053
44054 @@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44055 "md/raid10:%s: %s: Raid device exceeded "
44056 "read_error threshold [cur %d:max %d]\n",
44057 mdname(mddev), b,
44058 - atomic_read(&rdev->read_errors), max_read_errors);
44059 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44060 printk(KERN_NOTICE
44061 "md/raid10:%s: %s: Failing raid device\n",
44062 mdname(mddev), b);
44063 @@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44064 sect +
44065 choose_data_offset(r10_bio, rdev)),
44066 bdevname(rdev->bdev, b));
44067 - atomic_add(s, &rdev->corrected_errors);
44068 + atomic_add_unchecked(s, &rdev->corrected_errors);
44069 }
44070
44071 rdev_dec_pending(rdev, mddev);
44072 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44073 index 16f5c21..4df20dc 100644
44074 --- a/drivers/md/raid5.c
44075 +++ b/drivers/md/raid5.c
44076 @@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44077 mdname(conf->mddev), STRIPE_SECTORS,
44078 (unsigned long long)s,
44079 bdevname(rdev->bdev, b));
44080 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44081 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44082 clear_bit(R5_ReadError, &sh->dev[i].flags);
44083 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44084 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44085 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44086
44087 - if (atomic_read(&rdev->read_errors))
44088 - atomic_set(&rdev->read_errors, 0);
44089 + if (atomic_read_unchecked(&rdev->read_errors))
44090 + atomic_set_unchecked(&rdev->read_errors, 0);
44091 } else {
44092 const char *bdn = bdevname(rdev->bdev, b);
44093 int retry = 0;
44094 int set_bad = 0;
44095
44096 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44097 - atomic_inc(&rdev->read_errors);
44098 + atomic_inc_unchecked(&rdev->read_errors);
44099 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44100 printk_ratelimited(
44101 KERN_WARNING
44102 @@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44103 mdname(conf->mddev),
44104 (unsigned long long)s,
44105 bdn);
44106 - } else if (atomic_read(&rdev->read_errors)
44107 + } else if (atomic_read_unchecked(&rdev->read_errors)
44108 > conf->max_nr_stripes)
44109 printk(KERN_WARNING
44110 "md/raid:%s: Too many read errors, failing device %s.\n",
44111 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44112 index 983db75..ef9248c 100644
44113 --- a/drivers/media/dvb-core/dvbdev.c
44114 +++ b/drivers/media/dvb-core/dvbdev.c
44115 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44116 const struct dvb_device *template, void *priv, int type)
44117 {
44118 struct dvb_device *dvbdev;
44119 - struct file_operations *dvbdevfops;
44120 + file_operations_no_const *dvbdevfops;
44121 struct device *clsdev;
44122 int minor;
44123 int id;
44124 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44125 index 9b6c3bb..baeb5c7 100644
44126 --- a/drivers/media/dvb-frontends/dib3000.h
44127 +++ b/drivers/media/dvb-frontends/dib3000.h
44128 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44129 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44130 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44131 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44132 -};
44133 +} __no_const;
44134
44135 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44136 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44137 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44138 index ed8cb90..5ef7f79 100644
44139 --- a/drivers/media/pci/cx88/cx88-video.c
44140 +++ b/drivers/media/pci/cx88/cx88-video.c
44141 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44142
44143 /* ------------------------------------------------------------------ */
44144
44145 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44146 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44147 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44148 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44149 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44150 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44151
44152 module_param_array(video_nr, int, NULL, 0444);
44153 module_param_array(vbi_nr, int, NULL, 0444);
44154 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44155 index 802642d..5534900 100644
44156 --- a/drivers/media/pci/ivtv/ivtv-driver.c
44157 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
44158 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44159 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44160
44161 /* ivtv instance counter */
44162 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
44163 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44164
44165 /* Parameter declarations */
44166 static int cardtype[IVTV_MAX_CARDS];
44167 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44168 index dfd0a21..6bbb465 100644
44169 --- a/drivers/media/platform/omap/omap_vout.c
44170 +++ b/drivers/media/platform/omap/omap_vout.c
44171 @@ -63,7 +63,6 @@ enum omap_vout_channels {
44172 OMAP_VIDEO2,
44173 };
44174
44175 -static struct videobuf_queue_ops video_vbq_ops;
44176 /* Variables configurable through module params*/
44177 static u32 video1_numbuffers = 3;
44178 static u32 video2_numbuffers = 3;
44179 @@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44180 {
44181 struct videobuf_queue *q;
44182 struct omap_vout_device *vout = NULL;
44183 + static struct videobuf_queue_ops video_vbq_ops = {
44184 + .buf_setup = omap_vout_buffer_setup,
44185 + .buf_prepare = omap_vout_buffer_prepare,
44186 + .buf_release = omap_vout_buffer_release,
44187 + .buf_queue = omap_vout_buffer_queue,
44188 + };
44189
44190 vout = video_drvdata(file);
44191 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44192 @@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44193 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44194
44195 q = &vout->vbq;
44196 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44197 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44198 - video_vbq_ops.buf_release = omap_vout_buffer_release;
44199 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44200 spin_lock_init(&vout->vbq_lock);
44201
44202 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44203 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44204 index fb2acc5..a2fcbdc4 100644
44205 --- a/drivers/media/platform/s5p-tv/mixer.h
44206 +++ b/drivers/media/platform/s5p-tv/mixer.h
44207 @@ -156,7 +156,7 @@ struct mxr_layer {
44208 /** layer index (unique identifier) */
44209 int idx;
44210 /** callbacks for layer methods */
44211 - struct mxr_layer_ops ops;
44212 + struct mxr_layer_ops *ops;
44213 /** format array */
44214 const struct mxr_format **fmt_array;
44215 /** size of format array */
44216 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44217 index 74344c7..a39e70e 100644
44218 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44219 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44220 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44221 {
44222 struct mxr_layer *layer;
44223 int ret;
44224 - struct mxr_layer_ops ops = {
44225 + static struct mxr_layer_ops ops = {
44226 .release = mxr_graph_layer_release,
44227 .buffer_set = mxr_graph_buffer_set,
44228 .stream_set = mxr_graph_stream_set,
44229 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44230 index b713403..53cb5ad 100644
44231 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
44232 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44233 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44234 layer->update_buf = next;
44235 }
44236
44237 - layer->ops.buffer_set(layer, layer->update_buf);
44238 + layer->ops->buffer_set(layer, layer->update_buf);
44239
44240 if (done && done != layer->shadow_buf)
44241 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44242 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44243 index c5059ba..2649f28 100644
44244 --- a/drivers/media/platform/s5p-tv/mixer_video.c
44245 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
44246 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44247 layer->geo.src.height = layer->geo.src.full_height;
44248
44249 mxr_geometry_dump(mdev, &layer->geo);
44250 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44251 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44252 mxr_geometry_dump(mdev, &layer->geo);
44253 }
44254
44255 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44256 layer->geo.dst.full_width = mbus_fmt.width;
44257 layer->geo.dst.full_height = mbus_fmt.height;
44258 layer->geo.dst.field = mbus_fmt.field;
44259 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44260 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44261
44262 mxr_geometry_dump(mdev, &layer->geo);
44263 }
44264 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44265 /* set source size to highest accepted value */
44266 geo->src.full_width = max(geo->dst.full_width, pix->width);
44267 geo->src.full_height = max(geo->dst.full_height, pix->height);
44268 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44269 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44270 mxr_geometry_dump(mdev, &layer->geo);
44271 /* set cropping to total visible screen */
44272 geo->src.width = pix->width;
44273 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44274 geo->src.x_offset = 0;
44275 geo->src.y_offset = 0;
44276 /* assure consistency of geometry */
44277 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44278 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44279 mxr_geometry_dump(mdev, &layer->geo);
44280 /* set full size to lowest possible value */
44281 geo->src.full_width = 0;
44282 geo->src.full_height = 0;
44283 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44284 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44285 mxr_geometry_dump(mdev, &layer->geo);
44286
44287 /* returning results */
44288 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44289 target->width = s->r.width;
44290 target->height = s->r.height;
44291
44292 - layer->ops.fix_geometry(layer, stage, s->flags);
44293 + layer->ops->fix_geometry(layer, stage, s->flags);
44294
44295 /* retrieve update selection rectangle */
44296 res.left = target->x_offset;
44297 @@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44298 mxr_output_get(mdev);
44299
44300 mxr_layer_update_output(layer);
44301 - layer->ops.format_set(layer);
44302 + layer->ops->format_set(layer);
44303 /* enabling layer in hardware */
44304 spin_lock_irqsave(&layer->enq_slock, flags);
44305 layer->state = MXR_LAYER_STREAMING;
44306 spin_unlock_irqrestore(&layer->enq_slock, flags);
44307
44308 - layer->ops.stream_set(layer, MXR_ENABLE);
44309 + layer->ops->stream_set(layer, MXR_ENABLE);
44310 mxr_streamer_get(mdev);
44311
44312 return 0;
44313 @@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44314 spin_unlock_irqrestore(&layer->enq_slock, flags);
44315
44316 /* disabling layer in hardware */
44317 - layer->ops.stream_set(layer, MXR_DISABLE);
44318 + layer->ops->stream_set(layer, MXR_DISABLE);
44319 /* remove one streamer */
44320 mxr_streamer_put(mdev);
44321 /* allow changes in output configuration */
44322 @@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44323
44324 void mxr_layer_release(struct mxr_layer *layer)
44325 {
44326 - if (layer->ops.release)
44327 - layer->ops.release(layer);
44328 + if (layer->ops->release)
44329 + layer->ops->release(layer);
44330 }
44331
44332 void mxr_base_layer_release(struct mxr_layer *layer)
44333 @@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44334
44335 layer->mdev = mdev;
44336 layer->idx = idx;
44337 - layer->ops = *ops;
44338 + layer->ops = ops;
44339
44340 spin_lock_init(&layer->enq_slock);
44341 INIT_LIST_HEAD(&layer->enq_list);
44342 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44343 index c9388c4..ce71ece 100644
44344 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44345 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44346 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44347 {
44348 struct mxr_layer *layer;
44349 int ret;
44350 - struct mxr_layer_ops ops = {
44351 + static struct mxr_layer_ops ops = {
44352 .release = mxr_vp_layer_release,
44353 .buffer_set = mxr_vp_buffer_set,
44354 .stream_set = mxr_vp_stream_set,
44355 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44356 index 2d4e73b..8b4d5b6 100644
44357 --- a/drivers/media/platform/vivi.c
44358 +++ b/drivers/media/platform/vivi.c
44359 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44360 MODULE_LICENSE("Dual BSD/GPL");
44361 MODULE_VERSION(VIVI_VERSION);
44362
44363 -static unsigned video_nr = -1;
44364 -module_param(video_nr, uint, 0644);
44365 +static int video_nr = -1;
44366 +module_param(video_nr, int, 0644);
44367 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44368
44369 static unsigned n_devs = 1;
44370 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44371 index 545c04c..a14bded 100644
44372 --- a/drivers/media/radio/radio-cadet.c
44373 +++ b/drivers/media/radio/radio-cadet.c
44374 @@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44375 unsigned char readbuf[RDS_BUFFER];
44376 int i = 0;
44377
44378 + if (count > RDS_BUFFER)
44379 + return -EFAULT;
44380 mutex_lock(&dev->lock);
44381 if (dev->rdsstat == 0)
44382 cadet_start_rds(dev);
44383 @@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44384 while (i < count && dev->rdsin != dev->rdsout)
44385 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44386
44387 - if (i && copy_to_user(data, readbuf, i))
44388 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
44389 i = -EFAULT;
44390 unlock:
44391 mutex_unlock(&dev->lock);
44392 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44393 index 5236035..c622c74 100644
44394 --- a/drivers/media/radio/radio-maxiradio.c
44395 +++ b/drivers/media/radio/radio-maxiradio.c
44396 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44397 /* TEA5757 pin mappings */
44398 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44399
44400 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44401 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44402
44403 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44404 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44405 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44406 index 050b3bb..79f62b9 100644
44407 --- a/drivers/media/radio/radio-shark.c
44408 +++ b/drivers/media/radio/radio-shark.c
44409 @@ -79,7 +79,7 @@ struct shark_device {
44410 u32 last_val;
44411 };
44412
44413 -static atomic_t shark_instance = ATOMIC_INIT(0);
44414 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44415
44416 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44417 {
44418 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44419 index 8654e0d..0608a64 100644
44420 --- a/drivers/media/radio/radio-shark2.c
44421 +++ b/drivers/media/radio/radio-shark2.c
44422 @@ -74,7 +74,7 @@ struct shark_device {
44423 u8 *transfer_buffer;
44424 };
44425
44426 -static atomic_t shark_instance = ATOMIC_INIT(0);
44427 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44428
44429 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44430 {
44431 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44432 index 2fd9009..278cc1e 100644
44433 --- a/drivers/media/radio/radio-si476x.c
44434 +++ b/drivers/media/radio/radio-si476x.c
44435 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44436 struct si476x_radio *radio;
44437 struct v4l2_ctrl *ctrl;
44438
44439 - static atomic_t instance = ATOMIC_INIT(0);
44440 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
44441
44442 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44443 if (!radio)
44444 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44445 index a1c641e..3007da9 100644
44446 --- a/drivers/media/usb/dvb-usb/cxusb.c
44447 +++ b/drivers/media/usb/dvb-usb/cxusb.c
44448 @@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44449
44450 struct dib0700_adapter_state {
44451 int (*set_param_save) (struct dvb_frontend *);
44452 -};
44453 +} __no_const;
44454
44455 static int dib7070_set_param_override(struct dvb_frontend *fe)
44456 {
44457 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44458 index ae0f56a..ec71784 100644
44459 --- a/drivers/media/usb/dvb-usb/dw2102.c
44460 +++ b/drivers/media/usb/dvb-usb/dw2102.c
44461 @@ -118,7 +118,7 @@ struct su3000_state {
44462
44463 struct s6x0_state {
44464 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44465 -};
44466 +} __no_const;
44467
44468 /* debug */
44469 static int dvb_usb_dw2102_debug;
44470 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44471 index 8f7a6a4..eb0e1d4 100644
44472 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44473 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44474 @@ -326,7 +326,7 @@ struct v4l2_buffer32 {
44475 __u32 reserved;
44476 };
44477
44478 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44479 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44480 enum v4l2_memory memory)
44481 {
44482 void __user *up_pln;
44483 @@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44484 return 0;
44485 }
44486
44487 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44488 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44489 enum v4l2_memory memory)
44490 {
44491 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44492 @@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44493 * by passing a very big num_planes value */
44494 uplane = compat_alloc_user_space(num_planes *
44495 sizeof(struct v4l2_plane));
44496 - kp->m.planes = uplane;
44497 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44498
44499 while (--num_planes >= 0) {
44500 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44501 @@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44502 if (num_planes == 0)
44503 return 0;
44504
44505 - uplane = kp->m.planes;
44506 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44507 if (get_user(p, &up->m.planes))
44508 return -EFAULT;
44509 uplane32 = compat_ptr(p);
44510 @@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44511 get_user(kp->capability, &up->capability) ||
44512 get_user(kp->flags, &up->flags))
44513 return -EFAULT;
44514 - kp->base = compat_ptr(tmp);
44515 + kp->base = (void __force_kernel *)compat_ptr(tmp);
44516 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44517 return 0;
44518 }
44519 @@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44520 n * sizeof(struct v4l2_ext_control32)))
44521 return -EFAULT;
44522 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44523 - kp->controls = kcontrols;
44524 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44525 while (--n >= 0) {
44526 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44527 return -EFAULT;
44528 @@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44529 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44530 {
44531 struct v4l2_ext_control32 __user *ucontrols;
44532 - struct v4l2_ext_control __user *kcontrols = kp->controls;
44533 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44534 int n = kp->count;
44535 compat_caddr_t p;
44536
44537 @@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
44538 put_user(kp->start_block, &up->start_block) ||
44539 put_user(kp->blocks, &up->blocks) ||
44540 put_user(tmp, &up->edid) ||
44541 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44542 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44543 return -EFAULT;
44544 return 0;
44545 }
44546 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44547 index 6ff002b..6b9316b 100644
44548 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
44549 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44550 @@ -1401,8 +1401,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44551 return 0;
44552
44553 case V4L2_CTRL_TYPE_STRING:
44554 - len = strlen(c->string);
44555 - if (len < ctrl->minimum)
44556 + len = strlen_user(c->string);
44557 + if (!len || len < ctrl->minimum)
44558 return -ERANGE;
44559 if ((len - ctrl->minimum) % ctrl->step)
44560 return -ERANGE;
44561 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44562 index 02d1b63..5fd6b16 100644
44563 --- a/drivers/media/v4l2-core/v4l2-device.c
44564 +++ b/drivers/media/v4l2-core/v4l2-device.c
44565 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44566 EXPORT_SYMBOL_GPL(v4l2_device_put);
44567
44568 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44569 - atomic_t *instance)
44570 + atomic_unchecked_t *instance)
44571 {
44572 - int num = atomic_inc_return(instance) - 1;
44573 + int num = atomic_inc_return_unchecked(instance) - 1;
44574 int len = strlen(basename);
44575
44576 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44577 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44578 index 707aef7..93b8ac0 100644
44579 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
44580 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44581 @@ -1942,7 +1942,8 @@ struct v4l2_ioctl_info {
44582 struct file *file, void *fh, void *p);
44583 } u;
44584 void (*debug)(const void *arg, bool write_only);
44585 -};
44586 +} __do_const;
44587 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44588
44589 /* This control needs a priority check */
44590 #define INFO_FL_PRIO (1 << 0)
44591 @@ -2123,7 +2124,7 @@ static long __video_do_ioctl(struct file *file,
44592 struct video_device *vfd = video_devdata(file);
44593 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44594 bool write_only = false;
44595 - struct v4l2_ioctl_info default_info;
44596 + v4l2_ioctl_info_no_const default_info;
44597 const struct v4l2_ioctl_info *info;
44598 void *fh = file->private_data;
44599 struct v4l2_fh *vfh = NULL;
44600 @@ -2197,7 +2198,7 @@ done:
44601 }
44602
44603 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44604 - void * __user *user_ptr, void ***kernel_ptr)
44605 + void __user **user_ptr, void ***kernel_ptr)
44606 {
44607 int ret = 0;
44608
44609 @@ -2213,7 +2214,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44610 ret = -EINVAL;
44611 break;
44612 }
44613 - *user_ptr = (void __user *)buf->m.planes;
44614 + *user_ptr = (void __force_user *)buf->m.planes;
44615 *kernel_ptr = (void *)&buf->m.planes;
44616 *array_size = sizeof(struct v4l2_plane) * buf->length;
44617 ret = 1;
44618 @@ -2248,7 +2249,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44619 ret = -EINVAL;
44620 break;
44621 }
44622 - *user_ptr = (void __user *)ctrls->controls;
44623 + *user_ptr = (void __force_user *)ctrls->controls;
44624 *kernel_ptr = (void *)&ctrls->controls;
44625 *array_size = sizeof(struct v4l2_ext_control)
44626 * ctrls->count;
44627 @@ -2349,7 +2350,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44628 }
44629
44630 if (has_array_args) {
44631 - *kernel_ptr = user_ptr;
44632 + *kernel_ptr = (void __force_kernel *)user_ptr;
44633 if (copy_to_user(user_ptr, mbuf, array_size))
44634 err = -EFAULT;
44635 goto out_array_args;
44636 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44637 index 570b18a..f880314 100644
44638 --- a/drivers/message/fusion/mptbase.c
44639 +++ b/drivers/message/fusion/mptbase.c
44640 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44641 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44642 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44643
44644 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44645 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44646 +#else
44647 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44648 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44649 +#endif
44650 +
44651 /*
44652 * Rounding UP to nearest 4-kB boundary here...
44653 */
44654 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44655 ioc->facts.GlobalCredits);
44656
44657 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44658 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44659 + NULL, NULL);
44660 +#else
44661 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44662 +#endif
44663 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44664 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44665 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44666 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44667 index 00d339c..2ea899d 100644
44668 --- a/drivers/message/fusion/mptsas.c
44669 +++ b/drivers/message/fusion/mptsas.c
44670 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44671 return 0;
44672 }
44673
44674 +static inline void
44675 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44676 +{
44677 + if (phy_info->port_details) {
44678 + phy_info->port_details->rphy = rphy;
44679 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44680 + ioc->name, rphy));
44681 + }
44682 +
44683 + if (rphy) {
44684 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44685 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44686 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44687 + ioc->name, rphy, rphy->dev.release));
44688 + }
44689 +}
44690 +
44691 /* no mutex */
44692 static void
44693 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44694 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44695 return NULL;
44696 }
44697
44698 -static inline void
44699 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44700 -{
44701 - if (phy_info->port_details) {
44702 - phy_info->port_details->rphy = rphy;
44703 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44704 - ioc->name, rphy));
44705 - }
44706 -
44707 - if (rphy) {
44708 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44709 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44710 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44711 - ioc->name, rphy, rphy->dev.release));
44712 - }
44713 -}
44714 -
44715 static inline struct sas_port *
44716 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44717 {
44718 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44719 index 727819c..ad74694 100644
44720 --- a/drivers/message/fusion/mptscsih.c
44721 +++ b/drivers/message/fusion/mptscsih.c
44722 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44723
44724 h = shost_priv(SChost);
44725
44726 - if (h) {
44727 - if (h->info_kbuf == NULL)
44728 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44729 - return h->info_kbuf;
44730 - h->info_kbuf[0] = '\0';
44731 + if (!h)
44732 + return NULL;
44733
44734 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44735 - h->info_kbuf[size-1] = '\0';
44736 - }
44737 + if (h->info_kbuf == NULL)
44738 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44739 + return h->info_kbuf;
44740 + h->info_kbuf[0] = '\0';
44741 +
44742 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44743 + h->info_kbuf[size-1] = '\0';
44744
44745 return h->info_kbuf;
44746 }
44747 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44748 index b7d87cd..3fb36da 100644
44749 --- a/drivers/message/i2o/i2o_proc.c
44750 +++ b/drivers/message/i2o/i2o_proc.c
44751 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44752 "Array Controller Device"
44753 };
44754
44755 -static char *chtostr(char *tmp, u8 *chars, int n)
44756 -{
44757 - tmp[0] = 0;
44758 - return strncat(tmp, (char *)chars, n);
44759 -}
44760 -
44761 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44762 char *group)
44763 {
44764 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44765 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44766 {
44767 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44768 - static u32 work32[5];
44769 - static u8 *work8 = (u8 *) work32;
44770 - static u16 *work16 = (u16 *) work32;
44771 + u32 work32[5];
44772 + u8 *work8 = (u8 *) work32;
44773 + u16 *work16 = (u16 *) work32;
44774 int token;
44775 u32 hwcap;
44776
44777 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44778 } *result;
44779
44780 i2o_exec_execute_ddm_table ddm_table;
44781 - char tmp[28 + 1];
44782
44783 result = kmalloc(sizeof(*result), GFP_KERNEL);
44784 if (!result)
44785 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44786
44787 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44788 seq_printf(seq, "%-#8x", ddm_table.module_id);
44789 - seq_printf(seq, "%-29s",
44790 - chtostr(tmp, ddm_table.module_name_version, 28));
44791 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44792 seq_printf(seq, "%9d ", ddm_table.data_size);
44793 seq_printf(seq, "%8d", ddm_table.code_size);
44794
44795 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44796
44797 i2o_driver_result_table *result;
44798 i2o_driver_store_table *dst;
44799 - char tmp[28 + 1];
44800
44801 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44802 if (result == NULL)
44803 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44804
44805 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44806 seq_printf(seq, "%-#8x", dst->module_id);
44807 - seq_printf(seq, "%-29s",
44808 - chtostr(tmp, dst->module_name_version, 28));
44809 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44810 + seq_printf(seq, "%-.28s", dst->module_name_version);
44811 + seq_printf(seq, "%-.8s", dst->date);
44812 seq_printf(seq, "%8d ", dst->module_size);
44813 seq_printf(seq, "%8d ", dst->mpb_size);
44814 seq_printf(seq, "0x%04x", dst->module_flags);
44815 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44816 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44817 {
44818 struct i2o_device *d = (struct i2o_device *)seq->private;
44819 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44820 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44821 // == (allow) 512d bytes (max)
44822 - static u16 *work16 = (u16 *) work32;
44823 + u16 *work16 = (u16 *) work32;
44824 int token;
44825 - char tmp[16 + 1];
44826
44827 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44828
44829 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44830 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44831 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44832 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44833 - seq_printf(seq, "Vendor info : %s\n",
44834 - chtostr(tmp, (u8 *) (work32 + 2), 16));
44835 - seq_printf(seq, "Product info : %s\n",
44836 - chtostr(tmp, (u8 *) (work32 + 6), 16));
44837 - seq_printf(seq, "Description : %s\n",
44838 - chtostr(tmp, (u8 *) (work32 + 10), 16));
44839 - seq_printf(seq, "Product rev. : %s\n",
44840 - chtostr(tmp, (u8 *) (work32 + 14), 8));
44841 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44842 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44843 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44844 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44845
44846 seq_printf(seq, "Serial number : ");
44847 print_serial_number(seq, (u8 *) (work32 + 16),
44848 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44849 u8 pad[256]; // allow up to 256 byte (max) serial number
44850 } result;
44851
44852 - char tmp[24 + 1];
44853 -
44854 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44855
44856 if (token < 0) {
44857 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44858 }
44859
44860 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44861 - seq_printf(seq, "Module name : %s\n",
44862 - chtostr(tmp, result.module_name, 24));
44863 - seq_printf(seq, "Module revision : %s\n",
44864 - chtostr(tmp, result.module_rev, 8));
44865 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
44866 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44867
44868 seq_printf(seq, "Serial number : ");
44869 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44870 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44871 u8 instance_number[4];
44872 } result;
44873
44874 - char tmp[64 + 1];
44875 -
44876 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44877
44878 if (token < 0) {
44879 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44880 return 0;
44881 }
44882
44883 - seq_printf(seq, "Device name : %s\n",
44884 - chtostr(tmp, result.device_name, 64));
44885 - seq_printf(seq, "Service name : %s\n",
44886 - chtostr(tmp, result.service_name, 64));
44887 - seq_printf(seq, "Physical name : %s\n",
44888 - chtostr(tmp, result.physical_location, 64));
44889 - seq_printf(seq, "Instance number : %s\n",
44890 - chtostr(tmp, result.instance_number, 4));
44891 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
44892 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
44893 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
44894 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
44895
44896 return 0;
44897 }
44898 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44899 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
44900 {
44901 struct i2o_device *d = (struct i2o_device *)seq->private;
44902 - static u32 work32[12];
44903 - static u16 *work16 = (u16 *) work32;
44904 - static u8 *work8 = (u8 *) work32;
44905 + u32 work32[12];
44906 + u16 *work16 = (u16 *) work32;
44907 + u8 *work8 = (u8 *) work32;
44908 int token;
44909
44910 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
44911 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
44912 index a8c08f3..155fe3d 100644
44913 --- a/drivers/message/i2o/iop.c
44914 +++ b/drivers/message/i2o/iop.c
44915 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
44916
44917 spin_lock_irqsave(&c->context_list_lock, flags);
44918
44919 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
44920 - atomic_inc(&c->context_list_counter);
44921 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
44922 + atomic_inc_unchecked(&c->context_list_counter);
44923
44924 - entry->context = atomic_read(&c->context_list_counter);
44925 + entry->context = atomic_read_unchecked(&c->context_list_counter);
44926
44927 list_add(&entry->list, &c->context_list);
44928
44929 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
44930
44931 #if BITS_PER_LONG == 64
44932 spin_lock_init(&c->context_list_lock);
44933 - atomic_set(&c->context_list_counter, 0);
44934 + atomic_set_unchecked(&c->context_list_counter, 0);
44935 INIT_LIST_HEAD(&c->context_list);
44936 #endif
44937
44938 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
44939 index d1a22aa..d0f7bf7 100644
44940 --- a/drivers/mfd/ab8500-debugfs.c
44941 +++ b/drivers/mfd/ab8500-debugfs.c
44942 @@ -100,7 +100,7 @@ static int irq_last;
44943 static u32 *irq_count;
44944 static int num_irqs;
44945
44946 -static struct device_attribute **dev_attr;
44947 +static device_attribute_no_const **dev_attr;
44948 static char **event_name;
44949
44950 static u8 avg_sample = SAMPLE_16;
44951 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
44952 index 81b7d88..95ae998 100644
44953 --- a/drivers/mfd/janz-cmodio.c
44954 +++ b/drivers/mfd/janz-cmodio.c
44955 @@ -13,6 +13,7 @@
44956
44957 #include <linux/kernel.h>
44958 #include <linux/module.h>
44959 +#include <linux/slab.h>
44960 #include <linux/init.h>
44961 #include <linux/pci.h>
44962 #include <linux/interrupt.h>
44963 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
44964 index 176aa26..27811b2 100644
44965 --- a/drivers/mfd/max8925-i2c.c
44966 +++ b/drivers/mfd/max8925-i2c.c
44967 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
44968 const struct i2c_device_id *id)
44969 {
44970 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
44971 - static struct max8925_chip *chip;
44972 + struct max8925_chip *chip;
44973 struct device_node *node = client->dev.of_node;
44974
44975 if (node && !pdata) {
44976 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
44977 index 1f142d7..cc52c2a 100644
44978 --- a/drivers/mfd/tps65910.c
44979 +++ b/drivers/mfd/tps65910.c
44980 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
44981 struct tps65910_platform_data *pdata)
44982 {
44983 int ret = 0;
44984 - static struct regmap_irq_chip *tps6591x_irqs_chip;
44985 + struct regmap_irq_chip *tps6591x_irqs_chip;
44986
44987 if (!irq) {
44988 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
44989 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
44990 index 9aa6d1e..1631bfc 100644
44991 --- a/drivers/mfd/twl4030-irq.c
44992 +++ b/drivers/mfd/twl4030-irq.c
44993 @@ -35,6 +35,7 @@
44994 #include <linux/of.h>
44995 #include <linux/irqdomain.h>
44996 #include <linux/i2c/twl.h>
44997 +#include <asm/pgtable.h>
44998
44999 #include "twl-core.h"
45000
45001 @@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45002 * Install an irq handler for each of the SIH modules;
45003 * clone dummy irq_chip since PIH can't *do* anything
45004 */
45005 - twl4030_irq_chip = dummy_irq_chip;
45006 - twl4030_irq_chip.name = "twl4030";
45007 + pax_open_kernel();
45008 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45009 + *(const char **)&twl4030_irq_chip.name = "twl4030";
45010
45011 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45012 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45013 + pax_close_kernel();
45014
45015 for (i = irq_base; i < irq_end; i++) {
45016 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45017 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45018 index 464419b..64bae8d 100644
45019 --- a/drivers/misc/c2port/core.c
45020 +++ b/drivers/misc/c2port/core.c
45021 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45022 goto error_idr_alloc;
45023 c2dev->id = ret;
45024
45025 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45026 + pax_open_kernel();
45027 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45028 + pax_close_kernel();
45029
45030 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45031 "c2port%d", c2dev->id);
45032 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45033 index 9c34e57..b981cda 100644
45034 --- a/drivers/misc/eeprom/sunxi_sid.c
45035 +++ b/drivers/misc/eeprom/sunxi_sid.c
45036 @@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45037
45038 platform_set_drvdata(pdev, sid_data);
45039
45040 - sid_bin_attr.size = sid_data->keysize;
45041 + pax_open_kernel();
45042 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45043 + pax_close_kernel();
45044 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45045 return -ENODEV;
45046
45047 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45048 index 36f5d52..32311c3 100644
45049 --- a/drivers/misc/kgdbts.c
45050 +++ b/drivers/misc/kgdbts.c
45051 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45052 char before[BREAK_INSTR_SIZE];
45053 char after[BREAK_INSTR_SIZE];
45054
45055 - probe_kernel_read(before, (char *)kgdbts_break_test,
45056 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45057 BREAK_INSTR_SIZE);
45058 init_simple_test();
45059 ts.tst = plant_and_detach_test;
45060 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45061 /* Activate test with initial breakpoint */
45062 if (!is_early)
45063 kgdb_breakpoint();
45064 - probe_kernel_read(after, (char *)kgdbts_break_test,
45065 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45066 BREAK_INSTR_SIZE);
45067 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45068 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45069 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45070 index 036effe..b3a6336 100644
45071 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
45072 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45073 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45074 * the lid is closed. This leads to interrupts as soon as a little move
45075 * is done.
45076 */
45077 - atomic_inc(&lis3->count);
45078 + atomic_inc_unchecked(&lis3->count);
45079
45080 wake_up_interruptible(&lis3->misc_wait);
45081 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45082 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45083 if (lis3->pm_dev)
45084 pm_runtime_get_sync(lis3->pm_dev);
45085
45086 - atomic_set(&lis3->count, 0);
45087 + atomic_set_unchecked(&lis3->count, 0);
45088 return 0;
45089 }
45090
45091 @@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45092 add_wait_queue(&lis3->misc_wait, &wait);
45093 while (true) {
45094 set_current_state(TASK_INTERRUPTIBLE);
45095 - data = atomic_xchg(&lis3->count, 0);
45096 + data = atomic_xchg_unchecked(&lis3->count, 0);
45097 if (data)
45098 break;
45099
45100 @@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45101 struct lis3lv02d, miscdev);
45102
45103 poll_wait(file, &lis3->misc_wait, wait);
45104 - if (atomic_read(&lis3->count))
45105 + if (atomic_read_unchecked(&lis3->count))
45106 return POLLIN | POLLRDNORM;
45107 return 0;
45108 }
45109 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45110 index c439c82..1f20f57 100644
45111 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
45112 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45113 @@ -297,7 +297,7 @@ struct lis3lv02d {
45114 struct input_polled_dev *idev; /* input device */
45115 struct platform_device *pdev; /* platform device */
45116 struct regulator_bulk_data regulators[2];
45117 - atomic_t count; /* interrupt count after last read */
45118 + atomic_unchecked_t count; /* interrupt count after last read */
45119 union axis_conversion ac; /* hw -> logical axis */
45120 int mapped_btns[3];
45121
45122 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45123 index 2f30bad..c4c13d0 100644
45124 --- a/drivers/misc/sgi-gru/gruhandles.c
45125 +++ b/drivers/misc/sgi-gru/gruhandles.c
45126 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45127 unsigned long nsec;
45128
45129 nsec = CLKS2NSEC(clks);
45130 - atomic_long_inc(&mcs_op_statistics[op].count);
45131 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
45132 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45133 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45134 if (mcs_op_statistics[op].max < nsec)
45135 mcs_op_statistics[op].max = nsec;
45136 }
45137 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45138 index 4f76359..cdfcb2e 100644
45139 --- a/drivers/misc/sgi-gru/gruprocfs.c
45140 +++ b/drivers/misc/sgi-gru/gruprocfs.c
45141 @@ -32,9 +32,9 @@
45142
45143 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45144
45145 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45146 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45147 {
45148 - unsigned long val = atomic_long_read(v);
45149 + unsigned long val = atomic_long_read_unchecked(v);
45150
45151 seq_printf(s, "%16lu %s\n", val, id);
45152 }
45153 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45154
45155 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45156 for (op = 0; op < mcsop_last; op++) {
45157 - count = atomic_long_read(&mcs_op_statistics[op].count);
45158 - total = atomic_long_read(&mcs_op_statistics[op].total);
45159 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45160 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45161 max = mcs_op_statistics[op].max;
45162 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45163 count ? total / count : 0, max);
45164 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45165 index 5c3ce24..4915ccb 100644
45166 --- a/drivers/misc/sgi-gru/grutables.h
45167 +++ b/drivers/misc/sgi-gru/grutables.h
45168 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45169 * GRU statistics.
45170 */
45171 struct gru_stats_s {
45172 - atomic_long_t vdata_alloc;
45173 - atomic_long_t vdata_free;
45174 - atomic_long_t gts_alloc;
45175 - atomic_long_t gts_free;
45176 - atomic_long_t gms_alloc;
45177 - atomic_long_t gms_free;
45178 - atomic_long_t gts_double_allocate;
45179 - atomic_long_t assign_context;
45180 - atomic_long_t assign_context_failed;
45181 - atomic_long_t free_context;
45182 - atomic_long_t load_user_context;
45183 - atomic_long_t load_kernel_context;
45184 - atomic_long_t lock_kernel_context;
45185 - atomic_long_t unlock_kernel_context;
45186 - atomic_long_t steal_user_context;
45187 - atomic_long_t steal_kernel_context;
45188 - atomic_long_t steal_context_failed;
45189 - atomic_long_t nopfn;
45190 - atomic_long_t asid_new;
45191 - atomic_long_t asid_next;
45192 - atomic_long_t asid_wrap;
45193 - atomic_long_t asid_reuse;
45194 - atomic_long_t intr;
45195 - atomic_long_t intr_cbr;
45196 - atomic_long_t intr_tfh;
45197 - atomic_long_t intr_spurious;
45198 - atomic_long_t intr_mm_lock_failed;
45199 - atomic_long_t call_os;
45200 - atomic_long_t call_os_wait_queue;
45201 - atomic_long_t user_flush_tlb;
45202 - atomic_long_t user_unload_context;
45203 - atomic_long_t user_exception;
45204 - atomic_long_t set_context_option;
45205 - atomic_long_t check_context_retarget_intr;
45206 - atomic_long_t check_context_unload;
45207 - atomic_long_t tlb_dropin;
45208 - atomic_long_t tlb_preload_page;
45209 - atomic_long_t tlb_dropin_fail_no_asid;
45210 - atomic_long_t tlb_dropin_fail_upm;
45211 - atomic_long_t tlb_dropin_fail_invalid;
45212 - atomic_long_t tlb_dropin_fail_range_active;
45213 - atomic_long_t tlb_dropin_fail_idle;
45214 - atomic_long_t tlb_dropin_fail_fmm;
45215 - atomic_long_t tlb_dropin_fail_no_exception;
45216 - atomic_long_t tfh_stale_on_fault;
45217 - atomic_long_t mmu_invalidate_range;
45218 - atomic_long_t mmu_invalidate_page;
45219 - atomic_long_t flush_tlb;
45220 - atomic_long_t flush_tlb_gru;
45221 - atomic_long_t flush_tlb_gru_tgh;
45222 - atomic_long_t flush_tlb_gru_zero_asid;
45223 + atomic_long_unchecked_t vdata_alloc;
45224 + atomic_long_unchecked_t vdata_free;
45225 + atomic_long_unchecked_t gts_alloc;
45226 + atomic_long_unchecked_t gts_free;
45227 + atomic_long_unchecked_t gms_alloc;
45228 + atomic_long_unchecked_t gms_free;
45229 + atomic_long_unchecked_t gts_double_allocate;
45230 + atomic_long_unchecked_t assign_context;
45231 + atomic_long_unchecked_t assign_context_failed;
45232 + atomic_long_unchecked_t free_context;
45233 + atomic_long_unchecked_t load_user_context;
45234 + atomic_long_unchecked_t load_kernel_context;
45235 + atomic_long_unchecked_t lock_kernel_context;
45236 + atomic_long_unchecked_t unlock_kernel_context;
45237 + atomic_long_unchecked_t steal_user_context;
45238 + atomic_long_unchecked_t steal_kernel_context;
45239 + atomic_long_unchecked_t steal_context_failed;
45240 + atomic_long_unchecked_t nopfn;
45241 + atomic_long_unchecked_t asid_new;
45242 + atomic_long_unchecked_t asid_next;
45243 + atomic_long_unchecked_t asid_wrap;
45244 + atomic_long_unchecked_t asid_reuse;
45245 + atomic_long_unchecked_t intr;
45246 + atomic_long_unchecked_t intr_cbr;
45247 + atomic_long_unchecked_t intr_tfh;
45248 + atomic_long_unchecked_t intr_spurious;
45249 + atomic_long_unchecked_t intr_mm_lock_failed;
45250 + atomic_long_unchecked_t call_os;
45251 + atomic_long_unchecked_t call_os_wait_queue;
45252 + atomic_long_unchecked_t user_flush_tlb;
45253 + atomic_long_unchecked_t user_unload_context;
45254 + atomic_long_unchecked_t user_exception;
45255 + atomic_long_unchecked_t set_context_option;
45256 + atomic_long_unchecked_t check_context_retarget_intr;
45257 + atomic_long_unchecked_t check_context_unload;
45258 + atomic_long_unchecked_t tlb_dropin;
45259 + atomic_long_unchecked_t tlb_preload_page;
45260 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45261 + atomic_long_unchecked_t tlb_dropin_fail_upm;
45262 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
45263 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
45264 + atomic_long_unchecked_t tlb_dropin_fail_idle;
45265 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
45266 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45267 + atomic_long_unchecked_t tfh_stale_on_fault;
45268 + atomic_long_unchecked_t mmu_invalidate_range;
45269 + atomic_long_unchecked_t mmu_invalidate_page;
45270 + atomic_long_unchecked_t flush_tlb;
45271 + atomic_long_unchecked_t flush_tlb_gru;
45272 + atomic_long_unchecked_t flush_tlb_gru_tgh;
45273 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45274
45275 - atomic_long_t copy_gpa;
45276 - atomic_long_t read_gpa;
45277 + atomic_long_unchecked_t copy_gpa;
45278 + atomic_long_unchecked_t read_gpa;
45279
45280 - atomic_long_t mesq_receive;
45281 - atomic_long_t mesq_receive_none;
45282 - atomic_long_t mesq_send;
45283 - atomic_long_t mesq_send_failed;
45284 - atomic_long_t mesq_noop;
45285 - atomic_long_t mesq_send_unexpected_error;
45286 - atomic_long_t mesq_send_lb_overflow;
45287 - atomic_long_t mesq_send_qlimit_reached;
45288 - atomic_long_t mesq_send_amo_nacked;
45289 - atomic_long_t mesq_send_put_nacked;
45290 - atomic_long_t mesq_page_overflow;
45291 - atomic_long_t mesq_qf_locked;
45292 - atomic_long_t mesq_qf_noop_not_full;
45293 - atomic_long_t mesq_qf_switch_head_failed;
45294 - atomic_long_t mesq_qf_unexpected_error;
45295 - atomic_long_t mesq_noop_unexpected_error;
45296 - atomic_long_t mesq_noop_lb_overflow;
45297 - atomic_long_t mesq_noop_qlimit_reached;
45298 - atomic_long_t mesq_noop_amo_nacked;
45299 - atomic_long_t mesq_noop_put_nacked;
45300 - atomic_long_t mesq_noop_page_overflow;
45301 + atomic_long_unchecked_t mesq_receive;
45302 + atomic_long_unchecked_t mesq_receive_none;
45303 + atomic_long_unchecked_t mesq_send;
45304 + atomic_long_unchecked_t mesq_send_failed;
45305 + atomic_long_unchecked_t mesq_noop;
45306 + atomic_long_unchecked_t mesq_send_unexpected_error;
45307 + atomic_long_unchecked_t mesq_send_lb_overflow;
45308 + atomic_long_unchecked_t mesq_send_qlimit_reached;
45309 + atomic_long_unchecked_t mesq_send_amo_nacked;
45310 + atomic_long_unchecked_t mesq_send_put_nacked;
45311 + atomic_long_unchecked_t mesq_page_overflow;
45312 + atomic_long_unchecked_t mesq_qf_locked;
45313 + atomic_long_unchecked_t mesq_qf_noop_not_full;
45314 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
45315 + atomic_long_unchecked_t mesq_qf_unexpected_error;
45316 + atomic_long_unchecked_t mesq_noop_unexpected_error;
45317 + atomic_long_unchecked_t mesq_noop_lb_overflow;
45318 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
45319 + atomic_long_unchecked_t mesq_noop_amo_nacked;
45320 + atomic_long_unchecked_t mesq_noop_put_nacked;
45321 + atomic_long_unchecked_t mesq_noop_page_overflow;
45322
45323 };
45324
45325 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45326 tghop_invalidate, mcsop_last};
45327
45328 struct mcs_op_statistic {
45329 - atomic_long_t count;
45330 - atomic_long_t total;
45331 + atomic_long_unchecked_t count;
45332 + atomic_long_unchecked_t total;
45333 unsigned long max;
45334 };
45335
45336 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45337
45338 #define STAT(id) do { \
45339 if (gru_options & OPT_STATS) \
45340 - atomic_long_inc(&gru_stats.id); \
45341 + atomic_long_inc_unchecked(&gru_stats.id); \
45342 } while (0)
45343
45344 #ifdef CONFIG_SGI_GRU_DEBUG
45345 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45346 index c862cd4..0d176fe 100644
45347 --- a/drivers/misc/sgi-xp/xp.h
45348 +++ b/drivers/misc/sgi-xp/xp.h
45349 @@ -288,7 +288,7 @@ struct xpc_interface {
45350 xpc_notify_func, void *);
45351 void (*received) (short, int, void *);
45352 enum xp_retval (*partid_to_nasids) (short, void *);
45353 -};
45354 +} __no_const;
45355
45356 extern struct xpc_interface xpc_interface;
45357
45358 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45359 index 01be66d..e3a0c7e 100644
45360 --- a/drivers/misc/sgi-xp/xp_main.c
45361 +++ b/drivers/misc/sgi-xp/xp_main.c
45362 @@ -78,13 +78,13 @@ xpc_notloaded(void)
45363 }
45364
45365 struct xpc_interface xpc_interface = {
45366 - (void (*)(int))xpc_notloaded,
45367 - (void (*)(int))xpc_notloaded,
45368 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45369 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45370 + .connect = (void (*)(int))xpc_notloaded,
45371 + .disconnect = (void (*)(int))xpc_notloaded,
45372 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45373 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45374 void *))xpc_notloaded,
45375 - (void (*)(short, int, void *))xpc_notloaded,
45376 - (enum xp_retval(*)(short, void *))xpc_notloaded
45377 + .received = (void (*)(short, int, void *))xpc_notloaded,
45378 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45379 };
45380 EXPORT_SYMBOL_GPL(xpc_interface);
45381
45382 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45383 index b94d5f7..7f494c5 100644
45384 --- a/drivers/misc/sgi-xp/xpc.h
45385 +++ b/drivers/misc/sgi-xp/xpc.h
45386 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
45387 void (*received_payload) (struct xpc_channel *, void *);
45388 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45389 };
45390 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45391
45392 /* struct xpc_partition act_state values (for XPC HB) */
45393
45394 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45395 /* found in xpc_main.c */
45396 extern struct device *xpc_part;
45397 extern struct device *xpc_chan;
45398 -extern struct xpc_arch_operations xpc_arch_ops;
45399 +extern xpc_arch_operations_no_const xpc_arch_ops;
45400 extern int xpc_disengage_timelimit;
45401 extern int xpc_disengage_timedout;
45402 extern int xpc_activate_IRQ_rcvd;
45403 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45404 index 82dc574..8539ab2 100644
45405 --- a/drivers/misc/sgi-xp/xpc_main.c
45406 +++ b/drivers/misc/sgi-xp/xpc_main.c
45407 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45408 .notifier_call = xpc_system_die,
45409 };
45410
45411 -struct xpc_arch_operations xpc_arch_ops;
45412 +xpc_arch_operations_no_const xpc_arch_ops;
45413
45414 /*
45415 * Timer function to enforce the timelimit on the partition disengage.
45416 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45417
45418 if (((die_args->trapnr == X86_TRAP_MF) ||
45419 (die_args->trapnr == X86_TRAP_XF)) &&
45420 - !user_mode_vm(die_args->regs))
45421 + !user_mode(die_args->regs))
45422 xpc_die_deactivate();
45423
45424 break;
45425 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45426 index 7b5424f..ed1d6ac 100644
45427 --- a/drivers/mmc/card/block.c
45428 +++ b/drivers/mmc/card/block.c
45429 @@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45430 if (idata->ic.postsleep_min_us)
45431 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45432
45433 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45434 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45435 err = -EFAULT;
45436 goto cmd_rel_host;
45437 }
45438 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45439 index e5b5eeb..7bf2212 100644
45440 --- a/drivers/mmc/core/mmc_ops.c
45441 +++ b/drivers/mmc/core/mmc_ops.c
45442 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45443 void *data_buf;
45444 int is_on_stack;
45445
45446 - is_on_stack = object_is_on_stack(buf);
45447 + is_on_stack = object_starts_on_stack(buf);
45448 if (is_on_stack) {
45449 /*
45450 * dma onto stack is unsafe/nonportable, but callers to this
45451 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45452 index 6bf24ab..13d0293b 100644
45453 --- a/drivers/mmc/host/dw_mmc.h
45454 +++ b/drivers/mmc/host/dw_mmc.h
45455 @@ -258,5 +258,5 @@ struct dw_mci_drv_data {
45456 int (*parse_dt)(struct dw_mci *host);
45457 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45458 struct dw_mci_tuning_data *tuning_data);
45459 -};
45460 +} __do_const;
45461 #endif /* _DW_MMC_H_ */
45462 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45463 index b931226..df6a085 100644
45464 --- a/drivers/mmc/host/mmci.c
45465 +++ b/drivers/mmc/host/mmci.c
45466 @@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
45467 }
45468
45469 if (variant->busy_detect) {
45470 - mmci_ops.card_busy = mmci_card_busy;
45471 + pax_open_kernel();
45472 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
45473 + pax_close_kernel();
45474 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45475 }
45476
45477 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45478 index b841bb7..d82712f5 100644
45479 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
45480 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45481 @@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45482 host->mmc->caps |= MMC_CAP_1_8V_DDR;
45483 }
45484
45485 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45486 - sdhci_esdhc_ops.platform_execute_tuning =
45487 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45488 + pax_open_kernel();
45489 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45490 esdhc_executing_tuning;
45491 + pax_close_kernel();
45492 + }
45493
45494 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
45495 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
45496 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45497 index 6debda9..2ba7427 100644
45498 --- a/drivers/mmc/host/sdhci-s3c.c
45499 +++ b/drivers/mmc/host/sdhci-s3c.c
45500 @@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45501 * we can use overriding functions instead of default.
45502 */
45503 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45504 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45505 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45506 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45507 + pax_open_kernel();
45508 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45509 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45510 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45511 + pax_close_kernel();
45512 }
45513
45514 /* It supports additional host capabilities if needed */
45515 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45516 index 096993f..f02c23b 100644
45517 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
45518 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45519 @@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45520 size_t totlen = 0, thislen;
45521 int ret = 0;
45522 size_t buflen = 0;
45523 - static char *buffer;
45524 + char *buffer;
45525
45526 if (!ECCBUF_SIZE) {
45527 /* We should fall back to a general writev implementation.
45528 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45529 index c07cd57..61c4fbd 100644
45530 --- a/drivers/mtd/nand/denali.c
45531 +++ b/drivers/mtd/nand/denali.c
45532 @@ -24,6 +24,7 @@
45533 #include <linux/slab.h>
45534 #include <linux/mtd/mtd.h>
45535 #include <linux/module.h>
45536 +#include <linux/slab.h>
45537
45538 #include "denali.h"
45539
45540 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45541 index 51b9d6a..52af9a7 100644
45542 --- a/drivers/mtd/nftlmount.c
45543 +++ b/drivers/mtd/nftlmount.c
45544 @@ -24,6 +24,7 @@
45545 #include <asm/errno.h>
45546 #include <linux/delay.h>
45547 #include <linux/slab.h>
45548 +#include <linux/sched.h>
45549 #include <linux/mtd/mtd.h>
45550 #include <linux/mtd/nand.h>
45551 #include <linux/mtd/nftl.h>
45552 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45553 index 4b8e895..6b3c498 100644
45554 --- a/drivers/mtd/sm_ftl.c
45555 +++ b/drivers/mtd/sm_ftl.c
45556 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45557 #define SM_CIS_VENDOR_OFFSET 0x59
45558 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45559 {
45560 - struct attribute_group *attr_group;
45561 + attribute_group_no_const *attr_group;
45562 struct attribute **attributes;
45563 struct sm_sysfs_attribute *vendor_attribute;
45564
45565 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45566 index e5628fc..ffe54d1 100644
45567 --- a/drivers/net/bonding/bond_main.c
45568 +++ b/drivers/net/bonding/bond_main.c
45569 @@ -4551,6 +4551,7 @@ static void __exit bonding_exit(void)
45570
45571 bond_netlink_fini();
45572 unregister_pernet_subsys(&bond_net_ops);
45573 + rtnl_link_unregister(&bond_link_ops);
45574
45575 #ifdef CONFIG_NET_POLL_CONTROLLER
45576 /*
45577 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45578 index 70651f8..7eb1bdf 100644
45579 --- a/drivers/net/bonding/bond_netlink.c
45580 +++ b/drivers/net/bonding/bond_netlink.c
45581 @@ -542,7 +542,7 @@ nla_put_failure:
45582 return -EMSGSIZE;
45583 }
45584
45585 -struct rtnl_link_ops bond_link_ops __read_mostly = {
45586 +struct rtnl_link_ops bond_link_ops = {
45587 .kind = "bond",
45588 .priv_size = sizeof(struct bonding),
45589 .setup = bond_setup,
45590 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45591 index 9e7d95d..d447b88 100644
45592 --- a/drivers/net/can/Kconfig
45593 +++ b/drivers/net/can/Kconfig
45594 @@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45595
45596 config CAN_FLEXCAN
45597 tristate "Support for Freescale FLEXCAN based chips"
45598 - depends on ARM || PPC
45599 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45600 ---help---
45601 Say Y here if you want to support for Freescale FlexCAN.
45602
45603 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45604 index 455d4c3..3353ee7 100644
45605 --- a/drivers/net/ethernet/8390/ax88796.c
45606 +++ b/drivers/net/ethernet/8390/ax88796.c
45607 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
45608 if (ax->plat->reg_offsets)
45609 ei_local->reg_offset = ax->plat->reg_offsets;
45610 else {
45611 + resource_size_t _mem_size = mem_size;
45612 + do_div(_mem_size, 0x18);
45613 ei_local->reg_offset = ax->reg_offsets;
45614 for (ret = 0; ret < 0x18; ret++)
45615 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45616 + ax->reg_offsets[ret] = _mem_size * ret;
45617 }
45618
45619 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45620 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45621 index a89a40f..5a8a2ac 100644
45622 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45623 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45624 @@ -1062,7 +1062,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45625 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45626 {
45627 /* RX_MODE controlling object */
45628 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45629 + bnx2x_init_rx_mode_obj(bp);
45630
45631 /* multicast configuration controlling object */
45632 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45633 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45634 index 0fb6ff2..78fd55c 100644
45635 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45636 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45637 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45638 return rc;
45639 }
45640
45641 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45642 - struct bnx2x_rx_mode_obj *o)
45643 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45644 {
45645 if (CHIP_IS_E1x(bp)) {
45646 - o->wait_comp = bnx2x_empty_rx_mode_wait;
45647 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45648 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45649 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45650 } else {
45651 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45652 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
45653 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45654 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45655 }
45656 }
45657
45658 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45659 index 00d7f21..2cddec4 100644
45660 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45661 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45662 @@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45663
45664 /********************* RX MODE ****************/
45665
45666 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45667 - struct bnx2x_rx_mode_obj *o);
45668 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45669
45670 /**
45671 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45672 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45673 index 04321e5..b51cdc4 100644
45674 --- a/drivers/net/ethernet/broadcom/tg3.h
45675 +++ b/drivers/net/ethernet/broadcom/tg3.h
45676 @@ -150,6 +150,7 @@
45677 #define CHIPREV_ID_5750_A0 0x4000
45678 #define CHIPREV_ID_5750_A1 0x4001
45679 #define CHIPREV_ID_5750_A3 0x4003
45680 +#define CHIPREV_ID_5750_C1 0x4201
45681 #define CHIPREV_ID_5750_C2 0x4202
45682 #define CHIPREV_ID_5752_A0_HW 0x5000
45683 #define CHIPREV_ID_5752_A0 0x6000
45684 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45685 index 13f9636..228040f 100644
45686 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45687 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45688 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45689 }
45690
45691 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45692 - bna_cb_ioceth_enable,
45693 - bna_cb_ioceth_disable,
45694 - bna_cb_ioceth_hbfail,
45695 - bna_cb_ioceth_reset
45696 + .enable_cbfn = bna_cb_ioceth_enable,
45697 + .disable_cbfn = bna_cb_ioceth_disable,
45698 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
45699 + .reset_cbfn = bna_cb_ioceth_reset
45700 };
45701
45702 static void bna_attr_init(struct bna_ioceth *ioceth)
45703 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45704 index 8cffcdf..aadf043 100644
45705 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45706 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45707 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45708 */
45709 struct l2t_skb_cb {
45710 arp_failure_handler_func arp_failure_handler;
45711 -};
45712 +} __no_const;
45713
45714 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45715
45716 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45717 index 34e2488..07e2079 100644
45718 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45719 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45720 @@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45721
45722 int i;
45723 struct adapter *ap = netdev2adap(dev);
45724 - static const unsigned int *reg_ranges;
45725 + const unsigned int *reg_ranges;
45726 int arr_size = 0, buf_size = 0;
45727
45728 if (is_t4(ap->params.chip)) {
45729 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45730 index c05b66d..ed69872 100644
45731 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
45732 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45733 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45734 for (i=0; i<ETH_ALEN; i++) {
45735 tmp.addr[i] = dev->dev_addr[i];
45736 }
45737 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45738 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45739 break;
45740
45741 case DE4X5_SET_HWADDR: /* Set the hardware address */
45742 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45743 spin_lock_irqsave(&lp->lock, flags);
45744 memcpy(&statbuf, &lp->pktStats, ioc->len);
45745 spin_unlock_irqrestore(&lp->lock, flags);
45746 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
45747 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45748 return -EFAULT;
45749 break;
45750 }
45751 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45752 index 36c8061..ca5e1e0 100644
45753 --- a/drivers/net/ethernet/emulex/benet/be_main.c
45754 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
45755 @@ -534,7 +534,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45756
45757 if (wrapped)
45758 newacc += 65536;
45759 - ACCESS_ONCE(*acc) = newacc;
45760 + ACCESS_ONCE_RW(*acc) = newacc;
45761 }
45762
45763 static void populate_erx_stats(struct be_adapter *adapter,
45764 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45765 index c11ecbc..13bb299 100644
45766 --- a/drivers/net/ethernet/faraday/ftgmac100.c
45767 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
45768 @@ -30,6 +30,8 @@
45769 #include <linux/netdevice.h>
45770 #include <linux/phy.h>
45771 #include <linux/platform_device.h>
45772 +#include <linux/interrupt.h>
45773 +#include <linux/irqreturn.h>
45774 #include <net/ip.h>
45775
45776 #include "ftgmac100.h"
45777 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45778 index 8be5b40..081bc1b 100644
45779 --- a/drivers/net/ethernet/faraday/ftmac100.c
45780 +++ b/drivers/net/ethernet/faraday/ftmac100.c
45781 @@ -31,6 +31,8 @@
45782 #include <linux/module.h>
45783 #include <linux/netdevice.h>
45784 #include <linux/platform_device.h>
45785 +#include <linux/interrupt.h>
45786 +#include <linux/irqreturn.h>
45787
45788 #include "ftmac100.h"
45789
45790 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45791 index e33ec6c..f54cfe7 100644
45792 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45793 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45794 @@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
45795 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
45796
45797 /* Update the base adjustement value. */
45798 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
45799 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
45800 smp_mb(); /* Force the above update. */
45801 }
45802
45803 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45804 index 5184e2a..acb28c3 100644
45805 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45806 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45807 @@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45808 }
45809
45810 /* update the base incval used to calculate frequency adjustment */
45811 - ACCESS_ONCE(adapter->base_incval) = incval;
45812 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
45813 smp_mb();
45814
45815 /* need lock to prevent incorrect read while modifying cyclecounter */
45816 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45817 index 089b713..28d87ae 100644
45818 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45819 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45820 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45821 struct __vxge_hw_fifo *fifo;
45822 struct vxge_hw_fifo_config *config;
45823 u32 txdl_size, txdl_per_memblock;
45824 - struct vxge_hw_mempool_cbs fifo_mp_callback;
45825 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45826 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45827 + };
45828 +
45829 struct __vxge_hw_virtualpath *vpath;
45830
45831 if ((vp == NULL) || (attr == NULL)) {
45832 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45833 goto exit;
45834 }
45835
45836 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45837 -
45838 fifo->mempool =
45839 __vxge_hw_mempool_create(vpath->hldev,
45840 fifo->config->memblock_size,
45841 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45842 index 90a2dda..47e620e 100644
45843 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45844 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45845 @@ -2088,7 +2088,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45846 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45847 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45848 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45849 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45850 + pax_open_kernel();
45851 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45852 + pax_close_kernel();
45853 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45854 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
45855 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
45856 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45857 index be7d7a6..a8983f8 100644
45858 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45859 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45860 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
45861 case QLCNIC_NON_PRIV_FUNC:
45862 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
45863 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45864 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45865 + pax_open_kernel();
45866 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45867 + pax_close_kernel();
45868 break;
45869 case QLCNIC_PRIV_FUNC:
45870 ahw->op_mode = QLCNIC_PRIV_FUNC;
45871 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
45872 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45873 + pax_open_kernel();
45874 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45875 + pax_close_kernel();
45876 break;
45877 case QLCNIC_MGMT_FUNC:
45878 ahw->op_mode = QLCNIC_MGMT_FUNC;
45879 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45880 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45881 + pax_open_kernel();
45882 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45883 + pax_close_kernel();
45884 break;
45885 default:
45886 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
45887 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45888 index 7763962..c3499a7 100644
45889 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45890 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45891 @@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
45892 struct qlcnic_dump_entry *entry;
45893 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
45894 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
45895 - static const struct qlcnic_dump_operations *fw_dump_ops;
45896 + const struct qlcnic_dump_operations *fw_dump_ops;
45897 struct device *dev = &adapter->pdev->dev;
45898 struct qlcnic_hardware_context *ahw;
45899 void *temp_buffer;
45900 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
45901 index 3ff7bc3..366091b 100644
45902 --- a/drivers/net/ethernet/realtek/r8169.c
45903 +++ b/drivers/net/ethernet/realtek/r8169.c
45904 @@ -758,22 +758,22 @@ struct rtl8169_private {
45905 struct mdio_ops {
45906 void (*write)(struct rtl8169_private *, int, int);
45907 int (*read)(struct rtl8169_private *, int);
45908 - } mdio_ops;
45909 + } __no_const mdio_ops;
45910
45911 struct pll_power_ops {
45912 void (*down)(struct rtl8169_private *);
45913 void (*up)(struct rtl8169_private *);
45914 - } pll_power_ops;
45915 + } __no_const pll_power_ops;
45916
45917 struct jumbo_ops {
45918 void (*enable)(struct rtl8169_private *);
45919 void (*disable)(struct rtl8169_private *);
45920 - } jumbo_ops;
45921 + } __no_const jumbo_ops;
45922
45923 struct csi_ops {
45924 void (*write)(struct rtl8169_private *, int, int);
45925 u32 (*read)(struct rtl8169_private *, int);
45926 - } csi_ops;
45927 + } __no_const csi_ops;
45928
45929 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
45930 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
45931 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
45932 index d7a3682..9ce272a 100644
45933 --- a/drivers/net/ethernet/sfc/ptp.c
45934 +++ b/drivers/net/ethernet/sfc/ptp.c
45935 @@ -825,7 +825,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
45936 ptp->start.dma_addr);
45937
45938 /* Clear flag that signals MC ready */
45939 - ACCESS_ONCE(*start) = 0;
45940 + ACCESS_ONCE_RW(*start) = 0;
45941 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
45942 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
45943 EFX_BUG_ON_PARANOID(rc);
45944 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45945 index 50617c5..b13724c 100644
45946 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45947 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45948 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
45949
45950 writel(value, ioaddr + MMC_CNTRL);
45951
45952 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45953 - MMC_CNTRL, value);
45954 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45955 +// MMC_CNTRL, value);
45956 }
45957
45958 /* To mask all all interrupts.*/
45959 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
45960 index 7b594ce..1f6c5708 100644
45961 --- a/drivers/net/hyperv/hyperv_net.h
45962 +++ b/drivers/net/hyperv/hyperv_net.h
45963 @@ -100,7 +100,7 @@ struct rndis_device {
45964
45965 enum rndis_device_state state;
45966 bool link_state;
45967 - atomic_t new_req_id;
45968 + atomic_unchecked_t new_req_id;
45969
45970 spinlock_t request_lock;
45971 struct list_head req_list;
45972 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
45973 index b54fd25..9bd2bae 100644
45974 --- a/drivers/net/hyperv/rndis_filter.c
45975 +++ b/drivers/net/hyperv/rndis_filter.c
45976 @@ -103,7 +103,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
45977 * template
45978 */
45979 set = &rndis_msg->msg.set_req;
45980 - set->req_id = atomic_inc_return(&dev->new_req_id);
45981 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
45982
45983 /* Add to the request list */
45984 spin_lock_irqsave(&dev->request_lock, flags);
45985 @@ -770,7 +770,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
45986
45987 /* Setup the rndis set */
45988 halt = &request->request_msg.msg.halt_req;
45989 - halt->req_id = atomic_inc_return(&dev->new_req_id);
45990 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
45991
45992 /* Ignore return since this msg is optional. */
45993 rndis_filter_send_request(dev, request);
45994 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
45995 index bf0d55e..82bcfbd1 100644
45996 --- a/drivers/net/ieee802154/fakehard.c
45997 +++ b/drivers/net/ieee802154/fakehard.c
45998 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
45999 phy->transmit_power = 0xbf;
46000
46001 dev->netdev_ops = &fake_ops;
46002 - dev->ml_priv = &fake_mlme;
46003 + dev->ml_priv = (void *)&fake_mlme;
46004
46005 priv = netdev_priv(dev);
46006 priv->phy = phy;
46007 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46008 index 1831fb7..9c24bca 100644
46009 --- a/drivers/net/macvlan.c
46010 +++ b/drivers/net/macvlan.c
46011 @@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46012 int macvlan_link_register(struct rtnl_link_ops *ops)
46013 {
46014 /* common fields */
46015 - ops->priv_size = sizeof(struct macvlan_dev);
46016 - ops->validate = macvlan_validate;
46017 - ops->maxtype = IFLA_MACVLAN_MAX;
46018 - ops->policy = macvlan_policy;
46019 - ops->changelink = macvlan_changelink;
46020 - ops->get_size = macvlan_get_size;
46021 - ops->fill_info = macvlan_fill_info;
46022 + pax_open_kernel();
46023 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46024 + *(void **)&ops->validate = macvlan_validate;
46025 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46026 + *(const void **)&ops->policy = macvlan_policy;
46027 + *(void **)&ops->changelink = macvlan_changelink;
46028 + *(void **)&ops->get_size = macvlan_get_size;
46029 + *(void **)&ops->fill_info = macvlan_fill_info;
46030 + pax_close_kernel();
46031
46032 return rtnl_link_register(ops);
46033 };
46034 @@ -1045,7 +1047,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46035 return NOTIFY_DONE;
46036 }
46037
46038 -static struct notifier_block macvlan_notifier_block __read_mostly = {
46039 +static struct notifier_block macvlan_notifier_block = {
46040 .notifier_call = macvlan_device_event,
46041 };
46042
46043 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46044 index ff111a8..c4c3ac4 100644
46045 --- a/drivers/net/macvtap.c
46046 +++ b/drivers/net/macvtap.c
46047 @@ -1011,7 +1011,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46048 }
46049
46050 ret = 0;
46051 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46052 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46053 put_user(q->flags, &ifr->ifr_flags))
46054 ret = -EFAULT;
46055 macvtap_put_vlan(vlan);
46056 @@ -1181,7 +1181,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46057 return NOTIFY_DONE;
46058 }
46059
46060 -static struct notifier_block macvtap_notifier_block __read_mostly = {
46061 +static struct notifier_block macvtap_notifier_block = {
46062 .notifier_call = macvtap_device_event,
46063 };
46064
46065 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46066 index daec9b0..6428fcb 100644
46067 --- a/drivers/net/phy/mdio-bitbang.c
46068 +++ b/drivers/net/phy/mdio-bitbang.c
46069 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46070 struct mdiobb_ctrl *ctrl = bus->priv;
46071
46072 module_put(ctrl->ops->owner);
46073 + mdiobus_unregister(bus);
46074 mdiobus_free(bus);
46075 }
46076 EXPORT_SYMBOL(free_mdio_bitbang);
46077 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46078 index 72ff14b..11d442d 100644
46079 --- a/drivers/net/ppp/ppp_generic.c
46080 +++ b/drivers/net/ppp/ppp_generic.c
46081 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46082 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46083 struct ppp_stats stats;
46084 struct ppp_comp_stats cstats;
46085 - char *vers;
46086
46087 switch (cmd) {
46088 case SIOCGPPPSTATS:
46089 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46090 break;
46091
46092 case SIOCGPPPVER:
46093 - vers = PPP_VERSION;
46094 - if (copy_to_user(addr, vers, strlen(vers) + 1))
46095 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46096 break;
46097 err = 0;
46098 break;
46099 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46100 index 1252d9c..80e660b 100644
46101 --- a/drivers/net/slip/slhc.c
46102 +++ b/drivers/net/slip/slhc.c
46103 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46104 register struct tcphdr *thp;
46105 register struct iphdr *ip;
46106 register struct cstate *cs;
46107 - int len, hdrlen;
46108 + long len, hdrlen;
46109 unsigned char *cp = icp;
46110
46111 /* We've got a compressed packet; read the change byte */
46112 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46113 index c8624a8..f0a4f6a 100644
46114 --- a/drivers/net/team/team.c
46115 +++ b/drivers/net/team/team.c
46116 @@ -2869,7 +2869,7 @@ static int team_device_event(struct notifier_block *unused,
46117 return NOTIFY_DONE;
46118 }
46119
46120 -static struct notifier_block team_notifier_block __read_mostly = {
46121 +static struct notifier_block team_notifier_block = {
46122 .notifier_call = team_device_event,
46123 };
46124
46125 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46126 index 26f8635..c237839 100644
46127 --- a/drivers/net/tun.c
46128 +++ b/drivers/net/tun.c
46129 @@ -1876,7 +1876,7 @@ unlock:
46130 }
46131
46132 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46133 - unsigned long arg, int ifreq_len)
46134 + unsigned long arg, size_t ifreq_len)
46135 {
46136 struct tun_file *tfile = file->private_data;
46137 struct tun_struct *tun;
46138 @@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46139 unsigned int ifindex;
46140 int ret;
46141
46142 + if (ifreq_len > sizeof ifr)
46143 + return -EFAULT;
46144 +
46145 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46146 if (copy_from_user(&ifr, argp, ifreq_len))
46147 return -EFAULT;
46148 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46149 index 660bd5e..ac59452 100644
46150 --- a/drivers/net/usb/hso.c
46151 +++ b/drivers/net/usb/hso.c
46152 @@ -71,7 +71,7 @@
46153 #include <asm/byteorder.h>
46154 #include <linux/serial_core.h>
46155 #include <linux/serial.h>
46156 -
46157 +#include <asm/local.h>
46158
46159 #define MOD_AUTHOR "Option Wireless"
46160 #define MOD_DESCRIPTION "USB High Speed Option driver"
46161 @@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46162 struct urb *urb;
46163
46164 urb = serial->rx_urb[0];
46165 - if (serial->port.count > 0) {
46166 + if (atomic_read(&serial->port.count) > 0) {
46167 count = put_rxbuf_data(urb, serial);
46168 if (count == -1)
46169 return;
46170 @@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46171 DUMP1(urb->transfer_buffer, urb->actual_length);
46172
46173 /* Anyone listening? */
46174 - if (serial->port.count == 0)
46175 + if (atomic_read(&serial->port.count) == 0)
46176 return;
46177
46178 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46179 @@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46180 tty_port_tty_set(&serial->port, tty);
46181
46182 /* check for port already opened, if not set the termios */
46183 - serial->port.count++;
46184 - if (serial->port.count == 1) {
46185 + if (atomic_inc_return(&serial->port.count) == 1) {
46186 serial->rx_state = RX_IDLE;
46187 /* Force default termio settings */
46188 _hso_serial_set_termios(tty, NULL);
46189 @@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46190 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46191 if (result) {
46192 hso_stop_serial_device(serial->parent);
46193 - serial->port.count--;
46194 + atomic_dec(&serial->port.count);
46195 kref_put(&serial->parent->ref, hso_serial_ref_free);
46196 }
46197 } else {
46198 @@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46199
46200 /* reset the rts and dtr */
46201 /* do the actual close */
46202 - serial->port.count--;
46203 + atomic_dec(&serial->port.count);
46204
46205 - if (serial->port.count <= 0) {
46206 - serial->port.count = 0;
46207 + if (atomic_read(&serial->port.count) <= 0) {
46208 + atomic_set(&serial->port.count, 0);
46209 tty_port_tty_set(&serial->port, NULL);
46210 if (!usb_gone)
46211 hso_stop_serial_device(serial->parent);
46212 @@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46213
46214 /* the actual setup */
46215 spin_lock_irqsave(&serial->serial_lock, flags);
46216 - if (serial->port.count)
46217 + if (atomic_read(&serial->port.count))
46218 _hso_serial_set_termios(tty, old);
46219 else
46220 tty->termios = *old;
46221 @@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46222 D1("Pending read interrupt on port %d\n", i);
46223 spin_lock(&serial->serial_lock);
46224 if (serial->rx_state == RX_IDLE &&
46225 - serial->port.count > 0) {
46226 + atomic_read(&serial->port.count) > 0) {
46227 /* Setup and send a ctrl req read on
46228 * port i */
46229 if (!serial->rx_urb_filled[0]) {
46230 @@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46231 /* Start all serial ports */
46232 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46233 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46234 - if (dev2ser(serial_table[i])->port.count) {
46235 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46236 result =
46237 hso_start_serial_device(serial_table[i], GFP_NOIO);
46238 hso_kick_transmit(dev2ser(serial_table[i]));
46239 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46240 index adb12f3..48005ab 100644
46241 --- a/drivers/net/usb/r8152.c
46242 +++ b/drivers/net/usb/r8152.c
46243 @@ -513,7 +513,7 @@ struct r8152 {
46244 void (*disable)(struct r8152 *);
46245 void (*down)(struct r8152 *);
46246 void (*unload)(struct r8152 *);
46247 - } rtl_ops;
46248 + } __no_const rtl_ops;
46249
46250 int intr_interval;
46251 u32 msg_enable;
46252 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46253 index a2515887..6d13233 100644
46254 --- a/drivers/net/usb/sierra_net.c
46255 +++ b/drivers/net/usb/sierra_net.c
46256 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46257 /* atomic counter partially included in MAC address to make sure 2 devices
46258 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46259 */
46260 -static atomic_t iface_counter = ATOMIC_INIT(0);
46261 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46262
46263 /*
46264 * SYNC Timer Delay definition used to set the expiry time
46265 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46266 dev->net->netdev_ops = &sierra_net_device_ops;
46267
46268 /* change MAC addr to include, ifacenum, and to be unique */
46269 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46270 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46271 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46272
46273 /* we will have to manufacture ethernet headers, prepare template */
46274 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46275 index d091e52..568bb179 100644
46276 --- a/drivers/net/vxlan.c
46277 +++ b/drivers/net/vxlan.c
46278 @@ -2847,7 +2847,7 @@ nla_put_failure:
46279 return -EMSGSIZE;
46280 }
46281
46282 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46283 +static struct rtnl_link_ops vxlan_link_ops = {
46284 .kind = "vxlan",
46285 .maxtype = IFLA_VXLAN_MAX,
46286 .policy = vxlan_policy,
46287 @@ -2894,7 +2894,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46288 return NOTIFY_DONE;
46289 }
46290
46291 -static struct notifier_block vxlan_notifier_block __read_mostly = {
46292 +static struct notifier_block vxlan_notifier_block = {
46293 .notifier_call = vxlan_lowerdev_event,
46294 };
46295
46296 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46297 index 5920c99..ff2e4a5 100644
46298 --- a/drivers/net/wan/lmc/lmc_media.c
46299 +++ b/drivers/net/wan/lmc/lmc_media.c
46300 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46301 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46302
46303 lmc_media_t lmc_ds3_media = {
46304 - lmc_ds3_init, /* special media init stuff */
46305 - lmc_ds3_default, /* reset to default state */
46306 - lmc_ds3_set_status, /* reset status to state provided */
46307 - lmc_dummy_set_1, /* set clock source */
46308 - lmc_dummy_set2_1, /* set line speed */
46309 - lmc_ds3_set_100ft, /* set cable length */
46310 - lmc_ds3_set_scram, /* set scrambler */
46311 - lmc_ds3_get_link_status, /* get link status */
46312 - lmc_dummy_set_1, /* set link status */
46313 - lmc_ds3_set_crc_length, /* set CRC length */
46314 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46315 - lmc_ds3_watchdog
46316 + .init = lmc_ds3_init, /* special media init stuff */
46317 + .defaults = lmc_ds3_default, /* reset to default state */
46318 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
46319 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
46320 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46321 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46322 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46323 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
46324 + .set_link_status = lmc_dummy_set_1, /* set link status */
46325 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46326 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46327 + .watchdog = lmc_ds3_watchdog
46328 };
46329
46330 lmc_media_t lmc_hssi_media = {
46331 - lmc_hssi_init, /* special media init stuff */
46332 - lmc_hssi_default, /* reset to default state */
46333 - lmc_hssi_set_status, /* reset status to state provided */
46334 - lmc_hssi_set_clock, /* set clock source */
46335 - lmc_dummy_set2_1, /* set line speed */
46336 - lmc_dummy_set_1, /* set cable length */
46337 - lmc_dummy_set_1, /* set scrambler */
46338 - lmc_hssi_get_link_status, /* get link status */
46339 - lmc_hssi_set_link_status, /* set link status */
46340 - lmc_hssi_set_crc_length, /* set CRC length */
46341 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46342 - lmc_hssi_watchdog
46343 + .init = lmc_hssi_init, /* special media init stuff */
46344 + .defaults = lmc_hssi_default, /* reset to default state */
46345 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
46346 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46347 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46348 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46349 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46350 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
46351 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
46352 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46353 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46354 + .watchdog = lmc_hssi_watchdog
46355 };
46356
46357 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46358 - lmc_ssi_default, /* reset to default state */
46359 - lmc_ssi_set_status, /* reset status to state provided */
46360 - lmc_ssi_set_clock, /* set clock source */
46361 - lmc_ssi_set_speed, /* set line speed */
46362 - lmc_dummy_set_1, /* set cable length */
46363 - lmc_dummy_set_1, /* set scrambler */
46364 - lmc_ssi_get_link_status, /* get link status */
46365 - lmc_ssi_set_link_status, /* set link status */
46366 - lmc_ssi_set_crc_length, /* set CRC length */
46367 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46368 - lmc_ssi_watchdog
46369 +lmc_media_t lmc_ssi_media = {
46370 + .init = lmc_ssi_init, /* special media init stuff */
46371 + .defaults = lmc_ssi_default, /* reset to default state */
46372 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
46373 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46374 + .set_speed = lmc_ssi_set_speed, /* set line speed */
46375 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46376 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46377 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
46378 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
46379 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46380 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46381 + .watchdog = lmc_ssi_watchdog
46382 };
46383
46384 lmc_media_t lmc_t1_media = {
46385 - lmc_t1_init, /* special media init stuff */
46386 - lmc_t1_default, /* reset to default state */
46387 - lmc_t1_set_status, /* reset status to state provided */
46388 - lmc_t1_set_clock, /* set clock source */
46389 - lmc_dummy_set2_1, /* set line speed */
46390 - lmc_dummy_set_1, /* set cable length */
46391 - lmc_dummy_set_1, /* set scrambler */
46392 - lmc_t1_get_link_status, /* get link status */
46393 - lmc_dummy_set_1, /* set link status */
46394 - lmc_t1_set_crc_length, /* set CRC length */
46395 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46396 - lmc_t1_watchdog
46397 + .init = lmc_t1_init, /* special media init stuff */
46398 + .defaults = lmc_t1_default, /* reset to default state */
46399 + .set_status = lmc_t1_set_status, /* reset status to state provided */
46400 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
46401 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46402 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46403 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46404 + .get_link_status = lmc_t1_get_link_status, /* get link status */
46405 + .set_link_status = lmc_dummy_set_1, /* set link status */
46406 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46407 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46408 + .watchdog = lmc_t1_watchdog
46409 };
46410
46411 static void
46412 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46413 index feacc3b..5bac0de 100644
46414 --- a/drivers/net/wan/z85230.c
46415 +++ b/drivers/net/wan/z85230.c
46416 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46417
46418 struct z8530_irqhandler z8530_sync =
46419 {
46420 - z8530_rx,
46421 - z8530_tx,
46422 - z8530_status
46423 + .rx = z8530_rx,
46424 + .tx = z8530_tx,
46425 + .status = z8530_status
46426 };
46427
46428 EXPORT_SYMBOL(z8530_sync);
46429 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46430 }
46431
46432 static struct z8530_irqhandler z8530_dma_sync = {
46433 - z8530_dma_rx,
46434 - z8530_dma_tx,
46435 - z8530_dma_status
46436 + .rx = z8530_dma_rx,
46437 + .tx = z8530_dma_tx,
46438 + .status = z8530_dma_status
46439 };
46440
46441 static struct z8530_irqhandler z8530_txdma_sync = {
46442 - z8530_rx,
46443 - z8530_dma_tx,
46444 - z8530_dma_status
46445 + .rx = z8530_rx,
46446 + .tx = z8530_dma_tx,
46447 + .status = z8530_dma_status
46448 };
46449
46450 /**
46451 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46452
46453 struct z8530_irqhandler z8530_nop=
46454 {
46455 - z8530_rx_clear,
46456 - z8530_tx_clear,
46457 - z8530_status_clear
46458 + .rx = z8530_rx_clear,
46459 + .tx = z8530_tx_clear,
46460 + .status = z8530_status_clear
46461 };
46462
46463
46464 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46465 index 0b60295..b8bfa5b 100644
46466 --- a/drivers/net/wimax/i2400m/rx.c
46467 +++ b/drivers/net/wimax/i2400m/rx.c
46468 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46469 if (i2400m->rx_roq == NULL)
46470 goto error_roq_alloc;
46471
46472 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46473 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46474 GFP_KERNEL);
46475 if (rd == NULL) {
46476 result = -ENOMEM;
46477 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46478 index edf4b57..68b51c0 100644
46479 --- a/drivers/net/wireless/airo.c
46480 +++ b/drivers/net/wireless/airo.c
46481 @@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46482 struct airo_info *ai = dev->ml_priv;
46483 int ridcode;
46484 int enabled;
46485 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46486 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46487 unsigned char *iobuf;
46488
46489 /* Only super-user can write RIDs */
46490 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46491 index 99b3bfa..9559372 100644
46492 --- a/drivers/net/wireless/at76c50x-usb.c
46493 +++ b/drivers/net/wireless/at76c50x-usb.c
46494 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46495 }
46496
46497 /* Convert timeout from the DFU status to jiffies */
46498 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
46499 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46500 {
46501 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46502 | (s->poll_timeout[1] << 8)
46503 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46504 index edc57ab..ff49e0a 100644
46505 --- a/drivers/net/wireless/ath/ath10k/htc.c
46506 +++ b/drivers/net/wireless/ath/ath10k/htc.c
46507 @@ -831,7 +831,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46508 /* registered target arrival callback from the HIF layer */
46509 int ath10k_htc_init(struct ath10k *ar)
46510 {
46511 - struct ath10k_hif_cb htc_callbacks;
46512 + static struct ath10k_hif_cb htc_callbacks = {
46513 + .rx_completion = ath10k_htc_rx_completion_handler,
46514 + .tx_completion = ath10k_htc_tx_completion_handler,
46515 + };
46516 struct ath10k_htc_ep *ep = NULL;
46517 struct ath10k_htc *htc = &ar->htc;
46518
46519 @@ -841,8 +844,6 @@ int ath10k_htc_init(struct ath10k *ar)
46520 ath10k_htc_reset_endpoint_states(htc);
46521
46522 /* setup HIF layer callbacks */
46523 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46524 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46525 htc->ar = ar;
46526
46527 /* Get HIF default pipe for HTC message exchange */
46528 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46529 index 4716d33..a688310 100644
46530 --- a/drivers/net/wireless/ath/ath10k/htc.h
46531 +++ b/drivers/net/wireless/ath/ath10k/htc.h
46532 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46533
46534 struct ath10k_htc_ops {
46535 void (*target_send_suspend_complete)(struct ath10k *ar);
46536 -};
46537 +} __no_const;
46538
46539 struct ath10k_htc_ep_ops {
46540 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46541 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46542 void (*ep_tx_credits)(struct ath10k *);
46543 -};
46544 +} __no_const;
46545
46546 /* service connection information */
46547 struct ath10k_htc_svc_conn_req {
46548 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46549 index 741b38d..b7ae41b 100644
46550 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46551 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46552 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46553 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46554 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46555
46556 - ACCESS_ONCE(ads->ds_link) = i->link;
46557 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46558 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
46559 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46560
46561 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46562 ctl6 = SM(i->keytype, AR_EncrType);
46563 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46564
46565 if ((i->is_first || i->is_last) &&
46566 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46567 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46568 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46569 | set11nTries(i->rates, 1)
46570 | set11nTries(i->rates, 2)
46571 | set11nTries(i->rates, 3)
46572 | (i->dur_update ? AR_DurUpdateEna : 0)
46573 | SM(0, AR_BurstDur);
46574
46575 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46576 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46577 | set11nRate(i->rates, 1)
46578 | set11nRate(i->rates, 2)
46579 | set11nRate(i->rates, 3);
46580 } else {
46581 - ACCESS_ONCE(ads->ds_ctl2) = 0;
46582 - ACCESS_ONCE(ads->ds_ctl3) = 0;
46583 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46584 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46585 }
46586
46587 if (!i->is_first) {
46588 - ACCESS_ONCE(ads->ds_ctl0) = 0;
46589 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46590 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46591 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46592 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46593 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46594 return;
46595 }
46596
46597 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46598 break;
46599 }
46600
46601 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46602 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46603 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46604 | SM(i->txpower, AR_XmitPower)
46605 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46606 @@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46607 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46608 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46609
46610 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46611 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46612 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46613 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46614
46615 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46616 return;
46617
46618 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46619 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46620 | set11nPktDurRTSCTS(i->rates, 1);
46621
46622 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46623 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46624 | set11nPktDurRTSCTS(i->rates, 3);
46625
46626 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46627 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46628 | set11nRateFlags(i->rates, 1)
46629 | set11nRateFlags(i->rates, 2)
46630 | set11nRateFlags(i->rates, 3)
46631 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46632 index 729ffbf..49f50e3 100644
46633 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46634 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46635 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46636 (i->qcu << AR_TxQcuNum_S) | desc_len;
46637
46638 checksum += val;
46639 - ACCESS_ONCE(ads->info) = val;
46640 + ACCESS_ONCE_RW(ads->info) = val;
46641
46642 checksum += i->link;
46643 - ACCESS_ONCE(ads->link) = i->link;
46644 + ACCESS_ONCE_RW(ads->link) = i->link;
46645
46646 checksum += i->buf_addr[0];
46647 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46648 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46649 checksum += i->buf_addr[1];
46650 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46651 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46652 checksum += i->buf_addr[2];
46653 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46654 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46655 checksum += i->buf_addr[3];
46656 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46657 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46658
46659 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46660 - ACCESS_ONCE(ads->ctl3) = val;
46661 + ACCESS_ONCE_RW(ads->ctl3) = val;
46662 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46663 - ACCESS_ONCE(ads->ctl5) = val;
46664 + ACCESS_ONCE_RW(ads->ctl5) = val;
46665 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46666 - ACCESS_ONCE(ads->ctl7) = val;
46667 + ACCESS_ONCE_RW(ads->ctl7) = val;
46668 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46669 - ACCESS_ONCE(ads->ctl9) = val;
46670 + ACCESS_ONCE_RW(ads->ctl9) = val;
46671
46672 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46673 - ACCESS_ONCE(ads->ctl10) = checksum;
46674 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
46675
46676 if (i->is_first || i->is_last) {
46677 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46678 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46679 | set11nTries(i->rates, 1)
46680 | set11nTries(i->rates, 2)
46681 | set11nTries(i->rates, 3)
46682 | (i->dur_update ? AR_DurUpdateEna : 0)
46683 | SM(0, AR_BurstDur);
46684
46685 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46686 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46687 | set11nRate(i->rates, 1)
46688 | set11nRate(i->rates, 2)
46689 | set11nRate(i->rates, 3);
46690 } else {
46691 - ACCESS_ONCE(ads->ctl13) = 0;
46692 - ACCESS_ONCE(ads->ctl14) = 0;
46693 + ACCESS_ONCE_RW(ads->ctl13) = 0;
46694 + ACCESS_ONCE_RW(ads->ctl14) = 0;
46695 }
46696
46697 ads->ctl20 = 0;
46698 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46699
46700 ctl17 = SM(i->keytype, AR_EncrType);
46701 if (!i->is_first) {
46702 - ACCESS_ONCE(ads->ctl11) = 0;
46703 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46704 - ACCESS_ONCE(ads->ctl15) = 0;
46705 - ACCESS_ONCE(ads->ctl16) = 0;
46706 - ACCESS_ONCE(ads->ctl17) = ctl17;
46707 - ACCESS_ONCE(ads->ctl18) = 0;
46708 - ACCESS_ONCE(ads->ctl19) = 0;
46709 + ACCESS_ONCE_RW(ads->ctl11) = 0;
46710 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46711 + ACCESS_ONCE_RW(ads->ctl15) = 0;
46712 + ACCESS_ONCE_RW(ads->ctl16) = 0;
46713 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46714 + ACCESS_ONCE_RW(ads->ctl18) = 0;
46715 + ACCESS_ONCE_RW(ads->ctl19) = 0;
46716 return;
46717 }
46718
46719 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46720 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46721 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46722 | SM(i->txpower, AR_XmitPower)
46723 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46724 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46725 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46726 ctl12 |= SM(val, AR_PAPRDChainMask);
46727
46728 - ACCESS_ONCE(ads->ctl12) = ctl12;
46729 - ACCESS_ONCE(ads->ctl17) = ctl17;
46730 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46731 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46732
46733 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46734 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46735 | set11nPktDurRTSCTS(i->rates, 1);
46736
46737 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46738 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46739 | set11nPktDurRTSCTS(i->rates, 3);
46740
46741 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46742 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46743 | set11nRateFlags(i->rates, 1)
46744 | set11nRateFlags(i->rates, 2)
46745 | set11nRateFlags(i->rates, 3)
46746 | SM(i->rtscts_rate, AR_RTSCTSRate);
46747
46748 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46749 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46750 }
46751
46752 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46753 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46754 index 0acd4b5..0591c91 100644
46755 --- a/drivers/net/wireless/ath/ath9k/hw.h
46756 +++ b/drivers/net/wireless/ath/ath9k/hw.h
46757 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
46758
46759 /* ANI */
46760 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46761 -};
46762 +} __no_const;
46763
46764 /**
46765 * struct ath_spec_scan - parameters for Atheros spectral scan
46766 @@ -706,7 +706,7 @@ struct ath_hw_ops {
46767 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46768 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46769 #endif
46770 -};
46771 +} __no_const;
46772
46773 struct ath_nf_limits {
46774 s16 max;
46775 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46776 index 92190da..f3a4c4c 100644
46777 --- a/drivers/net/wireless/b43/phy_lp.c
46778 +++ b/drivers/net/wireless/b43/phy_lp.c
46779 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46780 {
46781 struct ssb_bus *bus = dev->dev->sdev->bus;
46782
46783 - static const struct b206x_channel *chandata = NULL;
46784 + const struct b206x_channel *chandata = NULL;
46785 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46786 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46787 u16 old_comm15, scale;
46788 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46789 index 0487461..fd9e84a 100644
46790 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
46791 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46792 @@ -3638,7 +3638,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46793 */
46794 if (il3945_mod_params.disable_hw_scan) {
46795 D_INFO("Disabling hw_scan\n");
46796 - il3945_mac_ops.hw_scan = NULL;
46797 + pax_open_kernel();
46798 + *(void **)&il3945_mac_ops.hw_scan = NULL;
46799 + pax_close_kernel();
46800 }
46801
46802 D_INFO("*** LOAD DRIVER ***\n");
46803 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46804 index d2fe259..0c4c682 100644
46805 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46806 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46807 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46808 {
46809 struct iwl_priv *priv = file->private_data;
46810 char buf[64];
46811 - int buf_size;
46812 + size_t buf_size;
46813 u32 offset, len;
46814
46815 memset(buf, 0, sizeof(buf));
46816 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46817 struct iwl_priv *priv = file->private_data;
46818
46819 char buf[8];
46820 - int buf_size;
46821 + size_t buf_size;
46822 u32 reset_flag;
46823
46824 memset(buf, 0, sizeof(buf));
46825 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46826 {
46827 struct iwl_priv *priv = file->private_data;
46828 char buf[8];
46829 - int buf_size;
46830 + size_t buf_size;
46831 int ht40;
46832
46833 memset(buf, 0, sizeof(buf));
46834 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46835 {
46836 struct iwl_priv *priv = file->private_data;
46837 char buf[8];
46838 - int buf_size;
46839 + size_t buf_size;
46840 int value;
46841
46842 memset(buf, 0, sizeof(buf));
46843 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46844 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46845 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46846
46847 -static const char *fmt_value = " %-30s %10u\n";
46848 -static const char *fmt_hex = " %-30s 0x%02X\n";
46849 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46850 -static const char *fmt_header =
46851 +static const char fmt_value[] = " %-30s %10u\n";
46852 +static const char fmt_hex[] = " %-30s 0x%02X\n";
46853 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46854 +static const char fmt_header[] =
46855 "%-32s current cumulative delta max\n";
46856
46857 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46858 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46859 {
46860 struct iwl_priv *priv = file->private_data;
46861 char buf[8];
46862 - int buf_size;
46863 + size_t buf_size;
46864 int clear;
46865
46866 memset(buf, 0, sizeof(buf));
46867 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46868 {
46869 struct iwl_priv *priv = file->private_data;
46870 char buf[8];
46871 - int buf_size;
46872 + size_t buf_size;
46873 int trace;
46874
46875 memset(buf, 0, sizeof(buf));
46876 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
46877 {
46878 struct iwl_priv *priv = file->private_data;
46879 char buf[8];
46880 - int buf_size;
46881 + size_t buf_size;
46882 int missed;
46883
46884 memset(buf, 0, sizeof(buf));
46885 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
46886
46887 struct iwl_priv *priv = file->private_data;
46888 char buf[8];
46889 - int buf_size;
46890 + size_t buf_size;
46891 int plcp;
46892
46893 memset(buf, 0, sizeof(buf));
46894 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
46895
46896 struct iwl_priv *priv = file->private_data;
46897 char buf[8];
46898 - int buf_size;
46899 + size_t buf_size;
46900 int flush;
46901
46902 memset(buf, 0, sizeof(buf));
46903 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
46904
46905 struct iwl_priv *priv = file->private_data;
46906 char buf[8];
46907 - int buf_size;
46908 + size_t buf_size;
46909 int rts;
46910
46911 if (!priv->cfg->ht_params)
46912 @@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
46913 {
46914 struct iwl_priv *priv = file->private_data;
46915 char buf[8];
46916 - int buf_size;
46917 + size_t buf_size;
46918
46919 memset(buf, 0, sizeof(buf));
46920 buf_size = min(count, sizeof(buf) - 1);
46921 @@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
46922 struct iwl_priv *priv = file->private_data;
46923 u32 event_log_flag;
46924 char buf[8];
46925 - int buf_size;
46926 + size_t buf_size;
46927
46928 /* check that the interface is up */
46929 if (!iwl_is_ready(priv))
46930 @@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
46931 struct iwl_priv *priv = file->private_data;
46932 char buf[8];
46933 u32 calib_disabled;
46934 - int buf_size;
46935 + size_t buf_size;
46936
46937 memset(buf, 0, sizeof(buf));
46938 buf_size = min(count, sizeof(buf) - 1);
46939 diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
46940 index ba1b1ea..0ff7e98 100644
46941 --- a/drivers/net/wireless/iwlwifi/dvm/main.c
46942 +++ b/drivers/net/wireless/iwlwifi/dvm/main.c
46943 @@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
46944 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46945 {
46946 struct iwl_nvm_data *data = priv->nvm_data;
46947 - char *debug_msg;
46948 + static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46949
46950 if (data->sku_cap_11n_enable &&
46951 !priv->cfg->ht_params) {
46952 @@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46953 return -EINVAL;
46954 }
46955
46956 - debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46957 IWL_DEBUG_INFO(priv, debug_msg,
46958 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
46959 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
46960 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
46961 index f950780..be9df93 100644
46962 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
46963 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
46964 @@ -1365,7 +1365,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
46965 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
46966
46967 char buf[8];
46968 - int buf_size;
46969 + size_t buf_size;
46970 u32 reset_flag;
46971
46972 memset(buf, 0, sizeof(buf));
46973 @@ -1386,7 +1386,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
46974 {
46975 struct iwl_trans *trans = file->private_data;
46976 char buf[8];
46977 - int buf_size;
46978 + size_t buf_size;
46979 int csr;
46980
46981 memset(buf, 0, sizeof(buf));
46982 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
46983 index 69d4c31..bd0b316 100644
46984 --- a/drivers/net/wireless/mac80211_hwsim.c
46985 +++ b/drivers/net/wireless/mac80211_hwsim.c
46986 @@ -2541,20 +2541,20 @@ static int __init init_mac80211_hwsim(void)
46987 if (channels < 1)
46988 return -EINVAL;
46989
46990 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
46991 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
46992 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
46993 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
46994 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
46995 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
46996 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
46997 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
46998 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
46999 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47000 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47001 - mac80211_hwsim_assign_vif_chanctx;
47002 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47003 - mac80211_hwsim_unassign_vif_chanctx;
47004 + pax_open_kernel();
47005 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47006 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47007 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47008 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47009 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47010 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47011 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47012 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47013 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47014 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47015 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47016 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47017 + pax_close_kernel();
47018
47019 spin_lock_init(&hwsim_radio_lock);
47020 INIT_LIST_HEAD(&hwsim_radios);
47021 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47022 index 5028557..91cf394 100644
47023 --- a/drivers/net/wireless/rndis_wlan.c
47024 +++ b/drivers/net/wireless/rndis_wlan.c
47025 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47026
47027 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47028
47029 - if (rts_threshold < 0 || rts_threshold > 2347)
47030 + if (rts_threshold > 2347)
47031 rts_threshold = 2347;
47032
47033 tmp = cpu_to_le32(rts_threshold);
47034 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47035 index e3b885d..7a7de2f 100644
47036 --- a/drivers/net/wireless/rt2x00/rt2x00.h
47037 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
47038 @@ -375,7 +375,7 @@ struct rt2x00_intf {
47039 * for hardware which doesn't support hardware
47040 * sequence counting.
47041 */
47042 - atomic_t seqno;
47043 + atomic_unchecked_t seqno;
47044 };
47045
47046 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47047 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47048 index 5642ccc..01f03eb 100644
47049 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47050 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47051 @@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47052 * sequence counter given by mac80211.
47053 */
47054 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47055 - seqno = atomic_add_return(0x10, &intf->seqno);
47056 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47057 else
47058 - seqno = atomic_read(&intf->seqno);
47059 + seqno = atomic_read_unchecked(&intf->seqno);
47060
47061 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47062 hdr->seq_ctrl |= cpu_to_le16(seqno);
47063 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47064 index e2b3d9c..67a5184 100644
47065 --- a/drivers/net/wireless/ti/wl1251/sdio.c
47066 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
47067 @@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47068
47069 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47070
47071 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47072 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47073 + pax_open_kernel();
47074 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47075 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47076 + pax_close_kernel();
47077
47078 wl1251_info("using dedicated interrupt line");
47079 } else {
47080 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47081 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47082 + pax_open_kernel();
47083 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47084 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47085 + pax_close_kernel();
47086
47087 wl1251_info("using SDIO interrupt");
47088 }
47089 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47090 index be7129b..4161356 100644
47091 --- a/drivers/net/wireless/ti/wl12xx/main.c
47092 +++ b/drivers/net/wireless/ti/wl12xx/main.c
47093 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47094 sizeof(wl->conf.mem));
47095
47096 /* read data preparation is only needed by wl127x */
47097 - wl->ops->prepare_read = wl127x_prepare_read;
47098 + pax_open_kernel();
47099 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47100 + pax_close_kernel();
47101
47102 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47103 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47104 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47105 sizeof(wl->conf.mem));
47106
47107 /* read data preparation is only needed by wl127x */
47108 - wl->ops->prepare_read = wl127x_prepare_read;
47109 + pax_open_kernel();
47110 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47111 + pax_close_kernel();
47112
47113 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47114 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47115 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47116 index ec37b16..7e34d66 100644
47117 --- a/drivers/net/wireless/ti/wl18xx/main.c
47118 +++ b/drivers/net/wireless/ti/wl18xx/main.c
47119 @@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47120 }
47121
47122 if (!checksum_param) {
47123 - wl18xx_ops.set_rx_csum = NULL;
47124 - wl18xx_ops.init_vif = NULL;
47125 + pax_open_kernel();
47126 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
47127 + *(void **)&wl18xx_ops.init_vif = NULL;
47128 + pax_close_kernel();
47129 }
47130
47131 /* Enable 11a Band only if we have 5G antennas */
47132 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47133 index a912dc0..a8225ba 100644
47134 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
47135 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47136 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47137 {
47138 struct zd_usb *usb = urb->context;
47139 struct zd_usb_interrupt *intr = &usb->intr;
47140 - int len;
47141 + unsigned int len;
47142 u16 int_num;
47143
47144 ZD_ASSERT(in_interrupt());
47145 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47146 index 683671a..4519fc2 100644
47147 --- a/drivers/nfc/nfcwilink.c
47148 +++ b/drivers/nfc/nfcwilink.c
47149 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47150
47151 static int nfcwilink_probe(struct platform_device *pdev)
47152 {
47153 - static struct nfcwilink *drv;
47154 + struct nfcwilink *drv;
47155 int rc;
47156 __u32 protocols;
47157
47158 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47159 index d93b2b6..ae50401 100644
47160 --- a/drivers/oprofile/buffer_sync.c
47161 +++ b/drivers/oprofile/buffer_sync.c
47162 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47163 if (cookie == NO_COOKIE)
47164 offset = pc;
47165 if (cookie == INVALID_COOKIE) {
47166 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47167 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47168 offset = pc;
47169 }
47170 if (cookie != last_cookie) {
47171 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47172 /* add userspace sample */
47173
47174 if (!mm) {
47175 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
47176 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47177 return 0;
47178 }
47179
47180 cookie = lookup_dcookie(mm, s->eip, &offset);
47181
47182 if (cookie == INVALID_COOKIE) {
47183 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47184 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47185 return 0;
47186 }
47187
47188 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47189 /* ignore backtraces if failed to add a sample */
47190 if (state == sb_bt_start) {
47191 state = sb_bt_ignore;
47192 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47193 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47194 }
47195 }
47196 release_mm(mm);
47197 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47198 index c0cc4e7..44d4e54 100644
47199 --- a/drivers/oprofile/event_buffer.c
47200 +++ b/drivers/oprofile/event_buffer.c
47201 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47202 }
47203
47204 if (buffer_pos == buffer_size) {
47205 - atomic_inc(&oprofile_stats.event_lost_overflow);
47206 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47207 return;
47208 }
47209
47210 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47211 index ed2c3ec..deda85a 100644
47212 --- a/drivers/oprofile/oprof.c
47213 +++ b/drivers/oprofile/oprof.c
47214 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47215 if (oprofile_ops.switch_events())
47216 return;
47217
47218 - atomic_inc(&oprofile_stats.multiplex_counter);
47219 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47220 start_switch_worker();
47221 }
47222
47223 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47224 index ee2cfce..7f8f699 100644
47225 --- a/drivers/oprofile/oprofile_files.c
47226 +++ b/drivers/oprofile/oprofile_files.c
47227 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47228
47229 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47230
47231 -static ssize_t timeout_read(struct file *file, char __user *buf,
47232 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47233 size_t count, loff_t *offset)
47234 {
47235 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47236 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47237 index 59659ce..6c860a0 100644
47238 --- a/drivers/oprofile/oprofile_stats.c
47239 +++ b/drivers/oprofile/oprofile_stats.c
47240 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47241 cpu_buf->sample_invalid_eip = 0;
47242 }
47243
47244 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47245 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47246 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
47247 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47248 - atomic_set(&oprofile_stats.multiplex_counter, 0);
47249 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47250 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47251 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47252 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47253 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47254 }
47255
47256
47257 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47258 index 1fc622b..8c48fc3 100644
47259 --- a/drivers/oprofile/oprofile_stats.h
47260 +++ b/drivers/oprofile/oprofile_stats.h
47261 @@ -13,11 +13,11 @@
47262 #include <linux/atomic.h>
47263
47264 struct oprofile_stat_struct {
47265 - atomic_t sample_lost_no_mm;
47266 - atomic_t sample_lost_no_mapping;
47267 - atomic_t bt_lost_no_mapping;
47268 - atomic_t event_lost_overflow;
47269 - atomic_t multiplex_counter;
47270 + atomic_unchecked_t sample_lost_no_mm;
47271 + atomic_unchecked_t sample_lost_no_mapping;
47272 + atomic_unchecked_t bt_lost_no_mapping;
47273 + atomic_unchecked_t event_lost_overflow;
47274 + atomic_unchecked_t multiplex_counter;
47275 };
47276
47277 extern struct oprofile_stat_struct oprofile_stats;
47278 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47279 index 3f49345..c750d0b 100644
47280 --- a/drivers/oprofile/oprofilefs.c
47281 +++ b/drivers/oprofile/oprofilefs.c
47282 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47283
47284 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47285 {
47286 - atomic_t *val = file->private_data;
47287 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47288 + atomic_unchecked_t *val = file->private_data;
47289 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47290 }
47291
47292
47293 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47294
47295
47296 int oprofilefs_create_ro_atomic(struct dentry *root,
47297 - char const *name, atomic_t *val)
47298 + char const *name, atomic_unchecked_t *val)
47299 {
47300 return __oprofilefs_create_file(root, name,
47301 &atomic_ro_fops, 0444, val);
47302 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47303 index 61be1d9..dec05d7 100644
47304 --- a/drivers/oprofile/timer_int.c
47305 +++ b/drivers/oprofile/timer_int.c
47306 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47307 return NOTIFY_OK;
47308 }
47309
47310 -static struct notifier_block __refdata oprofile_cpu_notifier = {
47311 +static struct notifier_block oprofile_cpu_notifier = {
47312 .notifier_call = oprofile_cpu_notify,
47313 };
47314
47315 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47316 index 92ed045..62d39bd7 100644
47317 --- a/drivers/parport/procfs.c
47318 +++ b/drivers/parport/procfs.c
47319 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47320
47321 *ppos += len;
47322
47323 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47324 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47325 }
47326
47327 #ifdef CONFIG_PARPORT_1284
47328 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47329
47330 *ppos += len;
47331
47332 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47333 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47334 }
47335 #endif /* IEEE1284.3 support. */
47336
47337 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47338 index 8dcccff..35d701d 100644
47339 --- a/drivers/pci/hotplug/acpiphp_ibm.c
47340 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
47341 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47342 goto init_cleanup;
47343 }
47344
47345 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47346 + pax_open_kernel();
47347 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47348 + pax_close_kernel();
47349 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47350
47351 return retval;
47352 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47353 index 7536eef..52dc8fa 100644
47354 --- a/drivers/pci/hotplug/cpcihp_generic.c
47355 +++ b/drivers/pci/hotplug/cpcihp_generic.c
47356 @@ -73,7 +73,6 @@ static u16 port;
47357 static unsigned int enum_bit;
47358 static u8 enum_mask;
47359
47360 -static struct cpci_hp_controller_ops generic_hpc_ops;
47361 static struct cpci_hp_controller generic_hpc;
47362
47363 static int __init validate_parameters(void)
47364 @@ -139,6 +138,10 @@ static int query_enum(void)
47365 return ((value & enum_mask) == enum_mask);
47366 }
47367
47368 +static struct cpci_hp_controller_ops generic_hpc_ops = {
47369 + .query_enum = query_enum,
47370 +};
47371 +
47372 static int __init cpcihp_generic_init(void)
47373 {
47374 int status;
47375 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47376 pci_dev_put(dev);
47377
47378 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47379 - generic_hpc_ops.query_enum = query_enum;
47380 generic_hpc.ops = &generic_hpc_ops;
47381
47382 status = cpci_hp_register_controller(&generic_hpc);
47383 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47384 index e8c4a7c..7046f5c 100644
47385 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
47386 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47387 @@ -59,7 +59,6 @@
47388 /* local variables */
47389 static bool debug;
47390 static bool poll;
47391 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
47392 static struct cpci_hp_controller zt5550_hpc;
47393
47394 /* Primary cPCI bus bridge device */
47395 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47396 return 0;
47397 }
47398
47399 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47400 + .query_enum = zt5550_hc_query_enum,
47401 +};
47402 +
47403 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47404 {
47405 int status;
47406 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47407 dbg("returned from zt5550_hc_config");
47408
47409 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47410 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47411 zt5550_hpc.ops = &zt5550_hpc_ops;
47412 if(!poll) {
47413 zt5550_hpc.irq = hc_dev->irq;
47414 zt5550_hpc.irq_flags = IRQF_SHARED;
47415 zt5550_hpc.dev_id = hc_dev;
47416
47417 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47418 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47419 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47420 + pax_open_kernel();
47421 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47422 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47423 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47424 + pax_open_kernel();
47425 } else {
47426 info("using ENUM# polling mode");
47427 }
47428 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47429 index 76ba8a1..20ca857 100644
47430 --- a/drivers/pci/hotplug/cpqphp_nvram.c
47431 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
47432 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47433
47434 void compaq_nvram_init (void __iomem *rom_start)
47435 {
47436 +
47437 +#ifndef CONFIG_PAX_KERNEXEC
47438 if (rom_start) {
47439 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47440 }
47441 +#endif
47442 +
47443 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47444
47445 /* initialize our int15 lock */
47446 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47447 index cfa92a9..29539c5 100644
47448 --- a/drivers/pci/hotplug/pci_hotplug_core.c
47449 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
47450 @@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47451 return -EINVAL;
47452 }
47453
47454 - slot->ops->owner = owner;
47455 - slot->ops->mod_name = mod_name;
47456 + pax_open_kernel();
47457 + *(struct module **)&slot->ops->owner = owner;
47458 + *(const char **)&slot->ops->mod_name = mod_name;
47459 + pax_close_kernel();
47460
47461 mutex_lock(&pci_hp_mutex);
47462 /*
47463 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47464 index 53b58de..4479896 100644
47465 --- a/drivers/pci/hotplug/pciehp_core.c
47466 +++ b/drivers/pci/hotplug/pciehp_core.c
47467 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47468 struct slot *slot = ctrl->slot;
47469 struct hotplug_slot *hotplug = NULL;
47470 struct hotplug_slot_info *info = NULL;
47471 - struct hotplug_slot_ops *ops = NULL;
47472 + hotplug_slot_ops_no_const *ops = NULL;
47473 char name[SLOT_NAME_SIZE];
47474 int retval = -ENOMEM;
47475
47476 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
47477 index 955ab79..d1df9c7 100644
47478 --- a/drivers/pci/msi.c
47479 +++ b/drivers/pci/msi.c
47480 @@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
47481 {
47482 struct attribute **msi_attrs;
47483 struct attribute *msi_attr;
47484 - struct device_attribute *msi_dev_attr;
47485 - struct attribute_group *msi_irq_group;
47486 + device_attribute_no_const *msi_dev_attr;
47487 + attribute_group_no_const *msi_irq_group;
47488 const struct attribute_group **msi_irq_groups;
47489 struct msi_desc *entry;
47490 int ret = -ENOMEM;
47491 @@ -589,7 +589,7 @@ error_attrs:
47492 count = 0;
47493 msi_attr = msi_attrs[count];
47494 while (msi_attr) {
47495 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
47496 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
47497 kfree(msi_attr->name);
47498 kfree(msi_dev_attr);
47499 ++count;
47500 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47501 index 276ef9c..1d33a36 100644
47502 --- a/drivers/pci/pci-sysfs.c
47503 +++ b/drivers/pci/pci-sysfs.c
47504 @@ -1112,7 +1112,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47505 {
47506 /* allocate attribute structure, piggyback attribute name */
47507 int name_len = write_combine ? 13 : 10;
47508 - struct bin_attribute *res_attr;
47509 + bin_attribute_no_const *res_attr;
47510 int retval;
47511
47512 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47513 @@ -1297,7 +1297,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47514 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47515 {
47516 int retval;
47517 - struct bin_attribute *attr;
47518 + bin_attribute_no_const *attr;
47519
47520 /* If the device has VPD, try to expose it in sysfs. */
47521 if (dev->vpd) {
47522 @@ -1344,7 +1344,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47523 {
47524 int retval;
47525 int rom_size = 0;
47526 - struct bin_attribute *attr;
47527 + bin_attribute_no_const *attr;
47528
47529 if (!sysfs_initialized)
47530 return -EACCES;
47531 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47532 index 4df38df..b6bb7fe 100644
47533 --- a/drivers/pci/pci.h
47534 +++ b/drivers/pci/pci.h
47535 @@ -93,7 +93,7 @@ struct pci_vpd_ops {
47536 struct pci_vpd {
47537 unsigned int len;
47538 const struct pci_vpd_ops *ops;
47539 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47540 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47541 };
47542
47543 int pci_vpd_pci22_init(struct pci_dev *dev);
47544 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47545 index e1e7026..d28dd33 100644
47546 --- a/drivers/pci/pcie/aspm.c
47547 +++ b/drivers/pci/pcie/aspm.c
47548 @@ -27,9 +27,9 @@
47549 #define MODULE_PARAM_PREFIX "pcie_aspm."
47550
47551 /* Note: those are not register definitions */
47552 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47553 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47554 -#define ASPM_STATE_L1 (4) /* L1 state */
47555 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47556 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47557 +#define ASPM_STATE_L1 (4U) /* L1 state */
47558 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47559 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47560
47561 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47562 index 6e34498..9911975 100644
47563 --- a/drivers/pci/probe.c
47564 +++ b/drivers/pci/probe.c
47565 @@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47566 struct pci_bus_region region, inverted_region;
47567 bool bar_too_big = false, bar_disabled = false;
47568
47569 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47570 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47571
47572 /* No printks while decoding is disabled! */
47573 if (!dev->mmio_always_on) {
47574 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47575 index 46d1378..30e452b 100644
47576 --- a/drivers/pci/proc.c
47577 +++ b/drivers/pci/proc.c
47578 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47579 static int __init pci_proc_init(void)
47580 {
47581 struct pci_dev *dev = NULL;
47582 +
47583 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47584 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47585 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47586 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47587 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47588 +#endif
47589 +#else
47590 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47591 +#endif
47592 proc_create("devices", 0, proc_bus_pci_dir,
47593 &proc_bus_pci_dev_operations);
47594 proc_initialized = 1;
47595 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47596 index 7f3aad0..7d604bb 100644
47597 --- a/drivers/platform/chrome/chromeos_laptop.c
47598 +++ b/drivers/platform/chrome/chromeos_laptop.c
47599 @@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
47600 .callback = chromeos_laptop_dmi_matched, \
47601 .driver_data = (void *)&board_
47602
47603 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
47604 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
47605 {
47606 .ident = "Samsung Series 5 550",
47607 .matches = {
47608 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47609 index c5e082f..d6307a0 100644
47610 --- a/drivers/platform/x86/asus-wmi.c
47611 +++ b/drivers/platform/x86/asus-wmi.c
47612 @@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
47613 int err;
47614 u32 retval = -1;
47615
47616 +#ifdef CONFIG_GRKERNSEC_KMEM
47617 + return -EPERM;
47618 +#endif
47619 +
47620 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47621
47622 if (err < 0)
47623 @@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
47624 int err;
47625 u32 retval = -1;
47626
47627 +#ifdef CONFIG_GRKERNSEC_KMEM
47628 + return -EPERM;
47629 +#endif
47630 +
47631 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47632 &retval);
47633
47634 @@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
47635 union acpi_object *obj;
47636 acpi_status status;
47637
47638 +#ifdef CONFIG_GRKERNSEC_KMEM
47639 + return -EPERM;
47640 +#endif
47641 +
47642 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47643 1, asus->debug.method_id,
47644 &input, &output);
47645 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47646 index 62f8030..c7f2a45 100644
47647 --- a/drivers/platform/x86/msi-laptop.c
47648 +++ b/drivers/platform/x86/msi-laptop.c
47649 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47650
47651 if (!quirks->ec_read_only) {
47652 /* allow userland write sysfs file */
47653 - dev_attr_bluetooth.store = store_bluetooth;
47654 - dev_attr_wlan.store = store_wlan;
47655 - dev_attr_threeg.store = store_threeg;
47656 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
47657 - dev_attr_wlan.attr.mode |= S_IWUSR;
47658 - dev_attr_threeg.attr.mode |= S_IWUSR;
47659 + pax_open_kernel();
47660 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47661 + *(void **)&dev_attr_wlan.store = store_wlan;
47662 + *(void **)&dev_attr_threeg.store = store_threeg;
47663 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47664 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47665 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47666 + pax_close_kernel();
47667 }
47668
47669 /* disable hardware control by fn key */
47670 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47671 index 70222f2..8c8ce66 100644
47672 --- a/drivers/platform/x86/msi-wmi.c
47673 +++ b/drivers/platform/x86/msi-wmi.c
47674 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47675 static void msi_wmi_notify(u32 value, void *context)
47676 {
47677 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47678 - static struct key_entry *key;
47679 + struct key_entry *key;
47680 union acpi_object *obj;
47681 acpi_status status;
47682
47683 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47684 index 8f8551a..3ace3ca 100644
47685 --- a/drivers/platform/x86/sony-laptop.c
47686 +++ b/drivers/platform/x86/sony-laptop.c
47687 @@ -2451,7 +2451,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47688 }
47689
47690 /* High speed charging function */
47691 -static struct device_attribute *hsc_handle;
47692 +static device_attribute_no_const *hsc_handle;
47693
47694 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47695 struct device_attribute *attr,
47696 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47697 index defb6af..7a5d3d1 100644
47698 --- a/drivers/platform/x86/thinkpad_acpi.c
47699 +++ b/drivers/platform/x86/thinkpad_acpi.c
47700 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
47701 return 0;
47702 }
47703
47704 -void static hotkey_mask_warn_incomplete_mask(void)
47705 +static void hotkey_mask_warn_incomplete_mask(void)
47706 {
47707 /* log only what the user can fix... */
47708 const u32 wantedmask = hotkey_driver_mask &
47709 @@ -2321,11 +2321,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
47710 }
47711 }
47712
47713 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47714 - struct tp_nvram_state *newn,
47715 - const u32 event_mask)
47716 -{
47717 -
47718 #define TPACPI_COMPARE_KEY(__scancode, __member) \
47719 do { \
47720 if ((event_mask & (1 << __scancode)) && \
47721 @@ -2339,36 +2334,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47722 tpacpi_hotkey_send_key(__scancode); \
47723 } while (0)
47724
47725 - void issue_volchange(const unsigned int oldvol,
47726 - const unsigned int newvol)
47727 - {
47728 - unsigned int i = oldvol;
47729 +static void issue_volchange(const unsigned int oldvol,
47730 + const unsigned int newvol,
47731 + const u32 event_mask)
47732 +{
47733 + unsigned int i = oldvol;
47734
47735 - while (i > newvol) {
47736 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47737 - i--;
47738 - }
47739 - while (i < newvol) {
47740 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47741 - i++;
47742 - }
47743 + while (i > newvol) {
47744 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47745 + i--;
47746 }
47747 + while (i < newvol) {
47748 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47749 + i++;
47750 + }
47751 +}
47752
47753 - void issue_brightnesschange(const unsigned int oldbrt,
47754 - const unsigned int newbrt)
47755 - {
47756 - unsigned int i = oldbrt;
47757 +static void issue_brightnesschange(const unsigned int oldbrt,
47758 + const unsigned int newbrt,
47759 + const u32 event_mask)
47760 +{
47761 + unsigned int i = oldbrt;
47762
47763 - while (i > newbrt) {
47764 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47765 - i--;
47766 - }
47767 - while (i < newbrt) {
47768 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47769 - i++;
47770 - }
47771 + while (i > newbrt) {
47772 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47773 + i--;
47774 + }
47775 + while (i < newbrt) {
47776 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47777 + i++;
47778 }
47779 +}
47780
47781 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47782 + struct tp_nvram_state *newn,
47783 + const u32 event_mask)
47784 +{
47785 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
47786 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
47787 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
47788 @@ -2402,7 +2403,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47789 oldn->volume_level != newn->volume_level) {
47790 /* recently muted, or repeated mute keypress, or
47791 * multiple presses ending in mute */
47792 - issue_volchange(oldn->volume_level, newn->volume_level);
47793 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47794 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
47795 }
47796 } else {
47797 @@ -2412,7 +2413,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47798 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47799 }
47800 if (oldn->volume_level != newn->volume_level) {
47801 - issue_volchange(oldn->volume_level, newn->volume_level);
47802 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47803 } else if (oldn->volume_toggle != newn->volume_toggle) {
47804 /* repeated vol up/down keypress at end of scale ? */
47805 if (newn->volume_level == 0)
47806 @@ -2425,7 +2426,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47807 /* handle brightness */
47808 if (oldn->brightness_level != newn->brightness_level) {
47809 issue_brightnesschange(oldn->brightness_level,
47810 - newn->brightness_level);
47811 + newn->brightness_level,
47812 + event_mask);
47813 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
47814 /* repeated key presses that didn't change state */
47815 if (newn->brightness_level == 0)
47816 @@ -2434,10 +2436,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47817 && !tp_features.bright_unkfw)
47818 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47819 }
47820 +}
47821
47822 #undef TPACPI_COMPARE_KEY
47823 #undef TPACPI_MAY_SEND_KEY
47824 -}
47825
47826 /*
47827 * Polling driver
47828 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47829 index 769d265..a3a05ca 100644
47830 --- a/drivers/pnp/pnpbios/bioscalls.c
47831 +++ b/drivers/pnp/pnpbios/bioscalls.c
47832 @@ -58,7 +58,7 @@ do { \
47833 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47834 } while(0)
47835
47836 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47837 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47838 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47839
47840 /*
47841 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47842
47843 cpu = get_cpu();
47844 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47845 +
47846 + pax_open_kernel();
47847 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47848 + pax_close_kernel();
47849
47850 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47851 spin_lock_irqsave(&pnp_bios_lock, flags);
47852 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47853 :"memory");
47854 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47855
47856 + pax_open_kernel();
47857 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47858 + pax_close_kernel();
47859 +
47860 put_cpu();
47861
47862 /* If we get here and this is set then the PnP BIOS faulted on us. */
47863 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47864 return status;
47865 }
47866
47867 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
47868 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47869 {
47870 int i;
47871
47872 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47873 pnp_bios_callpoint.offset = header->fields.pm16offset;
47874 pnp_bios_callpoint.segment = PNP_CS16;
47875
47876 + pax_open_kernel();
47877 +
47878 for_each_possible_cpu(i) {
47879 struct desc_struct *gdt = get_cpu_gdt_table(i);
47880 if (!gdt)
47881 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47882 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
47883 (unsigned long)__va(header->fields.pm16dseg));
47884 }
47885 +
47886 + pax_close_kernel();
47887 }
47888 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
47889 index bacddd1..65ea100 100644
47890 --- a/drivers/pnp/resource.c
47891 +++ b/drivers/pnp/resource.c
47892 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
47893 return 1;
47894
47895 /* check if the resource is valid */
47896 - if (*irq < 0 || *irq > 15)
47897 + if (*irq > 15)
47898 return 0;
47899
47900 /* check if the resource is reserved */
47901 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
47902 return 1;
47903
47904 /* check if the resource is valid */
47905 - if (*dma < 0 || *dma == 4 || *dma > 7)
47906 + if (*dma == 4 || *dma > 7)
47907 return 0;
47908
47909 /* check if the resource is reserved */
47910 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
47911 index 0c52e2a..3421ab7 100644
47912 --- a/drivers/power/pda_power.c
47913 +++ b/drivers/power/pda_power.c
47914 @@ -37,7 +37,11 @@ static int polling;
47915
47916 #if IS_ENABLED(CONFIG_USB_PHY)
47917 static struct usb_phy *transceiver;
47918 -static struct notifier_block otg_nb;
47919 +static int otg_handle_notification(struct notifier_block *nb,
47920 + unsigned long event, void *unused);
47921 +static struct notifier_block otg_nb = {
47922 + .notifier_call = otg_handle_notification
47923 +};
47924 #endif
47925
47926 static struct regulator *ac_draw;
47927 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
47928
47929 #if IS_ENABLED(CONFIG_USB_PHY)
47930 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
47931 - otg_nb.notifier_call = otg_handle_notification;
47932 ret = usb_register_notifier(transceiver, &otg_nb);
47933 if (ret) {
47934 dev_err(dev, "failure to register otg notifier\n");
47935 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
47936 index cc439fd..8fa30df 100644
47937 --- a/drivers/power/power_supply.h
47938 +++ b/drivers/power/power_supply.h
47939 @@ -16,12 +16,12 @@ struct power_supply;
47940
47941 #ifdef CONFIG_SYSFS
47942
47943 -extern void power_supply_init_attrs(struct device_type *dev_type);
47944 +extern void power_supply_init_attrs(void);
47945 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
47946
47947 #else
47948
47949 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
47950 +static inline void power_supply_init_attrs(void) {}
47951 #define power_supply_uevent NULL
47952
47953 #endif /* CONFIG_SYSFS */
47954 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
47955 index 2660664..75fcb04 100644
47956 --- a/drivers/power/power_supply_core.c
47957 +++ b/drivers/power/power_supply_core.c
47958 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
47959 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
47960 EXPORT_SYMBOL_GPL(power_supply_notifier);
47961
47962 -static struct device_type power_supply_dev_type;
47963 +extern const struct attribute_group *power_supply_attr_groups[];
47964 +static struct device_type power_supply_dev_type = {
47965 + .groups = power_supply_attr_groups,
47966 +};
47967
47968 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
47969 struct power_supply *supply)
47970 @@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
47971 return PTR_ERR(power_supply_class);
47972
47973 power_supply_class->dev_uevent = power_supply_uevent;
47974 - power_supply_init_attrs(&power_supply_dev_type);
47975 + power_supply_init_attrs();
47976
47977 return 0;
47978 }
47979 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
47980 index 44420d1..967126e 100644
47981 --- a/drivers/power/power_supply_sysfs.c
47982 +++ b/drivers/power/power_supply_sysfs.c
47983 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
47984 .is_visible = power_supply_attr_is_visible,
47985 };
47986
47987 -static const struct attribute_group *power_supply_attr_groups[] = {
47988 +const struct attribute_group *power_supply_attr_groups[] = {
47989 &power_supply_attr_group,
47990 NULL,
47991 };
47992
47993 -void power_supply_init_attrs(struct device_type *dev_type)
47994 +void power_supply_init_attrs(void)
47995 {
47996 int i;
47997
47998 - dev_type->groups = power_supply_attr_groups;
47999 -
48000 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48001 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48002 }
48003 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48004 index 84419af..268ede8 100644
48005 --- a/drivers/powercap/powercap_sys.c
48006 +++ b/drivers/powercap/powercap_sys.c
48007 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48008 struct device_attribute name_attr;
48009 };
48010
48011 +static ssize_t show_constraint_name(struct device *dev,
48012 + struct device_attribute *dev_attr,
48013 + char *buf);
48014 +
48015 static struct powercap_constraint_attr
48016 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48017 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48018 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48019 + .power_limit_attr = {
48020 + .attr = {
48021 + .name = NULL,
48022 + .mode = S_IWUSR | S_IRUGO
48023 + },
48024 + .show = show_constraint_power_limit_uw,
48025 + .store = store_constraint_power_limit_uw
48026 + },
48027 +
48028 + .time_window_attr = {
48029 + .attr = {
48030 + .name = NULL,
48031 + .mode = S_IWUSR | S_IRUGO
48032 + },
48033 + .show = show_constraint_time_window_us,
48034 + .store = store_constraint_time_window_us
48035 + },
48036 +
48037 + .max_power_attr = {
48038 + .attr = {
48039 + .name = NULL,
48040 + .mode = S_IRUGO
48041 + },
48042 + .show = show_constraint_max_power_uw,
48043 + .store = NULL
48044 + },
48045 +
48046 + .min_power_attr = {
48047 + .attr = {
48048 + .name = NULL,
48049 + .mode = S_IRUGO
48050 + },
48051 + .show = show_constraint_min_power_uw,
48052 + .store = NULL
48053 + },
48054 +
48055 + .max_time_window_attr = {
48056 + .attr = {
48057 + .name = NULL,
48058 + .mode = S_IRUGO
48059 + },
48060 + .show = show_constraint_max_time_window_us,
48061 + .store = NULL
48062 + },
48063 +
48064 + .min_time_window_attr = {
48065 + .attr = {
48066 + .name = NULL,
48067 + .mode = S_IRUGO
48068 + },
48069 + .show = show_constraint_min_time_window_us,
48070 + .store = NULL
48071 + },
48072 +
48073 + .name_attr = {
48074 + .attr = {
48075 + .name = NULL,
48076 + .mode = S_IRUGO
48077 + },
48078 + .show = show_constraint_name,
48079 + .store = NULL
48080 + }
48081 + }
48082 +};
48083
48084 /* A list of powercap control_types */
48085 static LIST_HEAD(powercap_cntrl_list);
48086 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48087 }
48088
48089 static int create_constraint_attribute(int id, const char *name,
48090 - int mode,
48091 - struct device_attribute *dev_attr,
48092 - ssize_t (*show)(struct device *,
48093 - struct device_attribute *, char *),
48094 - ssize_t (*store)(struct device *,
48095 - struct device_attribute *,
48096 - const char *, size_t)
48097 - )
48098 + struct device_attribute *dev_attr)
48099 {
48100 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48101
48102 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48103 - id, name);
48104 - if (!dev_attr->attr.name)
48105 + if (!name)
48106 return -ENOMEM;
48107 - dev_attr->attr.mode = mode;
48108 - dev_attr->show = show;
48109 - dev_attr->store = store;
48110 +
48111 + pax_open_kernel();
48112 + *(const char **)&dev_attr->attr.name = name;
48113 + pax_close_kernel();
48114
48115 return 0;
48116 }
48117 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48118
48119 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48120 ret = create_constraint_attribute(i, "power_limit_uw",
48121 - S_IWUSR | S_IRUGO,
48122 - &constraint_attrs[i].power_limit_attr,
48123 - show_constraint_power_limit_uw,
48124 - store_constraint_power_limit_uw);
48125 + &constraint_attrs[i].power_limit_attr);
48126 if (ret)
48127 goto err_alloc;
48128 ret = create_constraint_attribute(i, "time_window_us",
48129 - S_IWUSR | S_IRUGO,
48130 - &constraint_attrs[i].time_window_attr,
48131 - show_constraint_time_window_us,
48132 - store_constraint_time_window_us);
48133 + &constraint_attrs[i].time_window_attr);
48134 if (ret)
48135 goto err_alloc;
48136 - ret = create_constraint_attribute(i, "name", S_IRUGO,
48137 - &constraint_attrs[i].name_attr,
48138 - show_constraint_name,
48139 - NULL);
48140 + ret = create_constraint_attribute(i, "name",
48141 + &constraint_attrs[i].name_attr);
48142 if (ret)
48143 goto err_alloc;
48144 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48145 - &constraint_attrs[i].max_power_attr,
48146 - show_constraint_max_power_uw,
48147 - NULL);
48148 + ret = create_constraint_attribute(i, "max_power_uw",
48149 + &constraint_attrs[i].max_power_attr);
48150 if (ret)
48151 goto err_alloc;
48152 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48153 - &constraint_attrs[i].min_power_attr,
48154 - show_constraint_min_power_uw,
48155 - NULL);
48156 + ret = create_constraint_attribute(i, "min_power_uw",
48157 + &constraint_attrs[i].min_power_attr);
48158 if (ret)
48159 goto err_alloc;
48160 ret = create_constraint_attribute(i, "max_time_window_us",
48161 - S_IRUGO,
48162 - &constraint_attrs[i].max_time_window_attr,
48163 - show_constraint_max_time_window_us,
48164 - NULL);
48165 + &constraint_attrs[i].max_time_window_attr);
48166 if (ret)
48167 goto err_alloc;
48168 ret = create_constraint_attribute(i, "min_time_window_us",
48169 - S_IRUGO,
48170 - &constraint_attrs[i].min_time_window_attr,
48171 - show_constraint_min_time_window_us,
48172 - NULL);
48173 + &constraint_attrs[i].min_time_window_attr);
48174 if (ret)
48175 goto err_alloc;
48176
48177 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48178 power_zone->zone_dev_attrs[count++] =
48179 &dev_attr_max_energy_range_uj.attr;
48180 if (power_zone->ops->get_energy_uj) {
48181 + pax_open_kernel();
48182 if (power_zone->ops->reset_energy_uj)
48183 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48184 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48185 else
48186 - dev_attr_energy_uj.attr.mode = S_IRUGO;
48187 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48188 + pax_close_kernel();
48189 power_zone->zone_dev_attrs[count++] =
48190 &dev_attr_energy_uj.attr;
48191 }
48192 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48193 index afca1bc..86840b8 100644
48194 --- a/drivers/regulator/core.c
48195 +++ b/drivers/regulator/core.c
48196 @@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48197 {
48198 const struct regulation_constraints *constraints = NULL;
48199 const struct regulator_init_data *init_data;
48200 - static atomic_t regulator_no = ATOMIC_INIT(0);
48201 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48202 struct regulator_dev *rdev;
48203 struct device *dev;
48204 int ret, i;
48205 @@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48206 rdev->dev.of_node = config->of_node;
48207 rdev->dev.parent = dev;
48208 dev_set_name(&rdev->dev, "regulator.%d",
48209 - atomic_inc_return(&regulator_no) - 1);
48210 + atomic_inc_return_unchecked(&regulator_no) - 1);
48211 ret = device_register(&rdev->dev);
48212 if (ret != 0) {
48213 put_device(&rdev->dev);
48214 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48215 index 8d94d3d..653b623 100644
48216 --- a/drivers/regulator/max8660.c
48217 +++ b/drivers/regulator/max8660.c
48218 @@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48219 max8660->shadow_regs[MAX8660_OVER1] = 5;
48220 } else {
48221 /* Otherwise devices can be toggled via software */
48222 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
48223 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
48224 + pax_open_kernel();
48225 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48226 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48227 + pax_close_kernel();
48228 }
48229
48230 /*
48231 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48232 index 892aa1e..ebd1b9c 100644
48233 --- a/drivers/regulator/max8973-regulator.c
48234 +++ b/drivers/regulator/max8973-regulator.c
48235 @@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48236 if (!pdata || !pdata->enable_ext_control) {
48237 max->desc.enable_reg = MAX8973_VOUT;
48238 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48239 - max->ops.enable = regulator_enable_regmap;
48240 - max->ops.disable = regulator_disable_regmap;
48241 - max->ops.is_enabled = regulator_is_enabled_regmap;
48242 + pax_open_kernel();
48243 + *(void **)&max->ops.enable = regulator_enable_regmap;
48244 + *(void **)&max->ops.disable = regulator_disable_regmap;
48245 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48246 + pax_close_kernel();
48247 }
48248
48249 if (pdata) {
48250 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48251 index f374fa5..26f0683 100644
48252 --- a/drivers/regulator/mc13892-regulator.c
48253 +++ b/drivers/regulator/mc13892-regulator.c
48254 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48255 }
48256 mc13xxx_unlock(mc13892);
48257
48258 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48259 + pax_open_kernel();
48260 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48261 = mc13892_vcam_set_mode;
48262 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48263 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48264 = mc13892_vcam_get_mode;
48265 + pax_close_kernel();
48266
48267 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48268 ARRAY_SIZE(mc13892_regulators));
48269 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48270 index cae212f..58a3980 100644
48271 --- a/drivers/rtc/rtc-cmos.c
48272 +++ b/drivers/rtc/rtc-cmos.c
48273 @@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48274 hpet_rtc_timer_init();
48275
48276 /* export at least the first block of NVRAM */
48277 - nvram.size = address_space - NVRAM_OFFSET;
48278 + pax_open_kernel();
48279 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48280 + pax_close_kernel();
48281 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48282 if (retval < 0) {
48283 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48284 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48285 index d049393..bb20be0 100644
48286 --- a/drivers/rtc/rtc-dev.c
48287 +++ b/drivers/rtc/rtc-dev.c
48288 @@ -16,6 +16,7 @@
48289 #include <linux/module.h>
48290 #include <linux/rtc.h>
48291 #include <linux/sched.h>
48292 +#include <linux/grsecurity.h>
48293 #include "rtc-core.h"
48294
48295 static dev_t rtc_devt;
48296 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48297 if (copy_from_user(&tm, uarg, sizeof(tm)))
48298 return -EFAULT;
48299
48300 + gr_log_timechange();
48301 +
48302 return rtc_set_time(rtc, &tm);
48303
48304 case RTC_PIE_ON:
48305 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48306 index 4e75345..09f8663 100644
48307 --- a/drivers/rtc/rtc-ds1307.c
48308 +++ b/drivers/rtc/rtc-ds1307.c
48309 @@ -107,7 +107,7 @@ struct ds1307 {
48310 u8 offset; /* register's offset */
48311 u8 regs[11];
48312 u16 nvram_offset;
48313 - struct bin_attribute *nvram;
48314 + bin_attribute_no_const *nvram;
48315 enum ds_type type;
48316 unsigned long flags;
48317 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48318 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48319 index 11880c1..b823aa4 100644
48320 --- a/drivers/rtc/rtc-m48t59.c
48321 +++ b/drivers/rtc/rtc-m48t59.c
48322 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48323 if (IS_ERR(m48t59->rtc))
48324 return PTR_ERR(m48t59->rtc);
48325
48326 - m48t59_nvram_attr.size = pdata->offset;
48327 + pax_open_kernel();
48328 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48329 + pax_close_kernel();
48330
48331 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48332 if (ret)
48333 diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48334 index 14b5f8d..cc9bd26 100644
48335 --- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48336 +++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48337 @@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48338 for (bit = 0; bit < 8; bit++) {
48339
48340 if ((pci_status[i] & (0x1 << bit)) != 0) {
48341 - static const char *s;
48342 + const char *s;
48343
48344 s = pci_status_strings[bit];
48345 if (i == 7/*TARG*/ && bit == 3)
48346 @@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48347
48348 for (bit = 0; bit < 8; bit++) {
48349
48350 - if ((split_status[i] & (0x1 << bit)) != 0) {
48351 - static const char *s;
48352 -
48353 - s = split_status_strings[bit];
48354 - printk(s, ahd_name(ahd),
48355 + if ((split_status[i] & (0x1 << bit)) != 0)
48356 + printk(split_status_strings[bit], ahd_name(ahd),
48357 split_status_source[i]);
48358 - }
48359
48360 if (i > 1)
48361 continue;
48362
48363 - if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48364 - static const char *s;
48365 -
48366 - s = split_status_strings[bit];
48367 - printk(s, ahd_name(ahd), "SG");
48368 - }
48369 + if ((sg_split_status[i] & (0x1 << bit)) != 0)
48370 + printk(split_status_strings[bit], ahd_name(ahd), "SG");
48371 }
48372 }
48373 /*
48374 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48375 index e693af6..2e525b6 100644
48376 --- a/drivers/scsi/bfa/bfa_fcpim.h
48377 +++ b/drivers/scsi/bfa/bfa_fcpim.h
48378 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
48379
48380 struct bfa_itn_s {
48381 bfa_isr_func_t isr;
48382 -};
48383 +} __no_const;
48384
48385 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48386 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48387 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48388 index a3ab5cc..8143622 100644
48389 --- a/drivers/scsi/bfa/bfa_fcs.c
48390 +++ b/drivers/scsi/bfa/bfa_fcs.c
48391 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48392 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48393
48394 static struct bfa_fcs_mod_s fcs_modules[] = {
48395 - { bfa_fcs_port_attach, NULL, NULL },
48396 - { bfa_fcs_uf_attach, NULL, NULL },
48397 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48398 - bfa_fcs_fabric_modexit },
48399 + {
48400 + .attach = bfa_fcs_port_attach,
48401 + .modinit = NULL,
48402 + .modexit = NULL
48403 + },
48404 + {
48405 + .attach = bfa_fcs_uf_attach,
48406 + .modinit = NULL,
48407 + .modexit = NULL
48408 + },
48409 + {
48410 + .attach = bfa_fcs_fabric_attach,
48411 + .modinit = bfa_fcs_fabric_modinit,
48412 + .modexit = bfa_fcs_fabric_modexit
48413 + },
48414 };
48415
48416 /*
48417 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48418 index ff75ef8..2dfe00a 100644
48419 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
48420 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48421 @@ -89,15 +89,26 @@ static struct {
48422 void (*offline) (struct bfa_fcs_lport_s *port);
48423 } __port_action[] = {
48424 {
48425 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48426 - bfa_fcs_lport_unknown_offline}, {
48427 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48428 - bfa_fcs_lport_fab_offline}, {
48429 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48430 - bfa_fcs_lport_n2n_offline}, {
48431 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48432 - bfa_fcs_lport_loop_offline},
48433 - };
48434 + .init = bfa_fcs_lport_unknown_init,
48435 + .online = bfa_fcs_lport_unknown_online,
48436 + .offline = bfa_fcs_lport_unknown_offline
48437 + },
48438 + {
48439 + .init = bfa_fcs_lport_fab_init,
48440 + .online = bfa_fcs_lport_fab_online,
48441 + .offline = bfa_fcs_lport_fab_offline
48442 + },
48443 + {
48444 + .init = bfa_fcs_lport_n2n_init,
48445 + .online = bfa_fcs_lport_n2n_online,
48446 + .offline = bfa_fcs_lport_n2n_offline
48447 + },
48448 + {
48449 + .init = bfa_fcs_lport_loop_init,
48450 + .online = bfa_fcs_lport_loop_online,
48451 + .offline = bfa_fcs_lport_loop_offline
48452 + },
48453 +};
48454
48455 /*
48456 * fcs_port_sm FCS logical port state machine
48457 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48458 index 2e28392..9d865b6 100644
48459 --- a/drivers/scsi/bfa/bfa_ioc.h
48460 +++ b/drivers/scsi/bfa/bfa_ioc.h
48461 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48462 bfa_ioc_disable_cbfn_t disable_cbfn;
48463 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48464 bfa_ioc_reset_cbfn_t reset_cbfn;
48465 -};
48466 +} __no_const;
48467
48468 /*
48469 * IOC event notification mechanism.
48470 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48471 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48472 enum bfi_ioc_state fwstate);
48473 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48474 -};
48475 +} __no_const;
48476
48477 /*
48478 * Queue element to wait for room in request queue. FIFO order is
48479 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48480 index a14c784..6de6790 100644
48481 --- a/drivers/scsi/bfa/bfa_modules.h
48482 +++ b/drivers/scsi/bfa/bfa_modules.h
48483 @@ -78,12 +78,12 @@ enum {
48484 \
48485 extern struct bfa_module_s hal_mod_ ## __mod; \
48486 struct bfa_module_s hal_mod_ ## __mod = { \
48487 - bfa_ ## __mod ## _meminfo, \
48488 - bfa_ ## __mod ## _attach, \
48489 - bfa_ ## __mod ## _detach, \
48490 - bfa_ ## __mod ## _start, \
48491 - bfa_ ## __mod ## _stop, \
48492 - bfa_ ## __mod ## _iocdisable, \
48493 + .meminfo = bfa_ ## __mod ## _meminfo, \
48494 + .attach = bfa_ ## __mod ## _attach, \
48495 + .detach = bfa_ ## __mod ## _detach, \
48496 + .start = bfa_ ## __mod ## _start, \
48497 + .stop = bfa_ ## __mod ## _stop, \
48498 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
48499 }
48500
48501 #define BFA_CACHELINE_SZ (256)
48502 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48503 index 045c4e1..13de803 100644
48504 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
48505 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48506 @@ -33,8 +33,8 @@
48507 */
48508 #include "libfcoe.h"
48509
48510 -static atomic_t ctlr_num;
48511 -static atomic_t fcf_num;
48512 +static atomic_unchecked_t ctlr_num;
48513 +static atomic_unchecked_t fcf_num;
48514
48515 /*
48516 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48517 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48518 if (!ctlr)
48519 goto out;
48520
48521 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48522 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48523 ctlr->f = f;
48524 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48525 INIT_LIST_HEAD(&ctlr->fcfs);
48526 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48527 fcf->dev.parent = &ctlr->dev;
48528 fcf->dev.bus = &fcoe_bus_type;
48529 fcf->dev.type = &fcoe_fcf_device_type;
48530 - fcf->id = atomic_inc_return(&fcf_num) - 1;
48531 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48532 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48533
48534 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48535 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48536 {
48537 int error;
48538
48539 - atomic_set(&ctlr_num, 0);
48540 - atomic_set(&fcf_num, 0);
48541 + atomic_set_unchecked(&ctlr_num, 0);
48542 + atomic_set_unchecked(&fcf_num, 0);
48543
48544 error = bus_register(&fcoe_bus_type);
48545 if (error)
48546 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48547 index f28ea07..34b16d3 100644
48548 --- a/drivers/scsi/hosts.c
48549 +++ b/drivers/scsi/hosts.c
48550 @@ -42,7 +42,7 @@
48551 #include "scsi_logging.h"
48552
48553
48554 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48555 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48556
48557
48558 static void scsi_host_cls_release(struct device *dev)
48559 @@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48560 * subtract one because we increment first then return, but we need to
48561 * know what the next host number was before increment
48562 */
48563 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48564 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48565 shost->dma_channel = 0xff;
48566
48567 /* These three are default values which can be overridden */
48568 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48569 index 868318a..e07ef3b 100644
48570 --- a/drivers/scsi/hpsa.c
48571 +++ b/drivers/scsi/hpsa.c
48572 @@ -571,7 +571,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48573 unsigned long flags;
48574
48575 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48576 - return h->access.command_completed(h, q);
48577 + return h->access->command_completed(h, q);
48578
48579 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48580 a = rq->head[rq->current_entry];
48581 @@ -3474,7 +3474,7 @@ static void start_io(struct ctlr_info *h)
48582 while (!list_empty(&h->reqQ)) {
48583 c = list_entry(h->reqQ.next, struct CommandList, list);
48584 /* can't do anything if fifo is full */
48585 - if ((h->access.fifo_full(h))) {
48586 + if ((h->access->fifo_full(h))) {
48587 h->fifo_recently_full = 1;
48588 dev_warn(&h->pdev->dev, "fifo full\n");
48589 break;
48590 @@ -3498,7 +3498,7 @@ static void start_io(struct ctlr_info *h)
48591
48592 /* Tell the controller execute command */
48593 spin_unlock_irqrestore(&h->lock, flags);
48594 - h->access.submit_command(h, c);
48595 + h->access->submit_command(h, c);
48596 spin_lock_irqsave(&h->lock, flags);
48597 }
48598 spin_unlock_irqrestore(&h->lock, flags);
48599 @@ -3506,17 +3506,17 @@ static void start_io(struct ctlr_info *h)
48600
48601 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48602 {
48603 - return h->access.command_completed(h, q);
48604 + return h->access->command_completed(h, q);
48605 }
48606
48607 static inline bool interrupt_pending(struct ctlr_info *h)
48608 {
48609 - return h->access.intr_pending(h);
48610 + return h->access->intr_pending(h);
48611 }
48612
48613 static inline long interrupt_not_for_us(struct ctlr_info *h)
48614 {
48615 - return (h->access.intr_pending(h) == 0) ||
48616 + return (h->access->intr_pending(h) == 0) ||
48617 (h->interrupts_enabled == 0);
48618 }
48619
48620 @@ -4442,7 +4442,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48621 if (prod_index < 0)
48622 return -ENODEV;
48623 h->product_name = products[prod_index].product_name;
48624 - h->access = *(products[prod_index].access);
48625 + h->access = products[prod_index].access;
48626
48627 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48628 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48629 @@ -4712,7 +4712,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48630 {
48631 unsigned long flags;
48632
48633 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48634 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48635 spin_lock_irqsave(&h->lock, flags);
48636 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48637 spin_unlock_irqrestore(&h->lock, flags);
48638 @@ -4843,7 +4843,7 @@ reinit_after_soft_reset:
48639 }
48640
48641 /* make sure the board interrupts are off */
48642 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48643 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48644
48645 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48646 goto clean2;
48647 @@ -4877,7 +4877,7 @@ reinit_after_soft_reset:
48648 * fake ones to scoop up any residual completions.
48649 */
48650 spin_lock_irqsave(&h->lock, flags);
48651 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48652 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48653 spin_unlock_irqrestore(&h->lock, flags);
48654 free_irqs(h);
48655 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48656 @@ -4896,9 +4896,9 @@ reinit_after_soft_reset:
48657 dev_info(&h->pdev->dev, "Board READY.\n");
48658 dev_info(&h->pdev->dev,
48659 "Waiting for stale completions to drain.\n");
48660 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48661 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48662 msleep(10000);
48663 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48664 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48665
48666 rc = controller_reset_failed(h->cfgtable);
48667 if (rc)
48668 @@ -4919,7 +4919,7 @@ reinit_after_soft_reset:
48669 }
48670
48671 /* Turn the interrupts on so we can service requests */
48672 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48673 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48674
48675 hpsa_hba_inquiry(h);
48676 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48677 @@ -4988,7 +4988,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48678 * To write all data in the battery backed cache to disks
48679 */
48680 hpsa_flush_cache(h);
48681 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48682 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48683 hpsa_free_irqs_and_disable_msix(h);
48684 }
48685
48686 @@ -5162,7 +5162,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
48687 return;
48688 }
48689 /* Change the access methods to the performant access methods */
48690 - h->access = SA5_performant_access;
48691 + h->access = &SA5_performant_access;
48692 h->transMethod = CFGTBL_Trans_Performant;
48693 }
48694
48695 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48696 index 01c3283..4655219 100644
48697 --- a/drivers/scsi/hpsa.h
48698 +++ b/drivers/scsi/hpsa.h
48699 @@ -79,7 +79,7 @@ struct ctlr_info {
48700 unsigned int msix_vector;
48701 unsigned int msi_vector;
48702 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48703 - struct access_method access;
48704 + struct access_method *access;
48705
48706 /* queue and queue Info */
48707 struct list_head reqQ;
48708 @@ -388,19 +388,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
48709 }
48710
48711 static struct access_method SA5_access = {
48712 - SA5_submit_command,
48713 - SA5_intr_mask,
48714 - SA5_fifo_full,
48715 - SA5_intr_pending,
48716 - SA5_completed,
48717 + .submit_command = SA5_submit_command,
48718 + .set_intr_mask = SA5_intr_mask,
48719 + .fifo_full = SA5_fifo_full,
48720 + .intr_pending = SA5_intr_pending,
48721 + .command_completed = SA5_completed,
48722 };
48723
48724 static struct access_method SA5_performant_access = {
48725 - SA5_submit_command,
48726 - SA5_performant_intr_mask,
48727 - SA5_fifo_full,
48728 - SA5_performant_intr_pending,
48729 - SA5_performant_completed,
48730 + .submit_command = SA5_submit_command,
48731 + .set_intr_mask = SA5_performant_intr_mask,
48732 + .fifo_full = SA5_fifo_full,
48733 + .intr_pending = SA5_performant_intr_pending,
48734 + .command_completed = SA5_performant_completed,
48735 };
48736
48737 struct board_type {
48738 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48739 index 1b3a094..068e683 100644
48740 --- a/drivers/scsi/libfc/fc_exch.c
48741 +++ b/drivers/scsi/libfc/fc_exch.c
48742 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
48743 u16 pool_max_index;
48744
48745 struct {
48746 - atomic_t no_free_exch;
48747 - atomic_t no_free_exch_xid;
48748 - atomic_t xid_not_found;
48749 - atomic_t xid_busy;
48750 - atomic_t seq_not_found;
48751 - atomic_t non_bls_resp;
48752 + atomic_unchecked_t no_free_exch;
48753 + atomic_unchecked_t no_free_exch_xid;
48754 + atomic_unchecked_t xid_not_found;
48755 + atomic_unchecked_t xid_busy;
48756 + atomic_unchecked_t seq_not_found;
48757 + atomic_unchecked_t non_bls_resp;
48758 } stats;
48759 };
48760
48761 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48762 /* allocate memory for exchange */
48763 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48764 if (!ep) {
48765 - atomic_inc(&mp->stats.no_free_exch);
48766 + atomic_inc_unchecked(&mp->stats.no_free_exch);
48767 goto out;
48768 }
48769 memset(ep, 0, sizeof(*ep));
48770 @@ -874,7 +874,7 @@ out:
48771 return ep;
48772 err:
48773 spin_unlock_bh(&pool->lock);
48774 - atomic_inc(&mp->stats.no_free_exch_xid);
48775 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48776 mempool_free(ep, mp->ep_pool);
48777 return NULL;
48778 }
48779 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48780 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48781 ep = fc_exch_find(mp, xid);
48782 if (!ep) {
48783 - atomic_inc(&mp->stats.xid_not_found);
48784 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48785 reject = FC_RJT_OX_ID;
48786 goto out;
48787 }
48788 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48789 ep = fc_exch_find(mp, xid);
48790 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48791 if (ep) {
48792 - atomic_inc(&mp->stats.xid_busy);
48793 + atomic_inc_unchecked(&mp->stats.xid_busy);
48794 reject = FC_RJT_RX_ID;
48795 goto rel;
48796 }
48797 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48798 }
48799 xid = ep->xid; /* get our XID */
48800 } else if (!ep) {
48801 - atomic_inc(&mp->stats.xid_not_found);
48802 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48803 reject = FC_RJT_RX_ID; /* XID not found */
48804 goto out;
48805 }
48806 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48807 } else {
48808 sp = &ep->seq;
48809 if (sp->id != fh->fh_seq_id) {
48810 - atomic_inc(&mp->stats.seq_not_found);
48811 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48812 if (f_ctl & FC_FC_END_SEQ) {
48813 /*
48814 * Update sequence_id based on incoming last
48815 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48816
48817 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48818 if (!ep) {
48819 - atomic_inc(&mp->stats.xid_not_found);
48820 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48821 goto out;
48822 }
48823 if (ep->esb_stat & ESB_ST_COMPLETE) {
48824 - atomic_inc(&mp->stats.xid_not_found);
48825 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48826 goto rel;
48827 }
48828 if (ep->rxid == FC_XID_UNKNOWN)
48829 ep->rxid = ntohs(fh->fh_rx_id);
48830 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
48831 - atomic_inc(&mp->stats.xid_not_found);
48832 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48833 goto rel;
48834 }
48835 if (ep->did != ntoh24(fh->fh_s_id) &&
48836 ep->did != FC_FID_FLOGI) {
48837 - atomic_inc(&mp->stats.xid_not_found);
48838 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48839 goto rel;
48840 }
48841 sof = fr_sof(fp);
48842 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48843 sp->ssb_stat |= SSB_ST_RESP;
48844 sp->id = fh->fh_seq_id;
48845 } else if (sp->id != fh->fh_seq_id) {
48846 - atomic_inc(&mp->stats.seq_not_found);
48847 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48848 goto rel;
48849 }
48850
48851 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48852 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
48853
48854 if (!sp)
48855 - atomic_inc(&mp->stats.xid_not_found);
48856 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48857 else
48858 - atomic_inc(&mp->stats.non_bls_resp);
48859 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
48860
48861 fc_frame_free(fp);
48862 }
48863 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
48864
48865 list_for_each_entry(ema, &lport->ema_list, ema_list) {
48866 mp = ema->mp;
48867 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
48868 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
48869 st->fc_no_free_exch_xid +=
48870 - atomic_read(&mp->stats.no_free_exch_xid);
48871 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
48872 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
48873 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
48874 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
48875 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
48876 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
48877 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
48878 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
48879 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
48880 }
48881 }
48882 EXPORT_SYMBOL(fc_exch_update_stats);
48883 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
48884 index d289583..b745eec 100644
48885 --- a/drivers/scsi/libsas/sas_ata.c
48886 +++ b/drivers/scsi/libsas/sas_ata.c
48887 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
48888 .postreset = ata_std_postreset,
48889 .error_handler = ata_std_error_handler,
48890 .post_internal_cmd = sas_ata_post_internal,
48891 - .qc_defer = ata_std_qc_defer,
48892 + .qc_defer = ata_std_qc_defer,
48893 .qc_prep = ata_noop_qc_prep,
48894 .qc_issue = sas_ata_qc_issue,
48895 .qc_fill_rtf = sas_ata_qc_fill_rtf,
48896 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
48897 index 4e1b75c..0bbdfa9 100644
48898 --- a/drivers/scsi/lpfc/lpfc.h
48899 +++ b/drivers/scsi/lpfc/lpfc.h
48900 @@ -432,7 +432,7 @@ struct lpfc_vport {
48901 struct dentry *debug_nodelist;
48902 struct dentry *vport_debugfs_root;
48903 struct lpfc_debugfs_trc *disc_trc;
48904 - atomic_t disc_trc_cnt;
48905 + atomic_unchecked_t disc_trc_cnt;
48906 #endif
48907 uint8_t stat_data_enabled;
48908 uint8_t stat_data_blocked;
48909 @@ -865,8 +865,8 @@ struct lpfc_hba {
48910 struct timer_list fabric_block_timer;
48911 unsigned long bit_flags;
48912 #define FABRIC_COMANDS_BLOCKED 0
48913 - atomic_t num_rsrc_err;
48914 - atomic_t num_cmd_success;
48915 + atomic_unchecked_t num_rsrc_err;
48916 + atomic_unchecked_t num_cmd_success;
48917 unsigned long last_rsrc_error_time;
48918 unsigned long last_ramp_down_time;
48919 unsigned long last_ramp_up_time;
48920 @@ -902,7 +902,7 @@ struct lpfc_hba {
48921
48922 struct dentry *debug_slow_ring_trc;
48923 struct lpfc_debugfs_trc *slow_ring_trc;
48924 - atomic_t slow_ring_trc_cnt;
48925 + atomic_unchecked_t slow_ring_trc_cnt;
48926 /* iDiag debugfs sub-directory */
48927 struct dentry *idiag_root;
48928 struct dentry *idiag_pci_cfg;
48929 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
48930 index b800cc9..16b6a91 100644
48931 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
48932 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
48933 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
48934
48935 #include <linux/debugfs.h>
48936
48937 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48938 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48939 static unsigned long lpfc_debugfs_start_time = 0L;
48940
48941 /* iDiag */
48942 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
48943 lpfc_debugfs_enable = 0;
48944
48945 len = 0;
48946 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
48947 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
48948 (lpfc_debugfs_max_disc_trc - 1);
48949 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
48950 dtp = vport->disc_trc + i;
48951 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
48952 lpfc_debugfs_enable = 0;
48953
48954 len = 0;
48955 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
48956 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
48957 (lpfc_debugfs_max_slow_ring_trc - 1);
48958 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
48959 dtp = phba->slow_ring_trc + i;
48960 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
48961 !vport || !vport->disc_trc)
48962 return;
48963
48964 - index = atomic_inc_return(&vport->disc_trc_cnt) &
48965 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
48966 (lpfc_debugfs_max_disc_trc - 1);
48967 dtp = vport->disc_trc + index;
48968 dtp->fmt = fmt;
48969 dtp->data1 = data1;
48970 dtp->data2 = data2;
48971 dtp->data3 = data3;
48972 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48973 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48974 dtp->jif = jiffies;
48975 #endif
48976 return;
48977 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
48978 !phba || !phba->slow_ring_trc)
48979 return;
48980
48981 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
48982 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
48983 (lpfc_debugfs_max_slow_ring_trc - 1);
48984 dtp = phba->slow_ring_trc + index;
48985 dtp->fmt = fmt;
48986 dtp->data1 = data1;
48987 dtp->data2 = data2;
48988 dtp->data3 = data3;
48989 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48990 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48991 dtp->jif = jiffies;
48992 #endif
48993 return;
48994 @@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
48995 "slow_ring buffer\n");
48996 goto debug_failed;
48997 }
48998 - atomic_set(&phba->slow_ring_trc_cnt, 0);
48999 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49000 memset(phba->slow_ring_trc, 0,
49001 (sizeof(struct lpfc_debugfs_trc) *
49002 lpfc_debugfs_max_slow_ring_trc));
49003 @@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49004 "buffer\n");
49005 goto debug_failed;
49006 }
49007 - atomic_set(&vport->disc_trc_cnt, 0);
49008 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49009
49010 snprintf(name, sizeof(name), "discovery_trace");
49011 vport->debug_disc_trc =
49012 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49013 index 68c94cc..8c27be5 100644
49014 --- a/drivers/scsi/lpfc/lpfc_init.c
49015 +++ b/drivers/scsi/lpfc/lpfc_init.c
49016 @@ -10949,8 +10949,10 @@ lpfc_init(void)
49017 "misc_register returned with status %d", error);
49018
49019 if (lpfc_enable_npiv) {
49020 - lpfc_transport_functions.vport_create = lpfc_vport_create;
49021 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49022 + pax_open_kernel();
49023 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49024 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49025 + pax_close_kernel();
49026 }
49027 lpfc_transport_template =
49028 fc_attach_transport(&lpfc_transport_functions);
49029 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49030 index b2ede05..aaf482ca 100644
49031 --- a/drivers/scsi/lpfc/lpfc_scsi.c
49032 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
49033 @@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49034 uint32_t evt_posted;
49035
49036 spin_lock_irqsave(&phba->hbalock, flags);
49037 - atomic_inc(&phba->num_rsrc_err);
49038 + atomic_inc_unchecked(&phba->num_rsrc_err);
49039 phba->last_rsrc_error_time = jiffies;
49040
49041 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49042 @@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49043 unsigned long flags;
49044 struct lpfc_hba *phba = vport->phba;
49045 uint32_t evt_posted;
49046 - atomic_inc(&phba->num_cmd_success);
49047 + atomic_inc_unchecked(&phba->num_cmd_success);
49048
49049 if (vport->cfg_lun_queue_depth <= queue_depth)
49050 return;
49051 @@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49052 unsigned long num_rsrc_err, num_cmd_success;
49053 int i;
49054
49055 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49056 - num_cmd_success = atomic_read(&phba->num_cmd_success);
49057 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49058 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49059
49060 /*
49061 * The error and success command counters are global per
49062 @@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49063 }
49064 }
49065 lpfc_destroy_vport_work_array(phba, vports);
49066 - atomic_set(&phba->num_rsrc_err, 0);
49067 - atomic_set(&phba->num_cmd_success, 0);
49068 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49069 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49070 }
49071
49072 /**
49073 @@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49074 }
49075 }
49076 lpfc_destroy_vport_work_array(phba, vports);
49077 - atomic_set(&phba->num_rsrc_err, 0);
49078 - atomic_set(&phba->num_cmd_success, 0);
49079 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49080 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49081 }
49082
49083 /**
49084 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49085 index 7f0af4f..193ac3e 100644
49086 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49087 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49088 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49089 {
49090 struct scsi_device *sdev = to_scsi_device(dev);
49091 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49092 - static struct _raid_device *raid_device;
49093 + struct _raid_device *raid_device;
49094 unsigned long flags;
49095 Mpi2RaidVolPage0_t vol_pg0;
49096 Mpi2ConfigReply_t mpi_reply;
49097 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49098 {
49099 struct scsi_device *sdev = to_scsi_device(dev);
49100 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49101 - static struct _raid_device *raid_device;
49102 + struct _raid_device *raid_device;
49103 unsigned long flags;
49104 Mpi2RaidVolPage0_t vol_pg0;
49105 Mpi2ConfigReply_t mpi_reply;
49106 @@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49107 struct fw_event_work *fw_event)
49108 {
49109 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49110 - static struct _raid_device *raid_device;
49111 + struct _raid_device *raid_device;
49112 unsigned long flags;
49113 u16 handle;
49114
49115 @@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49116 u64 sas_address;
49117 struct _sas_device *sas_device;
49118 struct _sas_node *expander_device;
49119 - static struct _raid_device *raid_device;
49120 + struct _raid_device *raid_device;
49121 u8 retry_count;
49122 unsigned long flags;
49123
49124 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49125 index be8ce54..94ed33a 100644
49126 --- a/drivers/scsi/pmcraid.c
49127 +++ b/drivers/scsi/pmcraid.c
49128 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49129 res->scsi_dev = scsi_dev;
49130 scsi_dev->hostdata = res;
49131 res->change_detected = 0;
49132 - atomic_set(&res->read_failures, 0);
49133 - atomic_set(&res->write_failures, 0);
49134 + atomic_set_unchecked(&res->read_failures, 0);
49135 + atomic_set_unchecked(&res->write_failures, 0);
49136 rc = 0;
49137 }
49138 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49139 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49140
49141 /* If this was a SCSI read/write command keep count of errors */
49142 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49143 - atomic_inc(&res->read_failures);
49144 + atomic_inc_unchecked(&res->read_failures);
49145 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49146 - atomic_inc(&res->write_failures);
49147 + atomic_inc_unchecked(&res->write_failures);
49148
49149 if (!RES_IS_GSCSI(res->cfg_entry) &&
49150 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49151 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49152 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49153 * hrrq_id assigned here in queuecommand
49154 */
49155 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49156 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49157 pinstance->num_hrrq;
49158 cmd->cmd_done = pmcraid_io_done;
49159
49160 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49161 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49162 * hrrq_id assigned here in queuecommand
49163 */
49164 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49165 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49166 pinstance->num_hrrq;
49167
49168 if (request_size) {
49169 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49170
49171 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49172 /* add resources only after host is added into system */
49173 - if (!atomic_read(&pinstance->expose_resources))
49174 + if (!atomic_read_unchecked(&pinstance->expose_resources))
49175 return;
49176
49177 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49178 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49179 init_waitqueue_head(&pinstance->reset_wait_q);
49180
49181 atomic_set(&pinstance->outstanding_cmds, 0);
49182 - atomic_set(&pinstance->last_message_id, 0);
49183 - atomic_set(&pinstance->expose_resources, 0);
49184 + atomic_set_unchecked(&pinstance->last_message_id, 0);
49185 + atomic_set_unchecked(&pinstance->expose_resources, 0);
49186
49187 INIT_LIST_HEAD(&pinstance->free_res_q);
49188 INIT_LIST_HEAD(&pinstance->used_res_q);
49189 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49190 /* Schedule worker thread to handle CCN and take care of adding and
49191 * removing devices to OS
49192 */
49193 - atomic_set(&pinstance->expose_resources, 1);
49194 + atomic_set_unchecked(&pinstance->expose_resources, 1);
49195 schedule_work(&pinstance->worker_q);
49196 return rc;
49197
49198 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49199 index e1d150f..6c6df44 100644
49200 --- a/drivers/scsi/pmcraid.h
49201 +++ b/drivers/scsi/pmcraid.h
49202 @@ -748,7 +748,7 @@ struct pmcraid_instance {
49203 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49204
49205 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49206 - atomic_t last_message_id;
49207 + atomic_unchecked_t last_message_id;
49208
49209 /* configuration table */
49210 struct pmcraid_config_table *cfg_table;
49211 @@ -777,7 +777,7 @@ struct pmcraid_instance {
49212 atomic_t outstanding_cmds;
49213
49214 /* should add/delete resources to mid-layer now ?*/
49215 - atomic_t expose_resources;
49216 + atomic_unchecked_t expose_resources;
49217
49218
49219
49220 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49221 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49222 };
49223 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49224 - atomic_t read_failures; /* count of failed READ commands */
49225 - atomic_t write_failures; /* count of failed WRITE commands */
49226 + atomic_unchecked_t read_failures; /* count of failed READ commands */
49227 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49228
49229 /* To indicate add/delete/modify during CCN */
49230 u8 change_detected;
49231 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49232 index 4a0d7c9..3d658d7 100644
49233 --- a/drivers/scsi/qla2xxx/qla_attr.c
49234 +++ b/drivers/scsi/qla2xxx/qla_attr.c
49235 @@ -2038,7 +2038,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49236 return 0;
49237 }
49238
49239 -struct fc_function_template qla2xxx_transport_functions = {
49240 +fc_function_template_no_const qla2xxx_transport_functions = {
49241
49242 .show_host_node_name = 1,
49243 .show_host_port_name = 1,
49244 @@ -2086,7 +2086,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49245 .bsg_timeout = qla24xx_bsg_timeout,
49246 };
49247
49248 -struct fc_function_template qla2xxx_transport_vport_functions = {
49249 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
49250
49251 .show_host_node_name = 1,
49252 .show_host_port_name = 1,
49253 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49254 index 1f42662..bf9836c 100644
49255 --- a/drivers/scsi/qla2xxx/qla_gbl.h
49256 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
49257 @@ -546,8 +546,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49258 struct device_attribute;
49259 extern struct device_attribute *qla2x00_host_attrs[];
49260 struct fc_function_template;
49261 -extern struct fc_function_template qla2xxx_transport_functions;
49262 -extern struct fc_function_template qla2xxx_transport_vport_functions;
49263 +extern fc_function_template_no_const qla2xxx_transport_functions;
49264 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49265 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49266 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49267 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49268 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49269 index 89a5300..2a459ab 100644
49270 --- a/drivers/scsi/qla2xxx/qla_os.c
49271 +++ b/drivers/scsi/qla2xxx/qla_os.c
49272 @@ -1491,8 +1491,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49273 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49274 /* Ok, a 64bit DMA mask is applicable. */
49275 ha->flags.enable_64bit_addressing = 1;
49276 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49277 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49278 + pax_open_kernel();
49279 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49280 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49281 + pax_close_kernel();
49282 return;
49283 }
49284 }
49285 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49286 index aa67bb9..06d0e2a 100644
49287 --- a/drivers/scsi/qla4xxx/ql4_def.h
49288 +++ b/drivers/scsi/qla4xxx/ql4_def.h
49289 @@ -303,7 +303,7 @@ struct ddb_entry {
49290 * (4000 only) */
49291 atomic_t relogin_timer; /* Max Time to wait for
49292 * relogin to complete */
49293 - atomic_t relogin_retry_count; /* Num of times relogin has been
49294 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49295 * retried */
49296 uint32_t default_time2wait; /* Default Min time between
49297 * relogins (+aens) */
49298 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49299 index c21adc3..1b4155f 100644
49300 --- a/drivers/scsi/qla4xxx/ql4_os.c
49301 +++ b/drivers/scsi/qla4xxx/ql4_os.c
49302 @@ -4463,12 +4463,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49303 */
49304 if (!iscsi_is_session_online(cls_sess)) {
49305 /* Reset retry relogin timer */
49306 - atomic_inc(&ddb_entry->relogin_retry_count);
49307 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49308 DEBUG2(ql4_printk(KERN_INFO, ha,
49309 "%s: index[%d] relogin timed out-retrying"
49310 " relogin (%d), retry (%d)\n", __func__,
49311 ddb_entry->fw_ddb_index,
49312 - atomic_read(&ddb_entry->relogin_retry_count),
49313 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49314 ddb_entry->default_time2wait + 4));
49315 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49316 atomic_set(&ddb_entry->retry_relogin_timer,
49317 @@ -6552,7 +6552,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49318
49319 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49320 atomic_set(&ddb_entry->relogin_timer, 0);
49321 - atomic_set(&ddb_entry->relogin_retry_count, 0);
49322 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49323 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49324 ddb_entry->default_relogin_timeout =
49325 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49326 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49327 index d8afec8..3ec7152 100644
49328 --- a/drivers/scsi/scsi.c
49329 +++ b/drivers/scsi/scsi.c
49330 @@ -658,7 +658,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49331 struct Scsi_Host *host = cmd->device->host;
49332 int rtn = 0;
49333
49334 - atomic_inc(&cmd->device->iorequest_cnt);
49335 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49336
49337 /* check if the device is still usable */
49338 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49339 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49340 index 62ec84b..93159d8 100644
49341 --- a/drivers/scsi/scsi_lib.c
49342 +++ b/drivers/scsi/scsi_lib.c
49343 @@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49344 shost = sdev->host;
49345 scsi_init_cmd_errh(cmd);
49346 cmd->result = DID_NO_CONNECT << 16;
49347 - atomic_inc(&cmd->device->iorequest_cnt);
49348 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49349
49350 /*
49351 * SCSI request completion path will do scsi_device_unbusy(),
49352 @@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
49353
49354 INIT_LIST_HEAD(&cmd->eh_entry);
49355
49356 - atomic_inc(&cmd->device->iodone_cnt);
49357 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
49358 if (cmd->result)
49359 - atomic_inc(&cmd->device->ioerr_cnt);
49360 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49361
49362 disposition = scsi_decide_disposition(cmd);
49363 if (disposition != SUCCESS &&
49364 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49365 index 9117d0b..d289a7a 100644
49366 --- a/drivers/scsi/scsi_sysfs.c
49367 +++ b/drivers/scsi/scsi_sysfs.c
49368 @@ -739,7 +739,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49369 char *buf) \
49370 { \
49371 struct scsi_device *sdev = to_scsi_device(dev); \
49372 - unsigned long long count = atomic_read(&sdev->field); \
49373 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
49374 return snprintf(buf, 20, "0x%llx\n", count); \
49375 } \
49376 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49377 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49378 index 84a1fdf..693b0d6 100644
49379 --- a/drivers/scsi/scsi_tgt_lib.c
49380 +++ b/drivers/scsi/scsi_tgt_lib.c
49381 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49382 int err;
49383
49384 dprintk("%lx %u\n", uaddr, len);
49385 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49386 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49387 if (err) {
49388 /*
49389 * TODO: need to fixup sg_tablesize, max_segment_size,
49390 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49391 index 4628fd5..a94a1c2 100644
49392 --- a/drivers/scsi/scsi_transport_fc.c
49393 +++ b/drivers/scsi/scsi_transport_fc.c
49394 @@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49395 * Netlink Infrastructure
49396 */
49397
49398 -static atomic_t fc_event_seq;
49399 +static atomic_unchecked_t fc_event_seq;
49400
49401 /**
49402 * fc_get_event_number - Obtain the next sequential FC event number
49403 @@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
49404 u32
49405 fc_get_event_number(void)
49406 {
49407 - return atomic_add_return(1, &fc_event_seq);
49408 + return atomic_add_return_unchecked(1, &fc_event_seq);
49409 }
49410 EXPORT_SYMBOL(fc_get_event_number);
49411
49412 @@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
49413 {
49414 int error;
49415
49416 - atomic_set(&fc_event_seq, 0);
49417 + atomic_set_unchecked(&fc_event_seq, 0);
49418
49419 error = transport_class_register(&fc_host_class);
49420 if (error)
49421 @@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49422 char *cp;
49423
49424 *val = simple_strtoul(buf, &cp, 0);
49425 - if ((*cp && (*cp != '\n')) || (*val < 0))
49426 + if (*cp && (*cp != '\n'))
49427 return -EINVAL;
49428 /*
49429 * Check for overflow; dev_loss_tmo is u32
49430 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49431 index fd8ffe6..fd0bebf 100644
49432 --- a/drivers/scsi/scsi_transport_iscsi.c
49433 +++ b/drivers/scsi/scsi_transport_iscsi.c
49434 @@ -79,7 +79,7 @@ struct iscsi_internal {
49435 struct transport_container session_cont;
49436 };
49437
49438 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49439 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49440 static struct workqueue_struct *iscsi_eh_timer_workq;
49441
49442 static DEFINE_IDA(iscsi_sess_ida);
49443 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49444 int err;
49445
49446 ihost = shost->shost_data;
49447 - session->sid = atomic_add_return(1, &iscsi_session_nr);
49448 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49449
49450 if (target_id == ISCSI_MAX_TARGET) {
49451 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49452 @@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
49453 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49454 ISCSI_TRANSPORT_VERSION);
49455
49456 - atomic_set(&iscsi_session_nr, 0);
49457 + atomic_set_unchecked(&iscsi_session_nr, 0);
49458
49459 err = class_register(&iscsi_transport_class);
49460 if (err)
49461 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49462 index d47ffc8..30f46a9 100644
49463 --- a/drivers/scsi/scsi_transport_srp.c
49464 +++ b/drivers/scsi/scsi_transport_srp.c
49465 @@ -36,7 +36,7 @@
49466 #include "scsi_transport_srp_internal.h"
49467
49468 struct srp_host_attrs {
49469 - atomic_t next_port_id;
49470 + atomic_unchecked_t next_port_id;
49471 };
49472 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49473
49474 @@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49475 struct Scsi_Host *shost = dev_to_shost(dev);
49476 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49477
49478 - atomic_set(&srp_host->next_port_id, 0);
49479 + atomic_set_unchecked(&srp_host->next_port_id, 0);
49480 return 0;
49481 }
49482
49483 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49484 rport_fast_io_fail_timedout);
49485 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49486
49487 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49488 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49489 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49490
49491 transport_setup_device(&rport->dev);
49492 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49493 index 470954a..eca8d22 100644
49494 --- a/drivers/scsi/sd.c
49495 +++ b/drivers/scsi/sd.c
49496 @@ -2962,7 +2962,7 @@ static int sd_probe(struct device *dev)
49497 sdkp->disk = gd;
49498 sdkp->index = index;
49499 atomic_set(&sdkp->openers, 0);
49500 - atomic_set(&sdkp->device->ioerr_cnt, 0);
49501 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49502
49503 if (!sdp->request_queue->rq_timeout) {
49504 if (sdp->type != TYPE_MOD)
49505 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49506 index df5e961..df6b97f 100644
49507 --- a/drivers/scsi/sg.c
49508 +++ b/drivers/scsi/sg.c
49509 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49510 sdp->disk->disk_name,
49511 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49512 NULL,
49513 - (char *)arg);
49514 + (char __user *)arg);
49515 case BLKTRACESTART:
49516 return blk_trace_startstop(sdp->device->request_queue, 1);
49517 case BLKTRACESTOP:
49518 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49519 index d0b28bb..a263613 100644
49520 --- a/drivers/spi/spi.c
49521 +++ b/drivers/spi/spi.c
49522 @@ -1971,7 +1971,7 @@ int spi_bus_unlock(struct spi_master *master)
49523 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49524
49525 /* portable code must never pass more than 32 bytes */
49526 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49527 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49528
49529 static u8 *buf;
49530
49531 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49532 index 2c61783..4d49e4e 100644
49533 --- a/drivers/staging/android/timed_output.c
49534 +++ b/drivers/staging/android/timed_output.c
49535 @@ -25,7 +25,7 @@
49536 #include "timed_output.h"
49537
49538 static struct class *timed_output_class;
49539 -static atomic_t device_count;
49540 +static atomic_unchecked_t device_count;
49541
49542 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49543 char *buf)
49544 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49545 timed_output_class = class_create(THIS_MODULE, "timed_output");
49546 if (IS_ERR(timed_output_class))
49547 return PTR_ERR(timed_output_class);
49548 - atomic_set(&device_count, 0);
49549 + atomic_set_unchecked(&device_count, 0);
49550 timed_output_class->dev_groups = timed_output_groups;
49551 }
49552
49553 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49554 if (ret < 0)
49555 return ret;
49556
49557 - tdev->index = atomic_inc_return(&device_count);
49558 + tdev->index = atomic_inc_return_unchecked(&device_count);
49559 tdev->dev = device_create(timed_output_class, NULL,
49560 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49561 if (IS_ERR(tdev->dev))
49562 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49563 index fe47cd3..19a1bd1 100644
49564 --- a/drivers/staging/gdm724x/gdm_tty.c
49565 +++ b/drivers/staging/gdm724x/gdm_tty.c
49566 @@ -44,7 +44,7 @@
49567 #define gdm_tty_send_control(n, r, v, d, l) (\
49568 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49569
49570 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49571 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49572
49573 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49574 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49575 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49576 index 236ed66..dd9cd74 100644
49577 --- a/drivers/staging/imx-drm/imx-drm-core.c
49578 +++ b/drivers/staging/imx-drm/imx-drm-core.c
49579 @@ -488,7 +488,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
49580 goto err_busy;
49581 }
49582
49583 - if (imxdrm->drm->open_count) {
49584 + if (local_read(&imxdrm->drm->open_count)) {
49585 ret = -EBUSY;
49586 goto err_busy;
49587 }
49588 @@ -576,7 +576,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
49589
49590 mutex_lock(&imxdrm->mutex);
49591
49592 - if (imxdrm->drm->open_count) {
49593 + if (local_read(&imxdrm->drm->open_count)) {
49594 ret = -EBUSY;
49595 goto err_busy;
49596 }
49597 @@ -715,7 +715,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
49598
49599 mutex_lock(&imxdrm->mutex);
49600
49601 - if (imxdrm->drm->open_count) {
49602 + if (local_read(&imxdrm->drm->open_count)) {
49603 ret = -EBUSY;
49604 goto err_busy;
49605 }
49606 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49607 index 3f8020c..649fded 100644
49608 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49609 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49610 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49611 return 0;
49612 }
49613
49614 -sfw_test_client_ops_t brw_test_client;
49615 -void brw_init_test_client(void)
49616 -{
49617 - brw_test_client.tso_init = brw_client_init;
49618 - brw_test_client.tso_fini = brw_client_fini;
49619 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49620 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
49621 +sfw_test_client_ops_t brw_test_client = {
49622 + .tso_init = brw_client_init,
49623 + .tso_fini = brw_client_fini,
49624 + .tso_prep_rpc = brw_client_prep_rpc,
49625 + .tso_done_rpc = brw_client_done_rpc,
49626 };
49627
49628 srpc_service_t brw_test_service;
49629 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49630 index 050723a..fa6fdf1 100644
49631 --- a/drivers/staging/lustre/lnet/selftest/framework.c
49632 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
49633 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49634
49635 extern sfw_test_client_ops_t ping_test_client;
49636 extern srpc_service_t ping_test_service;
49637 -extern void ping_init_test_client(void);
49638 extern void ping_init_test_service(void);
49639
49640 extern sfw_test_client_ops_t brw_test_client;
49641 extern srpc_service_t brw_test_service;
49642 -extern void brw_init_test_client(void);
49643 extern void brw_init_test_service(void);
49644
49645
49646 @@ -1684,12 +1682,10 @@ sfw_startup (void)
49647 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49648 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49649
49650 - brw_init_test_client();
49651 brw_init_test_service();
49652 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49653 LASSERT (rc == 0);
49654
49655 - ping_init_test_client();
49656 ping_init_test_service();
49657 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49658 LASSERT (rc == 0);
49659 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49660 index 750cac4..e4d751f 100644
49661 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49662 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49663 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49664 return 0;
49665 }
49666
49667 -sfw_test_client_ops_t ping_test_client;
49668 -void ping_init_test_client(void)
49669 -{
49670 - ping_test_client.tso_init = ping_client_init;
49671 - ping_test_client.tso_fini = ping_client_fini;
49672 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49673 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
49674 -}
49675 +sfw_test_client_ops_t ping_test_client = {
49676 + .tso_init = ping_client_init,
49677 + .tso_fini = ping_client_fini,
49678 + .tso_prep_rpc = ping_client_prep_rpc,
49679 + .tso_done_rpc = ping_client_done_rpc,
49680 +};
49681
49682 srpc_service_t ping_test_service;
49683 void ping_init_test_service(void)
49684 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49685 index ec4bb5e..740c6dd 100644
49686 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49687 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49688 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49689 ldlm_completion_callback lcs_completion;
49690 ldlm_blocking_callback lcs_blocking;
49691 ldlm_glimpse_callback lcs_glimpse;
49692 -};
49693 +} __no_const;
49694
49695 /* ldlm_lockd.c */
49696 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49697 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49698 index c3470ce..2bef527 100644
49699 --- a/drivers/staging/lustre/lustre/include/obd.h
49700 +++ b/drivers/staging/lustre/lustre/include/obd.h
49701 @@ -1426,7 +1426,7 @@ struct md_ops {
49702 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49703 * wrapper function in include/linux/obd_class.h.
49704 */
49705 -};
49706 +} __no_const;
49707
49708 struct lsm_operations {
49709 void (*lsm_free)(struct lov_stripe_md *);
49710 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49711 index c9aae13..60ea292 100644
49712 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49713 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49714 @@ -239,7 +239,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49715 int added = (mode == LCK_NL);
49716 int overlaps = 0;
49717 int splitted = 0;
49718 - const struct ldlm_callback_suite null_cbs = { NULL };
49719 + const struct ldlm_callback_suite null_cbs = { };
49720
49721 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49722 LPU64" end "LPU64"\n", *flags,
49723 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49724 index e947b91..f408990 100644
49725 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49726 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49727 @@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49728 int LL_PROC_PROTO(proc_console_max_delay_cs)
49729 {
49730 int rc, max_delay_cs;
49731 - ctl_table_t dummy = *table;
49732 + ctl_table_no_const dummy = *table;
49733 cfs_duration_t d;
49734
49735 dummy.data = &max_delay_cs;
49736 @@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49737 int LL_PROC_PROTO(proc_console_min_delay_cs)
49738 {
49739 int rc, min_delay_cs;
49740 - ctl_table_t dummy = *table;
49741 + ctl_table_no_const dummy = *table;
49742 cfs_duration_t d;
49743
49744 dummy.data = &min_delay_cs;
49745 @@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49746 int LL_PROC_PROTO(proc_console_backoff)
49747 {
49748 int rc, backoff;
49749 - ctl_table_t dummy = *table;
49750 + ctl_table_no_const dummy = *table;
49751
49752 dummy.data = &backoff;
49753 dummy.proc_handler = &proc_dointvec;
49754 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49755 index 24ae26d..9d09cab 100644
49756 --- a/drivers/staging/lustre/lustre/libcfs/module.c
49757 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
49758 @@ -313,11 +313,11 @@ out:
49759
49760
49761 struct cfs_psdev_ops libcfs_psdev_ops = {
49762 - libcfs_psdev_open,
49763 - libcfs_psdev_release,
49764 - NULL,
49765 - NULL,
49766 - libcfs_ioctl
49767 + .p_open = libcfs_psdev_open,
49768 + .p_close = libcfs_psdev_release,
49769 + .p_read = NULL,
49770 + .p_write = NULL,
49771 + .p_ioctl = libcfs_ioctl
49772 };
49773
49774 extern int insert_proc(void);
49775 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
49776 index 52b7731..d604da0 100644
49777 --- a/drivers/staging/lustre/lustre/llite/dir.c
49778 +++ b/drivers/staging/lustre/lustre/llite/dir.c
49779 @@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
49780 int mode;
49781 int err;
49782
49783 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
49784 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
49785 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
49786 strlen(filename), mode, LUSTRE_OPC_MKDIR,
49787 lump);
49788 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49789 index 480b7c4..6846324 100644
49790 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
49791 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49792 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49793
49794 static int solo_sysfs_init(struct solo_dev *solo_dev)
49795 {
49796 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49797 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49798 struct device *dev = &solo_dev->dev;
49799 const char *driver;
49800 int i;
49801 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49802 index 1db18c7..35e6afc 100644
49803 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49804 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49805 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49806
49807 int solo_g723_init(struct solo_dev *solo_dev)
49808 {
49809 - static struct snd_device_ops ops = { NULL };
49810 + static struct snd_device_ops ops = { };
49811 struct snd_card *card;
49812 struct snd_kcontrol_new kctl;
49813 char name[32];
49814 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49815 index 7f2f247..d999137 100644
49816 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49817 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49818 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49819
49820 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49821 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49822 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49823 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49824 if (p2m_id < 0)
49825 p2m_id = -p2m_id;
49826 }
49827 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49828 index 8964f8b..36eb087 100644
49829 --- a/drivers/staging/media/solo6x10/solo6x10.h
49830 +++ b/drivers/staging/media/solo6x10/solo6x10.h
49831 @@ -237,7 +237,7 @@ struct solo_dev {
49832
49833 /* P2M DMA Engine */
49834 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49835 - atomic_t p2m_count;
49836 + atomic_unchecked_t p2m_count;
49837 int p2m_jiffies;
49838 unsigned int p2m_timeouts;
49839
49840 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
49841 index a0f4868..139f1fb 100644
49842 --- a/drivers/staging/octeon/ethernet-rx.c
49843 +++ b/drivers/staging/octeon/ethernet-rx.c
49844 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49845 /* Increment RX stats for virtual ports */
49846 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
49847 #ifdef CONFIG_64BIT
49848 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
49849 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
49850 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
49851 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
49852 #else
49853 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
49854 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
49855 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
49856 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
49857 #endif
49858 }
49859 netif_receive_skb(skb);
49860 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49861 dev->name);
49862 */
49863 #ifdef CONFIG_64BIT
49864 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
49865 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49866 #else
49867 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
49868 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
49869 #endif
49870 dev_kfree_skb_irq(skb);
49871 }
49872 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
49873 index 089dc4b..c9a687e 100644
49874 --- a/drivers/staging/octeon/ethernet.c
49875 +++ b/drivers/staging/octeon/ethernet.c
49876 @@ -253,11 +253,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
49877 * since the RX tasklet also increments it.
49878 */
49879 #ifdef CONFIG_64BIT
49880 - atomic64_add(rx_status.dropped_packets,
49881 - (atomic64_t *)&priv->stats.rx_dropped);
49882 + atomic64_add_unchecked(rx_status.dropped_packets,
49883 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49884 #else
49885 - atomic_add(rx_status.dropped_packets,
49886 - (atomic_t *)&priv->stats.rx_dropped);
49887 + atomic_add_unchecked(rx_status.dropped_packets,
49888 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
49889 #endif
49890 }
49891
49892 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
49893 index c274b34..f84de76 100644
49894 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
49895 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
49896 @@ -271,7 +271,7 @@ struct hal_ops {
49897 s32 (*c2h_handler)(struct adapter *padapter,
49898 struct c2h_evt_hdr *c2h_evt);
49899 c2h_id_filter c2h_id_filter_ccx;
49900 -};
49901 +} __no_const;
49902
49903 enum rt_eeprom_type {
49904 EEPROM_93C46,
49905 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
49906 index 3d1dfcc..ff5620a 100644
49907 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
49908 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
49909 @@ -126,7 +126,7 @@ struct _io_ops {
49910 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
49911 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
49912 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
49913 -};
49914 +} __no_const;
49915
49916 struct io_req {
49917 struct list_head list;
49918 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
49919 index dc23395..cf7e9b1 100644
49920 --- a/drivers/staging/rtl8712/rtl871x_io.h
49921 +++ b/drivers/staging/rtl8712/rtl871x_io.h
49922 @@ -108,7 +108,7 @@ struct _io_ops {
49923 u8 *pmem);
49924 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
49925 u8 *pmem);
49926 -};
49927 +} __no_const;
49928
49929 struct io_req {
49930 struct list_head list;
49931 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
49932 index 1f5088b..0e59820 100644
49933 --- a/drivers/staging/sbe-2t3e3/netdev.c
49934 +++ b/drivers/staging/sbe-2t3e3/netdev.c
49935 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49936 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
49937
49938 if (rlen)
49939 - if (copy_to_user(data, &resp, rlen))
49940 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
49941 return -EFAULT;
49942
49943 return 0;
49944 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
49945 index a863a98..d272795 100644
49946 --- a/drivers/staging/usbip/vhci.h
49947 +++ b/drivers/staging/usbip/vhci.h
49948 @@ -83,7 +83,7 @@ struct vhci_hcd {
49949 unsigned resuming:1;
49950 unsigned long re_timeout;
49951
49952 - atomic_t seqnum;
49953 + atomic_unchecked_t seqnum;
49954
49955 /*
49956 * NOTE:
49957 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
49958 index 72391ef..7c6717a 100644
49959 --- a/drivers/staging/usbip/vhci_hcd.c
49960 +++ b/drivers/staging/usbip/vhci_hcd.c
49961 @@ -440,7 +440,7 @@ static void vhci_tx_urb(struct urb *urb)
49962
49963 spin_lock(&vdev->priv_lock);
49964
49965 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
49966 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49967 if (priv->seqnum == 0xffff)
49968 dev_info(&urb->dev->dev, "seqnum max\n");
49969
49970 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
49971 return -ENOMEM;
49972 }
49973
49974 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
49975 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49976 if (unlink->seqnum == 0xffff)
49977 pr_info("seqnum max\n");
49978
49979 @@ -890,7 +890,7 @@ static int vhci_start(struct usb_hcd *hcd)
49980 vdev->rhport = rhport;
49981 }
49982
49983 - atomic_set(&vhci->seqnum, 0);
49984 + atomic_set_unchecked(&vhci->seqnum, 0);
49985 spin_lock_init(&vhci->lock);
49986
49987 hcd->power_budget = 0; /* no limit */
49988 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
49989 index d07fcb5..358e1e1 100644
49990 --- a/drivers/staging/usbip/vhci_rx.c
49991 +++ b/drivers/staging/usbip/vhci_rx.c
49992 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
49993 if (!urb) {
49994 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
49995 pr_info("max seqnum %d\n",
49996 - atomic_read(&the_controller->seqnum));
49997 + atomic_read_unchecked(&the_controller->seqnum));
49998 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
49999 return;
50000 }
50001 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50002 index 6eecd53..29317c6 100644
50003 --- a/drivers/staging/vt6655/hostap.c
50004 +++ b/drivers/staging/vt6655/hostap.c
50005 @@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50006 *
50007 */
50008
50009 +static net_device_ops_no_const apdev_netdev_ops;
50010 +
50011 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50012 {
50013 PSDevice apdev_priv;
50014 struct net_device *dev = pDevice->dev;
50015 int ret;
50016 - const struct net_device_ops apdev_netdev_ops = {
50017 - .ndo_start_xmit = pDevice->tx_80211,
50018 - };
50019
50020 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50021
50022 @@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50023 *apdev_priv = *pDevice;
50024 eth_hw_addr_inherit(pDevice->apdev, dev);
50025
50026 + /* only half broken now */
50027 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50028 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50029
50030 pDevice->apdev->type = ARPHRD_IEEE80211;
50031 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50032 index 67ba48b..24e602f 100644
50033 --- a/drivers/staging/vt6656/hostap.c
50034 +++ b/drivers/staging/vt6656/hostap.c
50035 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50036 *
50037 */
50038
50039 +static net_device_ops_no_const apdev_netdev_ops;
50040 +
50041 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50042 {
50043 struct vnt_private *apdev_priv;
50044 struct net_device *dev = pDevice->dev;
50045 int ret;
50046 - const struct net_device_ops apdev_netdev_ops = {
50047 - .ndo_start_xmit = pDevice->tx_80211,
50048 - };
50049
50050 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50051
50052 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50053 *apdev_priv = *pDevice;
50054 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50055
50056 + /* only half broken now */
50057 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50058 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50059
50060 pDevice->apdev->type = ARPHRD_IEEE80211;
50061 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50062 index 24884ca..26c8220 100644
50063 --- a/drivers/target/sbp/sbp_target.c
50064 +++ b/drivers/target/sbp/sbp_target.c
50065 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50066
50067 #define SESSION_MAINTENANCE_INTERVAL HZ
50068
50069 -static atomic_t login_id = ATOMIC_INIT(0);
50070 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50071
50072 static void session_maintenance_work(struct work_struct *);
50073 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50074 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
50075 login->lun = se_lun;
50076 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50077 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50078 - login->login_id = atomic_inc_return(&login_id);
50079 + login->login_id = atomic_inc_return_unchecked(&login_id);
50080
50081 login->tgt_agt = sbp_target_agent_register(login);
50082 if (IS_ERR(login->tgt_agt)) {
50083 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50084 index 65001e1..2ebfbb9 100644
50085 --- a/drivers/target/target_core_device.c
50086 +++ b/drivers/target/target_core_device.c
50087 @@ -1520,7 +1520,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50088 spin_lock_init(&dev->se_tmr_lock);
50089 spin_lock_init(&dev->qf_cmd_lock);
50090 sema_init(&dev->caw_sem, 1);
50091 - atomic_set(&dev->dev_ordered_id, 0);
50092 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
50093 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50094 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50095 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50096 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50097 index 2956250..b10f722 100644
50098 --- a/drivers/target/target_core_transport.c
50099 +++ b/drivers/target/target_core_transport.c
50100 @@ -1136,7 +1136,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50101 * Used to determine when ORDERED commands should go from
50102 * Dormant to Active status.
50103 */
50104 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50105 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50106 smp_mb__after_atomic_inc();
50107 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50108 cmd->se_ordered_id, cmd->sam_task_attr,
50109 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50110 index a57bb5a..1f727d33 100644
50111 --- a/drivers/tty/cyclades.c
50112 +++ b/drivers/tty/cyclades.c
50113 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50114 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50115 info->port.count);
50116 #endif
50117 - info->port.count++;
50118 + atomic_inc(&info->port.count);
50119 #ifdef CY_DEBUG_COUNT
50120 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50121 - current->pid, info->port.count);
50122 + current->pid, atomic_read(&info->port.count));
50123 #endif
50124
50125 /*
50126 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50127 for (j = 0; j < cy_card[i].nports; j++) {
50128 info = &cy_card[i].ports[j];
50129
50130 - if (info->port.count) {
50131 + if (atomic_read(&info->port.count)) {
50132 /* XXX is the ldisc num worth this? */
50133 struct tty_struct *tty;
50134 struct tty_ldisc *ld;
50135 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50136 index 50b4688..e1e8125 100644
50137 --- a/drivers/tty/hvc/hvc_console.c
50138 +++ b/drivers/tty/hvc/hvc_console.c
50139 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50140
50141 spin_lock_irqsave(&hp->port.lock, flags);
50142 /* Check and then increment for fast path open. */
50143 - if (hp->port.count++ > 0) {
50144 + if (atomic_inc_return(&hp->port.count) > 1) {
50145 spin_unlock_irqrestore(&hp->port.lock, flags);
50146 hvc_kick();
50147 return 0;
50148 @@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50149
50150 spin_lock_irqsave(&hp->port.lock, flags);
50151
50152 - if (--hp->port.count == 0) {
50153 + if (atomic_dec_return(&hp->port.count) == 0) {
50154 spin_unlock_irqrestore(&hp->port.lock, flags);
50155 /* We are done with the tty pointer now. */
50156 tty_port_tty_set(&hp->port, NULL);
50157 @@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50158 */
50159 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50160 } else {
50161 - if (hp->port.count < 0)
50162 + if (atomic_read(&hp->port.count) < 0)
50163 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50164 - hp->vtermno, hp->port.count);
50165 + hp->vtermno, atomic_read(&hp->port.count));
50166 spin_unlock_irqrestore(&hp->port.lock, flags);
50167 }
50168 }
50169 @@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
50170 * open->hangup case this can be called after the final close so prevent
50171 * that from happening for now.
50172 */
50173 - if (hp->port.count <= 0) {
50174 + if (atomic_read(&hp->port.count) <= 0) {
50175 spin_unlock_irqrestore(&hp->port.lock, flags);
50176 return;
50177 }
50178
50179 - hp->port.count = 0;
50180 + atomic_set(&hp->port.count, 0);
50181 spin_unlock_irqrestore(&hp->port.lock, flags);
50182 tty_port_tty_set(&hp->port, NULL);
50183
50184 @@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50185 return -EPIPE;
50186
50187 /* FIXME what's this (unprotected) check for? */
50188 - if (hp->port.count <= 0)
50189 + if (atomic_read(&hp->port.count) <= 0)
50190 return -EIO;
50191
50192 spin_lock_irqsave(&hp->lock, flags);
50193 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50194 index 81e939e..95ead10 100644
50195 --- a/drivers/tty/hvc/hvcs.c
50196 +++ b/drivers/tty/hvc/hvcs.c
50197 @@ -83,6 +83,7 @@
50198 #include <asm/hvcserver.h>
50199 #include <asm/uaccess.h>
50200 #include <asm/vio.h>
50201 +#include <asm/local.h>
50202
50203 /*
50204 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50205 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50206
50207 spin_lock_irqsave(&hvcsd->lock, flags);
50208
50209 - if (hvcsd->port.count > 0) {
50210 + if (atomic_read(&hvcsd->port.count) > 0) {
50211 spin_unlock_irqrestore(&hvcsd->lock, flags);
50212 printk(KERN_INFO "HVCS: vterm state unchanged. "
50213 "The hvcs device node is still in use.\n");
50214 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50215 }
50216 }
50217
50218 - hvcsd->port.count = 0;
50219 + atomic_set(&hvcsd->port.count, 0);
50220 hvcsd->port.tty = tty;
50221 tty->driver_data = hvcsd;
50222
50223 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50224 unsigned long flags;
50225
50226 spin_lock_irqsave(&hvcsd->lock, flags);
50227 - hvcsd->port.count++;
50228 + atomic_inc(&hvcsd->port.count);
50229 hvcsd->todo_mask |= HVCS_SCHED_READ;
50230 spin_unlock_irqrestore(&hvcsd->lock, flags);
50231
50232 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50233 hvcsd = tty->driver_data;
50234
50235 spin_lock_irqsave(&hvcsd->lock, flags);
50236 - if (--hvcsd->port.count == 0) {
50237 + if (atomic_dec_and_test(&hvcsd->port.count)) {
50238
50239 vio_disable_interrupts(hvcsd->vdev);
50240
50241 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50242
50243 free_irq(irq, hvcsd);
50244 return;
50245 - } else if (hvcsd->port.count < 0) {
50246 + } else if (atomic_read(&hvcsd->port.count) < 0) {
50247 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50248 " is missmanaged.\n",
50249 - hvcsd->vdev->unit_address, hvcsd->port.count);
50250 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50251 }
50252
50253 spin_unlock_irqrestore(&hvcsd->lock, flags);
50254 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50255
50256 spin_lock_irqsave(&hvcsd->lock, flags);
50257 /* Preserve this so that we know how many kref refs to put */
50258 - temp_open_count = hvcsd->port.count;
50259 + temp_open_count = atomic_read(&hvcsd->port.count);
50260
50261 /*
50262 * Don't kref put inside the spinlock because the destruction
50263 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50264 tty->driver_data = NULL;
50265 hvcsd->port.tty = NULL;
50266
50267 - hvcsd->port.count = 0;
50268 + atomic_set(&hvcsd->port.count, 0);
50269
50270 /* This will drop any buffered data on the floor which is OK in a hangup
50271 * scenario. */
50272 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50273 * the middle of a write operation? This is a crummy place to do this
50274 * but we want to keep it all in the spinlock.
50275 */
50276 - if (hvcsd->port.count <= 0) {
50277 + if (atomic_read(&hvcsd->port.count) <= 0) {
50278 spin_unlock_irqrestore(&hvcsd->lock, flags);
50279 return -ENODEV;
50280 }
50281 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50282 {
50283 struct hvcs_struct *hvcsd = tty->driver_data;
50284
50285 - if (!hvcsd || hvcsd->port.count <= 0)
50286 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50287 return 0;
50288
50289 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50290 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50291 index 4190199..06d5bfa 100644
50292 --- a/drivers/tty/hvc/hvsi.c
50293 +++ b/drivers/tty/hvc/hvsi.c
50294 @@ -85,7 +85,7 @@ struct hvsi_struct {
50295 int n_outbuf;
50296 uint32_t vtermno;
50297 uint32_t virq;
50298 - atomic_t seqno; /* HVSI packet sequence number */
50299 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
50300 uint16_t mctrl;
50301 uint8_t state; /* HVSI protocol state */
50302 uint8_t flags;
50303 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50304
50305 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50306 packet.hdr.len = sizeof(struct hvsi_query_response);
50307 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50308 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50309 packet.verb = VSV_SEND_VERSION_NUMBER;
50310 packet.u.version = HVSI_VERSION;
50311 packet.query_seqno = query_seqno+1;
50312 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50313
50314 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50315 packet.hdr.len = sizeof(struct hvsi_query);
50316 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50317 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50318 packet.verb = verb;
50319
50320 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50321 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50322 int wrote;
50323
50324 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50325 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50326 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50327 packet.hdr.len = sizeof(struct hvsi_control);
50328 packet.verb = VSV_SET_MODEM_CTL;
50329 packet.mask = HVSI_TSDTR;
50330 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50331 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50332
50333 packet.hdr.type = VS_DATA_PACKET_HEADER;
50334 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50335 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50336 packet.hdr.len = count + sizeof(struct hvsi_header);
50337 memcpy(&packet.data, buf, count);
50338
50339 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50340 struct hvsi_control packet __ALIGNED__;
50341
50342 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50343 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50344 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50345 packet.hdr.len = 6;
50346 packet.verb = VSV_CLOSE_PROTOCOL;
50347
50348 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50349
50350 tty_port_tty_set(&hp->port, tty);
50351 spin_lock_irqsave(&hp->lock, flags);
50352 - hp->port.count++;
50353 + atomic_inc(&hp->port.count);
50354 atomic_set(&hp->seqno, 0);
50355 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50356 spin_unlock_irqrestore(&hp->lock, flags);
50357 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50358
50359 spin_lock_irqsave(&hp->lock, flags);
50360
50361 - if (--hp->port.count == 0) {
50362 + if (atomic_dec_return(&hp->port.count) == 0) {
50363 tty_port_tty_set(&hp->port, NULL);
50364 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50365
50366 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50367
50368 spin_lock_irqsave(&hp->lock, flags);
50369 }
50370 - } else if (hp->port.count < 0)
50371 + } else if (atomic_read(&hp->port.count) < 0)
50372 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50373 - hp - hvsi_ports, hp->port.count);
50374 + hp - hvsi_ports, atomic_read(&hp->port.count));
50375
50376 spin_unlock_irqrestore(&hp->lock, flags);
50377 }
50378 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50379 tty_port_tty_set(&hp->port, NULL);
50380
50381 spin_lock_irqsave(&hp->lock, flags);
50382 - hp->port.count = 0;
50383 + atomic_set(&hp->port.count, 0);
50384 hp->n_outbuf = 0;
50385 spin_unlock_irqrestore(&hp->lock, flags);
50386 }
50387 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50388 index 7ae6c29..05c6dba 100644
50389 --- a/drivers/tty/hvc/hvsi_lib.c
50390 +++ b/drivers/tty/hvc/hvsi_lib.c
50391 @@ -8,7 +8,7 @@
50392
50393 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50394 {
50395 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50396 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50397
50398 /* Assumes that always succeeds, works in practice */
50399 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50400 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50401
50402 /* Reset state */
50403 pv->established = 0;
50404 - atomic_set(&pv->seqno, 0);
50405 + atomic_set_unchecked(&pv->seqno, 0);
50406
50407 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50408
50409 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50410 index ebd5bff..b1acad3 100644
50411 --- a/drivers/tty/ipwireless/tty.c
50412 +++ b/drivers/tty/ipwireless/tty.c
50413 @@ -28,6 +28,7 @@
50414 #include <linux/tty_driver.h>
50415 #include <linux/tty_flip.h>
50416 #include <linux/uaccess.h>
50417 +#include <asm/local.h>
50418
50419 #include "tty.h"
50420 #include "network.h"
50421 @@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50422 mutex_unlock(&tty->ipw_tty_mutex);
50423 return -ENODEV;
50424 }
50425 - if (tty->port.count == 0)
50426 + if (atomic_read(&tty->port.count) == 0)
50427 tty->tx_bytes_queued = 0;
50428
50429 - tty->port.count++;
50430 + atomic_inc(&tty->port.count);
50431
50432 tty->port.tty = linux_tty;
50433 linux_tty->driver_data = tty;
50434 @@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50435
50436 static void do_ipw_close(struct ipw_tty *tty)
50437 {
50438 - tty->port.count--;
50439 -
50440 - if (tty->port.count == 0) {
50441 + if (atomic_dec_return(&tty->port.count) == 0) {
50442 struct tty_struct *linux_tty = tty->port.tty;
50443
50444 if (linux_tty != NULL) {
50445 @@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50446 return;
50447
50448 mutex_lock(&tty->ipw_tty_mutex);
50449 - if (tty->port.count == 0) {
50450 + if (atomic_read(&tty->port.count) == 0) {
50451 mutex_unlock(&tty->ipw_tty_mutex);
50452 return;
50453 }
50454 @@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50455
50456 mutex_lock(&tty->ipw_tty_mutex);
50457
50458 - if (!tty->port.count) {
50459 + if (!atomic_read(&tty->port.count)) {
50460 mutex_unlock(&tty->ipw_tty_mutex);
50461 return;
50462 }
50463 @@ -205,7 +204,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50464 return -ENODEV;
50465
50466 mutex_lock(&tty->ipw_tty_mutex);
50467 - if (!tty->port.count) {
50468 + if (!atomic_read(&tty->port.count)) {
50469 mutex_unlock(&tty->ipw_tty_mutex);
50470 return -EINVAL;
50471 }
50472 @@ -245,7 +244,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50473 if (!tty)
50474 return -ENODEV;
50475
50476 - if (!tty->port.count)
50477 + if (!atomic_read(&tty->port.count))
50478 return -EINVAL;
50479
50480 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50481 @@ -287,7 +286,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50482 if (!tty)
50483 return 0;
50484
50485 - if (!tty->port.count)
50486 + if (!atomic_read(&tty->port.count))
50487 return 0;
50488
50489 return tty->tx_bytes_queued;
50490 @@ -368,7 +367,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50491 if (!tty)
50492 return -ENODEV;
50493
50494 - if (!tty->port.count)
50495 + if (!atomic_read(&tty->port.count))
50496 return -EINVAL;
50497
50498 return get_control_lines(tty);
50499 @@ -384,7 +383,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50500 if (!tty)
50501 return -ENODEV;
50502
50503 - if (!tty->port.count)
50504 + if (!atomic_read(&tty->port.count))
50505 return -EINVAL;
50506
50507 return set_control_lines(tty, set, clear);
50508 @@ -398,7 +397,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50509 if (!tty)
50510 return -ENODEV;
50511
50512 - if (!tty->port.count)
50513 + if (!atomic_read(&tty->port.count))
50514 return -EINVAL;
50515
50516 /* FIXME: Exactly how is the tty object locked here .. */
50517 @@ -554,7 +553,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50518 * are gone */
50519 mutex_lock(&ttyj->ipw_tty_mutex);
50520 }
50521 - while (ttyj->port.count)
50522 + while (atomic_read(&ttyj->port.count))
50523 do_ipw_close(ttyj);
50524 ipwireless_disassociate_network_ttys(network,
50525 ttyj->channel_idx);
50526 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50527 index 1deaca4..c8582d4 100644
50528 --- a/drivers/tty/moxa.c
50529 +++ b/drivers/tty/moxa.c
50530 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50531 }
50532
50533 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50534 - ch->port.count++;
50535 + atomic_inc(&ch->port.count);
50536 tty->driver_data = ch;
50537 tty_port_tty_set(&ch->port, tty);
50538 mutex_lock(&ch->port.mutex);
50539 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50540 index 2ebe47b..3205833 100644
50541 --- a/drivers/tty/n_gsm.c
50542 +++ b/drivers/tty/n_gsm.c
50543 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50544 spin_lock_init(&dlci->lock);
50545 mutex_init(&dlci->mutex);
50546 dlci->fifo = &dlci->_fifo;
50547 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50548 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50549 kfree(dlci);
50550 return NULL;
50551 }
50552 @@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50553 struct gsm_dlci *dlci = tty->driver_data;
50554 struct tty_port *port = &dlci->port;
50555
50556 - port->count++;
50557 + atomic_inc(&port->count);
50558 tty_port_tty_set(port, tty);
50559
50560 dlci->modem_rx = 0;
50561 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50562 index d15624c..e512bdb 100644
50563 --- a/drivers/tty/n_tty.c
50564 +++ b/drivers/tty/n_tty.c
50565 @@ -115,7 +115,7 @@ struct n_tty_data {
50566 int minimum_to_wake;
50567
50568 /* consumer-published */
50569 - size_t read_tail;
50570 + size_t read_tail __intentional_overflow(-1);
50571 size_t line_start;
50572
50573 /* protected by output lock */
50574 @@ -2515,6 +2515,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50575 {
50576 *ops = tty_ldisc_N_TTY;
50577 ops->owner = NULL;
50578 - ops->refcount = ops->flags = 0;
50579 + atomic_set(&ops->refcount, 0);
50580 + ops->flags = 0;
50581 }
50582 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50583 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50584 index 25c9bc7..24077b7 100644
50585 --- a/drivers/tty/pty.c
50586 +++ b/drivers/tty/pty.c
50587 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50588 panic("Couldn't register Unix98 pts driver");
50589
50590 /* Now create the /dev/ptmx special device */
50591 + pax_open_kernel();
50592 tty_default_fops(&ptmx_fops);
50593 - ptmx_fops.open = ptmx_open;
50594 + *(void **)&ptmx_fops.open = ptmx_open;
50595 + pax_close_kernel();
50596
50597 cdev_init(&ptmx_cdev, &ptmx_fops);
50598 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50599 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50600 index 383c4c7..d408e21 100644
50601 --- a/drivers/tty/rocket.c
50602 +++ b/drivers/tty/rocket.c
50603 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50604 tty->driver_data = info;
50605 tty_port_tty_set(port, tty);
50606
50607 - if (port->count++ == 0) {
50608 + if (atomic_inc_return(&port->count) == 1) {
50609 atomic_inc(&rp_num_ports_open);
50610
50611 #ifdef ROCKET_DEBUG_OPEN
50612 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50613 #endif
50614 }
50615 #ifdef ROCKET_DEBUG_OPEN
50616 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50617 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50618 #endif
50619
50620 /*
50621 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50622 spin_unlock_irqrestore(&info->port.lock, flags);
50623 return;
50624 }
50625 - if (info->port.count)
50626 + if (atomic_read(&info->port.count))
50627 atomic_dec(&rp_num_ports_open);
50628 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
50629 spin_unlock_irqrestore(&info->port.lock, flags);
50630 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
50631 index 1274499..f541382 100644
50632 --- a/drivers/tty/serial/ioc4_serial.c
50633 +++ b/drivers/tty/serial/ioc4_serial.c
50634 @@ -437,7 +437,7 @@ struct ioc4_soft {
50635 } is_intr_info[MAX_IOC4_INTR_ENTS];
50636
50637 /* Number of entries active in the above array */
50638 - atomic_t is_num_intrs;
50639 + atomic_unchecked_t is_num_intrs;
50640 } is_intr_type[IOC4_NUM_INTR_TYPES];
50641
50642 /* is_ir_lock must be held while
50643 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
50644 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
50645 || (type == IOC4_OTHER_INTR_TYPE)));
50646
50647 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
50648 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
50649 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
50650
50651 /* Save off the lower level interrupt handler */
50652 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
50653
50654 soft = arg;
50655 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
50656 - num_intrs = (int)atomic_read(
50657 + num_intrs = (int)atomic_read_unchecked(
50658 &soft->is_intr_type[intr_type].is_num_intrs);
50659
50660 this_mir = this_ir = pending_intrs(soft, intr_type);
50661 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50662 index a260cde..6b2b5ce 100644
50663 --- a/drivers/tty/serial/kgdboc.c
50664 +++ b/drivers/tty/serial/kgdboc.c
50665 @@ -24,8 +24,9 @@
50666 #define MAX_CONFIG_LEN 40
50667
50668 static struct kgdb_io kgdboc_io_ops;
50669 +static struct kgdb_io kgdboc_io_ops_console;
50670
50671 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50672 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50673 static int configured = -1;
50674
50675 static char config[MAX_CONFIG_LEN];
50676 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50677 kgdboc_unregister_kbd();
50678 if (configured == 1)
50679 kgdb_unregister_io_module(&kgdboc_io_ops);
50680 + else if (configured == 2)
50681 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
50682 }
50683
50684 static int configure_kgdboc(void)
50685 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50686 int err;
50687 char *cptr = config;
50688 struct console *cons;
50689 + int is_console = 0;
50690
50691 err = kgdboc_option_setup(config);
50692 if (err || !strlen(config) || isspace(config[0]))
50693 goto noconfig;
50694
50695 err = -ENODEV;
50696 - kgdboc_io_ops.is_console = 0;
50697 kgdb_tty_driver = NULL;
50698
50699 kgdboc_use_kms = 0;
50700 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
50701 int idx;
50702 if (cons->device && cons->device(cons, &idx) == p &&
50703 idx == tty_line) {
50704 - kgdboc_io_ops.is_console = 1;
50705 + is_console = 1;
50706 break;
50707 }
50708 cons = cons->next;
50709 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50710 kgdb_tty_line = tty_line;
50711
50712 do_register:
50713 - err = kgdb_register_io_module(&kgdboc_io_ops);
50714 + if (is_console) {
50715 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
50716 + configured = 2;
50717 + } else {
50718 + err = kgdb_register_io_module(&kgdboc_io_ops);
50719 + configured = 1;
50720 + }
50721 if (err)
50722 goto noconfig;
50723
50724 @@ -205,8 +214,6 @@ do_register:
50725 if (err)
50726 goto nmi_con_failed;
50727
50728 - configured = 1;
50729 -
50730 return 0;
50731
50732 nmi_con_failed:
50733 @@ -223,7 +230,7 @@ noconfig:
50734 static int __init init_kgdboc(void)
50735 {
50736 /* Already configured? */
50737 - if (configured == 1)
50738 + if (configured >= 1)
50739 return 0;
50740
50741 return configure_kgdboc();
50742 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50743 if (config[len - 1] == '\n')
50744 config[len - 1] = '\0';
50745
50746 - if (configured == 1)
50747 + if (configured >= 1)
50748 cleanup_kgdboc();
50749
50750 /* Go and configure with the new params. */
50751 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50752 .post_exception = kgdboc_post_exp_handler,
50753 };
50754
50755 +static struct kgdb_io kgdboc_io_ops_console = {
50756 + .name = "kgdboc",
50757 + .read_char = kgdboc_get_char,
50758 + .write_char = kgdboc_put_char,
50759 + .pre_exception = kgdboc_pre_exp_handler,
50760 + .post_exception = kgdboc_post_exp_handler,
50761 + .is_console = 1
50762 +};
50763 +
50764 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50765 /* This is only available if kgdboc is a built in for early debugging */
50766 static int __init kgdboc_early_init(char *opt)
50767 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50768 index b5d779c..3622cfe 100644
50769 --- a/drivers/tty/serial/msm_serial.c
50770 +++ b/drivers/tty/serial/msm_serial.c
50771 @@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
50772 .cons = MSM_CONSOLE,
50773 };
50774
50775 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
50776 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
50777
50778 static const struct of_device_id msm_uartdm_table[] = {
50779 { .compatible = "qcom,msm-uartdm" },
50780 @@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
50781 int irq;
50782
50783 if (pdev->id == -1)
50784 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
50785 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
50786
50787 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
50788 return -ENXIO;
50789 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
50790 index 9cd706d..6ff2de7 100644
50791 --- a/drivers/tty/serial/samsung.c
50792 +++ b/drivers/tty/serial/samsung.c
50793 @@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
50794 }
50795 }
50796
50797 +static int s3c64xx_serial_startup(struct uart_port *port);
50798 static int s3c24xx_serial_startup(struct uart_port *port)
50799 {
50800 struct s3c24xx_uart_port *ourport = to_ourport(port);
50801 int ret;
50802
50803 + /* Startup sequence is different for s3c64xx and higher SoC's */
50804 + if (s3c24xx_serial_has_interrupt_mask(port))
50805 + return s3c64xx_serial_startup(port);
50806 +
50807 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
50808 port->mapbase, port->membase);
50809
50810 @@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
50811 /* setup info for port */
50812 port->dev = &platdev->dev;
50813
50814 - /* Startup sequence is different for s3c64xx and higher SoC's */
50815 - if (s3c24xx_serial_has_interrupt_mask(port))
50816 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
50817 -
50818 port->uartclk = 1;
50819
50820 if (cfg->uart_flags & UPF_CONS_FLOW) {
50821 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
50822 index ece2049..fba2524 100644
50823 --- a/drivers/tty/serial/serial_core.c
50824 +++ b/drivers/tty/serial/serial_core.c
50825 @@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
50826 uart_flush_buffer(tty);
50827 uart_shutdown(tty, state);
50828 spin_lock_irqsave(&port->lock, flags);
50829 - port->count = 0;
50830 + atomic_set(&port->count, 0);
50831 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
50832 spin_unlock_irqrestore(&port->lock, flags);
50833 tty_port_tty_set(port, NULL);
50834 @@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50835 goto end;
50836 }
50837
50838 - port->count++;
50839 + atomic_inc(&port->count);
50840 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
50841 retval = -ENXIO;
50842 goto err_dec_count;
50843 @@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50844 /*
50845 * Make sure the device is in D0 state.
50846 */
50847 - if (port->count == 1)
50848 + if (atomic_read(&port->count) == 1)
50849 uart_change_pm(state, UART_PM_STATE_ON);
50850
50851 /*
50852 @@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50853 end:
50854 return retval;
50855 err_dec_count:
50856 - port->count--;
50857 + atomic_inc(&port->count);
50858 mutex_unlock(&port->mutex);
50859 goto end;
50860 }
50861 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
50862 index 5ae14b4..2c1288f 100644
50863 --- a/drivers/tty/synclink.c
50864 +++ b/drivers/tty/synclink.c
50865 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50866
50867 if (debug_level >= DEBUG_LEVEL_INFO)
50868 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
50869 - __FILE__,__LINE__, info->device_name, info->port.count);
50870 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50871
50872 if (tty_port_close_start(&info->port, tty, filp) == 0)
50873 goto cleanup;
50874 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50875 cleanup:
50876 if (debug_level >= DEBUG_LEVEL_INFO)
50877 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
50878 - tty->driver->name, info->port.count);
50879 + tty->driver->name, atomic_read(&info->port.count));
50880
50881 } /* end of mgsl_close() */
50882
50883 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
50884
50885 mgsl_flush_buffer(tty);
50886 shutdown(info);
50887 -
50888 - info->port.count = 0;
50889 +
50890 + atomic_set(&info->port.count, 0);
50891 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50892 info->port.tty = NULL;
50893
50894 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50895
50896 if (debug_level >= DEBUG_LEVEL_INFO)
50897 printk("%s(%d):block_til_ready before block on %s count=%d\n",
50898 - __FILE__,__LINE__, tty->driver->name, port->count );
50899 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50900
50901 spin_lock_irqsave(&info->irq_spinlock, flags);
50902 if (!tty_hung_up_p(filp)) {
50903 extra_count = true;
50904 - port->count--;
50905 + atomic_dec(&port->count);
50906 }
50907 spin_unlock_irqrestore(&info->irq_spinlock, flags);
50908 port->blocked_open++;
50909 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50910
50911 if (debug_level >= DEBUG_LEVEL_INFO)
50912 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
50913 - __FILE__,__LINE__, tty->driver->name, port->count );
50914 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50915
50916 tty_unlock(tty);
50917 schedule();
50918 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50919
50920 /* FIXME: Racy on hangup during close wait */
50921 if (extra_count)
50922 - port->count++;
50923 + atomic_inc(&port->count);
50924 port->blocked_open--;
50925
50926 if (debug_level >= DEBUG_LEVEL_INFO)
50927 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
50928 - __FILE__,__LINE__, tty->driver->name, port->count );
50929 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50930
50931 if (!retval)
50932 port->flags |= ASYNC_NORMAL_ACTIVE;
50933 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50934
50935 if (debug_level >= DEBUG_LEVEL_INFO)
50936 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
50937 - __FILE__,__LINE__,tty->driver->name, info->port.count);
50938 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50939
50940 /* If port is closing, signal caller to try again */
50941 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50942 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50943 spin_unlock_irqrestore(&info->netlock, flags);
50944 goto cleanup;
50945 }
50946 - info->port.count++;
50947 + atomic_inc(&info->port.count);
50948 spin_unlock_irqrestore(&info->netlock, flags);
50949
50950 - if (info->port.count == 1) {
50951 + if (atomic_read(&info->port.count) == 1) {
50952 /* 1st open on this device, init hardware */
50953 retval = startup(info);
50954 if (retval < 0)
50955 @@ -3446,8 +3446,8 @@ cleanup:
50956 if (retval) {
50957 if (tty->count == 1)
50958 info->port.tty = NULL; /* tty layer will release tty struct */
50959 - if(info->port.count)
50960 - info->port.count--;
50961 + if (atomic_read(&info->port.count))
50962 + atomic_dec(&info->port.count);
50963 }
50964
50965 return retval;
50966 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50967 unsigned short new_crctype;
50968
50969 /* return error if TTY interface open */
50970 - if (info->port.count)
50971 + if (atomic_read(&info->port.count))
50972 return -EBUSY;
50973
50974 switch (encoding)
50975 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
50976
50977 /* arbitrate between network and tty opens */
50978 spin_lock_irqsave(&info->netlock, flags);
50979 - if (info->port.count != 0 || info->netcount != 0) {
50980 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50981 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
50982 spin_unlock_irqrestore(&info->netlock, flags);
50983 return -EBUSY;
50984 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50985 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
50986
50987 /* return error if TTY interface open */
50988 - if (info->port.count)
50989 + if (atomic_read(&info->port.count))
50990 return -EBUSY;
50991
50992 if (cmd != SIOCWANDEV)
50993 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
50994 index c359a91..959fc26 100644
50995 --- a/drivers/tty/synclink_gt.c
50996 +++ b/drivers/tty/synclink_gt.c
50997 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
50998 tty->driver_data = info;
50999 info->port.tty = tty;
51000
51001 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51002 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51003
51004 /* If port is closing, signal caller to try again */
51005 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51006 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51007 mutex_unlock(&info->port.mutex);
51008 goto cleanup;
51009 }
51010 - info->port.count++;
51011 + atomic_inc(&info->port.count);
51012 spin_unlock_irqrestore(&info->netlock, flags);
51013
51014 - if (info->port.count == 1) {
51015 + if (atomic_read(&info->port.count) == 1) {
51016 /* 1st open on this device, init hardware */
51017 retval = startup(info);
51018 if (retval < 0) {
51019 @@ -715,8 +715,8 @@ cleanup:
51020 if (retval) {
51021 if (tty->count == 1)
51022 info->port.tty = NULL; /* tty layer will release tty struct */
51023 - if(info->port.count)
51024 - info->port.count--;
51025 + if(atomic_read(&info->port.count))
51026 + atomic_dec(&info->port.count);
51027 }
51028
51029 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51030 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51031
51032 if (sanity_check(info, tty->name, "close"))
51033 return;
51034 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51035 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51036
51037 if (tty_port_close_start(&info->port, tty, filp) == 0)
51038 goto cleanup;
51039 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51040 tty_port_close_end(&info->port, tty);
51041 info->port.tty = NULL;
51042 cleanup:
51043 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51044 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51045 }
51046
51047 static void hangup(struct tty_struct *tty)
51048 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51049 shutdown(info);
51050
51051 spin_lock_irqsave(&info->port.lock, flags);
51052 - info->port.count = 0;
51053 + atomic_set(&info->port.count, 0);
51054 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51055 info->port.tty = NULL;
51056 spin_unlock_irqrestore(&info->port.lock, flags);
51057 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51058 unsigned short new_crctype;
51059
51060 /* return error if TTY interface open */
51061 - if (info->port.count)
51062 + if (atomic_read(&info->port.count))
51063 return -EBUSY;
51064
51065 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51066 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51067
51068 /* arbitrate between network and tty opens */
51069 spin_lock_irqsave(&info->netlock, flags);
51070 - if (info->port.count != 0 || info->netcount != 0) {
51071 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51072 DBGINFO(("%s hdlc_open busy\n", dev->name));
51073 spin_unlock_irqrestore(&info->netlock, flags);
51074 return -EBUSY;
51075 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51076 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51077
51078 /* return error if TTY interface open */
51079 - if (info->port.count)
51080 + if (atomic_read(&info->port.count))
51081 return -EBUSY;
51082
51083 if (cmd != SIOCWANDEV)
51084 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51085 if (port == NULL)
51086 continue;
51087 spin_lock(&port->lock);
51088 - if ((port->port.count || port->netcount) &&
51089 + if ((atomic_read(&port->port.count) || port->netcount) &&
51090 port->pending_bh && !port->bh_running &&
51091 !port->bh_requested) {
51092 DBGISR(("%s bh queued\n", port->device_name));
51093 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51094 spin_lock_irqsave(&info->lock, flags);
51095 if (!tty_hung_up_p(filp)) {
51096 extra_count = true;
51097 - port->count--;
51098 + atomic_dec(&port->count);
51099 }
51100 spin_unlock_irqrestore(&info->lock, flags);
51101 port->blocked_open++;
51102 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51103 remove_wait_queue(&port->open_wait, &wait);
51104
51105 if (extra_count)
51106 - port->count++;
51107 + atomic_inc(&port->count);
51108 port->blocked_open--;
51109
51110 if (!retval)
51111 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51112 index 144202e..4ccb07d 100644
51113 --- a/drivers/tty/synclinkmp.c
51114 +++ b/drivers/tty/synclinkmp.c
51115 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51116
51117 if (debug_level >= DEBUG_LEVEL_INFO)
51118 printk("%s(%d):%s open(), old ref count = %d\n",
51119 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51120 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51121
51122 /* If port is closing, signal caller to try again */
51123 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51124 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51125 spin_unlock_irqrestore(&info->netlock, flags);
51126 goto cleanup;
51127 }
51128 - info->port.count++;
51129 + atomic_inc(&info->port.count);
51130 spin_unlock_irqrestore(&info->netlock, flags);
51131
51132 - if (info->port.count == 1) {
51133 + if (atomic_read(&info->port.count) == 1) {
51134 /* 1st open on this device, init hardware */
51135 retval = startup(info);
51136 if (retval < 0)
51137 @@ -796,8 +796,8 @@ cleanup:
51138 if (retval) {
51139 if (tty->count == 1)
51140 info->port.tty = NULL; /* tty layer will release tty struct */
51141 - if(info->port.count)
51142 - info->port.count--;
51143 + if(atomic_read(&info->port.count))
51144 + atomic_dec(&info->port.count);
51145 }
51146
51147 return retval;
51148 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51149
51150 if (debug_level >= DEBUG_LEVEL_INFO)
51151 printk("%s(%d):%s close() entry, count=%d\n",
51152 - __FILE__,__LINE__, info->device_name, info->port.count);
51153 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51154
51155 if (tty_port_close_start(&info->port, tty, filp) == 0)
51156 goto cleanup;
51157 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51158 cleanup:
51159 if (debug_level >= DEBUG_LEVEL_INFO)
51160 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51161 - tty->driver->name, info->port.count);
51162 + tty->driver->name, atomic_read(&info->port.count));
51163 }
51164
51165 /* Called by tty_hangup() when a hangup is signaled.
51166 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51167 shutdown(info);
51168
51169 spin_lock_irqsave(&info->port.lock, flags);
51170 - info->port.count = 0;
51171 + atomic_set(&info->port.count, 0);
51172 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51173 info->port.tty = NULL;
51174 spin_unlock_irqrestore(&info->port.lock, flags);
51175 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51176 unsigned short new_crctype;
51177
51178 /* return error if TTY interface open */
51179 - if (info->port.count)
51180 + if (atomic_read(&info->port.count))
51181 return -EBUSY;
51182
51183 switch (encoding)
51184 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51185
51186 /* arbitrate between network and tty opens */
51187 spin_lock_irqsave(&info->netlock, flags);
51188 - if (info->port.count != 0 || info->netcount != 0) {
51189 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51190 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51191 spin_unlock_irqrestore(&info->netlock, flags);
51192 return -EBUSY;
51193 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51194 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51195
51196 /* return error if TTY interface open */
51197 - if (info->port.count)
51198 + if (atomic_read(&info->port.count))
51199 return -EBUSY;
51200
51201 if (cmd != SIOCWANDEV)
51202 @@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51203 * do not request bottom half processing if the
51204 * device is not open in a normal mode.
51205 */
51206 - if ( port && (port->port.count || port->netcount) &&
51207 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51208 port->pending_bh && !port->bh_running &&
51209 !port->bh_requested ) {
51210 if ( debug_level >= DEBUG_LEVEL_ISR )
51211 @@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51212
51213 if (debug_level >= DEBUG_LEVEL_INFO)
51214 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51215 - __FILE__,__LINE__, tty->driver->name, port->count );
51216 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51217
51218 spin_lock_irqsave(&info->lock, flags);
51219 if (!tty_hung_up_p(filp)) {
51220 extra_count = true;
51221 - port->count--;
51222 + atomic_dec(&port->count);
51223 }
51224 spin_unlock_irqrestore(&info->lock, flags);
51225 port->blocked_open++;
51226 @@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51227
51228 if (debug_level >= DEBUG_LEVEL_INFO)
51229 printk("%s(%d):%s block_til_ready() count=%d\n",
51230 - __FILE__,__LINE__, tty->driver->name, port->count );
51231 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51232
51233 tty_unlock(tty);
51234 schedule();
51235 @@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51236 remove_wait_queue(&port->open_wait, &wait);
51237
51238 if (extra_count)
51239 - port->count++;
51240 + atomic_inc(&port->count);
51241 port->blocked_open--;
51242
51243 if (debug_level >= DEBUG_LEVEL_INFO)
51244 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51245 - __FILE__,__LINE__, tty->driver->name, port->count );
51246 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51247
51248 if (!retval)
51249 port->flags |= ASYNC_NORMAL_ACTIVE;
51250 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51251 index ce396ec..04a37be 100644
51252 --- a/drivers/tty/sysrq.c
51253 +++ b/drivers/tty/sysrq.c
51254 @@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51255 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51256 size_t count, loff_t *ppos)
51257 {
51258 - if (count) {
51259 + if (count && capable(CAP_SYS_ADMIN)) {
51260 char c;
51261
51262 if (get_user(c, buf))
51263 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51264 index c74a00a..02cf211a 100644
51265 --- a/drivers/tty/tty_io.c
51266 +++ b/drivers/tty/tty_io.c
51267 @@ -3474,7 +3474,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51268
51269 void tty_default_fops(struct file_operations *fops)
51270 {
51271 - *fops = tty_fops;
51272 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51273 }
51274
51275 /*
51276 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51277 index 2d822aa..a566234 100644
51278 --- a/drivers/tty/tty_ldisc.c
51279 +++ b/drivers/tty/tty_ldisc.c
51280 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51281 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51282 tty_ldiscs[disc] = new_ldisc;
51283 new_ldisc->num = disc;
51284 - new_ldisc->refcount = 0;
51285 + atomic_set(&new_ldisc->refcount, 0);
51286 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51287
51288 return ret;
51289 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51290 return -EINVAL;
51291
51292 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51293 - if (tty_ldiscs[disc]->refcount)
51294 + if (atomic_read(&tty_ldiscs[disc]->refcount))
51295 ret = -EBUSY;
51296 else
51297 tty_ldiscs[disc] = NULL;
51298 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51299 if (ldops) {
51300 ret = ERR_PTR(-EAGAIN);
51301 if (try_module_get(ldops->owner)) {
51302 - ldops->refcount++;
51303 + atomic_inc(&ldops->refcount);
51304 ret = ldops;
51305 }
51306 }
51307 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51308 unsigned long flags;
51309
51310 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51311 - ldops->refcount--;
51312 + atomic_dec(&ldops->refcount);
51313 module_put(ldops->owner);
51314 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51315 }
51316 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51317 index 3f746c8..2f2fcaa 100644
51318 --- a/drivers/tty/tty_port.c
51319 +++ b/drivers/tty/tty_port.c
51320 @@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
51321 unsigned long flags;
51322
51323 spin_lock_irqsave(&port->lock, flags);
51324 - port->count = 0;
51325 + atomic_set(&port->count, 0);
51326 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51327 tty = port->tty;
51328 if (tty)
51329 @@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51330 /* The port lock protects the port counts */
51331 spin_lock_irqsave(&port->lock, flags);
51332 if (!tty_hung_up_p(filp))
51333 - port->count--;
51334 + atomic_dec(&port->count);
51335 port->blocked_open++;
51336 spin_unlock_irqrestore(&port->lock, flags);
51337
51338 @@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51339 we must not mess that up further */
51340 spin_lock_irqsave(&port->lock, flags);
51341 if (!tty_hung_up_p(filp))
51342 - port->count++;
51343 + atomic_inc(&port->count);
51344 port->blocked_open--;
51345 if (retval == 0)
51346 port->flags |= ASYNC_NORMAL_ACTIVE;
51347 @@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
51348 return 0;
51349 }
51350
51351 - if (tty->count == 1 && port->count != 1) {
51352 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
51353 printk(KERN_WARNING
51354 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51355 - port->count);
51356 - port->count = 1;
51357 + atomic_read(&port->count));
51358 + atomic_set(&port->count, 1);
51359 }
51360 - if (--port->count < 0) {
51361 + if (atomic_dec_return(&port->count) < 0) {
51362 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51363 - port->count);
51364 - port->count = 0;
51365 + atomic_read(&port->count));
51366 + atomic_set(&port->count, 0);
51367 }
51368
51369 - if (port->count) {
51370 + if (atomic_read(&port->count)) {
51371 spin_unlock_irqrestore(&port->lock, flags);
51372 return 0;
51373 }
51374 @@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51375 {
51376 spin_lock_irq(&port->lock);
51377 if (!tty_hung_up_p(filp))
51378 - ++port->count;
51379 + atomic_inc(&port->count);
51380 spin_unlock_irq(&port->lock);
51381 tty_port_tty_set(port, tty);
51382
51383 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51384 index d0e3a44..5f8b754 100644
51385 --- a/drivers/tty/vt/keyboard.c
51386 +++ b/drivers/tty/vt/keyboard.c
51387 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51388 kbd->kbdmode == VC_OFF) &&
51389 value != KVAL(K_SAK))
51390 return; /* SAK is allowed even in raw mode */
51391 +
51392 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51393 + {
51394 + void *func = fn_handler[value];
51395 + if (func == fn_show_state || func == fn_show_ptregs ||
51396 + func == fn_show_mem)
51397 + return;
51398 + }
51399 +#endif
51400 +
51401 fn_handler[value](vc);
51402 }
51403
51404 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51405 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51406 return -EFAULT;
51407
51408 - if (!capable(CAP_SYS_TTY_CONFIG))
51409 - perm = 0;
51410 -
51411 switch (cmd) {
51412 case KDGKBENT:
51413 /* Ensure another thread doesn't free it under us */
51414 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51415 spin_unlock_irqrestore(&kbd_event_lock, flags);
51416 return put_user(val, &user_kbe->kb_value);
51417 case KDSKBENT:
51418 + if (!capable(CAP_SYS_TTY_CONFIG))
51419 + perm = 0;
51420 +
51421 if (!perm)
51422 return -EPERM;
51423 if (!i && v == K_NOSUCHMAP) {
51424 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51425 int i, j, k;
51426 int ret;
51427
51428 - if (!capable(CAP_SYS_TTY_CONFIG))
51429 - perm = 0;
51430 -
51431 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51432 if (!kbs) {
51433 ret = -ENOMEM;
51434 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51435 kfree(kbs);
51436 return ((p && *p) ? -EOVERFLOW : 0);
51437 case KDSKBSENT:
51438 + if (!capable(CAP_SYS_TTY_CONFIG))
51439 + perm = 0;
51440 +
51441 if (!perm) {
51442 ret = -EPERM;
51443 goto reterr;
51444 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51445 index a673e5b..36e5d32 100644
51446 --- a/drivers/uio/uio.c
51447 +++ b/drivers/uio/uio.c
51448 @@ -25,6 +25,7 @@
51449 #include <linux/kobject.h>
51450 #include <linux/cdev.h>
51451 #include <linux/uio_driver.h>
51452 +#include <asm/local.h>
51453
51454 #define UIO_MAX_DEVICES (1U << MINORBITS)
51455
51456 @@ -32,7 +33,7 @@ struct uio_device {
51457 struct module *owner;
51458 struct device *dev;
51459 int minor;
51460 - atomic_t event;
51461 + atomic_unchecked_t event;
51462 struct fasync_struct *async_queue;
51463 wait_queue_head_t wait;
51464 struct uio_info *info;
51465 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51466 struct device_attribute *attr, char *buf)
51467 {
51468 struct uio_device *idev = dev_get_drvdata(dev);
51469 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51470 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51471 }
51472 static DEVICE_ATTR_RO(event);
51473
51474 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51475 {
51476 struct uio_device *idev = info->uio_dev;
51477
51478 - atomic_inc(&idev->event);
51479 + atomic_inc_unchecked(&idev->event);
51480 wake_up_interruptible(&idev->wait);
51481 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51482 }
51483 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51484 }
51485
51486 listener->dev = idev;
51487 - listener->event_count = atomic_read(&idev->event);
51488 + listener->event_count = atomic_read_unchecked(&idev->event);
51489 filep->private_data = listener;
51490
51491 if (idev->info->open) {
51492 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51493 return -EIO;
51494
51495 poll_wait(filep, &idev->wait, wait);
51496 - if (listener->event_count != atomic_read(&idev->event))
51497 + if (listener->event_count != atomic_read_unchecked(&idev->event))
51498 return POLLIN | POLLRDNORM;
51499 return 0;
51500 }
51501 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51502 do {
51503 set_current_state(TASK_INTERRUPTIBLE);
51504
51505 - event_count = atomic_read(&idev->event);
51506 + event_count = atomic_read_unchecked(&idev->event);
51507 if (event_count != listener->event_count) {
51508 if (copy_to_user(buf, &event_count, count))
51509 retval = -EFAULT;
51510 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51511 static int uio_find_mem_index(struct vm_area_struct *vma)
51512 {
51513 struct uio_device *idev = vma->vm_private_data;
51514 + unsigned long size;
51515
51516 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51517 - if (idev->info->mem[vma->vm_pgoff].size == 0)
51518 + size = idev->info->mem[vma->vm_pgoff].size;
51519 + if (size == 0)
51520 + return -1;
51521 + if (vma->vm_end - vma->vm_start > size)
51522 return -1;
51523 return (int)vma->vm_pgoff;
51524 }
51525 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51526 idev->owner = owner;
51527 idev->info = info;
51528 init_waitqueue_head(&idev->wait);
51529 - atomic_set(&idev->event, 0);
51530 + atomic_set_unchecked(&idev->event, 0);
51531
51532 ret = uio_get_minor(idev);
51533 if (ret)
51534 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51535 index 813d4d3..a71934f 100644
51536 --- a/drivers/usb/atm/cxacru.c
51537 +++ b/drivers/usb/atm/cxacru.c
51538 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51539 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51540 if (ret < 2)
51541 return -EINVAL;
51542 - if (index < 0 || index > 0x7f)
51543 + if (index > 0x7f)
51544 return -EINVAL;
51545 pos += tmp;
51546
51547 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51548 index dada014..1d0d517 100644
51549 --- a/drivers/usb/atm/usbatm.c
51550 +++ b/drivers/usb/atm/usbatm.c
51551 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51552 if (printk_ratelimit())
51553 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51554 __func__, vpi, vci);
51555 - atomic_inc(&vcc->stats->rx_err);
51556 + atomic_inc_unchecked(&vcc->stats->rx_err);
51557 return;
51558 }
51559
51560 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51561 if (length > ATM_MAX_AAL5_PDU) {
51562 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51563 __func__, length, vcc);
51564 - atomic_inc(&vcc->stats->rx_err);
51565 + atomic_inc_unchecked(&vcc->stats->rx_err);
51566 goto out;
51567 }
51568
51569 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51570 if (sarb->len < pdu_length) {
51571 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51572 __func__, pdu_length, sarb->len, vcc);
51573 - atomic_inc(&vcc->stats->rx_err);
51574 + atomic_inc_unchecked(&vcc->stats->rx_err);
51575 goto out;
51576 }
51577
51578 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51579 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51580 __func__, vcc);
51581 - atomic_inc(&vcc->stats->rx_err);
51582 + atomic_inc_unchecked(&vcc->stats->rx_err);
51583 goto out;
51584 }
51585
51586 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51587 if (printk_ratelimit())
51588 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51589 __func__, length);
51590 - atomic_inc(&vcc->stats->rx_drop);
51591 + atomic_inc_unchecked(&vcc->stats->rx_drop);
51592 goto out;
51593 }
51594
51595 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51596
51597 vcc->push(vcc, skb);
51598
51599 - atomic_inc(&vcc->stats->rx);
51600 + atomic_inc_unchecked(&vcc->stats->rx);
51601 out:
51602 skb_trim(sarb, 0);
51603 }
51604 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51605 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51606
51607 usbatm_pop(vcc, skb);
51608 - atomic_inc(&vcc->stats->tx);
51609 + atomic_inc_unchecked(&vcc->stats->tx);
51610
51611 skb = skb_dequeue(&instance->sndqueue);
51612 }
51613 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
51614 if (!left--)
51615 return sprintf(page,
51616 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51617 - atomic_read(&atm_dev->stats.aal5.tx),
51618 - atomic_read(&atm_dev->stats.aal5.tx_err),
51619 - atomic_read(&atm_dev->stats.aal5.rx),
51620 - atomic_read(&atm_dev->stats.aal5.rx_err),
51621 - atomic_read(&atm_dev->stats.aal5.rx_drop));
51622 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51623 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51624 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51625 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
51626 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
51627
51628 if (!left--) {
51629 if (instance->disconnected)
51630 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
51631 index 2a3bbdf..91d72cf 100644
51632 --- a/drivers/usb/core/devices.c
51633 +++ b/drivers/usb/core/devices.c
51634 @@ -126,7 +126,7 @@ static const char format_endpt[] =
51635 * time it gets called.
51636 */
51637 static struct device_connect_event {
51638 - atomic_t count;
51639 + atomic_unchecked_t count;
51640 wait_queue_head_t wait;
51641 } device_event = {
51642 .count = ATOMIC_INIT(1),
51643 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
51644
51645 void usbfs_conn_disc_event(void)
51646 {
51647 - atomic_add(2, &device_event.count);
51648 + atomic_add_unchecked(2, &device_event.count);
51649 wake_up(&device_event.wait);
51650 }
51651
51652 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
51653
51654 poll_wait(file, &device_event.wait, wait);
51655
51656 - event_count = atomic_read(&device_event.count);
51657 + event_count = atomic_read_unchecked(&device_event.count);
51658 if (file->f_version != event_count) {
51659 file->f_version = event_count;
51660 return POLLIN | POLLRDNORM;
51661 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51662 index 90e18f6..5eeda46 100644
51663 --- a/drivers/usb/core/devio.c
51664 +++ b/drivers/usb/core/devio.c
51665 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51666 struct dev_state *ps = file->private_data;
51667 struct usb_device *dev = ps->dev;
51668 ssize_t ret = 0;
51669 - unsigned len;
51670 + size_t len;
51671 loff_t pos;
51672 int i;
51673
51674 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51675 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51676 struct usb_config_descriptor *config =
51677 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51678 - unsigned int length = le16_to_cpu(config->wTotalLength);
51679 + size_t length = le16_to_cpu(config->wTotalLength);
51680
51681 if (*ppos < pos + length) {
51682
51683 /* The descriptor may claim to be longer than it
51684 * really is. Here is the actual allocated length. */
51685 - unsigned alloclen =
51686 + size_t alloclen =
51687 le16_to_cpu(dev->config[i].desc.wTotalLength);
51688
51689 - len = length - (*ppos - pos);
51690 + len = length + pos - *ppos;
51691 if (len > nbytes)
51692 len = nbytes;
51693
51694 /* Simply don't write (skip over) unallocated parts */
51695 if (alloclen > (*ppos - pos)) {
51696 - alloclen -= (*ppos - pos);
51697 + alloclen = alloclen + pos - *ppos;
51698 if (copy_to_user(buf,
51699 dev->rawdescriptors[i] + (*ppos - pos),
51700 min(len, alloclen))) {
51701 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
51702 index 2518c32..1c201bb 100644
51703 --- a/drivers/usb/core/hcd.c
51704 +++ b/drivers/usb/core/hcd.c
51705 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51706 */
51707 usb_get_urb(urb);
51708 atomic_inc(&urb->use_count);
51709 - atomic_inc(&urb->dev->urbnum);
51710 + atomic_inc_unchecked(&urb->dev->urbnum);
51711 usbmon_urb_submit(&hcd->self, urb);
51712
51713 /* NOTE requirements on root-hub callers (usbfs and the hub
51714 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51715 urb->hcpriv = NULL;
51716 INIT_LIST_HEAD(&urb->urb_list);
51717 atomic_dec(&urb->use_count);
51718 - atomic_dec(&urb->dev->urbnum);
51719 + atomic_dec_unchecked(&urb->dev->urbnum);
51720 if (atomic_read(&urb->reject))
51721 wake_up(&usb_kill_urb_queue);
51722 usb_put_urb(urb);
51723 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51724 index 64ea219..dbc1780 100644
51725 --- a/drivers/usb/core/hub.c
51726 +++ b/drivers/usb/core/hub.c
51727 @@ -27,6 +27,7 @@
51728 #include <linux/freezer.h>
51729 #include <linux/random.h>
51730 #include <linux/pm_qos.h>
51731 +#include <linux/grsecurity.h>
51732
51733 #include <asm/uaccess.h>
51734 #include <asm/byteorder.h>
51735 @@ -4472,6 +4473,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51736 goto done;
51737 return;
51738 }
51739 +
51740 + if (gr_handle_new_usb())
51741 + goto done;
51742 +
51743 if (hub_is_superspeed(hub->hdev))
51744 unit_load = 150;
51745 else
51746 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51747 index f829a1a..e6c334a 100644
51748 --- a/drivers/usb/core/message.c
51749 +++ b/drivers/usb/core/message.c
51750 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51751 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51752 * error number.
51753 */
51754 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51755 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51756 __u8 requesttype, __u16 value, __u16 index, void *data,
51757 __u16 size, int timeout)
51758 {
51759 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51760 * If successful, 0. Otherwise a negative error number. The number of actual
51761 * bytes transferred will be stored in the @actual_length paramater.
51762 */
51763 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51764 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51765 void *data, int len, int *actual_length, int timeout)
51766 {
51767 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51768 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51769 * bytes transferred will be stored in the @actual_length parameter.
51770 *
51771 */
51772 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51773 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51774 void *data, int len, int *actual_length, int timeout)
51775 {
51776 struct urb *urb;
51777 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
51778 index 1236c60..d47a51c 100644
51779 --- a/drivers/usb/core/sysfs.c
51780 +++ b/drivers/usb/core/sysfs.c
51781 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
51782 struct usb_device *udev;
51783
51784 udev = to_usb_device(dev);
51785 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
51786 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
51787 }
51788 static DEVICE_ATTR_RO(urbnum);
51789
51790 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
51791 index 4d11449..f4ccabf 100644
51792 --- a/drivers/usb/core/usb.c
51793 +++ b/drivers/usb/core/usb.c
51794 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
51795 set_dev_node(&dev->dev, dev_to_node(bus->controller));
51796 dev->state = USB_STATE_ATTACHED;
51797 dev->lpm_disable_count = 1;
51798 - atomic_set(&dev->urbnum, 0);
51799 + atomic_set_unchecked(&dev->urbnum, 0);
51800
51801 INIT_LIST_HEAD(&dev->ep0.urb_list);
51802 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
51803 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
51804 index 2da0a5a..4870e09 100644
51805 --- a/drivers/usb/dwc3/gadget.c
51806 +++ b/drivers/usb/dwc3/gadget.c
51807 @@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
51808 if (!usb_endpoint_xfer_isoc(desc))
51809 return 0;
51810
51811 - memset(&trb_link, 0, sizeof(trb_link));
51812 -
51813 /* Link TRB for ISOC. The HWO bit is never reset */
51814 trb_st_hw = &dep->trb_pool[0];
51815
51816 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
51817 index 8cfc319..4868255 100644
51818 --- a/drivers/usb/early/ehci-dbgp.c
51819 +++ b/drivers/usb/early/ehci-dbgp.c
51820 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
51821
51822 #ifdef CONFIG_KGDB
51823 static struct kgdb_io kgdbdbgp_io_ops;
51824 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
51825 +static struct kgdb_io kgdbdbgp_io_ops_console;
51826 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
51827 #else
51828 #define dbgp_kgdb_mode (0)
51829 #endif
51830 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
51831 .write_char = kgdbdbgp_write_char,
51832 };
51833
51834 +static struct kgdb_io kgdbdbgp_io_ops_console = {
51835 + .name = "kgdbdbgp",
51836 + .read_char = kgdbdbgp_read_char,
51837 + .write_char = kgdbdbgp_write_char,
51838 + .is_console = 1
51839 +};
51840 +
51841 static int kgdbdbgp_wait_time;
51842
51843 static int __init kgdbdbgp_parse_config(char *str)
51844 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
51845 ptr++;
51846 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
51847 }
51848 - kgdb_register_io_module(&kgdbdbgp_io_ops);
51849 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
51850 + if (early_dbgp_console.index != -1)
51851 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
51852 + else
51853 + kgdb_register_io_module(&kgdbdbgp_io_ops);
51854
51855 return 0;
51856 }
51857 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
51858 index b369292..9f3ba40 100644
51859 --- a/drivers/usb/gadget/u_serial.c
51860 +++ b/drivers/usb/gadget/u_serial.c
51861 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51862 spin_lock_irq(&port->port_lock);
51863
51864 /* already open? Great. */
51865 - if (port->port.count) {
51866 + if (atomic_read(&port->port.count)) {
51867 status = 0;
51868 - port->port.count++;
51869 + atomic_inc(&port->port.count);
51870
51871 /* currently opening/closing? wait ... */
51872 } else if (port->openclose) {
51873 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51874 tty->driver_data = port;
51875 port->port.tty = tty;
51876
51877 - port->port.count = 1;
51878 + atomic_set(&port->port.count, 1);
51879 port->openclose = false;
51880
51881 /* if connected, start the I/O stream */
51882 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51883
51884 spin_lock_irq(&port->port_lock);
51885
51886 - if (port->port.count != 1) {
51887 - if (port->port.count == 0)
51888 + if (atomic_read(&port->port.count) != 1) {
51889 + if (atomic_read(&port->port.count) == 0)
51890 WARN_ON(1);
51891 else
51892 - --port->port.count;
51893 + atomic_dec(&port->port.count);
51894 goto exit;
51895 }
51896
51897 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51898 * and sleep if necessary
51899 */
51900 port->openclose = true;
51901 - port->port.count = 0;
51902 + atomic_set(&port->port.count, 0);
51903
51904 gser = port->port_usb;
51905 if (gser && gser->disconnect)
51906 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
51907 int cond;
51908
51909 spin_lock_irq(&port->port_lock);
51910 - cond = (port->port.count == 0) && !port->openclose;
51911 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
51912 spin_unlock_irq(&port->port_lock);
51913 return cond;
51914 }
51915 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
51916 /* if it's already open, start I/O ... and notify the serial
51917 * protocol about open/close status (connect/disconnect).
51918 */
51919 - if (port->port.count) {
51920 + if (atomic_read(&port->port.count)) {
51921 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
51922 gs_start_io(port);
51923 if (gser->connect)
51924 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
51925
51926 port->port_usb = NULL;
51927 gser->ioport = NULL;
51928 - if (port->port.count > 0 || port->openclose) {
51929 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
51930 wake_up_interruptible(&port->drain_wait);
51931 if (port->port.tty)
51932 tty_hangup(port->port.tty);
51933 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
51934
51935 /* finally, free any unused/unusable I/O buffers */
51936 spin_lock_irqsave(&port->port_lock, flags);
51937 - if (port->port.count == 0 && !port->openclose)
51938 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
51939 gs_buf_free(&port->port_write_buf);
51940 gs_free_requests(gser->out, &port->read_pool, NULL);
51941 gs_free_requests(gser->out, &port->read_queue, NULL);
51942 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
51943 index 7ae0c4d..35521b7 100644
51944 --- a/drivers/usb/host/ehci-hub.c
51945 +++ b/drivers/usb/host/ehci-hub.c
51946 @@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
51947 urb->transfer_flags = URB_DIR_IN;
51948 usb_get_urb(urb);
51949 atomic_inc(&urb->use_count);
51950 - atomic_inc(&urb->dev->urbnum);
51951 + atomic_inc_unchecked(&urb->dev->urbnum);
51952 urb->setup_dma = dma_map_single(
51953 hcd->self.controller,
51954 urb->setup_packet,
51955 @@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
51956 urb->status = -EINPROGRESS;
51957 usb_get_urb(urb);
51958 atomic_inc(&urb->use_count);
51959 - atomic_inc(&urb->dev->urbnum);
51960 + atomic_inc_unchecked(&urb->dev->urbnum);
51961 retval = submit_single_step_set_feature(hcd, urb, 0);
51962 if (!retval && !wait_for_completion_timeout(&done,
51963 msecs_to_jiffies(2000))) {
51964 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
51965 index ba6a5d6..f88f7f3 100644
51966 --- a/drivers/usb/misc/appledisplay.c
51967 +++ b/drivers/usb/misc/appledisplay.c
51968 @@ -83,7 +83,7 @@ struct appledisplay {
51969 spinlock_t lock;
51970 };
51971
51972 -static atomic_t count_displays = ATOMIC_INIT(0);
51973 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
51974 static struct workqueue_struct *wq;
51975
51976 static void appledisplay_complete(struct urb *urb)
51977 @@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
51978
51979 /* Register backlight device */
51980 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
51981 - atomic_inc_return(&count_displays) - 1);
51982 + atomic_inc_return_unchecked(&count_displays) - 1);
51983 memset(&props, 0, sizeof(struct backlight_properties));
51984 props.type = BACKLIGHT_RAW;
51985 props.max_brightness = 0xff;
51986 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
51987 index 8d7fc48..01c4986 100644
51988 --- a/drivers/usb/serial/console.c
51989 +++ b/drivers/usb/serial/console.c
51990 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
51991
51992 info->port = port;
51993
51994 - ++port->port.count;
51995 + atomic_inc(&port->port.count);
51996 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
51997 if (serial->type->set_termios) {
51998 /*
51999 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52000 }
52001 /* Now that any required fake tty operations are completed restore
52002 * the tty port count */
52003 - --port->port.count;
52004 + atomic_dec(&port->port.count);
52005 /* The console is special in terms of closing the device so
52006 * indicate this port is now acting as a system console. */
52007 port->port.console = 1;
52008 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52009 free_tty:
52010 kfree(tty);
52011 reset_open_count:
52012 - port->port.count = 0;
52013 + atomic_set(&port->port.count, 0);
52014 usb_autopm_put_interface(serial->interface);
52015 error_get_interface:
52016 usb_serial_put(serial);
52017 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52018 static void usb_console_write(struct console *co,
52019 const char *buf, unsigned count)
52020 {
52021 - static struct usbcons_info *info = &usbcons_info;
52022 + struct usbcons_info *info = &usbcons_info;
52023 struct usb_serial_port *port = info->port;
52024 struct usb_serial *serial;
52025 int retval = -ENODEV;
52026 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52027 index 75f70f0..d467e1a 100644
52028 --- a/drivers/usb/storage/usb.h
52029 +++ b/drivers/usb/storage/usb.h
52030 @@ -63,7 +63,7 @@ struct us_unusual_dev {
52031 __u8 useProtocol;
52032 __u8 useTransport;
52033 int (*initFunction)(struct us_data *);
52034 -};
52035 +} __do_const;
52036
52037
52038 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52039 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52040 index a2ef84b..aa7c2b8 100644
52041 --- a/drivers/usb/wusbcore/wa-hc.h
52042 +++ b/drivers/usb/wusbcore/wa-hc.h
52043 @@ -225,7 +225,7 @@ struct wahc {
52044 spinlock_t xfer_list_lock;
52045 struct work_struct xfer_enqueue_work;
52046 struct work_struct xfer_error_work;
52047 - atomic_t xfer_id_count;
52048 + atomic_unchecked_t xfer_id_count;
52049
52050 kernel_ulong_t quirks;
52051 };
52052 @@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52053 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52054 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52055 wa->dto_in_use = 0;
52056 - atomic_set(&wa->xfer_id_count, 1);
52057 + atomic_set_unchecked(&wa->xfer_id_count, 1);
52058 }
52059
52060 /**
52061 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52062 index 3cd96e9..bd7c58d 100644
52063 --- a/drivers/usb/wusbcore/wa-xfer.c
52064 +++ b/drivers/usb/wusbcore/wa-xfer.c
52065 @@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52066 */
52067 static void wa_xfer_id_init(struct wa_xfer *xfer)
52068 {
52069 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52070 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52071 }
52072
52073 /* Return the xfer's ID. */
52074 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52075 index 21271d8..45b55a0 100644
52076 --- a/drivers/vfio/vfio.c
52077 +++ b/drivers/vfio/vfio.c
52078 @@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52079 return 0;
52080
52081 /* TODO Prevent device auto probing */
52082 - WARN("Device %s added to live group %d!\n", dev_name(dev),
52083 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52084 iommu_group_id(group->iommu_group));
52085
52086 return 0;
52087 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52088 index 5174eba..451e6bc 100644
52089 --- a/drivers/vhost/vringh.c
52090 +++ b/drivers/vhost/vringh.c
52091 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52092 /* Userspace access helpers: in this case, addresses are really userspace. */
52093 static inline int getu16_user(u16 *val, const u16 *p)
52094 {
52095 - return get_user(*val, (__force u16 __user *)p);
52096 + return get_user(*val, (u16 __force_user *)p);
52097 }
52098
52099 static inline int putu16_user(u16 *p, u16 val)
52100 {
52101 - return put_user(val, (__force u16 __user *)p);
52102 + return put_user(val, (u16 __force_user *)p);
52103 }
52104
52105 static inline int copydesc_user(void *dst, const void *src, size_t len)
52106 {
52107 - return copy_from_user(dst, (__force void __user *)src, len) ?
52108 + return copy_from_user(dst, (void __force_user *)src, len) ?
52109 -EFAULT : 0;
52110 }
52111
52112 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52113 const struct vring_used_elem *src,
52114 unsigned int num)
52115 {
52116 - return copy_to_user((__force void __user *)dst, src,
52117 + return copy_to_user((void __force_user *)dst, src,
52118 sizeof(*dst) * num) ? -EFAULT : 0;
52119 }
52120
52121 static inline int xfer_from_user(void *src, void *dst, size_t len)
52122 {
52123 - return copy_from_user(dst, (__force void __user *)src, len) ?
52124 + return copy_from_user(dst, (void __force_user *)src, len) ?
52125 -EFAULT : 0;
52126 }
52127
52128 static inline int xfer_to_user(void *dst, void *src, size_t len)
52129 {
52130 - return copy_to_user((__force void __user *)dst, src, len) ?
52131 + return copy_to_user((void __force_user *)dst, src, len) ?
52132 -EFAULT : 0;
52133 }
52134
52135 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52136 vrh->last_used_idx = 0;
52137 vrh->vring.num = num;
52138 /* vring expects kernel addresses, but only used via accessors. */
52139 - vrh->vring.desc = (__force struct vring_desc *)desc;
52140 - vrh->vring.avail = (__force struct vring_avail *)avail;
52141 - vrh->vring.used = (__force struct vring_used *)used;
52142 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52143 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52144 + vrh->vring.used = (__force_kernel struct vring_used *)used;
52145 return 0;
52146 }
52147 EXPORT_SYMBOL(vringh_init_user);
52148 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52149
52150 static inline int putu16_kern(u16 *p, u16 val)
52151 {
52152 - ACCESS_ONCE(*p) = val;
52153 + ACCESS_ONCE_RW(*p) = val;
52154 return 0;
52155 }
52156
52157 diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52158 index 1b0b233..6f34c2c 100644
52159 --- a/drivers/video/arcfb.c
52160 +++ b/drivers/video/arcfb.c
52161 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52162 return -ENOSPC;
52163
52164 err = 0;
52165 - if ((count + p) > fbmemlength) {
52166 + if (count > (fbmemlength - p)) {
52167 count = fbmemlength - p;
52168 err = -ENOSPC;
52169 }
52170 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52171 index 52108be..c7c110d 100644
52172 --- a/drivers/video/aty/aty128fb.c
52173 +++ b/drivers/video/aty/aty128fb.c
52174 @@ -149,7 +149,7 @@ enum {
52175 };
52176
52177 /* Must match above enum */
52178 -static char * const r128_family[] = {
52179 +static const char * const r128_family[] = {
52180 "AGP",
52181 "PCI",
52182 "PRO AGP",
52183 diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52184 index 28fafbf..ae91651 100644
52185 --- a/drivers/video/aty/atyfb_base.c
52186 +++ b/drivers/video/aty/atyfb_base.c
52187 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52188 par->accel_flags = var->accel_flags; /* hack */
52189
52190 if (var->accel_flags) {
52191 - info->fbops->fb_sync = atyfb_sync;
52192 + pax_open_kernel();
52193 + *(void **)&info->fbops->fb_sync = atyfb_sync;
52194 + pax_close_kernel();
52195 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52196 } else {
52197 - info->fbops->fb_sync = NULL;
52198 + pax_open_kernel();
52199 + *(void **)&info->fbops->fb_sync = NULL;
52200 + pax_close_kernel();
52201 info->flags |= FBINFO_HWACCEL_DISABLED;
52202 }
52203
52204 diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52205 index 95ec042..e6affdd 100644
52206 --- a/drivers/video/aty/mach64_cursor.c
52207 +++ b/drivers/video/aty/mach64_cursor.c
52208 @@ -7,6 +7,7 @@
52209 #include <linux/string.h>
52210
52211 #include <asm/io.h>
52212 +#include <asm/pgtable.h>
52213
52214 #ifdef __sparc__
52215 #include <asm/fbio.h>
52216 @@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
52217 info->sprite.buf_align = 16; /* and 64 lines tall. */
52218 info->sprite.flags = FB_PIXMAP_IO;
52219
52220 - info->fbops->fb_cursor = atyfb_cursor;
52221 + pax_open_kernel();
52222 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52223 + pax_close_kernel();
52224
52225 return 0;
52226 }
52227 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52228 index 84a110a..96312c3 100644
52229 --- a/drivers/video/backlight/kb3886_bl.c
52230 +++ b/drivers/video/backlight/kb3886_bl.c
52231 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52232 static unsigned long kb3886bl_flags;
52233 #define KB3886BL_SUSPENDED 0x01
52234
52235 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52236 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52237 {
52238 .ident = "Sahara Touch-iT",
52239 .matches = {
52240 diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52241 index 900aa4e..6d49418 100644
52242 --- a/drivers/video/fb_defio.c
52243 +++ b/drivers/video/fb_defio.c
52244 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52245
52246 BUG_ON(!fbdefio);
52247 mutex_init(&fbdefio->lock);
52248 - info->fbops->fb_mmap = fb_deferred_io_mmap;
52249 + pax_open_kernel();
52250 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52251 + pax_close_kernel();
52252 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52253 INIT_LIST_HEAD(&fbdefio->pagelist);
52254 if (fbdefio->delay == 0) /* set a default of 1 s */
52255 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52256 page->mapping = NULL;
52257 }
52258
52259 - info->fbops->fb_mmap = NULL;
52260 + *(void **)&info->fbops->fb_mmap = NULL;
52261 mutex_destroy(&fbdefio->lock);
52262 }
52263 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52264 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52265 index 7309ac7..be3c49c 100644
52266 --- a/drivers/video/fbmem.c
52267 +++ b/drivers/video/fbmem.c
52268 @@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52269 image->dx += image->width + 8;
52270 }
52271 } else if (rotate == FB_ROTATE_UD) {
52272 - for (x = 0; x < num && image->dx >= 0; x++) {
52273 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52274 info->fbops->fb_imageblit(info, image);
52275 image->dx -= image->width + 8;
52276 }
52277 @@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52278 image->dy += image->height + 8;
52279 }
52280 } else if (rotate == FB_ROTATE_CCW) {
52281 - for (x = 0; x < num && image->dy >= 0; x++) {
52282 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52283 info->fbops->fb_imageblit(info, image);
52284 image->dy -= image->height + 8;
52285 }
52286 @@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52287 return -EFAULT;
52288 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52289 return -EINVAL;
52290 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52291 + if (con2fb.framebuffer >= FB_MAX)
52292 return -EINVAL;
52293 if (!registered_fb[con2fb.framebuffer])
52294 request_module("fb%d", con2fb.framebuffer);
52295 @@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52296 __u32 data;
52297 int err;
52298
52299 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52300 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52301
52302 data = (__u32) (unsigned long) fix->smem_start;
52303 err |= put_user(data, &fix32->smem_start);
52304 diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
52305 index 130708f..cdac1a9 100644
52306 --- a/drivers/video/hyperv_fb.c
52307 +++ b/drivers/video/hyperv_fb.c
52308 @@ -233,7 +233,7 @@ static uint screen_fb_size;
52309 static inline int synthvid_send(struct hv_device *hdev,
52310 struct synthvid_msg *msg)
52311 {
52312 - static atomic64_t request_id = ATOMIC64_INIT(0);
52313 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52314 int ret;
52315
52316 msg->pipe_hdr.type = PIPE_MSG_DATA;
52317 @@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52318
52319 ret = vmbus_sendpacket(hdev->channel, msg,
52320 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52321 - atomic64_inc_return(&request_id),
52322 + atomic64_inc_return_unchecked(&request_id),
52323 VM_PKT_DATA_INBAND, 0);
52324
52325 if (ret)
52326 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
52327 index 7672d2e..b56437f 100644
52328 --- a/drivers/video/i810/i810_accel.c
52329 +++ b/drivers/video/i810/i810_accel.c
52330 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52331 }
52332 }
52333 printk("ringbuffer lockup!!!\n");
52334 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52335 i810_report_error(mmio);
52336 par->dev_flags |= LOCKUP;
52337 info->pixmap.scan_align = 1;
52338 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
52339 index 3c14e43..2630570 100644
52340 --- a/drivers/video/logo/logo_linux_clut224.ppm
52341 +++ b/drivers/video/logo/logo_linux_clut224.ppm
52342 @@ -2,1603 +2,1123 @@ P3
52343 # Standard 224-color Linux logo
52344 80 80
52345 255
52346 - 0 0 0 0 0 0 0 0 0 0 0 0
52347 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 6 6 6 10 10 10 10 10 10
52356 - 10 10 10 6 6 6 6 6 6 6 6 6
52357 - 0 0 0 0 0 0 0 0 0 0 0 0
52358 - 0 0 0 0 0 0 0 0 0 0 0 0
52359 - 0 0 0 0 0 0 0 0 0 0 0 0
52360 - 0 0 0 0 0 0 0 0 0 0 0 0
52361 - 0 0 0 0 0 0 0 0 0 0 0 0
52362 - 0 0 0 0 0 0 0 0 0 0 0 0
52363 - 0 0 0 0 0 0 0 0 0 0 0 0
52364 - 0 0 0 0 0 0 0 0 0 0 0 0
52365 - 0 0 0 0 0 0 0 0 0 0 0 0
52366 - 0 0 0 0 0 0 0 0 0 0 0 0
52367 - 0 0 0 0 0 0 0 0 0 0 0 0
52368 - 0 0 0 0 0 0 0 0 0 0 0 0
52369 - 0 0 0 0 0 0 0 0 0 0 0 0
52370 - 0 0 0 0 0 0 0 0 0 0 0 0
52371 - 0 0 0 0 0 0 0 0 0 0 0 0
52372 - 0 0 0 0 0 0 0 0 0 0 0 0
52373 - 0 0 0 0 0 0 0 0 0 0 0 0
52374 - 0 0 0 6 6 6 10 10 10 14 14 14
52375 - 22 22 22 26 26 26 30 30 30 34 34 34
52376 - 30 30 30 30 30 30 26 26 26 18 18 18
52377 - 14 14 14 10 10 10 6 6 6 0 0 0
52378 - 0 0 0 0 0 0 0 0 0 0 0 0
52379 - 0 0 0 0 0 0 0 0 0 0 0 0
52380 - 0 0 0 0 0 0 0 0 0 0 0 0
52381 - 0 0 0 0 0 0 0 0 0 0 0 0
52382 - 0 0 0 0 0 0 0 0 0 0 0 0
52383 - 0 0 0 0 0 0 0 0 0 0 0 0
52384 - 0 0 0 0 0 0 0 0 0 0 0 0
52385 - 0 0 0 0 0 0 0 0 0 0 0 0
52386 - 0 0 0 0 0 0 0 0 0 0 0 0
52387 - 0 0 0 0 0 1 0 0 1 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 - 6 6 6 14 14 14 26 26 26 42 42 42
52395 - 54 54 54 66 66 66 78 78 78 78 78 78
52396 - 78 78 78 74 74 74 66 66 66 54 54 54
52397 - 42 42 42 26 26 26 18 18 18 10 10 10
52398 - 6 6 6 0 0 0 0 0 0 0 0 0
52399 - 0 0 0 0 0 0 0 0 0 0 0 0
52400 - 0 0 0 0 0 0 0 0 0 0 0 0
52401 - 0 0 0 0 0 0 0 0 0 0 0 0
52402 - 0 0 0 0 0 0 0 0 0 0 0 0
52403 - 0 0 0 0 0 0 0 0 0 0 0 0
52404 - 0 0 0 0 0 0 0 0 0 0 0 0
52405 - 0 0 0 0 0 0 0 0 0 0 0 0
52406 - 0 0 0 0 0 0 0 0 0 0 0 0
52407 - 0 0 1 0 0 0 0 0 0 0 0 0
52408 - 0 0 0 0 0 0 0 0 0 0 0 0
52409 - 0 0 0 0 0 0 0 0 0 0 0 0
52410 - 0 0 0 0 0 0 0 0 0 0 0 0
52411 - 0 0 0 0 0 0 0 0 0 0 0 0
52412 - 0 0 0 0 0 0 0 0 0 0 0 0
52413 - 0 0 0 0 0 0 0 0 0 10 10 10
52414 - 22 22 22 42 42 42 66 66 66 86 86 86
52415 - 66 66 66 38 38 38 38 38 38 22 22 22
52416 - 26 26 26 34 34 34 54 54 54 66 66 66
52417 - 86 86 86 70 70 70 46 46 46 26 26 26
52418 - 14 14 14 6 6 6 0 0 0 0 0 0
52419 - 0 0 0 0 0 0 0 0 0 0 0 0
52420 - 0 0 0 0 0 0 0 0 0 0 0 0
52421 - 0 0 0 0 0 0 0 0 0 0 0 0
52422 - 0 0 0 0 0 0 0 0 0 0 0 0
52423 - 0 0 0 0 0 0 0 0 0 0 0 0
52424 - 0 0 0 0 0 0 0 0 0 0 0 0
52425 - 0 0 0 0 0 0 0 0 0 0 0 0
52426 - 0 0 0 0 0 0 0 0 0 0 0 0
52427 - 0 0 1 0 0 1 0 0 1 0 0 0
52428 - 0 0 0 0 0 0 0 0 0 0 0 0
52429 - 0 0 0 0 0 0 0 0 0 0 0 0
52430 - 0 0 0 0 0 0 0 0 0 0 0 0
52431 - 0 0 0 0 0 0 0 0 0 0 0 0
52432 - 0 0 0 0 0 0 0 0 0 0 0 0
52433 - 0 0 0 0 0 0 10 10 10 26 26 26
52434 - 50 50 50 82 82 82 58 58 58 6 6 6
52435 - 2 2 6 2 2 6 2 2 6 2 2 6
52436 - 2 2 6 2 2 6 2 2 6 2 2 6
52437 - 6 6 6 54 54 54 86 86 86 66 66 66
52438 - 38 38 38 18 18 18 6 6 6 0 0 0
52439 - 0 0 0 0 0 0 0 0 0 0 0 0
52440 - 0 0 0 0 0 0 0 0 0 0 0 0
52441 - 0 0 0 0 0 0 0 0 0 0 0 0
52442 - 0 0 0 0 0 0 0 0 0 0 0 0
52443 - 0 0 0 0 0 0 0 0 0 0 0 0
52444 - 0 0 0 0 0 0 0 0 0 0 0 0
52445 - 0 0 0 0 0 0 0 0 0 0 0 0
52446 - 0 0 0 0 0 0 0 0 0 0 0 0
52447 - 0 0 0 0 0 0 0 0 0 0 0 0
52448 - 0 0 0 0 0 0 0 0 0 0 0 0
52449 - 0 0 0 0 0 0 0 0 0 0 0 0
52450 - 0 0 0 0 0 0 0 0 0 0 0 0
52451 - 0 0 0 0 0 0 0 0 0 0 0 0
52452 - 0 0 0 0 0 0 0 0 0 0 0 0
52453 - 0 0 0 6 6 6 22 22 22 50 50 50
52454 - 78 78 78 34 34 34 2 2 6 2 2 6
52455 - 2 2 6 2 2 6 2 2 6 2 2 6
52456 - 2 2 6 2 2 6 2 2 6 2 2 6
52457 - 2 2 6 2 2 6 6 6 6 70 70 70
52458 - 78 78 78 46 46 46 22 22 22 6 6 6
52459 - 0 0 0 0 0 0 0 0 0 0 0 0
52460 - 0 0 0 0 0 0 0 0 0 0 0 0
52461 - 0 0 0 0 0 0 0 0 0 0 0 0
52462 - 0 0 0 0 0 0 0 0 0 0 0 0
52463 - 0 0 0 0 0 0 0 0 0 0 0 0
52464 - 0 0 0 0 0 0 0 0 0 0 0 0
52465 - 0 0 0 0 0 0 0 0 0 0 0 0
52466 - 0 0 0 0 0 0 0 0 0 0 0 0
52467 - 0 0 1 0 0 1 0 0 1 0 0 0
52468 - 0 0 0 0 0 0 0 0 0 0 0 0
52469 - 0 0 0 0 0 0 0 0 0 0 0 0
52470 - 0 0 0 0 0 0 0 0 0 0 0 0
52471 - 0 0 0 0 0 0 0 0 0 0 0 0
52472 - 0 0 0 0 0 0 0 0 0 0 0 0
52473 - 6 6 6 18 18 18 42 42 42 82 82 82
52474 - 26 26 26 2 2 6 2 2 6 2 2 6
52475 - 2 2 6 2 2 6 2 2 6 2 2 6
52476 - 2 2 6 2 2 6 2 2 6 14 14 14
52477 - 46 46 46 34 34 34 6 6 6 2 2 6
52478 - 42 42 42 78 78 78 42 42 42 18 18 18
52479 - 6 6 6 0 0 0 0 0 0 0 0 0
52480 - 0 0 0 0 0 0 0 0 0 0 0 0
52481 - 0 0 0 0 0 0 0 0 0 0 0 0
52482 - 0 0 0 0 0 0 0 0 0 0 0 0
52483 - 0 0 0 0 0 0 0 0 0 0 0 0
52484 - 0 0 0 0 0 0 0 0 0 0 0 0
52485 - 0 0 0 0 0 0 0 0 0 0 0 0
52486 - 0 0 0 0 0 0 0 0 0 0 0 0
52487 - 0 0 1 0 0 0 0 0 1 0 0 0
52488 - 0 0 0 0 0 0 0 0 0 0 0 0
52489 - 0 0 0 0 0 0 0 0 0 0 0 0
52490 - 0 0 0 0 0 0 0 0 0 0 0 0
52491 - 0 0 0 0 0 0 0 0 0 0 0 0
52492 - 0 0 0 0 0 0 0 0 0 0 0 0
52493 - 10 10 10 30 30 30 66 66 66 58 58 58
52494 - 2 2 6 2 2 6 2 2 6 2 2 6
52495 - 2 2 6 2 2 6 2 2 6 2 2 6
52496 - 2 2 6 2 2 6 2 2 6 26 26 26
52497 - 86 86 86 101 101 101 46 46 46 10 10 10
52498 - 2 2 6 58 58 58 70 70 70 34 34 34
52499 - 10 10 10 0 0 0 0 0 0 0 0 0
52500 - 0 0 0 0 0 0 0 0 0 0 0 0
52501 - 0 0 0 0 0 0 0 0 0 0 0 0
52502 - 0 0 0 0 0 0 0 0 0 0 0 0
52503 - 0 0 0 0 0 0 0 0 0 0 0 0
52504 - 0 0 0 0 0 0 0 0 0 0 0 0
52505 - 0 0 0 0 0 0 0 0 0 0 0 0
52506 - 0 0 0 0 0 0 0 0 0 0 0 0
52507 - 0 0 1 0 0 1 0 0 1 0 0 0
52508 - 0 0 0 0 0 0 0 0 0 0 0 0
52509 - 0 0 0 0 0 0 0 0 0 0 0 0
52510 - 0 0 0 0 0 0 0 0 0 0 0 0
52511 - 0 0 0 0 0 0 0 0 0 0 0 0
52512 - 0 0 0 0 0 0 0 0 0 0 0 0
52513 - 14 14 14 42 42 42 86 86 86 10 10 10
52514 - 2 2 6 2 2 6 2 2 6 2 2 6
52515 - 2 2 6 2 2 6 2 2 6 2 2 6
52516 - 2 2 6 2 2 6 2 2 6 30 30 30
52517 - 94 94 94 94 94 94 58 58 58 26 26 26
52518 - 2 2 6 6 6 6 78 78 78 54 54 54
52519 - 22 22 22 6 6 6 0 0 0 0 0 0
52520 - 0 0 0 0 0 0 0 0 0 0 0 0
52521 - 0 0 0 0 0 0 0 0 0 0 0 0
52522 - 0 0 0 0 0 0 0 0 0 0 0 0
52523 - 0 0 0 0 0 0 0 0 0 0 0 0
52524 - 0 0 0 0 0 0 0 0 0 0 0 0
52525 - 0 0 0 0 0 0 0 0 0 0 0 0
52526 - 0 0 0 0 0 0 0 0 0 0 0 0
52527 - 0 0 0 0 0 0 0 0 0 0 0 0
52528 - 0 0 0 0 0 0 0 0 0 0 0 0
52529 - 0 0 0 0 0 0 0 0 0 0 0 0
52530 - 0 0 0 0 0 0 0 0 0 0 0 0
52531 - 0 0 0 0 0 0 0 0 0 0 0 0
52532 - 0 0 0 0 0 0 0 0 0 6 6 6
52533 - 22 22 22 62 62 62 62 62 62 2 2 6
52534 - 2 2 6 2 2 6 2 2 6 2 2 6
52535 - 2 2 6 2 2 6 2 2 6 2 2 6
52536 - 2 2 6 2 2 6 2 2 6 26 26 26
52537 - 54 54 54 38 38 38 18 18 18 10 10 10
52538 - 2 2 6 2 2 6 34 34 34 82 82 82
52539 - 38 38 38 14 14 14 0 0 0 0 0 0
52540 - 0 0 0 0 0 0 0 0 0 0 0 0
52541 - 0 0 0 0 0 0 0 0 0 0 0 0
52542 - 0 0 0 0 0 0 0 0 0 0 0 0
52543 - 0 0 0 0 0 0 0 0 0 0 0 0
52544 - 0 0 0 0 0 0 0 0 0 0 0 0
52545 - 0 0 0 0 0 0 0 0 0 0 0 0
52546 - 0 0 0 0 0 0 0 0 0 0 0 0
52547 - 0 0 0 0 0 1 0 0 1 0 0 0
52548 - 0 0 0 0 0 0 0 0 0 0 0 0
52549 - 0 0 0 0 0 0 0 0 0 0 0 0
52550 - 0 0 0 0 0 0 0 0 0 0 0 0
52551 - 0 0 0 0 0 0 0 0 0 0 0 0
52552 - 0 0 0 0 0 0 0 0 0 6 6 6
52553 - 30 30 30 78 78 78 30 30 30 2 2 6
52554 - 2 2 6 2 2 6 2 2 6 2 2 6
52555 - 2 2 6 2 2 6 2 2 6 2 2 6
52556 - 2 2 6 2 2 6 2 2 6 10 10 10
52557 - 10 10 10 2 2 6 2 2 6 2 2 6
52558 - 2 2 6 2 2 6 2 2 6 78 78 78
52559 - 50 50 50 18 18 18 6 6 6 0 0 0
52560 - 0 0 0 0 0 0 0 0 0 0 0 0
52561 - 0 0 0 0 0 0 0 0 0 0 0 0
52562 - 0 0 0 0 0 0 0 0 0 0 0 0
52563 - 0 0 0 0 0 0 0 0 0 0 0 0
52564 - 0 0 0 0 0 0 0 0 0 0 0 0
52565 - 0 0 0 0 0 0 0 0 0 0 0 0
52566 - 0 0 0 0 0 0 0 0 0 0 0 0
52567 - 0 0 1 0 0 0 0 0 0 0 0 0
52568 - 0 0 0 0 0 0 0 0 0 0 0 0
52569 - 0 0 0 0 0 0 0 0 0 0 0 0
52570 - 0 0 0 0 0 0 0 0 0 0 0 0
52571 - 0 0 0 0 0 0 0 0 0 0 0 0
52572 - 0 0 0 0 0 0 0 0 0 10 10 10
52573 - 38 38 38 86 86 86 14 14 14 2 2 6
52574 - 2 2 6 2 2 6 2 2 6 2 2 6
52575 - 2 2 6 2 2 6 2 2 6 2 2 6
52576 - 2 2 6 2 2 6 2 2 6 2 2 6
52577 - 2 2 6 2 2 6 2 2 6 2 2 6
52578 - 2 2 6 2 2 6 2 2 6 54 54 54
52579 - 66 66 66 26 26 26 6 6 6 0 0 0
52580 - 0 0 0 0 0 0 0 0 0 0 0 0
52581 - 0 0 0 0 0 0 0 0 0 0 0 0
52582 - 0 0 0 0 0 0 0 0 0 0 0 0
52583 - 0 0 0 0 0 0 0 0 0 0 0 0
52584 - 0 0 0 0 0 0 0 0 0 0 0 0
52585 - 0 0 0 0 0 0 0 0 0 0 0 0
52586 - 0 0 0 0 0 0 0 0 0 0 0 0
52587 - 0 0 0 0 0 1 0 0 1 0 0 0
52588 - 0 0 0 0 0 0 0 0 0 0 0 0
52589 - 0 0 0 0 0 0 0 0 0 0 0 0
52590 - 0 0 0 0 0 0 0 0 0 0 0 0
52591 - 0 0 0 0 0 0 0 0 0 0 0 0
52592 - 0 0 0 0 0 0 0 0 0 14 14 14
52593 - 42 42 42 82 82 82 2 2 6 2 2 6
52594 - 2 2 6 6 6 6 10 10 10 2 2 6
52595 - 2 2 6 2 2 6 2 2 6 2 2 6
52596 - 2 2 6 2 2 6 2 2 6 6 6 6
52597 - 14 14 14 10 10 10 2 2 6 2 2 6
52598 - 2 2 6 2 2 6 2 2 6 18 18 18
52599 - 82 82 82 34 34 34 10 10 10 0 0 0
52600 - 0 0 0 0 0 0 0 0 0 0 0 0
52601 - 0 0 0 0 0 0 0 0 0 0 0 0
52602 - 0 0 0 0 0 0 0 0 0 0 0 0
52603 - 0 0 0 0 0 0 0 0 0 0 0 0
52604 - 0 0 0 0 0 0 0 0 0 0 0 0
52605 - 0 0 0 0 0 0 0 0 0 0 0 0
52606 - 0 0 0 0 0 0 0 0 0 0 0 0
52607 - 0 0 1 0 0 0 0 0 0 0 0 0
52608 - 0 0 0 0 0 0 0 0 0 0 0 0
52609 - 0 0 0 0 0 0 0 0 0 0 0 0
52610 - 0 0 0 0 0 0 0 0 0 0 0 0
52611 - 0 0 0 0 0 0 0 0 0 0 0 0
52612 - 0 0 0 0 0 0 0 0 0 14 14 14
52613 - 46 46 46 86 86 86 2 2 6 2 2 6
52614 - 6 6 6 6 6 6 22 22 22 34 34 34
52615 - 6 6 6 2 2 6 2 2 6 2 2 6
52616 - 2 2 6 2 2 6 18 18 18 34 34 34
52617 - 10 10 10 50 50 50 22 22 22 2 2 6
52618 - 2 2 6 2 2 6 2 2 6 10 10 10
52619 - 86 86 86 42 42 42 14 14 14 0 0 0
52620 - 0 0 0 0 0 0 0 0 0 0 0 0
52621 - 0 0 0 0 0 0 0 0 0 0 0 0
52622 - 0 0 0 0 0 0 0 0 0 0 0 0
52623 - 0 0 0 0 0 0 0 0 0 0 0 0
52624 - 0 0 0 0 0 0 0 0 0 0 0 0
52625 - 0 0 0 0 0 0 0 0 0 0 0 0
52626 - 0 0 0 0 0 0 0 0 0 0 0 0
52627 - 0 0 1 0 0 1 0 0 1 0 0 0
52628 - 0 0 0 0 0 0 0 0 0 0 0 0
52629 - 0 0 0 0 0 0 0 0 0 0 0 0
52630 - 0 0 0 0 0 0 0 0 0 0 0 0
52631 - 0 0 0 0 0 0 0 0 0 0 0 0
52632 - 0 0 0 0 0 0 0 0 0 14 14 14
52633 - 46 46 46 86 86 86 2 2 6 2 2 6
52634 - 38 38 38 116 116 116 94 94 94 22 22 22
52635 - 22 22 22 2 2 6 2 2 6 2 2 6
52636 - 14 14 14 86 86 86 138 138 138 162 162 162
52637 -154 154 154 38 38 38 26 26 26 6 6 6
52638 - 2 2 6 2 2 6 2 2 6 2 2 6
52639 - 86 86 86 46 46 46 14 14 14 0 0 0
52640 - 0 0 0 0 0 0 0 0 0 0 0 0
52641 - 0 0 0 0 0 0 0 0 0 0 0 0
52642 - 0 0 0 0 0 0 0 0 0 0 0 0
52643 - 0 0 0 0 0 0 0 0 0 0 0 0
52644 - 0 0 0 0 0 0 0 0 0 0 0 0
52645 - 0 0 0 0 0 0 0 0 0 0 0 0
52646 - 0 0 0 0 0 0 0 0 0 0 0 0
52647 - 0 0 0 0 0 0 0 0 0 0 0 0
52648 - 0 0 0 0 0 0 0 0 0 0 0 0
52649 - 0 0 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 14 14 14
52653 - 46 46 46 86 86 86 2 2 6 14 14 14
52654 -134 134 134 198 198 198 195 195 195 116 116 116
52655 - 10 10 10 2 2 6 2 2 6 6 6 6
52656 -101 98 89 187 187 187 210 210 210 218 218 218
52657 -214 214 214 134 134 134 14 14 14 6 6 6
52658 - 2 2 6 2 2 6 2 2 6 2 2 6
52659 - 86 86 86 50 50 50 18 18 18 6 6 6
52660 - 0 0 0 0 0 0 0 0 0 0 0 0
52661 - 0 0 0 0 0 0 0 0 0 0 0 0
52662 - 0 0 0 0 0 0 0 0 0 0 0 0
52663 - 0 0 0 0 0 0 0 0 0 0 0 0
52664 - 0 0 0 0 0 0 0 0 0 0 0 0
52665 - 0 0 0 0 0 0 0 0 0 0 0 0
52666 - 0 0 0 0 0 0 0 0 1 0 0 0
52667 - 0 0 1 0 0 1 0 0 1 0 0 0
52668 - 0 0 0 0 0 0 0 0 0 0 0 0
52669 - 0 0 0 0 0 0 0 0 0 0 0 0
52670 - 0 0 0 0 0 0 0 0 0 0 0 0
52671 - 0 0 0 0 0 0 0 0 0 0 0 0
52672 - 0 0 0 0 0 0 0 0 0 14 14 14
52673 - 46 46 46 86 86 86 2 2 6 54 54 54
52674 -218 218 218 195 195 195 226 226 226 246 246 246
52675 - 58 58 58 2 2 6 2 2 6 30 30 30
52676 -210 210 210 253 253 253 174 174 174 123 123 123
52677 -221 221 221 234 234 234 74 74 74 2 2 6
52678 - 2 2 6 2 2 6 2 2 6 2 2 6
52679 - 70 70 70 58 58 58 22 22 22 6 6 6
52680 - 0 0 0 0 0 0 0 0 0 0 0 0
52681 - 0 0 0 0 0 0 0 0 0 0 0 0
52682 - 0 0 0 0 0 0 0 0 0 0 0 0
52683 - 0 0 0 0 0 0 0 0 0 0 0 0
52684 - 0 0 0 0 0 0 0 0 0 0 0 0
52685 - 0 0 0 0 0 0 0 0 0 0 0 0
52686 - 0 0 0 0 0 0 0 0 0 0 0 0
52687 - 0 0 0 0 0 0 0 0 0 0 0 0
52688 - 0 0 0 0 0 0 0 0 0 0 0 0
52689 - 0 0 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 14 14 14
52693 - 46 46 46 82 82 82 2 2 6 106 106 106
52694 -170 170 170 26 26 26 86 86 86 226 226 226
52695 -123 123 123 10 10 10 14 14 14 46 46 46
52696 -231 231 231 190 190 190 6 6 6 70 70 70
52697 - 90 90 90 238 238 238 158 158 158 2 2 6
52698 - 2 2 6 2 2 6 2 2 6 2 2 6
52699 - 70 70 70 58 58 58 22 22 22 6 6 6
52700 - 0 0 0 0 0 0 0 0 0 0 0 0
52701 - 0 0 0 0 0 0 0 0 0 0 0 0
52702 - 0 0 0 0 0 0 0 0 0 0 0 0
52703 - 0 0 0 0 0 0 0 0 0 0 0 0
52704 - 0 0 0 0 0 0 0 0 0 0 0 0
52705 - 0 0 0 0 0 0 0 0 0 0 0 0
52706 - 0 0 0 0 0 0 0 0 1 0 0 0
52707 - 0 0 1 0 0 1 0 0 1 0 0 0
52708 - 0 0 0 0 0 0 0 0 0 0 0 0
52709 - 0 0 0 0 0 0 0 0 0 0 0 0
52710 - 0 0 0 0 0 0 0 0 0 0 0 0
52711 - 0 0 0 0 0 0 0 0 0 0 0 0
52712 - 0 0 0 0 0 0 0 0 0 14 14 14
52713 - 42 42 42 86 86 86 6 6 6 116 116 116
52714 -106 106 106 6 6 6 70 70 70 149 149 149
52715 -128 128 128 18 18 18 38 38 38 54 54 54
52716 -221 221 221 106 106 106 2 2 6 14 14 14
52717 - 46 46 46 190 190 190 198 198 198 2 2 6
52718 - 2 2 6 2 2 6 2 2 6 2 2 6
52719 - 74 74 74 62 62 62 22 22 22 6 6 6
52720 - 0 0 0 0 0 0 0 0 0 0 0 0
52721 - 0 0 0 0 0 0 0 0 0 0 0 0
52722 - 0 0 0 0 0 0 0 0 0 0 0 0
52723 - 0 0 0 0 0 0 0 0 0 0 0 0
52724 - 0 0 0 0 0 0 0 0 0 0 0 0
52725 - 0 0 0 0 0 0 0 0 0 0 0 0
52726 - 0 0 0 0 0 0 0 0 1 0 0 0
52727 - 0 0 1 0 0 0 0 0 1 0 0 0
52728 - 0 0 0 0 0 0 0 0 0 0 0 0
52729 - 0 0 0 0 0 0 0 0 0 0 0 0
52730 - 0 0 0 0 0 0 0 0 0 0 0 0
52731 - 0 0 0 0 0 0 0 0 0 0 0 0
52732 - 0 0 0 0 0 0 0 0 0 14 14 14
52733 - 42 42 42 94 94 94 14 14 14 101 101 101
52734 -128 128 128 2 2 6 18 18 18 116 116 116
52735 -118 98 46 121 92 8 121 92 8 98 78 10
52736 -162 162 162 106 106 106 2 2 6 2 2 6
52737 - 2 2 6 195 195 195 195 195 195 6 6 6
52738 - 2 2 6 2 2 6 2 2 6 2 2 6
52739 - 74 74 74 62 62 62 22 22 22 6 6 6
52740 - 0 0 0 0 0 0 0 0 0 0 0 0
52741 - 0 0 0 0 0 0 0 0 0 0 0 0
52742 - 0 0 0 0 0 0 0 0 0 0 0 0
52743 - 0 0 0 0 0 0 0 0 0 0 0 0
52744 - 0 0 0 0 0 0 0 0 0 0 0 0
52745 - 0 0 0 0 0 0 0 0 0 0 0 0
52746 - 0 0 0 0 0 0 0 0 1 0 0 1
52747 - 0 0 1 0 0 0 0 0 1 0 0 0
52748 - 0 0 0 0 0 0 0 0 0 0 0 0
52749 - 0 0 0 0 0 0 0 0 0 0 0 0
52750 - 0 0 0 0 0 0 0 0 0 0 0 0
52751 - 0 0 0 0 0 0 0 0 0 0 0 0
52752 - 0 0 0 0 0 0 0 0 0 10 10 10
52753 - 38 38 38 90 90 90 14 14 14 58 58 58
52754 -210 210 210 26 26 26 54 38 6 154 114 10
52755 -226 170 11 236 186 11 225 175 15 184 144 12
52756 -215 174 15 175 146 61 37 26 9 2 2 6
52757 - 70 70 70 246 246 246 138 138 138 2 2 6
52758 - 2 2 6 2 2 6 2 2 6 2 2 6
52759 - 70 70 70 66 66 66 26 26 26 6 6 6
52760 - 0 0 0 0 0 0 0 0 0 0 0 0
52761 - 0 0 0 0 0 0 0 0 0 0 0 0
52762 - 0 0 0 0 0 0 0 0 0 0 0 0
52763 - 0 0 0 0 0 0 0 0 0 0 0 0
52764 - 0 0 0 0 0 0 0 0 0 0 0 0
52765 - 0 0 0 0 0 0 0 0 0 0 0 0
52766 - 0 0 0 0 0 0 0 0 0 0 0 0
52767 - 0 0 0 0 0 0 0 0 0 0 0 0
52768 - 0 0 0 0 0 0 0 0 0 0 0 0
52769 - 0 0 0 0 0 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 - 38 38 38 86 86 86 14 14 14 10 10 10
52774 -195 195 195 188 164 115 192 133 9 225 175 15
52775 -239 182 13 234 190 10 232 195 16 232 200 30
52776 -245 207 45 241 208 19 232 195 16 184 144 12
52777 -218 194 134 211 206 186 42 42 42 2 2 6
52778 - 2 2 6 2 2 6 2 2 6 2 2 6
52779 - 50 50 50 74 74 74 30 30 30 6 6 6
52780 - 0 0 0 0 0 0 0 0 0 0 0 0
52781 - 0 0 0 0 0 0 0 0 0 0 0 0
52782 - 0 0 0 0 0 0 0 0 0 0 0 0
52783 - 0 0 0 0 0 0 0 0 0 0 0 0
52784 - 0 0 0 0 0 0 0 0 0 0 0 0
52785 - 0 0 0 0 0 0 0 0 0 0 0 0
52786 - 0 0 0 0 0 0 0 0 0 0 0 0
52787 - 0 0 0 0 0 0 0 0 0 0 0 0
52788 - 0 0 0 0 0 0 0 0 0 0 0 0
52789 - 0 0 0 0 0 0 0 0 0 0 0 0
52790 - 0 0 0 0 0 0 0 0 0 0 0 0
52791 - 0 0 0 0 0 0 0 0 0 0 0 0
52792 - 0 0 0 0 0 0 0 0 0 10 10 10
52793 - 34 34 34 86 86 86 14 14 14 2 2 6
52794 -121 87 25 192 133 9 219 162 10 239 182 13
52795 -236 186 11 232 195 16 241 208 19 244 214 54
52796 -246 218 60 246 218 38 246 215 20 241 208 19
52797 -241 208 19 226 184 13 121 87 25 2 2 6
52798 - 2 2 6 2 2 6 2 2 6 2 2 6
52799 - 50 50 50 82 82 82 34 34 34 10 10 10
52800 - 0 0 0 0 0 0 0 0 0 0 0 0
52801 - 0 0 0 0 0 0 0 0 0 0 0 0
52802 - 0 0 0 0 0 0 0 0 0 0 0 0
52803 - 0 0 0 0 0 0 0 0 0 0 0 0
52804 - 0 0 0 0 0 0 0 0 0 0 0 0
52805 - 0 0 0 0 0 0 0 0 0 0 0 0
52806 - 0 0 0 0 0 0 0 0 0 0 0 0
52807 - 0 0 0 0 0 0 0 0 0 0 0 0
52808 - 0 0 0 0 0 0 0 0 0 0 0 0
52809 - 0 0 0 0 0 0 0 0 0 0 0 0
52810 - 0 0 0 0 0 0 0 0 0 0 0 0
52811 - 0 0 0 0 0 0 0 0 0 0 0 0
52812 - 0 0 0 0 0 0 0 0 0 10 10 10
52813 - 34 34 34 82 82 82 30 30 30 61 42 6
52814 -180 123 7 206 145 10 230 174 11 239 182 13
52815 -234 190 10 238 202 15 241 208 19 246 218 74
52816 -246 218 38 246 215 20 246 215 20 246 215 20
52817 -226 184 13 215 174 15 184 144 12 6 6 6
52818 - 2 2 6 2 2 6 2 2 6 2 2 6
52819 - 26 26 26 94 94 94 42 42 42 14 14 14
52820 - 0 0 0 0 0 0 0 0 0 0 0 0
52821 - 0 0 0 0 0 0 0 0 0 0 0 0
52822 - 0 0 0 0 0 0 0 0 0 0 0 0
52823 - 0 0 0 0 0 0 0 0 0 0 0 0
52824 - 0 0 0 0 0 0 0 0 0 0 0 0
52825 - 0 0 0 0 0 0 0 0 0 0 0 0
52826 - 0 0 0 0 0 0 0 0 0 0 0 0
52827 - 0 0 0 0 0 0 0 0 0 0 0 0
52828 - 0 0 0 0 0 0 0 0 0 0 0 0
52829 - 0 0 0 0 0 0 0 0 0 0 0 0
52830 - 0 0 0 0 0 0 0 0 0 0 0 0
52831 - 0 0 0 0 0 0 0 0 0 0 0 0
52832 - 0 0 0 0 0 0 0 0 0 10 10 10
52833 - 30 30 30 78 78 78 50 50 50 104 69 6
52834 -192 133 9 216 158 10 236 178 12 236 186 11
52835 -232 195 16 241 208 19 244 214 54 245 215 43
52836 -246 215 20 246 215 20 241 208 19 198 155 10
52837 -200 144 11 216 158 10 156 118 10 2 2 6
52838 - 2 2 6 2 2 6 2 2 6 2 2 6
52839 - 6 6 6 90 90 90 54 54 54 18 18 18
52840 - 6 6 6 0 0 0 0 0 0 0 0 0
52841 - 0 0 0 0 0 0 0 0 0 0 0 0
52842 - 0 0 0 0 0 0 0 0 0 0 0 0
52843 - 0 0 0 0 0 0 0 0 0 0 0 0
52844 - 0 0 0 0 0 0 0 0 0 0 0 0
52845 - 0 0 0 0 0 0 0 0 0 0 0 0
52846 - 0 0 0 0 0 0 0 0 0 0 0 0
52847 - 0 0 0 0 0 0 0 0 0 0 0 0
52848 - 0 0 0 0 0 0 0 0 0 0 0 0
52849 - 0 0 0 0 0 0 0 0 0 0 0 0
52850 - 0 0 0 0 0 0 0 0 0 0 0 0
52851 - 0 0 0 0 0 0 0 0 0 0 0 0
52852 - 0 0 0 0 0 0 0 0 0 10 10 10
52853 - 30 30 30 78 78 78 46 46 46 22 22 22
52854 -137 92 6 210 162 10 239 182 13 238 190 10
52855 -238 202 15 241 208 19 246 215 20 246 215 20
52856 -241 208 19 203 166 17 185 133 11 210 150 10
52857 -216 158 10 210 150 10 102 78 10 2 2 6
52858 - 6 6 6 54 54 54 14 14 14 2 2 6
52859 - 2 2 6 62 62 62 74 74 74 30 30 30
52860 - 10 10 10 0 0 0 0 0 0 0 0 0
52861 - 0 0 0 0 0 0 0 0 0 0 0 0
52862 - 0 0 0 0 0 0 0 0 0 0 0 0
52863 - 0 0 0 0 0 0 0 0 0 0 0 0
52864 - 0 0 0 0 0 0 0 0 0 0 0 0
52865 - 0 0 0 0 0 0 0 0 0 0 0 0
52866 - 0 0 0 0 0 0 0 0 0 0 0 0
52867 - 0 0 0 0 0 0 0 0 0 0 0 0
52868 - 0 0 0 0 0 0 0 0 0 0 0 0
52869 - 0 0 0 0 0 0 0 0 0 0 0 0
52870 - 0 0 0 0 0 0 0 0 0 0 0 0
52871 - 0 0 0 0 0 0 0 0 0 0 0 0
52872 - 0 0 0 0 0 0 0 0 0 10 10 10
52873 - 34 34 34 78 78 78 50 50 50 6 6 6
52874 - 94 70 30 139 102 15 190 146 13 226 184 13
52875 -232 200 30 232 195 16 215 174 15 190 146 13
52876 -168 122 10 192 133 9 210 150 10 213 154 11
52877 -202 150 34 182 157 106 101 98 89 2 2 6
52878 - 2 2 6 78 78 78 116 116 116 58 58 58
52879 - 2 2 6 22 22 22 90 90 90 46 46 46
52880 - 18 18 18 6 6 6 0 0 0 0 0 0
52881 - 0 0 0 0 0 0 0 0 0 0 0 0
52882 - 0 0 0 0 0 0 0 0 0 0 0 0
52883 - 0 0 0 0 0 0 0 0 0 0 0 0
52884 - 0 0 0 0 0 0 0 0 0 0 0 0
52885 - 0 0 0 0 0 0 0 0 0 0 0 0
52886 - 0 0 0 0 0 0 0 0 0 0 0 0
52887 - 0 0 0 0 0 0 0 0 0 0 0 0
52888 - 0 0 0 0 0 0 0 0 0 0 0 0
52889 - 0 0 0 0 0 0 0 0 0 0 0 0
52890 - 0 0 0 0 0 0 0 0 0 0 0 0
52891 - 0 0 0 0 0 0 0 0 0 0 0 0
52892 - 0 0 0 0 0 0 0 0 0 10 10 10
52893 - 38 38 38 86 86 86 50 50 50 6 6 6
52894 -128 128 128 174 154 114 156 107 11 168 122 10
52895 -198 155 10 184 144 12 197 138 11 200 144 11
52896 -206 145 10 206 145 10 197 138 11 188 164 115
52897 -195 195 195 198 198 198 174 174 174 14 14 14
52898 - 2 2 6 22 22 22 116 116 116 116 116 116
52899 - 22 22 22 2 2 6 74 74 74 70 70 70
52900 - 30 30 30 10 10 10 0 0 0 0 0 0
52901 - 0 0 0 0 0 0 0 0 0 0 0 0
52902 - 0 0 0 0 0 0 0 0 0 0 0 0
52903 - 0 0 0 0 0 0 0 0 0 0 0 0
52904 - 0 0 0 0 0 0 0 0 0 0 0 0
52905 - 0 0 0 0 0 0 0 0 0 0 0 0
52906 - 0 0 0 0 0 0 0 0 0 0 0 0
52907 - 0 0 0 0 0 0 0 0 0 0 0 0
52908 - 0 0 0 0 0 0 0 0 0 0 0 0
52909 - 0 0 0 0 0 0 0 0 0 0 0 0
52910 - 0 0 0 0 0 0 0 0 0 0 0 0
52911 - 0 0 0 0 0 0 0 0 0 0 0 0
52912 - 0 0 0 0 0 0 6 6 6 18 18 18
52913 - 50 50 50 101 101 101 26 26 26 10 10 10
52914 -138 138 138 190 190 190 174 154 114 156 107 11
52915 -197 138 11 200 144 11 197 138 11 192 133 9
52916 -180 123 7 190 142 34 190 178 144 187 187 187
52917 -202 202 202 221 221 221 214 214 214 66 66 66
52918 - 2 2 6 2 2 6 50 50 50 62 62 62
52919 - 6 6 6 2 2 6 10 10 10 90 90 90
52920 - 50 50 50 18 18 18 6 6 6 0 0 0
52921 - 0 0 0 0 0 0 0 0 0 0 0 0
52922 - 0 0 0 0 0 0 0 0 0 0 0 0
52923 - 0 0 0 0 0 0 0 0 0 0 0 0
52924 - 0 0 0 0 0 0 0 0 0 0 0 0
52925 - 0 0 0 0 0 0 0 0 0 0 0 0
52926 - 0 0 0 0 0 0 0 0 0 0 0 0
52927 - 0 0 0 0 0 0 0 0 0 0 0 0
52928 - 0 0 0 0 0 0 0 0 0 0 0 0
52929 - 0 0 0 0 0 0 0 0 0 0 0 0
52930 - 0 0 0 0 0 0 0 0 0 0 0 0
52931 - 0 0 0 0 0 0 0 0 0 0 0 0
52932 - 0 0 0 0 0 0 10 10 10 34 34 34
52933 - 74 74 74 74 74 74 2 2 6 6 6 6
52934 -144 144 144 198 198 198 190 190 190 178 166 146
52935 -154 121 60 156 107 11 156 107 11 168 124 44
52936 -174 154 114 187 187 187 190 190 190 210 210 210
52937 -246 246 246 253 253 253 253 253 253 182 182 182
52938 - 6 6 6 2 2 6 2 2 6 2 2 6
52939 - 2 2 6 2 2 6 2 2 6 62 62 62
52940 - 74 74 74 34 34 34 14 14 14 0 0 0
52941 - 0 0 0 0 0 0 0 0 0 0 0 0
52942 - 0 0 0 0 0 0 0 0 0 0 0 0
52943 - 0 0 0 0 0 0 0 0 0 0 0 0
52944 - 0 0 0 0 0 0 0 0 0 0 0 0
52945 - 0 0 0 0 0 0 0 0 0 0 0 0
52946 - 0 0 0 0 0 0 0 0 0 0 0 0
52947 - 0 0 0 0 0 0 0 0 0 0 0 0
52948 - 0 0 0 0 0 0 0 0 0 0 0 0
52949 - 0 0 0 0 0 0 0 0 0 0 0 0
52950 - 0 0 0 0 0 0 0 0 0 0 0 0
52951 - 0 0 0 0 0 0 0 0 0 0 0 0
52952 - 0 0 0 10 10 10 22 22 22 54 54 54
52953 - 94 94 94 18 18 18 2 2 6 46 46 46
52954 -234 234 234 221 221 221 190 190 190 190 190 190
52955 -190 190 190 187 187 187 187 187 187 190 190 190
52956 -190 190 190 195 195 195 214 214 214 242 242 242
52957 -253 253 253 253 253 253 253 253 253 253 253 253
52958 - 82 82 82 2 2 6 2 2 6 2 2 6
52959 - 2 2 6 2 2 6 2 2 6 14 14 14
52960 - 86 86 86 54 54 54 22 22 22 6 6 6
52961 - 0 0 0 0 0 0 0 0 0 0 0 0
52962 - 0 0 0 0 0 0 0 0 0 0 0 0
52963 - 0 0 0 0 0 0 0 0 0 0 0 0
52964 - 0 0 0 0 0 0 0 0 0 0 0 0
52965 - 0 0 0 0 0 0 0 0 0 0 0 0
52966 - 0 0 0 0 0 0 0 0 0 0 0 0
52967 - 0 0 0 0 0 0 0 0 0 0 0 0
52968 - 0 0 0 0 0 0 0 0 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 - 6 6 6 18 18 18 46 46 46 90 90 90
52973 - 46 46 46 18 18 18 6 6 6 182 182 182
52974 -253 253 253 246 246 246 206 206 206 190 190 190
52975 -190 190 190 190 190 190 190 190 190 190 190 190
52976 -206 206 206 231 231 231 250 250 250 253 253 253
52977 -253 253 253 253 253 253 253 253 253 253 253 253
52978 -202 202 202 14 14 14 2 2 6 2 2 6
52979 - 2 2 6 2 2 6 2 2 6 2 2 6
52980 - 42 42 42 86 86 86 42 42 42 18 18 18
52981 - 6 6 6 0 0 0 0 0 0 0 0 0
52982 - 0 0 0 0 0 0 0 0 0 0 0 0
52983 - 0 0 0 0 0 0 0 0 0 0 0 0
52984 - 0 0 0 0 0 0 0 0 0 0 0 0
52985 - 0 0 0 0 0 0 0 0 0 0 0 0
52986 - 0 0 0 0 0 0 0 0 0 0 0 0
52987 - 0 0 0 0 0 0 0 0 0 0 0 0
52988 - 0 0 0 0 0 0 0 0 0 0 0 0
52989 - 0 0 0 0 0 0 0 0 0 0 0 0
52990 - 0 0 0 0 0 0 0 0 0 0 0 0
52991 - 0 0 0 0 0 0 0 0 0 6 6 6
52992 - 14 14 14 38 38 38 74 74 74 66 66 66
52993 - 2 2 6 6 6 6 90 90 90 250 250 250
52994 -253 253 253 253 253 253 238 238 238 198 198 198
52995 -190 190 190 190 190 190 195 195 195 221 221 221
52996 -246 246 246 253 253 253 253 253 253 253 253 253
52997 -253 253 253 253 253 253 253 253 253 253 253 253
52998 -253 253 253 82 82 82 2 2 6 2 2 6
52999 - 2 2 6 2 2 6 2 2 6 2 2 6
53000 - 2 2 6 78 78 78 70 70 70 34 34 34
53001 - 14 14 14 6 6 6 0 0 0 0 0 0
53002 - 0 0 0 0 0 0 0 0 0 0 0 0
53003 - 0 0 0 0 0 0 0 0 0 0 0 0
53004 - 0 0 0 0 0 0 0 0 0 0 0 0
53005 - 0 0 0 0 0 0 0 0 0 0 0 0
53006 - 0 0 0 0 0 0 0 0 0 0 0 0
53007 - 0 0 0 0 0 0 0 0 0 0 0 0
53008 - 0 0 0 0 0 0 0 0 0 0 0 0
53009 - 0 0 0 0 0 0 0 0 0 0 0 0
53010 - 0 0 0 0 0 0 0 0 0 0 0 0
53011 - 0 0 0 0 0 0 0 0 0 14 14 14
53012 - 34 34 34 66 66 66 78 78 78 6 6 6
53013 - 2 2 6 18 18 18 218 218 218 253 253 253
53014 -253 253 253 253 253 253 253 253 253 246 246 246
53015 -226 226 226 231 231 231 246 246 246 253 253 253
53016 -253 253 253 253 253 253 253 253 253 253 253 253
53017 -253 253 253 253 253 253 253 253 253 253 253 253
53018 -253 253 253 178 178 178 2 2 6 2 2 6
53019 - 2 2 6 2 2 6 2 2 6 2 2 6
53020 - 2 2 6 18 18 18 90 90 90 62 62 62
53021 - 30 30 30 10 10 10 0 0 0 0 0 0
53022 - 0 0 0 0 0 0 0 0 0 0 0 0
53023 - 0 0 0 0 0 0 0 0 0 0 0 0
53024 - 0 0 0 0 0 0 0 0 0 0 0 0
53025 - 0 0 0 0 0 0 0 0 0 0 0 0
53026 - 0 0 0 0 0 0 0 0 0 0 0 0
53027 - 0 0 0 0 0 0 0 0 0 0 0 0
53028 - 0 0 0 0 0 0 0 0 0 0 0 0
53029 - 0 0 0 0 0 0 0 0 0 0 0 0
53030 - 0 0 0 0 0 0 0 0 0 0 0 0
53031 - 0 0 0 0 0 0 10 10 10 26 26 26
53032 - 58 58 58 90 90 90 18 18 18 2 2 6
53033 - 2 2 6 110 110 110 253 253 253 253 253 253
53034 -253 253 253 253 253 253 253 253 253 253 253 253
53035 -250 250 250 253 253 253 253 253 253 253 253 253
53036 -253 253 253 253 253 253 253 253 253 253 253 253
53037 -253 253 253 253 253 253 253 253 253 253 253 253
53038 -253 253 253 231 231 231 18 18 18 2 2 6
53039 - 2 2 6 2 2 6 2 2 6 2 2 6
53040 - 2 2 6 2 2 6 18 18 18 94 94 94
53041 - 54 54 54 26 26 26 10 10 10 0 0 0
53042 - 0 0 0 0 0 0 0 0 0 0 0 0
53043 - 0 0 0 0 0 0 0 0 0 0 0 0
53044 - 0 0 0 0 0 0 0 0 0 0 0 0
53045 - 0 0 0 0 0 0 0 0 0 0 0 0
53046 - 0 0 0 0 0 0 0 0 0 0 0 0
53047 - 0 0 0 0 0 0 0 0 0 0 0 0
53048 - 0 0 0 0 0 0 0 0 0 0 0 0
53049 - 0 0 0 0 0 0 0 0 0 0 0 0
53050 - 0 0 0 0 0 0 0 0 0 0 0 0
53051 - 0 0 0 6 6 6 22 22 22 50 50 50
53052 - 90 90 90 26 26 26 2 2 6 2 2 6
53053 - 14 14 14 195 195 195 250 250 250 253 253 253
53054 -253 253 253 253 253 253 253 253 253 253 253 253
53055 -253 253 253 253 253 253 253 253 253 253 253 253
53056 -253 253 253 253 253 253 253 253 253 253 253 253
53057 -253 253 253 253 253 253 253 253 253 253 253 253
53058 -250 250 250 242 242 242 54 54 54 2 2 6
53059 - 2 2 6 2 2 6 2 2 6 2 2 6
53060 - 2 2 6 2 2 6 2 2 6 38 38 38
53061 - 86 86 86 50 50 50 22 22 22 6 6 6
53062 - 0 0 0 0 0 0 0 0 0 0 0 0
53063 - 0 0 0 0 0 0 0 0 0 0 0 0
53064 - 0 0 0 0 0 0 0 0 0 0 0 0
53065 - 0 0 0 0 0 0 0 0 0 0 0 0
53066 - 0 0 0 0 0 0 0 0 0 0 0 0
53067 - 0 0 0 0 0 0 0 0 0 0 0 0
53068 - 0 0 0 0 0 0 0 0 0 0 0 0
53069 - 0 0 0 0 0 0 0 0 0 0 0 0
53070 - 0 0 0 0 0 0 0 0 0 0 0 0
53071 - 6 6 6 14 14 14 38 38 38 82 82 82
53072 - 34 34 34 2 2 6 2 2 6 2 2 6
53073 - 42 42 42 195 195 195 246 246 246 253 253 253
53074 -253 253 253 253 253 253 253 253 253 250 250 250
53075 -242 242 242 242 242 242 250 250 250 253 253 253
53076 -253 253 253 253 253 253 253 253 253 253 253 253
53077 -253 253 253 250 250 250 246 246 246 238 238 238
53078 -226 226 226 231 231 231 101 101 101 6 6 6
53079 - 2 2 6 2 2 6 2 2 6 2 2 6
53080 - 2 2 6 2 2 6 2 2 6 2 2 6
53081 - 38 38 38 82 82 82 42 42 42 14 14 14
53082 - 6 6 6 0 0 0 0 0 0 0 0 0
53083 - 0 0 0 0 0 0 0 0 0 0 0 0
53084 - 0 0 0 0 0 0 0 0 0 0 0 0
53085 - 0 0 0 0 0 0 0 0 0 0 0 0
53086 - 0 0 0 0 0 0 0 0 0 0 0 0
53087 - 0 0 0 0 0 0 0 0 0 0 0 0
53088 - 0 0 0 0 0 0 0 0 0 0 0 0
53089 - 0 0 0 0 0 0 0 0 0 0 0 0
53090 - 0 0 0 0 0 0 0 0 0 0 0 0
53091 - 10 10 10 26 26 26 62 62 62 66 66 66
53092 - 2 2 6 2 2 6 2 2 6 6 6 6
53093 - 70 70 70 170 170 170 206 206 206 234 234 234
53094 -246 246 246 250 250 250 250 250 250 238 238 238
53095 -226 226 226 231 231 231 238 238 238 250 250 250
53096 -250 250 250 250 250 250 246 246 246 231 231 231
53097 -214 214 214 206 206 206 202 202 202 202 202 202
53098 -198 198 198 202 202 202 182 182 182 18 18 18
53099 - 2 2 6 2 2 6 2 2 6 2 2 6
53100 - 2 2 6 2 2 6 2 2 6 2 2 6
53101 - 2 2 6 62 62 62 66 66 66 30 30 30
53102 - 10 10 10 0 0 0 0 0 0 0 0 0
53103 - 0 0 0 0 0 0 0 0 0 0 0 0
53104 - 0 0 0 0 0 0 0 0 0 0 0 0
53105 - 0 0 0 0 0 0 0 0 0 0 0 0
53106 - 0 0 0 0 0 0 0 0 0 0 0 0
53107 - 0 0 0 0 0 0 0 0 0 0 0 0
53108 - 0 0 0 0 0 0 0 0 0 0 0 0
53109 - 0 0 0 0 0 0 0 0 0 0 0 0
53110 - 0 0 0 0 0 0 0 0 0 0 0 0
53111 - 14 14 14 42 42 42 82 82 82 18 18 18
53112 - 2 2 6 2 2 6 2 2 6 10 10 10
53113 - 94 94 94 182 182 182 218 218 218 242 242 242
53114 -250 250 250 253 253 253 253 253 253 250 250 250
53115 -234 234 234 253 253 253 253 253 253 253 253 253
53116 -253 253 253 253 253 253 253 253 253 246 246 246
53117 -238 238 238 226 226 226 210 210 210 202 202 202
53118 -195 195 195 195 195 195 210 210 210 158 158 158
53119 - 6 6 6 14 14 14 50 50 50 14 14 14
53120 - 2 2 6 2 2 6 2 2 6 2 2 6
53121 - 2 2 6 6 6 6 86 86 86 46 46 46
53122 - 18 18 18 6 6 6 0 0 0 0 0 0
53123 - 0 0 0 0 0 0 0 0 0 0 0 0
53124 - 0 0 0 0 0 0 0 0 0 0 0 0
53125 - 0 0 0 0 0 0 0 0 0 0 0 0
53126 - 0 0 0 0 0 0 0 0 0 0 0 0
53127 - 0 0 0 0 0 0 0 0 0 0 0 0
53128 - 0 0 0 0 0 0 0 0 0 0 0 0
53129 - 0 0 0 0 0 0 0 0 0 0 0 0
53130 - 0 0 0 0 0 0 0 0 0 6 6 6
53131 - 22 22 22 54 54 54 70 70 70 2 2 6
53132 - 2 2 6 10 10 10 2 2 6 22 22 22
53133 -166 166 166 231 231 231 250 250 250 253 253 253
53134 -253 253 253 253 253 253 253 253 253 250 250 250
53135 -242 242 242 253 253 253 253 253 253 253 253 253
53136 -253 253 253 253 253 253 253 253 253 253 253 253
53137 -253 253 253 253 253 253 253 253 253 246 246 246
53138 -231 231 231 206 206 206 198 198 198 226 226 226
53139 - 94 94 94 2 2 6 6 6 6 38 38 38
53140 - 30 30 30 2 2 6 2 2 6 2 2 6
53141 - 2 2 6 2 2 6 62 62 62 66 66 66
53142 - 26 26 26 10 10 10 0 0 0 0 0 0
53143 - 0 0 0 0 0 0 0 0 0 0 0 0
53144 - 0 0 0 0 0 0 0 0 0 0 0 0
53145 - 0 0 0 0 0 0 0 0 0 0 0 0
53146 - 0 0 0 0 0 0 0 0 0 0 0 0
53147 - 0 0 0 0 0 0 0 0 0 0 0 0
53148 - 0 0 0 0 0 0 0 0 0 0 0 0
53149 - 0 0 0 0 0 0 0 0 0 0 0 0
53150 - 0 0 0 0 0 0 0 0 0 10 10 10
53151 - 30 30 30 74 74 74 50 50 50 2 2 6
53152 - 26 26 26 26 26 26 2 2 6 106 106 106
53153 -238 238 238 253 253 253 253 253 253 253 253 253
53154 -253 253 253 253 253 253 253 253 253 253 253 253
53155 -253 253 253 253 253 253 253 253 253 253 253 253
53156 -253 253 253 253 253 253 253 253 253 253 253 253
53157 -253 253 253 253 253 253 253 253 253 253 253 253
53158 -253 253 253 246 246 246 218 218 218 202 202 202
53159 -210 210 210 14 14 14 2 2 6 2 2 6
53160 - 30 30 30 22 22 22 2 2 6 2 2 6
53161 - 2 2 6 2 2 6 18 18 18 86 86 86
53162 - 42 42 42 14 14 14 0 0 0 0 0 0
53163 - 0 0 0 0 0 0 0 0 0 0 0 0
53164 - 0 0 0 0 0 0 0 0 0 0 0 0
53165 - 0 0 0 0 0 0 0 0 0 0 0 0
53166 - 0 0 0 0 0 0 0 0 0 0 0 0
53167 - 0 0 0 0 0 0 0 0 0 0 0 0
53168 - 0 0 0 0 0 0 0 0 0 0 0 0
53169 - 0 0 0 0 0 0 0 0 0 0 0 0
53170 - 0 0 0 0 0 0 0 0 0 14 14 14
53171 - 42 42 42 90 90 90 22 22 22 2 2 6
53172 - 42 42 42 2 2 6 18 18 18 218 218 218
53173 -253 253 253 253 253 253 253 253 253 253 253 253
53174 -253 253 253 253 253 253 253 253 253 253 253 253
53175 -253 253 253 253 253 253 253 253 253 253 253 253
53176 -253 253 253 253 253 253 253 253 253 253 253 253
53177 -253 253 253 253 253 253 253 253 253 253 253 253
53178 -253 253 253 253 253 253 250 250 250 221 221 221
53179 -218 218 218 101 101 101 2 2 6 14 14 14
53180 - 18 18 18 38 38 38 10 10 10 2 2 6
53181 - 2 2 6 2 2 6 2 2 6 78 78 78
53182 - 58 58 58 22 22 22 6 6 6 0 0 0
53183 - 0 0 0 0 0 0 0 0 0 0 0 0
53184 - 0 0 0 0 0 0 0 0 0 0 0 0
53185 - 0 0 0 0 0 0 0 0 0 0 0 0
53186 - 0 0 0 0 0 0 0 0 0 0 0 0
53187 - 0 0 0 0 0 0 0 0 0 0 0 0
53188 - 0 0 0 0 0 0 0 0 0 0 0 0
53189 - 0 0 0 0 0 0 0 0 0 0 0 0
53190 - 0 0 0 0 0 0 6 6 6 18 18 18
53191 - 54 54 54 82 82 82 2 2 6 26 26 26
53192 - 22 22 22 2 2 6 123 123 123 253 253 253
53193 -253 253 253 253 253 253 253 253 253 253 253 253
53194 -253 253 253 253 253 253 253 253 253 253 253 253
53195 -253 253 253 253 253 253 253 253 253 253 253 253
53196 -253 253 253 253 253 253 253 253 253 253 253 253
53197 -253 253 253 253 253 253 253 253 253 253 253 253
53198 -253 253 253 253 253 253 253 253 253 250 250 250
53199 -238 238 238 198 198 198 6 6 6 38 38 38
53200 - 58 58 58 26 26 26 38 38 38 2 2 6
53201 - 2 2 6 2 2 6 2 2 6 46 46 46
53202 - 78 78 78 30 30 30 10 10 10 0 0 0
53203 - 0 0 0 0 0 0 0 0 0 0 0 0
53204 - 0 0 0 0 0 0 0 0 0 0 0 0
53205 - 0 0 0 0 0 0 0 0 0 0 0 0
53206 - 0 0 0 0 0 0 0 0 0 0 0 0
53207 - 0 0 0 0 0 0 0 0 0 0 0 0
53208 - 0 0 0 0 0 0 0 0 0 0 0 0
53209 - 0 0 0 0 0 0 0 0 0 0 0 0
53210 - 0 0 0 0 0 0 10 10 10 30 30 30
53211 - 74 74 74 58 58 58 2 2 6 42 42 42
53212 - 2 2 6 22 22 22 231 231 231 253 253 253
53213 -253 253 253 253 253 253 253 253 253 253 253 253
53214 -253 253 253 253 253 253 253 253 253 250 250 250
53215 -253 253 253 253 253 253 253 253 253 253 253 253
53216 -253 253 253 253 253 253 253 253 253 253 253 253
53217 -253 253 253 253 253 253 253 253 253 253 253 253
53218 -253 253 253 253 253 253 253 253 253 253 253 253
53219 -253 253 253 246 246 246 46 46 46 38 38 38
53220 - 42 42 42 14 14 14 38 38 38 14 14 14
53221 - 2 2 6 2 2 6 2 2 6 6 6 6
53222 - 86 86 86 46 46 46 14 14 14 0 0 0
53223 - 0 0 0 0 0 0 0 0 0 0 0 0
53224 - 0 0 0 0 0 0 0 0 0 0 0 0
53225 - 0 0 0 0 0 0 0 0 0 0 0 0
53226 - 0 0 0 0 0 0 0 0 0 0 0 0
53227 - 0 0 0 0 0 0 0 0 0 0 0 0
53228 - 0 0 0 0 0 0 0 0 0 0 0 0
53229 - 0 0 0 0 0 0 0 0 0 0 0 0
53230 - 0 0 0 6 6 6 14 14 14 42 42 42
53231 - 90 90 90 18 18 18 18 18 18 26 26 26
53232 - 2 2 6 116 116 116 253 253 253 253 253 253
53233 -253 253 253 253 253 253 253 253 253 253 253 253
53234 -253 253 253 253 253 253 250 250 250 238 238 238
53235 -253 253 253 253 253 253 253 253 253 253 253 253
53236 -253 253 253 253 253 253 253 253 253 253 253 253
53237 -253 253 253 253 253 253 253 253 253 253 253 253
53238 -253 253 253 253 253 253 253 253 253 253 253 253
53239 -253 253 253 253 253 253 94 94 94 6 6 6
53240 - 2 2 6 2 2 6 10 10 10 34 34 34
53241 - 2 2 6 2 2 6 2 2 6 2 2 6
53242 - 74 74 74 58 58 58 22 22 22 6 6 6
53243 - 0 0 0 0 0 0 0 0 0 0 0 0
53244 - 0 0 0 0 0 0 0 0 0 0 0 0
53245 - 0 0 0 0 0 0 0 0 0 0 0 0
53246 - 0 0 0 0 0 0 0 0 0 0 0 0
53247 - 0 0 0 0 0 0 0 0 0 0 0 0
53248 - 0 0 0 0 0 0 0 0 0 0 0 0
53249 - 0 0 0 0 0 0 0 0 0 0 0 0
53250 - 0 0 0 10 10 10 26 26 26 66 66 66
53251 - 82 82 82 2 2 6 38 38 38 6 6 6
53252 - 14 14 14 210 210 210 253 253 253 253 253 253
53253 -253 253 253 253 253 253 253 253 253 253 253 253
53254 -253 253 253 253 253 253 246 246 246 242 242 242
53255 -253 253 253 253 253 253 253 253 253 253 253 253
53256 -253 253 253 253 253 253 253 253 253 253 253 253
53257 -253 253 253 253 253 253 253 253 253 253 253 253
53258 -253 253 253 253 253 253 253 253 253 253 253 253
53259 -253 253 253 253 253 253 144 144 144 2 2 6
53260 - 2 2 6 2 2 6 2 2 6 46 46 46
53261 - 2 2 6 2 2 6 2 2 6 2 2 6
53262 - 42 42 42 74 74 74 30 30 30 10 10 10
53263 - 0 0 0 0 0 0 0 0 0 0 0 0
53264 - 0 0 0 0 0 0 0 0 0 0 0 0
53265 - 0 0 0 0 0 0 0 0 0 0 0 0
53266 - 0 0 0 0 0 0 0 0 0 0 0 0
53267 - 0 0 0 0 0 0 0 0 0 0 0 0
53268 - 0 0 0 0 0 0 0 0 0 0 0 0
53269 - 0 0 0 0 0 0 0 0 0 0 0 0
53270 - 6 6 6 14 14 14 42 42 42 90 90 90
53271 - 26 26 26 6 6 6 42 42 42 2 2 6
53272 - 74 74 74 250 250 250 253 253 253 253 253 253
53273 -253 253 253 253 253 253 253 253 253 253 253 253
53274 -253 253 253 253 253 253 242 242 242 242 242 242
53275 -253 253 253 253 253 253 253 253 253 253 253 253
53276 -253 253 253 253 253 253 253 253 253 253 253 253
53277 -253 253 253 253 253 253 253 253 253 253 253 253
53278 -253 253 253 253 253 253 253 253 253 253 253 253
53279 -253 253 253 253 253 253 182 182 182 2 2 6
53280 - 2 2 6 2 2 6 2 2 6 46 46 46
53281 - 2 2 6 2 2 6 2 2 6 2 2 6
53282 - 10 10 10 86 86 86 38 38 38 10 10 10
53283 - 0 0 0 0 0 0 0 0 0 0 0 0
53284 - 0 0 0 0 0 0 0 0 0 0 0 0
53285 - 0 0 0 0 0 0 0 0 0 0 0 0
53286 - 0 0 0 0 0 0 0 0 0 0 0 0
53287 - 0 0 0 0 0 0 0 0 0 0 0 0
53288 - 0 0 0 0 0 0 0 0 0 0 0 0
53289 - 0 0 0 0 0 0 0 0 0 0 0 0
53290 - 10 10 10 26 26 26 66 66 66 82 82 82
53291 - 2 2 6 22 22 22 18 18 18 2 2 6
53292 -149 149 149 253 253 253 253 253 253 253 253 253
53293 -253 253 253 253 253 253 253 253 253 253 253 253
53294 -253 253 253 253 253 253 234 234 234 242 242 242
53295 -253 253 253 253 253 253 253 253 253 253 253 253
53296 -253 253 253 253 253 253 253 253 253 253 253 253
53297 -253 253 253 253 253 253 253 253 253 253 253 253
53298 -253 253 253 253 253 253 253 253 253 253 253 253
53299 -253 253 253 253 253 253 206 206 206 2 2 6
53300 - 2 2 6 2 2 6 2 2 6 38 38 38
53301 - 2 2 6 2 2 6 2 2 6 2 2 6
53302 - 6 6 6 86 86 86 46 46 46 14 14 14
53303 - 0 0 0 0 0 0 0 0 0 0 0 0
53304 - 0 0 0 0 0 0 0 0 0 0 0 0
53305 - 0 0 0 0 0 0 0 0 0 0 0 0
53306 - 0 0 0 0 0 0 0 0 0 0 0 0
53307 - 0 0 0 0 0 0 0 0 0 0 0 0
53308 - 0 0 0 0 0 0 0 0 0 0 0 0
53309 - 0 0 0 0 0 0 0 0 0 6 6 6
53310 - 18 18 18 46 46 46 86 86 86 18 18 18
53311 - 2 2 6 34 34 34 10 10 10 6 6 6
53312 -210 210 210 253 253 253 253 253 253 253 253 253
53313 -253 253 253 253 253 253 253 253 253 253 253 253
53314 -253 253 253 253 253 253 234 234 234 242 242 242
53315 -253 253 253 253 253 253 253 253 253 253 253 253
53316 -253 253 253 253 253 253 253 253 253 253 253 253
53317 -253 253 253 253 253 253 253 253 253 253 253 253
53318 -253 253 253 253 253 253 253 253 253 253 253 253
53319 -253 253 253 253 253 253 221 221 221 6 6 6
53320 - 2 2 6 2 2 6 6 6 6 30 30 30
53321 - 2 2 6 2 2 6 2 2 6 2 2 6
53322 - 2 2 6 82 82 82 54 54 54 18 18 18
53323 - 6 6 6 0 0 0 0 0 0 0 0 0
53324 - 0 0 0 0 0 0 0 0 0 0 0 0
53325 - 0 0 0 0 0 0 0 0 0 0 0 0
53326 - 0 0 0 0 0 0 0 0 0 0 0 0
53327 - 0 0 0 0 0 0 0 0 0 0 0 0
53328 - 0 0 0 0 0 0 0 0 0 0 0 0
53329 - 0 0 0 0 0 0 0 0 0 10 10 10
53330 - 26 26 26 66 66 66 62 62 62 2 2 6
53331 - 2 2 6 38 38 38 10 10 10 26 26 26
53332 -238 238 238 253 253 253 253 253 253 253 253 253
53333 -253 253 253 253 253 253 253 253 253 253 253 253
53334 -253 253 253 253 253 253 231 231 231 238 238 238
53335 -253 253 253 253 253 253 253 253 253 253 253 253
53336 -253 253 253 253 253 253 253 253 253 253 253 253
53337 -253 253 253 253 253 253 253 253 253 253 253 253
53338 -253 253 253 253 253 253 253 253 253 253 253 253
53339 -253 253 253 253 253 253 231 231 231 6 6 6
53340 - 2 2 6 2 2 6 10 10 10 30 30 30
53341 - 2 2 6 2 2 6 2 2 6 2 2 6
53342 - 2 2 6 66 66 66 58 58 58 22 22 22
53343 - 6 6 6 0 0 0 0 0 0 0 0 0
53344 - 0 0 0 0 0 0 0 0 0 0 0 0
53345 - 0 0 0 0 0 0 0 0 0 0 0 0
53346 - 0 0 0 0 0 0 0 0 0 0 0 0
53347 - 0 0 0 0 0 0 0 0 0 0 0 0
53348 - 0 0 0 0 0 0 0 0 0 0 0 0
53349 - 0 0 0 0 0 0 0 0 0 10 10 10
53350 - 38 38 38 78 78 78 6 6 6 2 2 6
53351 - 2 2 6 46 46 46 14 14 14 42 42 42
53352 -246 246 246 253 253 253 253 253 253 253 253 253
53353 -253 253 253 253 253 253 253 253 253 253 253 253
53354 -253 253 253 253 253 253 231 231 231 242 242 242
53355 -253 253 253 253 253 253 253 253 253 253 253 253
53356 -253 253 253 253 253 253 253 253 253 253 253 253
53357 -253 253 253 253 253 253 253 253 253 253 253 253
53358 -253 253 253 253 253 253 253 253 253 253 253 253
53359 -253 253 253 253 253 253 234 234 234 10 10 10
53360 - 2 2 6 2 2 6 22 22 22 14 14 14
53361 - 2 2 6 2 2 6 2 2 6 2 2 6
53362 - 2 2 6 66 66 66 62 62 62 22 22 22
53363 - 6 6 6 0 0 0 0 0 0 0 0 0
53364 - 0 0 0 0 0 0 0 0 0 0 0 0
53365 - 0 0 0 0 0 0 0 0 0 0 0 0
53366 - 0 0 0 0 0 0 0 0 0 0 0 0
53367 - 0 0 0 0 0 0 0 0 0 0 0 0
53368 - 0 0 0 0 0 0 0 0 0 0 0 0
53369 - 0 0 0 0 0 0 6 6 6 18 18 18
53370 - 50 50 50 74 74 74 2 2 6 2 2 6
53371 - 14 14 14 70 70 70 34 34 34 62 62 62
53372 -250 250 250 253 253 253 253 253 253 253 253 253
53373 -253 253 253 253 253 253 253 253 253 253 253 253
53374 -253 253 253 253 253 253 231 231 231 246 246 246
53375 -253 253 253 253 253 253 253 253 253 253 253 253
53376 -253 253 253 253 253 253 253 253 253 253 253 253
53377 -253 253 253 253 253 253 253 253 253 253 253 253
53378 -253 253 253 253 253 253 253 253 253 253 253 253
53379 -253 253 253 253 253 253 234 234 234 14 14 14
53380 - 2 2 6 2 2 6 30 30 30 2 2 6
53381 - 2 2 6 2 2 6 2 2 6 2 2 6
53382 - 2 2 6 66 66 66 62 62 62 22 22 22
53383 - 6 6 6 0 0 0 0 0 0 0 0 0
53384 - 0 0 0 0 0 0 0 0 0 0 0 0
53385 - 0 0 0 0 0 0 0 0 0 0 0 0
53386 - 0 0 0 0 0 0 0 0 0 0 0 0
53387 - 0 0 0 0 0 0 0 0 0 0 0 0
53388 - 0 0 0 0 0 0 0 0 0 0 0 0
53389 - 0 0 0 0 0 0 6 6 6 18 18 18
53390 - 54 54 54 62 62 62 2 2 6 2 2 6
53391 - 2 2 6 30 30 30 46 46 46 70 70 70
53392 -250 250 250 253 253 253 253 253 253 253 253 253
53393 -253 253 253 253 253 253 253 253 253 253 253 253
53394 -253 253 253 253 253 253 231 231 231 246 246 246
53395 -253 253 253 253 253 253 253 253 253 253 253 253
53396 -253 253 253 253 253 253 253 253 253 253 253 253
53397 -253 253 253 253 253 253 253 253 253 253 253 253
53398 -253 253 253 253 253 253 253 253 253 253 253 253
53399 -253 253 253 253 253 253 226 226 226 10 10 10
53400 - 2 2 6 6 6 6 30 30 30 2 2 6
53401 - 2 2 6 2 2 6 2 2 6 2 2 6
53402 - 2 2 6 66 66 66 58 58 58 22 22 22
53403 - 6 6 6 0 0 0 0 0 0 0 0 0
53404 - 0 0 0 0 0 0 0 0 0 0 0 0
53405 - 0 0 0 0 0 0 0 0 0 0 0 0
53406 - 0 0 0 0 0 0 0 0 0 0 0 0
53407 - 0 0 0 0 0 0 0 0 0 0 0 0
53408 - 0 0 0 0 0 0 0 0 0 0 0 0
53409 - 0 0 0 0 0 0 6 6 6 22 22 22
53410 - 58 58 58 62 62 62 2 2 6 2 2 6
53411 - 2 2 6 2 2 6 30 30 30 78 78 78
53412 -250 250 250 253 253 253 253 253 253 253 253 253
53413 -253 253 253 253 253 253 253 253 253 253 253 253
53414 -253 253 253 253 253 253 231 231 231 246 246 246
53415 -253 253 253 253 253 253 253 253 253 253 253 253
53416 -253 253 253 253 253 253 253 253 253 253 253 253
53417 -253 253 253 253 253 253 253 253 253 253 253 253
53418 -253 253 253 253 253 253 253 253 253 253 253 253
53419 -253 253 253 253 253 253 206 206 206 2 2 6
53420 - 22 22 22 34 34 34 18 14 6 22 22 22
53421 - 26 26 26 18 18 18 6 6 6 2 2 6
53422 - 2 2 6 82 82 82 54 54 54 18 18 18
53423 - 6 6 6 0 0 0 0 0 0 0 0 0
53424 - 0 0 0 0 0 0 0 0 0 0 0 0
53425 - 0 0 0 0 0 0 0 0 0 0 0 0
53426 - 0 0 0 0 0 0 0 0 0 0 0 0
53427 - 0 0 0 0 0 0 0 0 0 0 0 0
53428 - 0 0 0 0 0 0 0 0 0 0 0 0
53429 - 0 0 0 0 0 0 6 6 6 26 26 26
53430 - 62 62 62 106 106 106 74 54 14 185 133 11
53431 -210 162 10 121 92 8 6 6 6 62 62 62
53432 -238 238 238 253 253 253 253 253 253 253 253 253
53433 -253 253 253 253 253 253 253 253 253 253 253 253
53434 -253 253 253 253 253 253 231 231 231 246 246 246
53435 -253 253 253 253 253 253 253 253 253 253 253 253
53436 -253 253 253 253 253 253 253 253 253 253 253 253
53437 -253 253 253 253 253 253 253 253 253 253 253 253
53438 -253 253 253 253 253 253 253 253 253 253 253 253
53439 -253 253 253 253 253 253 158 158 158 18 18 18
53440 - 14 14 14 2 2 6 2 2 6 2 2 6
53441 - 6 6 6 18 18 18 66 66 66 38 38 38
53442 - 6 6 6 94 94 94 50 50 50 18 18 18
53443 - 6 6 6 0 0 0 0 0 0 0 0 0
53444 - 0 0 0 0 0 0 0 0 0 0 0 0
53445 - 0 0 0 0 0 0 0 0 0 0 0 0
53446 - 0 0 0 0 0 0 0 0 0 0 0 0
53447 - 0 0 0 0 0 0 0 0 0 0 0 0
53448 - 0 0 0 0 0 0 0 0 0 6 6 6
53449 - 10 10 10 10 10 10 18 18 18 38 38 38
53450 - 78 78 78 142 134 106 216 158 10 242 186 14
53451 -246 190 14 246 190 14 156 118 10 10 10 10
53452 - 90 90 90 238 238 238 253 253 253 253 253 253
53453 -253 253 253 253 253 253 253 253 253 253 253 253
53454 -253 253 253 253 253 253 231 231 231 250 250 250
53455 -253 253 253 253 253 253 253 253 253 253 253 253
53456 -253 253 253 253 253 253 253 253 253 253 253 253
53457 -253 253 253 253 253 253 253 253 253 253 253 253
53458 -253 253 253 253 253 253 253 253 253 246 230 190
53459 -238 204 91 238 204 91 181 142 44 37 26 9
53460 - 2 2 6 2 2 6 2 2 6 2 2 6
53461 - 2 2 6 2 2 6 38 38 38 46 46 46
53462 - 26 26 26 106 106 106 54 54 54 18 18 18
53463 - 6 6 6 0 0 0 0 0 0 0 0 0
53464 - 0 0 0 0 0 0 0 0 0 0 0 0
53465 - 0 0 0 0 0 0 0 0 0 0 0 0
53466 - 0 0 0 0 0 0 0 0 0 0 0 0
53467 - 0 0 0 0 0 0 0 0 0 0 0 0
53468 - 0 0 0 6 6 6 14 14 14 22 22 22
53469 - 30 30 30 38 38 38 50 50 50 70 70 70
53470 -106 106 106 190 142 34 226 170 11 242 186 14
53471 -246 190 14 246 190 14 246 190 14 154 114 10
53472 - 6 6 6 74 74 74 226 226 226 253 253 253
53473 -253 253 253 253 253 253 253 253 253 253 253 253
53474 -253 253 253 253 253 253 231 231 231 250 250 250
53475 -253 253 253 253 253 253 253 253 253 253 253 253
53476 -253 253 253 253 253 253 253 253 253 253 253 253
53477 -253 253 253 253 253 253 253 253 253 253 253 253
53478 -253 253 253 253 253 253 253 253 253 228 184 62
53479 -241 196 14 241 208 19 232 195 16 38 30 10
53480 - 2 2 6 2 2 6 2 2 6 2 2 6
53481 - 2 2 6 6 6 6 30 30 30 26 26 26
53482 -203 166 17 154 142 90 66 66 66 26 26 26
53483 - 6 6 6 0 0 0 0 0 0 0 0 0
53484 - 0 0 0 0 0 0 0 0 0 0 0 0
53485 - 0 0 0 0 0 0 0 0 0 0 0 0
53486 - 0 0 0 0 0 0 0 0 0 0 0 0
53487 - 0 0 0 0 0 0 0 0 0 0 0 0
53488 - 6 6 6 18 18 18 38 38 38 58 58 58
53489 - 78 78 78 86 86 86 101 101 101 123 123 123
53490 -175 146 61 210 150 10 234 174 13 246 186 14
53491 -246 190 14 246 190 14 246 190 14 238 190 10
53492 -102 78 10 2 2 6 46 46 46 198 198 198
53493 -253 253 253 253 253 253 253 253 253 253 253 253
53494 -253 253 253 253 253 253 234 234 234 242 242 242
53495 -253 253 253 253 253 253 253 253 253 253 253 253
53496 -253 253 253 253 253 253 253 253 253 253 253 253
53497 -253 253 253 253 253 253 253 253 253 253 253 253
53498 -253 253 253 253 253 253 253 253 253 224 178 62
53499 -242 186 14 241 196 14 210 166 10 22 18 6
53500 - 2 2 6 2 2 6 2 2 6 2 2 6
53501 - 2 2 6 2 2 6 6 6 6 121 92 8
53502 -238 202 15 232 195 16 82 82 82 34 34 34
53503 - 10 10 10 0 0 0 0 0 0 0 0 0
53504 - 0 0 0 0 0 0 0 0 0 0 0 0
53505 - 0 0 0 0 0 0 0 0 0 0 0 0
53506 - 0 0 0 0 0 0 0 0 0 0 0 0
53507 - 0 0 0 0 0 0 0 0 0 0 0 0
53508 - 14 14 14 38 38 38 70 70 70 154 122 46
53509 -190 142 34 200 144 11 197 138 11 197 138 11
53510 -213 154 11 226 170 11 242 186 14 246 190 14
53511 -246 190 14 246 190 14 246 190 14 246 190 14
53512 -225 175 15 46 32 6 2 2 6 22 22 22
53513 -158 158 158 250 250 250 253 253 253 253 253 253
53514 -253 253 253 253 253 253 253 253 253 253 253 253
53515 -253 253 253 253 253 253 253 253 253 253 253 253
53516 -253 253 253 253 253 253 253 253 253 253 253 253
53517 -253 253 253 253 253 253 253 253 253 253 253 253
53518 -253 253 253 250 250 250 242 242 242 224 178 62
53519 -239 182 13 236 186 11 213 154 11 46 32 6
53520 - 2 2 6 2 2 6 2 2 6 2 2 6
53521 - 2 2 6 2 2 6 61 42 6 225 175 15
53522 -238 190 10 236 186 11 112 100 78 42 42 42
53523 - 14 14 14 0 0 0 0 0 0 0 0 0
53524 - 0 0 0 0 0 0 0 0 0 0 0 0
53525 - 0 0 0 0 0 0 0 0 0 0 0 0
53526 - 0 0 0 0 0 0 0 0 0 0 0 0
53527 - 0 0 0 0 0 0 0 0 0 6 6 6
53528 - 22 22 22 54 54 54 154 122 46 213 154 11
53529 -226 170 11 230 174 11 226 170 11 226 170 11
53530 -236 178 12 242 186 14 246 190 14 246 190 14
53531 -246 190 14 246 190 14 246 190 14 246 190 14
53532 -241 196 14 184 144 12 10 10 10 2 2 6
53533 - 6 6 6 116 116 116 242 242 242 253 253 253
53534 -253 253 253 253 253 253 253 253 253 253 253 253
53535 -253 253 253 253 253 253 253 253 253 253 253 253
53536 -253 253 253 253 253 253 253 253 253 253 253 253
53537 -253 253 253 253 253 253 253 253 253 253 253 253
53538 -253 253 253 231 231 231 198 198 198 214 170 54
53539 -236 178 12 236 178 12 210 150 10 137 92 6
53540 - 18 14 6 2 2 6 2 2 6 2 2 6
53541 - 6 6 6 70 47 6 200 144 11 236 178 12
53542 -239 182 13 239 182 13 124 112 88 58 58 58
53543 - 22 22 22 6 6 6 0 0 0 0 0 0
53544 - 0 0 0 0 0 0 0 0 0 0 0 0
53545 - 0 0 0 0 0 0 0 0 0 0 0 0
53546 - 0 0 0 0 0 0 0 0 0 0 0 0
53547 - 0 0 0 0 0 0 0 0 0 10 10 10
53548 - 30 30 30 70 70 70 180 133 36 226 170 11
53549 -239 182 13 242 186 14 242 186 14 246 186 14
53550 -246 190 14 246 190 14 246 190 14 246 190 14
53551 -246 190 14 246 190 14 246 190 14 246 190 14
53552 -246 190 14 232 195 16 98 70 6 2 2 6
53553 - 2 2 6 2 2 6 66 66 66 221 221 221
53554 -253 253 253 253 253 253 253 253 253 253 253 253
53555 -253 253 253 253 253 253 253 253 253 253 253 253
53556 -253 253 253 253 253 253 253 253 253 253 253 253
53557 -253 253 253 253 253 253 253 253 253 253 253 253
53558 -253 253 253 206 206 206 198 198 198 214 166 58
53559 -230 174 11 230 174 11 216 158 10 192 133 9
53560 -163 110 8 116 81 8 102 78 10 116 81 8
53561 -167 114 7 197 138 11 226 170 11 239 182 13
53562 -242 186 14 242 186 14 162 146 94 78 78 78
53563 - 34 34 34 14 14 14 6 6 6 0 0 0
53564 - 0 0 0 0 0 0 0 0 0 0 0 0
53565 - 0 0 0 0 0 0 0 0 0 0 0 0
53566 - 0 0 0 0 0 0 0 0 0 0 0 0
53567 - 0 0 0 0 0 0 0 0 0 6 6 6
53568 - 30 30 30 78 78 78 190 142 34 226 170 11
53569 -239 182 13 246 190 14 246 190 14 246 190 14
53570 -246 190 14 246 190 14 246 190 14 246 190 14
53571 -246 190 14 246 190 14 246 190 14 246 190 14
53572 -246 190 14 241 196 14 203 166 17 22 18 6
53573 - 2 2 6 2 2 6 2 2 6 38 38 38
53574 -218 218 218 253 253 253 253 253 253 253 253 253
53575 -253 253 253 253 253 253 253 253 253 253 253 253
53576 -253 253 253 253 253 253 253 253 253 253 253 253
53577 -253 253 253 253 253 253 253 253 253 253 253 253
53578 -250 250 250 206 206 206 198 198 198 202 162 69
53579 -226 170 11 236 178 12 224 166 10 210 150 10
53580 -200 144 11 197 138 11 192 133 9 197 138 11
53581 -210 150 10 226 170 11 242 186 14 246 190 14
53582 -246 190 14 246 186 14 225 175 15 124 112 88
53583 - 62 62 62 30 30 30 14 14 14 6 6 6
53584 - 0 0 0 0 0 0 0 0 0 0 0 0
53585 - 0 0 0 0 0 0 0 0 0 0 0 0
53586 - 0 0 0 0 0 0 0 0 0 0 0 0
53587 - 0 0 0 0 0 0 0 0 0 10 10 10
53588 - 30 30 30 78 78 78 174 135 50 224 166 10
53589 -239 182 13 246 190 14 246 190 14 246 190 14
53590 -246 190 14 246 190 14 246 190 14 246 190 14
53591 -246 190 14 246 190 14 246 190 14 246 190 14
53592 -246 190 14 246 190 14 241 196 14 139 102 15
53593 - 2 2 6 2 2 6 2 2 6 2 2 6
53594 - 78 78 78 250 250 250 253 253 253 253 253 253
53595 -253 253 253 253 253 253 253 253 253 253 253 253
53596 -253 253 253 253 253 253 253 253 253 253 253 253
53597 -253 253 253 253 253 253 253 253 253 253 253 253
53598 -250 250 250 214 214 214 198 198 198 190 150 46
53599 -219 162 10 236 178 12 234 174 13 224 166 10
53600 -216 158 10 213 154 11 213 154 11 216 158 10
53601 -226 170 11 239 182 13 246 190 14 246 190 14
53602 -246 190 14 246 190 14 242 186 14 206 162 42
53603 -101 101 101 58 58 58 30 30 30 14 14 14
53604 - 6 6 6 0 0 0 0 0 0 0 0 0
53605 - 0 0 0 0 0 0 0 0 0 0 0 0
53606 - 0 0 0 0 0 0 0 0 0 0 0 0
53607 - 0 0 0 0 0 0 0 0 0 10 10 10
53608 - 30 30 30 74 74 74 174 135 50 216 158 10
53609 -236 178 12 246 190 14 246 190 14 246 190 14
53610 -246 190 14 246 190 14 246 190 14 246 190 14
53611 -246 190 14 246 190 14 246 190 14 246 190 14
53612 -246 190 14 246 190 14 241 196 14 226 184 13
53613 - 61 42 6 2 2 6 2 2 6 2 2 6
53614 - 22 22 22 238 238 238 253 253 253 253 253 253
53615 -253 253 253 253 253 253 253 253 253 253 253 253
53616 -253 253 253 253 253 253 253 253 253 253 253 253
53617 -253 253 253 253 253 253 253 253 253 253 253 253
53618 -253 253 253 226 226 226 187 187 187 180 133 36
53619 -216 158 10 236 178 12 239 182 13 236 178 12
53620 -230 174 11 226 170 11 226 170 11 230 174 11
53621 -236 178 12 242 186 14 246 190 14 246 190 14
53622 -246 190 14 246 190 14 246 186 14 239 182 13
53623 -206 162 42 106 106 106 66 66 66 34 34 34
53624 - 14 14 14 6 6 6 0 0 0 0 0 0
53625 - 0 0 0 0 0 0 0 0 0 0 0 0
53626 - 0 0 0 0 0 0 0 0 0 0 0 0
53627 - 0 0 0 0 0 0 0 0 0 6 6 6
53628 - 26 26 26 70 70 70 163 133 67 213 154 11
53629 -236 178 12 246 190 14 246 190 14 246 190 14
53630 -246 190 14 246 190 14 246 190 14 246 190 14
53631 -246 190 14 246 190 14 246 190 14 246 190 14
53632 -246 190 14 246 190 14 246 190 14 241 196 14
53633 -190 146 13 18 14 6 2 2 6 2 2 6
53634 - 46 46 46 246 246 246 253 253 253 253 253 253
53635 -253 253 253 253 253 253 253 253 253 253 253 253
53636 -253 253 253 253 253 253 253 253 253 253 253 253
53637 -253 253 253 253 253 253 253 253 253 253 253 253
53638 -253 253 253 221 221 221 86 86 86 156 107 11
53639 -216 158 10 236 178 12 242 186 14 246 186 14
53640 -242 186 14 239 182 13 239 182 13 242 186 14
53641 -242 186 14 246 186 14 246 190 14 246 190 14
53642 -246 190 14 246 190 14 246 190 14 246 190 14
53643 -242 186 14 225 175 15 142 122 72 66 66 66
53644 - 30 30 30 10 10 10 0 0 0 0 0 0
53645 - 0 0 0 0 0 0 0 0 0 0 0 0
53646 - 0 0 0 0 0 0 0 0 0 0 0 0
53647 - 0 0 0 0 0 0 0 0 0 6 6 6
53648 - 26 26 26 70 70 70 163 133 67 210 150 10
53649 -236 178 12 246 190 14 246 190 14 246 190 14
53650 -246 190 14 246 190 14 246 190 14 246 190 14
53651 -246 190 14 246 190 14 246 190 14 246 190 14
53652 -246 190 14 246 190 14 246 190 14 246 190 14
53653 -232 195 16 121 92 8 34 34 34 106 106 106
53654 -221 221 221 253 253 253 253 253 253 253 253 253
53655 -253 253 253 253 253 253 253 253 253 253 253 253
53656 -253 253 253 253 253 253 253 253 253 253 253 253
53657 -253 253 253 253 253 253 253 253 253 253 253 253
53658 -242 242 242 82 82 82 18 14 6 163 110 8
53659 -216 158 10 236 178 12 242 186 14 246 190 14
53660 -246 190 14 246 190 14 246 190 14 246 190 14
53661 -246 190 14 246 190 14 246 190 14 246 190 14
53662 -246 190 14 246 190 14 246 190 14 246 190 14
53663 -246 190 14 246 190 14 242 186 14 163 133 67
53664 - 46 46 46 18 18 18 6 6 6 0 0 0
53665 - 0 0 0 0 0 0 0 0 0 0 0 0
53666 - 0 0 0 0 0 0 0 0 0 0 0 0
53667 - 0 0 0 0 0 0 0 0 0 10 10 10
53668 - 30 30 30 78 78 78 163 133 67 210 150 10
53669 -236 178 12 246 186 14 246 190 14 246 190 14
53670 -246 190 14 246 190 14 246 190 14 246 190 14
53671 -246 190 14 246 190 14 246 190 14 246 190 14
53672 -246 190 14 246 190 14 246 190 14 246 190 14
53673 -241 196 14 215 174 15 190 178 144 253 253 253
53674 -253 253 253 253 253 253 253 253 253 253 253 253
53675 -253 253 253 253 253 253 253 253 253 253 253 253
53676 -253 253 253 253 253 253 253 253 253 253 253 253
53677 -253 253 253 253 253 253 253 253 253 218 218 218
53678 - 58 58 58 2 2 6 22 18 6 167 114 7
53679 -216 158 10 236 178 12 246 186 14 246 190 14
53680 -246 190 14 246 190 14 246 190 14 246 190 14
53681 -246 190 14 246 190 14 246 190 14 246 190 14
53682 -246 190 14 246 190 14 246 190 14 246 190 14
53683 -246 190 14 246 186 14 242 186 14 190 150 46
53684 - 54 54 54 22 22 22 6 6 6 0 0 0
53685 - 0 0 0 0 0 0 0 0 0 0 0 0
53686 - 0 0 0 0 0 0 0 0 0 0 0 0
53687 - 0 0 0 0 0 0 0 0 0 14 14 14
53688 - 38 38 38 86 86 86 180 133 36 213 154 11
53689 -236 178 12 246 186 14 246 190 14 246 190 14
53690 -246 190 14 246 190 14 246 190 14 246 190 14
53691 -246 190 14 246 190 14 246 190 14 246 190 14
53692 -246 190 14 246 190 14 246 190 14 246 190 14
53693 -246 190 14 232 195 16 190 146 13 214 214 214
53694 -253 253 253 253 253 253 253 253 253 253 253 253
53695 -253 253 253 253 253 253 253 253 253 253 253 253
53696 -253 253 253 253 253 253 253 253 253 253 253 253
53697 -253 253 253 250 250 250 170 170 170 26 26 26
53698 - 2 2 6 2 2 6 37 26 9 163 110 8
53699 -219 162 10 239 182 13 246 186 14 246 190 14
53700 -246 190 14 246 190 14 246 190 14 246 190 14
53701 -246 190 14 246 190 14 246 190 14 246 190 14
53702 -246 190 14 246 190 14 246 190 14 246 190 14
53703 -246 186 14 236 178 12 224 166 10 142 122 72
53704 - 46 46 46 18 18 18 6 6 6 0 0 0
53705 - 0 0 0 0 0 0 0 0 0 0 0 0
53706 - 0 0 0 0 0 0 0 0 0 0 0 0
53707 - 0 0 0 0 0 0 6 6 6 18 18 18
53708 - 50 50 50 109 106 95 192 133 9 224 166 10
53709 -242 186 14 246 190 14 246 190 14 246 190 14
53710 -246 190 14 246 190 14 246 190 14 246 190 14
53711 -246 190 14 246 190 14 246 190 14 246 190 14
53712 -246 190 14 246 190 14 246 190 14 246 190 14
53713 -242 186 14 226 184 13 210 162 10 142 110 46
53714 -226 226 226 253 253 253 253 253 253 253 253 253
53715 -253 253 253 253 253 253 253 253 253 253 253 253
53716 -253 253 253 253 253 253 253 253 253 253 253 253
53717 -198 198 198 66 66 66 2 2 6 2 2 6
53718 - 2 2 6 2 2 6 50 34 6 156 107 11
53719 -219 162 10 239 182 13 246 186 14 246 190 14
53720 -246 190 14 246 190 14 246 190 14 246 190 14
53721 -246 190 14 246 190 14 246 190 14 246 190 14
53722 -246 190 14 246 190 14 246 190 14 242 186 14
53723 -234 174 13 213 154 11 154 122 46 66 66 66
53724 - 30 30 30 10 10 10 0 0 0 0 0 0
53725 - 0 0 0 0 0 0 0 0 0 0 0 0
53726 - 0 0 0 0 0 0 0 0 0 0 0 0
53727 - 0 0 0 0 0 0 6 6 6 22 22 22
53728 - 58 58 58 154 121 60 206 145 10 234 174 13
53729 -242 186 14 246 186 14 246 190 14 246 190 14
53730 -246 190 14 246 190 14 246 190 14 246 190 14
53731 -246 190 14 246 190 14 246 190 14 246 190 14
53732 -246 190 14 246 190 14 246 190 14 246 190 14
53733 -246 186 14 236 178 12 210 162 10 163 110 8
53734 - 61 42 6 138 138 138 218 218 218 250 250 250
53735 -253 253 253 253 253 253 253 253 253 250 250 250
53736 -242 242 242 210 210 210 144 144 144 66 66 66
53737 - 6 6 6 2 2 6 2 2 6 2 2 6
53738 - 2 2 6 2 2 6 61 42 6 163 110 8
53739 -216 158 10 236 178 12 246 190 14 246 190 14
53740 -246 190 14 246 190 14 246 190 14 246 190 14
53741 -246 190 14 246 190 14 246 190 14 246 190 14
53742 -246 190 14 239 182 13 230 174 11 216 158 10
53743 -190 142 34 124 112 88 70 70 70 38 38 38
53744 - 18 18 18 6 6 6 0 0 0 0 0 0
53745 - 0 0 0 0 0 0 0 0 0 0 0 0
53746 - 0 0 0 0 0 0 0 0 0 0 0 0
53747 - 0 0 0 0 0 0 6 6 6 22 22 22
53748 - 62 62 62 168 124 44 206 145 10 224 166 10
53749 -236 178 12 239 182 13 242 186 14 242 186 14
53750 -246 186 14 246 190 14 246 190 14 246 190 14
53751 -246 190 14 246 190 14 246 190 14 246 190 14
53752 -246 190 14 246 190 14 246 190 14 246 190 14
53753 -246 190 14 236 178 12 216 158 10 175 118 6
53754 - 80 54 7 2 2 6 6 6 6 30 30 30
53755 - 54 54 54 62 62 62 50 50 50 38 38 38
53756 - 14 14 14 2 2 6 2 2 6 2 2 6
53757 - 2 2 6 2 2 6 2 2 6 2 2 6
53758 - 2 2 6 6 6 6 80 54 7 167 114 7
53759 -213 154 11 236 178 12 246 190 14 246 190 14
53760 -246 190 14 246 190 14 246 190 14 246 190 14
53761 -246 190 14 242 186 14 239 182 13 239 182 13
53762 -230 174 11 210 150 10 174 135 50 124 112 88
53763 - 82 82 82 54 54 54 34 34 34 18 18 18
53764 - 6 6 6 0 0 0 0 0 0 0 0 0
53765 - 0 0 0 0 0 0 0 0 0 0 0 0
53766 - 0 0 0 0 0 0 0 0 0 0 0 0
53767 - 0 0 0 0 0 0 6 6 6 18 18 18
53768 - 50 50 50 158 118 36 192 133 9 200 144 11
53769 -216 158 10 219 162 10 224 166 10 226 170 11
53770 -230 174 11 236 178 12 239 182 13 239 182 13
53771 -242 186 14 246 186 14 246 190 14 246 190 14
53772 -246 190 14 246 190 14 246 190 14 246 190 14
53773 -246 186 14 230 174 11 210 150 10 163 110 8
53774 -104 69 6 10 10 10 2 2 6 2 2 6
53775 - 2 2 6 2 2 6 2 2 6 2 2 6
53776 - 2 2 6 2 2 6 2 2 6 2 2 6
53777 - 2 2 6 2 2 6 2 2 6 2 2 6
53778 - 2 2 6 6 6 6 91 60 6 167 114 7
53779 -206 145 10 230 174 11 242 186 14 246 190 14
53780 -246 190 14 246 190 14 246 186 14 242 186 14
53781 -239 182 13 230 174 11 224 166 10 213 154 11
53782 -180 133 36 124 112 88 86 86 86 58 58 58
53783 - 38 38 38 22 22 22 10 10 10 6 6 6
53784 - 0 0 0 0 0 0 0 0 0 0 0 0
53785 - 0 0 0 0 0 0 0 0 0 0 0 0
53786 - 0 0 0 0 0 0 0 0 0 0 0 0
53787 - 0 0 0 0 0 0 0 0 0 14 14 14
53788 - 34 34 34 70 70 70 138 110 50 158 118 36
53789 -167 114 7 180 123 7 192 133 9 197 138 11
53790 -200 144 11 206 145 10 213 154 11 219 162 10
53791 -224 166 10 230 174 11 239 182 13 242 186 14
53792 -246 186 14 246 186 14 246 186 14 246 186 14
53793 -239 182 13 216 158 10 185 133 11 152 99 6
53794 -104 69 6 18 14 6 2 2 6 2 2 6
53795 - 2 2 6 2 2 6 2 2 6 2 2 6
53796 - 2 2 6 2 2 6 2 2 6 2 2 6
53797 - 2 2 6 2 2 6 2 2 6 2 2 6
53798 - 2 2 6 6 6 6 80 54 7 152 99 6
53799 -192 133 9 219 162 10 236 178 12 239 182 13
53800 -246 186 14 242 186 14 239 182 13 236 178 12
53801 -224 166 10 206 145 10 192 133 9 154 121 60
53802 - 94 94 94 62 62 62 42 42 42 22 22 22
53803 - 14 14 14 6 6 6 0 0 0 0 0 0
53804 - 0 0 0 0 0 0 0 0 0 0 0 0
53805 - 0 0 0 0 0 0 0 0 0 0 0 0
53806 - 0 0 0 0 0 0 0 0 0 0 0 0
53807 - 0 0 0 0 0 0 0 0 0 6 6 6
53808 - 18 18 18 34 34 34 58 58 58 78 78 78
53809 -101 98 89 124 112 88 142 110 46 156 107 11
53810 -163 110 8 167 114 7 175 118 6 180 123 7
53811 -185 133 11 197 138 11 210 150 10 219 162 10
53812 -226 170 11 236 178 12 236 178 12 234 174 13
53813 -219 162 10 197 138 11 163 110 8 130 83 6
53814 - 91 60 6 10 10 10 2 2 6 2 2 6
53815 - 18 18 18 38 38 38 38 38 38 38 38 38
53816 - 38 38 38 38 38 38 38 38 38 38 38 38
53817 - 38 38 38 38 38 38 26 26 26 2 2 6
53818 - 2 2 6 6 6 6 70 47 6 137 92 6
53819 -175 118 6 200 144 11 219 162 10 230 174 11
53820 -234 174 13 230 174 11 219 162 10 210 150 10
53821 -192 133 9 163 110 8 124 112 88 82 82 82
53822 - 50 50 50 30 30 30 14 14 14 6 6 6
53823 - 0 0 0 0 0 0 0 0 0 0 0 0
53824 - 0 0 0 0 0 0 0 0 0 0 0 0
53825 - 0 0 0 0 0 0 0 0 0 0 0 0
53826 - 0 0 0 0 0 0 0 0 0 0 0 0
53827 - 0 0 0 0 0 0 0 0 0 0 0 0
53828 - 6 6 6 14 14 14 22 22 22 34 34 34
53829 - 42 42 42 58 58 58 74 74 74 86 86 86
53830 -101 98 89 122 102 70 130 98 46 121 87 25
53831 -137 92 6 152 99 6 163 110 8 180 123 7
53832 -185 133 11 197 138 11 206 145 10 200 144 11
53833 -180 123 7 156 107 11 130 83 6 104 69 6
53834 - 50 34 6 54 54 54 110 110 110 101 98 89
53835 - 86 86 86 82 82 82 78 78 78 78 78 78
53836 - 78 78 78 78 78 78 78 78 78 78 78 78
53837 - 78 78 78 82 82 82 86 86 86 94 94 94
53838 -106 106 106 101 101 101 86 66 34 124 80 6
53839 -156 107 11 180 123 7 192 133 9 200 144 11
53840 -206 145 10 200 144 11 192 133 9 175 118 6
53841 -139 102 15 109 106 95 70 70 70 42 42 42
53842 - 22 22 22 10 10 10 0 0 0 0 0 0
53843 - 0 0 0 0 0 0 0 0 0 0 0 0
53844 - 0 0 0 0 0 0 0 0 0 0 0 0
53845 - 0 0 0 0 0 0 0 0 0 0 0 0
53846 - 0 0 0 0 0 0 0 0 0 0 0 0
53847 - 0 0 0 0 0 0 0 0 0 0 0 0
53848 - 0 0 0 0 0 0 6 6 6 10 10 10
53849 - 14 14 14 22 22 22 30 30 30 38 38 38
53850 - 50 50 50 62 62 62 74 74 74 90 90 90
53851 -101 98 89 112 100 78 121 87 25 124 80 6
53852 -137 92 6 152 99 6 152 99 6 152 99 6
53853 -138 86 6 124 80 6 98 70 6 86 66 30
53854 -101 98 89 82 82 82 58 58 58 46 46 46
53855 - 38 38 38 34 34 34 34 34 34 34 34 34
53856 - 34 34 34 34 34 34 34 34 34 34 34 34
53857 - 34 34 34 34 34 34 38 38 38 42 42 42
53858 - 54 54 54 82 82 82 94 86 76 91 60 6
53859 -134 86 6 156 107 11 167 114 7 175 118 6
53860 -175 118 6 167 114 7 152 99 6 121 87 25
53861 -101 98 89 62 62 62 34 34 34 18 18 18
53862 - 6 6 6 0 0 0 0 0 0 0 0 0
53863 - 0 0 0 0 0 0 0 0 0 0 0 0
53864 - 0 0 0 0 0 0 0 0 0 0 0 0
53865 - 0 0 0 0 0 0 0 0 0 0 0 0
53866 - 0 0 0 0 0 0 0 0 0 0 0 0
53867 - 0 0 0 0 0 0 0 0 0 0 0 0
53868 - 0 0 0 0 0 0 0 0 0 0 0 0
53869 - 0 0 0 6 6 6 6 6 6 10 10 10
53870 - 18 18 18 22 22 22 30 30 30 42 42 42
53871 - 50 50 50 66 66 66 86 86 86 101 98 89
53872 -106 86 58 98 70 6 104 69 6 104 69 6
53873 -104 69 6 91 60 6 82 62 34 90 90 90
53874 - 62 62 62 38 38 38 22 22 22 14 14 14
53875 - 10 10 10 10 10 10 10 10 10 10 10 10
53876 - 10 10 10 10 10 10 6 6 6 10 10 10
53877 - 10 10 10 10 10 10 10 10 10 14 14 14
53878 - 22 22 22 42 42 42 70 70 70 89 81 66
53879 - 80 54 7 104 69 6 124 80 6 137 92 6
53880 -134 86 6 116 81 8 100 82 52 86 86 86
53881 - 58 58 58 30 30 30 14 14 14 6 6 6
53882 - 0 0 0 0 0 0 0 0 0 0 0 0
53883 - 0 0 0 0 0 0 0 0 0 0 0 0
53884 - 0 0 0 0 0 0 0 0 0 0 0 0
53885 - 0 0 0 0 0 0 0 0 0 0 0 0
53886 - 0 0 0 0 0 0 0 0 0 0 0 0
53887 - 0 0 0 0 0 0 0 0 0 0 0 0
53888 - 0 0 0 0 0 0 0 0 0 0 0 0
53889 - 0 0 0 0 0 0 0 0 0 0 0 0
53890 - 0 0 0 6 6 6 10 10 10 14 14 14
53891 - 18 18 18 26 26 26 38 38 38 54 54 54
53892 - 70 70 70 86 86 86 94 86 76 89 81 66
53893 - 89 81 66 86 86 86 74 74 74 50 50 50
53894 - 30 30 30 14 14 14 6 6 6 0 0 0
53895 - 0 0 0 0 0 0 0 0 0 0 0 0
53896 - 0 0 0 0 0 0 0 0 0 0 0 0
53897 - 0 0 0 0 0 0 0 0 0 0 0 0
53898 - 6 6 6 18 18 18 34 34 34 58 58 58
53899 - 82 82 82 89 81 66 89 81 66 89 81 66
53900 - 94 86 66 94 86 76 74 74 74 50 50 50
53901 - 26 26 26 14 14 14 6 6 6 0 0 0
53902 - 0 0 0 0 0 0 0 0 0 0 0 0
53903 - 0 0 0 0 0 0 0 0 0 0 0 0
53904 - 0 0 0 0 0 0 0 0 0 0 0 0
53905 - 0 0 0 0 0 0 0 0 0 0 0 0
53906 - 0 0 0 0 0 0 0 0 0 0 0 0
53907 - 0 0 0 0 0 0 0 0 0 0 0 0
53908 - 0 0 0 0 0 0 0 0 0 0 0 0
53909 - 0 0 0 0 0 0 0 0 0 0 0 0
53910 - 0 0 0 0 0 0 0 0 0 0 0 0
53911 - 6 6 6 6 6 6 14 14 14 18 18 18
53912 - 30 30 30 38 38 38 46 46 46 54 54 54
53913 - 50 50 50 42 42 42 30 30 30 18 18 18
53914 - 10 10 10 0 0 0 0 0 0 0 0 0
53915 - 0 0 0 0 0 0 0 0 0 0 0 0
53916 - 0 0 0 0 0 0 0 0 0 0 0 0
53917 - 0 0 0 0 0 0 0 0 0 0 0 0
53918 - 0 0 0 6 6 6 14 14 14 26 26 26
53919 - 38 38 38 50 50 50 58 58 58 58 58 58
53920 - 54 54 54 42 42 42 30 30 30 18 18 18
53921 - 10 10 10 0 0 0 0 0 0 0 0 0
53922 - 0 0 0 0 0 0 0 0 0 0 0 0
53923 - 0 0 0 0 0 0 0 0 0 0 0 0
53924 - 0 0 0 0 0 0 0 0 0 0 0 0
53925 - 0 0 0 0 0 0 0 0 0 0 0 0
53926 - 0 0 0 0 0 0 0 0 0 0 0 0
53927 - 0 0 0 0 0 0 0 0 0 0 0 0
53928 - 0 0 0 0 0 0 0 0 0 0 0 0
53929 - 0 0 0 0 0 0 0 0 0 0 0 0
53930 - 0 0 0 0 0 0 0 0 0 0 0 0
53931 - 0 0 0 0 0 0 0 0 0 6 6 6
53932 - 6 6 6 10 10 10 14 14 14 18 18 18
53933 - 18 18 18 14 14 14 10 10 10 6 6 6
53934 - 0 0 0 0 0 0 0 0 0 0 0 0
53935 - 0 0 0 0 0 0 0 0 0 0 0 0
53936 - 0 0 0 0 0 0 0 0 0 0 0 0
53937 - 0 0 0 0 0 0 0 0 0 0 0 0
53938 - 0 0 0 0 0 0 0 0 0 6 6 6
53939 - 14 14 14 18 18 18 22 22 22 22 22 22
53940 - 18 18 18 14 14 14 10 10 10 6 6 6
53941 - 0 0 0 0 0 0 0 0 0 0 0 0
53942 - 0 0 0 0 0 0 0 0 0 0 0 0
53943 - 0 0 0 0 0 0 0 0 0 0 0 0
53944 - 0 0 0 0 0 0 0 0 0 0 0 0
53945 - 0 0 0 0 0 0 0 0 0 0 0 0
53946 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
53951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53953 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53954 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53959 +4 4 4 4 4 4
53960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53973 +4 4 4 4 4 4
53974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53987 +4 4 4 4 4 4
53988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54001 +4 4 4 4 4 4
54002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54015 +4 4 4 4 4 4
54016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54029 +4 4 4 4 4 4
54030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54034 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54035 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54039 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54040 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54041 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54043 +4 4 4 4 4 4
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 2 2 2 0 0 0 3 4 3 26 28 28
54049 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54050 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54053 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54054 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54055 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54056 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54057 +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 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54063 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54064 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54067 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54068 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54069 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54070 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54071 +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 5 5 5 5 5 5 2 2 2 0 0 0
54076 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54077 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54078 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54080 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54081 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54082 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54083 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54084 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54085 +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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54090 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54091 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54092 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54093 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54094 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54095 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54096 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54097 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54098 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54099 +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 5 5 5
54103 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54104 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54105 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54106 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54107 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54108 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54109 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54110 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54111 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54112 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54113 +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 5 5 5 3 3 3
54117 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54118 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54119 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54120 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54121 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54122 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54123 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54124 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54125 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54126 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54127 +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 2 2 2 0 0 0 4 0 0
54131 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54132 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54133 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54134 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54135 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54136 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54137 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54138 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54139 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54140 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54141 +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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54145 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54146 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54147 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54148 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54149 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54150 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54151 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54152 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54153 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54154 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54155 +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 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54159 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54160 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54161 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54162 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54163 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54164 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54165 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54166 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54167 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54168 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54169 +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 3 3 3 0 0 0
54172 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54173 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54174 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54175 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54176 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54177 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54178 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54179 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54180 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54181 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54182 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54183 +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 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54186 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54187 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54188 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54189 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54190 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54191 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54192 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54193 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54194 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54195 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54196 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54197 +0 0 0 4 4 4
54198 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54199 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54200 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54201 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54202 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54203 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54204 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54205 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54206 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54207 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54208 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54209 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54210 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54211 +2 0 0 0 0 0
54212 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54213 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54214 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54215 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54216 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54217 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54218 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54219 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54220 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54221 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54222 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54223 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54224 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54225 +37 38 37 0 0 0
54226 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54227 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54228 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54229 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54230 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54231 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54232 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54233 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54234 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54235 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54236 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54237 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54238 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54239 +85 115 134 4 0 0
54240 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54241 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54242 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54243 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54244 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54245 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54246 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54247 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54248 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54249 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54250 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54251 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54252 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54253 +60 73 81 4 0 0
54254 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54255 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54256 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54257 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54258 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54259 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54260 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54261 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54262 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54263 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54264 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54265 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54266 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54267 +16 19 21 4 0 0
54268 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54269 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54270 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54271 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54272 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
54273 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
54274 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
54275 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
54276 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
54277 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
54278 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
54279 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
54280 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
54281 +4 0 0 4 3 3
54282 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
54283 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
54284 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
54285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
54286 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
54287 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
54288 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
54289 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
54290 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
54291 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
54292 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
54293 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
54294 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
54295 +3 2 2 4 4 4
54296 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
54297 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
54298 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
54299 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54300 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
54301 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
54302 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
54303 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
54304 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
54305 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
54306 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
54307 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
54308 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
54309 +4 4 4 4 4 4
54310 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
54311 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
54312 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
54313 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
54314 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
54315 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
54316 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
54317 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
54318 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
54319 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
54320 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
54321 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
54322 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
54323 +4 4 4 4 4 4
54324 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
54325 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
54326 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
54327 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
54328 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
54329 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54330 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
54331 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
54332 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
54333 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
54334 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
54335 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
54336 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
54337 +5 5 5 5 5 5
54338 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
54339 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
54340 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
54341 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
54342 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
54343 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54344 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
54345 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
54346 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
54347 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
54348 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
54349 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
54350 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54351 +5 5 5 4 4 4
54352 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
54353 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
54354 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
54355 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
54356 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54357 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
54358 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
54359 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
54360 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
54361 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
54362 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
54363 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54365 +4 4 4 4 4 4
54366 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
54367 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
54368 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
54369 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
54370 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
54371 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54372 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54373 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
54374 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
54375 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
54376 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
54377 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
54378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54379 +4 4 4 4 4 4
54380 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
54381 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
54382 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
54383 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
54384 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54385 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
54386 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
54387 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
54388 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
54389 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
54390 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
54391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54393 +4 4 4 4 4 4
54394 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
54395 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
54396 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
54397 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
54398 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54399 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54400 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54401 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
54402 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
54403 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
54404 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
54405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54407 +4 4 4 4 4 4
54408 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
54409 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
54410 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
54411 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
54412 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54413 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
54414 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54415 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
54416 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
54417 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
54418 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54420 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54421 +4 4 4 4 4 4
54422 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
54423 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
54424 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
54425 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
54426 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54427 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
54428 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
54429 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
54430 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
54431 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
54432 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
54433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54434 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54435 +4 4 4 4 4 4
54436 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
54437 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
54438 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
54439 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
54440 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54441 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
54442 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
54443 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
54444 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
54445 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
54446 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
54447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54449 +4 4 4 4 4 4
54450 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
54451 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
54452 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
54453 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54454 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
54455 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
54456 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
54457 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
54458 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
54459 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
54460 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54463 +4 4 4 4 4 4
54464 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
54465 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
54466 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
54467 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54468 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54469 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
54470 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
54471 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
54472 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
54473 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
54474 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54477 +4 4 4 4 4 4
54478 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
54479 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
54480 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54481 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54482 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54483 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
54484 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
54485 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
54486 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
54487 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
54488 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54491 +4 4 4 4 4 4
54492 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
54493 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
54494 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54495 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54496 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54497 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
54498 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
54499 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
54500 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54501 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54502 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54505 +4 4 4 4 4 4
54506 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54507 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
54508 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54509 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
54510 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
54511 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
54512 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
54513 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
54514 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54515 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54516 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54519 +4 4 4 4 4 4
54520 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54521 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
54522 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54523 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
54524 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54525 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
54526 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
54527 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
54528 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54529 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54530 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54531 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54532 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54533 +4 4 4 4 4 4
54534 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
54535 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
54536 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54537 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
54538 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
54539 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
54540 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
54541 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
54542 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54543 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54544 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54545 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54546 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54547 +4 4 4 4 4 4
54548 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
54549 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
54550 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54551 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
54552 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
54553 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
54554 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
54555 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
54556 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54557 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54558 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54560 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54561 +4 4 4 4 4 4
54562 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54563 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
54564 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54565 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
54566 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
54567 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
54568 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
54569 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
54570 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54571 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54572 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54573 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54575 +4 4 4 4 4 4
54576 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
54577 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
54578 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54579 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
54580 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
54581 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
54582 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
54583 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
54584 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
54585 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54586 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54589 +4 4 4 4 4 4
54590 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54591 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
54592 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
54593 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
54594 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
54595 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
54596 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
54597 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
54598 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54599 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54600 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54603 +4 4 4 4 4 4
54604 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54605 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
54606 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54607 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
54608 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
54609 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
54610 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
54611 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
54612 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54613 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54614 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54617 +4 4 4 4 4 4
54618 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54619 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
54620 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
54621 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
54622 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
54623 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
54624 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54625 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
54626 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54627 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54628 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54631 +4 4 4 4 4 4
54632 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54633 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
54634 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
54635 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54636 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
54637 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
54638 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54639 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
54640 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54641 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54642 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54645 +4 4 4 4 4 4
54646 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54647 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
54648 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
54649 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
54650 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
54651 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
54652 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
54653 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
54654 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
54655 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54656 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54659 +4 4 4 4 4 4
54660 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54661 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
54662 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
54663 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
54664 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
54665 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
54666 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
54667 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
54668 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
54669 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54670 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54673 +4 4 4 4 4 4
54674 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
54675 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
54676 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
54677 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
54678 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54679 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
54680 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
54681 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
54682 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
54683 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54684 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54687 +4 4 4 4 4 4
54688 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54689 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
54690 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
54691 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
54692 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
54693 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
54694 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
54695 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
54696 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
54697 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54698 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54701 +4 4 4 4 4 4
54702 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
54703 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
54704 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
54705 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
54706 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
54707 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
54708 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
54709 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
54710 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
54711 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
54712 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54715 +4 4 4 4 4 4
54716 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
54717 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54718 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
54719 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
54720 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
54721 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
54722 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
54723 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
54724 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
54725 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
54726 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54729 +4 4 4 4 4 4
54730 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
54731 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54732 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
54733 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
54734 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
54735 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
54736 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54737 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
54738 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
54739 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
54740 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54743 +4 4 4 4 4 4
54744 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
54745 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
54746 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
54747 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
54748 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
54749 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
54750 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
54751 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
54752 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
54753 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
54754 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54757 +4 4 4 4 4 4
54758 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
54759 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
54760 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54761 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
54762 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
54763 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
54764 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
54765 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
54766 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
54767 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
54768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54771 +4 4 4 4 4 4
54772 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54773 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
54774 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
54775 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
54776 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
54777 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
54778 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
54779 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
54780 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
54781 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54785 +4 4 4 4 4 4
54786 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
54787 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
54788 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
54789 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
54790 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
54791 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
54792 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
54793 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
54794 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
54795 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54798 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54799 +4 4 4 4 4 4
54800 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
54801 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
54802 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
54803 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
54804 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
54805 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
54806 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
54807 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
54808 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54809 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54810 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54812 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54813 +4 4 4 4 4 4
54814 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
54815 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54816 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
54817 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54818 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
54819 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
54820 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
54821 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
54822 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
54823 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54824 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54827 +4 4 4 4 4 4
54828 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
54829 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
54830 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
54831 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
54832 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
54833 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
54834 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
54835 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
54836 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
54837 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54841 +4 4 4 4 4 4
54842 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54843 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
54844 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
54845 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
54846 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
54847 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
54848 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
54849 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
54850 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54851 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54855 +4 4 4 4 4 4
54856 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
54857 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
54858 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54859 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
54860 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
54861 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
54862 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
54863 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
54864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54865 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54869 +4 4 4 4 4 4
54870 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
54871 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
54872 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
54873 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
54874 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
54875 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
54876 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
54877 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54883 +4 4 4 4 4 4
54884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54885 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
54886 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54887 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
54888 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
54889 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
54890 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
54891 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
54892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54897 +4 4 4 4 4 4
54898 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54899 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
54900 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
54901 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
54902 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
54903 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
54904 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
54905 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
54906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54911 +4 4 4 4 4 4
54912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54913 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54914 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
54915 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54916 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
54917 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
54918 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
54919 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54925 +4 4 4 4 4 4
54926 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54927 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54928 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54929 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
54930 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
54931 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
54932 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
54933 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54938 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54939 +4 4 4 4 4 4
54940 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54941 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54942 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54943 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54944 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
54945 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
54946 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
54947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54953 +4 4 4 4 4 4
54954 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54957 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54958 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54959 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
54960 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
54961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54967 +4 4 4 4 4 4
54968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54971 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54972 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54973 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54974 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
54975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54981 +4 4 4 4 4 4
54982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54985 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
54986 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
54987 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
54988 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
54989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54995 +4 4 4 4 4 4
54996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55000 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55001 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55002 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55009 +4 4 4 4 4 4
55010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55014 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55015 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55016 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55023 +4 4 4 4 4 4
55024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55028 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55029 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55030 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55037 +4 4 4 4 4 4
55038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55042 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55043 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55051 +4 4 4 4 4 4
55052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55056 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55057 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55065 +4 4 4 4 4 4
55066 diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55067 index a01147f..5d896f8 100644
55068 --- a/drivers/video/matrox/matroxfb_DAC1064.c
55069 +++ b/drivers/video/matrox/matroxfb_DAC1064.c
55070 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55071
55072 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55073 struct matrox_switch matrox_mystique = {
55074 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55075 + .preinit = MGA1064_preinit,
55076 + .reset = MGA1064_reset,
55077 + .init = MGA1064_init,
55078 + .restore = MGA1064_restore,
55079 };
55080 EXPORT_SYMBOL(matrox_mystique);
55081 #endif
55082
55083 #ifdef CONFIG_FB_MATROX_G
55084 struct matrox_switch matrox_G100 = {
55085 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55086 + .preinit = MGAG100_preinit,
55087 + .reset = MGAG100_reset,
55088 + .init = MGAG100_init,
55089 + .restore = MGAG100_restore,
55090 };
55091 EXPORT_SYMBOL(matrox_G100);
55092 #endif
55093 diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55094 index 195ad7c..09743fc 100644
55095 --- a/drivers/video/matrox/matroxfb_Ti3026.c
55096 +++ b/drivers/video/matrox/matroxfb_Ti3026.c
55097 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55098 }
55099
55100 struct matrox_switch matrox_millennium = {
55101 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55102 + .preinit = Ti3026_preinit,
55103 + .reset = Ti3026_reset,
55104 + .init = Ti3026_init,
55105 + .restore = Ti3026_restore
55106 };
55107 EXPORT_SYMBOL(matrox_millennium);
55108 #endif
55109 diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55110 index fe92eed..106e085 100644
55111 --- a/drivers/video/mb862xx/mb862xxfb_accel.c
55112 +++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55113 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55114 struct mb862xxfb_par *par = info->par;
55115
55116 if (info->var.bits_per_pixel == 32) {
55117 - info->fbops->fb_fillrect = cfb_fillrect;
55118 - info->fbops->fb_copyarea = cfb_copyarea;
55119 - info->fbops->fb_imageblit = cfb_imageblit;
55120 + pax_open_kernel();
55121 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55122 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55123 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55124 + pax_close_kernel();
55125 } else {
55126 outreg(disp, GC_L0EM, 3);
55127 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55128 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55129 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55130 + pax_open_kernel();
55131 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55132 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55133 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55134 + pax_close_kernel();
55135 }
55136 outreg(draw, GDC_REG_DRAW_BASE, 0);
55137 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55138 diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55139 index def0412..fed6529 100644
55140 --- a/drivers/video/nvidia/nvidia.c
55141 +++ b/drivers/video/nvidia/nvidia.c
55142 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55143 info->fix.line_length = (info->var.xres_virtual *
55144 info->var.bits_per_pixel) >> 3;
55145 if (info->var.accel_flags) {
55146 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55147 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55148 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55149 - info->fbops->fb_sync = nvidiafb_sync;
55150 + pax_open_kernel();
55151 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55152 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55153 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55154 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55155 + pax_close_kernel();
55156 info->pixmap.scan_align = 4;
55157 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55158 info->flags |= FBINFO_READS_FAST;
55159 NVResetGraphics(info);
55160 } else {
55161 - info->fbops->fb_imageblit = cfb_imageblit;
55162 - info->fbops->fb_fillrect = cfb_fillrect;
55163 - info->fbops->fb_copyarea = cfb_copyarea;
55164 - info->fbops->fb_sync = NULL;
55165 + pax_open_kernel();
55166 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55167 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55168 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55169 + *(void **)&info->fbops->fb_sync = NULL;
55170 + pax_close_kernel();
55171 info->pixmap.scan_align = 1;
55172 info->flags |= FBINFO_HWACCEL_DISABLED;
55173 info->flags &= ~FBINFO_READS_FAST;
55174 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55175 info->pixmap.size = 8 * 1024;
55176 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55177
55178 - if (!hwcur)
55179 - info->fbops->fb_cursor = NULL;
55180 + if (!hwcur) {
55181 + pax_open_kernel();
55182 + *(void **)&info->fbops->fb_cursor = NULL;
55183 + pax_close_kernel();
55184 + }
55185
55186 info->var.accel_flags = (!noaccel);
55187
55188 diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55189 index 669a81f..e216d76 100644
55190 --- a/drivers/video/omap2/dss/display.c
55191 +++ b/drivers/video/omap2/dss/display.c
55192 @@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55193 snprintf(dssdev->alias, sizeof(dssdev->alias),
55194 "display%d", disp_num_counter++);
55195
55196 + pax_open_kernel();
55197 if (drv && drv->get_resolution == NULL)
55198 - drv->get_resolution = omapdss_default_get_resolution;
55199 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55200 if (drv && drv->get_recommended_bpp == NULL)
55201 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55202 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55203 if (drv && drv->get_timings == NULL)
55204 - drv->get_timings = omapdss_default_get_timings;
55205 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55206 + pax_close_kernel();
55207
55208 mutex_lock(&panel_list_mutex);
55209 list_add_tail(&dssdev->panel_list, &panel_list);
55210 diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55211 index 83433cb..71e9b98 100644
55212 --- a/drivers/video/s1d13xxxfb.c
55213 +++ b/drivers/video/s1d13xxxfb.c
55214 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55215
55216 switch(prod_id) {
55217 case S1D13506_PROD_ID: /* activate acceleration */
55218 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55219 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55220 + pax_open_kernel();
55221 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55222 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55223 + pax_close_kernel();
55224 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55225 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55226 break;
55227 diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55228 index d513ed6..90b0de9 100644
55229 --- a/drivers/video/smscufx.c
55230 +++ b/drivers/video/smscufx.c
55231 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55232 fb_deferred_io_cleanup(info);
55233 kfree(info->fbdefio);
55234 info->fbdefio = NULL;
55235 - info->fbops->fb_mmap = ufx_ops_mmap;
55236 + pax_open_kernel();
55237 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55238 + pax_close_kernel();
55239 }
55240
55241 pr_debug("released /dev/fb%d user=%d count=%d",
55242 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55243 index 77b890e..458e666 100644
55244 --- a/drivers/video/udlfb.c
55245 +++ b/drivers/video/udlfb.c
55246 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55247 dlfb_urb_completion(urb);
55248
55249 error:
55250 - atomic_add(bytes_sent, &dev->bytes_sent);
55251 - atomic_add(bytes_identical, &dev->bytes_identical);
55252 - atomic_add(width*height*2, &dev->bytes_rendered);
55253 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55254 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55255 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55256 end_cycles = get_cycles();
55257 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55258 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55259 >> 10)), /* Kcycles */
55260 &dev->cpu_kcycles_used);
55261
55262 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55263 dlfb_urb_completion(urb);
55264
55265 error:
55266 - atomic_add(bytes_sent, &dev->bytes_sent);
55267 - atomic_add(bytes_identical, &dev->bytes_identical);
55268 - atomic_add(bytes_rendered, &dev->bytes_rendered);
55269 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55270 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55271 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55272 end_cycles = get_cycles();
55273 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55274 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55275 >> 10)), /* Kcycles */
55276 &dev->cpu_kcycles_used);
55277 }
55278 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55279 fb_deferred_io_cleanup(info);
55280 kfree(info->fbdefio);
55281 info->fbdefio = NULL;
55282 - info->fbops->fb_mmap = dlfb_ops_mmap;
55283 + pax_open_kernel();
55284 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55285 + pax_close_kernel();
55286 }
55287
55288 pr_warn("released /dev/fb%d user=%d count=%d\n",
55289 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55290 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55291 struct dlfb_data *dev = fb_info->par;
55292 return snprintf(buf, PAGE_SIZE, "%u\n",
55293 - atomic_read(&dev->bytes_rendered));
55294 + atomic_read_unchecked(&dev->bytes_rendered));
55295 }
55296
55297 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55298 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55299 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55300 struct dlfb_data *dev = fb_info->par;
55301 return snprintf(buf, PAGE_SIZE, "%u\n",
55302 - atomic_read(&dev->bytes_identical));
55303 + atomic_read_unchecked(&dev->bytes_identical));
55304 }
55305
55306 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55307 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55308 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55309 struct dlfb_data *dev = fb_info->par;
55310 return snprintf(buf, PAGE_SIZE, "%u\n",
55311 - atomic_read(&dev->bytes_sent));
55312 + atomic_read_unchecked(&dev->bytes_sent));
55313 }
55314
55315 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55316 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55317 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55318 struct dlfb_data *dev = fb_info->par;
55319 return snprintf(buf, PAGE_SIZE, "%u\n",
55320 - atomic_read(&dev->cpu_kcycles_used));
55321 + atomic_read_unchecked(&dev->cpu_kcycles_used));
55322 }
55323
55324 static ssize_t edid_show(
55325 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55326 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55327 struct dlfb_data *dev = fb_info->par;
55328
55329 - atomic_set(&dev->bytes_rendered, 0);
55330 - atomic_set(&dev->bytes_identical, 0);
55331 - atomic_set(&dev->bytes_sent, 0);
55332 - atomic_set(&dev->cpu_kcycles_used, 0);
55333 + atomic_set_unchecked(&dev->bytes_rendered, 0);
55334 + atomic_set_unchecked(&dev->bytes_identical, 0);
55335 + atomic_set_unchecked(&dev->bytes_sent, 0);
55336 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55337
55338 return count;
55339 }
55340 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
55341 index 256fba7..6e75516 100644
55342 --- a/drivers/video/uvesafb.c
55343 +++ b/drivers/video/uvesafb.c
55344 @@ -19,6 +19,7 @@
55345 #include <linux/io.h>
55346 #include <linux/mutex.h>
55347 #include <linux/slab.h>
55348 +#include <linux/moduleloader.h>
55349 #include <video/edid.h>
55350 #include <video/uvesafb.h>
55351 #ifdef CONFIG_X86
55352 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55353 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55354 par->pmi_setpal = par->ypan = 0;
55355 } else {
55356 +
55357 +#ifdef CONFIG_PAX_KERNEXEC
55358 +#ifdef CONFIG_MODULES
55359 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55360 +#endif
55361 + if (!par->pmi_code) {
55362 + par->pmi_setpal = par->ypan = 0;
55363 + return 0;
55364 + }
55365 +#endif
55366 +
55367 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55368 + task->t.regs.edi);
55369 +
55370 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55371 + pax_open_kernel();
55372 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55373 + pax_close_kernel();
55374 +
55375 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55376 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55377 +#else
55378 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55379 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55380 +#endif
55381 +
55382 printk(KERN_INFO "uvesafb: protected mode interface info at "
55383 "%04x:%04x\n",
55384 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55385 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55386 par->ypan = ypan;
55387
55388 if (par->pmi_setpal || par->ypan) {
55389 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55390 if (__supported_pte_mask & _PAGE_NX) {
55391 par->pmi_setpal = par->ypan = 0;
55392 printk(KERN_WARNING "uvesafb: NX protection is active, "
55393 "better not use the PMI.\n");
55394 - } else {
55395 + } else
55396 +#endif
55397 uvesafb_vbe_getpmi(task, par);
55398 - }
55399 }
55400 #else
55401 /* The protected mode interface is not available on non-x86. */
55402 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55403 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55404
55405 /* Disable blanking if the user requested so. */
55406 - if (!blank)
55407 - info->fbops->fb_blank = NULL;
55408 + if (!blank) {
55409 + pax_open_kernel();
55410 + *(void **)&info->fbops->fb_blank = NULL;
55411 + pax_close_kernel();
55412 + }
55413
55414 /*
55415 * Find out how much IO memory is required for the mode with
55416 @@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55417 info->flags = FBINFO_FLAG_DEFAULT |
55418 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55419
55420 - if (!par->ypan)
55421 - info->fbops->fb_pan_display = NULL;
55422 + if (!par->ypan) {
55423 + pax_open_kernel();
55424 + *(void **)&info->fbops->fb_pan_display = NULL;
55425 + pax_close_kernel();
55426 + }
55427 }
55428
55429 static void uvesafb_init_mtrr(struct fb_info *info)
55430 @@ -1792,6 +1822,11 @@ out_mode:
55431 out:
55432 kfree(par->vbe_modes);
55433
55434 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55435 + if (par->pmi_code)
55436 + module_free_exec(NULL, par->pmi_code);
55437 +#endif
55438 +
55439 framebuffer_release(info);
55440 return err;
55441 }
55442 @@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
55443 kfree(par->vbe_modes);
55444 kfree(par->vbe_state_orig);
55445 kfree(par->vbe_state_saved);
55446 +
55447 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55448 + if (par->pmi_code)
55449 + module_free_exec(NULL, par->pmi_code);
55450 +#endif
55451 +
55452 }
55453
55454 framebuffer_release(info);
55455 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
55456 index 1c7da3b..56ea0bd 100644
55457 --- a/drivers/video/vesafb.c
55458 +++ b/drivers/video/vesafb.c
55459 @@ -9,6 +9,7 @@
55460 */
55461
55462 #include <linux/module.h>
55463 +#include <linux/moduleloader.h>
55464 #include <linux/kernel.h>
55465 #include <linux/errno.h>
55466 #include <linux/string.h>
55467 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55468 static int vram_total; /* Set total amount of memory */
55469 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55470 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55471 -static void (*pmi_start)(void) __read_mostly;
55472 -static void (*pmi_pal) (void) __read_mostly;
55473 +static void (*pmi_start)(void) __read_only;
55474 +static void (*pmi_pal) (void) __read_only;
55475 static int depth __read_mostly;
55476 static int vga_compat __read_mostly;
55477 /* --------------------------------------------------------------------- */
55478 @@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
55479 unsigned int size_remap;
55480 unsigned int size_total;
55481 char *option = NULL;
55482 + void *pmi_code = NULL;
55483
55484 /* ignore error return of fb_get_options */
55485 fb_get_options("vesafb", &option);
55486 @@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
55487 size_remap = size_total;
55488 vesafb_fix.smem_len = size_remap;
55489
55490 -#ifndef __i386__
55491 - screen_info.vesapm_seg = 0;
55492 -#endif
55493 -
55494 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55495 printk(KERN_WARNING
55496 "vesafb: cannot reserve video memory at 0x%lx\n",
55497 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55498 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55499 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55500
55501 +#ifdef __i386__
55502 +
55503 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55504 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
55505 + if (!pmi_code)
55506 +#elif !defined(CONFIG_PAX_KERNEXEC)
55507 + if (0)
55508 +#endif
55509 +
55510 +#endif
55511 + screen_info.vesapm_seg = 0;
55512 +
55513 if (screen_info.vesapm_seg) {
55514 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55515 - screen_info.vesapm_seg,screen_info.vesapm_off);
55516 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55517 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55518 }
55519
55520 if (screen_info.vesapm_seg < 0xc000)
55521 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55522
55523 if (ypan || pmi_setpal) {
55524 unsigned short *pmi_base;
55525 +
55526 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55527 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55528 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55529 +
55530 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55531 + pax_open_kernel();
55532 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55533 +#else
55534 + pmi_code = pmi_base;
55535 +#endif
55536 +
55537 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55538 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55539 +
55540 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55541 + pmi_start = ktva_ktla(pmi_start);
55542 + pmi_pal = ktva_ktla(pmi_pal);
55543 + pax_close_kernel();
55544 +#endif
55545 +
55546 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55547 if (pmi_base[3]) {
55548 printk(KERN_INFO "vesafb: pmi: ports = ");
55549 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55550 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55551 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55552
55553 - if (!ypan)
55554 - info->fbops->fb_pan_display = NULL;
55555 + if (!ypan) {
55556 + pax_open_kernel();
55557 + *(void **)&info->fbops->fb_pan_display = NULL;
55558 + pax_close_kernel();
55559 + }
55560
55561 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55562 err = -ENOMEM;
55563 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55564 fb_info(info, "%s frame buffer device\n", info->fix.id);
55565 return 0;
55566 err:
55567 +
55568 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55569 + module_free_exec(NULL, pmi_code);
55570 +#endif
55571 +
55572 if (info->screen_base)
55573 iounmap(info->screen_base);
55574 framebuffer_release(info);
55575 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
55576 index 88714ae..16c2e11 100644
55577 --- a/drivers/video/via/via_clock.h
55578 +++ b/drivers/video/via/via_clock.h
55579 @@ -56,7 +56,7 @@ struct via_clock {
55580
55581 void (*set_engine_pll_state)(u8 state);
55582 void (*set_engine_pll)(struct via_pll_config config);
55583 -};
55584 +} __no_const;
55585
55586
55587 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55588 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
55589 index fef20db..d28b1ab 100644
55590 --- a/drivers/xen/xenfs/xenstored.c
55591 +++ b/drivers/xen/xenfs/xenstored.c
55592 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
55593 static int xsd_kva_open(struct inode *inode, struct file *file)
55594 {
55595 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
55596 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55597 + NULL);
55598 +#else
55599 xen_store_interface);
55600 +#endif
55601 +
55602 if (!file->private_data)
55603 return -ENOMEM;
55604 return 0;
55605 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
55606 index c71e886..61d3d44b 100644
55607 --- a/fs/9p/vfs_addr.c
55608 +++ b/fs/9p/vfs_addr.c
55609 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
55610
55611 retval = v9fs_file_write_internal(inode,
55612 v9inode->writeback_fid,
55613 - (__force const char __user *)buffer,
55614 + (const char __force_user *)buffer,
55615 len, &offset, 0);
55616 if (retval > 0)
55617 retval = 0;
55618 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
55619 index bb7991c..481e21a 100644
55620 --- a/fs/9p/vfs_inode.c
55621 +++ b/fs/9p/vfs_inode.c
55622 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55623 void
55624 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55625 {
55626 - char *s = nd_get_link(nd);
55627 + const char *s = nd_get_link(nd);
55628
55629 p9_debug(P9_DEBUG_VFS, " %s %s\n",
55630 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
55631 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
55632 index 370b24c..ff0be7b 100644
55633 --- a/fs/Kconfig.binfmt
55634 +++ b/fs/Kconfig.binfmt
55635 @@ -103,7 +103,7 @@ config HAVE_AOUT
55636
55637 config BINFMT_AOUT
55638 tristate "Kernel support for a.out and ECOFF binaries"
55639 - depends on HAVE_AOUT
55640 + depends on HAVE_AOUT && BROKEN
55641 ---help---
55642 A.out (Assembler.OUTput) is a set of formats for libraries and
55643 executables used in the earliest versions of UNIX. Linux used
55644 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
55645 index ce25d75..dc09eeb 100644
55646 --- a/fs/afs/inode.c
55647 +++ b/fs/afs/inode.c
55648 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55649 struct afs_vnode *vnode;
55650 struct super_block *sb;
55651 struct inode *inode;
55652 - static atomic_t afs_autocell_ino;
55653 + static atomic_unchecked_t afs_autocell_ino;
55654
55655 _enter("{%x:%u},%*.*s,",
55656 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
55657 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55658 data.fid.unique = 0;
55659 data.fid.vnode = 0;
55660
55661 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
55662 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
55663 afs_iget5_autocell_test, afs_iget5_set,
55664 &data);
55665 if (!inode) {
55666 diff --git a/fs/aio.c b/fs/aio.c
55667 index 062a5f6..e5618e0 100644
55668 --- a/fs/aio.c
55669 +++ b/fs/aio.c
55670 @@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
55671 size += sizeof(struct io_event) * nr_events;
55672
55673 nr_pages = PFN_UP(size);
55674 - if (nr_pages < 0)
55675 + if (nr_pages <= 0)
55676 return -EINVAL;
55677
55678 file = aio_private_file(ctx, nr_pages);
55679 diff --git a/fs/attr.c b/fs/attr.c
55680 index 5d4e59d..fd02418 100644
55681 --- a/fs/attr.c
55682 +++ b/fs/attr.c
55683 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
55684 unsigned long limit;
55685
55686 limit = rlimit(RLIMIT_FSIZE);
55687 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
55688 if (limit != RLIM_INFINITY && offset > limit)
55689 goto out_sig;
55690 if (offset > inode->i_sb->s_maxbytes)
55691 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
55692 index 116fd38..c04182da 100644
55693 --- a/fs/autofs4/waitq.c
55694 +++ b/fs/autofs4/waitq.c
55695 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
55696 {
55697 unsigned long sigpipe, flags;
55698 mm_segment_t fs;
55699 - const char *data = (const char *)addr;
55700 + const char __user *data = (const char __force_user *)addr;
55701 ssize_t wr = 0;
55702
55703 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
55704 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55705 return 1;
55706 }
55707
55708 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55709 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
55710 +#endif
55711 +
55712 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55713 enum autofs_notify notify)
55714 {
55715 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55716
55717 /* If this is a direct mount request create a dummy name */
55718 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
55719 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55720 + /* this name does get written to userland via autofs4_write() */
55721 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
55722 +#else
55723 qstr.len = sprintf(name, "%p", dentry);
55724 +#endif
55725 else {
55726 qstr.len = autofs4_getpath(sbi, dentry, &name);
55727 if (!qstr.len) {
55728 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
55729 index 2722387..56059b5 100644
55730 --- a/fs/befs/endian.h
55731 +++ b/fs/befs/endian.h
55732 @@ -11,7 +11,7 @@
55733
55734 #include <asm/byteorder.h>
55735
55736 -static inline u64
55737 +static inline u64 __intentional_overflow(-1)
55738 fs64_to_cpu(const struct super_block *sb, fs64 n)
55739 {
55740 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55741 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
55742 return (__force fs64)cpu_to_be64(n);
55743 }
55744
55745 -static inline u32
55746 +static inline u32 __intentional_overflow(-1)
55747 fs32_to_cpu(const struct super_block *sb, fs32 n)
55748 {
55749 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55750 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
55751 return (__force fs32)cpu_to_be32(n);
55752 }
55753
55754 -static inline u16
55755 +static inline u16 __intentional_overflow(-1)
55756 fs16_to_cpu(const struct super_block *sb, fs16 n)
55757 {
55758 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55759 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
55760 index ca0ba15..0fa3257 100644
55761 --- a/fs/binfmt_aout.c
55762 +++ b/fs/binfmt_aout.c
55763 @@ -16,6 +16,7 @@
55764 #include <linux/string.h>
55765 #include <linux/fs.h>
55766 #include <linux/file.h>
55767 +#include <linux/security.h>
55768 #include <linux/stat.h>
55769 #include <linux/fcntl.h>
55770 #include <linux/ptrace.h>
55771 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
55772 #endif
55773 # define START_STACK(u) ((void __user *)u.start_stack)
55774
55775 + memset(&dump, 0, sizeof(dump));
55776 +
55777 fs = get_fs();
55778 set_fs(KERNEL_DS);
55779 has_dumped = 1;
55780 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
55781
55782 /* If the size of the dump file exceeds the rlimit, then see what would happen
55783 if we wrote the stack, but not the data area. */
55784 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
55785 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
55786 dump.u_dsize = 0;
55787
55788 /* Make sure we have enough room to write the stack and data areas. */
55789 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
55790 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
55791 dump.u_ssize = 0;
55792
55793 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
55794 rlim = rlimit(RLIMIT_DATA);
55795 if (rlim >= RLIM_INFINITY)
55796 rlim = ~0;
55797 +
55798 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
55799 if (ex.a_data + ex.a_bss > rlim)
55800 return -ENOMEM;
55801
55802 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
55803
55804 install_exec_creds(bprm);
55805
55806 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55807 + current->mm->pax_flags = 0UL;
55808 +#endif
55809 +
55810 +#ifdef CONFIG_PAX_PAGEEXEC
55811 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
55812 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
55813 +
55814 +#ifdef CONFIG_PAX_EMUTRAMP
55815 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
55816 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
55817 +#endif
55818 +
55819 +#ifdef CONFIG_PAX_MPROTECT
55820 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
55821 + current->mm->pax_flags |= MF_PAX_MPROTECT;
55822 +#endif
55823 +
55824 + }
55825 +#endif
55826 +
55827 if (N_MAGIC(ex) == OMAGIC) {
55828 unsigned long text_addr, map_size;
55829 loff_t pos;
55830 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
55831 }
55832
55833 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
55834 - PROT_READ | PROT_WRITE | PROT_EXEC,
55835 + PROT_READ | PROT_WRITE,
55836 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
55837 fd_offset + ex.a_text);
55838 if (error != N_DATADDR(ex)) {
55839 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
55840 index 67be295..83e2f86 100644
55841 --- a/fs/binfmt_elf.c
55842 +++ b/fs/binfmt_elf.c
55843 @@ -34,6 +34,7 @@
55844 #include <linux/utsname.h>
55845 #include <linux/coredump.h>
55846 #include <linux/sched.h>
55847 +#include <linux/xattr.h>
55848 #include <asm/uaccess.h>
55849 #include <asm/param.h>
55850 #include <asm/page.h>
55851 @@ -48,7 +49,7 @@
55852 static int load_elf_binary(struct linux_binprm *bprm);
55853 static int load_elf_library(struct file *);
55854 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
55855 - int, int, unsigned long);
55856 + int, int, unsigned long) __intentional_overflow(-1);
55857
55858 /*
55859 * If we don't support core dumping, then supply a NULL so we
55860 @@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
55861 #define elf_core_dump NULL
55862 #endif
55863
55864 +#ifdef CONFIG_PAX_MPROTECT
55865 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
55866 +#endif
55867 +
55868 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55869 +static void elf_handle_mmap(struct file *file);
55870 +#endif
55871 +
55872 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
55873 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
55874 #else
55875 @@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
55876 .load_binary = load_elf_binary,
55877 .load_shlib = load_elf_library,
55878 .core_dump = elf_core_dump,
55879 +
55880 +#ifdef CONFIG_PAX_MPROTECT
55881 + .handle_mprotect= elf_handle_mprotect,
55882 +#endif
55883 +
55884 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55885 + .handle_mmap = elf_handle_mmap,
55886 +#endif
55887 +
55888 .min_coredump = ELF_EXEC_PAGESIZE,
55889 };
55890
55891 @@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
55892
55893 static int set_brk(unsigned long start, unsigned long end)
55894 {
55895 + unsigned long e = end;
55896 +
55897 start = ELF_PAGEALIGN(start);
55898 end = ELF_PAGEALIGN(end);
55899 if (end > start) {
55900 @@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
55901 if (BAD_ADDR(addr))
55902 return addr;
55903 }
55904 - current->mm->start_brk = current->mm->brk = end;
55905 + current->mm->start_brk = current->mm->brk = e;
55906 return 0;
55907 }
55908
55909 @@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55910 elf_addr_t __user *u_rand_bytes;
55911 const char *k_platform = ELF_PLATFORM;
55912 const char *k_base_platform = ELF_BASE_PLATFORM;
55913 - unsigned char k_rand_bytes[16];
55914 + u32 k_rand_bytes[4];
55915 int items;
55916 elf_addr_t *elf_info;
55917 int ei_index = 0;
55918 const struct cred *cred = current_cred();
55919 struct vm_area_struct *vma;
55920 + unsigned long saved_auxv[AT_VECTOR_SIZE];
55921
55922 /*
55923 * In some cases (e.g. Hyper-Threading), we want to avoid L1
55924 @@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55925 * Generate 16 random bytes for userspace PRNG seeding.
55926 */
55927 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
55928 - u_rand_bytes = (elf_addr_t __user *)
55929 - STACK_ALLOC(p, sizeof(k_rand_bytes));
55930 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
55931 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
55932 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
55933 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
55934 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
55935 + u_rand_bytes = (elf_addr_t __user *) p;
55936 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
55937 return -EFAULT;
55938
55939 @@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55940 return -EFAULT;
55941 current->mm->env_end = p;
55942
55943 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
55944 +
55945 /* Put the elf_info on the stack in the right place. */
55946 sp = (elf_addr_t __user *)envp + 1;
55947 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
55948 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
55949 return -EFAULT;
55950 return 0;
55951 }
55952 @@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
55953 an ELF header */
55954
55955 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55956 - struct file *interpreter, unsigned long *interp_map_addr,
55957 - unsigned long no_base)
55958 + struct file *interpreter, unsigned long no_base)
55959 {
55960 struct elf_phdr *elf_phdata;
55961 struct elf_phdr *eppnt;
55962 - unsigned long load_addr = 0;
55963 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
55964 int load_addr_set = 0;
55965 unsigned long last_bss = 0, elf_bss = 0;
55966 - unsigned long error = ~0UL;
55967 + unsigned long error = -EINVAL;
55968 unsigned long total_size;
55969 int retval, i, size;
55970
55971 @@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55972 goto out_close;
55973 }
55974
55975 +#ifdef CONFIG_PAX_SEGMEXEC
55976 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
55977 + pax_task_size = SEGMEXEC_TASK_SIZE;
55978 +#endif
55979 +
55980 eppnt = elf_phdata;
55981 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
55982 if (eppnt->p_type == PT_LOAD) {
55983 @@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55984 map_addr = elf_map(interpreter, load_addr + vaddr,
55985 eppnt, elf_prot, elf_type, total_size);
55986 total_size = 0;
55987 - if (!*interp_map_addr)
55988 - *interp_map_addr = map_addr;
55989 error = map_addr;
55990 if (BAD_ADDR(map_addr))
55991 goto out_close;
55992 @@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55993 k = load_addr + eppnt->p_vaddr;
55994 if (BAD_ADDR(k) ||
55995 eppnt->p_filesz > eppnt->p_memsz ||
55996 - eppnt->p_memsz > TASK_SIZE ||
55997 - TASK_SIZE - eppnt->p_memsz < k) {
55998 + eppnt->p_memsz > pax_task_size ||
55999 + pax_task_size - eppnt->p_memsz < k) {
56000 error = -ENOMEM;
56001 goto out_close;
56002 }
56003 @@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56004 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56005
56006 /* Map the last of the bss segment */
56007 - error = vm_brk(elf_bss, last_bss - elf_bss);
56008 - if (BAD_ADDR(error))
56009 - goto out_close;
56010 + if (last_bss > elf_bss) {
56011 + error = vm_brk(elf_bss, last_bss - elf_bss);
56012 + if (BAD_ADDR(error))
56013 + goto out_close;
56014 + }
56015 }
56016
56017 error = load_addr;
56018 @@ -538,6 +569,336 @@ out:
56019 return error;
56020 }
56021
56022 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56023 +#ifdef CONFIG_PAX_SOFTMODE
56024 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56025 +{
56026 + unsigned long pax_flags = 0UL;
56027 +
56028 +#ifdef CONFIG_PAX_PAGEEXEC
56029 + if (elf_phdata->p_flags & PF_PAGEEXEC)
56030 + pax_flags |= MF_PAX_PAGEEXEC;
56031 +#endif
56032 +
56033 +#ifdef CONFIG_PAX_SEGMEXEC
56034 + if (elf_phdata->p_flags & PF_SEGMEXEC)
56035 + pax_flags |= MF_PAX_SEGMEXEC;
56036 +#endif
56037 +
56038 +#ifdef CONFIG_PAX_EMUTRAMP
56039 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56040 + pax_flags |= MF_PAX_EMUTRAMP;
56041 +#endif
56042 +
56043 +#ifdef CONFIG_PAX_MPROTECT
56044 + if (elf_phdata->p_flags & PF_MPROTECT)
56045 + pax_flags |= MF_PAX_MPROTECT;
56046 +#endif
56047 +
56048 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56049 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56050 + pax_flags |= MF_PAX_RANDMMAP;
56051 +#endif
56052 +
56053 + return pax_flags;
56054 +}
56055 +#endif
56056 +
56057 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56058 +{
56059 + unsigned long pax_flags = 0UL;
56060 +
56061 +#ifdef CONFIG_PAX_PAGEEXEC
56062 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56063 + pax_flags |= MF_PAX_PAGEEXEC;
56064 +#endif
56065 +
56066 +#ifdef CONFIG_PAX_SEGMEXEC
56067 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56068 + pax_flags |= MF_PAX_SEGMEXEC;
56069 +#endif
56070 +
56071 +#ifdef CONFIG_PAX_EMUTRAMP
56072 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56073 + pax_flags |= MF_PAX_EMUTRAMP;
56074 +#endif
56075 +
56076 +#ifdef CONFIG_PAX_MPROTECT
56077 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56078 + pax_flags |= MF_PAX_MPROTECT;
56079 +#endif
56080 +
56081 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56082 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56083 + pax_flags |= MF_PAX_RANDMMAP;
56084 +#endif
56085 +
56086 + return pax_flags;
56087 +}
56088 +#endif
56089 +
56090 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56091 +#ifdef CONFIG_PAX_SOFTMODE
56092 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56093 +{
56094 + unsigned long pax_flags = 0UL;
56095 +
56096 +#ifdef CONFIG_PAX_PAGEEXEC
56097 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56098 + pax_flags |= MF_PAX_PAGEEXEC;
56099 +#endif
56100 +
56101 +#ifdef CONFIG_PAX_SEGMEXEC
56102 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56103 + pax_flags |= MF_PAX_SEGMEXEC;
56104 +#endif
56105 +
56106 +#ifdef CONFIG_PAX_EMUTRAMP
56107 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56108 + pax_flags |= MF_PAX_EMUTRAMP;
56109 +#endif
56110 +
56111 +#ifdef CONFIG_PAX_MPROTECT
56112 + if (pax_flags_softmode & MF_PAX_MPROTECT)
56113 + pax_flags |= MF_PAX_MPROTECT;
56114 +#endif
56115 +
56116 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56117 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56118 + pax_flags |= MF_PAX_RANDMMAP;
56119 +#endif
56120 +
56121 + return pax_flags;
56122 +}
56123 +#endif
56124 +
56125 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56126 +{
56127 + unsigned long pax_flags = 0UL;
56128 +
56129 +#ifdef CONFIG_PAX_PAGEEXEC
56130 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56131 + pax_flags |= MF_PAX_PAGEEXEC;
56132 +#endif
56133 +
56134 +#ifdef CONFIG_PAX_SEGMEXEC
56135 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56136 + pax_flags |= MF_PAX_SEGMEXEC;
56137 +#endif
56138 +
56139 +#ifdef CONFIG_PAX_EMUTRAMP
56140 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56141 + pax_flags |= MF_PAX_EMUTRAMP;
56142 +#endif
56143 +
56144 +#ifdef CONFIG_PAX_MPROTECT
56145 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56146 + pax_flags |= MF_PAX_MPROTECT;
56147 +#endif
56148 +
56149 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56150 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56151 + pax_flags |= MF_PAX_RANDMMAP;
56152 +#endif
56153 +
56154 + return pax_flags;
56155 +}
56156 +#endif
56157 +
56158 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56159 +static unsigned long pax_parse_defaults(void)
56160 +{
56161 + unsigned long pax_flags = 0UL;
56162 +
56163 +#ifdef CONFIG_PAX_SOFTMODE
56164 + if (pax_softmode)
56165 + return pax_flags;
56166 +#endif
56167 +
56168 +#ifdef CONFIG_PAX_PAGEEXEC
56169 + pax_flags |= MF_PAX_PAGEEXEC;
56170 +#endif
56171 +
56172 +#ifdef CONFIG_PAX_SEGMEXEC
56173 + pax_flags |= MF_PAX_SEGMEXEC;
56174 +#endif
56175 +
56176 +#ifdef CONFIG_PAX_MPROTECT
56177 + pax_flags |= MF_PAX_MPROTECT;
56178 +#endif
56179 +
56180 +#ifdef CONFIG_PAX_RANDMMAP
56181 + if (randomize_va_space)
56182 + pax_flags |= MF_PAX_RANDMMAP;
56183 +#endif
56184 +
56185 + return pax_flags;
56186 +}
56187 +
56188 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56189 +{
56190 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56191 +
56192 +#ifdef CONFIG_PAX_EI_PAX
56193 +
56194 +#ifdef CONFIG_PAX_SOFTMODE
56195 + if (pax_softmode)
56196 + return pax_flags;
56197 +#endif
56198 +
56199 + pax_flags = 0UL;
56200 +
56201 +#ifdef CONFIG_PAX_PAGEEXEC
56202 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56203 + pax_flags |= MF_PAX_PAGEEXEC;
56204 +#endif
56205 +
56206 +#ifdef CONFIG_PAX_SEGMEXEC
56207 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56208 + pax_flags |= MF_PAX_SEGMEXEC;
56209 +#endif
56210 +
56211 +#ifdef CONFIG_PAX_EMUTRAMP
56212 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56213 + pax_flags |= MF_PAX_EMUTRAMP;
56214 +#endif
56215 +
56216 +#ifdef CONFIG_PAX_MPROTECT
56217 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56218 + pax_flags |= MF_PAX_MPROTECT;
56219 +#endif
56220 +
56221 +#ifdef CONFIG_PAX_ASLR
56222 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56223 + pax_flags |= MF_PAX_RANDMMAP;
56224 +#endif
56225 +
56226 +#endif
56227 +
56228 + return pax_flags;
56229 +
56230 +}
56231 +
56232 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56233 +{
56234 +
56235 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56236 + unsigned long i;
56237 +
56238 + for (i = 0UL; i < elf_ex->e_phnum; i++)
56239 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56240 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56241 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56242 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56243 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56244 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56245 + return PAX_PARSE_FLAGS_FALLBACK;
56246 +
56247 +#ifdef CONFIG_PAX_SOFTMODE
56248 + if (pax_softmode)
56249 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56250 + else
56251 +#endif
56252 +
56253 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56254 + break;
56255 + }
56256 +#endif
56257 +
56258 + return PAX_PARSE_FLAGS_FALLBACK;
56259 +}
56260 +
56261 +static unsigned long pax_parse_xattr_pax(struct file * const file)
56262 +{
56263 +
56264 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56265 + ssize_t xattr_size, i;
56266 + unsigned char xattr_value[sizeof("pemrs") - 1];
56267 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56268 +
56269 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56270 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56271 + return PAX_PARSE_FLAGS_FALLBACK;
56272 +
56273 + for (i = 0; i < xattr_size; i++)
56274 + switch (xattr_value[i]) {
56275 + default:
56276 + return PAX_PARSE_FLAGS_FALLBACK;
56277 +
56278 +#define parse_flag(option1, option2, flag) \
56279 + case option1: \
56280 + if (pax_flags_hardmode & MF_PAX_##flag) \
56281 + return PAX_PARSE_FLAGS_FALLBACK;\
56282 + pax_flags_hardmode |= MF_PAX_##flag; \
56283 + break; \
56284 + case option2: \
56285 + if (pax_flags_softmode & MF_PAX_##flag) \
56286 + return PAX_PARSE_FLAGS_FALLBACK;\
56287 + pax_flags_softmode |= MF_PAX_##flag; \
56288 + break;
56289 +
56290 + parse_flag('p', 'P', PAGEEXEC);
56291 + parse_flag('e', 'E', EMUTRAMP);
56292 + parse_flag('m', 'M', MPROTECT);
56293 + parse_flag('r', 'R', RANDMMAP);
56294 + parse_flag('s', 'S', SEGMEXEC);
56295 +
56296 +#undef parse_flag
56297 + }
56298 +
56299 + if (pax_flags_hardmode & pax_flags_softmode)
56300 + return PAX_PARSE_FLAGS_FALLBACK;
56301 +
56302 +#ifdef CONFIG_PAX_SOFTMODE
56303 + if (pax_softmode)
56304 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56305 + else
56306 +#endif
56307 +
56308 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56309 +#else
56310 + return PAX_PARSE_FLAGS_FALLBACK;
56311 +#endif
56312 +
56313 +}
56314 +
56315 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56316 +{
56317 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56318 +
56319 + pax_flags = pax_parse_defaults();
56320 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
56321 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56322 + xattr_pax_flags = pax_parse_xattr_pax(file);
56323 +
56324 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56325 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56326 + pt_pax_flags != xattr_pax_flags)
56327 + return -EINVAL;
56328 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56329 + pax_flags = xattr_pax_flags;
56330 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56331 + pax_flags = pt_pax_flags;
56332 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56333 + pax_flags = ei_pax_flags;
56334 +
56335 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56336 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56337 + if ((__supported_pte_mask & _PAGE_NX))
56338 + pax_flags &= ~MF_PAX_SEGMEXEC;
56339 + else
56340 + pax_flags &= ~MF_PAX_PAGEEXEC;
56341 + }
56342 +#endif
56343 +
56344 + if (0 > pax_check_flags(&pax_flags))
56345 + return -EINVAL;
56346 +
56347 + current->mm->pax_flags = pax_flags;
56348 + return 0;
56349 +}
56350 +#endif
56351 +
56352 /*
56353 * These are the functions used to load ELF style executables and shared
56354 * libraries. There is no binary dependent code anywhere else.
56355 @@ -551,6 +912,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56356 {
56357 unsigned int random_variable = 0;
56358
56359 +#ifdef CONFIG_PAX_RANDUSTACK
56360 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56361 + return stack_top - current->mm->delta_stack;
56362 +#endif
56363 +
56364 if ((current->flags & PF_RANDOMIZE) &&
56365 !(current->personality & ADDR_NO_RANDOMIZE)) {
56366 random_variable = get_random_int() & STACK_RND_MASK;
56367 @@ -569,7 +935,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56368 unsigned long load_addr = 0, load_bias = 0;
56369 int load_addr_set = 0;
56370 char * elf_interpreter = NULL;
56371 - unsigned long error;
56372 + unsigned long error = 0;
56373 struct elf_phdr *elf_ppnt, *elf_phdata;
56374 unsigned long elf_bss, elf_brk;
56375 int retval, i;
56376 @@ -579,12 +945,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
56377 unsigned long start_code, end_code, start_data, end_data;
56378 unsigned long reloc_func_desc __maybe_unused = 0;
56379 int executable_stack = EXSTACK_DEFAULT;
56380 - unsigned long def_flags = 0;
56381 struct pt_regs *regs = current_pt_regs();
56382 struct {
56383 struct elfhdr elf_ex;
56384 struct elfhdr interp_elf_ex;
56385 } *loc;
56386 + unsigned long pax_task_size;
56387
56388 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56389 if (!loc) {
56390 @@ -720,11 +1086,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
56391 goto out_free_dentry;
56392
56393 /* OK, This is the point of no return */
56394 - current->mm->def_flags = def_flags;
56395 + current->mm->def_flags = 0;
56396
56397 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56398 may depend on the personality. */
56399 SET_PERSONALITY(loc->elf_ex);
56400 +
56401 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56402 + current->mm->pax_flags = 0UL;
56403 +#endif
56404 +
56405 +#ifdef CONFIG_PAX_DLRESOLVE
56406 + current->mm->call_dl_resolve = 0UL;
56407 +#endif
56408 +
56409 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56410 + current->mm->call_syscall = 0UL;
56411 +#endif
56412 +
56413 +#ifdef CONFIG_PAX_ASLR
56414 + current->mm->delta_mmap = 0UL;
56415 + current->mm->delta_stack = 0UL;
56416 +#endif
56417 +
56418 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56419 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56420 + send_sig(SIGKILL, current, 0);
56421 + goto out_free_dentry;
56422 + }
56423 +#endif
56424 +
56425 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56426 + pax_set_initial_flags(bprm);
56427 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56428 + if (pax_set_initial_flags_func)
56429 + (pax_set_initial_flags_func)(bprm);
56430 +#endif
56431 +
56432 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56433 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56434 + current->mm->context.user_cs_limit = PAGE_SIZE;
56435 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56436 + }
56437 +#endif
56438 +
56439 +#ifdef CONFIG_PAX_SEGMEXEC
56440 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56441 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56442 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56443 + pax_task_size = SEGMEXEC_TASK_SIZE;
56444 + current->mm->def_flags |= VM_NOHUGEPAGE;
56445 + } else
56446 +#endif
56447 +
56448 + pax_task_size = TASK_SIZE;
56449 +
56450 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56451 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56452 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56453 + put_cpu();
56454 + }
56455 +#endif
56456 +
56457 +#ifdef CONFIG_PAX_ASLR
56458 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56459 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56460 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56461 + }
56462 +#endif
56463 +
56464 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56465 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56466 + executable_stack = EXSTACK_DISABLE_X;
56467 + current->personality &= ~READ_IMPLIES_EXEC;
56468 + } else
56469 +#endif
56470 +
56471 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56472 current->personality |= READ_IMPLIES_EXEC;
56473
56474 @@ -814,6 +1251,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56475 #else
56476 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56477 #endif
56478 +
56479 +#ifdef CONFIG_PAX_RANDMMAP
56480 + /* PaX: randomize base address at the default exe base if requested */
56481 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56482 +#ifdef CONFIG_SPARC64
56483 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56484 +#else
56485 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56486 +#endif
56487 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56488 + elf_flags |= MAP_FIXED;
56489 + }
56490 +#endif
56491 +
56492 }
56493
56494 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56495 @@ -846,9 +1297,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56496 * allowed task size. Note that p_filesz must always be
56497 * <= p_memsz so it is only necessary to check p_memsz.
56498 */
56499 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56500 - elf_ppnt->p_memsz > TASK_SIZE ||
56501 - TASK_SIZE - elf_ppnt->p_memsz < k) {
56502 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56503 + elf_ppnt->p_memsz > pax_task_size ||
56504 + pax_task_size - elf_ppnt->p_memsz < k) {
56505 /* set_brk can never work. Avoid overflows. */
56506 send_sig(SIGKILL, current, 0);
56507 retval = -EINVAL;
56508 @@ -887,17 +1338,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56509 goto out_free_dentry;
56510 }
56511 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56512 - send_sig(SIGSEGV, current, 0);
56513 - retval = -EFAULT; /* Nobody gets to see this, but.. */
56514 - goto out_free_dentry;
56515 + /*
56516 + * This bss-zeroing can fail if the ELF
56517 + * file specifies odd protections. So
56518 + * we don't check the return value
56519 + */
56520 }
56521
56522 +#ifdef CONFIG_PAX_RANDMMAP
56523 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56524 + unsigned long start, size, flags;
56525 + vm_flags_t vm_flags;
56526 +
56527 + start = ELF_PAGEALIGN(elf_brk);
56528 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56529 + flags = MAP_FIXED | MAP_PRIVATE;
56530 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56531 +
56532 + down_write(&current->mm->mmap_sem);
56533 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56534 + retval = -ENOMEM;
56535 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56536 +// if (current->personality & ADDR_NO_RANDOMIZE)
56537 +// vm_flags |= VM_READ | VM_MAYREAD;
56538 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56539 + retval = IS_ERR_VALUE(start) ? start : 0;
56540 + }
56541 + up_write(&current->mm->mmap_sem);
56542 + if (retval == 0)
56543 + retval = set_brk(start + size, start + size + PAGE_SIZE);
56544 + if (retval < 0) {
56545 + send_sig(SIGKILL, current, 0);
56546 + goto out_free_dentry;
56547 + }
56548 + }
56549 +#endif
56550 +
56551 if (elf_interpreter) {
56552 - unsigned long interp_map_addr = 0;
56553 -
56554 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56555 interpreter,
56556 - &interp_map_addr,
56557 load_bias);
56558 if (!IS_ERR((void *)elf_entry)) {
56559 /*
56560 @@ -1119,7 +1598,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56561 * Decide what to dump of a segment, part, all or none.
56562 */
56563 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56564 - unsigned long mm_flags)
56565 + unsigned long mm_flags, long signr)
56566 {
56567 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
56568
56569 @@ -1157,7 +1636,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
56570 if (vma->vm_file == NULL)
56571 return 0;
56572
56573 - if (FILTER(MAPPED_PRIVATE))
56574 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
56575 goto whole;
56576
56577 /*
56578 @@ -1364,9 +1843,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
56579 {
56580 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
56581 int i = 0;
56582 - do
56583 + do {
56584 i += 2;
56585 - while (auxv[i - 2] != AT_NULL);
56586 + } while (auxv[i - 2] != AT_NULL);
56587 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
56588 }
56589
56590 @@ -1375,7 +1854,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
56591 {
56592 mm_segment_t old_fs = get_fs();
56593 set_fs(KERNEL_DS);
56594 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
56595 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
56596 set_fs(old_fs);
56597 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
56598 }
56599 @@ -1999,14 +2478,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
56600 }
56601
56602 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
56603 - unsigned long mm_flags)
56604 + struct coredump_params *cprm)
56605 {
56606 struct vm_area_struct *vma;
56607 size_t size = 0;
56608
56609 for (vma = first_vma(current, gate_vma); vma != NULL;
56610 vma = next_vma(vma, gate_vma))
56611 - size += vma_dump_size(vma, mm_flags);
56612 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56613 return size;
56614 }
56615
56616 @@ -2097,7 +2576,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56617
56618 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
56619
56620 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
56621 + offset += elf_core_vma_data_size(gate_vma, cprm);
56622 offset += elf_core_extra_data_size();
56623 e_shoff = offset;
56624
56625 @@ -2125,7 +2604,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56626 phdr.p_offset = offset;
56627 phdr.p_vaddr = vma->vm_start;
56628 phdr.p_paddr = 0;
56629 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
56630 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56631 phdr.p_memsz = vma->vm_end - vma->vm_start;
56632 offset += phdr.p_filesz;
56633 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
56634 @@ -2158,7 +2637,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56635 unsigned long addr;
56636 unsigned long end;
56637
56638 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
56639 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56640
56641 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
56642 struct page *page;
56643 @@ -2199,6 +2678,167 @@ out:
56644
56645 #endif /* CONFIG_ELF_CORE */
56646
56647 +#ifdef CONFIG_PAX_MPROTECT
56648 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
56649 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
56650 + * we'll remove VM_MAYWRITE for good on RELRO segments.
56651 + *
56652 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
56653 + * basis because we want to allow the common case and not the special ones.
56654 + */
56655 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
56656 +{
56657 + struct elfhdr elf_h;
56658 + struct elf_phdr elf_p;
56659 + unsigned long i;
56660 + unsigned long oldflags;
56661 + bool is_textrel_rw, is_textrel_rx, is_relro;
56662 +
56663 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
56664 + return;
56665 +
56666 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
56667 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
56668 +
56669 +#ifdef CONFIG_PAX_ELFRELOCS
56670 + /* possible TEXTREL */
56671 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
56672 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
56673 +#else
56674 + is_textrel_rw = false;
56675 + is_textrel_rx = false;
56676 +#endif
56677 +
56678 + /* possible RELRO */
56679 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
56680 +
56681 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
56682 + return;
56683 +
56684 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56685 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56686 +
56687 +#ifdef CONFIG_PAX_ETEXECRELOCS
56688 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56689 +#else
56690 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
56691 +#endif
56692 +
56693 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56694 + !elf_check_arch(&elf_h) ||
56695 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56696 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56697 + return;
56698 +
56699 + for (i = 0UL; i < elf_h.e_phnum; i++) {
56700 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56701 + return;
56702 + switch (elf_p.p_type) {
56703 + case PT_DYNAMIC:
56704 + if (!is_textrel_rw && !is_textrel_rx)
56705 + continue;
56706 + i = 0UL;
56707 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
56708 + elf_dyn dyn;
56709 +
56710 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
56711 + break;
56712 + if (dyn.d_tag == DT_NULL)
56713 + break;
56714 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
56715 + gr_log_textrel(vma);
56716 + if (is_textrel_rw)
56717 + vma->vm_flags |= VM_MAYWRITE;
56718 + else
56719 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
56720 + vma->vm_flags &= ~VM_MAYWRITE;
56721 + break;
56722 + }
56723 + i++;
56724 + }
56725 + is_textrel_rw = false;
56726 + is_textrel_rx = false;
56727 + continue;
56728 +
56729 + case PT_GNU_RELRO:
56730 + if (!is_relro)
56731 + continue;
56732 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
56733 + vma->vm_flags &= ~VM_MAYWRITE;
56734 + is_relro = false;
56735 + continue;
56736 +
56737 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56738 + case PT_PAX_FLAGS: {
56739 + const char *msg_mprotect = "", *msg_emutramp = "";
56740 + char *buffer_lib, *buffer_exe;
56741 +
56742 + if (elf_p.p_flags & PF_NOMPROTECT)
56743 + msg_mprotect = "MPROTECT disabled";
56744 +
56745 +#ifdef CONFIG_PAX_EMUTRAMP
56746 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
56747 + msg_emutramp = "EMUTRAMP enabled";
56748 +#endif
56749 +
56750 + if (!msg_mprotect[0] && !msg_emutramp[0])
56751 + continue;
56752 +
56753 + if (!printk_ratelimit())
56754 + continue;
56755 +
56756 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
56757 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
56758 + if (buffer_lib && buffer_exe) {
56759 + char *path_lib, *path_exe;
56760 +
56761 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
56762 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
56763 +
56764 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
56765 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
56766 +
56767 + }
56768 + free_page((unsigned long)buffer_exe);
56769 + free_page((unsigned long)buffer_lib);
56770 + continue;
56771 + }
56772 +#endif
56773 +
56774 + }
56775 + }
56776 +}
56777 +#endif
56778 +
56779 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56780 +
56781 +extern int grsec_enable_log_rwxmaps;
56782 +
56783 +static void elf_handle_mmap(struct file *file)
56784 +{
56785 + struct elfhdr elf_h;
56786 + struct elf_phdr elf_p;
56787 + unsigned long i;
56788 +
56789 + if (!grsec_enable_log_rwxmaps)
56790 + return;
56791 +
56792 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56793 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56794 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
56795 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56796 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56797 + return;
56798 +
56799 + for (i = 0UL; i < elf_h.e_phnum; i++) {
56800 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56801 + return;
56802 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
56803 + gr_log_ptgnustack(file);
56804 + }
56805 +}
56806 +#endif
56807 +
56808 static int __init init_elf_binfmt(void)
56809 {
56810 register_binfmt(&elf_format);
56811 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
56812 index d50bbe5..af3b649 100644
56813 --- a/fs/binfmt_flat.c
56814 +++ b/fs/binfmt_flat.c
56815 @@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
56816 realdatastart = (unsigned long) -ENOMEM;
56817 printk("Unable to allocate RAM for process data, errno %d\n",
56818 (int)-realdatastart);
56819 + down_write(&current->mm->mmap_sem);
56820 vm_munmap(textpos, text_len);
56821 + up_write(&current->mm->mmap_sem);
56822 ret = realdatastart;
56823 goto err;
56824 }
56825 @@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56826 }
56827 if (IS_ERR_VALUE(result)) {
56828 printk("Unable to read data+bss, errno %d\n", (int)-result);
56829 + down_write(&current->mm->mmap_sem);
56830 vm_munmap(textpos, text_len);
56831 vm_munmap(realdatastart, len);
56832 + up_write(&current->mm->mmap_sem);
56833 ret = result;
56834 goto err;
56835 }
56836 @@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56837 }
56838 if (IS_ERR_VALUE(result)) {
56839 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
56840 + down_write(&current->mm->mmap_sem);
56841 vm_munmap(textpos, text_len + data_len + extra +
56842 MAX_SHARED_LIBS * sizeof(unsigned long));
56843 + up_write(&current->mm->mmap_sem);
56844 ret = result;
56845 goto err;
56846 }
56847 diff --git a/fs/bio.c b/fs/bio.c
56848 index 8754e7b..0669094 100644
56849 --- a/fs/bio.c
56850 +++ b/fs/bio.c
56851 @@ -1145,7 +1145,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
56852 /*
56853 * Overflow, abort
56854 */
56855 - if (end < start)
56856 + if (end < start || end - start > INT_MAX - nr_pages)
56857 return ERR_PTR(-EINVAL);
56858
56859 nr_pages += end - start;
56860 @@ -1279,7 +1279,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
56861 /*
56862 * Overflow, abort
56863 */
56864 - if (end < start)
56865 + if (end < start || end - start > INT_MAX - nr_pages)
56866 return ERR_PTR(-EINVAL);
56867
56868 nr_pages += end - start;
56869 @@ -1541,7 +1541,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
56870 const int read = bio_data_dir(bio) == READ;
56871 struct bio_map_data *bmd = bio->bi_private;
56872 int i;
56873 - char *p = bmd->sgvecs[0].iov_base;
56874 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
56875
56876 bio_for_each_segment_all(bvec, bio, i) {
56877 char *addr = page_address(bvec->bv_page);
56878 diff --git a/fs/block_dev.c b/fs/block_dev.c
56879 index 1e86823..8e34695 100644
56880 --- a/fs/block_dev.c
56881 +++ b/fs/block_dev.c
56882 @@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
56883 else if (bdev->bd_contains == bdev)
56884 return true; /* is a whole device which isn't held */
56885
56886 - else if (whole->bd_holder == bd_may_claim)
56887 + else if (whole->bd_holder == (void *)bd_may_claim)
56888 return true; /* is a partition of a device that is being partitioned */
56889 else if (whole->bd_holder != NULL)
56890 return false; /* is a partition of a held device */
56891 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
56892 index cbd3a7d..c6a2881 100644
56893 --- a/fs/btrfs/ctree.c
56894 +++ b/fs/btrfs/ctree.c
56895 @@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
56896 free_extent_buffer(buf);
56897 add_root_to_dirty_list(root);
56898 } else {
56899 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
56900 - parent_start = parent->start;
56901 - else
56902 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
56903 + if (parent)
56904 + parent_start = parent->start;
56905 + else
56906 + parent_start = 0;
56907 + } else
56908 parent_start = 0;
56909
56910 WARN_ON(trans->transid != btrfs_header_generation(parent));
56911 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
56912 index 451b00c..a2cccee 100644
56913 --- a/fs/btrfs/delayed-inode.c
56914 +++ b/fs/btrfs/delayed-inode.c
56915 @@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
56916
56917 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
56918 {
56919 - int seq = atomic_inc_return(&delayed_root->items_seq);
56920 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
56921 if ((atomic_dec_return(&delayed_root->items) <
56922 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
56923 waitqueue_active(&delayed_root->wait))
56924 @@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
56925
56926 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
56927 {
56928 - int val = atomic_read(&delayed_root->items_seq);
56929 + int val = atomic_read_unchecked(&delayed_root->items_seq);
56930
56931 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
56932 return 1;
56933 @@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
56934 int seq;
56935 int ret;
56936
56937 - seq = atomic_read(&delayed_root->items_seq);
56938 + seq = atomic_read_unchecked(&delayed_root->items_seq);
56939
56940 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
56941 if (ret)
56942 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
56943 index f70119f..ab5894d 100644
56944 --- a/fs/btrfs/delayed-inode.h
56945 +++ b/fs/btrfs/delayed-inode.h
56946 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
56947 */
56948 struct list_head prepare_list;
56949 atomic_t items; /* for delayed items */
56950 - atomic_t items_seq; /* for delayed items */
56951 + atomic_unchecked_t items_seq; /* for delayed items */
56952 int nodes; /* for delayed nodes */
56953 wait_queue_head_t wait;
56954 };
56955 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
56956 struct btrfs_delayed_root *delayed_root)
56957 {
56958 atomic_set(&delayed_root->items, 0);
56959 - atomic_set(&delayed_root->items_seq, 0);
56960 + atomic_set_unchecked(&delayed_root->items_seq, 0);
56961 delayed_root->nodes = 0;
56962 spin_lock_init(&delayed_root->lock);
56963 init_waitqueue_head(&delayed_root->wait);
56964 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
56965 index a6d8efa..2f062cf 100644
56966 --- a/fs/btrfs/ioctl.c
56967 +++ b/fs/btrfs/ioctl.c
56968 @@ -3491,9 +3491,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
56969 for (i = 0; i < num_types; i++) {
56970 struct btrfs_space_info *tmp;
56971
56972 + /* Don't copy in more than we allocated */
56973 if (!slot_count)
56974 break;
56975
56976 + slot_count--;
56977 +
56978 info = NULL;
56979 rcu_read_lock();
56980 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
56981 @@ -3515,10 +3518,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
56982 memcpy(dest, &space, sizeof(space));
56983 dest++;
56984 space_args.total_spaces++;
56985 - slot_count--;
56986 }
56987 - if (!slot_count)
56988 - break;
56989 }
56990 up_read(&info->groups_sem);
56991 }
56992 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
56993 index d04db81..96e54f1 100644
56994 --- a/fs/btrfs/super.c
56995 +++ b/fs/btrfs/super.c
56996 @@ -268,7 +268,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
56997 function, line, errstr);
56998 return;
56999 }
57000 - ACCESS_ONCE(trans->transaction->aborted) = errno;
57001 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57002 /* Wake up anybody who may be waiting on this transaction */
57003 wake_up(&root->fs_info->transaction_wait);
57004 wake_up(&root->fs_info->transaction_blocked_wait);
57005 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57006 index 865f4cf..f321e86 100644
57007 --- a/fs/btrfs/sysfs.c
57008 +++ b/fs/btrfs/sysfs.c
57009 @@ -436,7 +436,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57010 for (set = 0; set < FEAT_MAX; set++) {
57011 int i;
57012 struct attribute *attrs[2];
57013 - struct attribute_group agroup = {
57014 + attribute_group_no_const agroup = {
57015 .name = "features",
57016 .attrs = attrs,
57017 };
57018 diff --git a/fs/buffer.c b/fs/buffer.c
57019 index 27265a8..289f488 100644
57020 --- a/fs/buffer.c
57021 +++ b/fs/buffer.c
57022 @@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57023 bh_cachep = kmem_cache_create("buffer_head",
57024 sizeof(struct buffer_head), 0,
57025 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57026 - SLAB_MEM_SPREAD),
57027 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57028 NULL);
57029
57030 /*
57031 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57032 index 622f469..e8d2d55 100644
57033 --- a/fs/cachefiles/bind.c
57034 +++ b/fs/cachefiles/bind.c
57035 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57036 args);
57037
57038 /* start by checking things over */
57039 - ASSERT(cache->fstop_percent >= 0 &&
57040 - cache->fstop_percent < cache->fcull_percent &&
57041 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
57042 cache->fcull_percent < cache->frun_percent &&
57043 cache->frun_percent < 100);
57044
57045 - ASSERT(cache->bstop_percent >= 0 &&
57046 - cache->bstop_percent < cache->bcull_percent &&
57047 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
57048 cache->bcull_percent < cache->brun_percent &&
57049 cache->brun_percent < 100);
57050
57051 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57052 index 0a1467b..6a53245 100644
57053 --- a/fs/cachefiles/daemon.c
57054 +++ b/fs/cachefiles/daemon.c
57055 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57056 if (n > buflen)
57057 return -EMSGSIZE;
57058
57059 - if (copy_to_user(_buffer, buffer, n) != 0)
57060 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57061 return -EFAULT;
57062
57063 return n;
57064 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57065 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57066 return -EIO;
57067
57068 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
57069 + if (datalen > PAGE_SIZE - 1)
57070 return -EOPNOTSUPP;
57071
57072 /* drag the command string into the kernel so we can parse it */
57073 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57074 if (args[0] != '%' || args[1] != '\0')
57075 return -EINVAL;
57076
57077 - if (fstop < 0 || fstop >= cache->fcull_percent)
57078 + if (fstop >= cache->fcull_percent)
57079 return cachefiles_daemon_range_error(cache, args);
57080
57081 cache->fstop_percent = fstop;
57082 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57083 if (args[0] != '%' || args[1] != '\0')
57084 return -EINVAL;
57085
57086 - if (bstop < 0 || bstop >= cache->bcull_percent)
57087 + if (bstop >= cache->bcull_percent)
57088 return cachefiles_daemon_range_error(cache, args);
57089
57090 cache->bstop_percent = bstop;
57091 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57092 index 5349473..d6c0b93 100644
57093 --- a/fs/cachefiles/internal.h
57094 +++ b/fs/cachefiles/internal.h
57095 @@ -59,7 +59,7 @@ struct cachefiles_cache {
57096 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57097 struct rb_root active_nodes; /* active nodes (can't be culled) */
57098 rwlock_t active_lock; /* lock for active_nodes */
57099 - atomic_t gravecounter; /* graveyard uniquifier */
57100 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57101 unsigned frun_percent; /* when to stop culling (% files) */
57102 unsigned fcull_percent; /* when to start culling (% files) */
57103 unsigned fstop_percent; /* when to stop allocating (% files) */
57104 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57105 * proc.c
57106 */
57107 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57108 -extern atomic_t cachefiles_lookup_histogram[HZ];
57109 -extern atomic_t cachefiles_mkdir_histogram[HZ];
57110 -extern atomic_t cachefiles_create_histogram[HZ];
57111 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57112 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57113 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57114
57115 extern int __init cachefiles_proc_init(void);
57116 extern void cachefiles_proc_cleanup(void);
57117 static inline
57118 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57119 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57120 {
57121 unsigned long jif = jiffies - start_jif;
57122 if (jif >= HZ)
57123 jif = HZ - 1;
57124 - atomic_inc(&histogram[jif]);
57125 + atomic_inc_unchecked(&histogram[jif]);
57126 }
57127
57128 #else
57129 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57130 index ca65f39..48921e3 100644
57131 --- a/fs/cachefiles/namei.c
57132 +++ b/fs/cachefiles/namei.c
57133 @@ -317,7 +317,7 @@ try_again:
57134 /* first step is to make up a grave dentry in the graveyard */
57135 sprintf(nbuffer, "%08x%08x",
57136 (uint32_t) get_seconds(),
57137 - (uint32_t) atomic_inc_return(&cache->gravecounter));
57138 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57139
57140 /* do the multiway lock magic */
57141 trap = lock_rename(cache->graveyard, dir);
57142 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57143 index eccd339..4c1d995 100644
57144 --- a/fs/cachefiles/proc.c
57145 +++ b/fs/cachefiles/proc.c
57146 @@ -14,9 +14,9 @@
57147 #include <linux/seq_file.h>
57148 #include "internal.h"
57149
57150 -atomic_t cachefiles_lookup_histogram[HZ];
57151 -atomic_t cachefiles_mkdir_histogram[HZ];
57152 -atomic_t cachefiles_create_histogram[HZ];
57153 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57154 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57155 +atomic_unchecked_t cachefiles_create_histogram[HZ];
57156
57157 /*
57158 * display the latency histogram
57159 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57160 return 0;
57161 default:
57162 index = (unsigned long) v - 3;
57163 - x = atomic_read(&cachefiles_lookup_histogram[index]);
57164 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
57165 - z = atomic_read(&cachefiles_create_histogram[index]);
57166 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57167 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57168 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57169 if (x == 0 && y == 0 && z == 0)
57170 return 0;
57171
57172 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57173 index ebaff36..7e3ea26 100644
57174 --- a/fs/cachefiles/rdwr.c
57175 +++ b/fs/cachefiles/rdwr.c
57176 @@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57177 old_fs = get_fs();
57178 set_fs(KERNEL_DS);
57179 ret = file->f_op->write(
57180 - file, (const void __user *) data, len, &pos);
57181 + file, (const void __force_user *) data, len, &pos);
57182 set_fs(old_fs);
57183 kunmap(page);
57184 file_end_write(file);
57185 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57186 index 45eda6d..9126f7f 100644
57187 --- a/fs/ceph/dir.c
57188 +++ b/fs/ceph/dir.c
57189 @@ -248,7 +248,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57190 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57191 struct ceph_mds_client *mdsc = fsc->mdsc;
57192 unsigned frag = fpos_frag(ctx->pos);
57193 - int off = fpos_off(ctx->pos);
57194 + unsigned int off = fpos_off(ctx->pos);
57195 int err;
57196 u32 ftype;
57197 struct ceph_mds_reply_info_parsed *rinfo;
57198 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57199 index 10a4ccb..92dbc5e 100644
57200 --- a/fs/ceph/super.c
57201 +++ b/fs/ceph/super.c
57202 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57203 /*
57204 * construct our own bdi so we can control readahead, etc.
57205 */
57206 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57207 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57208
57209 static int ceph_register_bdi(struct super_block *sb,
57210 struct ceph_fs_client *fsc)
57211 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57212 default_backing_dev_info.ra_pages;
57213
57214 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57215 - atomic_long_inc_return(&bdi_seq));
57216 + atomic_long_inc_return_unchecked(&bdi_seq));
57217 if (!err)
57218 sb->s_bdi = &fsc->backing_dev_info;
57219 return err;
57220 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57221 index f3ac415..3d2420c 100644
57222 --- a/fs/cifs/cifs_debug.c
57223 +++ b/fs/cifs/cifs_debug.c
57224 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57225
57226 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57227 #ifdef CONFIG_CIFS_STATS2
57228 - atomic_set(&totBufAllocCount, 0);
57229 - atomic_set(&totSmBufAllocCount, 0);
57230 + atomic_set_unchecked(&totBufAllocCount, 0);
57231 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57232 #endif /* CONFIG_CIFS_STATS2 */
57233 spin_lock(&cifs_tcp_ses_lock);
57234 list_for_each(tmp1, &cifs_tcp_ses_list) {
57235 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57236 tcon = list_entry(tmp3,
57237 struct cifs_tcon,
57238 tcon_list);
57239 - atomic_set(&tcon->num_smbs_sent, 0);
57240 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57241 if (server->ops->clear_stats)
57242 server->ops->clear_stats(tcon);
57243 }
57244 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57245 smBufAllocCount.counter, cifs_min_small);
57246 #ifdef CONFIG_CIFS_STATS2
57247 seq_printf(m, "Total Large %d Small %d Allocations\n",
57248 - atomic_read(&totBufAllocCount),
57249 - atomic_read(&totSmBufAllocCount));
57250 + atomic_read_unchecked(&totBufAllocCount),
57251 + atomic_read_unchecked(&totSmBufAllocCount));
57252 #endif /* CONFIG_CIFS_STATS2 */
57253
57254 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57255 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57256 if (tcon->need_reconnect)
57257 seq_puts(m, "\tDISCONNECTED ");
57258 seq_printf(m, "\nSMBs: %d",
57259 - atomic_read(&tcon->num_smbs_sent));
57260 + atomic_read_unchecked(&tcon->num_smbs_sent));
57261 if (server->ops->print_stats)
57262 server->ops->print_stats(m, tcon);
57263 }
57264 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57265 index 849f613..eae6dec 100644
57266 --- a/fs/cifs/cifsfs.c
57267 +++ b/fs/cifs/cifsfs.c
57268 @@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
57269 */
57270 cifs_req_cachep = kmem_cache_create("cifs_request",
57271 CIFSMaxBufSize + max_hdr_size, 0,
57272 - SLAB_HWCACHE_ALIGN, NULL);
57273 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57274 if (cifs_req_cachep == NULL)
57275 return -ENOMEM;
57276
57277 @@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
57278 efficient to alloc 1 per page off the slab compared to 17K (5page)
57279 alloc of large cifs buffers even when page debugging is on */
57280 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57281 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57282 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57283 NULL);
57284 if (cifs_sm_req_cachep == NULL) {
57285 mempool_destroy(cifs_req_poolp);
57286 @@ -1168,8 +1168,8 @@ init_cifs(void)
57287 atomic_set(&bufAllocCount, 0);
57288 atomic_set(&smBufAllocCount, 0);
57289 #ifdef CONFIG_CIFS_STATS2
57290 - atomic_set(&totBufAllocCount, 0);
57291 - atomic_set(&totSmBufAllocCount, 0);
57292 + atomic_set_unchecked(&totBufAllocCount, 0);
57293 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57294 #endif /* CONFIG_CIFS_STATS2 */
57295
57296 atomic_set(&midCount, 0);
57297 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57298 index c0f3718..6afed7d 100644
57299 --- a/fs/cifs/cifsglob.h
57300 +++ b/fs/cifs/cifsglob.h
57301 @@ -804,35 +804,35 @@ struct cifs_tcon {
57302 __u16 Flags; /* optional support bits */
57303 enum statusEnum tidStatus;
57304 #ifdef CONFIG_CIFS_STATS
57305 - atomic_t num_smbs_sent;
57306 + atomic_unchecked_t num_smbs_sent;
57307 union {
57308 struct {
57309 - atomic_t num_writes;
57310 - atomic_t num_reads;
57311 - atomic_t num_flushes;
57312 - atomic_t num_oplock_brks;
57313 - atomic_t num_opens;
57314 - atomic_t num_closes;
57315 - atomic_t num_deletes;
57316 - atomic_t num_mkdirs;
57317 - atomic_t num_posixopens;
57318 - atomic_t num_posixmkdirs;
57319 - atomic_t num_rmdirs;
57320 - atomic_t num_renames;
57321 - atomic_t num_t2renames;
57322 - atomic_t num_ffirst;
57323 - atomic_t num_fnext;
57324 - atomic_t num_fclose;
57325 - atomic_t num_hardlinks;
57326 - atomic_t num_symlinks;
57327 - atomic_t num_locks;
57328 - atomic_t num_acl_get;
57329 - atomic_t num_acl_set;
57330 + atomic_unchecked_t num_writes;
57331 + atomic_unchecked_t num_reads;
57332 + atomic_unchecked_t num_flushes;
57333 + atomic_unchecked_t num_oplock_brks;
57334 + atomic_unchecked_t num_opens;
57335 + atomic_unchecked_t num_closes;
57336 + atomic_unchecked_t num_deletes;
57337 + atomic_unchecked_t num_mkdirs;
57338 + atomic_unchecked_t num_posixopens;
57339 + atomic_unchecked_t num_posixmkdirs;
57340 + atomic_unchecked_t num_rmdirs;
57341 + atomic_unchecked_t num_renames;
57342 + atomic_unchecked_t num_t2renames;
57343 + atomic_unchecked_t num_ffirst;
57344 + atomic_unchecked_t num_fnext;
57345 + atomic_unchecked_t num_fclose;
57346 + atomic_unchecked_t num_hardlinks;
57347 + atomic_unchecked_t num_symlinks;
57348 + atomic_unchecked_t num_locks;
57349 + atomic_unchecked_t num_acl_get;
57350 + atomic_unchecked_t num_acl_set;
57351 } cifs_stats;
57352 #ifdef CONFIG_CIFS_SMB2
57353 struct {
57354 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57355 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57356 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57357 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57358 } smb2_stats;
57359 #endif /* CONFIG_CIFS_SMB2 */
57360 } stats;
57361 @@ -1162,7 +1162,7 @@ convert_delimiter(char *path, char delim)
57362 }
57363
57364 #ifdef CONFIG_CIFS_STATS
57365 -#define cifs_stats_inc atomic_inc
57366 +#define cifs_stats_inc atomic_inc_unchecked
57367
57368 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57369 unsigned int bytes)
57370 @@ -1528,8 +1528,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57371 /* Various Debug counters */
57372 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57373 #ifdef CONFIG_CIFS_STATS2
57374 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57375 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57376 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57377 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57378 #endif
57379 GLOBAL_EXTERN atomic_t smBufAllocCount;
57380 GLOBAL_EXTERN atomic_t midCount;
57381 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57382 index 834fce7..8a314b5 100644
57383 --- a/fs/cifs/file.c
57384 +++ b/fs/cifs/file.c
57385 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57386 index = mapping->writeback_index; /* Start from prev offset */
57387 end = -1;
57388 } else {
57389 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
57390 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
57391 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57392 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57393 range_whole = true;
57394 + index = 0;
57395 + end = ULONG_MAX;
57396 + } else {
57397 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
57398 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
57399 + }
57400 scanned = true;
57401 }
57402 retry:
57403 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57404 index 2f9f379..43f8025 100644
57405 --- a/fs/cifs/misc.c
57406 +++ b/fs/cifs/misc.c
57407 @@ -170,7 +170,7 @@ cifs_buf_get(void)
57408 memset(ret_buf, 0, buf_size + 3);
57409 atomic_inc(&bufAllocCount);
57410 #ifdef CONFIG_CIFS_STATS2
57411 - atomic_inc(&totBufAllocCount);
57412 + atomic_inc_unchecked(&totBufAllocCount);
57413 #endif /* CONFIG_CIFS_STATS2 */
57414 }
57415
57416 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57417 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57418 atomic_inc(&smBufAllocCount);
57419 #ifdef CONFIG_CIFS_STATS2
57420 - atomic_inc(&totSmBufAllocCount);
57421 + atomic_inc_unchecked(&totSmBufAllocCount);
57422 #endif /* CONFIG_CIFS_STATS2 */
57423
57424 }
57425 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57426 index 526fb89..ecdbf5a 100644
57427 --- a/fs/cifs/smb1ops.c
57428 +++ b/fs/cifs/smb1ops.c
57429 @@ -616,27 +616,27 @@ static void
57430 cifs_clear_stats(struct cifs_tcon *tcon)
57431 {
57432 #ifdef CONFIG_CIFS_STATS
57433 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57434 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57435 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57436 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57437 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57438 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57439 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57440 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57441 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57442 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57443 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57444 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57445 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57446 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57447 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57448 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57449 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57450 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57451 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57452 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57453 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57454 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57455 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57456 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57457 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57458 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57459 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57460 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57461 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57462 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57463 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57464 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57465 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57466 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57467 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57468 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57469 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57470 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57471 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57472 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57473 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57474 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57475 #endif
57476 }
57477
57478 @@ -645,36 +645,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57479 {
57480 #ifdef CONFIG_CIFS_STATS
57481 seq_printf(m, " Oplocks breaks: %d",
57482 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57483 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57484 seq_printf(m, "\nReads: %d Bytes: %llu",
57485 - atomic_read(&tcon->stats.cifs_stats.num_reads),
57486 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57487 (long long)(tcon->bytes_read));
57488 seq_printf(m, "\nWrites: %d Bytes: %llu",
57489 - atomic_read(&tcon->stats.cifs_stats.num_writes),
57490 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57491 (long long)(tcon->bytes_written));
57492 seq_printf(m, "\nFlushes: %d",
57493 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
57494 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57495 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57496 - atomic_read(&tcon->stats.cifs_stats.num_locks),
57497 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57498 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57499 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57500 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57501 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57502 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57503 - atomic_read(&tcon->stats.cifs_stats.num_opens),
57504 - atomic_read(&tcon->stats.cifs_stats.num_closes),
57505 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
57506 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57507 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57508 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57509 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57510 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57511 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57512 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57513 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57514 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57515 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57516 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57517 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57518 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57519 seq_printf(m, "\nRenames: %d T2 Renames %d",
57520 - atomic_read(&tcon->stats.cifs_stats.num_renames),
57521 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57522 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57523 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57524 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57525 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57526 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
57527 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
57528 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57529 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57530 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57531 #endif
57532 }
57533
57534 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57535 index 192f51a..539307e 100644
57536 --- a/fs/cifs/smb2ops.c
57537 +++ b/fs/cifs/smb2ops.c
57538 @@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57539 #ifdef CONFIG_CIFS_STATS
57540 int i;
57541 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57542 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57543 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57544 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57545 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57546 }
57547 #endif
57548 }
57549 @@ -405,65 +405,65 @@ static void
57550 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57551 {
57552 #ifdef CONFIG_CIFS_STATS
57553 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57554 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57555 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57556 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57557 seq_printf(m, "\nNegotiates: %d sent %d failed",
57558 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
57559 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
57560 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
57561 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
57562 seq_printf(m, "\nSessionSetups: %d sent %d failed",
57563 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
57564 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
57565 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
57566 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
57567 seq_printf(m, "\nLogoffs: %d sent %d failed",
57568 - atomic_read(&sent[SMB2_LOGOFF_HE]),
57569 - atomic_read(&failed[SMB2_LOGOFF_HE]));
57570 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
57571 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
57572 seq_printf(m, "\nTreeConnects: %d sent %d failed",
57573 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
57574 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
57575 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
57576 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
57577 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
57578 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
57579 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
57580 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
57581 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
57582 seq_printf(m, "\nCreates: %d sent %d failed",
57583 - atomic_read(&sent[SMB2_CREATE_HE]),
57584 - atomic_read(&failed[SMB2_CREATE_HE]));
57585 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
57586 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
57587 seq_printf(m, "\nCloses: %d sent %d failed",
57588 - atomic_read(&sent[SMB2_CLOSE_HE]),
57589 - atomic_read(&failed[SMB2_CLOSE_HE]));
57590 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
57591 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
57592 seq_printf(m, "\nFlushes: %d sent %d failed",
57593 - atomic_read(&sent[SMB2_FLUSH_HE]),
57594 - atomic_read(&failed[SMB2_FLUSH_HE]));
57595 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
57596 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
57597 seq_printf(m, "\nReads: %d sent %d failed",
57598 - atomic_read(&sent[SMB2_READ_HE]),
57599 - atomic_read(&failed[SMB2_READ_HE]));
57600 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
57601 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
57602 seq_printf(m, "\nWrites: %d sent %d failed",
57603 - atomic_read(&sent[SMB2_WRITE_HE]),
57604 - atomic_read(&failed[SMB2_WRITE_HE]));
57605 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
57606 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
57607 seq_printf(m, "\nLocks: %d sent %d failed",
57608 - atomic_read(&sent[SMB2_LOCK_HE]),
57609 - atomic_read(&failed[SMB2_LOCK_HE]));
57610 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
57611 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
57612 seq_printf(m, "\nIOCTLs: %d sent %d failed",
57613 - atomic_read(&sent[SMB2_IOCTL_HE]),
57614 - atomic_read(&failed[SMB2_IOCTL_HE]));
57615 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
57616 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
57617 seq_printf(m, "\nCancels: %d sent %d failed",
57618 - atomic_read(&sent[SMB2_CANCEL_HE]),
57619 - atomic_read(&failed[SMB2_CANCEL_HE]));
57620 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
57621 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
57622 seq_printf(m, "\nEchos: %d sent %d failed",
57623 - atomic_read(&sent[SMB2_ECHO_HE]),
57624 - atomic_read(&failed[SMB2_ECHO_HE]));
57625 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
57626 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
57627 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
57628 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
57629 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
57630 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
57631 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
57632 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
57633 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
57634 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
57635 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
57636 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
57637 seq_printf(m, "\nQueryInfos: %d sent %d failed",
57638 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
57639 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
57640 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
57641 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
57642 seq_printf(m, "\nSetInfos: %d sent %d failed",
57643 - atomic_read(&sent[SMB2_SET_INFO_HE]),
57644 - atomic_read(&failed[SMB2_SET_INFO_HE]));
57645 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
57646 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
57647 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
57648 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
57649 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
57650 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
57651 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
57652 #endif
57653 }
57654
57655 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
57656 index 8603447..f9caeee 100644
57657 --- a/fs/cifs/smb2pdu.c
57658 +++ b/fs/cifs/smb2pdu.c
57659 @@ -2094,8 +2094,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
57660 default:
57661 cifs_dbg(VFS, "info level %u isn't supported\n",
57662 srch_inf->info_level);
57663 - rc = -EINVAL;
57664 - goto qdir_exit;
57665 + return -EINVAL;
57666 }
57667
57668 req->FileIndex = cpu_to_le32(index);
57669 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
57670 index 1da168c..8bc7ff6 100644
57671 --- a/fs/coda/cache.c
57672 +++ b/fs/coda/cache.c
57673 @@ -24,7 +24,7 @@
57674 #include "coda_linux.h"
57675 #include "coda_cache.h"
57676
57677 -static atomic_t permission_epoch = ATOMIC_INIT(0);
57678 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
57679
57680 /* replace or extend an acl cache hit */
57681 void coda_cache_enter(struct inode *inode, int mask)
57682 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
57683 struct coda_inode_info *cii = ITOC(inode);
57684
57685 spin_lock(&cii->c_lock);
57686 - cii->c_cached_epoch = atomic_read(&permission_epoch);
57687 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
57688 if (!uid_eq(cii->c_uid, current_fsuid())) {
57689 cii->c_uid = current_fsuid();
57690 cii->c_cached_perm = mask;
57691 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
57692 {
57693 struct coda_inode_info *cii = ITOC(inode);
57694 spin_lock(&cii->c_lock);
57695 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
57696 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
57697 spin_unlock(&cii->c_lock);
57698 }
57699
57700 /* remove all acl caches */
57701 void coda_cache_clear_all(struct super_block *sb)
57702 {
57703 - atomic_inc(&permission_epoch);
57704 + atomic_inc_unchecked(&permission_epoch);
57705 }
57706
57707
57708 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
57709 spin_lock(&cii->c_lock);
57710 hit = (mask & cii->c_cached_perm) == mask &&
57711 uid_eq(cii->c_uid, current_fsuid()) &&
57712 - cii->c_cached_epoch == atomic_read(&permission_epoch);
57713 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
57714 spin_unlock(&cii->c_lock);
57715
57716 return hit;
57717 diff --git a/fs/compat.c b/fs/compat.c
57718 index 6af20de..fec3fbb 100644
57719 --- a/fs/compat.c
57720 +++ b/fs/compat.c
57721 @@ -54,7 +54,7 @@
57722 #include <asm/ioctls.h>
57723 #include "internal.h"
57724
57725 -int compat_log = 1;
57726 +int compat_log = 0;
57727
57728 int compat_printk(const char *fmt, ...)
57729 {
57730 @@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
57731
57732 set_fs(KERNEL_DS);
57733 /* The __user pointer cast is valid because of the set_fs() */
57734 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
57735 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
57736 set_fs(oldfs);
57737 /* truncating is ok because it's a user address */
57738 if (!ret)
57739 @@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
57740 goto out;
57741
57742 ret = -EINVAL;
57743 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
57744 + if (nr_segs > UIO_MAXIOV)
57745 goto out;
57746 if (nr_segs > fast_segs) {
57747 ret = -ENOMEM;
57748 @@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
57749 struct compat_readdir_callback {
57750 struct dir_context ctx;
57751 struct compat_old_linux_dirent __user *dirent;
57752 + struct file * file;
57753 int result;
57754 };
57755
57756 @@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
57757 buf->result = -EOVERFLOW;
57758 return -EOVERFLOW;
57759 }
57760 +
57761 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57762 + return 0;
57763 +
57764 buf->result++;
57765 dirent = buf->dirent;
57766 if (!access_ok(VERIFY_WRITE, dirent,
57767 @@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
57768 if (!f.file)
57769 return -EBADF;
57770
57771 + buf.file = f.file;
57772 error = iterate_dir(f.file, &buf.ctx);
57773 if (buf.result)
57774 error = buf.result;
57775 @@ -901,6 +907,7 @@ struct compat_getdents_callback {
57776 struct dir_context ctx;
57777 struct compat_linux_dirent __user *current_dir;
57778 struct compat_linux_dirent __user *previous;
57779 + struct file * file;
57780 int count;
57781 int error;
57782 };
57783 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
57784 buf->error = -EOVERFLOW;
57785 return -EOVERFLOW;
57786 }
57787 +
57788 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57789 + return 0;
57790 +
57791 dirent = buf->previous;
57792 if (dirent) {
57793 if (__put_user(offset, &dirent->d_off))
57794 @@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
57795 if (!f.file)
57796 return -EBADF;
57797
57798 + buf.file = f.file;
57799 error = iterate_dir(f.file, &buf.ctx);
57800 if (error >= 0)
57801 error = buf.error;
57802 @@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
57803 struct dir_context ctx;
57804 struct linux_dirent64 __user *current_dir;
57805 struct linux_dirent64 __user *previous;
57806 + struct file * file;
57807 int count;
57808 int error;
57809 };
57810 @@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
57811 buf->error = -EINVAL; /* only used if we fail.. */
57812 if (reclen > buf->count)
57813 return -EINVAL;
57814 +
57815 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57816 + return 0;
57817 +
57818 dirent = buf->previous;
57819
57820 if (dirent) {
57821 @@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
57822 if (!f.file)
57823 return -EBADF;
57824
57825 + buf.file = f.file;
57826 error = iterate_dir(f.file, &buf.ctx);
57827 if (error >= 0)
57828 error = buf.error;
57829 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
57830 index a81147e..20bf2b5 100644
57831 --- a/fs/compat_binfmt_elf.c
57832 +++ b/fs/compat_binfmt_elf.c
57833 @@ -30,11 +30,13 @@
57834 #undef elf_phdr
57835 #undef elf_shdr
57836 #undef elf_note
57837 +#undef elf_dyn
57838 #undef elf_addr_t
57839 #define elfhdr elf32_hdr
57840 #define elf_phdr elf32_phdr
57841 #define elf_shdr elf32_shdr
57842 #define elf_note elf32_note
57843 +#define elf_dyn Elf32_Dyn
57844 #define elf_addr_t Elf32_Addr
57845
57846 /*
57847 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
57848 index 3881610..ab3df0b 100644
57849 --- a/fs/compat_ioctl.c
57850 +++ b/fs/compat_ioctl.c
57851 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
57852 return -EFAULT;
57853 if (__get_user(udata, &ss32->iomem_base))
57854 return -EFAULT;
57855 - ss.iomem_base = compat_ptr(udata);
57856 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
57857 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
57858 __get_user(ss.port_high, &ss32->port_high))
57859 return -EFAULT;
57860 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
57861 for (i = 0; i < nmsgs; i++) {
57862 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
57863 return -EFAULT;
57864 - if (get_user(datap, &umsgs[i].buf) ||
57865 - put_user(compat_ptr(datap), &tmsgs[i].buf))
57866 + if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
57867 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
57868 return -EFAULT;
57869 }
57870 return sys_ioctl(fd, cmd, (unsigned long)tdata);
57871 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
57872 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
57873 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
57874 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
57875 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
57876 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
57877 return -EFAULT;
57878
57879 return ioctl_preallocate(file, p);
57880 @@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
57881 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
57882 {
57883 unsigned int a, b;
57884 - a = *(unsigned int *)p;
57885 - b = *(unsigned int *)q;
57886 + a = *(const unsigned int *)p;
57887 + b = *(const unsigned int *)q;
57888 if (a > b)
57889 return 1;
57890 if (a < b)
57891 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
57892 index e081acb..911df21 100644
57893 --- a/fs/configfs/dir.c
57894 +++ b/fs/configfs/dir.c
57895 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57896 }
57897 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
57898 struct configfs_dirent *next;
57899 - const char *name;
57900 + const unsigned char * name;
57901 + char d_name[sizeof(next->s_dentry->d_iname)];
57902 int len;
57903 struct inode *inode = NULL;
57904
57905 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57906 continue;
57907
57908 name = configfs_get_name(next);
57909 - len = strlen(name);
57910 + if (next->s_dentry && name == next->s_dentry->d_iname) {
57911 + len = next->s_dentry->d_name.len;
57912 + memcpy(d_name, name, len);
57913 + name = d_name;
57914 + } else
57915 + len = strlen(name);
57916
57917 /*
57918 * We'll have a dentry and an inode for
57919 diff --git a/fs/coredump.c b/fs/coredump.c
57920 index e3ad709..4a1552d 100644
57921 --- a/fs/coredump.c
57922 +++ b/fs/coredump.c
57923 @@ -437,8 +437,8 @@ static void wait_for_dump_helpers(struct file *file)
57924 struct pipe_inode_info *pipe = file->private_data;
57925
57926 pipe_lock(pipe);
57927 - pipe->readers++;
57928 - pipe->writers--;
57929 + atomic_inc(&pipe->readers);
57930 + atomic_dec(&pipe->writers);
57931 wake_up_interruptible_sync(&pipe->wait);
57932 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
57933 pipe_unlock(pipe);
57934 @@ -447,11 +447,11 @@ static void wait_for_dump_helpers(struct file *file)
57935 * We actually want wait_event_freezable() but then we need
57936 * to clear TIF_SIGPENDING and improve dump_interrupted().
57937 */
57938 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
57939 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
57940
57941 pipe_lock(pipe);
57942 - pipe->readers--;
57943 - pipe->writers++;
57944 + atomic_dec(&pipe->readers);
57945 + atomic_inc(&pipe->writers);
57946 pipe_unlock(pipe);
57947 }
57948
57949 @@ -498,7 +498,9 @@ void do_coredump(const siginfo_t *siginfo)
57950 struct files_struct *displaced;
57951 bool need_nonrelative = false;
57952 bool core_dumped = false;
57953 - static atomic_t core_dump_count = ATOMIC_INIT(0);
57954 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
57955 + long signr = siginfo->si_signo;
57956 + int dumpable;
57957 struct coredump_params cprm = {
57958 .siginfo = siginfo,
57959 .regs = signal_pt_regs(),
57960 @@ -511,12 +513,17 @@ void do_coredump(const siginfo_t *siginfo)
57961 .mm_flags = mm->flags,
57962 };
57963
57964 - audit_core_dumps(siginfo->si_signo);
57965 + audit_core_dumps(signr);
57966 +
57967 + dumpable = __get_dumpable(cprm.mm_flags);
57968 +
57969 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
57970 + gr_handle_brute_attach(dumpable);
57971
57972 binfmt = mm->binfmt;
57973 if (!binfmt || !binfmt->core_dump)
57974 goto fail;
57975 - if (!__get_dumpable(cprm.mm_flags))
57976 + if (!dumpable)
57977 goto fail;
57978
57979 cred = prepare_creds();
57980 @@ -535,7 +542,7 @@ void do_coredump(const siginfo_t *siginfo)
57981 need_nonrelative = true;
57982 }
57983
57984 - retval = coredump_wait(siginfo->si_signo, &core_state);
57985 + retval = coredump_wait(signr, &core_state);
57986 if (retval < 0)
57987 goto fail_creds;
57988
57989 @@ -578,7 +585,7 @@ void do_coredump(const siginfo_t *siginfo)
57990 }
57991 cprm.limit = RLIM_INFINITY;
57992
57993 - dump_count = atomic_inc_return(&core_dump_count);
57994 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
57995 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
57996 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
57997 task_tgid_vnr(current), current->comm);
57998 @@ -610,6 +617,8 @@ void do_coredump(const siginfo_t *siginfo)
57999 } else {
58000 struct inode *inode;
58001
58002 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58003 +
58004 if (cprm.limit < binfmt->min_coredump)
58005 goto fail_unlock;
58006
58007 @@ -668,7 +677,7 @@ close_fail:
58008 filp_close(cprm.file, NULL);
58009 fail_dropcount:
58010 if (ispipe)
58011 - atomic_dec(&core_dump_count);
58012 + atomic_dec_unchecked(&core_dump_count);
58013 fail_unlock:
58014 kfree(cn.corename);
58015 coredump_finish(mm, core_dumped);
58016 @@ -689,6 +698,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58017 struct file *file = cprm->file;
58018 loff_t pos = file->f_pos;
58019 ssize_t n;
58020 +
58021 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58022 if (cprm->written + nr > cprm->limit)
58023 return 0;
58024 while (nr) {
58025 diff --git a/fs/dcache.c b/fs/dcache.c
58026 index ca02c13..7e2b581 100644
58027 --- a/fs/dcache.c
58028 +++ b/fs/dcache.c
58029 @@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58030 */
58031 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58032 if (name->len > DNAME_INLINE_LEN-1) {
58033 - dname = kmalloc(name->len + 1, GFP_KERNEL);
58034 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58035 if (!dname) {
58036 kmem_cache_free(dentry_cache, dentry);
58037 return NULL;
58038 @@ -3431,7 +3431,8 @@ void __init vfs_caches_init(unsigned long mempages)
58039 mempages -= reserve;
58040
58041 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58042 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58043 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58044 + SLAB_NO_SANITIZE, NULL);
58045
58046 dcache_init();
58047 inode_init();
58048 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58049 index 9c0444c..628490c 100644
58050 --- a/fs/debugfs/inode.c
58051 +++ b/fs/debugfs/inode.c
58052 @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58053 */
58054 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58055 {
58056 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58057 + return __create_file(name, S_IFDIR | S_IRWXU,
58058 +#else
58059 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58060 +#endif
58061 parent, NULL, NULL);
58062 }
58063 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58064 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58065 index b167ca4..a224e19 100644
58066 --- a/fs/ecryptfs/inode.c
58067 +++ b/fs/ecryptfs/inode.c
58068 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58069 old_fs = get_fs();
58070 set_fs(get_ds());
58071 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58072 - (char __user *)lower_buf,
58073 + (char __force_user *)lower_buf,
58074 PATH_MAX);
58075 set_fs(old_fs);
58076 if (rc < 0)
58077 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58078 index e4141f2..d8263e8 100644
58079 --- a/fs/ecryptfs/miscdev.c
58080 +++ b/fs/ecryptfs/miscdev.c
58081 @@ -304,7 +304,7 @@ check_list:
58082 goto out_unlock_msg_ctx;
58083 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58084 if (msg_ctx->msg) {
58085 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
58086 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58087 goto out_unlock_msg_ctx;
58088 i += packet_length_size;
58089 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58090 diff --git a/fs/exec.c b/fs/exec.c
58091 index 3d78fcc..5a38b6b 100644
58092 --- a/fs/exec.c
58093 +++ b/fs/exec.c
58094 @@ -55,8 +55,20 @@
58095 #include <linux/pipe_fs_i.h>
58096 #include <linux/oom.h>
58097 #include <linux/compat.h>
58098 +#include <linux/random.h>
58099 +#include <linux/seq_file.h>
58100 +#include <linux/coredump.h>
58101 +#include <linux/mman.h>
58102 +
58103 +#ifdef CONFIG_PAX_REFCOUNT
58104 +#include <linux/kallsyms.h>
58105 +#include <linux/kdebug.h>
58106 +#endif
58107 +
58108 +#include <trace/events/fs.h>
58109
58110 #include <asm/uaccess.h>
58111 +#include <asm/sections.h>
58112 #include <asm/mmu_context.h>
58113 #include <asm/tlb.h>
58114
58115 @@ -65,19 +77,34 @@
58116
58117 #include <trace/events/sched.h>
58118
58119 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58120 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58121 +{
58122 + 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");
58123 +}
58124 +#endif
58125 +
58126 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58127 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58128 +EXPORT_SYMBOL(pax_set_initial_flags_func);
58129 +#endif
58130 +
58131 int suid_dumpable = 0;
58132
58133 static LIST_HEAD(formats);
58134 static DEFINE_RWLOCK(binfmt_lock);
58135
58136 +extern int gr_process_kernel_exec_ban(void);
58137 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58138 +
58139 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58140 {
58141 BUG_ON(!fmt);
58142 if (WARN_ON(!fmt->load_binary))
58143 return;
58144 write_lock(&binfmt_lock);
58145 - insert ? list_add(&fmt->lh, &formats) :
58146 - list_add_tail(&fmt->lh, &formats);
58147 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58148 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58149 write_unlock(&binfmt_lock);
58150 }
58151
58152 @@ -86,7 +113,7 @@ EXPORT_SYMBOL(__register_binfmt);
58153 void unregister_binfmt(struct linux_binfmt * fmt)
58154 {
58155 write_lock(&binfmt_lock);
58156 - list_del(&fmt->lh);
58157 + pax_list_del((struct list_head *)&fmt->lh);
58158 write_unlock(&binfmt_lock);
58159 }
58160
58161 @@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58162 int write)
58163 {
58164 struct page *page;
58165 - int ret;
58166
58167 -#ifdef CONFIG_STACK_GROWSUP
58168 - if (write) {
58169 - ret = expand_downwards(bprm->vma, pos);
58170 - if (ret < 0)
58171 - return NULL;
58172 - }
58173 -#endif
58174 - ret = get_user_pages(current, bprm->mm, pos,
58175 - 1, write, 1, &page, NULL);
58176 - if (ret <= 0)
58177 + if (0 > expand_downwards(bprm->vma, pos))
58178 + return NULL;
58179 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58180 return NULL;
58181
58182 if (write) {
58183 @@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58184 if (size <= ARG_MAX)
58185 return page;
58186
58187 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58188 + // only allow 512KB for argv+env on suid/sgid binaries
58189 + // to prevent easy ASLR exhaustion
58190 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58191 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
58192 + (size > (512 * 1024))) {
58193 + put_page(page);
58194 + return NULL;
58195 + }
58196 +#endif
58197 +
58198 /*
58199 * Limit to 1/4-th the stack size for the argv+env strings.
58200 * This ensures that:
58201 @@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58202 vma->vm_end = STACK_TOP_MAX;
58203 vma->vm_start = vma->vm_end - PAGE_SIZE;
58204 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58205 +
58206 +#ifdef CONFIG_PAX_SEGMEXEC
58207 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58208 +#endif
58209 +
58210 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58211 INIT_LIST_HEAD(&vma->anon_vma_chain);
58212
58213 @@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58214 mm->stack_vm = mm->total_vm = 1;
58215 up_write(&mm->mmap_sem);
58216 bprm->p = vma->vm_end - sizeof(void *);
58217 +
58218 +#ifdef CONFIG_PAX_RANDUSTACK
58219 + if (randomize_va_space)
58220 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
58221 +#endif
58222 +
58223 return 0;
58224 err:
58225 up_write(&mm->mmap_sem);
58226 @@ -396,7 +437,7 @@ struct user_arg_ptr {
58227 } ptr;
58228 };
58229
58230 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58231 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58232 {
58233 const char __user *native;
58234
58235 @@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58236 compat_uptr_t compat;
58237
58238 if (get_user(compat, argv.ptr.compat + nr))
58239 - return ERR_PTR(-EFAULT);
58240 + return (const char __force_user *)ERR_PTR(-EFAULT);
58241
58242 return compat_ptr(compat);
58243 }
58244 #endif
58245
58246 if (get_user(native, argv.ptr.native + nr))
58247 - return ERR_PTR(-EFAULT);
58248 + return (const char __force_user *)ERR_PTR(-EFAULT);
58249
58250 return native;
58251 }
58252 @@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
58253 if (!p)
58254 break;
58255
58256 - if (IS_ERR(p))
58257 + if (IS_ERR((const char __force_kernel *)p))
58258 return -EFAULT;
58259
58260 if (i >= max)
58261 @@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58262
58263 ret = -EFAULT;
58264 str = get_user_arg_ptr(argv, argc);
58265 - if (IS_ERR(str))
58266 + if (IS_ERR((const char __force_kernel *)str))
58267 goto out;
58268
58269 len = strnlen_user(str, MAX_ARG_STRLEN);
58270 @@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58271 int r;
58272 mm_segment_t oldfs = get_fs();
58273 struct user_arg_ptr argv = {
58274 - .ptr.native = (const char __user *const __user *)__argv,
58275 + .ptr.native = (const char __user * const __force_user *)__argv,
58276 };
58277
58278 set_fs(KERNEL_DS);
58279 @@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58280 unsigned long new_end = old_end - shift;
58281 struct mmu_gather tlb;
58282
58283 - BUG_ON(new_start > new_end);
58284 + if (new_start >= new_end || new_start < mmap_min_addr)
58285 + return -ENOMEM;
58286
58287 /*
58288 * ensure there are no vmas between where we want to go
58289 @@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58290 if (vma != find_vma(mm, new_start))
58291 return -EFAULT;
58292
58293 +#ifdef CONFIG_PAX_SEGMEXEC
58294 + BUG_ON(pax_find_mirror_vma(vma));
58295 +#endif
58296 +
58297 /*
58298 * cover the whole range: [new_start, old_end)
58299 */
58300 @@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58301 stack_top = arch_align_stack(stack_top);
58302 stack_top = PAGE_ALIGN(stack_top);
58303
58304 - if (unlikely(stack_top < mmap_min_addr) ||
58305 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58306 - return -ENOMEM;
58307 -
58308 stack_shift = vma->vm_end - stack_top;
58309
58310 bprm->p -= stack_shift;
58311 @@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58312 bprm->exec -= stack_shift;
58313
58314 down_write(&mm->mmap_sem);
58315 +
58316 + /* Move stack pages down in memory. */
58317 + if (stack_shift) {
58318 + ret = shift_arg_pages(vma, stack_shift);
58319 + if (ret)
58320 + goto out_unlock;
58321 + }
58322 +
58323 vm_flags = VM_STACK_FLAGS;
58324
58325 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58326 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58327 + vm_flags &= ~VM_EXEC;
58328 +
58329 +#ifdef CONFIG_PAX_MPROTECT
58330 + if (mm->pax_flags & MF_PAX_MPROTECT)
58331 + vm_flags &= ~VM_MAYEXEC;
58332 +#endif
58333 +
58334 + }
58335 +#endif
58336 +
58337 /*
58338 * Adjust stack execute permissions; explicitly enable for
58339 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58340 @@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58341 goto out_unlock;
58342 BUG_ON(prev != vma);
58343
58344 - /* Move stack pages down in memory. */
58345 - if (stack_shift) {
58346 - ret = shift_arg_pages(vma, stack_shift);
58347 - if (ret)
58348 - goto out_unlock;
58349 - }
58350 -
58351 /* mprotect_fixup is overkill to remove the temporary stack flags */
58352 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58353
58354 @@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58355 #endif
58356 current->mm->start_stack = bprm->p;
58357 ret = expand_stack(vma, stack_base);
58358 +
58359 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58360 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58361 + unsigned long size;
58362 + vm_flags_t vm_flags;
58363 +
58364 + size = STACK_TOP - vma->vm_end;
58365 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58366 +
58367 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58368 +
58369 +#ifdef CONFIG_X86
58370 + if (!ret) {
58371 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58372 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58373 + }
58374 +#endif
58375 +
58376 + }
58377 +#endif
58378 +
58379 if (ret)
58380 ret = -EFAULT;
58381
58382 @@ -772,6 +848,8 @@ static struct file *do_open_exec(struct filename *name)
58383
58384 fsnotify_open(file);
58385
58386 + trace_open_exec(name->name);
58387 +
58388 err = deny_write_access(file);
58389 if (err)
58390 goto exit;
58391 @@ -801,7 +879,7 @@ int kernel_read(struct file *file, loff_t offset,
58392 old_fs = get_fs();
58393 set_fs(get_ds());
58394 /* The cast to a user pointer is valid due to the set_fs() */
58395 - result = vfs_read(file, (void __user *)addr, count, &pos);
58396 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
58397 set_fs(old_fs);
58398 return result;
58399 }
58400 @@ -1258,7 +1336,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
58401 }
58402 rcu_read_unlock();
58403
58404 - if (p->fs->users > n_fs)
58405 + if (atomic_read(&p->fs->users) > n_fs)
58406 bprm->unsafe |= LSM_UNSAFE_SHARE;
58407 else
58408 p->fs->in_exec = 1;
58409 @@ -1434,6 +1512,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58410 return ret;
58411 }
58412
58413 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58414 +static DEFINE_PER_CPU(u64, exec_counter);
58415 +static int __init init_exec_counters(void)
58416 +{
58417 + unsigned int cpu;
58418 +
58419 + for_each_possible_cpu(cpu) {
58420 + per_cpu(exec_counter, cpu) = (u64)cpu;
58421 + }
58422 +
58423 + return 0;
58424 +}
58425 +early_initcall(init_exec_counters);
58426 +static inline void increment_exec_counter(void)
58427 +{
58428 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
58429 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58430 +}
58431 +#else
58432 +static inline void increment_exec_counter(void) {}
58433 +#endif
58434 +
58435 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
58436 + struct user_arg_ptr argv);
58437 +
58438 /*
58439 * sys_execve() executes a new program.
58440 */
58441 @@ -1441,6 +1544,11 @@ static int do_execve_common(struct filename *filename,
58442 struct user_arg_ptr argv,
58443 struct user_arg_ptr envp)
58444 {
58445 +#ifdef CONFIG_GRKERNSEC
58446 + struct file *old_exec_file;
58447 + struct acl_subject_label *old_acl;
58448 + struct rlimit old_rlim[RLIM_NLIMITS];
58449 +#endif
58450 struct linux_binprm *bprm;
58451 struct file *file;
58452 struct files_struct *displaced;
58453 @@ -1449,6 +1557,8 @@ static int do_execve_common(struct filename *filename,
58454 if (IS_ERR(filename))
58455 return PTR_ERR(filename);
58456
58457 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58458 +
58459 /*
58460 * We move the actual failure in case of RLIMIT_NPROC excess from
58461 * set*uid() to execve() because too many poorly written programs
58462 @@ -1486,11 +1596,21 @@ static int do_execve_common(struct filename *filename,
58463 if (IS_ERR(file))
58464 goto out_unmark;
58465
58466 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
58467 + retval = -EPERM;
58468 + goto out_unmark;
58469 + }
58470 +
58471 sched_exec();
58472
58473 bprm->file = file;
58474 bprm->filename = bprm->interp = filename->name;
58475
58476 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58477 + retval = -EACCES;
58478 + goto out_unmark;
58479 + }
58480 +
58481 retval = bprm_mm_init(bprm);
58482 if (retval)
58483 goto out_unmark;
58484 @@ -1507,24 +1627,70 @@ static int do_execve_common(struct filename *filename,
58485 if (retval < 0)
58486 goto out;
58487
58488 +#ifdef CONFIG_GRKERNSEC
58489 + old_acl = current->acl;
58490 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58491 + old_exec_file = current->exec_file;
58492 + get_file(file);
58493 + current->exec_file = file;
58494 +#endif
58495 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58496 + /* limit suid stack to 8MB
58497 + * we saved the old limits above and will restore them if this exec fails
58498 + */
58499 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58500 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58501 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58502 +#endif
58503 +
58504 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58505 + retval = -EPERM;
58506 + goto out_fail;
58507 + }
58508 +
58509 + if (!gr_tpe_allow(file)) {
58510 + retval = -EACCES;
58511 + goto out_fail;
58512 + }
58513 +
58514 + if (gr_check_crash_exec(file)) {
58515 + retval = -EACCES;
58516 + goto out_fail;
58517 + }
58518 +
58519 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58520 + bprm->unsafe);
58521 + if (retval < 0)
58522 + goto out_fail;
58523 +
58524 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58525 if (retval < 0)
58526 - goto out;
58527 + goto out_fail;
58528
58529 bprm->exec = bprm->p;
58530 retval = copy_strings(bprm->envc, envp, bprm);
58531 if (retval < 0)
58532 - goto out;
58533 + goto out_fail;
58534
58535 retval = copy_strings(bprm->argc, argv, bprm);
58536 if (retval < 0)
58537 - goto out;
58538 + goto out_fail;
58539 +
58540 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58541 +
58542 + gr_handle_exec_args(bprm, argv);
58543
58544 retval = exec_binprm(bprm);
58545 if (retval < 0)
58546 - goto out;
58547 + goto out_fail;
58548 +#ifdef CONFIG_GRKERNSEC
58549 + if (old_exec_file)
58550 + fput(old_exec_file);
58551 +#endif
58552
58553 /* execve succeeded */
58554 +
58555 + increment_exec_counter();
58556 current->fs->in_exec = 0;
58557 current->in_execve = 0;
58558 acct_update_integrals(current);
58559 @@ -1535,6 +1701,14 @@ static int do_execve_common(struct filename *filename,
58560 put_files_struct(displaced);
58561 return retval;
58562
58563 +out_fail:
58564 +#ifdef CONFIG_GRKERNSEC
58565 + current->acl = old_acl;
58566 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
58567 + fput(current->exec_file);
58568 + current->exec_file = old_exec_file;
58569 +#endif
58570 +
58571 out:
58572 if (bprm->mm) {
58573 acct_arg_size(bprm, 0);
58574 @@ -1626,3 +1800,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
58575 return compat_do_execve(getname(filename), argv, envp);
58576 }
58577 #endif
58578 +
58579 +int pax_check_flags(unsigned long *flags)
58580 +{
58581 + int retval = 0;
58582 +
58583 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
58584 + if (*flags & MF_PAX_SEGMEXEC)
58585 + {
58586 + *flags &= ~MF_PAX_SEGMEXEC;
58587 + retval = -EINVAL;
58588 + }
58589 +#endif
58590 +
58591 + if ((*flags & MF_PAX_PAGEEXEC)
58592 +
58593 +#ifdef CONFIG_PAX_PAGEEXEC
58594 + && (*flags & MF_PAX_SEGMEXEC)
58595 +#endif
58596 +
58597 + )
58598 + {
58599 + *flags &= ~MF_PAX_PAGEEXEC;
58600 + retval = -EINVAL;
58601 + }
58602 +
58603 + if ((*flags & MF_PAX_MPROTECT)
58604 +
58605 +#ifdef CONFIG_PAX_MPROTECT
58606 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58607 +#endif
58608 +
58609 + )
58610 + {
58611 + *flags &= ~MF_PAX_MPROTECT;
58612 + retval = -EINVAL;
58613 + }
58614 +
58615 + if ((*flags & MF_PAX_EMUTRAMP)
58616 +
58617 +#ifdef CONFIG_PAX_EMUTRAMP
58618 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58619 +#endif
58620 +
58621 + )
58622 + {
58623 + *flags &= ~MF_PAX_EMUTRAMP;
58624 + retval = -EINVAL;
58625 + }
58626 +
58627 + return retval;
58628 +}
58629 +
58630 +EXPORT_SYMBOL(pax_check_flags);
58631 +
58632 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58633 +char *pax_get_path(const struct path *path, char *buf, int buflen)
58634 +{
58635 + char *pathname = d_path(path, buf, buflen);
58636 +
58637 + if (IS_ERR(pathname))
58638 + goto toolong;
58639 +
58640 + pathname = mangle_path(buf, pathname, "\t\n\\");
58641 + if (!pathname)
58642 + goto toolong;
58643 +
58644 + *pathname = 0;
58645 + return buf;
58646 +
58647 +toolong:
58648 + return "<path too long>";
58649 +}
58650 +EXPORT_SYMBOL(pax_get_path);
58651 +
58652 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
58653 +{
58654 + struct task_struct *tsk = current;
58655 + struct mm_struct *mm = current->mm;
58656 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
58657 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
58658 + char *path_exec = NULL;
58659 + char *path_fault = NULL;
58660 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
58661 + siginfo_t info = { };
58662 +
58663 + if (buffer_exec && buffer_fault) {
58664 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
58665 +
58666 + down_read(&mm->mmap_sem);
58667 + vma = mm->mmap;
58668 + while (vma && (!vma_exec || !vma_fault)) {
58669 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
58670 + vma_exec = vma;
58671 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
58672 + vma_fault = vma;
58673 + vma = vma->vm_next;
58674 + }
58675 + if (vma_exec)
58676 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
58677 + if (vma_fault) {
58678 + start = vma_fault->vm_start;
58679 + end = vma_fault->vm_end;
58680 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
58681 + if (vma_fault->vm_file)
58682 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
58683 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
58684 + path_fault = "<heap>";
58685 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
58686 + path_fault = "<stack>";
58687 + else
58688 + path_fault = "<anonymous mapping>";
58689 + }
58690 + up_read(&mm->mmap_sem);
58691 + }
58692 + if (tsk->signal->curr_ip)
58693 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
58694 + else
58695 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
58696 + 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),
58697 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
58698 + free_page((unsigned long)buffer_exec);
58699 + free_page((unsigned long)buffer_fault);
58700 + pax_report_insns(regs, pc, sp);
58701 + info.si_signo = SIGKILL;
58702 + info.si_errno = 0;
58703 + info.si_code = SI_KERNEL;
58704 + info.si_pid = 0;
58705 + info.si_uid = 0;
58706 + do_coredump(&info);
58707 +}
58708 +#endif
58709 +
58710 +#ifdef CONFIG_PAX_REFCOUNT
58711 +void pax_report_refcount_overflow(struct pt_regs *regs)
58712 +{
58713 + if (current->signal->curr_ip)
58714 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
58715 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
58716 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58717 + else
58718 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
58719 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58720 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
58721 + preempt_disable();
58722 + show_regs(regs);
58723 + preempt_enable();
58724 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
58725 +}
58726 +#endif
58727 +
58728 +#ifdef CONFIG_PAX_USERCOPY
58729 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
58730 +static noinline int check_stack_object(const void *obj, unsigned long len)
58731 +{
58732 + const void * const stack = task_stack_page(current);
58733 + const void * const stackend = stack + THREAD_SIZE;
58734 +
58735 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58736 + const void *frame = NULL;
58737 + const void *oldframe;
58738 +#endif
58739 +
58740 + if (obj + len < obj)
58741 + return -1;
58742 +
58743 + if (obj + len <= stack || stackend <= obj)
58744 + return 0;
58745 +
58746 + if (obj < stack || stackend < obj + len)
58747 + return -1;
58748 +
58749 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58750 + oldframe = __builtin_frame_address(1);
58751 + if (oldframe)
58752 + frame = __builtin_frame_address(2);
58753 + /*
58754 + low ----------------------------------------------> high
58755 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
58756 + ^----------------^
58757 + allow copies only within here
58758 + */
58759 + while (stack <= frame && frame < stackend) {
58760 + /* if obj + len extends past the last frame, this
58761 + check won't pass and the next frame will be 0,
58762 + causing us to bail out and correctly report
58763 + the copy as invalid
58764 + */
58765 + if (obj + len <= frame)
58766 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
58767 + oldframe = frame;
58768 + frame = *(const void * const *)frame;
58769 + }
58770 + return -1;
58771 +#else
58772 + return 1;
58773 +#endif
58774 +}
58775 +
58776 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
58777 +{
58778 + if (current->signal->curr_ip)
58779 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58780 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58781 + else
58782 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58783 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58784 + dump_stack();
58785 + gr_handle_kernel_exploit();
58786 + do_group_exit(SIGKILL);
58787 +}
58788 +#endif
58789 +
58790 +#ifdef CONFIG_PAX_USERCOPY
58791 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
58792 +{
58793 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
58794 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
58795 +#ifdef CONFIG_MODULES
58796 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
58797 +#else
58798 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
58799 +#endif
58800 +
58801 +#else
58802 + unsigned long textlow = (unsigned long)_stext;
58803 + unsigned long texthigh = (unsigned long)_etext;
58804 +
58805 +#ifdef CONFIG_X86_64
58806 + /* check against linear mapping as well */
58807 + if (high > (unsigned long)__va(__pa(textlow)) &&
58808 + low < (unsigned long)__va(__pa(texthigh)))
58809 + return true;
58810 +#endif
58811 +
58812 +#endif
58813 +
58814 + if (high <= textlow || low >= texthigh)
58815 + return false;
58816 + else
58817 + return true;
58818 +}
58819 +#endif
58820 +
58821 +void __check_object_size(const void *ptr, unsigned long n, bool to_user)
58822 +{
58823 +
58824 +#ifdef CONFIG_PAX_USERCOPY
58825 + const char *type;
58826 +
58827 + if (!n)
58828 + return;
58829 +
58830 + type = check_heap_object(ptr, n);
58831 + if (!type) {
58832 + int ret = check_stack_object(ptr, n);
58833 + if (ret == 1 || ret == 2)
58834 + return;
58835 + if (ret == 0) {
58836 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
58837 + type = "<kernel text>";
58838 + else
58839 + return;
58840 + } else
58841 + type = "<process stack>";
58842 + }
58843 +
58844 + pax_report_usercopy(ptr, n, to_user, type);
58845 +#endif
58846 +
58847 +}
58848 +EXPORT_SYMBOL(__check_object_size);
58849 +
58850 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
58851 +void pax_track_stack(void)
58852 +{
58853 + unsigned long sp = (unsigned long)&sp;
58854 + if (sp < current_thread_info()->lowest_stack &&
58855 + sp > (unsigned long)task_stack_page(current))
58856 + current_thread_info()->lowest_stack = sp;
58857 +}
58858 +EXPORT_SYMBOL(pax_track_stack);
58859 +#endif
58860 +
58861 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
58862 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
58863 +{
58864 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
58865 + dump_stack();
58866 + do_group_exit(SIGKILL);
58867 +}
58868 +EXPORT_SYMBOL(report_size_overflow);
58869 +#endif
58870 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
58871 index 9f9992b..8b59411 100644
58872 --- a/fs/ext2/balloc.c
58873 +++ b/fs/ext2/balloc.c
58874 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
58875
58876 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58877 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58878 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58879 + if (free_blocks < root_blocks + 1 &&
58880 !uid_eq(sbi->s_resuid, current_fsuid()) &&
58881 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58882 - !in_group_p (sbi->s_resgid))) {
58883 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58884 return 0;
58885 }
58886 return 1;
58887 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
58888 index 9142614..97484fa 100644
58889 --- a/fs/ext2/xattr.c
58890 +++ b/fs/ext2/xattr.c
58891 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
58892 struct buffer_head *bh = NULL;
58893 struct ext2_xattr_entry *entry;
58894 char *end;
58895 - size_t rest = buffer_size;
58896 + size_t rest = buffer_size, total_size = 0;
58897 int error;
58898
58899 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
58900 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
58901 buffer += size;
58902 }
58903 rest -= size;
58904 + total_size += size;
58905 }
58906 }
58907 - error = buffer_size - rest; /* total size */
58908 + error = total_size;
58909
58910 cleanup:
58911 brelse(bh);
58912 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
58913 index 22548f5..41521d8 100644
58914 --- a/fs/ext3/balloc.c
58915 +++ b/fs/ext3/balloc.c
58916 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
58917
58918 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58919 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58920 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58921 + if (free_blocks < root_blocks + 1 &&
58922 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
58923 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58924 - !in_group_p (sbi->s_resgid))) {
58925 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58926 return 0;
58927 }
58928 return 1;
58929 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
58930 index c6874be..f8a6ae8 100644
58931 --- a/fs/ext3/xattr.c
58932 +++ b/fs/ext3/xattr.c
58933 @@ -330,7 +330,7 @@ static int
58934 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
58935 char *buffer, size_t buffer_size)
58936 {
58937 - size_t rest = buffer_size;
58938 + size_t rest = buffer_size, total_size = 0;
58939
58940 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
58941 const struct xattr_handler *handler =
58942 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
58943 buffer += size;
58944 }
58945 rest -= size;
58946 + total_size += size;
58947 }
58948 }
58949 - return buffer_size - rest;
58950 + return total_size;
58951 }
58952
58953 static int
58954 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
58955 index 6ea7b14..8fa16d9 100644
58956 --- a/fs/ext4/balloc.c
58957 +++ b/fs/ext4/balloc.c
58958 @@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
58959 /* Hm, nope. Are (enough) root reserved clusters available? */
58960 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
58961 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
58962 - capable(CAP_SYS_RESOURCE) ||
58963 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
58964 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
58965 + capable_nolog(CAP_SYS_RESOURCE)) {
58966
58967 if (free_clusters >= (nclusters + dirty_clusters +
58968 resv_clusters))
58969 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
58970 index d3a534f..242c50a 100644
58971 --- a/fs/ext4/ext4.h
58972 +++ b/fs/ext4/ext4.h
58973 @@ -1269,19 +1269,19 @@ struct ext4_sb_info {
58974 unsigned long s_mb_last_start;
58975
58976 /* stats for buddy allocator */
58977 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
58978 - atomic_t s_bal_success; /* we found long enough chunks */
58979 - atomic_t s_bal_allocated; /* in blocks */
58980 - atomic_t s_bal_ex_scanned; /* total extents scanned */
58981 - atomic_t s_bal_goals; /* goal hits */
58982 - atomic_t s_bal_breaks; /* too long searches */
58983 - atomic_t s_bal_2orders; /* 2^order hits */
58984 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
58985 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
58986 + atomic_unchecked_t s_bal_allocated; /* in blocks */
58987 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
58988 + atomic_unchecked_t s_bal_goals; /* goal hits */
58989 + atomic_unchecked_t s_bal_breaks; /* too long searches */
58990 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
58991 spinlock_t s_bal_lock;
58992 unsigned long s_mb_buddies_generated;
58993 unsigned long long s_mb_generation_time;
58994 - atomic_t s_mb_lost_chunks;
58995 - atomic_t s_mb_preallocated;
58996 - atomic_t s_mb_discarded;
58997 + atomic_unchecked_t s_mb_lost_chunks;
58998 + atomic_unchecked_t s_mb_preallocated;
58999 + atomic_unchecked_t s_mb_discarded;
59000 atomic_t s_lock_busy;
59001
59002 /* locality groups */
59003 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59004 index 04a5c75..09894fa 100644
59005 --- a/fs/ext4/mballoc.c
59006 +++ b/fs/ext4/mballoc.c
59007 @@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59008 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59009
59010 if (EXT4_SB(sb)->s_mb_stats)
59011 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59012 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59013
59014 break;
59015 }
59016 @@ -2189,7 +2189,7 @@ repeat:
59017 ac->ac_status = AC_STATUS_CONTINUE;
59018 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59019 cr = 3;
59020 - atomic_inc(&sbi->s_mb_lost_chunks);
59021 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59022 goto repeat;
59023 }
59024 }
59025 @@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59026 if (sbi->s_mb_stats) {
59027 ext4_msg(sb, KERN_INFO,
59028 "mballoc: %u blocks %u reqs (%u success)",
59029 - atomic_read(&sbi->s_bal_allocated),
59030 - atomic_read(&sbi->s_bal_reqs),
59031 - atomic_read(&sbi->s_bal_success));
59032 + atomic_read_unchecked(&sbi->s_bal_allocated),
59033 + atomic_read_unchecked(&sbi->s_bal_reqs),
59034 + atomic_read_unchecked(&sbi->s_bal_success));
59035 ext4_msg(sb, KERN_INFO,
59036 "mballoc: %u extents scanned, %u goal hits, "
59037 "%u 2^N hits, %u breaks, %u lost",
59038 - atomic_read(&sbi->s_bal_ex_scanned),
59039 - atomic_read(&sbi->s_bal_goals),
59040 - atomic_read(&sbi->s_bal_2orders),
59041 - atomic_read(&sbi->s_bal_breaks),
59042 - atomic_read(&sbi->s_mb_lost_chunks));
59043 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59044 + atomic_read_unchecked(&sbi->s_bal_goals),
59045 + atomic_read_unchecked(&sbi->s_bal_2orders),
59046 + atomic_read_unchecked(&sbi->s_bal_breaks),
59047 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59048 ext4_msg(sb, KERN_INFO,
59049 "mballoc: %lu generated and it took %Lu",
59050 sbi->s_mb_buddies_generated,
59051 sbi->s_mb_generation_time);
59052 ext4_msg(sb, KERN_INFO,
59053 "mballoc: %u preallocated, %u discarded",
59054 - atomic_read(&sbi->s_mb_preallocated),
59055 - atomic_read(&sbi->s_mb_discarded));
59056 + atomic_read_unchecked(&sbi->s_mb_preallocated),
59057 + atomic_read_unchecked(&sbi->s_mb_discarded));
59058 }
59059
59060 free_percpu(sbi->s_locality_groups);
59061 @@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59062 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59063
59064 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59065 - atomic_inc(&sbi->s_bal_reqs);
59066 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59067 + atomic_inc_unchecked(&sbi->s_bal_reqs);
59068 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59069 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59070 - atomic_inc(&sbi->s_bal_success);
59071 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59072 + atomic_inc_unchecked(&sbi->s_bal_success);
59073 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59074 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59075 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59076 - atomic_inc(&sbi->s_bal_goals);
59077 + atomic_inc_unchecked(&sbi->s_bal_goals);
59078 if (ac->ac_found > sbi->s_mb_max_to_scan)
59079 - atomic_inc(&sbi->s_bal_breaks);
59080 + atomic_inc_unchecked(&sbi->s_bal_breaks);
59081 }
59082
59083 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59084 @@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59085 trace_ext4_mb_new_inode_pa(ac, pa);
59086
59087 ext4_mb_use_inode_pa(ac, pa);
59088 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59089 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59090
59091 ei = EXT4_I(ac->ac_inode);
59092 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59093 @@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59094 trace_ext4_mb_new_group_pa(ac, pa);
59095
59096 ext4_mb_use_group_pa(ac, pa);
59097 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59098 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59099
59100 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59101 lg = ac->ac_lg;
59102 @@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59103 * from the bitmap and continue.
59104 */
59105 }
59106 - atomic_add(free, &sbi->s_mb_discarded);
59107 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
59108
59109 return err;
59110 }
59111 @@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59112 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59113 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59114 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59115 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59116 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59117 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59118
59119 return 0;
59120 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59121 index 04434ad..6404663 100644
59122 --- a/fs/ext4/mmp.c
59123 +++ b/fs/ext4/mmp.c
59124 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59125 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59126 const char *function, unsigned int line, const char *msg)
59127 {
59128 - __ext4_warning(sb, function, line, msg);
59129 + __ext4_warning(sb, function, line, "%s", msg);
59130 __ext4_warning(sb, function, line,
59131 "MMP failure info: last update time: %llu, last update "
59132 "node: %s, last update device: %s\n",
59133 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59134 index 710fed2..a82e4e8 100644
59135 --- a/fs/ext4/super.c
59136 +++ b/fs/ext4/super.c
59137 @@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59138 }
59139
59140 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59141 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59142 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59143 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59144
59145 #ifdef CONFIG_QUOTA
59146 @@ -2450,7 +2450,7 @@ struct ext4_attr {
59147 int offset;
59148 int deprecated_val;
59149 } u;
59150 -};
59151 +} __do_const;
59152
59153 static int parse_strtoull(const char *buf,
59154 unsigned long long max, unsigned long long *value)
59155 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59156 index e175e94..3ea69bf 100644
59157 --- a/fs/ext4/xattr.c
59158 +++ b/fs/ext4/xattr.c
59159 @@ -381,7 +381,7 @@ static int
59160 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59161 char *buffer, size_t buffer_size)
59162 {
59163 - size_t rest = buffer_size;
59164 + size_t rest = buffer_size, total_size = 0;
59165
59166 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59167 const struct xattr_handler *handler =
59168 @@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59169 buffer += size;
59170 }
59171 rest -= size;
59172 + total_size += size;
59173 }
59174 }
59175 - return buffer_size - rest;
59176 + return total_size;
59177 }
59178
59179 static int
59180 diff --git a/fs/fcntl.c b/fs/fcntl.c
59181 index ef68665..5deacdc 100644
59182 --- a/fs/fcntl.c
59183 +++ b/fs/fcntl.c
59184 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59185 if (err)
59186 return err;
59187
59188 + if (gr_handle_chroot_fowner(pid, type))
59189 + return -ENOENT;
59190 + if (gr_check_protected_task_fowner(pid, type))
59191 + return -EACCES;
59192 +
59193 f_modown(filp, pid, type, force);
59194 return 0;
59195 }
59196 diff --git a/fs/fhandle.c b/fs/fhandle.c
59197 index 999ff5c..41f4109 100644
59198 --- a/fs/fhandle.c
59199 +++ b/fs/fhandle.c
59200 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59201 } else
59202 retval = 0;
59203 /* copy the mount id */
59204 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59205 - sizeof(*mnt_id)) ||
59206 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59207 copy_to_user(ufh, handle,
59208 sizeof(struct file_handle) + handle_bytes))
59209 retval = -EFAULT;
59210 diff --git a/fs/file.c b/fs/file.c
59211 index eb56a13..ccee850 100644
59212 --- a/fs/file.c
59213 +++ b/fs/file.c
59214 @@ -16,6 +16,7 @@
59215 #include <linux/slab.h>
59216 #include <linux/vmalloc.h>
59217 #include <linux/file.h>
59218 +#include <linux/security.h>
59219 #include <linux/fdtable.h>
59220 #include <linux/bitops.h>
59221 #include <linux/interrupt.h>
59222 @@ -141,7 +142,7 @@ out:
59223 * Return <0 error code on error; 1 on successful completion.
59224 * The files->file_lock should be held on entry, and will be held on exit.
59225 */
59226 -static int expand_fdtable(struct files_struct *files, int nr)
59227 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
59228 __releases(files->file_lock)
59229 __acquires(files->file_lock)
59230 {
59231 @@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59232 * expanded and execution may have blocked.
59233 * The files->file_lock should be held on entry, and will be held on exit.
59234 */
59235 -static int expand_files(struct files_struct *files, int nr)
59236 +static int expand_files(struct files_struct *files, unsigned int nr)
59237 {
59238 struct fdtable *fdt;
59239
59240 @@ -807,6 +808,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59241 if (!file)
59242 return __close_fd(files, fd);
59243
59244 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59245 if (fd >= rlimit(RLIMIT_NOFILE))
59246 return -EBADF;
59247
59248 @@ -833,6 +835,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59249 if (unlikely(oldfd == newfd))
59250 return -EINVAL;
59251
59252 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59253 if (newfd >= rlimit(RLIMIT_NOFILE))
59254 return -EBADF;
59255
59256 @@ -888,6 +891,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59257 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59258 {
59259 int err;
59260 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59261 if (from >= rlimit(RLIMIT_NOFILE))
59262 return -EINVAL;
59263 err = alloc_fd(from, flags);
59264 diff --git a/fs/filesystems.c b/fs/filesystems.c
59265 index 92567d9..fcd8cbf 100644
59266 --- a/fs/filesystems.c
59267 +++ b/fs/filesystems.c
59268 @@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
59269 int len = dot ? dot - name : strlen(name);
59270
59271 fs = __get_fs_type(name, len);
59272 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
59273 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59274 +#else
59275 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59276 +#endif
59277 fs = __get_fs_type(name, len);
59278
59279 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59280 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59281 index 7dca743..543d620 100644
59282 --- a/fs/fs_struct.c
59283 +++ b/fs/fs_struct.c
59284 @@ -4,6 +4,7 @@
59285 #include <linux/path.h>
59286 #include <linux/slab.h>
59287 #include <linux/fs_struct.h>
59288 +#include <linux/grsecurity.h>
59289 #include "internal.h"
59290
59291 /*
59292 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59293 write_seqcount_begin(&fs->seq);
59294 old_root = fs->root;
59295 fs->root = *path;
59296 + gr_set_chroot_entries(current, path);
59297 write_seqcount_end(&fs->seq);
59298 spin_unlock(&fs->lock);
59299 if (old_root.dentry)
59300 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59301 int hits = 0;
59302 spin_lock(&fs->lock);
59303 write_seqcount_begin(&fs->seq);
59304 + /* this root replacement is only done by pivot_root,
59305 + leave grsec's chroot tagging alone for this task
59306 + so that a pivoted root isn't treated as a chroot
59307 + */
59308 hits += replace_path(&fs->root, old_root, new_root);
59309 hits += replace_path(&fs->pwd, old_root, new_root);
59310 write_seqcount_end(&fs->seq);
59311 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59312 task_lock(tsk);
59313 spin_lock(&fs->lock);
59314 tsk->fs = NULL;
59315 - kill = !--fs->users;
59316 + gr_clear_chroot_entries(tsk);
59317 + kill = !atomic_dec_return(&fs->users);
59318 spin_unlock(&fs->lock);
59319 task_unlock(tsk);
59320 if (kill)
59321 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59322 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59323 /* We don't need to lock fs - think why ;-) */
59324 if (fs) {
59325 - fs->users = 1;
59326 + atomic_set(&fs->users, 1);
59327 fs->in_exec = 0;
59328 spin_lock_init(&fs->lock);
59329 seqcount_init(&fs->seq);
59330 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59331 spin_lock(&old->lock);
59332 fs->root = old->root;
59333 path_get(&fs->root);
59334 + /* instead of calling gr_set_chroot_entries here,
59335 + we call it from every caller of this function
59336 + */
59337 fs->pwd = old->pwd;
59338 path_get(&fs->pwd);
59339 spin_unlock(&old->lock);
59340 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59341
59342 task_lock(current);
59343 spin_lock(&fs->lock);
59344 - kill = !--fs->users;
59345 + kill = !atomic_dec_return(&fs->users);
59346 current->fs = new_fs;
59347 + gr_set_chroot_entries(current, &new_fs->root);
59348 spin_unlock(&fs->lock);
59349 task_unlock(current);
59350
59351 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59352
59353 int current_umask(void)
59354 {
59355 - return current->fs->umask;
59356 + return current->fs->umask | gr_acl_umask();
59357 }
59358 EXPORT_SYMBOL(current_umask);
59359
59360 /* to be mentioned only in INIT_TASK */
59361 struct fs_struct init_fs = {
59362 - .users = 1,
59363 + .users = ATOMIC_INIT(1),
59364 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59365 .seq = SEQCNT_ZERO(init_fs.seq),
59366 .umask = 0022,
59367 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59368 index 29d7feb..303644d 100644
59369 --- a/fs/fscache/cookie.c
59370 +++ b/fs/fscache/cookie.c
59371 @@ -19,7 +19,7 @@
59372
59373 struct kmem_cache *fscache_cookie_jar;
59374
59375 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59376 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59377
59378 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59379 static int fscache_alloc_object(struct fscache_cache *cache,
59380 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59381 parent ? (char *) parent->def->name : "<no-parent>",
59382 def->name, netfs_data, enable);
59383
59384 - fscache_stat(&fscache_n_acquires);
59385 + fscache_stat_unchecked(&fscache_n_acquires);
59386
59387 /* if there's no parent cookie, then we don't create one here either */
59388 if (!parent) {
59389 - fscache_stat(&fscache_n_acquires_null);
59390 + fscache_stat_unchecked(&fscache_n_acquires_null);
59391 _leave(" [no parent]");
59392 return NULL;
59393 }
59394 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59395 /* allocate and initialise a cookie */
59396 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59397 if (!cookie) {
59398 - fscache_stat(&fscache_n_acquires_oom);
59399 + fscache_stat_unchecked(&fscache_n_acquires_oom);
59400 _leave(" [ENOMEM]");
59401 return NULL;
59402 }
59403 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59404
59405 switch (cookie->def->type) {
59406 case FSCACHE_COOKIE_TYPE_INDEX:
59407 - fscache_stat(&fscache_n_cookie_index);
59408 + fscache_stat_unchecked(&fscache_n_cookie_index);
59409 break;
59410 case FSCACHE_COOKIE_TYPE_DATAFILE:
59411 - fscache_stat(&fscache_n_cookie_data);
59412 + fscache_stat_unchecked(&fscache_n_cookie_data);
59413 break;
59414 default:
59415 - fscache_stat(&fscache_n_cookie_special);
59416 + fscache_stat_unchecked(&fscache_n_cookie_special);
59417 break;
59418 }
59419
59420 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59421 } else {
59422 atomic_dec(&parent->n_children);
59423 __fscache_cookie_put(cookie);
59424 - fscache_stat(&fscache_n_acquires_nobufs);
59425 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59426 _leave(" = NULL");
59427 return NULL;
59428 }
59429 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59430 }
59431 }
59432
59433 - fscache_stat(&fscache_n_acquires_ok);
59434 + fscache_stat_unchecked(&fscache_n_acquires_ok);
59435 _leave(" = %p", cookie);
59436 return cookie;
59437 }
59438 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59439 cache = fscache_select_cache_for_object(cookie->parent);
59440 if (!cache) {
59441 up_read(&fscache_addremove_sem);
59442 - fscache_stat(&fscache_n_acquires_no_cache);
59443 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59444 _leave(" = -ENOMEDIUM [no cache]");
59445 return -ENOMEDIUM;
59446 }
59447 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59448 object = cache->ops->alloc_object(cache, cookie);
59449 fscache_stat_d(&fscache_n_cop_alloc_object);
59450 if (IS_ERR(object)) {
59451 - fscache_stat(&fscache_n_object_no_alloc);
59452 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
59453 ret = PTR_ERR(object);
59454 goto error;
59455 }
59456
59457 - fscache_stat(&fscache_n_object_alloc);
59458 + fscache_stat_unchecked(&fscache_n_object_alloc);
59459
59460 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59461 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59462
59463 _debug("ALLOC OBJ%x: %s {%lx}",
59464 object->debug_id, cookie->def->name, object->events);
59465 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59466
59467 _enter("{%s}", cookie->def->name);
59468
59469 - fscache_stat(&fscache_n_invalidates);
59470 + fscache_stat_unchecked(&fscache_n_invalidates);
59471
59472 /* Only permit invalidation of data files. Invalidating an index will
59473 * require the caller to release all its attachments to the tree rooted
59474 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59475 {
59476 struct fscache_object *object;
59477
59478 - fscache_stat(&fscache_n_updates);
59479 + fscache_stat_unchecked(&fscache_n_updates);
59480
59481 if (!cookie) {
59482 - fscache_stat(&fscache_n_updates_null);
59483 + fscache_stat_unchecked(&fscache_n_updates_null);
59484 _leave(" [no cookie]");
59485 return;
59486 }
59487 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59488 */
59489 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59490 {
59491 - fscache_stat(&fscache_n_relinquishes);
59492 + fscache_stat_unchecked(&fscache_n_relinquishes);
59493 if (retire)
59494 - fscache_stat(&fscache_n_relinquishes_retire);
59495 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59496
59497 if (!cookie) {
59498 - fscache_stat(&fscache_n_relinquishes_null);
59499 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
59500 _leave(" [no cookie]");
59501 return;
59502 }
59503 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
59504 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
59505 goto inconsistent;
59506
59507 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59508 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59509
59510 __fscache_use_cookie(cookie);
59511 if (fscache_submit_op(object, op) < 0)
59512 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
59513 index 4226f66..0fb3f45 100644
59514 --- a/fs/fscache/internal.h
59515 +++ b/fs/fscache/internal.h
59516 @@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
59517 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
59518 extern int fscache_wait_for_operation_activation(struct fscache_object *,
59519 struct fscache_operation *,
59520 - atomic_t *,
59521 - atomic_t *,
59522 + atomic_unchecked_t *,
59523 + atomic_unchecked_t *,
59524 void (*)(struct fscache_operation *));
59525 extern void fscache_invalidate_writes(struct fscache_cookie *);
59526
59527 @@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
59528 * stats.c
59529 */
59530 #ifdef CONFIG_FSCACHE_STATS
59531 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59532 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59533 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59534 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59535
59536 -extern atomic_t fscache_n_op_pend;
59537 -extern atomic_t fscache_n_op_run;
59538 -extern atomic_t fscache_n_op_enqueue;
59539 -extern atomic_t fscache_n_op_deferred_release;
59540 -extern atomic_t fscache_n_op_release;
59541 -extern atomic_t fscache_n_op_gc;
59542 -extern atomic_t fscache_n_op_cancelled;
59543 -extern atomic_t fscache_n_op_rejected;
59544 +extern atomic_unchecked_t fscache_n_op_pend;
59545 +extern atomic_unchecked_t fscache_n_op_run;
59546 +extern atomic_unchecked_t fscache_n_op_enqueue;
59547 +extern atomic_unchecked_t fscache_n_op_deferred_release;
59548 +extern atomic_unchecked_t fscache_n_op_release;
59549 +extern atomic_unchecked_t fscache_n_op_gc;
59550 +extern atomic_unchecked_t fscache_n_op_cancelled;
59551 +extern atomic_unchecked_t fscache_n_op_rejected;
59552
59553 -extern atomic_t fscache_n_attr_changed;
59554 -extern atomic_t fscache_n_attr_changed_ok;
59555 -extern atomic_t fscache_n_attr_changed_nobufs;
59556 -extern atomic_t fscache_n_attr_changed_nomem;
59557 -extern atomic_t fscache_n_attr_changed_calls;
59558 +extern atomic_unchecked_t fscache_n_attr_changed;
59559 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
59560 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
59561 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
59562 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
59563
59564 -extern atomic_t fscache_n_allocs;
59565 -extern atomic_t fscache_n_allocs_ok;
59566 -extern atomic_t fscache_n_allocs_wait;
59567 -extern atomic_t fscache_n_allocs_nobufs;
59568 -extern atomic_t fscache_n_allocs_intr;
59569 -extern atomic_t fscache_n_allocs_object_dead;
59570 -extern atomic_t fscache_n_alloc_ops;
59571 -extern atomic_t fscache_n_alloc_op_waits;
59572 +extern atomic_unchecked_t fscache_n_allocs;
59573 +extern atomic_unchecked_t fscache_n_allocs_ok;
59574 +extern atomic_unchecked_t fscache_n_allocs_wait;
59575 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
59576 +extern atomic_unchecked_t fscache_n_allocs_intr;
59577 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
59578 +extern atomic_unchecked_t fscache_n_alloc_ops;
59579 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
59580
59581 -extern atomic_t fscache_n_retrievals;
59582 -extern atomic_t fscache_n_retrievals_ok;
59583 -extern atomic_t fscache_n_retrievals_wait;
59584 -extern atomic_t fscache_n_retrievals_nodata;
59585 -extern atomic_t fscache_n_retrievals_nobufs;
59586 -extern atomic_t fscache_n_retrievals_intr;
59587 -extern atomic_t fscache_n_retrievals_nomem;
59588 -extern atomic_t fscache_n_retrievals_object_dead;
59589 -extern atomic_t fscache_n_retrieval_ops;
59590 -extern atomic_t fscache_n_retrieval_op_waits;
59591 +extern atomic_unchecked_t fscache_n_retrievals;
59592 +extern atomic_unchecked_t fscache_n_retrievals_ok;
59593 +extern atomic_unchecked_t fscache_n_retrievals_wait;
59594 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
59595 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
59596 +extern atomic_unchecked_t fscache_n_retrievals_intr;
59597 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
59598 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
59599 +extern atomic_unchecked_t fscache_n_retrieval_ops;
59600 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
59601
59602 -extern atomic_t fscache_n_stores;
59603 -extern atomic_t fscache_n_stores_ok;
59604 -extern atomic_t fscache_n_stores_again;
59605 -extern atomic_t fscache_n_stores_nobufs;
59606 -extern atomic_t fscache_n_stores_oom;
59607 -extern atomic_t fscache_n_store_ops;
59608 -extern atomic_t fscache_n_store_calls;
59609 -extern atomic_t fscache_n_store_pages;
59610 -extern atomic_t fscache_n_store_radix_deletes;
59611 -extern atomic_t fscache_n_store_pages_over_limit;
59612 +extern atomic_unchecked_t fscache_n_stores;
59613 +extern atomic_unchecked_t fscache_n_stores_ok;
59614 +extern atomic_unchecked_t fscache_n_stores_again;
59615 +extern atomic_unchecked_t fscache_n_stores_nobufs;
59616 +extern atomic_unchecked_t fscache_n_stores_oom;
59617 +extern atomic_unchecked_t fscache_n_store_ops;
59618 +extern atomic_unchecked_t fscache_n_store_calls;
59619 +extern atomic_unchecked_t fscache_n_store_pages;
59620 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
59621 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
59622
59623 -extern atomic_t fscache_n_store_vmscan_not_storing;
59624 -extern atomic_t fscache_n_store_vmscan_gone;
59625 -extern atomic_t fscache_n_store_vmscan_busy;
59626 -extern atomic_t fscache_n_store_vmscan_cancelled;
59627 -extern atomic_t fscache_n_store_vmscan_wait;
59628 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59629 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
59630 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
59631 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59632 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
59633
59634 -extern atomic_t fscache_n_marks;
59635 -extern atomic_t fscache_n_uncaches;
59636 +extern atomic_unchecked_t fscache_n_marks;
59637 +extern atomic_unchecked_t fscache_n_uncaches;
59638
59639 -extern atomic_t fscache_n_acquires;
59640 -extern atomic_t fscache_n_acquires_null;
59641 -extern atomic_t fscache_n_acquires_no_cache;
59642 -extern atomic_t fscache_n_acquires_ok;
59643 -extern atomic_t fscache_n_acquires_nobufs;
59644 -extern atomic_t fscache_n_acquires_oom;
59645 +extern atomic_unchecked_t fscache_n_acquires;
59646 +extern atomic_unchecked_t fscache_n_acquires_null;
59647 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
59648 +extern atomic_unchecked_t fscache_n_acquires_ok;
59649 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
59650 +extern atomic_unchecked_t fscache_n_acquires_oom;
59651
59652 -extern atomic_t fscache_n_invalidates;
59653 -extern atomic_t fscache_n_invalidates_run;
59654 +extern atomic_unchecked_t fscache_n_invalidates;
59655 +extern atomic_unchecked_t fscache_n_invalidates_run;
59656
59657 -extern atomic_t fscache_n_updates;
59658 -extern atomic_t fscache_n_updates_null;
59659 -extern atomic_t fscache_n_updates_run;
59660 +extern atomic_unchecked_t fscache_n_updates;
59661 +extern atomic_unchecked_t fscache_n_updates_null;
59662 +extern atomic_unchecked_t fscache_n_updates_run;
59663
59664 -extern atomic_t fscache_n_relinquishes;
59665 -extern atomic_t fscache_n_relinquishes_null;
59666 -extern atomic_t fscache_n_relinquishes_waitcrt;
59667 -extern atomic_t fscache_n_relinquishes_retire;
59668 +extern atomic_unchecked_t fscache_n_relinquishes;
59669 +extern atomic_unchecked_t fscache_n_relinquishes_null;
59670 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59671 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
59672
59673 -extern atomic_t fscache_n_cookie_index;
59674 -extern atomic_t fscache_n_cookie_data;
59675 -extern atomic_t fscache_n_cookie_special;
59676 +extern atomic_unchecked_t fscache_n_cookie_index;
59677 +extern atomic_unchecked_t fscache_n_cookie_data;
59678 +extern atomic_unchecked_t fscache_n_cookie_special;
59679
59680 -extern atomic_t fscache_n_object_alloc;
59681 -extern atomic_t fscache_n_object_no_alloc;
59682 -extern atomic_t fscache_n_object_lookups;
59683 -extern atomic_t fscache_n_object_lookups_negative;
59684 -extern atomic_t fscache_n_object_lookups_positive;
59685 -extern atomic_t fscache_n_object_lookups_timed_out;
59686 -extern atomic_t fscache_n_object_created;
59687 -extern atomic_t fscache_n_object_avail;
59688 -extern atomic_t fscache_n_object_dead;
59689 +extern atomic_unchecked_t fscache_n_object_alloc;
59690 +extern atomic_unchecked_t fscache_n_object_no_alloc;
59691 +extern atomic_unchecked_t fscache_n_object_lookups;
59692 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
59693 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
59694 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
59695 +extern atomic_unchecked_t fscache_n_object_created;
59696 +extern atomic_unchecked_t fscache_n_object_avail;
59697 +extern atomic_unchecked_t fscache_n_object_dead;
59698
59699 -extern atomic_t fscache_n_checkaux_none;
59700 -extern atomic_t fscache_n_checkaux_okay;
59701 -extern atomic_t fscache_n_checkaux_update;
59702 -extern atomic_t fscache_n_checkaux_obsolete;
59703 +extern atomic_unchecked_t fscache_n_checkaux_none;
59704 +extern atomic_unchecked_t fscache_n_checkaux_okay;
59705 +extern atomic_unchecked_t fscache_n_checkaux_update;
59706 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
59707
59708 extern atomic_t fscache_n_cop_alloc_object;
59709 extern atomic_t fscache_n_cop_lookup_object;
59710 @@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
59711 atomic_inc(stat);
59712 }
59713
59714 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
59715 +{
59716 + atomic_inc_unchecked(stat);
59717 +}
59718 +
59719 static inline void fscache_stat_d(atomic_t *stat)
59720 {
59721 atomic_dec(stat);
59722 @@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
59723
59724 #define __fscache_stat(stat) (NULL)
59725 #define fscache_stat(stat) do {} while (0)
59726 +#define fscache_stat_unchecked(stat) do {} while (0)
59727 #define fscache_stat_d(stat) do {} while (0)
59728 #endif
59729
59730 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
59731 index d3b4539..ed0c659 100644
59732 --- a/fs/fscache/object.c
59733 +++ b/fs/fscache/object.c
59734 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59735 _debug("LOOKUP \"%s\" in \"%s\"",
59736 cookie->def->name, object->cache->tag->name);
59737
59738 - fscache_stat(&fscache_n_object_lookups);
59739 + fscache_stat_unchecked(&fscache_n_object_lookups);
59740 fscache_stat(&fscache_n_cop_lookup_object);
59741 ret = object->cache->ops->lookup_object(object);
59742 fscache_stat_d(&fscache_n_cop_lookup_object);
59743 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59744 if (ret == -ETIMEDOUT) {
59745 /* probably stuck behind another object, so move this one to
59746 * the back of the queue */
59747 - fscache_stat(&fscache_n_object_lookups_timed_out);
59748 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
59749 _leave(" [timeout]");
59750 return NO_TRANSIT;
59751 }
59752 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
59753 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
59754
59755 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59756 - fscache_stat(&fscache_n_object_lookups_negative);
59757 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
59758
59759 /* Allow write requests to begin stacking up and read requests to begin
59760 * returning ENODATA.
59761 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
59762 /* if we were still looking up, then we must have a positive lookup
59763 * result, in which case there may be data available */
59764 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59765 - fscache_stat(&fscache_n_object_lookups_positive);
59766 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
59767
59768 /* We do (presumably) have data */
59769 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
59770 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
59771 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
59772 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
59773 } else {
59774 - fscache_stat(&fscache_n_object_created);
59775 + fscache_stat_unchecked(&fscache_n_object_created);
59776 }
59777
59778 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
59779 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
59780 fscache_stat_d(&fscache_n_cop_lookup_complete);
59781
59782 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
59783 - fscache_stat(&fscache_n_object_avail);
59784 + fscache_stat_unchecked(&fscache_n_object_avail);
59785
59786 _leave("");
59787 return transit_to(JUMPSTART_DEPS);
59788 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
59789
59790 /* this just shifts the object release to the work processor */
59791 fscache_put_object(object);
59792 - fscache_stat(&fscache_n_object_dead);
59793 + fscache_stat_unchecked(&fscache_n_object_dead);
59794
59795 _leave("");
59796 return transit_to(OBJECT_DEAD);
59797 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59798 enum fscache_checkaux result;
59799
59800 if (!object->cookie->def->check_aux) {
59801 - fscache_stat(&fscache_n_checkaux_none);
59802 + fscache_stat_unchecked(&fscache_n_checkaux_none);
59803 return FSCACHE_CHECKAUX_OKAY;
59804 }
59805
59806 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59807 switch (result) {
59808 /* entry okay as is */
59809 case FSCACHE_CHECKAUX_OKAY:
59810 - fscache_stat(&fscache_n_checkaux_okay);
59811 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
59812 break;
59813
59814 /* entry requires update */
59815 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
59816 - fscache_stat(&fscache_n_checkaux_update);
59817 + fscache_stat_unchecked(&fscache_n_checkaux_update);
59818 break;
59819
59820 /* entry requires deletion */
59821 case FSCACHE_CHECKAUX_OBSOLETE:
59822 - fscache_stat(&fscache_n_checkaux_obsolete);
59823 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
59824 break;
59825
59826 default:
59827 @@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
59828 {
59829 const struct fscache_state *s;
59830
59831 - fscache_stat(&fscache_n_invalidates_run);
59832 + fscache_stat_unchecked(&fscache_n_invalidates_run);
59833 fscache_stat(&fscache_n_cop_invalidate_object);
59834 s = _fscache_invalidate_object(object, event);
59835 fscache_stat_d(&fscache_n_cop_invalidate_object);
59836 @@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
59837 {
59838 _enter("{OBJ%x},%d", object->debug_id, event);
59839
59840 - fscache_stat(&fscache_n_updates_run);
59841 + fscache_stat_unchecked(&fscache_n_updates_run);
59842 fscache_stat(&fscache_n_cop_update_object);
59843 object->cache->ops->update_object(object);
59844 fscache_stat_d(&fscache_n_cop_update_object);
59845 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
59846 index 318071a..379938b 100644
59847 --- a/fs/fscache/operation.c
59848 +++ b/fs/fscache/operation.c
59849 @@ -17,7 +17,7 @@
59850 #include <linux/slab.h>
59851 #include "internal.h"
59852
59853 -atomic_t fscache_op_debug_id;
59854 +atomic_unchecked_t fscache_op_debug_id;
59855 EXPORT_SYMBOL(fscache_op_debug_id);
59856
59857 /**
59858 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
59859 ASSERTCMP(atomic_read(&op->usage), >, 0);
59860 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
59861
59862 - fscache_stat(&fscache_n_op_enqueue);
59863 + fscache_stat_unchecked(&fscache_n_op_enqueue);
59864 switch (op->flags & FSCACHE_OP_TYPE) {
59865 case FSCACHE_OP_ASYNC:
59866 _debug("queue async");
59867 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
59868 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
59869 if (op->processor)
59870 fscache_enqueue_operation(op);
59871 - fscache_stat(&fscache_n_op_run);
59872 + fscache_stat_unchecked(&fscache_n_op_run);
59873 }
59874
59875 /*
59876 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59877 if (object->n_in_progress > 0) {
59878 atomic_inc(&op->usage);
59879 list_add_tail(&op->pend_link, &object->pending_ops);
59880 - fscache_stat(&fscache_n_op_pend);
59881 + fscache_stat_unchecked(&fscache_n_op_pend);
59882 } else if (!list_empty(&object->pending_ops)) {
59883 atomic_inc(&op->usage);
59884 list_add_tail(&op->pend_link, &object->pending_ops);
59885 - fscache_stat(&fscache_n_op_pend);
59886 + fscache_stat_unchecked(&fscache_n_op_pend);
59887 fscache_start_operations(object);
59888 } else {
59889 ASSERTCMP(object->n_in_progress, ==, 0);
59890 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59891 object->n_exclusive++; /* reads and writes must wait */
59892 atomic_inc(&op->usage);
59893 list_add_tail(&op->pend_link, &object->pending_ops);
59894 - fscache_stat(&fscache_n_op_pend);
59895 + fscache_stat_unchecked(&fscache_n_op_pend);
59896 ret = 0;
59897 } else {
59898 /* If we're in any other state, there must have been an I/O
59899 @@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
59900 if (object->n_exclusive > 0) {
59901 atomic_inc(&op->usage);
59902 list_add_tail(&op->pend_link, &object->pending_ops);
59903 - fscache_stat(&fscache_n_op_pend);
59904 + fscache_stat_unchecked(&fscache_n_op_pend);
59905 } else if (!list_empty(&object->pending_ops)) {
59906 atomic_inc(&op->usage);
59907 list_add_tail(&op->pend_link, &object->pending_ops);
59908 - fscache_stat(&fscache_n_op_pend);
59909 + fscache_stat_unchecked(&fscache_n_op_pend);
59910 fscache_start_operations(object);
59911 } else {
59912 ASSERTCMP(object->n_exclusive, ==, 0);
59913 @@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
59914 object->n_ops++;
59915 atomic_inc(&op->usage);
59916 list_add_tail(&op->pend_link, &object->pending_ops);
59917 - fscache_stat(&fscache_n_op_pend);
59918 + fscache_stat_unchecked(&fscache_n_op_pend);
59919 ret = 0;
59920 } else if (fscache_object_is_dying(object)) {
59921 - fscache_stat(&fscache_n_op_rejected);
59922 + fscache_stat_unchecked(&fscache_n_op_rejected);
59923 op->state = FSCACHE_OP_ST_CANCELLED;
59924 ret = -ENOBUFS;
59925 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
59926 @@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
59927 ret = -EBUSY;
59928 if (op->state == FSCACHE_OP_ST_PENDING) {
59929 ASSERT(!list_empty(&op->pend_link));
59930 - fscache_stat(&fscache_n_op_cancelled);
59931 + fscache_stat_unchecked(&fscache_n_op_cancelled);
59932 list_del_init(&op->pend_link);
59933 if (do_cancel)
59934 do_cancel(op);
59935 @@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
59936 while (!list_empty(&object->pending_ops)) {
59937 op = list_entry(object->pending_ops.next,
59938 struct fscache_operation, pend_link);
59939 - fscache_stat(&fscache_n_op_cancelled);
59940 + fscache_stat_unchecked(&fscache_n_op_cancelled);
59941 list_del_init(&op->pend_link);
59942
59943 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
59944 @@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
59945 op->state, ==, FSCACHE_OP_ST_CANCELLED);
59946 op->state = FSCACHE_OP_ST_DEAD;
59947
59948 - fscache_stat(&fscache_n_op_release);
59949 + fscache_stat_unchecked(&fscache_n_op_release);
59950
59951 if (op->release) {
59952 op->release(op);
59953 @@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
59954 * lock, and defer it otherwise */
59955 if (!spin_trylock(&object->lock)) {
59956 _debug("defer put");
59957 - fscache_stat(&fscache_n_op_deferred_release);
59958 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
59959
59960 cache = object->cache;
59961 spin_lock(&cache->op_gc_list_lock);
59962 @@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
59963
59964 _debug("GC DEFERRED REL OBJ%x OP%x",
59965 object->debug_id, op->debug_id);
59966 - fscache_stat(&fscache_n_op_gc);
59967 + fscache_stat_unchecked(&fscache_n_op_gc);
59968
59969 ASSERTCMP(atomic_read(&op->usage), ==, 0);
59970 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
59971 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
59972 index 7f5c658..6c1e164 100644
59973 --- a/fs/fscache/page.c
59974 +++ b/fs/fscache/page.c
59975 @@ -61,7 +61,7 @@ try_again:
59976 val = radix_tree_lookup(&cookie->stores, page->index);
59977 if (!val) {
59978 rcu_read_unlock();
59979 - fscache_stat(&fscache_n_store_vmscan_not_storing);
59980 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
59981 __fscache_uncache_page(cookie, page);
59982 return true;
59983 }
59984 @@ -91,11 +91,11 @@ try_again:
59985 spin_unlock(&cookie->stores_lock);
59986
59987 if (xpage) {
59988 - fscache_stat(&fscache_n_store_vmscan_cancelled);
59989 - fscache_stat(&fscache_n_store_radix_deletes);
59990 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
59991 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
59992 ASSERTCMP(xpage, ==, page);
59993 } else {
59994 - fscache_stat(&fscache_n_store_vmscan_gone);
59995 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
59996 }
59997
59998 wake_up_bit(&cookie->flags, 0);
59999 @@ -110,11 +110,11 @@ page_busy:
60000 * sleeping on memory allocation, so we may need to impose a timeout
60001 * too. */
60002 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60003 - fscache_stat(&fscache_n_store_vmscan_busy);
60004 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60005 return false;
60006 }
60007
60008 - fscache_stat(&fscache_n_store_vmscan_wait);
60009 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60010 __fscache_wait_on_page_write(cookie, page);
60011 gfp &= ~__GFP_WAIT;
60012 goto try_again;
60013 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60014 FSCACHE_COOKIE_STORING_TAG);
60015 if (!radix_tree_tag_get(&cookie->stores, page->index,
60016 FSCACHE_COOKIE_PENDING_TAG)) {
60017 - fscache_stat(&fscache_n_store_radix_deletes);
60018 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60019 xpage = radix_tree_delete(&cookie->stores, page->index);
60020 }
60021 spin_unlock(&cookie->stores_lock);
60022 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60023
60024 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60025
60026 - fscache_stat(&fscache_n_attr_changed_calls);
60027 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60028
60029 if (fscache_object_is_active(object)) {
60030 fscache_stat(&fscache_n_cop_attr_changed);
60031 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60032
60033 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60034
60035 - fscache_stat(&fscache_n_attr_changed);
60036 + fscache_stat_unchecked(&fscache_n_attr_changed);
60037
60038 op = kzalloc(sizeof(*op), GFP_KERNEL);
60039 if (!op) {
60040 - fscache_stat(&fscache_n_attr_changed_nomem);
60041 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60042 _leave(" = -ENOMEM");
60043 return -ENOMEM;
60044 }
60045 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60046 if (fscache_submit_exclusive_op(object, op) < 0)
60047 goto nobufs;
60048 spin_unlock(&cookie->lock);
60049 - fscache_stat(&fscache_n_attr_changed_ok);
60050 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60051 fscache_put_operation(op);
60052 _leave(" = 0");
60053 return 0;
60054 @@ -225,7 +225,7 @@ nobufs:
60055 kfree(op);
60056 if (wake_cookie)
60057 __fscache_wake_unused_cookie(cookie);
60058 - fscache_stat(&fscache_n_attr_changed_nobufs);
60059 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60060 _leave(" = %d", -ENOBUFS);
60061 return -ENOBUFS;
60062 }
60063 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60064 /* allocate a retrieval operation and attempt to submit it */
60065 op = kzalloc(sizeof(*op), GFP_NOIO);
60066 if (!op) {
60067 - fscache_stat(&fscache_n_retrievals_nomem);
60068 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60069 return NULL;
60070 }
60071
60072 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60073 return 0;
60074 }
60075
60076 - fscache_stat(&fscache_n_retrievals_wait);
60077 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
60078
60079 jif = jiffies;
60080 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60081 fscache_wait_bit_interruptible,
60082 TASK_INTERRUPTIBLE) != 0) {
60083 - fscache_stat(&fscache_n_retrievals_intr);
60084 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60085 _leave(" = -ERESTARTSYS");
60086 return -ERESTARTSYS;
60087 }
60088 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60089 */
60090 int fscache_wait_for_operation_activation(struct fscache_object *object,
60091 struct fscache_operation *op,
60092 - atomic_t *stat_op_waits,
60093 - atomic_t *stat_object_dead,
60094 + atomic_unchecked_t *stat_op_waits,
60095 + atomic_unchecked_t *stat_object_dead,
60096 void (*do_cancel)(struct fscache_operation *))
60097 {
60098 int ret;
60099 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60100
60101 _debug(">>> WT");
60102 if (stat_op_waits)
60103 - fscache_stat(stat_op_waits);
60104 + fscache_stat_unchecked(stat_op_waits);
60105 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60106 fscache_wait_bit_interruptible,
60107 TASK_INTERRUPTIBLE) != 0) {
60108 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60109 check_if_dead:
60110 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60111 if (stat_object_dead)
60112 - fscache_stat(stat_object_dead);
60113 + fscache_stat_unchecked(stat_object_dead);
60114 _leave(" = -ENOBUFS [cancelled]");
60115 return -ENOBUFS;
60116 }
60117 @@ -366,7 +366,7 @@ check_if_dead:
60118 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60119 fscache_cancel_op(op, do_cancel);
60120 if (stat_object_dead)
60121 - fscache_stat(stat_object_dead);
60122 + fscache_stat_unchecked(stat_object_dead);
60123 return -ENOBUFS;
60124 }
60125 return 0;
60126 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60127
60128 _enter("%p,%p,,,", cookie, page);
60129
60130 - fscache_stat(&fscache_n_retrievals);
60131 + fscache_stat_unchecked(&fscache_n_retrievals);
60132
60133 if (hlist_empty(&cookie->backing_objects))
60134 goto nobufs;
60135 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60136 goto nobufs_unlock_dec;
60137 spin_unlock(&cookie->lock);
60138
60139 - fscache_stat(&fscache_n_retrieval_ops);
60140 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60141
60142 /* pin the netfs read context in case we need to do the actual netfs
60143 * read because we've encountered a cache read failure */
60144 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60145
60146 error:
60147 if (ret == -ENOMEM)
60148 - fscache_stat(&fscache_n_retrievals_nomem);
60149 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60150 else if (ret == -ERESTARTSYS)
60151 - fscache_stat(&fscache_n_retrievals_intr);
60152 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60153 else if (ret == -ENODATA)
60154 - fscache_stat(&fscache_n_retrievals_nodata);
60155 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60156 else if (ret < 0)
60157 - fscache_stat(&fscache_n_retrievals_nobufs);
60158 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60159 else
60160 - fscache_stat(&fscache_n_retrievals_ok);
60161 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60162
60163 fscache_put_retrieval(op);
60164 _leave(" = %d", ret);
60165 @@ -490,7 +490,7 @@ nobufs_unlock:
60166 __fscache_wake_unused_cookie(cookie);
60167 kfree(op);
60168 nobufs:
60169 - fscache_stat(&fscache_n_retrievals_nobufs);
60170 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60171 _leave(" = -ENOBUFS");
60172 return -ENOBUFS;
60173 }
60174 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60175
60176 _enter("%p,,%d,,,", cookie, *nr_pages);
60177
60178 - fscache_stat(&fscache_n_retrievals);
60179 + fscache_stat_unchecked(&fscache_n_retrievals);
60180
60181 if (hlist_empty(&cookie->backing_objects))
60182 goto nobufs;
60183 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60184 goto nobufs_unlock_dec;
60185 spin_unlock(&cookie->lock);
60186
60187 - fscache_stat(&fscache_n_retrieval_ops);
60188 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60189
60190 /* pin the netfs read context in case we need to do the actual netfs
60191 * read because we've encountered a cache read failure */
60192 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60193
60194 error:
60195 if (ret == -ENOMEM)
60196 - fscache_stat(&fscache_n_retrievals_nomem);
60197 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60198 else if (ret == -ERESTARTSYS)
60199 - fscache_stat(&fscache_n_retrievals_intr);
60200 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60201 else if (ret == -ENODATA)
60202 - fscache_stat(&fscache_n_retrievals_nodata);
60203 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60204 else if (ret < 0)
60205 - fscache_stat(&fscache_n_retrievals_nobufs);
60206 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60207 else
60208 - fscache_stat(&fscache_n_retrievals_ok);
60209 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60210
60211 fscache_put_retrieval(op);
60212 _leave(" = %d", ret);
60213 @@ -621,7 +621,7 @@ nobufs_unlock:
60214 if (wake_cookie)
60215 __fscache_wake_unused_cookie(cookie);
60216 nobufs:
60217 - fscache_stat(&fscache_n_retrievals_nobufs);
60218 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60219 _leave(" = -ENOBUFS");
60220 return -ENOBUFS;
60221 }
60222 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60223
60224 _enter("%p,%p,,,", cookie, page);
60225
60226 - fscache_stat(&fscache_n_allocs);
60227 + fscache_stat_unchecked(&fscache_n_allocs);
60228
60229 if (hlist_empty(&cookie->backing_objects))
60230 goto nobufs;
60231 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60232 goto nobufs_unlock_dec;
60233 spin_unlock(&cookie->lock);
60234
60235 - fscache_stat(&fscache_n_alloc_ops);
60236 + fscache_stat_unchecked(&fscache_n_alloc_ops);
60237
60238 ret = fscache_wait_for_operation_activation(
60239 object, &op->op,
60240 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60241
60242 error:
60243 if (ret == -ERESTARTSYS)
60244 - fscache_stat(&fscache_n_allocs_intr);
60245 + fscache_stat_unchecked(&fscache_n_allocs_intr);
60246 else if (ret < 0)
60247 - fscache_stat(&fscache_n_allocs_nobufs);
60248 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60249 else
60250 - fscache_stat(&fscache_n_allocs_ok);
60251 + fscache_stat_unchecked(&fscache_n_allocs_ok);
60252
60253 fscache_put_retrieval(op);
60254 _leave(" = %d", ret);
60255 @@ -715,7 +715,7 @@ nobufs_unlock:
60256 if (wake_cookie)
60257 __fscache_wake_unused_cookie(cookie);
60258 nobufs:
60259 - fscache_stat(&fscache_n_allocs_nobufs);
60260 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60261 _leave(" = -ENOBUFS");
60262 return -ENOBUFS;
60263 }
60264 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60265
60266 spin_lock(&cookie->stores_lock);
60267
60268 - fscache_stat(&fscache_n_store_calls);
60269 + fscache_stat_unchecked(&fscache_n_store_calls);
60270
60271 /* find a page to store */
60272 page = NULL;
60273 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60274 page = results[0];
60275 _debug("gang %d [%lx]", n, page->index);
60276 if (page->index > op->store_limit) {
60277 - fscache_stat(&fscache_n_store_pages_over_limit);
60278 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60279 goto superseded;
60280 }
60281
60282 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60283 spin_unlock(&cookie->stores_lock);
60284 spin_unlock(&object->lock);
60285
60286 - fscache_stat(&fscache_n_store_pages);
60287 + fscache_stat_unchecked(&fscache_n_store_pages);
60288 fscache_stat(&fscache_n_cop_write_page);
60289 ret = object->cache->ops->write_page(op, page);
60290 fscache_stat_d(&fscache_n_cop_write_page);
60291 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60292 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60293 ASSERT(PageFsCache(page));
60294
60295 - fscache_stat(&fscache_n_stores);
60296 + fscache_stat_unchecked(&fscache_n_stores);
60297
60298 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60299 _leave(" = -ENOBUFS [invalidating]");
60300 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60301 spin_unlock(&cookie->stores_lock);
60302 spin_unlock(&object->lock);
60303
60304 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60305 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60306 op->store_limit = object->store_limit;
60307
60308 __fscache_use_cookie(cookie);
60309 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60310
60311 spin_unlock(&cookie->lock);
60312 radix_tree_preload_end();
60313 - fscache_stat(&fscache_n_store_ops);
60314 - fscache_stat(&fscache_n_stores_ok);
60315 + fscache_stat_unchecked(&fscache_n_store_ops);
60316 + fscache_stat_unchecked(&fscache_n_stores_ok);
60317
60318 /* the work queue now carries its own ref on the object */
60319 fscache_put_operation(&op->op);
60320 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60321 return 0;
60322
60323 already_queued:
60324 - fscache_stat(&fscache_n_stores_again);
60325 + fscache_stat_unchecked(&fscache_n_stores_again);
60326 already_pending:
60327 spin_unlock(&cookie->stores_lock);
60328 spin_unlock(&object->lock);
60329 spin_unlock(&cookie->lock);
60330 radix_tree_preload_end();
60331 kfree(op);
60332 - fscache_stat(&fscache_n_stores_ok);
60333 + fscache_stat_unchecked(&fscache_n_stores_ok);
60334 _leave(" = 0");
60335 return 0;
60336
60337 @@ -1024,14 +1024,14 @@ nobufs:
60338 kfree(op);
60339 if (wake_cookie)
60340 __fscache_wake_unused_cookie(cookie);
60341 - fscache_stat(&fscache_n_stores_nobufs);
60342 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
60343 _leave(" = -ENOBUFS");
60344 return -ENOBUFS;
60345
60346 nomem_free:
60347 kfree(op);
60348 nomem:
60349 - fscache_stat(&fscache_n_stores_oom);
60350 + fscache_stat_unchecked(&fscache_n_stores_oom);
60351 _leave(" = -ENOMEM");
60352 return -ENOMEM;
60353 }
60354 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60355 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60356 ASSERTCMP(page, !=, NULL);
60357
60358 - fscache_stat(&fscache_n_uncaches);
60359 + fscache_stat_unchecked(&fscache_n_uncaches);
60360
60361 /* cache withdrawal may beat us to it */
60362 if (!PageFsCache(page))
60363 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60364 struct fscache_cookie *cookie = op->op.object->cookie;
60365
60366 #ifdef CONFIG_FSCACHE_STATS
60367 - atomic_inc(&fscache_n_marks);
60368 + atomic_inc_unchecked(&fscache_n_marks);
60369 #endif
60370
60371 _debug("- mark %p{%lx}", page, page->index);
60372 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60373 index 40d13c7..ddf52b9 100644
60374 --- a/fs/fscache/stats.c
60375 +++ b/fs/fscache/stats.c
60376 @@ -18,99 +18,99 @@
60377 /*
60378 * operation counters
60379 */
60380 -atomic_t fscache_n_op_pend;
60381 -atomic_t fscache_n_op_run;
60382 -atomic_t fscache_n_op_enqueue;
60383 -atomic_t fscache_n_op_requeue;
60384 -atomic_t fscache_n_op_deferred_release;
60385 -atomic_t fscache_n_op_release;
60386 -atomic_t fscache_n_op_gc;
60387 -atomic_t fscache_n_op_cancelled;
60388 -atomic_t fscache_n_op_rejected;
60389 +atomic_unchecked_t fscache_n_op_pend;
60390 +atomic_unchecked_t fscache_n_op_run;
60391 +atomic_unchecked_t fscache_n_op_enqueue;
60392 +atomic_unchecked_t fscache_n_op_requeue;
60393 +atomic_unchecked_t fscache_n_op_deferred_release;
60394 +atomic_unchecked_t fscache_n_op_release;
60395 +atomic_unchecked_t fscache_n_op_gc;
60396 +atomic_unchecked_t fscache_n_op_cancelled;
60397 +atomic_unchecked_t fscache_n_op_rejected;
60398
60399 -atomic_t fscache_n_attr_changed;
60400 -atomic_t fscache_n_attr_changed_ok;
60401 -atomic_t fscache_n_attr_changed_nobufs;
60402 -atomic_t fscache_n_attr_changed_nomem;
60403 -atomic_t fscache_n_attr_changed_calls;
60404 +atomic_unchecked_t fscache_n_attr_changed;
60405 +atomic_unchecked_t fscache_n_attr_changed_ok;
60406 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
60407 +atomic_unchecked_t fscache_n_attr_changed_nomem;
60408 +atomic_unchecked_t fscache_n_attr_changed_calls;
60409
60410 -atomic_t fscache_n_allocs;
60411 -atomic_t fscache_n_allocs_ok;
60412 -atomic_t fscache_n_allocs_wait;
60413 -atomic_t fscache_n_allocs_nobufs;
60414 -atomic_t fscache_n_allocs_intr;
60415 -atomic_t fscache_n_allocs_object_dead;
60416 -atomic_t fscache_n_alloc_ops;
60417 -atomic_t fscache_n_alloc_op_waits;
60418 +atomic_unchecked_t fscache_n_allocs;
60419 +atomic_unchecked_t fscache_n_allocs_ok;
60420 +atomic_unchecked_t fscache_n_allocs_wait;
60421 +atomic_unchecked_t fscache_n_allocs_nobufs;
60422 +atomic_unchecked_t fscache_n_allocs_intr;
60423 +atomic_unchecked_t fscache_n_allocs_object_dead;
60424 +atomic_unchecked_t fscache_n_alloc_ops;
60425 +atomic_unchecked_t fscache_n_alloc_op_waits;
60426
60427 -atomic_t fscache_n_retrievals;
60428 -atomic_t fscache_n_retrievals_ok;
60429 -atomic_t fscache_n_retrievals_wait;
60430 -atomic_t fscache_n_retrievals_nodata;
60431 -atomic_t fscache_n_retrievals_nobufs;
60432 -atomic_t fscache_n_retrievals_intr;
60433 -atomic_t fscache_n_retrievals_nomem;
60434 -atomic_t fscache_n_retrievals_object_dead;
60435 -atomic_t fscache_n_retrieval_ops;
60436 -atomic_t fscache_n_retrieval_op_waits;
60437 +atomic_unchecked_t fscache_n_retrievals;
60438 +atomic_unchecked_t fscache_n_retrievals_ok;
60439 +atomic_unchecked_t fscache_n_retrievals_wait;
60440 +atomic_unchecked_t fscache_n_retrievals_nodata;
60441 +atomic_unchecked_t fscache_n_retrievals_nobufs;
60442 +atomic_unchecked_t fscache_n_retrievals_intr;
60443 +atomic_unchecked_t fscache_n_retrievals_nomem;
60444 +atomic_unchecked_t fscache_n_retrievals_object_dead;
60445 +atomic_unchecked_t fscache_n_retrieval_ops;
60446 +atomic_unchecked_t fscache_n_retrieval_op_waits;
60447
60448 -atomic_t fscache_n_stores;
60449 -atomic_t fscache_n_stores_ok;
60450 -atomic_t fscache_n_stores_again;
60451 -atomic_t fscache_n_stores_nobufs;
60452 -atomic_t fscache_n_stores_oom;
60453 -atomic_t fscache_n_store_ops;
60454 -atomic_t fscache_n_store_calls;
60455 -atomic_t fscache_n_store_pages;
60456 -atomic_t fscache_n_store_radix_deletes;
60457 -atomic_t fscache_n_store_pages_over_limit;
60458 +atomic_unchecked_t fscache_n_stores;
60459 +atomic_unchecked_t fscache_n_stores_ok;
60460 +atomic_unchecked_t fscache_n_stores_again;
60461 +atomic_unchecked_t fscache_n_stores_nobufs;
60462 +atomic_unchecked_t fscache_n_stores_oom;
60463 +atomic_unchecked_t fscache_n_store_ops;
60464 +atomic_unchecked_t fscache_n_store_calls;
60465 +atomic_unchecked_t fscache_n_store_pages;
60466 +atomic_unchecked_t fscache_n_store_radix_deletes;
60467 +atomic_unchecked_t fscache_n_store_pages_over_limit;
60468
60469 -atomic_t fscache_n_store_vmscan_not_storing;
60470 -atomic_t fscache_n_store_vmscan_gone;
60471 -atomic_t fscache_n_store_vmscan_busy;
60472 -atomic_t fscache_n_store_vmscan_cancelled;
60473 -atomic_t fscache_n_store_vmscan_wait;
60474 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60475 +atomic_unchecked_t fscache_n_store_vmscan_gone;
60476 +atomic_unchecked_t fscache_n_store_vmscan_busy;
60477 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60478 +atomic_unchecked_t fscache_n_store_vmscan_wait;
60479
60480 -atomic_t fscache_n_marks;
60481 -atomic_t fscache_n_uncaches;
60482 +atomic_unchecked_t fscache_n_marks;
60483 +atomic_unchecked_t fscache_n_uncaches;
60484
60485 -atomic_t fscache_n_acquires;
60486 -atomic_t fscache_n_acquires_null;
60487 -atomic_t fscache_n_acquires_no_cache;
60488 -atomic_t fscache_n_acquires_ok;
60489 -atomic_t fscache_n_acquires_nobufs;
60490 -atomic_t fscache_n_acquires_oom;
60491 +atomic_unchecked_t fscache_n_acquires;
60492 +atomic_unchecked_t fscache_n_acquires_null;
60493 +atomic_unchecked_t fscache_n_acquires_no_cache;
60494 +atomic_unchecked_t fscache_n_acquires_ok;
60495 +atomic_unchecked_t fscache_n_acquires_nobufs;
60496 +atomic_unchecked_t fscache_n_acquires_oom;
60497
60498 -atomic_t fscache_n_invalidates;
60499 -atomic_t fscache_n_invalidates_run;
60500 +atomic_unchecked_t fscache_n_invalidates;
60501 +atomic_unchecked_t fscache_n_invalidates_run;
60502
60503 -atomic_t fscache_n_updates;
60504 -atomic_t fscache_n_updates_null;
60505 -atomic_t fscache_n_updates_run;
60506 +atomic_unchecked_t fscache_n_updates;
60507 +atomic_unchecked_t fscache_n_updates_null;
60508 +atomic_unchecked_t fscache_n_updates_run;
60509
60510 -atomic_t fscache_n_relinquishes;
60511 -atomic_t fscache_n_relinquishes_null;
60512 -atomic_t fscache_n_relinquishes_waitcrt;
60513 -atomic_t fscache_n_relinquishes_retire;
60514 +atomic_unchecked_t fscache_n_relinquishes;
60515 +atomic_unchecked_t fscache_n_relinquishes_null;
60516 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60517 +atomic_unchecked_t fscache_n_relinquishes_retire;
60518
60519 -atomic_t fscache_n_cookie_index;
60520 -atomic_t fscache_n_cookie_data;
60521 -atomic_t fscache_n_cookie_special;
60522 +atomic_unchecked_t fscache_n_cookie_index;
60523 +atomic_unchecked_t fscache_n_cookie_data;
60524 +atomic_unchecked_t fscache_n_cookie_special;
60525
60526 -atomic_t fscache_n_object_alloc;
60527 -atomic_t fscache_n_object_no_alloc;
60528 -atomic_t fscache_n_object_lookups;
60529 -atomic_t fscache_n_object_lookups_negative;
60530 -atomic_t fscache_n_object_lookups_positive;
60531 -atomic_t fscache_n_object_lookups_timed_out;
60532 -atomic_t fscache_n_object_created;
60533 -atomic_t fscache_n_object_avail;
60534 -atomic_t fscache_n_object_dead;
60535 +atomic_unchecked_t fscache_n_object_alloc;
60536 +atomic_unchecked_t fscache_n_object_no_alloc;
60537 +atomic_unchecked_t fscache_n_object_lookups;
60538 +atomic_unchecked_t fscache_n_object_lookups_negative;
60539 +atomic_unchecked_t fscache_n_object_lookups_positive;
60540 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
60541 +atomic_unchecked_t fscache_n_object_created;
60542 +atomic_unchecked_t fscache_n_object_avail;
60543 +atomic_unchecked_t fscache_n_object_dead;
60544
60545 -atomic_t fscache_n_checkaux_none;
60546 -atomic_t fscache_n_checkaux_okay;
60547 -atomic_t fscache_n_checkaux_update;
60548 -atomic_t fscache_n_checkaux_obsolete;
60549 +atomic_unchecked_t fscache_n_checkaux_none;
60550 +atomic_unchecked_t fscache_n_checkaux_okay;
60551 +atomic_unchecked_t fscache_n_checkaux_update;
60552 +atomic_unchecked_t fscache_n_checkaux_obsolete;
60553
60554 atomic_t fscache_n_cop_alloc_object;
60555 atomic_t fscache_n_cop_lookup_object;
60556 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
60557 seq_puts(m, "FS-Cache statistics\n");
60558
60559 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
60560 - atomic_read(&fscache_n_cookie_index),
60561 - atomic_read(&fscache_n_cookie_data),
60562 - atomic_read(&fscache_n_cookie_special));
60563 + atomic_read_unchecked(&fscache_n_cookie_index),
60564 + atomic_read_unchecked(&fscache_n_cookie_data),
60565 + atomic_read_unchecked(&fscache_n_cookie_special));
60566
60567 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
60568 - atomic_read(&fscache_n_object_alloc),
60569 - atomic_read(&fscache_n_object_no_alloc),
60570 - atomic_read(&fscache_n_object_avail),
60571 - atomic_read(&fscache_n_object_dead));
60572 + atomic_read_unchecked(&fscache_n_object_alloc),
60573 + atomic_read_unchecked(&fscache_n_object_no_alloc),
60574 + atomic_read_unchecked(&fscache_n_object_avail),
60575 + atomic_read_unchecked(&fscache_n_object_dead));
60576 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
60577 - atomic_read(&fscache_n_checkaux_none),
60578 - atomic_read(&fscache_n_checkaux_okay),
60579 - atomic_read(&fscache_n_checkaux_update),
60580 - atomic_read(&fscache_n_checkaux_obsolete));
60581 + atomic_read_unchecked(&fscache_n_checkaux_none),
60582 + atomic_read_unchecked(&fscache_n_checkaux_okay),
60583 + atomic_read_unchecked(&fscache_n_checkaux_update),
60584 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
60585
60586 seq_printf(m, "Pages : mrk=%u unc=%u\n",
60587 - atomic_read(&fscache_n_marks),
60588 - atomic_read(&fscache_n_uncaches));
60589 + atomic_read_unchecked(&fscache_n_marks),
60590 + atomic_read_unchecked(&fscache_n_uncaches));
60591
60592 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
60593 " oom=%u\n",
60594 - atomic_read(&fscache_n_acquires),
60595 - atomic_read(&fscache_n_acquires_null),
60596 - atomic_read(&fscache_n_acquires_no_cache),
60597 - atomic_read(&fscache_n_acquires_ok),
60598 - atomic_read(&fscache_n_acquires_nobufs),
60599 - atomic_read(&fscache_n_acquires_oom));
60600 + atomic_read_unchecked(&fscache_n_acquires),
60601 + atomic_read_unchecked(&fscache_n_acquires_null),
60602 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
60603 + atomic_read_unchecked(&fscache_n_acquires_ok),
60604 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
60605 + atomic_read_unchecked(&fscache_n_acquires_oom));
60606
60607 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
60608 - atomic_read(&fscache_n_object_lookups),
60609 - atomic_read(&fscache_n_object_lookups_negative),
60610 - atomic_read(&fscache_n_object_lookups_positive),
60611 - atomic_read(&fscache_n_object_created),
60612 - atomic_read(&fscache_n_object_lookups_timed_out));
60613 + atomic_read_unchecked(&fscache_n_object_lookups),
60614 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
60615 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
60616 + atomic_read_unchecked(&fscache_n_object_created),
60617 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
60618
60619 seq_printf(m, "Invals : n=%u run=%u\n",
60620 - atomic_read(&fscache_n_invalidates),
60621 - atomic_read(&fscache_n_invalidates_run));
60622 + atomic_read_unchecked(&fscache_n_invalidates),
60623 + atomic_read_unchecked(&fscache_n_invalidates_run));
60624
60625 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
60626 - atomic_read(&fscache_n_updates),
60627 - atomic_read(&fscache_n_updates_null),
60628 - atomic_read(&fscache_n_updates_run));
60629 + atomic_read_unchecked(&fscache_n_updates),
60630 + atomic_read_unchecked(&fscache_n_updates_null),
60631 + atomic_read_unchecked(&fscache_n_updates_run));
60632
60633 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
60634 - atomic_read(&fscache_n_relinquishes),
60635 - atomic_read(&fscache_n_relinquishes_null),
60636 - atomic_read(&fscache_n_relinquishes_waitcrt),
60637 - atomic_read(&fscache_n_relinquishes_retire));
60638 + atomic_read_unchecked(&fscache_n_relinquishes),
60639 + atomic_read_unchecked(&fscache_n_relinquishes_null),
60640 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
60641 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
60642
60643 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
60644 - atomic_read(&fscache_n_attr_changed),
60645 - atomic_read(&fscache_n_attr_changed_ok),
60646 - atomic_read(&fscache_n_attr_changed_nobufs),
60647 - atomic_read(&fscache_n_attr_changed_nomem),
60648 - atomic_read(&fscache_n_attr_changed_calls));
60649 + atomic_read_unchecked(&fscache_n_attr_changed),
60650 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
60651 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
60652 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
60653 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
60654
60655 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
60656 - atomic_read(&fscache_n_allocs),
60657 - atomic_read(&fscache_n_allocs_ok),
60658 - atomic_read(&fscache_n_allocs_wait),
60659 - atomic_read(&fscache_n_allocs_nobufs),
60660 - atomic_read(&fscache_n_allocs_intr));
60661 + atomic_read_unchecked(&fscache_n_allocs),
60662 + atomic_read_unchecked(&fscache_n_allocs_ok),
60663 + atomic_read_unchecked(&fscache_n_allocs_wait),
60664 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
60665 + atomic_read_unchecked(&fscache_n_allocs_intr));
60666 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
60667 - atomic_read(&fscache_n_alloc_ops),
60668 - atomic_read(&fscache_n_alloc_op_waits),
60669 - atomic_read(&fscache_n_allocs_object_dead));
60670 + atomic_read_unchecked(&fscache_n_alloc_ops),
60671 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
60672 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
60673
60674 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
60675 " int=%u oom=%u\n",
60676 - atomic_read(&fscache_n_retrievals),
60677 - atomic_read(&fscache_n_retrievals_ok),
60678 - atomic_read(&fscache_n_retrievals_wait),
60679 - atomic_read(&fscache_n_retrievals_nodata),
60680 - atomic_read(&fscache_n_retrievals_nobufs),
60681 - atomic_read(&fscache_n_retrievals_intr),
60682 - atomic_read(&fscache_n_retrievals_nomem));
60683 + atomic_read_unchecked(&fscache_n_retrievals),
60684 + atomic_read_unchecked(&fscache_n_retrievals_ok),
60685 + atomic_read_unchecked(&fscache_n_retrievals_wait),
60686 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
60687 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
60688 + atomic_read_unchecked(&fscache_n_retrievals_intr),
60689 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
60690 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
60691 - atomic_read(&fscache_n_retrieval_ops),
60692 - atomic_read(&fscache_n_retrieval_op_waits),
60693 - atomic_read(&fscache_n_retrievals_object_dead));
60694 + atomic_read_unchecked(&fscache_n_retrieval_ops),
60695 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
60696 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
60697
60698 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
60699 - atomic_read(&fscache_n_stores),
60700 - atomic_read(&fscache_n_stores_ok),
60701 - atomic_read(&fscache_n_stores_again),
60702 - atomic_read(&fscache_n_stores_nobufs),
60703 - atomic_read(&fscache_n_stores_oom));
60704 + atomic_read_unchecked(&fscache_n_stores),
60705 + atomic_read_unchecked(&fscache_n_stores_ok),
60706 + atomic_read_unchecked(&fscache_n_stores_again),
60707 + atomic_read_unchecked(&fscache_n_stores_nobufs),
60708 + atomic_read_unchecked(&fscache_n_stores_oom));
60709 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
60710 - atomic_read(&fscache_n_store_ops),
60711 - atomic_read(&fscache_n_store_calls),
60712 - atomic_read(&fscache_n_store_pages),
60713 - atomic_read(&fscache_n_store_radix_deletes),
60714 - atomic_read(&fscache_n_store_pages_over_limit));
60715 + atomic_read_unchecked(&fscache_n_store_ops),
60716 + atomic_read_unchecked(&fscache_n_store_calls),
60717 + atomic_read_unchecked(&fscache_n_store_pages),
60718 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
60719 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
60720
60721 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
60722 - atomic_read(&fscache_n_store_vmscan_not_storing),
60723 - atomic_read(&fscache_n_store_vmscan_gone),
60724 - atomic_read(&fscache_n_store_vmscan_busy),
60725 - atomic_read(&fscache_n_store_vmscan_cancelled),
60726 - atomic_read(&fscache_n_store_vmscan_wait));
60727 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
60728 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
60729 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
60730 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
60731 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
60732
60733 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
60734 - atomic_read(&fscache_n_op_pend),
60735 - atomic_read(&fscache_n_op_run),
60736 - atomic_read(&fscache_n_op_enqueue),
60737 - atomic_read(&fscache_n_op_cancelled),
60738 - atomic_read(&fscache_n_op_rejected));
60739 + atomic_read_unchecked(&fscache_n_op_pend),
60740 + atomic_read_unchecked(&fscache_n_op_run),
60741 + atomic_read_unchecked(&fscache_n_op_enqueue),
60742 + atomic_read_unchecked(&fscache_n_op_cancelled),
60743 + atomic_read_unchecked(&fscache_n_op_rejected));
60744 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
60745 - atomic_read(&fscache_n_op_deferred_release),
60746 - atomic_read(&fscache_n_op_release),
60747 - atomic_read(&fscache_n_op_gc));
60748 + atomic_read_unchecked(&fscache_n_op_deferred_release),
60749 + atomic_read_unchecked(&fscache_n_op_release),
60750 + atomic_read_unchecked(&fscache_n_op_gc));
60751
60752 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
60753 atomic_read(&fscache_n_cop_alloc_object),
60754 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
60755 index b96a49b..9bfdc47 100644
60756 --- a/fs/fuse/cuse.c
60757 +++ b/fs/fuse/cuse.c
60758 @@ -606,10 +606,12 @@ static int __init cuse_init(void)
60759 INIT_LIST_HEAD(&cuse_conntbl[i]);
60760
60761 /* inherit and extend fuse_dev_operations */
60762 - cuse_channel_fops = fuse_dev_operations;
60763 - cuse_channel_fops.owner = THIS_MODULE;
60764 - cuse_channel_fops.open = cuse_channel_open;
60765 - cuse_channel_fops.release = cuse_channel_release;
60766 + pax_open_kernel();
60767 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
60768 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
60769 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
60770 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
60771 + pax_close_kernel();
60772
60773 cuse_class = class_create(THIS_MODULE, "cuse");
60774 if (IS_ERR(cuse_class))
60775 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
60776 index 0a648bb..8d463f1 100644
60777 --- a/fs/fuse/dev.c
60778 +++ b/fs/fuse/dev.c
60779 @@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60780 ret = 0;
60781 pipe_lock(pipe);
60782
60783 - if (!pipe->readers) {
60784 + if (!atomic_read(&pipe->readers)) {
60785 send_sig(SIGPIPE, current, 0);
60786 if (!ret)
60787 ret = -EPIPE;
60788 @@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60789 page_nr++;
60790 ret += buf->len;
60791
60792 - if (pipe->files)
60793 + if (atomic_read(&pipe->files))
60794 do_wakeup = 1;
60795 }
60796
60797 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
60798 index 1d1292c..bba17ea 100644
60799 --- a/fs/fuse/dir.c
60800 +++ b/fs/fuse/dir.c
60801 @@ -1418,7 +1418,7 @@ static char *read_link(struct dentry *dentry)
60802 return link;
60803 }
60804
60805 -static void free_link(char *link)
60806 +static void free_link(const char *link)
60807 {
60808 if (!IS_ERR(link))
60809 free_page((unsigned long) link);
60810 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
60811 index fe649d3..c679164 100644
60812 --- a/fs/hostfs/hostfs_kern.c
60813 +++ b/fs/hostfs/hostfs_kern.c
60814 @@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60815
60816 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60817 {
60818 - char *s = nd_get_link(nd);
60819 + const char *s = nd_get_link(nd);
60820 if (!IS_ERR(s))
60821 __putname(s);
60822 }
60823 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
60824 index d19b30a..ef89c36 100644
60825 --- a/fs/hugetlbfs/inode.c
60826 +++ b/fs/hugetlbfs/inode.c
60827 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60828 struct mm_struct *mm = current->mm;
60829 struct vm_area_struct *vma;
60830 struct hstate *h = hstate_file(file);
60831 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
60832 struct vm_unmapped_area_info info;
60833
60834 if (len & ~huge_page_mask(h))
60835 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60836 return addr;
60837 }
60838
60839 +#ifdef CONFIG_PAX_RANDMMAP
60840 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
60841 +#endif
60842 +
60843 if (addr) {
60844 addr = ALIGN(addr, huge_page_size(h));
60845 vma = find_vma(mm, addr);
60846 - if (TASK_SIZE - len >= addr &&
60847 - (!vma || addr + len <= vma->vm_start))
60848 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
60849 return addr;
60850 }
60851
60852 info.flags = 0;
60853 info.length = len;
60854 info.low_limit = TASK_UNMAPPED_BASE;
60855 +
60856 +#ifdef CONFIG_PAX_RANDMMAP
60857 + if (mm->pax_flags & MF_PAX_RANDMMAP)
60858 + info.low_limit += mm->delta_mmap;
60859 +#endif
60860 +
60861 info.high_limit = TASK_SIZE;
60862 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
60863 info.align_offset = 0;
60864 @@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
60865 };
60866 MODULE_ALIAS_FS("hugetlbfs");
60867
60868 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60869 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60870
60871 static int can_do_hugetlb_shm(void)
60872 {
60873 diff --git a/fs/inode.c b/fs/inode.c
60874 index 4bcdad3..1883822 100644
60875 --- a/fs/inode.c
60876 +++ b/fs/inode.c
60877 @@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
60878
60879 #ifdef CONFIG_SMP
60880 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
60881 - static atomic_t shared_last_ino;
60882 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
60883 + static atomic_unchecked_t shared_last_ino;
60884 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
60885
60886 res = next - LAST_INO_BATCH;
60887 }
60888 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
60889 index 4a6cf28..d3a29d3 100644
60890 --- a/fs/jffs2/erase.c
60891 +++ b/fs/jffs2/erase.c
60892 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
60893 struct jffs2_unknown_node marker = {
60894 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
60895 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60896 - .totlen = cpu_to_je32(c->cleanmarker_size)
60897 + .totlen = cpu_to_je32(c->cleanmarker_size),
60898 + .hdr_crc = cpu_to_je32(0)
60899 };
60900
60901 jffs2_prealloc_raw_node_refs(c, jeb, 1);
60902 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
60903 index a6597d6..41b30ec 100644
60904 --- a/fs/jffs2/wbuf.c
60905 +++ b/fs/jffs2/wbuf.c
60906 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
60907 {
60908 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
60909 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60910 - .totlen = constant_cpu_to_je32(8)
60911 + .totlen = constant_cpu_to_je32(8),
60912 + .hdr_crc = constant_cpu_to_je32(0)
60913 };
60914
60915 /*
60916 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
60917 index e2b7483..855bca3 100644
60918 --- a/fs/jfs/super.c
60919 +++ b/fs/jfs/super.c
60920 @@ -884,7 +884,7 @@ static int __init init_jfs_fs(void)
60921
60922 jfs_inode_cachep =
60923 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
60924 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
60925 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
60926 init_once);
60927 if (jfs_inode_cachep == NULL)
60928 return -ENOMEM;
60929 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
60930 index bd6e18b..812d4ff 100644
60931 --- a/fs/kernfs/dir.c
60932 +++ b/fs/kernfs/dir.c
60933 @@ -28,7 +28,7 @@ DEFINE_MUTEX(kernfs_mutex);
60934 *
60935 * Returns 31 bit hash of ns + name (so it fits in an off_t )
60936 */
60937 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
60938 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
60939 {
60940 unsigned long hash = init_name_hash();
60941 unsigned int len = strlen(name);
60942 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
60943 index dbf397b..d624b48 100644
60944 --- a/fs/kernfs/file.c
60945 +++ b/fs/kernfs/file.c
60946 @@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
60947
60948 struct kernfs_open_node {
60949 atomic_t refcnt;
60950 - atomic_t event;
60951 + atomic_unchecked_t event;
60952 wait_queue_head_t poll;
60953 struct list_head files; /* goes through kernfs_open_file.list */
60954 };
60955 @@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
60956 {
60957 struct kernfs_open_file *of = sf->private;
60958
60959 - of->event = atomic_read(&of->kn->attr.open->event);
60960 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
60961
60962 return of->kn->attr.ops->seq_show(sf, v);
60963 }
60964 @@ -353,12 +353,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
60965 return ret;
60966 }
60967
60968 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
60969 - void *buf, int len, int write)
60970 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
60971 + void *buf, size_t len, int write)
60972 {
60973 struct file *file = vma->vm_file;
60974 struct kernfs_open_file *of = kernfs_of(file);
60975 - int ret;
60976 + ssize_t ret;
60977
60978 if (!of->vm_ops)
60979 return -EINVAL;
60980 @@ -557,7 +557,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
60981 return -ENOMEM;
60982
60983 atomic_set(&new_on->refcnt, 0);
60984 - atomic_set(&new_on->event, 1);
60985 + atomic_set_unchecked(&new_on->event, 1);
60986 init_waitqueue_head(&new_on->poll);
60987 INIT_LIST_HEAD(&new_on->files);
60988 goto retry;
60989 @@ -754,7 +754,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
60990
60991 kernfs_put_active(kn);
60992
60993 - if (of->event != atomic_read(&on->event))
60994 + if (of->event != atomic_read_unchecked(&on->event))
60995 goto trigger;
60996
60997 return DEFAULT_POLLMASK;
60998 @@ -779,7 +779,7 @@ void kernfs_notify(struct kernfs_node *kn)
60999 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61000 on = kn->attr.open;
61001 if (on) {
61002 - atomic_inc(&on->event);
61003 + atomic_inc_unchecked(&on->event);
61004 wake_up_interruptible(&on->poll);
61005 }
61006 }
61007 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61008 index 4d45705..b35e0bd 100644
61009 --- a/fs/kernfs/symlink.c
61010 +++ b/fs/kernfs/symlink.c
61011 @@ -132,7 +132,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61012 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61013 void *cookie)
61014 {
61015 - char *page = nd_get_link(nd);
61016 + const char *page = nd_get_link(nd);
61017 if (!IS_ERR(page))
61018 free_page((unsigned long)page);
61019 }
61020 diff --git a/fs/libfs.c b/fs/libfs.c
61021 index a184424..944ddce 100644
61022 --- a/fs/libfs.c
61023 +++ b/fs/libfs.c
61024 @@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61025
61026 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61027 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61028 + char d_name[sizeof(next->d_iname)];
61029 + const unsigned char *name;
61030 +
61031 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61032 if (!simple_positive(next)) {
61033 spin_unlock(&next->d_lock);
61034 @@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61035
61036 spin_unlock(&next->d_lock);
61037 spin_unlock(&dentry->d_lock);
61038 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61039 + name = next->d_name.name;
61040 + if (name == next->d_iname) {
61041 + memcpy(d_name, name, next->d_name.len);
61042 + name = d_name;
61043 + }
61044 + if (!dir_emit(ctx, name, next->d_name.len,
61045 next->d_inode->i_ino, dt_type(next->d_inode)))
61046 return 0;
61047 spin_lock(&dentry->d_lock);
61048 @@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61049 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61050 void *cookie)
61051 {
61052 - char *s = nd_get_link(nd);
61053 + const char *s = nd_get_link(nd);
61054 if (!IS_ERR(s))
61055 kfree(s);
61056 }
61057 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61058 index acd3947..1f896e2 100644
61059 --- a/fs/lockd/clntproc.c
61060 +++ b/fs/lockd/clntproc.c
61061 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61062 /*
61063 * Cookie counter for NLM requests
61064 */
61065 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61066 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61067
61068 void nlmclnt_next_cookie(struct nlm_cookie *c)
61069 {
61070 - u32 cookie = atomic_inc_return(&nlm_cookie);
61071 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61072
61073 memcpy(c->data, &cookie, 4);
61074 c->len=4;
61075 diff --git a/fs/locks.c b/fs/locks.c
61076 index 92a0f0a..45a48f0 100644
61077 --- a/fs/locks.c
61078 +++ b/fs/locks.c
61079 @@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
61080 return;
61081
61082 if (filp->f_op->flock) {
61083 - struct file_lock fl = {
61084 + struct file_lock flock = {
61085 .fl_pid = current->tgid,
61086 .fl_file = filp,
61087 .fl_flags = FL_FLOCK,
61088 .fl_type = F_UNLCK,
61089 .fl_end = OFFSET_MAX,
61090 };
61091 - filp->f_op->flock(filp, F_SETLKW, &fl);
61092 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
61093 - fl.fl_ops->fl_release_private(&fl);
61094 + filp->f_op->flock(filp, F_SETLKW, &flock);
61095 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
61096 + flock.fl_ops->fl_release_private(&flock);
61097 }
61098
61099 spin_lock(&inode->i_lock);
61100 diff --git a/fs/mount.h b/fs/mount.h
61101 index b29e42f..5ea7fdf 100644
61102 --- a/fs/mount.h
61103 +++ b/fs/mount.h
61104 @@ -11,7 +11,7 @@ struct mnt_namespace {
61105 u64 seq; /* Sequence number to prevent loops */
61106 wait_queue_head_t poll;
61107 int event;
61108 -};
61109 +} __randomize_layout;
61110
61111 struct mnt_pcp {
61112 int mnt_count;
61113 @@ -57,7 +57,7 @@ struct mount {
61114 int mnt_expiry_mark; /* true if marked for expiry */
61115 int mnt_pinned;
61116 struct path mnt_ex_mountpoint;
61117 -};
61118 +} __randomize_layout;
61119
61120 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61121
61122 diff --git a/fs/namei.c b/fs/namei.c
61123 index 4b491b4..a0166f9 100644
61124 --- a/fs/namei.c
61125 +++ b/fs/namei.c
61126 @@ -330,16 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61127 if (ret != -EACCES)
61128 return ret;
61129
61130 +#ifdef CONFIG_GRKERNSEC
61131 + /* we'll block if we have to log due to a denied capability use */
61132 + if (mask & MAY_NOT_BLOCK)
61133 + return -ECHILD;
61134 +#endif
61135 +
61136 if (S_ISDIR(inode->i_mode)) {
61137 /* DACs are overridable for directories */
61138 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
61139 - return 0;
61140 if (!(mask & MAY_WRITE))
61141 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61142 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61143 + inode_capable(inode, CAP_DAC_READ_SEARCH))
61144 return 0;
61145 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
61146 + return 0;
61147 return -EACCES;
61148 }
61149 /*
61150 + * Searching includes executable on directories, else just read.
61151 + */
61152 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61153 + if (mask == MAY_READ)
61154 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61155 + inode_capable(inode, CAP_DAC_READ_SEARCH))
61156 + return 0;
61157 +
61158 + /*
61159 * Read/write DACs are always overridable.
61160 * Executable DACs are overridable when there is
61161 * at least one exec bit set.
61162 @@ -348,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61163 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61164 return 0;
61165
61166 - /*
61167 - * Searching includes executable on directories, else just read.
61168 - */
61169 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61170 - if (mask == MAY_READ)
61171 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61172 - return 0;
61173 -
61174 return -EACCES;
61175 }
61176
61177 @@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61178 {
61179 struct dentry *dentry = link->dentry;
61180 int error;
61181 - char *s;
61182 + const char *s;
61183
61184 BUG_ON(nd->flags & LOOKUP_RCU);
61185
61186 @@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61187 if (error)
61188 goto out_put_nd_path;
61189
61190 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
61191 + dentry->d_inode, dentry, nd->path.mnt)) {
61192 + error = -EACCES;
61193 + goto out_put_nd_path;
61194 + }
61195 +
61196 nd->last_type = LAST_BIND;
61197 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61198 error = PTR_ERR(*p);
61199 @@ -1590,6 +1604,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61200 if (res)
61201 break;
61202 res = walk_component(nd, path, LOOKUP_FOLLOW);
61203 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61204 + res = -EACCES;
61205 put_link(nd, &link, cookie);
61206 } while (res > 0);
61207
61208 @@ -1663,7 +1679,7 @@ EXPORT_SYMBOL(full_name_hash);
61209 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61210 {
61211 unsigned long a, b, adata, bdata, mask, hash, len;
61212 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61213 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61214
61215 hash = a = 0;
61216 len = -sizeof(unsigned long);
61217 @@ -1947,6 +1963,8 @@ static int path_lookupat(int dfd, const char *name,
61218 if (err)
61219 break;
61220 err = lookup_last(nd, &path);
61221 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
61222 + err = -EACCES;
61223 put_link(nd, &link, cookie);
61224 }
61225 }
61226 @@ -1954,6 +1972,13 @@ static int path_lookupat(int dfd, const char *name,
61227 if (!err)
61228 err = complete_walk(nd);
61229
61230 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
61231 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61232 + path_put(&nd->path);
61233 + err = -ENOENT;
61234 + }
61235 + }
61236 +
61237 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61238 if (!d_is_directory(nd->path.dentry)) {
61239 path_put(&nd->path);
61240 @@ -1981,8 +2006,15 @@ static int filename_lookup(int dfd, struct filename *name,
61241 retval = path_lookupat(dfd, name->name,
61242 flags | LOOKUP_REVAL, nd);
61243
61244 - if (likely(!retval))
61245 + if (likely(!retval)) {
61246 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61247 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61248 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61249 + path_put(&nd->path);
61250 + return -ENOENT;
61251 + }
61252 + }
61253 + }
61254 return retval;
61255 }
61256
61257 @@ -2556,6 +2588,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61258 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61259 return -EPERM;
61260
61261 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61262 + return -EPERM;
61263 + if (gr_handle_rawio(inode))
61264 + return -EPERM;
61265 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61266 + return -EACCES;
61267 +
61268 return 0;
61269 }
61270
61271 @@ -2787,7 +2826,7 @@ looked_up:
61272 * cleared otherwise prior to returning.
61273 */
61274 static int lookup_open(struct nameidata *nd, struct path *path,
61275 - struct file *file,
61276 + struct path *link, struct file *file,
61277 const struct open_flags *op,
61278 bool got_write, int *opened)
61279 {
61280 @@ -2822,6 +2861,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61281 /* Negative dentry, just create the file */
61282 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61283 umode_t mode = op->mode;
61284 +
61285 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61286 + error = -EACCES;
61287 + goto out_dput;
61288 + }
61289 +
61290 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61291 + error = -EACCES;
61292 + goto out_dput;
61293 + }
61294 +
61295 if (!IS_POSIXACL(dir->d_inode))
61296 mode &= ~current_umask();
61297 /*
61298 @@ -2843,6 +2893,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61299 nd->flags & LOOKUP_EXCL);
61300 if (error)
61301 goto out_dput;
61302 + else
61303 + gr_handle_create(dentry, nd->path.mnt);
61304 }
61305 out_no_open:
61306 path->dentry = dentry;
61307 @@ -2857,7 +2909,7 @@ out_dput:
61308 /*
61309 * Handle the last step of open()
61310 */
61311 -static int do_last(struct nameidata *nd, struct path *path,
61312 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61313 struct file *file, const struct open_flags *op,
61314 int *opened, struct filename *name)
61315 {
61316 @@ -2907,6 +2959,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61317 if (error)
61318 return error;
61319
61320 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61321 + error = -ENOENT;
61322 + goto out;
61323 + }
61324 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
61325 + error = -EACCES;
61326 + goto out;
61327 + }
61328 +
61329 audit_inode(name, dir, LOOKUP_PARENT);
61330 error = -EISDIR;
61331 /* trailing slashes? */
61332 @@ -2926,7 +2987,7 @@ retry_lookup:
61333 */
61334 }
61335 mutex_lock(&dir->d_inode->i_mutex);
61336 - error = lookup_open(nd, path, file, op, got_write, opened);
61337 + error = lookup_open(nd, path, link, file, op, got_write, opened);
61338 mutex_unlock(&dir->d_inode->i_mutex);
61339
61340 if (error <= 0) {
61341 @@ -2950,11 +3011,28 @@ retry_lookup:
61342 goto finish_open_created;
61343 }
61344
61345 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61346 + error = -ENOENT;
61347 + goto exit_dput;
61348 + }
61349 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61350 + error = -EACCES;
61351 + goto exit_dput;
61352 + }
61353 +
61354 /*
61355 * create/update audit record if it already exists.
61356 */
61357 - if (d_is_positive(path->dentry))
61358 + if (d_is_positive(path->dentry)) {
61359 + /* only check if O_CREAT is specified, all other checks need to go
61360 + into may_open */
61361 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61362 + error = -EACCES;
61363 + goto exit_dput;
61364 + }
61365 +
61366 audit_inode(name, path->dentry, 0);
61367 + }
61368
61369 /*
61370 * If atomic_open() acquired write access it is dropped now due to
61371 @@ -2995,6 +3073,11 @@ finish_lookup:
61372 }
61373 }
61374 BUG_ON(inode != path->dentry->d_inode);
61375 + /* if we're resolving a symlink to another symlink */
61376 + if (link && gr_handle_symlink_owner(link, inode)) {
61377 + error = -EACCES;
61378 + goto out;
61379 + }
61380 return 1;
61381 }
61382
61383 @@ -3004,7 +3087,6 @@ finish_lookup:
61384 save_parent.dentry = nd->path.dentry;
61385 save_parent.mnt = mntget(path->mnt);
61386 nd->path.dentry = path->dentry;
61387 -
61388 }
61389 nd->inode = inode;
61390 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61391 @@ -3014,7 +3096,18 @@ finish_open:
61392 path_put(&save_parent);
61393 return error;
61394 }
61395 +
61396 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61397 + error = -ENOENT;
61398 + goto out;
61399 + }
61400 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
61401 + error = -EACCES;
61402 + goto out;
61403 + }
61404 +
61405 audit_inode(name, nd->path.dentry, 0);
61406 +
61407 error = -EISDIR;
61408 if ((open_flag & O_CREAT) &&
61409 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
61410 @@ -3178,7 +3271,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61411 if (unlikely(error))
61412 goto out;
61413
61414 - error = do_last(nd, &path, file, op, &opened, pathname);
61415 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61416 while (unlikely(error > 0)) { /* trailing symlink */
61417 struct path link = path;
61418 void *cookie;
61419 @@ -3196,7 +3289,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61420 error = follow_link(&link, nd, &cookie);
61421 if (unlikely(error))
61422 break;
61423 - error = do_last(nd, &path, file, op, &opened, pathname);
61424 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
61425 put_link(nd, &link, cookie);
61426 }
61427 out:
61428 @@ -3296,9 +3389,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61429 goto unlock;
61430
61431 error = -EEXIST;
61432 - if (d_is_positive(dentry))
61433 + if (d_is_positive(dentry)) {
61434 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61435 + error = -ENOENT;
61436 goto fail;
61437 -
61438 + }
61439 /*
61440 * Special case - lookup gave negative, but... we had foo/bar/
61441 * From the vfs_mknod() POV we just have a negative dentry -
61442 @@ -3350,6 +3445,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61443 }
61444 EXPORT_SYMBOL(user_path_create);
61445
61446 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61447 +{
61448 + struct filename *tmp = getname(pathname);
61449 + struct dentry *res;
61450 + if (IS_ERR(tmp))
61451 + return ERR_CAST(tmp);
61452 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61453 + if (IS_ERR(res))
61454 + putname(tmp);
61455 + else
61456 + *to = tmp;
61457 + return res;
61458 +}
61459 +
61460 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61461 {
61462 int error = may_create(dir, dentry);
61463 @@ -3412,6 +3521,17 @@ retry:
61464
61465 if (!IS_POSIXACL(path.dentry->d_inode))
61466 mode &= ~current_umask();
61467 +
61468 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61469 + error = -EPERM;
61470 + goto out;
61471 + }
61472 +
61473 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61474 + error = -EACCES;
61475 + goto out;
61476 + }
61477 +
61478 error = security_path_mknod(&path, dentry, mode, dev);
61479 if (error)
61480 goto out;
61481 @@ -3428,6 +3548,8 @@ retry:
61482 break;
61483 }
61484 out:
61485 + if (!error)
61486 + gr_handle_create(dentry, path.mnt);
61487 done_path_create(&path, dentry);
61488 if (retry_estale(error, lookup_flags)) {
61489 lookup_flags |= LOOKUP_REVAL;
61490 @@ -3480,9 +3602,16 @@ retry:
61491
61492 if (!IS_POSIXACL(path.dentry->d_inode))
61493 mode &= ~current_umask();
61494 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
61495 + error = -EACCES;
61496 + goto out;
61497 + }
61498 error = security_path_mkdir(&path, dentry, mode);
61499 if (!error)
61500 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
61501 + if (!error)
61502 + gr_handle_create(dentry, path.mnt);
61503 +out:
61504 done_path_create(&path, dentry);
61505 if (retry_estale(error, lookup_flags)) {
61506 lookup_flags |= LOOKUP_REVAL;
61507 @@ -3563,6 +3692,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
61508 struct filename *name;
61509 struct dentry *dentry;
61510 struct nameidata nd;
61511 + ino_t saved_ino = 0;
61512 + dev_t saved_dev = 0;
61513 unsigned int lookup_flags = 0;
61514 retry:
61515 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61516 @@ -3595,10 +3726,21 @@ retry:
61517 error = -ENOENT;
61518 goto exit3;
61519 }
61520 +
61521 + saved_ino = dentry->d_inode->i_ino;
61522 + saved_dev = gr_get_dev_from_dentry(dentry);
61523 +
61524 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
61525 + error = -EACCES;
61526 + goto exit3;
61527 + }
61528 +
61529 error = security_path_rmdir(&nd.path, dentry);
61530 if (error)
61531 goto exit3;
61532 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
61533 + if (!error && (saved_dev || saved_ino))
61534 + gr_handle_delete(saved_ino, saved_dev);
61535 exit3:
61536 dput(dentry);
61537 exit2:
61538 @@ -3688,6 +3830,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
61539 struct nameidata nd;
61540 struct inode *inode = NULL;
61541 struct inode *delegated_inode = NULL;
61542 + ino_t saved_ino = 0;
61543 + dev_t saved_dev = 0;
61544 unsigned int lookup_flags = 0;
61545 retry:
61546 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61547 @@ -3714,10 +3858,22 @@ retry_deleg:
61548 if (d_is_negative(dentry))
61549 goto slashes;
61550 ihold(inode);
61551 +
61552 + if (inode->i_nlink <= 1) {
61553 + saved_ino = inode->i_ino;
61554 + saved_dev = gr_get_dev_from_dentry(dentry);
61555 + }
61556 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
61557 + error = -EACCES;
61558 + goto exit2;
61559 + }
61560 +
61561 error = security_path_unlink(&nd.path, dentry);
61562 if (error)
61563 goto exit2;
61564 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
61565 + if (!error && (saved_ino || saved_dev))
61566 + gr_handle_delete(saved_ino, saved_dev);
61567 exit2:
61568 dput(dentry);
61569 }
61570 @@ -3805,9 +3961,17 @@ retry:
61571 if (IS_ERR(dentry))
61572 goto out_putname;
61573
61574 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
61575 + error = -EACCES;
61576 + goto out;
61577 + }
61578 +
61579 error = security_path_symlink(&path, dentry, from->name);
61580 if (!error)
61581 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
61582 + if (!error)
61583 + gr_handle_create(dentry, path.mnt);
61584 +out:
61585 done_path_create(&path, dentry);
61586 if (retry_estale(error, lookup_flags)) {
61587 lookup_flags |= LOOKUP_REVAL;
61588 @@ -3910,6 +4074,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
61589 struct dentry *new_dentry;
61590 struct path old_path, new_path;
61591 struct inode *delegated_inode = NULL;
61592 + struct filename *to = NULL;
61593 int how = 0;
61594 int error;
61595
61596 @@ -3933,7 +4098,7 @@ retry:
61597 if (error)
61598 return error;
61599
61600 - new_dentry = user_path_create(newdfd, newname, &new_path,
61601 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
61602 (how & LOOKUP_REVAL));
61603 error = PTR_ERR(new_dentry);
61604 if (IS_ERR(new_dentry))
61605 @@ -3945,11 +4110,28 @@ retry:
61606 error = may_linkat(&old_path);
61607 if (unlikely(error))
61608 goto out_dput;
61609 +
61610 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
61611 + old_path.dentry->d_inode,
61612 + old_path.dentry->d_inode->i_mode, to)) {
61613 + error = -EACCES;
61614 + goto out_dput;
61615 + }
61616 +
61617 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
61618 + old_path.dentry, old_path.mnt, to)) {
61619 + error = -EACCES;
61620 + goto out_dput;
61621 + }
61622 +
61623 error = security_path_link(old_path.dentry, &new_path, new_dentry);
61624 if (error)
61625 goto out_dput;
61626 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
61627 + if (!error)
61628 + gr_handle_create(new_dentry, new_path.mnt);
61629 out_dput:
61630 + putname(to);
61631 done_path_create(&new_path, new_dentry);
61632 if (delegated_inode) {
61633 error = break_deleg_wait(&delegated_inode);
61634 @@ -4236,6 +4418,12 @@ retry_deleg:
61635 if (new_dentry == trap)
61636 goto exit5;
61637
61638 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
61639 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
61640 + to);
61641 + if (error)
61642 + goto exit5;
61643 +
61644 error = security_path_rename(&oldnd.path, old_dentry,
61645 &newnd.path, new_dentry);
61646 if (error)
61647 @@ -4243,6 +4431,9 @@ retry_deleg:
61648 error = vfs_rename(old_dir->d_inode, old_dentry,
61649 new_dir->d_inode, new_dentry,
61650 &delegated_inode);
61651 + if (!error)
61652 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
61653 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
61654 exit5:
61655 dput(new_dentry);
61656 exit4:
61657 @@ -4279,6 +4470,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
61658
61659 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
61660 {
61661 + char tmpbuf[64];
61662 + const char *newlink;
61663 int len;
61664
61665 len = PTR_ERR(link);
61666 @@ -4288,7 +4481,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
61667 len = strlen(link);
61668 if (len > (unsigned) buflen)
61669 len = buflen;
61670 - if (copy_to_user(buffer, link, len))
61671 +
61672 + if (len < sizeof(tmpbuf)) {
61673 + memcpy(tmpbuf, link, len);
61674 + newlink = tmpbuf;
61675 + } else
61676 + newlink = link;
61677 +
61678 + if (copy_to_user(buffer, newlink, len))
61679 len = -EFAULT;
61680 out:
61681 return len;
61682 diff --git a/fs/namespace.c b/fs/namespace.c
61683 index 2ffc5a2..6737083 100644
61684 --- a/fs/namespace.c
61685 +++ b/fs/namespace.c
61686 @@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
61687 if (!(sb->s_flags & MS_RDONLY))
61688 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
61689 up_write(&sb->s_umount);
61690 +
61691 + gr_log_remount(mnt->mnt_devname, retval);
61692 +
61693 return retval;
61694 }
61695
61696 @@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
61697 }
61698 unlock_mount_hash();
61699 namespace_unlock();
61700 +
61701 + gr_log_unmount(mnt->mnt_devname, retval);
61702 +
61703 return retval;
61704 }
61705
61706 @@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
61707 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
61708 */
61709
61710 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
61711 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
61712 {
61713 struct path path;
61714 struct mount *mnt;
61715 @@ -1422,7 +1428,7 @@ out:
61716 /*
61717 * The 2.0 compatible umount. No flags.
61718 */
61719 -SYSCALL_DEFINE1(oldumount, char __user *, name)
61720 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
61721 {
61722 return sys_umount(name, 0);
61723 }
61724 @@ -2426,6 +2432,16 @@ long do_mount(const char *dev_name, const char *dir_name,
61725 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
61726 MS_STRICTATIME);
61727
61728 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
61729 + retval = -EPERM;
61730 + goto dput_out;
61731 + }
61732 +
61733 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
61734 + retval = -EPERM;
61735 + goto dput_out;
61736 + }
61737 +
61738 if (flags & MS_REMOUNT)
61739 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
61740 data_page);
61741 @@ -2440,6 +2456,9 @@ long do_mount(const char *dev_name, const char *dir_name,
61742 dev_name, data_page);
61743 dput_out:
61744 path_put(&path);
61745 +
61746 + gr_log_mount(dev_name, dir_name, retval);
61747 +
61748 return retval;
61749 }
61750
61751 @@ -2457,7 +2476,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
61752 * number incrementing at 10Ghz will take 12,427 years to wrap which
61753 * is effectively never, so we can ignore the possibility.
61754 */
61755 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
61756 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
61757
61758 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61759 {
61760 @@ -2472,7 +2491,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61761 kfree(new_ns);
61762 return ERR_PTR(ret);
61763 }
61764 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
61765 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
61766 atomic_set(&new_ns->count, 1);
61767 new_ns->root = NULL;
61768 INIT_LIST_HEAD(&new_ns->list);
61769 @@ -2482,7 +2501,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61770 return new_ns;
61771 }
61772
61773 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61774 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61775 struct user_namespace *user_ns, struct fs_struct *new_fs)
61776 {
61777 struct mnt_namespace *new_ns;
61778 @@ -2603,8 +2622,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
61779 }
61780 EXPORT_SYMBOL(mount_subtree);
61781
61782 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
61783 - char __user *, type, unsigned long, flags, void __user *, data)
61784 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
61785 + const char __user *, type, unsigned long, flags, void __user *, data)
61786 {
61787 int ret;
61788 char *kernel_type;
61789 @@ -2717,6 +2736,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
61790 if (error)
61791 goto out2;
61792
61793 + if (gr_handle_chroot_pivot()) {
61794 + error = -EPERM;
61795 + goto out2;
61796 + }
61797 +
61798 get_fs_root(current->fs, &root);
61799 old_mp = lock_mount(&old);
61800 error = PTR_ERR(old_mp);
61801 @@ -2985,7 +3009,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
61802 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
61803 return -EPERM;
61804
61805 - if (fs->users != 1)
61806 + if (atomic_read(&fs->users) != 1)
61807 return -EINVAL;
61808
61809 get_mnt_ns(mnt_ns);
61810 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
61811 index f4ccfe6..a5cf064 100644
61812 --- a/fs/nfs/callback_xdr.c
61813 +++ b/fs/nfs/callback_xdr.c
61814 @@ -51,7 +51,7 @@ struct callback_op {
61815 callback_decode_arg_t decode_args;
61816 callback_encode_res_t encode_res;
61817 long res_maxsize;
61818 -};
61819 +} __do_const;
61820
61821 static struct callback_op callback_ops[];
61822
61823 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
61824 index 360114a..ac6e265 100644
61825 --- a/fs/nfs/inode.c
61826 +++ b/fs/nfs/inode.c
61827 @@ -1189,16 +1189,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
61828 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
61829 }
61830
61831 -static atomic_long_t nfs_attr_generation_counter;
61832 +static atomic_long_unchecked_t nfs_attr_generation_counter;
61833
61834 static unsigned long nfs_read_attr_generation_counter(void)
61835 {
61836 - return atomic_long_read(&nfs_attr_generation_counter);
61837 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
61838 }
61839
61840 unsigned long nfs_inc_attr_generation_counter(void)
61841 {
61842 - return atomic_long_inc_return(&nfs_attr_generation_counter);
61843 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
61844 }
61845
61846 void nfs_fattr_init(struct nfs_fattr *fattr)
61847 diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
61848 index 450bfed..d5d06e8 100644
61849 --- a/fs/nfs/nfs4proc.c
61850 +++ b/fs/nfs/nfs4proc.c
61851 @@ -1068,6 +1068,7 @@ static void nfs4_opendata_free(struct kref *kref)
61852 dput(p->dentry);
61853 nfs_sb_deactive(sb);
61854 nfs_fattr_free_names(&p->f_attr);
61855 + kfree(p->f_attr.mdsthreshold);
61856 kfree(p);
61857 }
61858
61859 @@ -2244,10 +2245,12 @@ static int _nfs4_do_open(struct inode *dir,
61860 }
61861 }
61862
61863 - if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
61864 - opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
61865 - if (!opendata->f_attr.mdsthreshold)
61866 - goto err_free_label;
61867 + if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
61868 + if (!opendata->f_attr.mdsthreshold) {
61869 + opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
61870 + if (!opendata->f_attr.mdsthreshold)
61871 + goto err_free_label;
61872 + }
61873 opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0];
61874 }
61875 if (dentry->d_inode != NULL)
61876 @@ -2275,11 +2278,10 @@ static int _nfs4_do_open(struct inode *dir,
61877 if (opendata->file_created)
61878 *opened |= FILE_CREATED;
61879
61880 - if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server))
61881 + if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) {
61882 *ctx_th = opendata->f_attr.mdsthreshold;
61883 - else
61884 - kfree(opendata->f_attr.mdsthreshold);
61885 - opendata->f_attr.mdsthreshold = NULL;
61886 + opendata->f_attr.mdsthreshold = NULL;
61887 + }
61888
61889 nfs4_label_free(olabel);
61890
61891 @@ -2289,7 +2291,6 @@ static int _nfs4_do_open(struct inode *dir,
61892 err_free_label:
61893 nfs4_label_free(olabel);
61894 err_opendata_put:
61895 - kfree(opendata->f_attr.mdsthreshold);
61896 nfs4_opendata_put(opendata);
61897 err_put_state_owner:
61898 nfs4_put_state_owner(sp);
61899 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
61900 index 82189b2..e43a39f 100644
61901 --- a/fs/nfsd/nfs4proc.c
61902 +++ b/fs/nfsd/nfs4proc.c
61903 @@ -1178,7 +1178,7 @@ struct nfsd4_operation {
61904 nfsd4op_rsize op_rsize_bop;
61905 stateid_getter op_get_currentstateid;
61906 stateid_setter op_set_currentstateid;
61907 -};
61908 +} __do_const;
61909
61910 static struct nfsd4_operation nfsd4_ops[];
61911
61912 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
61913 index 63f2395..7c47f4d 100644
61914 --- a/fs/nfsd/nfs4xdr.c
61915 +++ b/fs/nfsd/nfs4xdr.c
61916 @@ -1531,7 +1531,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
61917
61918 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
61919
61920 -static nfsd4_dec nfsd4_dec_ops[] = {
61921 +static const nfsd4_dec nfsd4_dec_ops[] = {
61922 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
61923 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
61924 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
61925 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
61926 index f8f060f..c4ba09a 100644
61927 --- a/fs/nfsd/nfscache.c
61928 +++ b/fs/nfsd/nfscache.c
61929 @@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
61930 {
61931 struct svc_cacherep *rp = rqstp->rq_cacherep;
61932 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
61933 - int len;
61934 + long len;
61935 size_t bufsize = 0;
61936
61937 if (!rp)
61938 return;
61939
61940 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
61941 - len >>= 2;
61942 + if (statp) {
61943 + len = (char*)statp - (char*)resv->iov_base;
61944 + len = resv->iov_len - len;
61945 + len >>= 2;
61946 + }
61947
61948 /* Don't cache excessive amounts of data and XDR failures */
61949 if (!statp || len > (256 >> 2)) {
61950 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
61951 index 6d7be3f..ef02c86 100644
61952 --- a/fs/nfsd/vfs.c
61953 +++ b/fs/nfsd/vfs.c
61954 @@ -834,7 +834,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61955 } else {
61956 oldfs = get_fs();
61957 set_fs(KERNEL_DS);
61958 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
61959 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
61960 set_fs(oldfs);
61961 }
61962
61963 @@ -925,7 +925,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61964
61965 /* Write the data. */
61966 oldfs = get_fs(); set_fs(KERNEL_DS);
61967 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
61968 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
61969 set_fs(oldfs);
61970 if (host_err < 0)
61971 goto out_nfserr;
61972 @@ -1470,7 +1470,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
61973 */
61974
61975 oldfs = get_fs(); set_fs(KERNEL_DS);
61976 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
61977 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
61978 set_fs(oldfs);
61979
61980 if (host_err < 0)
61981 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
61982 index 52ccd34..43a53b1 100644
61983 --- a/fs/nls/nls_base.c
61984 +++ b/fs/nls/nls_base.c
61985 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
61986
61987 int __register_nls(struct nls_table *nls, struct module *owner)
61988 {
61989 - struct nls_table ** tmp = &tables;
61990 + struct nls_table *tmp = tables;
61991
61992 if (nls->next)
61993 return -EBUSY;
61994
61995 - nls->owner = owner;
61996 + pax_open_kernel();
61997 + *(void **)&nls->owner = owner;
61998 + pax_close_kernel();
61999 spin_lock(&nls_lock);
62000 - while (*tmp) {
62001 - if (nls == *tmp) {
62002 + while (tmp) {
62003 + if (nls == tmp) {
62004 spin_unlock(&nls_lock);
62005 return -EBUSY;
62006 }
62007 - tmp = &(*tmp)->next;
62008 + tmp = tmp->next;
62009 }
62010 - nls->next = tables;
62011 + pax_open_kernel();
62012 + *(struct nls_table **)&nls->next = tables;
62013 + pax_close_kernel();
62014 tables = nls;
62015 spin_unlock(&nls_lock);
62016 return 0;
62017 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62018
62019 int unregister_nls(struct nls_table * nls)
62020 {
62021 - struct nls_table ** tmp = &tables;
62022 + struct nls_table * const * tmp = &tables;
62023
62024 spin_lock(&nls_lock);
62025 while (*tmp) {
62026 if (nls == *tmp) {
62027 - *tmp = nls->next;
62028 + pax_open_kernel();
62029 + *(struct nls_table **)tmp = nls->next;
62030 + pax_close_kernel();
62031 spin_unlock(&nls_lock);
62032 return 0;
62033 }
62034 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62035 index 162b3f1..6076a7c 100644
62036 --- a/fs/nls/nls_euc-jp.c
62037 +++ b/fs/nls/nls_euc-jp.c
62038 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62039 p_nls = load_nls("cp932");
62040
62041 if (p_nls) {
62042 - table.charset2upper = p_nls->charset2upper;
62043 - table.charset2lower = p_nls->charset2lower;
62044 + pax_open_kernel();
62045 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62046 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62047 + pax_close_kernel();
62048 return register_nls(&table);
62049 }
62050
62051 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62052 index a80a741..7b96e1b 100644
62053 --- a/fs/nls/nls_koi8-ru.c
62054 +++ b/fs/nls/nls_koi8-ru.c
62055 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62056 p_nls = load_nls("koi8-u");
62057
62058 if (p_nls) {
62059 - table.charset2upper = p_nls->charset2upper;
62060 - table.charset2lower = p_nls->charset2lower;
62061 + pax_open_kernel();
62062 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62063 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62064 + pax_close_kernel();
62065 return register_nls(&table);
62066 }
62067
62068 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62069 index 287a22c..a2a043a 100644
62070 --- a/fs/notify/fanotify/fanotify_user.c
62071 +++ b/fs/notify/fanotify/fanotify_user.c
62072 @@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62073
62074 fd = fanotify_event_metadata.fd;
62075 ret = -EFAULT;
62076 - if (copy_to_user(buf, &fanotify_event_metadata,
62077 - fanotify_event_metadata.event_len))
62078 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62079 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62080 goto out_close_fd;
62081
62082 ret = prepare_for_access_response(group, event, fd);
62083 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62084 index 1e58402..bb2d6f4 100644
62085 --- a/fs/notify/notification.c
62086 +++ b/fs/notify/notification.c
62087 @@ -48,7 +48,7 @@
62088 #include <linux/fsnotify_backend.h>
62089 #include "fsnotify.h"
62090
62091 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62092 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62093
62094 /**
62095 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62096 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62097 */
62098 u32 fsnotify_get_cookie(void)
62099 {
62100 - return atomic_inc_return(&fsnotify_sync_cookie);
62101 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62102 }
62103 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62104
62105 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62106 index 9e38daf..5727cae 100644
62107 --- a/fs/ntfs/dir.c
62108 +++ b/fs/ntfs/dir.c
62109 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
62110 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62111 ~(s64)(ndir->itype.index.block_size - 1)));
62112 /* Bounds checks. */
62113 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62114 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62115 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62116 "inode 0x%lx or driver bug.", vdir->i_ino);
62117 goto err_out;
62118 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62119 index db9bd8a..8338fb6 100644
62120 --- a/fs/ntfs/file.c
62121 +++ b/fs/ntfs/file.c
62122 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62123 char *addr;
62124 size_t total = 0;
62125 unsigned len;
62126 - int left;
62127 + unsigned left;
62128
62129 do {
62130 len = PAGE_CACHE_SIZE - ofs;
62131 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62132 index 82650d5..db37dcf 100644
62133 --- a/fs/ntfs/super.c
62134 +++ b/fs/ntfs/super.c
62135 @@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62136 if (!silent)
62137 ntfs_error(sb, "Primary boot sector is invalid.");
62138 } else if (!silent)
62139 - ntfs_error(sb, read_err_str, "primary");
62140 + ntfs_error(sb, read_err_str, "%s", "primary");
62141 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62142 if (bh_primary)
62143 brelse(bh_primary);
62144 @@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62145 goto hotfix_primary_boot_sector;
62146 brelse(bh_backup);
62147 } else if (!silent)
62148 - ntfs_error(sb, read_err_str, "backup");
62149 + ntfs_error(sb, read_err_str, "%s", "backup");
62150 /* Try to read NT3.51- backup boot sector. */
62151 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62152 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62153 @@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62154 "sector.");
62155 brelse(bh_backup);
62156 } else if (!silent)
62157 - ntfs_error(sb, read_err_str, "backup");
62158 + ntfs_error(sb, read_err_str, "%s", "backup");
62159 /* We failed. Cleanup and return. */
62160 if (bh_primary)
62161 brelse(bh_primary);
62162 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62163 index 0440134..d52c93a 100644
62164 --- a/fs/ocfs2/localalloc.c
62165 +++ b/fs/ocfs2/localalloc.c
62166 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62167 goto bail;
62168 }
62169
62170 - atomic_inc(&osb->alloc_stats.moves);
62171 + atomic_inc_unchecked(&osb->alloc_stats.moves);
62172
62173 bail:
62174 if (handle)
62175 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62176 index 553f53c..aaf5133 100644
62177 --- a/fs/ocfs2/ocfs2.h
62178 +++ b/fs/ocfs2/ocfs2.h
62179 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
62180
62181 struct ocfs2_alloc_stats
62182 {
62183 - atomic_t moves;
62184 - atomic_t local_data;
62185 - atomic_t bitmap_data;
62186 - atomic_t bg_allocs;
62187 - atomic_t bg_extends;
62188 + atomic_unchecked_t moves;
62189 + atomic_unchecked_t local_data;
62190 + atomic_unchecked_t bitmap_data;
62191 + atomic_unchecked_t bg_allocs;
62192 + atomic_unchecked_t bg_extends;
62193 };
62194
62195 enum ocfs2_local_alloc_state
62196 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62197 index 47ae266..6e8b793 100644
62198 --- a/fs/ocfs2/suballoc.c
62199 +++ b/fs/ocfs2/suballoc.c
62200 @@ -866,7 +866,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62201 mlog_errno(status);
62202 goto bail;
62203 }
62204 - atomic_inc(&osb->alloc_stats.bg_extends);
62205 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62206
62207 /* You should never ask for this much metadata */
62208 BUG_ON(bits_wanted >
62209 @@ -1992,7 +1992,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62210 mlog_errno(status);
62211 goto bail;
62212 }
62213 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62214 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62215
62216 *suballoc_loc = res.sr_bg_blkno;
62217 *suballoc_bit_start = res.sr_bit_offset;
62218 @@ -2156,7 +2156,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62219 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62220 res->sr_bits);
62221
62222 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62223 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62224
62225 BUG_ON(res->sr_bits != 1);
62226
62227 @@ -2198,7 +2198,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62228 mlog_errno(status);
62229 goto bail;
62230 }
62231 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62232 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62233
62234 BUG_ON(res.sr_bits != 1);
62235
62236 @@ -2302,7 +2302,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62237 cluster_start,
62238 num_clusters);
62239 if (!status)
62240 - atomic_inc(&osb->alloc_stats.local_data);
62241 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
62242 } else {
62243 if (min_clusters > (osb->bitmap_cpg - 1)) {
62244 /* The only paths asking for contiguousness
62245 @@ -2328,7 +2328,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62246 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62247 res.sr_bg_blkno,
62248 res.sr_bit_offset);
62249 - atomic_inc(&osb->alloc_stats.bitmap_data);
62250 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62251 *num_clusters = res.sr_bits;
62252 }
62253 }
62254 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62255 index 49d84f8..4807e0b 100644
62256 --- a/fs/ocfs2/super.c
62257 +++ b/fs/ocfs2/super.c
62258 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62259 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62260 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62261 "Stats",
62262 - atomic_read(&osb->alloc_stats.bitmap_data),
62263 - atomic_read(&osb->alloc_stats.local_data),
62264 - atomic_read(&osb->alloc_stats.bg_allocs),
62265 - atomic_read(&osb->alloc_stats.moves),
62266 - atomic_read(&osb->alloc_stats.bg_extends));
62267 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62268 + atomic_read_unchecked(&osb->alloc_stats.local_data),
62269 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62270 + atomic_read_unchecked(&osb->alloc_stats.moves),
62271 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62272
62273 out += snprintf(buf + out, len - out,
62274 "%10s => State: %u Descriptor: %llu Size: %u bits "
62275 @@ -2123,11 +2123,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62276 spin_lock_init(&osb->osb_xattr_lock);
62277 ocfs2_init_steal_slots(osb);
62278
62279 - atomic_set(&osb->alloc_stats.moves, 0);
62280 - atomic_set(&osb->alloc_stats.local_data, 0);
62281 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
62282 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
62283 - atomic_set(&osb->alloc_stats.bg_extends, 0);
62284 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62285 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62286 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62287 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62288 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62289
62290 /* Copy the blockcheck stats from the superblock probe */
62291 osb->osb_ecc_stats = *stats;
62292 diff --git a/fs/open.c b/fs/open.c
62293 index b9ed8b2..0d5c7a0 100644
62294 --- a/fs/open.c
62295 +++ b/fs/open.c
62296 @@ -32,6 +32,8 @@
62297 #include <linux/dnotify.h>
62298 #include <linux/compat.h>
62299
62300 +#define CREATE_TRACE_POINTS
62301 +#include <trace/events/fs.h>
62302 #include "internal.h"
62303
62304 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62305 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62306 error = locks_verify_truncate(inode, NULL, length);
62307 if (!error)
62308 error = security_path_truncate(path);
62309 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62310 + error = -EACCES;
62311 if (!error)
62312 error = do_truncate(path->dentry, length, 0, NULL);
62313
62314 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62315 error = locks_verify_truncate(inode, f.file, length);
62316 if (!error)
62317 error = security_path_truncate(&f.file->f_path);
62318 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62319 + error = -EACCES;
62320 if (!error)
62321 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62322 sb_end_write(inode->i_sb);
62323 @@ -361,6 +367,9 @@ retry:
62324 if (__mnt_is_readonly(path.mnt))
62325 res = -EROFS;
62326
62327 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62328 + res = -EACCES;
62329 +
62330 out_path_release:
62331 path_put(&path);
62332 if (retry_estale(res, lookup_flags)) {
62333 @@ -392,6 +401,8 @@ retry:
62334 if (error)
62335 goto dput_and_out;
62336
62337 + gr_log_chdir(path.dentry, path.mnt);
62338 +
62339 set_fs_pwd(current->fs, &path);
62340
62341 dput_and_out:
62342 @@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62343 goto out_putf;
62344
62345 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62346 +
62347 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62348 + error = -EPERM;
62349 +
62350 + if (!error)
62351 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62352 +
62353 if (!error)
62354 set_fs_pwd(current->fs, &f.file->f_path);
62355 out_putf:
62356 @@ -450,7 +468,13 @@ retry:
62357 if (error)
62358 goto dput_and_out;
62359
62360 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62361 + goto dput_and_out;
62362 +
62363 set_fs_root(current->fs, &path);
62364 +
62365 + gr_handle_chroot_chdir(&path);
62366 +
62367 error = 0;
62368 dput_and_out:
62369 path_put(&path);
62370 @@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
62371 return error;
62372 retry_deleg:
62373 mutex_lock(&inode->i_mutex);
62374 +
62375 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62376 + error = -EACCES;
62377 + goto out_unlock;
62378 + }
62379 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62380 + error = -EACCES;
62381 + goto out_unlock;
62382 + }
62383 +
62384 error = security_path_chmod(path, mode);
62385 if (error)
62386 goto out_unlock;
62387 @@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62388 uid = make_kuid(current_user_ns(), user);
62389 gid = make_kgid(current_user_ns(), group);
62390
62391 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
62392 + return -EACCES;
62393 +
62394 newattrs.ia_valid = ATTR_CTIME;
62395 if (user != (uid_t) -1) {
62396 if (!uid_valid(uid))
62397 @@ -994,6 +1031,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62398 } else {
62399 fsnotify_open(f);
62400 fd_install(fd, f);
62401 + trace_do_sys_open(tmp->name, flags, mode);
62402 }
62403 }
62404 putname(tmp);
62405 diff --git a/fs/pipe.c b/fs/pipe.c
62406 index 78fd0d0..f71fc09 100644
62407 --- a/fs/pipe.c
62408 +++ b/fs/pipe.c
62409 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62410
62411 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62412 {
62413 - if (pipe->files)
62414 + if (atomic_read(&pipe->files))
62415 mutex_lock_nested(&pipe->mutex, subclass);
62416 }
62417
62418 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62419
62420 void pipe_unlock(struct pipe_inode_info *pipe)
62421 {
62422 - if (pipe->files)
62423 + if (atomic_read(&pipe->files))
62424 mutex_unlock(&pipe->mutex);
62425 }
62426 EXPORT_SYMBOL(pipe_unlock);
62427 @@ -449,9 +449,9 @@ redo:
62428 }
62429 if (bufs) /* More to do? */
62430 continue;
62431 - if (!pipe->writers)
62432 + if (!atomic_read(&pipe->writers))
62433 break;
62434 - if (!pipe->waiting_writers) {
62435 + if (!atomic_read(&pipe->waiting_writers)) {
62436 /* syscall merging: Usually we must not sleep
62437 * if O_NONBLOCK is set, or if we got some data.
62438 * But if a writer sleeps in kernel space, then
62439 @@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62440 ret = 0;
62441 __pipe_lock(pipe);
62442
62443 - if (!pipe->readers) {
62444 + if (!atomic_read(&pipe->readers)) {
62445 send_sig(SIGPIPE, current, 0);
62446 ret = -EPIPE;
62447 goto out;
62448 @@ -562,7 +562,7 @@ redo1:
62449 for (;;) {
62450 int bufs;
62451
62452 - if (!pipe->readers) {
62453 + if (!atomic_read(&pipe->readers)) {
62454 send_sig(SIGPIPE, current, 0);
62455 if (!ret)
62456 ret = -EPIPE;
62457 @@ -653,9 +653,9 @@ redo2:
62458 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62459 do_wakeup = 0;
62460 }
62461 - pipe->waiting_writers++;
62462 + atomic_inc(&pipe->waiting_writers);
62463 pipe_wait(pipe);
62464 - pipe->waiting_writers--;
62465 + atomic_dec(&pipe->waiting_writers);
62466 }
62467 out:
62468 __pipe_unlock(pipe);
62469 @@ -710,7 +710,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62470 mask = 0;
62471 if (filp->f_mode & FMODE_READ) {
62472 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62473 - if (!pipe->writers && filp->f_version != pipe->w_counter)
62474 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62475 mask |= POLLHUP;
62476 }
62477
62478 @@ -720,7 +720,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62479 * Most Unices do not set POLLERR for FIFOs but on Linux they
62480 * behave exactly like pipes for poll().
62481 */
62482 - if (!pipe->readers)
62483 + if (!atomic_read(&pipe->readers))
62484 mask |= POLLERR;
62485 }
62486
62487 @@ -732,7 +732,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62488 int kill = 0;
62489
62490 spin_lock(&inode->i_lock);
62491 - if (!--pipe->files) {
62492 + if (atomic_dec_and_test(&pipe->files)) {
62493 inode->i_pipe = NULL;
62494 kill = 1;
62495 }
62496 @@ -749,11 +749,11 @@ pipe_release(struct inode *inode, struct file *file)
62497
62498 __pipe_lock(pipe);
62499 if (file->f_mode & FMODE_READ)
62500 - pipe->readers--;
62501 + atomic_dec(&pipe->readers);
62502 if (file->f_mode & FMODE_WRITE)
62503 - pipe->writers--;
62504 + atomic_dec(&pipe->writers);
62505
62506 - if (pipe->readers || pipe->writers) {
62507 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62508 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62509 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62510 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62511 @@ -818,7 +818,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62512 kfree(pipe);
62513 }
62514
62515 -static struct vfsmount *pipe_mnt __read_mostly;
62516 +struct vfsmount *pipe_mnt __read_mostly;
62517
62518 /*
62519 * pipefs_dname() is called from d_path().
62520 @@ -848,8 +848,9 @@ static struct inode * get_pipe_inode(void)
62521 goto fail_iput;
62522
62523 inode->i_pipe = pipe;
62524 - pipe->files = 2;
62525 - pipe->readers = pipe->writers = 1;
62526 + atomic_set(&pipe->files, 2);
62527 + atomic_set(&pipe->readers, 1);
62528 + atomic_set(&pipe->writers, 1);
62529 inode->i_fop = &pipefifo_fops;
62530
62531 /*
62532 @@ -1028,17 +1029,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62533 spin_lock(&inode->i_lock);
62534 if (inode->i_pipe) {
62535 pipe = inode->i_pipe;
62536 - pipe->files++;
62537 + atomic_inc(&pipe->files);
62538 spin_unlock(&inode->i_lock);
62539 } else {
62540 spin_unlock(&inode->i_lock);
62541 pipe = alloc_pipe_info();
62542 if (!pipe)
62543 return -ENOMEM;
62544 - pipe->files = 1;
62545 + atomic_set(&pipe->files, 1);
62546 spin_lock(&inode->i_lock);
62547 if (unlikely(inode->i_pipe)) {
62548 - inode->i_pipe->files++;
62549 + atomic_inc(&inode->i_pipe->files);
62550 spin_unlock(&inode->i_lock);
62551 free_pipe_info(pipe);
62552 pipe = inode->i_pipe;
62553 @@ -1063,10 +1064,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
62554 * opened, even when there is no process writing the FIFO.
62555 */
62556 pipe->r_counter++;
62557 - if (pipe->readers++ == 0)
62558 + if (atomic_inc_return(&pipe->readers) == 1)
62559 wake_up_partner(pipe);
62560
62561 - if (!is_pipe && !pipe->writers) {
62562 + if (!is_pipe && !atomic_read(&pipe->writers)) {
62563 if ((filp->f_flags & O_NONBLOCK)) {
62564 /* suppress POLLHUP until we have
62565 * seen a writer */
62566 @@ -1085,14 +1086,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
62567 * errno=ENXIO when there is no process reading the FIFO.
62568 */
62569 ret = -ENXIO;
62570 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
62571 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
62572 goto err;
62573
62574 pipe->w_counter++;
62575 - if (!pipe->writers++)
62576 + if (atomic_inc_return(&pipe->writers) == 1)
62577 wake_up_partner(pipe);
62578
62579 - if (!is_pipe && !pipe->readers) {
62580 + if (!is_pipe && !atomic_read(&pipe->readers)) {
62581 if (wait_for_partner(pipe, &pipe->r_counter))
62582 goto err_wr;
62583 }
62584 @@ -1106,11 +1107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
62585 * the process can at least talk to itself.
62586 */
62587
62588 - pipe->readers++;
62589 - pipe->writers++;
62590 + atomic_inc(&pipe->readers);
62591 + atomic_inc(&pipe->writers);
62592 pipe->r_counter++;
62593 pipe->w_counter++;
62594 - if (pipe->readers == 1 || pipe->writers == 1)
62595 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
62596 wake_up_partner(pipe);
62597 break;
62598
62599 @@ -1124,13 +1125,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
62600 return 0;
62601
62602 err_rd:
62603 - if (!--pipe->readers)
62604 + if (atomic_dec_and_test(&pipe->readers))
62605 wake_up_interruptible(&pipe->wait);
62606 ret = -ERESTARTSYS;
62607 goto err;
62608
62609 err_wr:
62610 - if (!--pipe->writers)
62611 + if (atomic_dec_and_test(&pipe->writers))
62612 wake_up_interruptible(&pipe->wait);
62613 ret = -ERESTARTSYS;
62614 goto err;
62615 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
62616 index 11c54fd..eef5f0b 100644
62617 --- a/fs/posix_acl.c
62618 +++ b/fs/posix_acl.c
62619 @@ -20,6 +20,7 @@
62620 #include <linux/xattr.h>
62621 #include <linux/export.h>
62622 #include <linux/user_namespace.h>
62623 +#include <linux/grsecurity.h>
62624
62625 struct posix_acl **acl_by_type(struct inode *inode, int type)
62626 {
62627 @@ -271,7 +272,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
62628 }
62629 }
62630 if (mode_p)
62631 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62632 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62633 return not_equiv;
62634 }
62635 EXPORT_SYMBOL(posix_acl_equiv_mode);
62636 @@ -421,7 +422,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
62637 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
62638 }
62639
62640 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62641 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62642 return not_equiv;
62643 }
62644
62645 @@ -479,6 +480,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
62646 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
62647 int err = -ENOMEM;
62648 if (clone) {
62649 + *mode_p &= ~gr_acl_umask();
62650 +
62651 err = posix_acl_create_masq(clone, mode_p);
62652 if (err < 0) {
62653 posix_acl_release(clone);
62654 @@ -653,11 +656,12 @@ struct posix_acl *
62655 posix_acl_from_xattr(struct user_namespace *user_ns,
62656 const void *value, size_t size)
62657 {
62658 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
62659 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
62660 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
62661 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
62662 int count;
62663 struct posix_acl *acl;
62664 struct posix_acl_entry *acl_e;
62665 + umode_t umask = gr_acl_umask();
62666
62667 if (!value)
62668 return NULL;
62669 @@ -683,12 +687,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
62670
62671 switch(acl_e->e_tag) {
62672 case ACL_USER_OBJ:
62673 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
62674 + break;
62675 case ACL_GROUP_OBJ:
62676 case ACL_MASK:
62677 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
62678 + break;
62679 case ACL_OTHER:
62680 + acl_e->e_perm &= ~(umask & S_IRWXO);
62681 break;
62682
62683 case ACL_USER:
62684 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
62685 acl_e->e_uid =
62686 make_kuid(user_ns,
62687 le32_to_cpu(entry->e_id));
62688 @@ -696,6 +706,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
62689 goto fail;
62690 break;
62691 case ACL_GROUP:
62692 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
62693 acl_e->e_gid =
62694 make_kgid(user_ns,
62695 le32_to_cpu(entry->e_id));
62696 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
62697 index 2183fcf..3c32a98 100644
62698 --- a/fs/proc/Kconfig
62699 +++ b/fs/proc/Kconfig
62700 @@ -30,7 +30,7 @@ config PROC_FS
62701
62702 config PROC_KCORE
62703 bool "/proc/kcore support" if !ARM
62704 - depends on PROC_FS && MMU
62705 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
62706 help
62707 Provides a virtual ELF core file of the live kernel. This can
62708 be read with gdb and other ELF tools. No modifications can be
62709 @@ -38,8 +38,8 @@ config PROC_KCORE
62710
62711 config PROC_VMCORE
62712 bool "/proc/vmcore support"
62713 - depends on PROC_FS && CRASH_DUMP
62714 - default y
62715 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
62716 + default n
62717 help
62718 Exports the dump image of crashed kernel in ELF format.
62719
62720 @@ -63,8 +63,8 @@ config PROC_SYSCTL
62721 limited in memory.
62722
62723 config PROC_PAGE_MONITOR
62724 - default y
62725 - depends on PROC_FS && MMU
62726 + default n
62727 + depends on PROC_FS && MMU && !GRKERNSEC
62728 bool "Enable /proc page monitoring" if EXPERT
62729 help
62730 Various /proc files exist to monitor process memory utilization:
62731 diff --git a/fs/proc/array.c b/fs/proc/array.c
62732 index 656e401..b5b86b9 100644
62733 --- a/fs/proc/array.c
62734 +++ b/fs/proc/array.c
62735 @@ -60,6 +60,7 @@
62736 #include <linux/tty.h>
62737 #include <linux/string.h>
62738 #include <linux/mman.h>
62739 +#include <linux/grsecurity.h>
62740 #include <linux/proc_fs.h>
62741 #include <linux/ioport.h>
62742 #include <linux/uaccess.h>
62743 @@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
62744 seq_putc(m, '\n');
62745 }
62746
62747 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62748 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
62749 +{
62750 + if (p->mm)
62751 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
62752 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
62753 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
62754 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
62755 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
62756 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
62757 + else
62758 + seq_printf(m, "PaX:\t-----\n");
62759 +}
62760 +#endif
62761 +
62762 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62763 struct pid *pid, struct task_struct *task)
62764 {
62765 @@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62766 task_cpus_allowed(m, task);
62767 cpuset_task_status_allowed(m, task);
62768 task_context_switch_counts(m, task);
62769 +
62770 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62771 + task_pax(m, task);
62772 +#endif
62773 +
62774 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
62775 + task_grsec_rbac(m, task);
62776 +#endif
62777 +
62778 return 0;
62779 }
62780
62781 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62782 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62783 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
62784 + _mm->pax_flags & MF_PAX_SEGMEXEC))
62785 +#endif
62786 +
62787 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62788 struct pid *pid, struct task_struct *task, int whole)
62789 {
62790 @@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62791 char tcomm[sizeof(task->comm)];
62792 unsigned long flags;
62793
62794 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62795 + if (current->exec_id != m->exec_id) {
62796 + gr_log_badprocpid("stat");
62797 + return 0;
62798 + }
62799 +#endif
62800 +
62801 state = *get_task_state(task);
62802 vsize = eip = esp = 0;
62803 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62804 @@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62805 gtime = task_gtime(task);
62806 }
62807
62808 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62809 + if (PAX_RAND_FLAGS(mm)) {
62810 + eip = 0;
62811 + esp = 0;
62812 + wchan = 0;
62813 + }
62814 +#endif
62815 +#ifdef CONFIG_GRKERNSEC_HIDESYM
62816 + wchan = 0;
62817 + eip =0;
62818 + esp =0;
62819 +#endif
62820 +
62821 /* scale priority and nice values from timeslices to -20..20 */
62822 /* to make it look like a "normal" Unix priority/nice value */
62823 priority = task_prio(task);
62824 @@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62825 seq_put_decimal_ull(m, ' ', vsize);
62826 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
62827 seq_put_decimal_ull(m, ' ', rsslim);
62828 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62829 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
62830 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
62831 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
62832 +#else
62833 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
62834 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
62835 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
62836 +#endif
62837 seq_put_decimal_ull(m, ' ', esp);
62838 seq_put_decimal_ull(m, ' ', eip);
62839 /* The signal information here is obsolete.
62840 @@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62841 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
62842 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
62843
62844 - if (mm && permitted) {
62845 + if (mm && permitted
62846 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62847 + && !PAX_RAND_FLAGS(mm)
62848 +#endif
62849 + ) {
62850 seq_put_decimal_ull(m, ' ', mm->start_data);
62851 seq_put_decimal_ull(m, ' ', mm->end_data);
62852 seq_put_decimal_ull(m, ' ', mm->start_brk);
62853 @@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62854 struct pid *pid, struct task_struct *task)
62855 {
62856 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
62857 - struct mm_struct *mm = get_task_mm(task);
62858 + struct mm_struct *mm;
62859
62860 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62861 + if (current->exec_id != m->exec_id) {
62862 + gr_log_badprocpid("statm");
62863 + return 0;
62864 + }
62865 +#endif
62866 + mm = get_task_mm(task);
62867 if (mm) {
62868 size = task_statm(mm, &shared, &text, &data, &resident);
62869 mmput(mm);
62870 @@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62871 return 0;
62872 }
62873
62874 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62875 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
62876 +{
62877 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
62878 +}
62879 +#endif
62880 +
62881 #ifdef CONFIG_CHECKPOINT_RESTORE
62882 static struct pid *
62883 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
62884 diff --git a/fs/proc/base.c b/fs/proc/base.c
62885 index b976062..584d0bc 100644
62886 --- a/fs/proc/base.c
62887 +++ b/fs/proc/base.c
62888 @@ -113,6 +113,14 @@ struct pid_entry {
62889 union proc_op op;
62890 };
62891
62892 +struct getdents_callback {
62893 + struct linux_dirent __user * current_dir;
62894 + struct linux_dirent __user * previous;
62895 + struct file * file;
62896 + int count;
62897 + int error;
62898 +};
62899 +
62900 #define NOD(NAME, MODE, IOP, FOP, OP) { \
62901 .name = (NAME), \
62902 .len = sizeof(NAME) - 1, \
62903 @@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
62904 if (!mm->arg_end)
62905 goto out_mm; /* Shh! No looking before we're done */
62906
62907 + if (gr_acl_handle_procpidmem(task))
62908 + goto out_mm;
62909 +
62910 len = mm->arg_end - mm->arg_start;
62911
62912 if (len > PAGE_SIZE)
62913 @@ -237,12 +248,28 @@ out:
62914 return res;
62915 }
62916
62917 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62918 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62919 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
62920 + _mm->pax_flags & MF_PAX_SEGMEXEC))
62921 +#endif
62922 +
62923 static int proc_pid_auxv(struct task_struct *task, char *buffer)
62924 {
62925 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
62926 int res = PTR_ERR(mm);
62927 if (mm && !IS_ERR(mm)) {
62928 unsigned int nwords = 0;
62929 +
62930 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62931 + /* allow if we're currently ptracing this task */
62932 + if (PAX_RAND_FLAGS(mm) &&
62933 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
62934 + mmput(mm);
62935 + return 0;
62936 + }
62937 +#endif
62938 +
62939 do {
62940 nwords += 2;
62941 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
62942 @@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
62943 }
62944
62945
62946 -#ifdef CONFIG_KALLSYMS
62947 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62948 /*
62949 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
62950 * Returns the resolved symbol. If that fails, simply return the address.
62951 @@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
62952 mutex_unlock(&task->signal->cred_guard_mutex);
62953 }
62954
62955 -#ifdef CONFIG_STACKTRACE
62956 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62957
62958 #define MAX_STACK_TRACE_DEPTH 64
62959
62960 @@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
62961 return count;
62962 }
62963
62964 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62965 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62966 static int proc_pid_syscall(struct task_struct *task, char *buffer)
62967 {
62968 long nr;
62969 @@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
62970 /************************************************************************/
62971
62972 /* permission checks */
62973 -static int proc_fd_access_allowed(struct inode *inode)
62974 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
62975 {
62976 struct task_struct *task;
62977 int allowed = 0;
62978 @@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
62979 */
62980 task = get_proc_task(inode);
62981 if (task) {
62982 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62983 + if (log)
62984 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62985 + else
62986 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62987 put_task_struct(task);
62988 }
62989 return allowed;
62990 @@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
62991 struct task_struct *task,
62992 int hide_pid_min)
62993 {
62994 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62995 + return false;
62996 +
62997 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62998 + rcu_read_lock();
62999 + {
63000 + const struct cred *tmpcred = current_cred();
63001 + const struct cred *cred = __task_cred(task);
63002 +
63003 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63004 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63005 + || in_group_p(grsec_proc_gid)
63006 +#endif
63007 + ) {
63008 + rcu_read_unlock();
63009 + return true;
63010 + }
63011 + }
63012 + rcu_read_unlock();
63013 +
63014 + if (!pid->hide_pid)
63015 + return false;
63016 +#endif
63017 +
63018 if (pid->hide_pid < hide_pid_min)
63019 return true;
63020 if (in_group_p(pid->pid_gid))
63021 return true;
63022 +
63023 return ptrace_may_access(task, PTRACE_MODE_READ);
63024 }
63025
63026 @@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63027 put_task_struct(task);
63028
63029 if (!has_perms) {
63030 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63031 + {
63032 +#else
63033 if (pid->hide_pid == 2) {
63034 +#endif
63035 /*
63036 * Let's make getdents(), stat(), and open()
63037 * consistent with each other. If a process
63038 @@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63039 if (!task)
63040 return -ESRCH;
63041
63042 + if (gr_acl_handle_procpidmem(task)) {
63043 + put_task_struct(task);
63044 + return -EPERM;
63045 + }
63046 +
63047 mm = mm_access(task, mode);
63048 put_task_struct(task);
63049
63050 @@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63051
63052 file->private_data = mm;
63053
63054 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63055 + file->f_version = current->exec_id;
63056 +#endif
63057 +
63058 return 0;
63059 }
63060
63061 @@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63062 ssize_t copied;
63063 char *page;
63064
63065 +#ifdef CONFIG_GRKERNSEC
63066 + if (write)
63067 + return -EPERM;
63068 +#endif
63069 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63070 + if (file->f_version != current->exec_id) {
63071 + gr_log_badprocpid("mem");
63072 + return 0;
63073 + }
63074 +#endif
63075 +
63076 if (!mm)
63077 return 0;
63078
63079 @@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63080 goto free;
63081
63082 while (count > 0) {
63083 - int this_len = min_t(int, count, PAGE_SIZE);
63084 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63085
63086 if (write && copy_from_user(page, buf, this_len)) {
63087 copied = -EFAULT;
63088 @@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63089 if (!mm)
63090 return 0;
63091
63092 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63093 + if (file->f_version != current->exec_id) {
63094 + gr_log_badprocpid("environ");
63095 + return 0;
63096 + }
63097 +#endif
63098 +
63099 page = (char *)__get_free_page(GFP_TEMPORARY);
63100 if (!page)
63101 return -ENOMEM;
63102 @@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63103 goto free;
63104 while (count > 0) {
63105 size_t this_len, max_len;
63106 - int retval;
63107 + ssize_t retval;
63108
63109 if (src >= (mm->env_end - mm->env_start))
63110 break;
63111 @@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63112 int error = -EACCES;
63113
63114 /* Are we allowed to snoop on the tasks file descriptors? */
63115 - if (!proc_fd_access_allowed(inode))
63116 + if (!proc_fd_access_allowed(inode, 0))
63117 goto out;
63118
63119 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63120 @@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63121 struct path path;
63122
63123 /* Are we allowed to snoop on the tasks file descriptors? */
63124 - if (!proc_fd_access_allowed(inode))
63125 - goto out;
63126 + /* logging this is needed for learning on chromium to work properly,
63127 + but we don't want to flood the logs from 'ps' which does a readlink
63128 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63129 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
63130 + */
63131 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63132 + if (!proc_fd_access_allowed(inode,0))
63133 + goto out;
63134 + } else {
63135 + if (!proc_fd_access_allowed(inode,1))
63136 + goto out;
63137 + }
63138
63139 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63140 if (error)
63141 @@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63142 rcu_read_lock();
63143 cred = __task_cred(task);
63144 inode->i_uid = cred->euid;
63145 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63146 + inode->i_gid = grsec_proc_gid;
63147 +#else
63148 inode->i_gid = cred->egid;
63149 +#endif
63150 rcu_read_unlock();
63151 }
63152 security_task_to_inode(task, inode);
63153 @@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63154 return -ENOENT;
63155 }
63156 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63157 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63158 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63159 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63160 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63161 +#endif
63162 task_dumpable(task)) {
63163 cred = __task_cred(task);
63164 stat->uid = cred->euid;
63165 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63166 + stat->gid = grsec_proc_gid;
63167 +#else
63168 stat->gid = cred->egid;
63169 +#endif
63170 }
63171 }
63172 rcu_read_unlock();
63173 @@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63174
63175 if (task) {
63176 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63177 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63178 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63179 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63180 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63181 +#endif
63182 task_dumpable(task)) {
63183 rcu_read_lock();
63184 cred = __task_cred(task);
63185 inode->i_uid = cred->euid;
63186 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63187 + inode->i_gid = grsec_proc_gid;
63188 +#else
63189 inode->i_gid = cred->egid;
63190 +#endif
63191 rcu_read_unlock();
63192 } else {
63193 inode->i_uid = GLOBAL_ROOT_UID;
63194 @@ -2178,6 +2296,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63195 if (!task)
63196 goto out_no_task;
63197
63198 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63199 + goto out;
63200 +
63201 /*
63202 * Yes, it does not scale. And it should not. Don't add
63203 * new entries into /proc/<tgid>/ without very good reasons.
63204 @@ -2208,6 +2329,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63205 if (!task)
63206 return -ENOENT;
63207
63208 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63209 + goto out;
63210 +
63211 if (!dir_emit_dots(file, ctx))
63212 goto out;
63213
63214 @@ -2597,7 +2721,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63215 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63216 #endif
63217 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63218 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63219 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63220 INF("syscall", S_IRUGO, proc_pid_syscall),
63221 #endif
63222 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63223 @@ -2622,10 +2746,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63224 #ifdef CONFIG_SECURITY
63225 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63226 #endif
63227 -#ifdef CONFIG_KALLSYMS
63228 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63229 INF("wchan", S_IRUGO, proc_pid_wchan),
63230 #endif
63231 -#ifdef CONFIG_STACKTRACE
63232 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63233 ONE("stack", S_IRUGO, proc_pid_stack),
63234 #endif
63235 #ifdef CONFIG_SCHEDSTATS
63236 @@ -2659,6 +2783,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63237 #ifdef CONFIG_HARDWALL
63238 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63239 #endif
63240 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63241 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63242 +#endif
63243 #ifdef CONFIG_USER_NS
63244 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63245 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63246 @@ -2789,7 +2916,14 @@ static int proc_pid_instantiate(struct inode *dir,
63247 if (!inode)
63248 goto out;
63249
63250 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63251 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63252 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63253 + inode->i_gid = grsec_proc_gid;
63254 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63255 +#else
63256 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63257 +#endif
63258 inode->i_op = &proc_tgid_base_inode_operations;
63259 inode->i_fop = &proc_tgid_base_operations;
63260 inode->i_flags|=S_IMMUTABLE;
63261 @@ -2827,7 +2961,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63262 if (!task)
63263 goto out;
63264
63265 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63266 + goto out_put_task;
63267 +
63268 result = proc_pid_instantiate(dir, dentry, task, NULL);
63269 +out_put_task:
63270 put_task_struct(task);
63271 out:
63272 return ERR_PTR(result);
63273 @@ -2933,7 +3071,7 @@ static const struct pid_entry tid_base_stuff[] = {
63274 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63275 #endif
63276 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63277 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63278 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63279 INF("syscall", S_IRUGO, proc_pid_syscall),
63280 #endif
63281 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63282 @@ -2960,10 +3098,10 @@ static const struct pid_entry tid_base_stuff[] = {
63283 #ifdef CONFIG_SECURITY
63284 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63285 #endif
63286 -#ifdef CONFIG_KALLSYMS
63287 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63288 INF("wchan", S_IRUGO, proc_pid_wchan),
63289 #endif
63290 -#ifdef CONFIG_STACKTRACE
63291 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63292 ONE("stack", S_IRUGO, proc_pid_stack),
63293 #endif
63294 #ifdef CONFIG_SCHEDSTATS
63295 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63296 index cbd82df..c0407d2 100644
63297 --- a/fs/proc/cmdline.c
63298 +++ b/fs/proc/cmdline.c
63299 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63300
63301 static int __init proc_cmdline_init(void)
63302 {
63303 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63304 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63305 +#else
63306 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63307 +#endif
63308 return 0;
63309 }
63310 fs_initcall(proc_cmdline_init);
63311 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63312 index 50493ed..248166b 100644
63313 --- a/fs/proc/devices.c
63314 +++ b/fs/proc/devices.c
63315 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63316
63317 static int __init proc_devices_init(void)
63318 {
63319 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63320 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63321 +#else
63322 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63323 +#endif
63324 return 0;
63325 }
63326 fs_initcall(proc_devices_init);
63327 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63328 index 985ea88..d118a0a 100644
63329 --- a/fs/proc/fd.c
63330 +++ b/fs/proc/fd.c
63331 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
63332 if (!task)
63333 return -ENOENT;
63334
63335 - files = get_files_struct(task);
63336 + if (!gr_acl_handle_procpidmem(task))
63337 + files = get_files_struct(task);
63338 put_task_struct(task);
63339
63340 if (files) {
63341 @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63342 */
63343 int proc_fd_permission(struct inode *inode, int mask)
63344 {
63345 + struct task_struct *task;
63346 int rv = generic_permission(inode, mask);
63347 - if (rv == 0)
63348 - return 0;
63349 +
63350 if (task_tgid(current) == proc_pid(inode))
63351 rv = 0;
63352 +
63353 + task = get_proc_task(inode);
63354 + if (task == NULL)
63355 + return rv;
63356 +
63357 + if (gr_acl_handle_procpidmem(task))
63358 + rv = -EACCES;
63359 +
63360 + put_task_struct(task);
63361 +
63362 return rv;
63363 }
63364
63365 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63366 index 124fc43..8afbb02 100644
63367 --- a/fs/proc/inode.c
63368 +++ b/fs/proc/inode.c
63369 @@ -23,11 +23,17 @@
63370 #include <linux/slab.h>
63371 #include <linux/mount.h>
63372 #include <linux/magic.h>
63373 +#include <linux/grsecurity.h>
63374
63375 #include <asm/uaccess.h>
63376
63377 #include "internal.h"
63378
63379 +#ifdef CONFIG_PROC_SYSCTL
63380 +extern const struct inode_operations proc_sys_inode_operations;
63381 +extern const struct inode_operations proc_sys_dir_operations;
63382 +#endif
63383 +
63384 static void proc_evict_inode(struct inode *inode)
63385 {
63386 struct proc_dir_entry *de;
63387 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63388 ns = PROC_I(inode)->ns.ns;
63389 if (ns_ops && ns)
63390 ns_ops->put(ns);
63391 +
63392 +#ifdef CONFIG_PROC_SYSCTL
63393 + if (inode->i_op == &proc_sys_inode_operations ||
63394 + inode->i_op == &proc_sys_dir_operations)
63395 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63396 +#endif
63397 +
63398 }
63399
63400 static struct kmem_cache * proc_inode_cachep;
63401 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63402 if (de->mode) {
63403 inode->i_mode = de->mode;
63404 inode->i_uid = de->uid;
63405 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63406 + inode->i_gid = grsec_proc_gid;
63407 +#else
63408 inode->i_gid = de->gid;
63409 +#endif
63410 }
63411 if (de->size)
63412 inode->i_size = de->size;
63413 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63414 index 651d09a..3d7f0bf 100644
63415 --- a/fs/proc/internal.h
63416 +++ b/fs/proc/internal.h
63417 @@ -48,7 +48,7 @@ struct proc_dir_entry {
63418 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
63419 u8 namelen;
63420 char name[];
63421 -};
63422 +} __randomize_layout;
63423
63424 union proc_op {
63425 int (*proc_get_link)(struct dentry *, struct path *);
63426 @@ -67,7 +67,7 @@ struct proc_inode {
63427 struct ctl_table *sysctl_entry;
63428 struct proc_ns ns;
63429 struct inode vfs_inode;
63430 -};
63431 +} __randomize_layout;
63432
63433 /*
63434 * General functions
63435 @@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
63436 struct pid *, struct task_struct *);
63437 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
63438 struct pid *, struct task_struct *);
63439 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63440 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
63441 +#endif
63442
63443 /*
63444 * base.c
63445 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
63446 index a352d57..cb94a5c 100644
63447 --- a/fs/proc/interrupts.c
63448 +++ b/fs/proc/interrupts.c
63449 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
63450
63451 static int __init proc_interrupts_init(void)
63452 {
63453 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63454 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
63455 +#else
63456 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
63457 +#endif
63458 return 0;
63459 }
63460 fs_initcall(proc_interrupts_init);
63461 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
63462 index 39e6ef3..2f9cb5e 100644
63463 --- a/fs/proc/kcore.c
63464 +++ b/fs/proc/kcore.c
63465 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63466 * the addresses in the elf_phdr on our list.
63467 */
63468 start = kc_offset_to_vaddr(*fpos - elf_buflen);
63469 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
63470 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
63471 + if (tsz > buflen)
63472 tsz = buflen;
63473 -
63474 +
63475 while (buflen) {
63476 struct kcore_list *m;
63477
63478 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63479 kfree(elf_buf);
63480 } else {
63481 if (kern_addr_valid(start)) {
63482 - unsigned long n;
63483 + char *elf_buf;
63484 + mm_segment_t oldfs;
63485
63486 - n = copy_to_user(buffer, (char *)start, tsz);
63487 - /*
63488 - * We cannot distinguish between fault on source
63489 - * and fault on destination. When this happens
63490 - * we clear too and hope it will trigger the
63491 - * EFAULT again.
63492 - */
63493 - if (n) {
63494 - if (clear_user(buffer + tsz - n,
63495 - n))
63496 + elf_buf = kmalloc(tsz, GFP_KERNEL);
63497 + if (!elf_buf)
63498 + return -ENOMEM;
63499 + oldfs = get_fs();
63500 + set_fs(KERNEL_DS);
63501 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
63502 + set_fs(oldfs);
63503 + if (copy_to_user(buffer, elf_buf, tsz)) {
63504 + kfree(elf_buf);
63505 return -EFAULT;
63506 + }
63507 }
63508 + set_fs(oldfs);
63509 + kfree(elf_buf);
63510 } else {
63511 if (clear_user(buffer, tsz))
63512 return -EFAULT;
63513 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63514
63515 static int open_kcore(struct inode *inode, struct file *filp)
63516 {
63517 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
63518 + return -EPERM;
63519 +#endif
63520 if (!capable(CAP_SYS_RAWIO))
63521 return -EPERM;
63522 if (kcore_need_update)
63523 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
63524 index 136e548..1f88922 100644
63525 --- a/fs/proc/meminfo.c
63526 +++ b/fs/proc/meminfo.c
63527 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
63528 vmi.used >> 10,
63529 vmi.largest_chunk >> 10
63530 #ifdef CONFIG_MEMORY_FAILURE
63531 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63532 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63533 #endif
63534 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63535 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
63536 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
63537 index d4a3574..b421ce9 100644
63538 --- a/fs/proc/nommu.c
63539 +++ b/fs/proc/nommu.c
63540 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
63541
63542 if (file) {
63543 seq_pad(m, ' ');
63544 - seq_path(m, &file->f_path, "");
63545 + seq_path(m, &file->f_path, "\n\\");
63546 }
63547
63548 seq_putc(m, '\n');
63549 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
63550 index 4677bb7..408e936 100644
63551 --- a/fs/proc/proc_net.c
63552 +++ b/fs/proc/proc_net.c
63553 @@ -23,6 +23,7 @@
63554 #include <linux/nsproxy.h>
63555 #include <net/net_namespace.h>
63556 #include <linux/seq_file.h>
63557 +#include <linux/grsecurity.h>
63558
63559 #include "internal.h"
63560
63561 @@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
63562 struct task_struct *task;
63563 struct nsproxy *ns;
63564 struct net *net = NULL;
63565 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63566 + const struct cred *cred = current_cred();
63567 +#endif
63568 +
63569 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63570 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
63571 + return net;
63572 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63573 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
63574 + return net;
63575 +#endif
63576
63577 rcu_read_lock();
63578 task = pid_task(proc_pid(dir), PIDTYPE_PID);
63579 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
63580 index 7129046..6914844 100644
63581 --- a/fs/proc/proc_sysctl.c
63582 +++ b/fs/proc/proc_sysctl.c
63583 @@ -11,13 +11,21 @@
63584 #include <linux/namei.h>
63585 #include <linux/mm.h>
63586 #include <linux/module.h>
63587 +#include <linux/nsproxy.h>
63588 +#ifdef CONFIG_GRKERNSEC
63589 +#include <net/net_namespace.h>
63590 +#endif
63591 #include "internal.h"
63592
63593 +extern int gr_handle_chroot_sysctl(const int op);
63594 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
63595 + const int op);
63596 +
63597 static const struct dentry_operations proc_sys_dentry_operations;
63598 static const struct file_operations proc_sys_file_operations;
63599 -static const struct inode_operations proc_sys_inode_operations;
63600 +const struct inode_operations proc_sys_inode_operations;
63601 static const struct file_operations proc_sys_dir_file_operations;
63602 -static const struct inode_operations proc_sys_dir_operations;
63603 +const struct inode_operations proc_sys_dir_operations;
63604
63605 void proc_sys_poll_notify(struct ctl_table_poll *poll)
63606 {
63607 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
63608
63609 err = NULL;
63610 d_set_d_op(dentry, &proc_sys_dentry_operations);
63611 +
63612 + gr_handle_proc_create(dentry, inode);
63613 +
63614 d_add(dentry, inode);
63615
63616 out:
63617 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63618 struct inode *inode = file_inode(filp);
63619 struct ctl_table_header *head = grab_header(inode);
63620 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
63621 + int op = write ? MAY_WRITE : MAY_READ;
63622 ssize_t error;
63623 size_t res;
63624
63625 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63626 * and won't be until we finish.
63627 */
63628 error = -EPERM;
63629 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
63630 + if (sysctl_perm(head, table, op))
63631 goto out;
63632
63633 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
63634 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63635 if (!table->proc_handler)
63636 goto out;
63637
63638 +#ifdef CONFIG_GRKERNSEC
63639 + error = -EPERM;
63640 + if (gr_handle_chroot_sysctl(op))
63641 + goto out;
63642 + dget(filp->f_path.dentry);
63643 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
63644 + dput(filp->f_path.dentry);
63645 + goto out;
63646 + }
63647 + dput(filp->f_path.dentry);
63648 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
63649 + goto out;
63650 + if (write) {
63651 + if (current->nsproxy->net_ns != table->extra2) {
63652 + if (!capable(CAP_SYS_ADMIN))
63653 + goto out;
63654 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
63655 + goto out;
63656 + }
63657 +#endif
63658 +
63659 /* careful: calling conventions are nasty here */
63660 res = count;
63661 error = table->proc_handler(table, write, buf, &res, ppos);
63662 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
63663 return false;
63664 } else {
63665 d_set_d_op(child, &proc_sys_dentry_operations);
63666 +
63667 + gr_handle_proc_create(child, inode);
63668 +
63669 d_add(child, inode);
63670 }
63671 } else {
63672 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
63673 if ((*pos)++ < ctx->pos)
63674 return true;
63675
63676 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
63677 + return 0;
63678 +
63679 if (unlikely(S_ISLNK(table->mode)))
63680 res = proc_sys_link_fill_cache(file, ctx, head, table);
63681 else
63682 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
63683 if (IS_ERR(head))
63684 return PTR_ERR(head);
63685
63686 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
63687 + return -ENOENT;
63688 +
63689 generic_fillattr(inode, stat);
63690 if (table)
63691 stat->mode = (stat->mode & S_IFMT) | table->mode;
63692 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
63693 .llseek = generic_file_llseek,
63694 };
63695
63696 -static const struct inode_operations proc_sys_inode_operations = {
63697 +const struct inode_operations proc_sys_inode_operations = {
63698 .permission = proc_sys_permission,
63699 .setattr = proc_sys_setattr,
63700 .getattr = proc_sys_getattr,
63701 };
63702
63703 -static const struct inode_operations proc_sys_dir_operations = {
63704 +const struct inode_operations proc_sys_dir_operations = {
63705 .lookup = proc_sys_lookup,
63706 .permission = proc_sys_permission,
63707 .setattr = proc_sys_setattr,
63708 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
63709 static struct ctl_dir *new_dir(struct ctl_table_set *set,
63710 const char *name, int namelen)
63711 {
63712 - struct ctl_table *table;
63713 + ctl_table_no_const *table;
63714 struct ctl_dir *new;
63715 struct ctl_node *node;
63716 char *new_name;
63717 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
63718 return NULL;
63719
63720 node = (struct ctl_node *)(new + 1);
63721 - table = (struct ctl_table *)(node + 1);
63722 + table = (ctl_table_no_const *)(node + 1);
63723 new_name = (char *)(table + 2);
63724 memcpy(new_name, name, namelen);
63725 new_name[namelen] = '\0';
63726 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
63727 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
63728 struct ctl_table_root *link_root)
63729 {
63730 - struct ctl_table *link_table, *entry, *link;
63731 + ctl_table_no_const *link_table, *link;
63732 + struct ctl_table *entry;
63733 struct ctl_table_header *links;
63734 struct ctl_node *node;
63735 char *link_name;
63736 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
63737 return NULL;
63738
63739 node = (struct ctl_node *)(links + 1);
63740 - link_table = (struct ctl_table *)(node + nr_entries);
63741 + link_table = (ctl_table_no_const *)(node + nr_entries);
63742 link_name = (char *)&link_table[nr_entries + 1];
63743
63744 for (link = link_table, entry = table; entry->procname; link++, entry++) {
63745 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63746 struct ctl_table_header ***subheader, struct ctl_table_set *set,
63747 struct ctl_table *table)
63748 {
63749 - struct ctl_table *ctl_table_arg = NULL;
63750 - struct ctl_table *entry, *files;
63751 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
63752 + struct ctl_table *entry;
63753 int nr_files = 0;
63754 int nr_dirs = 0;
63755 int err = -ENOMEM;
63756 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63757 nr_files++;
63758 }
63759
63760 - files = table;
63761 /* If there are mixed files and directories we need a new table */
63762 if (nr_dirs && nr_files) {
63763 - struct ctl_table *new;
63764 + ctl_table_no_const *new;
63765 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
63766 GFP_KERNEL);
63767 if (!files)
63768 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63769 /* Register everything except a directory full of subdirectories */
63770 if (nr_files || !nr_dirs) {
63771 struct ctl_table_header *header;
63772 - header = __register_sysctl_table(set, path, files);
63773 + header = __register_sysctl_table(set, path, files ? files : table);
63774 if (!header) {
63775 kfree(ctl_table_arg);
63776 goto out;
63777 diff --git a/fs/proc/root.c b/fs/proc/root.c
63778 index 87dbcbe..55e1b4d 100644
63779 --- a/fs/proc/root.c
63780 +++ b/fs/proc/root.c
63781 @@ -186,7 +186,15 @@ void __init proc_root_init(void)
63782 #ifdef CONFIG_PROC_DEVICETREE
63783 proc_device_tree_init();
63784 #endif
63785 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63786 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63787 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
63788 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63789 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
63790 +#endif
63791 +#else
63792 proc_mkdir("bus", NULL);
63793 +#endif
63794 proc_sys_init();
63795 }
63796
63797 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
63798 index 6f599c6..8f4644f 100644
63799 --- a/fs/proc/stat.c
63800 +++ b/fs/proc/stat.c
63801 @@ -11,6 +11,7 @@
63802 #include <linux/irqnr.h>
63803 #include <asm/cputime.h>
63804 #include <linux/tick.h>
63805 +#include <linux/grsecurity.h>
63806
63807 #ifndef arch_irq_stat_cpu
63808 #define arch_irq_stat_cpu(cpu) 0
63809 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
63810 u64 sum_softirq = 0;
63811 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
63812 struct timespec boottime;
63813 + int unrestricted = 1;
63814 +
63815 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63816 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63817 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
63818 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63819 + && !in_group_p(grsec_proc_gid)
63820 +#endif
63821 + )
63822 + unrestricted = 0;
63823 +#endif
63824 +#endif
63825
63826 user = nice = system = idle = iowait =
63827 irq = softirq = steal = 0;
63828 @@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
63829 getboottime(&boottime);
63830 jif = boottime.tv_sec;
63831
63832 + if (unrestricted) {
63833 for_each_possible_cpu(i) {
63834 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
63835 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
63836 @@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
63837 }
63838 }
63839 sum += arch_irq_stat();
63840 + }
63841
63842 seq_puts(p, "cpu ");
63843 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
63844 @@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
63845 seq_putc(p, '\n');
63846
63847 for_each_online_cpu(i) {
63848 + if (unrestricted) {
63849 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
63850 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
63851 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
63852 @@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
63853 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
63854 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
63855 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
63856 + }
63857 seq_printf(p, "cpu%d", i);
63858 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
63859 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
63860 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
63861
63862 /* sum again ? it could be updated? */
63863 for_each_irq_nr(j)
63864 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
63865 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
63866
63867 seq_printf(p,
63868 "\nctxt %llu\n"
63869 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
63870 "processes %lu\n"
63871 "procs_running %lu\n"
63872 "procs_blocked %lu\n",
63873 - nr_context_switches(),
63874 + unrestricted ? nr_context_switches() : 0ULL,
63875 (unsigned long)jif,
63876 - total_forks,
63877 - nr_running(),
63878 - nr_iowait());
63879 + unrestricted ? total_forks : 0UL,
63880 + unrestricted ? nr_running() : 0UL,
63881 + unrestricted ? nr_iowait() : 0UL);
63882
63883 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
63884
63885 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
63886 index fb52b54..5fc7c14 100644
63887 --- a/fs/proc/task_mmu.c
63888 +++ b/fs/proc/task_mmu.c
63889 @@ -12,12 +12,19 @@
63890 #include <linux/swap.h>
63891 #include <linux/swapops.h>
63892 #include <linux/mmu_notifier.h>
63893 +#include <linux/grsecurity.h>
63894
63895 #include <asm/elf.h>
63896 #include <asm/uaccess.h>
63897 #include <asm/tlbflush.h>
63898 #include "internal.h"
63899
63900 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63901 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63902 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63903 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63904 +#endif
63905 +
63906 void task_mem(struct seq_file *m, struct mm_struct *mm)
63907 {
63908 unsigned long data, text, lib, swap;
63909 @@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63910 "VmExe:\t%8lu kB\n"
63911 "VmLib:\t%8lu kB\n"
63912 "VmPTE:\t%8lu kB\n"
63913 - "VmSwap:\t%8lu kB\n",
63914 - hiwater_vm << (PAGE_SHIFT-10),
63915 + "VmSwap:\t%8lu kB\n"
63916 +
63917 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63918 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
63919 +#endif
63920 +
63921 + ,hiwater_vm << (PAGE_SHIFT-10),
63922 total_vm << (PAGE_SHIFT-10),
63923 mm->locked_vm << (PAGE_SHIFT-10),
63924 mm->pinned_vm << (PAGE_SHIFT-10),
63925 @@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63926 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
63927 (PTRS_PER_PTE * sizeof(pte_t) *
63928 atomic_long_read(&mm->nr_ptes)) >> 10,
63929 - swap << (PAGE_SHIFT-10));
63930 + swap << (PAGE_SHIFT-10)
63931 +
63932 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63933 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63934 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
63935 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
63936 +#else
63937 + , mm->context.user_cs_base
63938 + , mm->context.user_cs_limit
63939 +#endif
63940 +#endif
63941 +
63942 + );
63943 }
63944
63945 unsigned long task_vsize(struct mm_struct *mm)
63946 @@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63947 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
63948 }
63949
63950 - /* We don't show the stack guard page in /proc/maps */
63951 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63952 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
63953 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
63954 +#else
63955 start = vma->vm_start;
63956 - if (stack_guard_page_start(vma, start))
63957 - start += PAGE_SIZE;
63958 end = vma->vm_end;
63959 - if (stack_guard_page_end(vma, end))
63960 - end -= PAGE_SIZE;
63961 +#endif
63962
63963 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
63964 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
63965 @@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63966 flags & VM_WRITE ? 'w' : '-',
63967 flags & VM_EXEC ? 'x' : '-',
63968 flags & VM_MAYSHARE ? 's' : 'p',
63969 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63970 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
63971 +#else
63972 pgoff,
63973 +#endif
63974 MAJOR(dev), MINOR(dev), ino);
63975
63976 /*
63977 @@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63978 */
63979 if (file) {
63980 seq_pad(m, ' ');
63981 - seq_path(m, &file->f_path, "\n");
63982 + seq_path(m, &file->f_path, "\n\\");
63983 goto done;
63984 }
63985
63986 @@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63987 * Thread stack in /proc/PID/task/TID/maps or
63988 * the main process stack.
63989 */
63990 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
63991 - vma->vm_end >= mm->start_stack)) {
63992 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
63993 + (vma->vm_start <= mm->start_stack &&
63994 + vma->vm_end >= mm->start_stack)) {
63995 name = "[stack]";
63996 } else {
63997 /* Thread stack in /proc/PID/maps */
63998 @@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
63999 struct proc_maps_private *priv = m->private;
64000 struct task_struct *task = priv->task;
64001
64002 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64003 + if (current->exec_id != m->exec_id) {
64004 + gr_log_badprocpid("maps");
64005 + return 0;
64006 + }
64007 +#endif
64008 +
64009 show_map_vma(m, vma, is_pid);
64010
64011 if (m->count < m->size) /* vma is copied successfully */
64012 @@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64013 .private = &mss,
64014 };
64015
64016 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64017 + if (current->exec_id != m->exec_id) {
64018 + gr_log_badprocpid("smaps");
64019 + return 0;
64020 + }
64021 +#endif
64022 memset(&mss, 0, sizeof mss);
64023 - mss.vma = vma;
64024 - /* mmap_sem is held in m_start */
64025 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64026 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64027 -
64028 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64029 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64030 +#endif
64031 + mss.vma = vma;
64032 + /* mmap_sem is held in m_start */
64033 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64034 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64035 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64036 + }
64037 +#endif
64038 show_map_vma(m, vma, is_pid);
64039
64040 seq_printf(m,
64041 @@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64042 "KernelPageSize: %8lu kB\n"
64043 "MMUPageSize: %8lu kB\n"
64044 "Locked: %8lu kB\n",
64045 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64046 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64047 +#else
64048 (vma->vm_end - vma->vm_start) >> 10,
64049 +#endif
64050 mss.resident >> 10,
64051 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64052 mss.shared_clean >> 10,
64053 @@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64054 char buffer[64];
64055 int nid;
64056
64057 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64058 + if (current->exec_id != m->exec_id) {
64059 + gr_log_badprocpid("numa_maps");
64060 + return 0;
64061 + }
64062 +#endif
64063 +
64064 if (!mm)
64065 return 0;
64066
64067 @@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64068 mpol_to_str(buffer, sizeof(buffer), pol);
64069 mpol_cond_put(pol);
64070
64071 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64072 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64073 +#else
64074 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64075 +#endif
64076
64077 if (file) {
64078 seq_printf(m, " file=");
64079 - seq_path(m, &file->f_path, "\n\t= ");
64080 + seq_path(m, &file->f_path, "\n\t\\= ");
64081 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64082 seq_printf(m, " heap");
64083 } else {
64084 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64085 index 678455d..ebd3245 100644
64086 --- a/fs/proc/task_nommu.c
64087 +++ b/fs/proc/task_nommu.c
64088 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64089 else
64090 bytes += kobjsize(mm);
64091
64092 - if (current->fs && current->fs->users > 1)
64093 + if (current->fs && atomic_read(&current->fs->users) > 1)
64094 sbytes += kobjsize(current->fs);
64095 else
64096 bytes += kobjsize(current->fs);
64097 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64098
64099 if (file) {
64100 seq_pad(m, ' ');
64101 - seq_path(m, &file->f_path, "");
64102 + seq_path(m, &file->f_path, "\n\\");
64103 } else if (mm) {
64104 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64105
64106 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64107 index 88d4585..c10bfeb 100644
64108 --- a/fs/proc/vmcore.c
64109 +++ b/fs/proc/vmcore.c
64110 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64111 nr_bytes = count;
64112
64113 /* If pfn is not ram, return zeros for sparse dump files */
64114 - if (pfn_is_ram(pfn) == 0)
64115 - memset(buf, 0, nr_bytes);
64116 - else {
64117 + if (pfn_is_ram(pfn) == 0) {
64118 + if (userbuf) {
64119 + if (clear_user((char __force_user *)buf, nr_bytes))
64120 + return -EFAULT;
64121 + } else
64122 + memset(buf, 0, nr_bytes);
64123 + } else {
64124 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64125 offset, userbuf);
64126 if (tmp < 0)
64127 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64128 static int copy_to(void *target, void *src, size_t size, int userbuf)
64129 {
64130 if (userbuf) {
64131 - if (copy_to_user((char __user *) target, src, size))
64132 + if (copy_to_user((char __force_user *) target, src, size))
64133 return -EFAULT;
64134 } else {
64135 memcpy(target, src, size);
64136 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64137 if (*fpos < m->offset + m->size) {
64138 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64139 start = m->paddr + *fpos - m->offset;
64140 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64141 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64142 if (tmp < 0)
64143 return tmp;
64144 buflen -= tsz;
64145 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64146 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64147 size_t buflen, loff_t *fpos)
64148 {
64149 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64150 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64151 }
64152
64153 /*
64154 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64155 index b00fcc9..e0c6381 100644
64156 --- a/fs/qnx6/qnx6.h
64157 +++ b/fs/qnx6/qnx6.h
64158 @@ -74,7 +74,7 @@ enum {
64159 BYTESEX_BE,
64160 };
64161
64162 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64163 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64164 {
64165 if (sbi->s_bytesex == BYTESEX_LE)
64166 return le64_to_cpu((__force __le64)n);
64167 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64168 return (__force __fs64)cpu_to_be64(n);
64169 }
64170
64171 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64172 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64173 {
64174 if (sbi->s_bytesex == BYTESEX_LE)
64175 return le32_to_cpu((__force __le32)n);
64176 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
64177 index 72d2917..c917c12 100644
64178 --- a/fs/quota/netlink.c
64179 +++ b/fs/quota/netlink.c
64180 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
64181 void quota_send_warning(struct kqid qid, dev_t dev,
64182 const char warntype)
64183 {
64184 - static atomic_t seq;
64185 + static atomic_unchecked_t seq;
64186 struct sk_buff *skb;
64187 void *msg_head;
64188 int ret;
64189 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64190 "VFS: Not enough memory to send quota warning.\n");
64191 return;
64192 }
64193 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64194 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64195 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64196 if (!msg_head) {
64197 printk(KERN_ERR
64198 diff --git a/fs/read_write.c b/fs/read_write.c
64199 index 28cc9c8..208e4fb 100644
64200 --- a/fs/read_write.c
64201 +++ b/fs/read_write.c
64202 @@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64203
64204 old_fs = get_fs();
64205 set_fs(get_ds());
64206 - p = (__force const char __user *)buf;
64207 + p = (const char __force_user *)buf;
64208 if (count > MAX_RW_COUNT)
64209 count = MAX_RW_COUNT;
64210 if (file->f_op->write)
64211 diff --git a/fs/readdir.c b/fs/readdir.c
64212 index 5b53d99..a6c3049 100644
64213 --- a/fs/readdir.c
64214 +++ b/fs/readdir.c
64215 @@ -17,6 +17,7 @@
64216 #include <linux/security.h>
64217 #include <linux/syscalls.h>
64218 #include <linux/unistd.h>
64219 +#include <linux/namei.h>
64220
64221 #include <asm/uaccess.h>
64222
64223 @@ -69,6 +70,7 @@ struct old_linux_dirent {
64224 struct readdir_callback {
64225 struct dir_context ctx;
64226 struct old_linux_dirent __user * dirent;
64227 + struct file * file;
64228 int result;
64229 };
64230
64231 @@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64232 buf->result = -EOVERFLOW;
64233 return -EOVERFLOW;
64234 }
64235 +
64236 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64237 + return 0;
64238 +
64239 buf->result++;
64240 dirent = buf->dirent;
64241 if (!access_ok(VERIFY_WRITE, dirent,
64242 @@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64243 if (!f.file)
64244 return -EBADF;
64245
64246 + buf.file = f.file;
64247 error = iterate_dir(f.file, &buf.ctx);
64248 if (buf.result)
64249 error = buf.result;
64250 @@ -142,6 +149,7 @@ struct getdents_callback {
64251 struct dir_context ctx;
64252 struct linux_dirent __user * current_dir;
64253 struct linux_dirent __user * previous;
64254 + struct file * file;
64255 int count;
64256 int error;
64257 };
64258 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64259 buf->error = -EOVERFLOW;
64260 return -EOVERFLOW;
64261 }
64262 +
64263 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64264 + return 0;
64265 +
64266 dirent = buf->previous;
64267 if (dirent) {
64268 if (__put_user(offset, &dirent->d_off))
64269 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64270 if (!f.file)
64271 return -EBADF;
64272
64273 + buf.file = f.file;
64274 error = iterate_dir(f.file, &buf.ctx);
64275 if (error >= 0)
64276 error = buf.error;
64277 @@ -226,6 +239,7 @@ struct getdents_callback64 {
64278 struct dir_context ctx;
64279 struct linux_dirent64 __user * current_dir;
64280 struct linux_dirent64 __user * previous;
64281 + struct file *file;
64282 int count;
64283 int error;
64284 };
64285 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64286 buf->error = -EINVAL; /* only used if we fail.. */
64287 if (reclen > buf->count)
64288 return -EINVAL;
64289 +
64290 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64291 + return 0;
64292 +
64293 dirent = buf->previous;
64294 if (dirent) {
64295 if (__put_user(offset, &dirent->d_off))
64296 @@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64297 if (!f.file)
64298 return -EBADF;
64299
64300 + buf.file = f.file;
64301 error = iterate_dir(f.file, &buf.ctx);
64302 if (error >= 0)
64303 error = buf.error;
64304 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64305 index 9a3c68c..767933e 100644
64306 --- a/fs/reiserfs/do_balan.c
64307 +++ b/fs/reiserfs/do_balan.c
64308 @@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64309 return;
64310 }
64311
64312 - atomic_inc(&(fs_generation(tb->tb_sb)));
64313 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64314 do_balance_starts(tb);
64315
64316 /* balance leaf returns 0 except if combining L R and S into
64317 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64318 index ee382ef..f4eb6eb5 100644
64319 --- a/fs/reiserfs/item_ops.c
64320 +++ b/fs/reiserfs/item_ops.c
64321 @@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64322 }
64323
64324 static struct item_operations errcatch_ops = {
64325 - errcatch_bytes_number,
64326 - errcatch_decrement_key,
64327 - errcatch_is_left_mergeable,
64328 - errcatch_print_item,
64329 - errcatch_check_item,
64330 + .bytes_number = errcatch_bytes_number,
64331 + .decrement_key = errcatch_decrement_key,
64332 + .is_left_mergeable = errcatch_is_left_mergeable,
64333 + .print_item = errcatch_print_item,
64334 + .check_item = errcatch_check_item,
64335
64336 - errcatch_create_vi,
64337 - errcatch_check_left,
64338 - errcatch_check_right,
64339 - errcatch_part_size,
64340 - errcatch_unit_num,
64341 - errcatch_print_vi
64342 + .create_vi = errcatch_create_vi,
64343 + .check_left = errcatch_check_left,
64344 + .check_right = errcatch_check_right,
64345 + .part_size = errcatch_part_size,
64346 + .unit_num = errcatch_unit_num,
64347 + .print_vi = errcatch_print_vi
64348 };
64349
64350 //////////////////////////////////////////////////////////////////////////////
64351 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
64352 index 02b0b7d..c85018b 100644
64353 --- a/fs/reiserfs/procfs.c
64354 +++ b/fs/reiserfs/procfs.c
64355 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
64356 "SMALL_TAILS " : "NO_TAILS ",
64357 replay_only(sb) ? "REPLAY_ONLY " : "",
64358 convert_reiserfs(sb) ? "CONV " : "",
64359 - atomic_read(&r->s_generation_counter),
64360 + atomic_read_unchecked(&r->s_generation_counter),
64361 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
64362 SF(s_do_balance), SF(s_unneeded_left_neighbor),
64363 SF(s_good_search_by_key_reada), SF(s_bmaps),
64364 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
64365 index 8d06adf..7e1c9f8 100644
64366 --- a/fs/reiserfs/reiserfs.h
64367 +++ b/fs/reiserfs/reiserfs.h
64368 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
64369 /* Comment? -Hans */
64370 wait_queue_head_t s_wait;
64371 /* To be obsoleted soon by per buffer seals.. -Hans */
64372 - atomic_t s_generation_counter; // increased by one every time the
64373 + atomic_unchecked_t s_generation_counter; // increased by one every time the
64374 // tree gets re-balanced
64375 unsigned long s_properties; /* File system properties. Currently holds
64376 on-disk FS format */
64377 @@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64378 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64379
64380 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64381 -#define get_generation(s) atomic_read (&fs_generation(s))
64382 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64383 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64384 #define __fs_changed(gen,s) (gen != get_generation (s))
64385 #define fs_changed(gen,s) \
64386 diff --git a/fs/select.c b/fs/select.c
64387 index 467bb1c..cf9d65a 100644
64388 --- a/fs/select.c
64389 +++ b/fs/select.c
64390 @@ -20,6 +20,7 @@
64391 #include <linux/export.h>
64392 #include <linux/slab.h>
64393 #include <linux/poll.h>
64394 +#include <linux/security.h>
64395 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
64396 #include <linux/file.h>
64397 #include <linux/fdtable.h>
64398 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
64399 struct poll_list *walk = head;
64400 unsigned long todo = nfds;
64401
64402 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
64403 if (nfds > rlimit(RLIMIT_NOFILE))
64404 return -EINVAL;
64405
64406 diff --git a/fs/seq_file.c b/fs/seq_file.c
64407 index 1d641bb..e600623 100644
64408 --- a/fs/seq_file.c
64409 +++ b/fs/seq_file.c
64410 @@ -10,6 +10,7 @@
64411 #include <linux/seq_file.h>
64412 #include <linux/slab.h>
64413 #include <linux/cred.h>
64414 +#include <linux/sched.h>
64415
64416 #include <asm/uaccess.h>
64417 #include <asm/page.h>
64418 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
64419 #ifdef CONFIG_USER_NS
64420 p->user_ns = file->f_cred->user_ns;
64421 #endif
64422 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64423 + p->exec_id = current->exec_id;
64424 +#endif
64425
64426 /*
64427 * Wrappers around seq_open(e.g. swaps_open) need to be
64428 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
64429 return 0;
64430 }
64431 if (!m->buf) {
64432 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64433 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64434 if (!m->buf)
64435 return -ENOMEM;
64436 }
64437 @@ -137,7 +141,7 @@ Eoverflow:
64438 m->op->stop(m, p);
64439 kfree(m->buf);
64440 m->count = 0;
64441 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64442 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64443 return !m->buf ? -ENOMEM : -EAGAIN;
64444 }
64445
64446 @@ -153,7 +157,7 @@ Eoverflow:
64447 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64448 {
64449 struct seq_file *m = file->private_data;
64450 - size_t copied = 0;
64451 + ssize_t copied = 0;
64452 loff_t pos;
64453 size_t n;
64454 void *p;
64455 @@ -192,7 +196,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64456
64457 /* grab buffer if we didn't have one */
64458 if (!m->buf) {
64459 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64460 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64461 if (!m->buf)
64462 goto Enomem;
64463 }
64464 @@ -234,7 +238,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64465 m->op->stop(m, p);
64466 kfree(m->buf);
64467 m->count = 0;
64468 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64469 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64470 if (!m->buf)
64471 goto Enomem;
64472 m->version = 0;
64473 @@ -584,7 +588,7 @@ static void single_stop(struct seq_file *p, void *v)
64474 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
64475 void *data)
64476 {
64477 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
64478 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
64479 int res = -ENOMEM;
64480
64481 if (op) {
64482 diff --git a/fs/splice.c b/fs/splice.c
64483 index 12028fa..a6f2619 100644
64484 --- a/fs/splice.c
64485 +++ b/fs/splice.c
64486 @@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64487 pipe_lock(pipe);
64488
64489 for (;;) {
64490 - if (!pipe->readers) {
64491 + if (!atomic_read(&pipe->readers)) {
64492 send_sig(SIGPIPE, current, 0);
64493 if (!ret)
64494 ret = -EPIPE;
64495 @@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64496 page_nr++;
64497 ret += buf->len;
64498
64499 - if (pipe->files)
64500 + if (atomic_read(&pipe->files))
64501 do_wakeup = 1;
64502
64503 if (!--spd->nr_pages)
64504 @@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64505 do_wakeup = 0;
64506 }
64507
64508 - pipe->waiting_writers++;
64509 + atomic_inc(&pipe->waiting_writers);
64510 pipe_wait(pipe);
64511 - pipe->waiting_writers--;
64512 + atomic_dec(&pipe->waiting_writers);
64513 }
64514
64515 pipe_unlock(pipe);
64516 @@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
64517 old_fs = get_fs();
64518 set_fs(get_ds());
64519 /* The cast to a user pointer is valid due to the set_fs() */
64520 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
64521 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
64522 set_fs(old_fs);
64523
64524 return res;
64525 @@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
64526 old_fs = get_fs();
64527 set_fs(get_ds());
64528 /* The cast to a user pointer is valid due to the set_fs() */
64529 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
64530 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
64531 set_fs(old_fs);
64532
64533 return res;
64534 @@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
64535 goto err;
64536
64537 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
64538 - vec[i].iov_base = (void __user *) page_address(page);
64539 + vec[i].iov_base = (void __force_user *) page_address(page);
64540 vec[i].iov_len = this_len;
64541 spd.pages[i] = page;
64542 spd.nr_pages++;
64543 @@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
64544 ops->release(pipe, buf);
64545 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
64546 pipe->nrbufs--;
64547 - if (pipe->files)
64548 + if (atomic_read(&pipe->files))
64549 sd->need_wakeup = true;
64550 }
64551
64552 @@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
64553 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
64554 {
64555 while (!pipe->nrbufs) {
64556 - if (!pipe->writers)
64557 + if (!atomic_read(&pipe->writers))
64558 return 0;
64559
64560 - if (!pipe->waiting_writers && sd->num_spliced)
64561 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
64562 return 0;
64563
64564 if (sd->flags & SPLICE_F_NONBLOCK)
64565 @@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
64566 * out of the pipe right after the splice_to_pipe(). So set
64567 * PIPE_READERS appropriately.
64568 */
64569 - pipe->readers = 1;
64570 + atomic_set(&pipe->readers, 1);
64571
64572 current->splice_pipe = pipe;
64573 }
64574 @@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
64575
64576 partial[buffers].offset = off;
64577 partial[buffers].len = plen;
64578 + partial[buffers].private = 0;
64579
64580 off = 0;
64581 len -= plen;
64582 @@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64583 ret = -ERESTARTSYS;
64584 break;
64585 }
64586 - if (!pipe->writers)
64587 + if (!atomic_read(&pipe->writers))
64588 break;
64589 - if (!pipe->waiting_writers) {
64590 + if (!atomic_read(&pipe->waiting_writers)) {
64591 if (flags & SPLICE_F_NONBLOCK) {
64592 ret = -EAGAIN;
64593 break;
64594 @@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64595 pipe_lock(pipe);
64596
64597 while (pipe->nrbufs >= pipe->buffers) {
64598 - if (!pipe->readers) {
64599 + if (!atomic_read(&pipe->readers)) {
64600 send_sig(SIGPIPE, current, 0);
64601 ret = -EPIPE;
64602 break;
64603 @@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64604 ret = -ERESTARTSYS;
64605 break;
64606 }
64607 - pipe->waiting_writers++;
64608 + atomic_inc(&pipe->waiting_writers);
64609 pipe_wait(pipe);
64610 - pipe->waiting_writers--;
64611 + atomic_dec(&pipe->waiting_writers);
64612 }
64613
64614 pipe_unlock(pipe);
64615 @@ -1880,14 +1881,14 @@ retry:
64616 pipe_double_lock(ipipe, opipe);
64617
64618 do {
64619 - if (!opipe->readers) {
64620 + if (!atomic_read(&opipe->readers)) {
64621 send_sig(SIGPIPE, current, 0);
64622 if (!ret)
64623 ret = -EPIPE;
64624 break;
64625 }
64626
64627 - if (!ipipe->nrbufs && !ipipe->writers)
64628 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
64629 break;
64630
64631 /*
64632 @@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64633 pipe_double_lock(ipipe, opipe);
64634
64635 do {
64636 - if (!opipe->readers) {
64637 + if (!atomic_read(&opipe->readers)) {
64638 send_sig(SIGPIPE, current, 0);
64639 if (!ret)
64640 ret = -EPIPE;
64641 @@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64642 * return EAGAIN if we have the potential of some data in the
64643 * future, otherwise just return 0
64644 */
64645 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
64646 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
64647 ret = -EAGAIN;
64648
64649 pipe_unlock(ipipe);
64650 diff --git a/fs/stat.c b/fs/stat.c
64651 index ae0c3ce..9ee641c 100644
64652 --- a/fs/stat.c
64653 +++ b/fs/stat.c
64654 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
64655 stat->gid = inode->i_gid;
64656 stat->rdev = inode->i_rdev;
64657 stat->size = i_size_read(inode);
64658 - stat->atime = inode->i_atime;
64659 - stat->mtime = inode->i_mtime;
64660 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64661 + stat->atime = inode->i_ctime;
64662 + stat->mtime = inode->i_ctime;
64663 + } else {
64664 + stat->atime = inode->i_atime;
64665 + stat->mtime = inode->i_mtime;
64666 + }
64667 stat->ctime = inode->i_ctime;
64668 stat->blksize = (1 << inode->i_blkbits);
64669 stat->blocks = inode->i_blocks;
64670 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
64671 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
64672 {
64673 struct inode *inode = path->dentry->d_inode;
64674 + int retval;
64675
64676 - if (inode->i_op->getattr)
64677 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
64678 + if (inode->i_op->getattr) {
64679 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
64680 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64681 + stat->atime = stat->ctime;
64682 + stat->mtime = stat->ctime;
64683 + }
64684 + return retval;
64685 + }
64686
64687 generic_fillattr(inode, stat);
64688 return 0;
64689 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
64690 index ee0d761..b346c58 100644
64691 --- a/fs/sysfs/dir.c
64692 +++ b/fs/sysfs/dir.c
64693 @@ -62,9 +62,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
64694 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
64695 {
64696 struct kernfs_node *parent, *kn;
64697 + const char *name;
64698 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
64699 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
64700 + const char *parent_name;
64701 +#endif
64702
64703 BUG_ON(!kobj);
64704
64705 + name = kobject_name(kobj);
64706 +
64707 if (kobj->parent)
64708 parent = kobj->parent->sd;
64709 else
64710 @@ -73,11 +80,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
64711 if (!parent)
64712 return -ENOENT;
64713
64714 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
64715 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
64716 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
64717 + parent_name = parent->name;
64718 + mode = S_IRWXU;
64719 +
64720 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
64721 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
64722 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
64723 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
64724 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
64725 +#endif
64726 +
64727 + kn = kernfs_create_dir_ns(parent, name,
64728 + mode, kobj, ns);
64729 if (IS_ERR(kn)) {
64730 if (PTR_ERR(kn) == -EEXIST)
64731 - sysfs_warn_dup(parent, kobject_name(kobj));
64732 + sysfs_warn_dup(parent, name);
64733 return PTR_ERR(kn);
64734 }
64735
64736 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
64737 index 69d4889..a810bd4 100644
64738 --- a/fs/sysv/sysv.h
64739 +++ b/fs/sysv/sysv.h
64740 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
64741 #endif
64742 }
64743
64744 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64745 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64746 {
64747 if (sbi->s_bytesex == BYTESEX_PDP)
64748 return PDP_swab((__force __u32)n);
64749 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
64750 index e18b988..f1d4ad0f 100644
64751 --- a/fs/ubifs/io.c
64752 +++ b/fs/ubifs/io.c
64753 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
64754 return err;
64755 }
64756
64757 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64758 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64759 {
64760 int err;
64761
64762 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
64763 index c175b4d..8f36a16 100644
64764 --- a/fs/udf/misc.c
64765 +++ b/fs/udf/misc.c
64766 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
64767
64768 u8 udf_tag_checksum(const struct tag *t)
64769 {
64770 - u8 *data = (u8 *)t;
64771 + const u8 *data = (const u8 *)t;
64772 u8 checksum = 0;
64773 int i;
64774 for (i = 0; i < sizeof(struct tag); ++i)
64775 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
64776 index 8d974c4..b82f6ec 100644
64777 --- a/fs/ufs/swab.h
64778 +++ b/fs/ufs/swab.h
64779 @@ -22,7 +22,7 @@ enum {
64780 BYTESEX_BE
64781 };
64782
64783 -static inline u64
64784 +static inline u64 __intentional_overflow(-1)
64785 fs64_to_cpu(struct super_block *sbp, __fs64 n)
64786 {
64787 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64788 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
64789 return (__force __fs64)cpu_to_be64(n);
64790 }
64791
64792 -static inline u32
64793 +static inline u32 __intentional_overflow(-1)
64794 fs32_to_cpu(struct super_block *sbp, __fs32 n)
64795 {
64796 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64797 diff --git a/fs/utimes.c b/fs/utimes.c
64798 index aa138d6..5f3a811 100644
64799 --- a/fs/utimes.c
64800 +++ b/fs/utimes.c
64801 @@ -1,6 +1,7 @@
64802 #include <linux/compiler.h>
64803 #include <linux/file.h>
64804 #include <linux/fs.h>
64805 +#include <linux/security.h>
64806 #include <linux/linkage.h>
64807 #include <linux/mount.h>
64808 #include <linux/namei.h>
64809 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
64810 }
64811 }
64812 retry_deleg:
64813 +
64814 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
64815 + error = -EACCES;
64816 + goto mnt_drop_write_and_out;
64817 + }
64818 +
64819 mutex_lock(&inode->i_mutex);
64820 error = notify_change(path->dentry, &newattrs, &delegated_inode);
64821 mutex_unlock(&inode->i_mutex);
64822 diff --git a/fs/xattr.c b/fs/xattr.c
64823 index 3377dff..f394815 100644
64824 --- a/fs/xattr.c
64825 +++ b/fs/xattr.c
64826 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
64827 return rc;
64828 }
64829
64830 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
64831 +ssize_t
64832 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
64833 +{
64834 + struct inode *inode = dentry->d_inode;
64835 + ssize_t error;
64836 +
64837 + error = inode_permission(inode, MAY_EXEC);
64838 + if (error)
64839 + return error;
64840 +
64841 + if (inode->i_op->getxattr)
64842 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
64843 + else
64844 + error = -EOPNOTSUPP;
64845 +
64846 + return error;
64847 +}
64848 +EXPORT_SYMBOL(pax_getxattr);
64849 +#endif
64850 +
64851 ssize_t
64852 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
64853 {
64854 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
64855 * Extended attribute SET operations
64856 */
64857 static long
64858 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
64859 +setxattr(struct path *path, const char __user *name, const void __user *value,
64860 size_t size, int flags)
64861 {
64862 int error;
64863 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
64864 posix_acl_fix_xattr_from_user(kvalue, size);
64865 }
64866
64867 - error = vfs_setxattr(d, kname, kvalue, size, flags);
64868 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
64869 + error = -EACCES;
64870 + goto out;
64871 + }
64872 +
64873 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
64874 out:
64875 if (vvalue)
64876 vfree(vvalue);
64877 @@ -377,7 +403,7 @@ retry:
64878 return error;
64879 error = mnt_want_write(path.mnt);
64880 if (!error) {
64881 - error = setxattr(path.dentry, name, value, size, flags);
64882 + error = setxattr(&path, name, value, size, flags);
64883 mnt_drop_write(path.mnt);
64884 }
64885 path_put(&path);
64886 @@ -401,7 +427,7 @@ retry:
64887 return error;
64888 error = mnt_want_write(path.mnt);
64889 if (!error) {
64890 - error = setxattr(path.dentry, name, value, size, flags);
64891 + error = setxattr(&path, name, value, size, flags);
64892 mnt_drop_write(path.mnt);
64893 }
64894 path_put(&path);
64895 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
64896 const void __user *,value, size_t, size, int, flags)
64897 {
64898 struct fd f = fdget(fd);
64899 - struct dentry *dentry;
64900 int error = -EBADF;
64901
64902 if (!f.file)
64903 return error;
64904 - dentry = f.file->f_path.dentry;
64905 - audit_inode(NULL, dentry, 0);
64906 + audit_inode(NULL, f.file->f_path.dentry, 0);
64907 error = mnt_want_write_file(f.file);
64908 if (!error) {
64909 - error = setxattr(dentry, name, value, size, flags);
64910 + error = setxattr(&f.file->f_path, name, value, size, flags);
64911 mnt_drop_write_file(f.file);
64912 }
64913 fdput(f);
64914 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
64915 * Extended attribute REMOVE operations
64916 */
64917 static long
64918 -removexattr(struct dentry *d, const char __user *name)
64919 +removexattr(struct path *path, const char __user *name)
64920 {
64921 int error;
64922 char kname[XATTR_NAME_MAX + 1];
64923 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
64924 if (error < 0)
64925 return error;
64926
64927 - return vfs_removexattr(d, kname);
64928 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
64929 + return -EACCES;
64930 +
64931 + return vfs_removexattr(path->dentry, kname);
64932 }
64933
64934 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
64935 @@ -652,7 +679,7 @@ retry:
64936 return error;
64937 error = mnt_want_write(path.mnt);
64938 if (!error) {
64939 - error = removexattr(path.dentry, name);
64940 + error = removexattr(&path, name);
64941 mnt_drop_write(path.mnt);
64942 }
64943 path_put(&path);
64944 @@ -675,7 +702,7 @@ retry:
64945 return error;
64946 error = mnt_want_write(path.mnt);
64947 if (!error) {
64948 - error = removexattr(path.dentry, name);
64949 + error = removexattr(&path, name);
64950 mnt_drop_write(path.mnt);
64951 }
64952 path_put(&path);
64953 @@ -689,16 +716,16 @@ retry:
64954 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
64955 {
64956 struct fd f = fdget(fd);
64957 - struct dentry *dentry;
64958 + struct path *path;
64959 int error = -EBADF;
64960
64961 if (!f.file)
64962 return error;
64963 - dentry = f.file->f_path.dentry;
64964 - audit_inode(NULL, dentry, 0);
64965 + path = &f.file->f_path;
64966 + audit_inode(NULL, path->dentry, 0);
64967 error = mnt_want_write_file(f.file);
64968 if (!error) {
64969 - error = removexattr(dentry, name);
64970 + error = removexattr(path, name);
64971 mnt_drop_write_file(f.file);
64972 }
64973 fdput(f);
64974 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
64975 index 152543c..d80c361 100644
64976 --- a/fs/xfs/xfs_bmap.c
64977 +++ b/fs/xfs/xfs_bmap.c
64978 @@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
64979
64980 #else
64981 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
64982 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
64983 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
64984 #endif /* DEBUG */
64985
64986 /*
64987 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
64988 index aead369..0dfecfd 100644
64989 --- a/fs/xfs/xfs_dir2_readdir.c
64990 +++ b/fs/xfs/xfs_dir2_readdir.c
64991 @@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
64992 ino = dp->d_ops->sf_get_ino(sfp, sfep);
64993 filetype = dp->d_ops->sf_get_ftype(sfep);
64994 ctx->pos = off & 0x7fffffff;
64995 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
64996 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
64997 + char name[sfep->namelen];
64998 + memcpy(name, sfep->name, sfep->namelen);
64999 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65000 + return 0;
65001 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65002 xfs_dir3_get_dtype(mp, filetype)))
65003 return 0;
65004 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65005 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65006 index bcfe612..aa399c0 100644
65007 --- a/fs/xfs/xfs_ioctl.c
65008 +++ b/fs/xfs/xfs_ioctl.c
65009 @@ -122,7 +122,7 @@ xfs_find_handle(
65010 }
65011
65012 error = -EFAULT;
65013 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65014 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65015 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65016 goto out_put;
65017
65018 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65019 new file mode 100644
65020 index 0000000..3abaf02
65021 --- /dev/null
65022 +++ b/grsecurity/Kconfig
65023 @@ -0,0 +1,1161 @@
65024 +#
65025 +# grecurity configuration
65026 +#
65027 +menu "Memory Protections"
65028 +depends on GRKERNSEC
65029 +
65030 +config GRKERNSEC_KMEM
65031 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65032 + default y if GRKERNSEC_CONFIG_AUTO
65033 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65034 + help
65035 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65036 + be written to or read from to modify or leak the contents of the running
65037 + kernel. /dev/port will also not be allowed to be opened, writing to
65038 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65039 + If you have module support disabled, enabling this will close up several
65040 + ways that are currently used to insert malicious code into the running
65041 + kernel.
65042 +
65043 + Even with this feature enabled, we still highly recommend that
65044 + you use the RBAC system, as it is still possible for an attacker to
65045 + modify the running kernel through other more obscure methods.
65046 +
65047 + It is highly recommended that you say Y here if you meet all the
65048 + conditions above.
65049 +
65050 +config GRKERNSEC_VM86
65051 + bool "Restrict VM86 mode"
65052 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65053 + depends on X86_32
65054 +
65055 + help
65056 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65057 + make use of a special execution mode on 32bit x86 processors called
65058 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65059 + video cards and will still work with this option enabled. The purpose
65060 + of the option is to prevent exploitation of emulation errors in
65061 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
65062 + Nearly all users should be able to enable this option.
65063 +
65064 +config GRKERNSEC_IO
65065 + bool "Disable privileged I/O"
65066 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65067 + depends on X86
65068 + select RTC_CLASS
65069 + select RTC_INTF_DEV
65070 + select RTC_DRV_CMOS
65071 +
65072 + help
65073 + If you say Y here, all ioperm and iopl calls will return an error.
65074 + Ioperm and iopl can be used to modify the running kernel.
65075 + Unfortunately, some programs need this access to operate properly,
65076 + the most notable of which are XFree86 and hwclock. hwclock can be
65077 + remedied by having RTC support in the kernel, so real-time
65078 + clock support is enabled if this option is enabled, to ensure
65079 + that hwclock operates correctly. If hwclock still does not work,
65080 + either update udev or symlink /dev/rtc to /dev/rtc0.
65081 +
65082 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
65083 + you may not be able to boot into a graphical environment with this
65084 + option enabled. In this case, you should use the RBAC system instead.
65085 +
65086 +config GRKERNSEC_JIT_HARDEN
65087 + bool "Harden BPF JIT against spray attacks"
65088 + default y if GRKERNSEC_CONFIG_AUTO
65089 + depends on BPF_JIT && X86
65090 + help
65091 + If you say Y here, the native code generated by the kernel's Berkeley
65092 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65093 + attacks that attempt to fit attacker-beneficial instructions in
65094 + 32bit immediate fields of JIT-generated native instructions. The
65095 + attacker will generally aim to cause an unintended instruction sequence
65096 + of JIT-generated native code to execute by jumping into the middle of
65097 + a generated instruction. This feature effectively randomizes the 32bit
65098 + immediate constants present in the generated code to thwart such attacks.
65099 +
65100 + If you're using KERNEXEC, it's recommended that you enable this option
65101 + to supplement the hardening of the kernel.
65102 +
65103 +config GRKERNSEC_PERF_HARDEN
65104 + bool "Disable unprivileged PERF_EVENTS usage by default"
65105 + default y if GRKERNSEC_CONFIG_AUTO
65106 + depends on PERF_EVENTS
65107 + help
65108 + If you say Y here, the range of acceptable values for the
65109 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65110 + default to a new value: 3. When the sysctl is set to this value, no
65111 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65112 +
65113 + Though PERF_EVENTS can be used legitimately for performance monitoring
65114 + and low-level application profiling, it is forced on regardless of
65115 + configuration, has been at fault for several vulnerabilities, and
65116 + creates new opportunities for side channels and other information leaks.
65117 +
65118 + This feature puts PERF_EVENTS into a secure default state and permits
65119 + the administrator to change out of it temporarily if unprivileged
65120 + application profiling is needed.
65121 +
65122 +config GRKERNSEC_RAND_THREADSTACK
65123 + bool "Insert random gaps between thread stacks"
65124 + default y if GRKERNSEC_CONFIG_AUTO
65125 + depends on PAX_RANDMMAP && !PPC
65126 + help
65127 + If you say Y here, a random-sized gap will be enforced between allocated
65128 + thread stacks. Glibc's NPTL and other threading libraries that
65129 + pass MAP_STACK to the kernel for thread stack allocation are supported.
65130 + The implementation currently provides 8 bits of entropy for the gap.
65131 +
65132 + Many distributions do not compile threaded remote services with the
65133 + -fstack-check argument to GCC, causing the variable-sized stack-based
65134 + allocator, alloca(), to not probe the stack on allocation. This
65135 + permits an unbounded alloca() to skip over any guard page and potentially
65136 + modify another thread's stack reliably. An enforced random gap
65137 + reduces the reliability of such an attack and increases the chance
65138 + that such a read/write to another thread's stack instead lands in
65139 + an unmapped area, causing a crash and triggering grsecurity's
65140 + anti-bruteforcing logic.
65141 +
65142 +config GRKERNSEC_PROC_MEMMAP
65143 + bool "Harden ASLR against information leaks and entropy reduction"
65144 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65145 + depends on PAX_NOEXEC || PAX_ASLR
65146 + help
65147 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65148 + give no information about the addresses of its mappings if
65149 + PaX features that rely on random addresses are enabled on the task.
65150 + In addition to sanitizing this information and disabling other
65151 + dangerous sources of information, this option causes reads of sensitive
65152 + /proc/<pid> entries where the file descriptor was opened in a different
65153 + task than the one performing the read. Such attempts are logged.
65154 + This option also limits argv/env strings for suid/sgid binaries
65155 + to 512KB to prevent a complete exhaustion of the stack entropy provided
65156 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65157 + binaries to prevent alternative mmap layouts from being abused.
65158 +
65159 + If you use PaX it is essential that you say Y here as it closes up
65160 + several holes that make full ASLR useless locally.
65161 +
65162 +config GRKERNSEC_BRUTE
65163 + bool "Deter exploit bruteforcing"
65164 + default y if GRKERNSEC_CONFIG_AUTO
65165 + help
65166 + If you say Y here, attempts to bruteforce exploits against forking
65167 + daemons such as apache or sshd, as well as against suid/sgid binaries
65168 + will be deterred. When a child of a forking daemon is killed by PaX
65169 + or crashes due to an illegal instruction or other suspicious signal,
65170 + the parent process will be delayed 30 seconds upon every subsequent
65171 + fork until the administrator is able to assess the situation and
65172 + restart the daemon.
65173 + In the suid/sgid case, the attempt is logged, the user has all their
65174 + existing instances of the suid/sgid binary terminated and will
65175 + be unable to execute any suid/sgid binaries for 15 minutes.
65176 +
65177 + It is recommended that you also enable signal logging in the auditing
65178 + section so that logs are generated when a process triggers a suspicious
65179 + signal.
65180 + If the sysctl option is enabled, a sysctl option with name
65181 + "deter_bruteforce" is created.
65182 +
65183 +config GRKERNSEC_MODHARDEN
65184 + bool "Harden module auto-loading"
65185 + default y if GRKERNSEC_CONFIG_AUTO
65186 + depends on MODULES
65187 + help
65188 + If you say Y here, module auto-loading in response to use of some
65189 + feature implemented by an unloaded module will be restricted to
65190 + root users. Enabling this option helps defend against attacks
65191 + by unprivileged users who abuse the auto-loading behavior to
65192 + cause a vulnerable module to load that is then exploited.
65193 +
65194 + If this option prevents a legitimate use of auto-loading for a
65195 + non-root user, the administrator can execute modprobe manually
65196 + with the exact name of the module mentioned in the alert log.
65197 + Alternatively, the administrator can add the module to the list
65198 + of modules loaded at boot by modifying init scripts.
65199 +
65200 + Modification of init scripts will most likely be needed on
65201 + Ubuntu servers with encrypted home directory support enabled,
65202 + as the first non-root user logging in will cause the ecb(aes),
65203 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65204 +
65205 +config GRKERNSEC_HIDESYM
65206 + bool "Hide kernel symbols"
65207 + default y if GRKERNSEC_CONFIG_AUTO
65208 + select PAX_USERCOPY_SLABS
65209 + help
65210 + If you say Y here, getting information on loaded modules, and
65211 + displaying all kernel symbols through a syscall will be restricted
65212 + to users with CAP_SYS_MODULE. For software compatibility reasons,
65213 + /proc/kallsyms will be restricted to the root user. The RBAC
65214 + system can hide that entry even from root.
65215 +
65216 + This option also prevents leaking of kernel addresses through
65217 + several /proc entries.
65218 +
65219 + Note that this option is only effective provided the following
65220 + conditions are met:
65221 + 1) The kernel using grsecurity is not precompiled by some distribution
65222 + 2) You have also enabled GRKERNSEC_DMESG
65223 + 3) You are using the RBAC system and hiding other files such as your
65224 + kernel image and System.map. Alternatively, enabling this option
65225 + causes the permissions on /boot, /lib/modules, and the kernel
65226 + source directory to change at compile time to prevent
65227 + reading by non-root users.
65228 + If the above conditions are met, this option will aid in providing a
65229 + useful protection against local kernel exploitation of overflows
65230 + and arbitrary read/write vulnerabilities.
65231 +
65232 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65233 + in addition to this feature.
65234 +
65235 +config GRKERNSEC_RANDSTRUCT
65236 + bool "Randomize layout of sensitive kernel structures"
65237 + default y if GRKERNSEC_CONFIG_AUTO
65238 + select GRKERNSEC_HIDESYM
65239 + select MODVERSIONS if MODULES
65240 + help
65241 + If you say Y here, the layouts of a number of sensitive kernel
65242 + structures (task, fs, cred, etc) and all structures composed entirely
65243 + of function pointers (aka "ops" structs) will be randomized at compile-time.
65244 + This can introduce the requirement of an additional infoleak
65245 + vulnerability for exploits targeting these structure types.
65246 +
65247 + Enabling this feature will introduce some performance impact, slightly
65248 + increase memory usage, and prevent the use of forensic tools like
65249 + Volatility against the system (unless the kernel source tree isn't
65250 + cleaned after kernel installation).
65251 +
65252 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65253 + It remains after a make clean to allow for external modules to be compiled
65254 + with the existing seed and will be removed by a make mrproper or
65255 + make distclean.
65256 +
65257 + Note that the implementation requires gcc 4.6.4. or newer. You may need
65258 + to install the supporting headers explicitly in addition to the normal
65259 + gcc package.
65260 +
65261 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65262 + bool "Use cacheline-aware structure randomization"
65263 + depends on GRKERNSEC_RANDSTRUCT
65264 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65265 + help
65266 + If you say Y here, the RANDSTRUCT randomization will make a best effort
65267 + at restricting randomization to cacheline-sized groups of elements. It
65268 + will further not randomize bitfields in structures. This reduces the
65269 + performance hit of RANDSTRUCT at the cost of weakened randomization.
65270 +
65271 +config GRKERNSEC_KERN_LOCKOUT
65272 + bool "Active kernel exploit response"
65273 + default y if GRKERNSEC_CONFIG_AUTO
65274 + depends on X86 || ARM || PPC || SPARC
65275 + help
65276 + If you say Y here, when a PaX alert is triggered due to suspicious
65277 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65278 + or an OOPS occurs due to bad memory accesses, instead of just
65279 + terminating the offending process (and potentially allowing
65280 + a subsequent exploit from the same user), we will take one of two
65281 + actions:
65282 + If the user was root, we will panic the system
65283 + If the user was non-root, we will log the attempt, terminate
65284 + all processes owned by the user, then prevent them from creating
65285 + any new processes until the system is restarted
65286 + This deters repeated kernel exploitation/bruteforcing attempts
65287 + and is useful for later forensics.
65288 +
65289 +config GRKERNSEC_OLD_ARM_USERLAND
65290 + bool "Old ARM userland compatibility"
65291 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
65292 + help
65293 + If you say Y here, stubs of executable code to perform such operations
65294 + as "compare-exchange" will be placed at fixed locations in the ARM vector
65295 + table. This is unfortunately needed for old ARM userland meant to run
65296 + across a wide range of processors. Without this option enabled,
65297 + the get_tls and data memory barrier stubs will be emulated by the kernel,
65298 + which is enough for Linaro userlands or other userlands designed for v6
65299 + and newer ARM CPUs. It's recommended that you try without this option enabled
65300 + first, and only enable it if your userland does not boot (it will likely fail
65301 + at init time).
65302 +
65303 +endmenu
65304 +menu "Role Based Access Control Options"
65305 +depends on GRKERNSEC
65306 +
65307 +config GRKERNSEC_RBAC_DEBUG
65308 + bool
65309 +
65310 +config GRKERNSEC_NO_RBAC
65311 + bool "Disable RBAC system"
65312 + help
65313 + If you say Y here, the /dev/grsec device will be removed from the kernel,
65314 + preventing the RBAC system from being enabled. You should only say Y
65315 + here if you have no intention of using the RBAC system, so as to prevent
65316 + an attacker with root access from misusing the RBAC system to hide files
65317 + and processes when loadable module support and /dev/[k]mem have been
65318 + locked down.
65319 +
65320 +config GRKERNSEC_ACL_HIDEKERN
65321 + bool "Hide kernel processes"
65322 + help
65323 + If you say Y here, all kernel threads will be hidden to all
65324 + processes but those whose subject has the "view hidden processes"
65325 + flag.
65326 +
65327 +config GRKERNSEC_ACL_MAXTRIES
65328 + int "Maximum tries before password lockout"
65329 + default 3
65330 + help
65331 + This option enforces the maximum number of times a user can attempt
65332 + to authorize themselves with the grsecurity RBAC system before being
65333 + denied the ability to attempt authorization again for a specified time.
65334 + The lower the number, the harder it will be to brute-force a password.
65335 +
65336 +config GRKERNSEC_ACL_TIMEOUT
65337 + int "Time to wait after max password tries, in seconds"
65338 + default 30
65339 + help
65340 + This option specifies the time the user must wait after attempting to
65341 + authorize to the RBAC system with the maximum number of invalid
65342 + passwords. The higher the number, the harder it will be to brute-force
65343 + a password.
65344 +
65345 +endmenu
65346 +menu "Filesystem Protections"
65347 +depends on GRKERNSEC
65348 +
65349 +config GRKERNSEC_PROC
65350 + bool "Proc restrictions"
65351 + default y if GRKERNSEC_CONFIG_AUTO
65352 + help
65353 + If you say Y here, the permissions of the /proc filesystem
65354 + will be altered to enhance system security and privacy. You MUST
65355 + choose either a user only restriction or a user and group restriction.
65356 + Depending upon the option you choose, you can either restrict users to
65357 + see only the processes they themselves run, or choose a group that can
65358 + view all processes and files normally restricted to root if you choose
65359 + the "restrict to user only" option. NOTE: If you're running identd or
65360 + ntpd as a non-root user, you will have to run it as the group you
65361 + specify here.
65362 +
65363 +config GRKERNSEC_PROC_USER
65364 + bool "Restrict /proc to user only"
65365 + depends on GRKERNSEC_PROC
65366 + help
65367 + If you say Y here, non-root users will only be able to view their own
65368 + processes, and restricts them from viewing network-related information,
65369 + and viewing kernel symbol and module information.
65370 +
65371 +config GRKERNSEC_PROC_USERGROUP
65372 + bool "Allow special group"
65373 + default y if GRKERNSEC_CONFIG_AUTO
65374 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
65375 + help
65376 + If you say Y here, you will be able to select a group that will be
65377 + able to view all processes and network-related information. If you've
65378 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
65379 + remain hidden. This option is useful if you want to run identd as
65380 + a non-root user. The group you select may also be chosen at boot time
65381 + via "grsec_proc_gid=" on the kernel commandline.
65382 +
65383 +config GRKERNSEC_PROC_GID
65384 + int "GID for special group"
65385 + depends on GRKERNSEC_PROC_USERGROUP
65386 + default 1001
65387 +
65388 +config GRKERNSEC_PROC_ADD
65389 + bool "Additional restrictions"
65390 + default y if GRKERNSEC_CONFIG_AUTO
65391 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
65392 + help
65393 + If you say Y here, additional restrictions will be placed on
65394 + /proc that keep normal users from viewing device information and
65395 + slabinfo information that could be useful for exploits.
65396 +
65397 +config GRKERNSEC_LINK
65398 + bool "Linking restrictions"
65399 + default y if GRKERNSEC_CONFIG_AUTO
65400 + help
65401 + If you say Y here, /tmp race exploits will be prevented, since users
65402 + will no longer be able to follow symlinks owned by other users in
65403 + world-writable +t directories (e.g. /tmp), unless the owner of the
65404 + symlink is the owner of the directory. users will also not be
65405 + able to hardlink to files they do not own. If the sysctl option is
65406 + enabled, a sysctl option with name "linking_restrictions" is created.
65407 +
65408 +config GRKERNSEC_SYMLINKOWN
65409 + bool "Kernel-enforced SymlinksIfOwnerMatch"
65410 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65411 + help
65412 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
65413 + that prevents it from being used as a security feature. As Apache
65414 + verifies the symlink by performing a stat() against the target of
65415 + the symlink before it is followed, an attacker can setup a symlink
65416 + to point to a same-owned file, then replace the symlink with one
65417 + that targets another user's file just after Apache "validates" the
65418 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
65419 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
65420 + will be in place for the group you specify. If the sysctl option
65421 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
65422 + created.
65423 +
65424 +config GRKERNSEC_SYMLINKOWN_GID
65425 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
65426 + depends on GRKERNSEC_SYMLINKOWN
65427 + default 1006
65428 + help
65429 + Setting this GID determines what group kernel-enforced
65430 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
65431 + is enabled, a sysctl option with name "symlinkown_gid" is created.
65432 +
65433 +config GRKERNSEC_FIFO
65434 + bool "FIFO restrictions"
65435 + default y if GRKERNSEC_CONFIG_AUTO
65436 + help
65437 + If you say Y here, users will not be able to write to FIFOs they don't
65438 + own in world-writable +t directories (e.g. /tmp), unless the owner of
65439 + the FIFO is the same owner of the directory it's held in. If the sysctl
65440 + option is enabled, a sysctl option with name "fifo_restrictions" is
65441 + created.
65442 +
65443 +config GRKERNSEC_SYSFS_RESTRICT
65444 + bool "Sysfs/debugfs restriction"
65445 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65446 + depends on SYSFS
65447 + help
65448 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
65449 + any filesystem normally mounted under it (e.g. debugfs) will be
65450 + mostly accessible only by root. These filesystems generally provide access
65451 + to hardware and debug information that isn't appropriate for unprivileged
65452 + users of the system. Sysfs and debugfs have also become a large source
65453 + of new vulnerabilities, ranging from infoleaks to local compromise.
65454 + There has been very little oversight with an eye toward security involved
65455 + in adding new exporters of information to these filesystems, so their
65456 + use is discouraged.
65457 + For reasons of compatibility, a few directories have been whitelisted
65458 + for access by non-root users:
65459 + /sys/fs/selinux
65460 + /sys/fs/fuse
65461 + /sys/devices/system/cpu
65462 +
65463 +config GRKERNSEC_ROFS
65464 + bool "Runtime read-only mount protection"
65465 + depends on SYSCTL
65466 + help
65467 + If you say Y here, a sysctl option with name "romount_protect" will
65468 + be created. By setting this option to 1 at runtime, filesystems
65469 + will be protected in the following ways:
65470 + * No new writable mounts will be allowed
65471 + * Existing read-only mounts won't be able to be remounted read/write
65472 + * Write operations will be denied on all block devices
65473 + This option acts independently of grsec_lock: once it is set to 1,
65474 + it cannot be turned off. Therefore, please be mindful of the resulting
65475 + behavior if this option is enabled in an init script on a read-only
65476 + filesystem.
65477 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
65478 + and GRKERNSEC_IO should be enabled and module loading disabled via
65479 + config or at runtime.
65480 + This feature is mainly intended for secure embedded systems.
65481 +
65482 +
65483 +config GRKERNSEC_DEVICE_SIDECHANNEL
65484 + bool "Eliminate stat/notify-based device sidechannels"
65485 + default y if GRKERNSEC_CONFIG_AUTO
65486 + help
65487 + If you say Y here, timing analyses on block or character
65488 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
65489 + will be thwarted for unprivileged users. If a process without
65490 + CAP_MKNOD stats such a device, the last access and last modify times
65491 + will match the device's create time. No access or modify events
65492 + will be triggered through inotify/dnotify/fanotify for such devices.
65493 + This feature will prevent attacks that may at a minimum
65494 + allow an attacker to determine the administrator's password length.
65495 +
65496 +config GRKERNSEC_CHROOT
65497 + bool "Chroot jail restrictions"
65498 + default y if GRKERNSEC_CONFIG_AUTO
65499 + help
65500 + If you say Y here, you will be able to choose several options that will
65501 + make breaking out of a chrooted jail much more difficult. If you
65502 + encounter no software incompatibilities with the following options, it
65503 + is recommended that you enable each one.
65504 +
65505 + Note that the chroot restrictions are not intended to apply to "chroots"
65506 + to directories that are simple bind mounts of the global root filesystem.
65507 + For several other reasons, a user shouldn't expect any significant
65508 + security by performing such a chroot.
65509 +
65510 +config GRKERNSEC_CHROOT_MOUNT
65511 + bool "Deny mounts"
65512 + default y if GRKERNSEC_CONFIG_AUTO
65513 + depends on GRKERNSEC_CHROOT
65514 + help
65515 + If you say Y here, processes inside a chroot will not be able to
65516 + mount or remount filesystems. If the sysctl option is enabled, a
65517 + sysctl option with name "chroot_deny_mount" is created.
65518 +
65519 +config GRKERNSEC_CHROOT_DOUBLE
65520 + bool "Deny double-chroots"
65521 + default y if GRKERNSEC_CONFIG_AUTO
65522 + depends on GRKERNSEC_CHROOT
65523 + help
65524 + If you say Y here, processes inside a chroot will not be able to chroot
65525 + again outside the chroot. This is a widely used method of breaking
65526 + out of a chroot jail and should not be allowed. If the sysctl
65527 + option is enabled, a sysctl option with name
65528 + "chroot_deny_chroot" is created.
65529 +
65530 +config GRKERNSEC_CHROOT_PIVOT
65531 + bool "Deny pivot_root in chroot"
65532 + default y if GRKERNSEC_CONFIG_AUTO
65533 + depends on GRKERNSEC_CHROOT
65534 + help
65535 + If you say Y here, processes inside a chroot will not be able to use
65536 + a function called pivot_root() that was introduced in Linux 2.3.41. It
65537 + works similar to chroot in that it changes the root filesystem. This
65538 + function could be misused in a chrooted process to attempt to break out
65539 + of the chroot, and therefore should not be allowed. If the sysctl
65540 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
65541 + created.
65542 +
65543 +config GRKERNSEC_CHROOT_CHDIR
65544 + bool "Enforce chdir(\"/\") on all chroots"
65545 + default y if GRKERNSEC_CONFIG_AUTO
65546 + depends on GRKERNSEC_CHROOT
65547 + help
65548 + If you say Y here, the current working directory of all newly-chrooted
65549 + applications will be set to the the root directory of the chroot.
65550 + The man page on chroot(2) states:
65551 + Note that this call does not change the current working
65552 + directory, so that `.' can be outside the tree rooted at
65553 + `/'. In particular, the super-user can escape from a
65554 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
65555 +
65556 + It is recommended that you say Y here, since it's not known to break
65557 + any software. If the sysctl option is enabled, a sysctl option with
65558 + name "chroot_enforce_chdir" is created.
65559 +
65560 +config GRKERNSEC_CHROOT_CHMOD
65561 + bool "Deny (f)chmod +s"
65562 + default y if GRKERNSEC_CONFIG_AUTO
65563 + depends on GRKERNSEC_CHROOT
65564 + help
65565 + If you say Y here, processes inside a chroot will not be able to chmod
65566 + or fchmod files to make them have suid or sgid bits. This protects
65567 + against another published method of breaking a chroot. If the sysctl
65568 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
65569 + created.
65570 +
65571 +config GRKERNSEC_CHROOT_FCHDIR
65572 + bool "Deny fchdir out of chroot"
65573 + default y if GRKERNSEC_CONFIG_AUTO
65574 + depends on GRKERNSEC_CHROOT
65575 + help
65576 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
65577 + to a file descriptor of the chrooting process that points to a directory
65578 + outside the filesystem will be stopped. If the sysctl option
65579 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
65580 +
65581 +config GRKERNSEC_CHROOT_MKNOD
65582 + bool "Deny mknod"
65583 + default y if GRKERNSEC_CONFIG_AUTO
65584 + depends on GRKERNSEC_CHROOT
65585 + help
65586 + If you say Y here, processes inside a chroot will not be allowed to
65587 + mknod. The problem with using mknod inside a chroot is that it
65588 + would allow an attacker to create a device entry that is the same
65589 + as one on the physical root of your system, which could range from
65590 + anything from the console device to a device for your harddrive (which
65591 + they could then use to wipe the drive or steal data). It is recommended
65592 + that you say Y here, unless you run into software incompatibilities.
65593 + If the sysctl option is enabled, a sysctl option with name
65594 + "chroot_deny_mknod" is created.
65595 +
65596 +config GRKERNSEC_CHROOT_SHMAT
65597 + bool "Deny shmat() out of chroot"
65598 + default y if GRKERNSEC_CONFIG_AUTO
65599 + depends on GRKERNSEC_CHROOT
65600 + help
65601 + If you say Y here, processes inside a chroot will not be able to attach
65602 + to shared memory segments that were created outside of the chroot jail.
65603 + It is recommended that you say Y here. If the sysctl option is enabled,
65604 + a sysctl option with name "chroot_deny_shmat" is created.
65605 +
65606 +config GRKERNSEC_CHROOT_UNIX
65607 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
65608 + default y if GRKERNSEC_CONFIG_AUTO
65609 + depends on GRKERNSEC_CHROOT
65610 + help
65611 + If you say Y here, processes inside a chroot will not be able to
65612 + connect to abstract (meaning not belonging to a filesystem) Unix
65613 + domain sockets that were bound outside of a chroot. It is recommended
65614 + that you say Y here. If the sysctl option is enabled, a sysctl option
65615 + with name "chroot_deny_unix" is created.
65616 +
65617 +config GRKERNSEC_CHROOT_FINDTASK
65618 + bool "Protect outside processes"
65619 + default y if GRKERNSEC_CONFIG_AUTO
65620 + depends on GRKERNSEC_CHROOT
65621 + help
65622 + If you say Y here, processes inside a chroot will not be able to
65623 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
65624 + getsid, or view any process outside of the chroot. If the sysctl
65625 + option is enabled, a sysctl option with name "chroot_findtask" is
65626 + created.
65627 +
65628 +config GRKERNSEC_CHROOT_NICE
65629 + bool "Restrict priority changes"
65630 + default y if GRKERNSEC_CONFIG_AUTO
65631 + depends on GRKERNSEC_CHROOT
65632 + help
65633 + If you say Y here, processes inside a chroot will not be able to raise
65634 + the priority of processes in the chroot, or alter the priority of
65635 + processes outside the chroot. This provides more security than simply
65636 + removing CAP_SYS_NICE from the process' capability set. If the
65637 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
65638 + is created.
65639 +
65640 +config GRKERNSEC_CHROOT_SYSCTL
65641 + bool "Deny sysctl writes"
65642 + default y if GRKERNSEC_CONFIG_AUTO
65643 + depends on GRKERNSEC_CHROOT
65644 + help
65645 + If you say Y here, an attacker in a chroot will not be able to
65646 + write to sysctl entries, either by sysctl(2) or through a /proc
65647 + interface. It is strongly recommended that you say Y here. If the
65648 + sysctl option is enabled, a sysctl option with name
65649 + "chroot_deny_sysctl" is created.
65650 +
65651 +config GRKERNSEC_CHROOT_CAPS
65652 + bool "Capability restrictions"
65653 + default y if GRKERNSEC_CONFIG_AUTO
65654 + depends on GRKERNSEC_CHROOT
65655 + help
65656 + If you say Y here, the capabilities on all processes within a
65657 + chroot jail will be lowered to stop module insertion, raw i/o,
65658 + system and net admin tasks, rebooting the system, modifying immutable
65659 + files, modifying IPC owned by another, and changing the system time.
65660 + This is left an option because it can break some apps. Disable this
65661 + if your chrooted apps are having problems performing those kinds of
65662 + tasks. If the sysctl option is enabled, a sysctl option with
65663 + name "chroot_caps" is created.
65664 +
65665 +config GRKERNSEC_CHROOT_INITRD
65666 + bool "Exempt initrd tasks from restrictions"
65667 + default y if GRKERNSEC_CONFIG_AUTO
65668 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
65669 + help
65670 + If you say Y here, tasks started prior to init will be exempted from
65671 + grsecurity's chroot restrictions. This option is mainly meant to
65672 + resolve Plymouth's performing privileged operations unnecessarily
65673 + in a chroot.
65674 +
65675 +endmenu
65676 +menu "Kernel Auditing"
65677 +depends on GRKERNSEC
65678 +
65679 +config GRKERNSEC_AUDIT_GROUP
65680 + bool "Single group for auditing"
65681 + help
65682 + If you say Y here, the exec and chdir logging features will only operate
65683 + on a group you specify. This option is recommended if you only want to
65684 + watch certain users instead of having a large amount of logs from the
65685 + entire system. If the sysctl option is enabled, a sysctl option with
65686 + name "audit_group" is created.
65687 +
65688 +config GRKERNSEC_AUDIT_GID
65689 + int "GID for auditing"
65690 + depends on GRKERNSEC_AUDIT_GROUP
65691 + default 1007
65692 +
65693 +config GRKERNSEC_EXECLOG
65694 + bool "Exec logging"
65695 + help
65696 + If you say Y here, all execve() calls will be logged (since the
65697 + other exec*() calls are frontends to execve(), all execution
65698 + will be logged). Useful for shell-servers that like to keep track
65699 + of their users. If the sysctl option is enabled, a sysctl option with
65700 + name "exec_logging" is created.
65701 + WARNING: This option when enabled will produce a LOT of logs, especially
65702 + on an active system.
65703 +
65704 +config GRKERNSEC_RESLOG
65705 + bool "Resource logging"
65706 + default y if GRKERNSEC_CONFIG_AUTO
65707 + help
65708 + If you say Y here, all attempts to overstep resource limits will
65709 + be logged with the resource name, the requested size, and the current
65710 + limit. It is highly recommended that you say Y here. If the sysctl
65711 + option is enabled, a sysctl option with name "resource_logging" is
65712 + created. If the RBAC system is enabled, the sysctl value is ignored.
65713 +
65714 +config GRKERNSEC_CHROOT_EXECLOG
65715 + bool "Log execs within chroot"
65716 + help
65717 + If you say Y here, all executions inside a chroot jail will be logged
65718 + to syslog. This can cause a large amount of logs if certain
65719 + applications (eg. djb's daemontools) are installed on the system, and
65720 + is therefore left as an option. If the sysctl option is enabled, a
65721 + sysctl option with name "chroot_execlog" is created.
65722 +
65723 +config GRKERNSEC_AUDIT_PTRACE
65724 + bool "Ptrace logging"
65725 + help
65726 + If you say Y here, all attempts to attach to a process via ptrace
65727 + will be logged. If the sysctl option is enabled, a sysctl option
65728 + with name "audit_ptrace" is created.
65729 +
65730 +config GRKERNSEC_AUDIT_CHDIR
65731 + bool "Chdir logging"
65732 + help
65733 + If you say Y here, all chdir() calls will be logged. If the sysctl
65734 + option is enabled, a sysctl option with name "audit_chdir" is created.
65735 +
65736 +config GRKERNSEC_AUDIT_MOUNT
65737 + bool "(Un)Mount logging"
65738 + help
65739 + If you say Y here, all mounts and unmounts will be logged. If the
65740 + sysctl option is enabled, a sysctl option with name "audit_mount" is
65741 + created.
65742 +
65743 +config GRKERNSEC_SIGNAL
65744 + bool "Signal logging"
65745 + default y if GRKERNSEC_CONFIG_AUTO
65746 + help
65747 + If you say Y here, certain important signals will be logged, such as
65748 + SIGSEGV, which will as a result inform you of when a error in a program
65749 + occurred, which in some cases could mean a possible exploit attempt.
65750 + If the sysctl option is enabled, a sysctl option with name
65751 + "signal_logging" is created.
65752 +
65753 +config GRKERNSEC_FORKFAIL
65754 + bool "Fork failure logging"
65755 + help
65756 + If you say Y here, all failed fork() attempts will be logged.
65757 + This could suggest a fork bomb, or someone attempting to overstep
65758 + their process limit. If the sysctl option is enabled, a sysctl option
65759 + with name "forkfail_logging" is created.
65760 +
65761 +config GRKERNSEC_TIME
65762 + bool "Time change logging"
65763 + default y if GRKERNSEC_CONFIG_AUTO
65764 + help
65765 + If you say Y here, any changes of the system clock will be logged.
65766 + If the sysctl option is enabled, a sysctl option with name
65767 + "timechange_logging" is created.
65768 +
65769 +config GRKERNSEC_PROC_IPADDR
65770 + bool "/proc/<pid>/ipaddr support"
65771 + default y if GRKERNSEC_CONFIG_AUTO
65772 + help
65773 + If you say Y here, a new entry will be added to each /proc/<pid>
65774 + directory that contains the IP address of the person using the task.
65775 + The IP is carried across local TCP and AF_UNIX stream sockets.
65776 + This information can be useful for IDS/IPSes to perform remote response
65777 + to a local attack. The entry is readable by only the owner of the
65778 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
65779 + the RBAC system), and thus does not create privacy concerns.
65780 +
65781 +config GRKERNSEC_RWXMAP_LOG
65782 + bool 'Denied RWX mmap/mprotect logging'
65783 + default y if GRKERNSEC_CONFIG_AUTO
65784 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
65785 + help
65786 + If you say Y here, calls to mmap() and mprotect() with explicit
65787 + usage of PROT_WRITE and PROT_EXEC together will be logged when
65788 + denied by the PAX_MPROTECT feature. This feature will also
65789 + log other problematic scenarios that can occur when PAX_MPROTECT
65790 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
65791 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
65792 + is created.
65793 +
65794 +endmenu
65795 +
65796 +menu "Executable Protections"
65797 +depends on GRKERNSEC
65798 +
65799 +config GRKERNSEC_DMESG
65800 + bool "Dmesg(8) restriction"
65801 + default y if GRKERNSEC_CONFIG_AUTO
65802 + help
65803 + If you say Y here, non-root users will not be able to use dmesg(8)
65804 + to view the contents of the kernel's circular log buffer.
65805 + The kernel's log buffer often contains kernel addresses and other
65806 + identifying information useful to an attacker in fingerprinting a
65807 + system for a targeted exploit.
65808 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
65809 + created.
65810 +
65811 +config GRKERNSEC_HARDEN_PTRACE
65812 + bool "Deter ptrace-based process snooping"
65813 + default y if GRKERNSEC_CONFIG_AUTO
65814 + help
65815 + If you say Y here, TTY sniffers and other malicious monitoring
65816 + programs implemented through ptrace will be defeated. If you
65817 + have been using the RBAC system, this option has already been
65818 + enabled for several years for all users, with the ability to make
65819 + fine-grained exceptions.
65820 +
65821 + This option only affects the ability of non-root users to ptrace
65822 + processes that are not a descendent of the ptracing process.
65823 + This means that strace ./binary and gdb ./binary will still work,
65824 + but attaching to arbitrary processes will not. If the sysctl
65825 + option is enabled, a sysctl option with name "harden_ptrace" is
65826 + created.
65827 +
65828 +config GRKERNSEC_PTRACE_READEXEC
65829 + bool "Require read access to ptrace sensitive binaries"
65830 + default y if GRKERNSEC_CONFIG_AUTO
65831 + help
65832 + If you say Y here, unprivileged users will not be able to ptrace unreadable
65833 + binaries. This option is useful in environments that
65834 + remove the read bits (e.g. file mode 4711) from suid binaries to
65835 + prevent infoleaking of their contents. This option adds
65836 + consistency to the use of that file mode, as the binary could normally
65837 + be read out when run without privileges while ptracing.
65838 +
65839 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
65840 + is created.
65841 +
65842 +config GRKERNSEC_SETXID
65843 + bool "Enforce consistent multithreaded privileges"
65844 + default y if GRKERNSEC_CONFIG_AUTO
65845 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
65846 + help
65847 + If you say Y here, a change from a root uid to a non-root uid
65848 + in a multithreaded application will cause the resulting uids,
65849 + gids, supplementary groups, and capabilities in that thread
65850 + to be propagated to the other threads of the process. In most
65851 + cases this is unnecessary, as glibc will emulate this behavior
65852 + on behalf of the application. Other libcs do not act in the
65853 + same way, allowing the other threads of the process to continue
65854 + running with root privileges. If the sysctl option is enabled,
65855 + a sysctl option with name "consistent_setxid" is created.
65856 +
65857 +config GRKERNSEC_HARDEN_IPC
65858 + bool "Disallow access to overly-permissive IPC objects"
65859 + default y if GRKERNSEC_CONFIG_AUTO
65860 + depends on SYSVIPC
65861 + help
65862 + If you say Y here, access to overly-permissive IPC objects (shared
65863 + memory, message queues, and semaphores) will be denied for processes
65864 + given the following criteria beyond normal permission checks:
65865 + 1) If the IPC object is world-accessible and the euid doesn't match
65866 + that of the creator or current uid for the IPC object
65867 + 2) If the IPC object is group-accessible and the egid doesn't
65868 + match that of the creator or current gid for the IPC object
65869 + It's a common error to grant too much permission to these objects,
65870 + with impact ranging from denial of service and information leaking to
65871 + privilege escalation. This feature was developed in response to
65872 + research by Tim Brown:
65873 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
65874 + who found hundreds of such insecure usages. Processes with
65875 + CAP_IPC_OWNER are still permitted to access these IPC objects.
65876 + If the sysctl option is enabled, a sysctl option with name
65877 + "harden_ipc" is created.
65878 +
65879 +config GRKERNSEC_TPE
65880 + bool "Trusted Path Execution (TPE)"
65881 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65882 + help
65883 + If you say Y here, you will be able to choose a gid to add to the
65884 + supplementary groups of users you want to mark as "untrusted."
65885 + These users will not be able to execute any files that are not in
65886 + root-owned directories writable only by root. If the sysctl option
65887 + is enabled, a sysctl option with name "tpe" is created.
65888 +
65889 +config GRKERNSEC_TPE_ALL
65890 + bool "Partially restrict all non-root users"
65891 + depends on GRKERNSEC_TPE
65892 + help
65893 + If you say Y here, all non-root users will be covered under
65894 + a weaker TPE restriction. This is separate from, and in addition to,
65895 + the main TPE options that you have selected elsewhere. Thus, if a
65896 + "trusted" GID is chosen, this restriction applies to even that GID.
65897 + Under this restriction, all non-root users will only be allowed to
65898 + execute files in directories they own that are not group or
65899 + world-writable, or in directories owned by root and writable only by
65900 + root. If the sysctl option is enabled, a sysctl option with name
65901 + "tpe_restrict_all" is created.
65902 +
65903 +config GRKERNSEC_TPE_INVERT
65904 + bool "Invert GID option"
65905 + depends on GRKERNSEC_TPE
65906 + help
65907 + If you say Y here, the group you specify in the TPE configuration will
65908 + decide what group TPE restrictions will be *disabled* for. This
65909 + option is useful if you want TPE restrictions to be applied to most
65910 + users on the system. If the sysctl option is enabled, a sysctl option
65911 + with name "tpe_invert" is created. Unlike other sysctl options, this
65912 + entry will default to on for backward-compatibility.
65913 +
65914 +config GRKERNSEC_TPE_GID
65915 + int
65916 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
65917 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
65918 +
65919 +config GRKERNSEC_TPE_UNTRUSTED_GID
65920 + int "GID for TPE-untrusted users"
65921 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
65922 + default 1005
65923 + help
65924 + Setting this GID determines what group TPE restrictions will be
65925 + *enabled* for. If the sysctl option is enabled, a sysctl option
65926 + with name "tpe_gid" is created.
65927 +
65928 +config GRKERNSEC_TPE_TRUSTED_GID
65929 + int "GID for TPE-trusted users"
65930 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
65931 + default 1005
65932 + help
65933 + Setting this GID determines what group TPE restrictions will be
65934 + *disabled* for. If the sysctl option is enabled, a sysctl option
65935 + with name "tpe_gid" is created.
65936 +
65937 +endmenu
65938 +menu "Network Protections"
65939 +depends on GRKERNSEC
65940 +
65941 +config GRKERNSEC_RANDNET
65942 + bool "Larger entropy pools"
65943 + default y if GRKERNSEC_CONFIG_AUTO
65944 + help
65945 + If you say Y here, the entropy pools used for many features of Linux
65946 + and grsecurity will be doubled in size. Since several grsecurity
65947 + features use additional randomness, it is recommended that you say Y
65948 + here. Saying Y here has a similar effect as modifying
65949 + /proc/sys/kernel/random/poolsize.
65950 +
65951 +config GRKERNSEC_BLACKHOLE
65952 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
65953 + default y if GRKERNSEC_CONFIG_AUTO
65954 + depends on NET
65955 + help
65956 + If you say Y here, neither TCP resets nor ICMP
65957 + destination-unreachable packets will be sent in response to packets
65958 + sent to ports for which no associated listening process exists.
65959 + This feature supports both IPV4 and IPV6 and exempts the
65960 + loopback interface from blackholing. Enabling this feature
65961 + makes a host more resilient to DoS attacks and reduces network
65962 + visibility against scanners.
65963 +
65964 + The blackhole feature as-implemented is equivalent to the FreeBSD
65965 + blackhole feature, as it prevents RST responses to all packets, not
65966 + just SYNs. Under most application behavior this causes no
65967 + problems, but applications (like haproxy) may not close certain
65968 + connections in a way that cleanly terminates them on the remote
65969 + end, leaving the remote host in LAST_ACK state. Because of this
65970 + side-effect and to prevent intentional LAST_ACK DoSes, this
65971 + feature also adds automatic mitigation against such attacks.
65972 + The mitigation drastically reduces the amount of time a socket
65973 + can spend in LAST_ACK state. If you're using haproxy and not
65974 + all servers it connects to have this option enabled, consider
65975 + disabling this feature on the haproxy host.
65976 +
65977 + If the sysctl option is enabled, two sysctl options with names
65978 + "ip_blackhole" and "lastack_retries" will be created.
65979 + While "ip_blackhole" takes the standard zero/non-zero on/off
65980 + toggle, "lastack_retries" uses the same kinds of values as
65981 + "tcp_retries1" and "tcp_retries2". The default value of 4
65982 + prevents a socket from lasting more than 45 seconds in LAST_ACK
65983 + state.
65984 +
65985 +config GRKERNSEC_NO_SIMULT_CONNECT
65986 + bool "Disable TCP Simultaneous Connect"
65987 + default y if GRKERNSEC_CONFIG_AUTO
65988 + depends on NET
65989 + help
65990 + If you say Y here, a feature by Willy Tarreau will be enabled that
65991 + removes a weakness in Linux's strict implementation of TCP that
65992 + allows two clients to connect to each other without either entering
65993 + a listening state. The weakness allows an attacker to easily prevent
65994 + a client from connecting to a known server provided the source port
65995 + for the connection is guessed correctly.
65996 +
65997 + As the weakness could be used to prevent an antivirus or IPS from
65998 + fetching updates, or prevent an SSL gateway from fetching a CRL,
65999 + it should be eliminated by enabling this option. Though Linux is
66000 + one of few operating systems supporting simultaneous connect, it
66001 + has no legitimate use in practice and is rarely supported by firewalls.
66002 +
66003 +config GRKERNSEC_SOCKET
66004 + bool "Socket restrictions"
66005 + depends on NET
66006 + help
66007 + If you say Y here, you will be able to choose from several options.
66008 + If you assign a GID on your system and add it to the supplementary
66009 + groups of users you want to restrict socket access to, this patch
66010 + will perform up to three things, based on the option(s) you choose.
66011 +
66012 +config GRKERNSEC_SOCKET_ALL
66013 + bool "Deny any sockets to group"
66014 + depends on GRKERNSEC_SOCKET
66015 + help
66016 + If you say Y here, you will be able to choose a GID of whose users will
66017 + be unable to connect to other hosts from your machine or run server
66018 + applications from your machine. If the sysctl option is enabled, a
66019 + sysctl option with name "socket_all" is created.
66020 +
66021 +config GRKERNSEC_SOCKET_ALL_GID
66022 + int "GID to deny all sockets for"
66023 + depends on GRKERNSEC_SOCKET_ALL
66024 + default 1004
66025 + help
66026 + Here you can choose the GID to disable socket access for. Remember to
66027 + add the users you want socket access disabled for to the GID
66028 + specified here. If the sysctl option is enabled, a sysctl option
66029 + with name "socket_all_gid" is created.
66030 +
66031 +config GRKERNSEC_SOCKET_CLIENT
66032 + bool "Deny client sockets to group"
66033 + depends on GRKERNSEC_SOCKET
66034 + help
66035 + If you say Y here, you will be able to choose a GID of whose users will
66036 + be unable to connect to other hosts from your machine, but will be
66037 + able to run servers. If this option is enabled, all users in the group
66038 + you specify will have to use passive mode when initiating ftp transfers
66039 + from the shell on your machine. If the sysctl option is enabled, a
66040 + sysctl option with name "socket_client" is created.
66041 +
66042 +config GRKERNSEC_SOCKET_CLIENT_GID
66043 + int "GID to deny client sockets for"
66044 + depends on GRKERNSEC_SOCKET_CLIENT
66045 + default 1003
66046 + help
66047 + Here you can choose the GID to disable client socket access for.
66048 + Remember to add the users you want client socket access disabled for to
66049 + the GID specified here. If the sysctl option is enabled, a sysctl
66050 + option with name "socket_client_gid" is created.
66051 +
66052 +config GRKERNSEC_SOCKET_SERVER
66053 + bool "Deny server sockets to group"
66054 + depends on GRKERNSEC_SOCKET
66055 + help
66056 + If you say Y here, you will be able to choose a GID of whose users will
66057 + be unable to run server applications from your machine. If the sysctl
66058 + option is enabled, a sysctl option with name "socket_server" is created.
66059 +
66060 +config GRKERNSEC_SOCKET_SERVER_GID
66061 + int "GID to deny server sockets for"
66062 + depends on GRKERNSEC_SOCKET_SERVER
66063 + default 1002
66064 + help
66065 + Here you can choose the GID to disable server socket access for.
66066 + Remember to add the users you want server socket access disabled for to
66067 + the GID specified here. If the sysctl option is enabled, a sysctl
66068 + option with name "socket_server_gid" is created.
66069 +
66070 +endmenu
66071 +
66072 +menu "Physical Protections"
66073 +depends on GRKERNSEC
66074 +
66075 +config GRKERNSEC_DENYUSB
66076 + bool "Deny new USB connections after toggle"
66077 + default y if GRKERNSEC_CONFIG_AUTO
66078 + depends on SYSCTL && USB_SUPPORT
66079 + help
66080 + If you say Y here, a new sysctl option with name "deny_new_usb"
66081 + will be created. Setting its value to 1 will prevent any new
66082 + USB devices from being recognized by the OS. Any attempted USB
66083 + device insertion will be logged. This option is intended to be
66084 + used against custom USB devices designed to exploit vulnerabilities
66085 + in various USB device drivers.
66086 +
66087 + For greatest effectiveness, this sysctl should be set after any
66088 + relevant init scripts. This option is safe to enable in distros
66089 + as each user can choose whether or not to toggle the sysctl.
66090 +
66091 +config GRKERNSEC_DENYUSB_FORCE
66092 + bool "Reject all USB devices not connected at boot"
66093 + select USB
66094 + depends on GRKERNSEC_DENYUSB
66095 + help
66096 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66097 + that doesn't involve a sysctl entry. This option should only be
66098 + enabled if you're sure you want to deny all new USB connections
66099 + at runtime and don't want to modify init scripts. This should not
66100 + be enabled by distros. It forces the core USB code to be built
66101 + into the kernel image so that all devices connected at boot time
66102 + can be recognized and new USB device connections can be prevented
66103 + prior to init running.
66104 +
66105 +endmenu
66106 +
66107 +menu "Sysctl Support"
66108 +depends on GRKERNSEC && SYSCTL
66109 +
66110 +config GRKERNSEC_SYSCTL
66111 + bool "Sysctl support"
66112 + default y if GRKERNSEC_CONFIG_AUTO
66113 + help
66114 + If you say Y here, you will be able to change the options that
66115 + grsecurity runs with at bootup, without having to recompile your
66116 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66117 + to enable (1) or disable (0) various features. All the sysctl entries
66118 + are mutable until the "grsec_lock" entry is set to a non-zero value.
66119 + All features enabled in the kernel configuration are disabled at boot
66120 + if you do not say Y to the "Turn on features by default" option.
66121 + All options should be set at startup, and the grsec_lock entry should
66122 + be set to a non-zero value after all the options are set.
66123 + *THIS IS EXTREMELY IMPORTANT*
66124 +
66125 +config GRKERNSEC_SYSCTL_DISTRO
66126 + bool "Extra sysctl support for distro makers (READ HELP)"
66127 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66128 + help
66129 + If you say Y here, additional sysctl options will be created
66130 + for features that affect processes running as root. Therefore,
66131 + it is critical when using this option that the grsec_lock entry be
66132 + enabled after boot. Only distros with prebuilt kernel packages
66133 + with this option enabled that can ensure grsec_lock is enabled
66134 + after boot should use this option.
66135 + *Failure to set grsec_lock after boot makes all grsec features
66136 + this option covers useless*
66137 +
66138 + Currently this option creates the following sysctl entries:
66139 + "Disable Privileged I/O": "disable_priv_io"
66140 +
66141 +config GRKERNSEC_SYSCTL_ON
66142 + bool "Turn on features by default"
66143 + default y if GRKERNSEC_CONFIG_AUTO
66144 + depends on GRKERNSEC_SYSCTL
66145 + help
66146 + If you say Y here, instead of having all features enabled in the
66147 + kernel configuration disabled at boot time, the features will be
66148 + enabled at boot time. It is recommended you say Y here unless
66149 + there is some reason you would want all sysctl-tunable features to
66150 + be disabled by default. As mentioned elsewhere, it is important
66151 + to enable the grsec_lock entry once you have finished modifying
66152 + the sysctl entries.
66153 +
66154 +endmenu
66155 +menu "Logging Options"
66156 +depends on GRKERNSEC
66157 +
66158 +config GRKERNSEC_FLOODTIME
66159 + int "Seconds in between log messages (minimum)"
66160 + default 10
66161 + help
66162 + This option allows you to enforce the number of seconds between
66163 + grsecurity log messages. The default should be suitable for most
66164 + people, however, if you choose to change it, choose a value small enough
66165 + to allow informative logs to be produced, but large enough to
66166 + prevent flooding.
66167 +
66168 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66169 + any rate limiting on grsecurity log messages.
66170 +
66171 +config GRKERNSEC_FLOODBURST
66172 + int "Number of messages in a burst (maximum)"
66173 + default 6
66174 + help
66175 + This option allows you to choose the maximum number of messages allowed
66176 + within the flood time interval you chose in a separate option. The
66177 + default should be suitable for most people, however if you find that
66178 + many of your logs are being interpreted as flooding, you may want to
66179 + raise this value.
66180 +
66181 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66182 + any rate limiting on grsecurity log messages.
66183 +
66184 +endmenu
66185 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66186 new file mode 100644
66187 index 0000000..5307c8a
66188 --- /dev/null
66189 +++ b/grsecurity/Makefile
66190 @@ -0,0 +1,54 @@
66191 +# grsecurity – access control and security hardening for Linux
66192 +# All code in this directory and various hooks located throughout the Linux kernel are
66193 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66194 +# http://www.grsecurity.net spender@grsecurity.net
66195 +#
66196 +# This program is free software; you can redistribute it and/or
66197 +# modify it under the terms of the GNU General Public License version 2
66198 +# as published by the Free Software Foundation.
66199 +#
66200 +# This program is distributed in the hope that it will be useful,
66201 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
66202 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66203 +# GNU General Public License for more details.
66204 +#
66205 +# You should have received a copy of the GNU General Public License
66206 +# along with this program; if not, write to the Free Software
66207 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66208 +
66209 +KBUILD_CFLAGS += -Werror
66210 +
66211 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66212 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
66213 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66214 + grsec_usb.o grsec_ipc.o
66215 +
66216 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66217 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66218 + gracl_learn.o grsec_log.o gracl_policy.o
66219 +ifdef CONFIG_COMPAT
66220 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66221 +endif
66222 +
66223 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66224 +
66225 +ifdef CONFIG_NET
66226 +obj-y += grsec_sock.o
66227 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66228 +endif
66229 +
66230 +ifndef CONFIG_GRKERNSEC
66231 +obj-y += grsec_disabled.o
66232 +endif
66233 +
66234 +ifdef CONFIG_GRKERNSEC_HIDESYM
66235 +extra-y := grsec_hidesym.o
66236 +$(obj)/grsec_hidesym.o:
66237 + @-chmod -f 500 /boot
66238 + @-chmod -f 500 /lib/modules
66239 + @-chmod -f 500 /lib64/modules
66240 + @-chmod -f 500 /lib32/modules
66241 + @-chmod -f 700 .
66242 + @-chmod -f 700 $(objtree)
66243 + @echo ' grsec: protected kernel image paths'
66244 +endif
66245 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66246 new file mode 100644
66247 index 0000000..e56396f
66248 --- /dev/null
66249 +++ b/grsecurity/gracl.c
66250 @@ -0,0 +1,2679 @@
66251 +#include <linux/kernel.h>
66252 +#include <linux/module.h>
66253 +#include <linux/sched.h>
66254 +#include <linux/mm.h>
66255 +#include <linux/file.h>
66256 +#include <linux/fs.h>
66257 +#include <linux/namei.h>
66258 +#include <linux/mount.h>
66259 +#include <linux/tty.h>
66260 +#include <linux/proc_fs.h>
66261 +#include <linux/lglock.h>
66262 +#include <linux/slab.h>
66263 +#include <linux/vmalloc.h>
66264 +#include <linux/types.h>
66265 +#include <linux/sysctl.h>
66266 +#include <linux/netdevice.h>
66267 +#include <linux/ptrace.h>
66268 +#include <linux/gracl.h>
66269 +#include <linux/gralloc.h>
66270 +#include <linux/security.h>
66271 +#include <linux/grinternal.h>
66272 +#include <linux/pid_namespace.h>
66273 +#include <linux/stop_machine.h>
66274 +#include <linux/fdtable.h>
66275 +#include <linux/percpu.h>
66276 +#include <linux/lglock.h>
66277 +#include <linux/hugetlb.h>
66278 +#include <linux/posix-timers.h>
66279 +#include <linux/prefetch.h>
66280 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66281 +#include <linux/magic.h>
66282 +#include <linux/pagemap.h>
66283 +#include "../fs/btrfs/async-thread.h"
66284 +#include "../fs/btrfs/ctree.h"
66285 +#include "../fs/btrfs/btrfs_inode.h"
66286 +#endif
66287 +#include "../fs/mount.h"
66288 +
66289 +#include <asm/uaccess.h>
66290 +#include <asm/errno.h>
66291 +#include <asm/mman.h>
66292 +
66293 +#define FOR_EACH_ROLE_START(role) \
66294 + role = running_polstate.role_list; \
66295 + while (role) {
66296 +
66297 +#define FOR_EACH_ROLE_END(role) \
66298 + role = role->prev; \
66299 + }
66300 +
66301 +extern struct path gr_real_root;
66302 +
66303 +static struct gr_policy_state running_polstate;
66304 +struct gr_policy_state *polstate = &running_polstate;
66305 +extern struct gr_alloc_state *current_alloc_state;
66306 +
66307 +extern char *gr_shared_page[4];
66308 +DEFINE_RWLOCK(gr_inode_lock);
66309 +
66310 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
66311 +
66312 +#ifdef CONFIG_NET
66313 +extern struct vfsmount *sock_mnt;
66314 +#endif
66315 +
66316 +extern struct vfsmount *pipe_mnt;
66317 +extern struct vfsmount *shm_mnt;
66318 +
66319 +#ifdef CONFIG_HUGETLBFS
66320 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
66321 +#endif
66322 +
66323 +extern u16 acl_sp_role_value;
66324 +extern struct acl_object_label *fakefs_obj_rw;
66325 +extern struct acl_object_label *fakefs_obj_rwx;
66326 +
66327 +int gr_acl_is_enabled(void)
66328 +{
66329 + return (gr_status & GR_READY);
66330 +}
66331 +
66332 +void gr_enable_rbac_system(void)
66333 +{
66334 + pax_open_kernel();
66335 + gr_status |= GR_READY;
66336 + pax_close_kernel();
66337 +}
66338 +
66339 +int gr_rbac_disable(void *unused)
66340 +{
66341 + pax_open_kernel();
66342 + gr_status &= ~GR_READY;
66343 + pax_close_kernel();
66344 +
66345 + return 0;
66346 +}
66347 +
66348 +static inline dev_t __get_dev(const struct dentry *dentry)
66349 +{
66350 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66351 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66352 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
66353 + else
66354 +#endif
66355 + return dentry->d_sb->s_dev;
66356 +}
66357 +
66358 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
66359 +{
66360 + return __get_dev(dentry);
66361 +}
66362 +
66363 +static char gr_task_roletype_to_char(struct task_struct *task)
66364 +{
66365 + switch (task->role->roletype &
66366 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
66367 + GR_ROLE_SPECIAL)) {
66368 + case GR_ROLE_DEFAULT:
66369 + return 'D';
66370 + case GR_ROLE_USER:
66371 + return 'U';
66372 + case GR_ROLE_GROUP:
66373 + return 'G';
66374 + case GR_ROLE_SPECIAL:
66375 + return 'S';
66376 + }
66377 +
66378 + return 'X';
66379 +}
66380 +
66381 +char gr_roletype_to_char(void)
66382 +{
66383 + return gr_task_roletype_to_char(current);
66384 +}
66385 +
66386 +__inline__ int
66387 +gr_acl_tpe_check(void)
66388 +{
66389 + if (unlikely(!(gr_status & GR_READY)))
66390 + return 0;
66391 + if (current->role->roletype & GR_ROLE_TPE)
66392 + return 1;
66393 + else
66394 + return 0;
66395 +}
66396 +
66397 +int
66398 +gr_handle_rawio(const struct inode *inode)
66399 +{
66400 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66401 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
66402 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
66403 + !capable(CAP_SYS_RAWIO))
66404 + return 1;
66405 +#endif
66406 + return 0;
66407 +}
66408 +
66409 +int
66410 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
66411 +{
66412 + if (likely(lena != lenb))
66413 + return 0;
66414 +
66415 + return !memcmp(a, b, lena);
66416 +}
66417 +
66418 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
66419 +{
66420 + *buflen -= namelen;
66421 + if (*buflen < 0)
66422 + return -ENAMETOOLONG;
66423 + *buffer -= namelen;
66424 + memcpy(*buffer, str, namelen);
66425 + return 0;
66426 +}
66427 +
66428 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
66429 +{
66430 + return prepend(buffer, buflen, name->name, name->len);
66431 +}
66432 +
66433 +static int prepend_path(const struct path *path, struct path *root,
66434 + char **buffer, int *buflen)
66435 +{
66436 + struct dentry *dentry = path->dentry;
66437 + struct vfsmount *vfsmnt = path->mnt;
66438 + struct mount *mnt = real_mount(vfsmnt);
66439 + bool slash = false;
66440 + int error = 0;
66441 +
66442 + while (dentry != root->dentry || vfsmnt != root->mnt) {
66443 + struct dentry * parent;
66444 +
66445 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
66446 + /* Global root? */
66447 + if (!mnt_has_parent(mnt)) {
66448 + goto out;
66449 + }
66450 + dentry = mnt->mnt_mountpoint;
66451 + mnt = mnt->mnt_parent;
66452 + vfsmnt = &mnt->mnt;
66453 + continue;
66454 + }
66455 + parent = dentry->d_parent;
66456 + prefetch(parent);
66457 + spin_lock(&dentry->d_lock);
66458 + error = prepend_name(buffer, buflen, &dentry->d_name);
66459 + spin_unlock(&dentry->d_lock);
66460 + if (!error)
66461 + error = prepend(buffer, buflen, "/", 1);
66462 + if (error)
66463 + break;
66464 +
66465 + slash = true;
66466 + dentry = parent;
66467 + }
66468 +
66469 +out:
66470 + if (!error && !slash)
66471 + error = prepend(buffer, buflen, "/", 1);
66472 +
66473 + return error;
66474 +}
66475 +
66476 +/* this must be called with mount_lock and rename_lock held */
66477 +
66478 +static char *__our_d_path(const struct path *path, struct path *root,
66479 + char *buf, int buflen)
66480 +{
66481 + char *res = buf + buflen;
66482 + int error;
66483 +
66484 + prepend(&res, &buflen, "\0", 1);
66485 + error = prepend_path(path, root, &res, &buflen);
66486 + if (error)
66487 + return ERR_PTR(error);
66488 +
66489 + return res;
66490 +}
66491 +
66492 +static char *
66493 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
66494 +{
66495 + char *retval;
66496 +
66497 + retval = __our_d_path(path, root, buf, buflen);
66498 + if (unlikely(IS_ERR(retval)))
66499 + retval = strcpy(buf, "<path too long>");
66500 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
66501 + retval[1] = '\0';
66502 +
66503 + return retval;
66504 +}
66505 +
66506 +static char *
66507 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66508 + char *buf, int buflen)
66509 +{
66510 + struct path path;
66511 + char *res;
66512 +
66513 + path.dentry = (struct dentry *)dentry;
66514 + path.mnt = (struct vfsmount *)vfsmnt;
66515 +
66516 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
66517 + by the RBAC system */
66518 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
66519 +
66520 + return res;
66521 +}
66522 +
66523 +static char *
66524 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66525 + char *buf, int buflen)
66526 +{
66527 + char *res;
66528 + struct path path;
66529 + struct path root;
66530 + struct task_struct *reaper = init_pid_ns.child_reaper;
66531 +
66532 + path.dentry = (struct dentry *)dentry;
66533 + path.mnt = (struct vfsmount *)vfsmnt;
66534 +
66535 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
66536 + get_fs_root(reaper->fs, &root);
66537 +
66538 + read_seqlock_excl(&mount_lock);
66539 + write_seqlock(&rename_lock);
66540 + res = gen_full_path(&path, &root, buf, buflen);
66541 + write_sequnlock(&rename_lock);
66542 + read_sequnlock_excl(&mount_lock);
66543 +
66544 + path_put(&root);
66545 + return res;
66546 +}
66547 +
66548 +char *
66549 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66550 +{
66551 + char *ret;
66552 + read_seqlock_excl(&mount_lock);
66553 + write_seqlock(&rename_lock);
66554 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66555 + PAGE_SIZE);
66556 + write_sequnlock(&rename_lock);
66557 + read_sequnlock_excl(&mount_lock);
66558 + return ret;
66559 +}
66560 +
66561 +static char *
66562 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66563 +{
66564 + char *ret;
66565 + char *buf;
66566 + int buflen;
66567 +
66568 + read_seqlock_excl(&mount_lock);
66569 + write_seqlock(&rename_lock);
66570 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
66571 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
66572 + buflen = (int)(ret - buf);
66573 + if (buflen >= 5)
66574 + prepend(&ret, &buflen, "/proc", 5);
66575 + else
66576 + ret = strcpy(buf, "<path too long>");
66577 + write_sequnlock(&rename_lock);
66578 + read_sequnlock_excl(&mount_lock);
66579 + return ret;
66580 +}
66581 +
66582 +char *
66583 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
66584 +{
66585 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66586 + PAGE_SIZE);
66587 +}
66588 +
66589 +char *
66590 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
66591 +{
66592 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66593 + PAGE_SIZE);
66594 +}
66595 +
66596 +char *
66597 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
66598 +{
66599 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
66600 + PAGE_SIZE);
66601 +}
66602 +
66603 +char *
66604 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
66605 +{
66606 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
66607 + PAGE_SIZE);
66608 +}
66609 +
66610 +char *
66611 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
66612 +{
66613 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
66614 + PAGE_SIZE);
66615 +}
66616 +
66617 +__inline__ __u32
66618 +to_gr_audit(const __u32 reqmode)
66619 +{
66620 + /* masks off auditable permission flags, then shifts them to create
66621 + auditing flags, and adds the special case of append auditing if
66622 + we're requesting write */
66623 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
66624 +}
66625 +
66626 +struct acl_role_label *
66627 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
66628 + const gid_t gid)
66629 +{
66630 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
66631 + struct acl_role_label *match;
66632 + struct role_allowed_ip *ipp;
66633 + unsigned int x;
66634 + u32 curr_ip = task->signal->saved_ip;
66635 +
66636 + match = state->acl_role_set.r_hash[index];
66637 +
66638 + while (match) {
66639 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
66640 + for (x = 0; x < match->domain_child_num; x++) {
66641 + if (match->domain_children[x] == uid)
66642 + goto found;
66643 + }
66644 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
66645 + break;
66646 + match = match->next;
66647 + }
66648 +found:
66649 + if (match == NULL) {
66650 + try_group:
66651 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
66652 + match = state->acl_role_set.r_hash[index];
66653 +
66654 + while (match) {
66655 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
66656 + for (x = 0; x < match->domain_child_num; x++) {
66657 + if (match->domain_children[x] == gid)
66658 + goto found2;
66659 + }
66660 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
66661 + break;
66662 + match = match->next;
66663 + }
66664 +found2:
66665 + if (match == NULL)
66666 + match = state->default_role;
66667 + if (match->allowed_ips == NULL)
66668 + return match;
66669 + else {
66670 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66671 + if (likely
66672 + ((ntohl(curr_ip) & ipp->netmask) ==
66673 + (ntohl(ipp->addr) & ipp->netmask)))
66674 + return match;
66675 + }
66676 + match = state->default_role;
66677 + }
66678 + } else if (match->allowed_ips == NULL) {
66679 + return match;
66680 + } else {
66681 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66682 + if (likely
66683 + ((ntohl(curr_ip) & ipp->netmask) ==
66684 + (ntohl(ipp->addr) & ipp->netmask)))
66685 + return match;
66686 + }
66687 + goto try_group;
66688 + }
66689 +
66690 + return match;
66691 +}
66692 +
66693 +static struct acl_role_label *
66694 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
66695 + const gid_t gid)
66696 +{
66697 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
66698 +}
66699 +
66700 +struct acl_subject_label *
66701 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
66702 + const struct acl_role_label *role)
66703 +{
66704 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66705 + struct acl_subject_label *match;
66706 +
66707 + match = role->subj_hash[index];
66708 +
66709 + while (match && (match->inode != ino || match->device != dev ||
66710 + (match->mode & GR_DELETED))) {
66711 + match = match->next;
66712 + }
66713 +
66714 + if (match && !(match->mode & GR_DELETED))
66715 + return match;
66716 + else
66717 + return NULL;
66718 +}
66719 +
66720 +struct acl_subject_label *
66721 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
66722 + const struct acl_role_label *role)
66723 +{
66724 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66725 + struct acl_subject_label *match;
66726 +
66727 + match = role->subj_hash[index];
66728 +
66729 + while (match && (match->inode != ino || match->device != dev ||
66730 + !(match->mode & GR_DELETED))) {
66731 + match = match->next;
66732 + }
66733 +
66734 + if (match && (match->mode & GR_DELETED))
66735 + return match;
66736 + else
66737 + return NULL;
66738 +}
66739 +
66740 +static struct acl_object_label *
66741 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
66742 + const struct acl_subject_label *subj)
66743 +{
66744 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
66745 + struct acl_object_label *match;
66746 +
66747 + match = subj->obj_hash[index];
66748 +
66749 + while (match && (match->inode != ino || match->device != dev ||
66750 + (match->mode & GR_DELETED))) {
66751 + match = match->next;
66752 + }
66753 +
66754 + if (match && !(match->mode & GR_DELETED))
66755 + return match;
66756 + else
66757 + return NULL;
66758 +}
66759 +
66760 +static struct acl_object_label *
66761 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
66762 + const struct acl_subject_label *subj)
66763 +{
66764 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
66765 + struct acl_object_label *match;
66766 +
66767 + match = subj->obj_hash[index];
66768 +
66769 + while (match && (match->inode != ino || match->device != dev ||
66770 + !(match->mode & GR_DELETED))) {
66771 + match = match->next;
66772 + }
66773 +
66774 + if (match && (match->mode & GR_DELETED))
66775 + return match;
66776 +
66777 + match = subj->obj_hash[index];
66778 +
66779 + while (match && (match->inode != ino || match->device != dev ||
66780 + (match->mode & GR_DELETED))) {
66781 + match = match->next;
66782 + }
66783 +
66784 + if (match && !(match->mode & GR_DELETED))
66785 + return match;
66786 + else
66787 + return NULL;
66788 +}
66789 +
66790 +struct name_entry *
66791 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
66792 +{
66793 + unsigned int len = strlen(name);
66794 + unsigned int key = full_name_hash(name, len);
66795 + unsigned int index = key % state->name_set.n_size;
66796 + struct name_entry *match;
66797 +
66798 + match = state->name_set.n_hash[index];
66799 +
66800 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
66801 + match = match->next;
66802 +
66803 + return match;
66804 +}
66805 +
66806 +static struct name_entry *
66807 +lookup_name_entry(const char *name)
66808 +{
66809 + return __lookup_name_entry(&running_polstate, name);
66810 +}
66811 +
66812 +static struct name_entry *
66813 +lookup_name_entry_create(const char *name)
66814 +{
66815 + unsigned int len = strlen(name);
66816 + unsigned int key = full_name_hash(name, len);
66817 + unsigned int index = key % running_polstate.name_set.n_size;
66818 + struct name_entry *match;
66819 +
66820 + match = running_polstate.name_set.n_hash[index];
66821 +
66822 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66823 + !match->deleted))
66824 + match = match->next;
66825 +
66826 + if (match && match->deleted)
66827 + return match;
66828 +
66829 + match = running_polstate.name_set.n_hash[index];
66830 +
66831 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66832 + match->deleted))
66833 + match = match->next;
66834 +
66835 + if (match && !match->deleted)
66836 + return match;
66837 + else
66838 + return NULL;
66839 +}
66840 +
66841 +static struct inodev_entry *
66842 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
66843 +{
66844 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
66845 + struct inodev_entry *match;
66846 +
66847 + match = running_polstate.inodev_set.i_hash[index];
66848 +
66849 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
66850 + match = match->next;
66851 +
66852 + return match;
66853 +}
66854 +
66855 +void
66856 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
66857 +{
66858 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
66859 + state->inodev_set.i_size);
66860 + struct inodev_entry **curr;
66861 +
66862 + entry->prev = NULL;
66863 +
66864 + curr = &state->inodev_set.i_hash[index];
66865 + if (*curr != NULL)
66866 + (*curr)->prev = entry;
66867 +
66868 + entry->next = *curr;
66869 + *curr = entry;
66870 +
66871 + return;
66872 +}
66873 +
66874 +static void
66875 +insert_inodev_entry(struct inodev_entry *entry)
66876 +{
66877 + __insert_inodev_entry(&running_polstate, entry);
66878 +}
66879 +
66880 +void
66881 +insert_acl_obj_label(struct acl_object_label *obj,
66882 + struct acl_subject_label *subj)
66883 +{
66884 + unsigned int index =
66885 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
66886 + struct acl_object_label **curr;
66887 +
66888 + obj->prev = NULL;
66889 +
66890 + curr = &subj->obj_hash[index];
66891 + if (*curr != NULL)
66892 + (*curr)->prev = obj;
66893 +
66894 + obj->next = *curr;
66895 + *curr = obj;
66896 +
66897 + return;
66898 +}
66899 +
66900 +void
66901 +insert_acl_subj_label(struct acl_subject_label *obj,
66902 + struct acl_role_label *role)
66903 +{
66904 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
66905 + struct acl_subject_label **curr;
66906 +
66907 + obj->prev = NULL;
66908 +
66909 + curr = &role->subj_hash[index];
66910 + if (*curr != NULL)
66911 + (*curr)->prev = obj;
66912 +
66913 + obj->next = *curr;
66914 + *curr = obj;
66915 +
66916 + return;
66917 +}
66918 +
66919 +/* derived from glibc fnmatch() 0: match, 1: no match*/
66920 +
66921 +static int
66922 +glob_match(const char *p, const char *n)
66923 +{
66924 + char c;
66925 +
66926 + while ((c = *p++) != '\0') {
66927 + switch (c) {
66928 + case '?':
66929 + if (*n == '\0')
66930 + return 1;
66931 + else if (*n == '/')
66932 + return 1;
66933 + break;
66934 + case '\\':
66935 + if (*n != c)
66936 + return 1;
66937 + break;
66938 + case '*':
66939 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
66940 + if (*n == '/')
66941 + return 1;
66942 + else if (c == '?') {
66943 + if (*n == '\0')
66944 + return 1;
66945 + else
66946 + ++n;
66947 + }
66948 + }
66949 + if (c == '\0') {
66950 + return 0;
66951 + } else {
66952 + const char *endp;
66953 +
66954 + if ((endp = strchr(n, '/')) == NULL)
66955 + endp = n + strlen(n);
66956 +
66957 + if (c == '[') {
66958 + for (--p; n < endp; ++n)
66959 + if (!glob_match(p, n))
66960 + return 0;
66961 + } else if (c == '/') {
66962 + while (*n != '\0' && *n != '/')
66963 + ++n;
66964 + if (*n == '/' && !glob_match(p, n + 1))
66965 + return 0;
66966 + } else {
66967 + for (--p; n < endp; ++n)
66968 + if (*n == c && !glob_match(p, n))
66969 + return 0;
66970 + }
66971 +
66972 + return 1;
66973 + }
66974 + case '[':
66975 + {
66976 + int not;
66977 + char cold;
66978 +
66979 + if (*n == '\0' || *n == '/')
66980 + return 1;
66981 +
66982 + not = (*p == '!' || *p == '^');
66983 + if (not)
66984 + ++p;
66985 +
66986 + c = *p++;
66987 + for (;;) {
66988 + unsigned char fn = (unsigned char)*n;
66989 +
66990 + if (c == '\0')
66991 + return 1;
66992 + else {
66993 + if (c == fn)
66994 + goto matched;
66995 + cold = c;
66996 + c = *p++;
66997 +
66998 + if (c == '-' && *p != ']') {
66999 + unsigned char cend = *p++;
67000 +
67001 + if (cend == '\0')
67002 + return 1;
67003 +
67004 + if (cold <= fn && fn <= cend)
67005 + goto matched;
67006 +
67007 + c = *p++;
67008 + }
67009 + }
67010 +
67011 + if (c == ']')
67012 + break;
67013 + }
67014 + if (!not)
67015 + return 1;
67016 + break;
67017 + matched:
67018 + while (c != ']') {
67019 + if (c == '\0')
67020 + return 1;
67021 +
67022 + c = *p++;
67023 + }
67024 + if (not)
67025 + return 1;
67026 + }
67027 + break;
67028 + default:
67029 + if (c != *n)
67030 + return 1;
67031 + }
67032 +
67033 + ++n;
67034 + }
67035 +
67036 + if (*n == '\0')
67037 + return 0;
67038 +
67039 + if (*n == '/')
67040 + return 0;
67041 +
67042 + return 1;
67043 +}
67044 +
67045 +static struct acl_object_label *
67046 +chk_glob_label(struct acl_object_label *globbed,
67047 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67048 +{
67049 + struct acl_object_label *tmp;
67050 +
67051 + if (*path == NULL)
67052 + *path = gr_to_filename_nolock(dentry, mnt);
67053 +
67054 + tmp = globbed;
67055 +
67056 + while (tmp) {
67057 + if (!glob_match(tmp->filename, *path))
67058 + return tmp;
67059 + tmp = tmp->next;
67060 + }
67061 +
67062 + return NULL;
67063 +}
67064 +
67065 +static struct acl_object_label *
67066 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67067 + const ino_t curr_ino, const dev_t curr_dev,
67068 + const struct acl_subject_label *subj, char **path, const int checkglob)
67069 +{
67070 + struct acl_subject_label *tmpsubj;
67071 + struct acl_object_label *retval;
67072 + struct acl_object_label *retval2;
67073 +
67074 + tmpsubj = (struct acl_subject_label *) subj;
67075 + read_lock(&gr_inode_lock);
67076 + do {
67077 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67078 + if (retval) {
67079 + if (checkglob && retval->globbed) {
67080 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67081 + if (retval2)
67082 + retval = retval2;
67083 + }
67084 + break;
67085 + }
67086 + } while ((tmpsubj = tmpsubj->parent_subject));
67087 + read_unlock(&gr_inode_lock);
67088 +
67089 + return retval;
67090 +}
67091 +
67092 +static __inline__ struct acl_object_label *
67093 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67094 + struct dentry *curr_dentry,
67095 + const struct acl_subject_label *subj, char **path, const int checkglob)
67096 +{
67097 + int newglob = checkglob;
67098 + ino_t inode;
67099 + dev_t device;
67100 +
67101 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67102 + as we don't want a / * rule to match instead of the / object
67103 + don't do this for create lookups that call this function though, since they're looking up
67104 + on the parent and thus need globbing checks on all paths
67105 + */
67106 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67107 + newglob = GR_NO_GLOB;
67108 +
67109 + spin_lock(&curr_dentry->d_lock);
67110 + inode = curr_dentry->d_inode->i_ino;
67111 + device = __get_dev(curr_dentry);
67112 + spin_unlock(&curr_dentry->d_lock);
67113 +
67114 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67115 +}
67116 +
67117 +#ifdef CONFIG_HUGETLBFS
67118 +static inline bool
67119 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
67120 +{
67121 + int i;
67122 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67123 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67124 + return true;
67125 + }
67126 +
67127 + return false;
67128 +}
67129 +#endif
67130 +
67131 +static struct acl_object_label *
67132 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67133 + const struct acl_subject_label *subj, char *path, const int checkglob)
67134 +{
67135 + struct dentry *dentry = (struct dentry *) l_dentry;
67136 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67137 + struct mount *real_mnt = real_mount(mnt);
67138 + struct acl_object_label *retval;
67139 + struct dentry *parent;
67140 +
67141 + read_seqlock_excl(&mount_lock);
67142 + write_seqlock(&rename_lock);
67143 +
67144 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67145 +#ifdef CONFIG_NET
67146 + mnt == sock_mnt ||
67147 +#endif
67148 +#ifdef CONFIG_HUGETLBFS
67149 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67150 +#endif
67151 + /* ignore Eric Biederman */
67152 + IS_PRIVATE(l_dentry->d_inode))) {
67153 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67154 + goto out;
67155 + }
67156 +
67157 + for (;;) {
67158 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67159 + break;
67160 +
67161 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67162 + if (!mnt_has_parent(real_mnt))
67163 + break;
67164 +
67165 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67166 + if (retval != NULL)
67167 + goto out;
67168 +
67169 + dentry = real_mnt->mnt_mountpoint;
67170 + real_mnt = real_mnt->mnt_parent;
67171 + mnt = &real_mnt->mnt;
67172 + continue;
67173 + }
67174 +
67175 + parent = dentry->d_parent;
67176 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67177 + if (retval != NULL)
67178 + goto out;
67179 +
67180 + dentry = parent;
67181 + }
67182 +
67183 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67184 +
67185 + /* gr_real_root is pinned so we don't have to hold a reference */
67186 + if (retval == NULL)
67187 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67188 +out:
67189 + write_sequnlock(&rename_lock);
67190 + read_sequnlock_excl(&mount_lock);
67191 +
67192 + BUG_ON(retval == NULL);
67193 +
67194 + return retval;
67195 +}
67196 +
67197 +static __inline__ struct acl_object_label *
67198 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67199 + const struct acl_subject_label *subj)
67200 +{
67201 + char *path = NULL;
67202 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67203 +}
67204 +
67205 +static __inline__ struct acl_object_label *
67206 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67207 + const struct acl_subject_label *subj)
67208 +{
67209 + char *path = NULL;
67210 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67211 +}
67212 +
67213 +static __inline__ struct acl_object_label *
67214 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67215 + const struct acl_subject_label *subj, char *path)
67216 +{
67217 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67218 +}
67219 +
67220 +struct acl_subject_label *
67221 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67222 + const struct acl_role_label *role)
67223 +{
67224 + struct dentry *dentry = (struct dentry *) l_dentry;
67225 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67226 + struct mount *real_mnt = real_mount(mnt);
67227 + struct acl_subject_label *retval;
67228 + struct dentry *parent;
67229 +
67230 + read_seqlock_excl(&mount_lock);
67231 + write_seqlock(&rename_lock);
67232 +
67233 + for (;;) {
67234 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67235 + break;
67236 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67237 + if (!mnt_has_parent(real_mnt))
67238 + break;
67239 +
67240 + spin_lock(&dentry->d_lock);
67241 + read_lock(&gr_inode_lock);
67242 + retval =
67243 + lookup_acl_subj_label(dentry->d_inode->i_ino,
67244 + __get_dev(dentry), role);
67245 + read_unlock(&gr_inode_lock);
67246 + spin_unlock(&dentry->d_lock);
67247 + if (retval != NULL)
67248 + goto out;
67249 +
67250 + dentry = real_mnt->mnt_mountpoint;
67251 + real_mnt = real_mnt->mnt_parent;
67252 + mnt = &real_mnt->mnt;
67253 + continue;
67254 + }
67255 +
67256 + spin_lock(&dentry->d_lock);
67257 + read_lock(&gr_inode_lock);
67258 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67259 + __get_dev(dentry), role);
67260 + read_unlock(&gr_inode_lock);
67261 + parent = dentry->d_parent;
67262 + spin_unlock(&dentry->d_lock);
67263 +
67264 + if (retval != NULL)
67265 + goto out;
67266 +
67267 + dentry = parent;
67268 + }
67269 +
67270 + spin_lock(&dentry->d_lock);
67271 + read_lock(&gr_inode_lock);
67272 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67273 + __get_dev(dentry), role);
67274 + read_unlock(&gr_inode_lock);
67275 + spin_unlock(&dentry->d_lock);
67276 +
67277 + if (unlikely(retval == NULL)) {
67278 + /* gr_real_root is pinned, we don't need to hold a reference */
67279 + read_lock(&gr_inode_lock);
67280 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67281 + __get_dev(gr_real_root.dentry), role);
67282 + read_unlock(&gr_inode_lock);
67283 + }
67284 +out:
67285 + write_sequnlock(&rename_lock);
67286 + read_sequnlock_excl(&mount_lock);
67287 +
67288 + BUG_ON(retval == NULL);
67289 +
67290 + return retval;
67291 +}
67292 +
67293 +void
67294 +assign_special_role(const char *rolename)
67295 +{
67296 + struct acl_object_label *obj;
67297 + struct acl_role_label *r;
67298 + struct acl_role_label *assigned = NULL;
67299 + struct task_struct *tsk;
67300 + struct file *filp;
67301 +
67302 + FOR_EACH_ROLE_START(r)
67303 + if (!strcmp(rolename, r->rolename) &&
67304 + (r->roletype & GR_ROLE_SPECIAL)) {
67305 + assigned = r;
67306 + break;
67307 + }
67308 + FOR_EACH_ROLE_END(r)
67309 +
67310 + if (!assigned)
67311 + return;
67312 +
67313 + read_lock(&tasklist_lock);
67314 + read_lock(&grsec_exec_file_lock);
67315 +
67316 + tsk = current->real_parent;
67317 + if (tsk == NULL)
67318 + goto out_unlock;
67319 +
67320 + filp = tsk->exec_file;
67321 + if (filp == NULL)
67322 + goto out_unlock;
67323 +
67324 + tsk->is_writable = 0;
67325 + tsk->inherited = 0;
67326 +
67327 + tsk->acl_sp_role = 1;
67328 + tsk->acl_role_id = ++acl_sp_role_value;
67329 + tsk->role = assigned;
67330 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
67331 +
67332 + /* ignore additional mmap checks for processes that are writable
67333 + by the default ACL */
67334 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67335 + if (unlikely(obj->mode & GR_WRITE))
67336 + tsk->is_writable = 1;
67337 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
67338 + if (unlikely(obj->mode & GR_WRITE))
67339 + tsk->is_writable = 1;
67340 +
67341 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67342 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
67343 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
67344 +#endif
67345 +
67346 +out_unlock:
67347 + read_unlock(&grsec_exec_file_lock);
67348 + read_unlock(&tasklist_lock);
67349 + return;
67350 +}
67351 +
67352 +
67353 +static void
67354 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
67355 +{
67356 + struct task_struct *task = current;
67357 + const struct cred *cred = current_cred();
67358 +
67359 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
67360 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67361 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67362 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
67363 +
67364 + return;
67365 +}
67366 +
67367 +static void
67368 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
67369 +{
67370 + struct task_struct *task = current;
67371 + const struct cred *cred = current_cred();
67372 +
67373 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67374 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67375 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67376 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
67377 +
67378 + return;
67379 +}
67380 +
67381 +static void
67382 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
67383 +{
67384 + struct task_struct *task = current;
67385 + const struct cred *cred = current_cred();
67386 +
67387 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67388 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67389 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67390 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
67391 +
67392 + return;
67393 +}
67394 +
67395 +static void
67396 +gr_set_proc_res(struct task_struct *task)
67397 +{
67398 + struct acl_subject_label *proc;
67399 + unsigned short i;
67400 +
67401 + proc = task->acl;
67402 +
67403 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
67404 + return;
67405 +
67406 + for (i = 0; i < RLIM_NLIMITS; i++) {
67407 + if (!(proc->resmask & (1U << i)))
67408 + continue;
67409 +
67410 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
67411 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
67412 +
67413 + if (i == RLIMIT_CPU)
67414 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
67415 + }
67416 +
67417 + return;
67418 +}
67419 +
67420 +/* both of the below must be called with
67421 + rcu_read_lock();
67422 + read_lock(&tasklist_lock);
67423 + read_lock(&grsec_exec_file_lock);
67424 +*/
67425 +
67426 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
67427 +{
67428 + char *tmpname;
67429 + struct acl_subject_label *tmpsubj;
67430 + struct file *filp;
67431 + struct name_entry *nmatch;
67432 +
67433 + filp = task->exec_file;
67434 + if (filp == NULL)
67435 + return NULL;
67436 +
67437 + /* the following is to apply the correct subject
67438 + on binaries running when the RBAC system
67439 + is enabled, when the binaries have been
67440 + replaced or deleted since their execution
67441 + -----
67442 + when the RBAC system starts, the inode/dev
67443 + from exec_file will be one the RBAC system
67444 + is unaware of. It only knows the inode/dev
67445 + of the present file on disk, or the absence
67446 + of it.
67447 + */
67448 +
67449 + if (filename)
67450 + nmatch = __lookup_name_entry(state, filename);
67451 + else {
67452 + preempt_disable();
67453 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
67454 +
67455 + nmatch = __lookup_name_entry(state, tmpname);
67456 + preempt_enable();
67457 + }
67458 + tmpsubj = NULL;
67459 + if (nmatch) {
67460 + if (nmatch->deleted)
67461 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
67462 + else
67463 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
67464 + }
67465 + /* this also works for the reload case -- if we don't match a potentially inherited subject
67466 + then we fall back to a normal lookup based on the binary's ino/dev
67467 + */
67468 + if (tmpsubj == NULL)
67469 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
67470 +
67471 + return tmpsubj;
67472 +}
67473 +
67474 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
67475 +{
67476 + return __gr_get_subject_for_task(&running_polstate, task, filename);
67477 +}
67478 +
67479 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
67480 +{
67481 + struct acl_object_label *obj;
67482 + struct file *filp;
67483 +
67484 + filp = task->exec_file;
67485 +
67486 + task->acl = subj;
67487 + task->is_writable = 0;
67488 + /* ignore additional mmap checks for processes that are writable
67489 + by the default ACL */
67490 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
67491 + if (unlikely(obj->mode & GR_WRITE))
67492 + task->is_writable = 1;
67493 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67494 + if (unlikely(obj->mode & GR_WRITE))
67495 + task->is_writable = 1;
67496 +
67497 + gr_set_proc_res(task);
67498 +
67499 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67500 + 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);
67501 +#endif
67502 +}
67503 +
67504 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
67505 +{
67506 + __gr_apply_subject_to_task(&running_polstate, task, subj);
67507 +}
67508 +
67509 +__u32
67510 +gr_search_file(const struct dentry * dentry, const __u32 mode,
67511 + const struct vfsmount * mnt)
67512 +{
67513 + __u32 retval = mode;
67514 + struct acl_subject_label *curracl;
67515 + struct acl_object_label *currobj;
67516 +
67517 + if (unlikely(!(gr_status & GR_READY)))
67518 + return (mode & ~GR_AUDITS);
67519 +
67520 + curracl = current->acl;
67521 +
67522 + currobj = chk_obj_label(dentry, mnt, curracl);
67523 + retval = currobj->mode & mode;
67524 +
67525 + /* if we're opening a specified transfer file for writing
67526 + (e.g. /dev/initctl), then transfer our role to init
67527 + */
67528 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
67529 + current->role->roletype & GR_ROLE_PERSIST)) {
67530 + struct task_struct *task = init_pid_ns.child_reaper;
67531 +
67532 + if (task->role != current->role) {
67533 + struct acl_subject_label *subj;
67534 +
67535 + task->acl_sp_role = 0;
67536 + task->acl_role_id = current->acl_role_id;
67537 + task->role = current->role;
67538 + rcu_read_lock();
67539 + read_lock(&grsec_exec_file_lock);
67540 + subj = gr_get_subject_for_task(task, NULL);
67541 + gr_apply_subject_to_task(task, subj);
67542 + read_unlock(&grsec_exec_file_lock);
67543 + rcu_read_unlock();
67544 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
67545 + }
67546 + }
67547 +
67548 + if (unlikely
67549 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
67550 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
67551 + __u32 new_mode = mode;
67552 +
67553 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67554 +
67555 + retval = new_mode;
67556 +
67557 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
67558 + new_mode |= GR_INHERIT;
67559 +
67560 + if (!(mode & GR_NOLEARN))
67561 + gr_log_learn(dentry, mnt, new_mode);
67562 + }
67563 +
67564 + return retval;
67565 +}
67566 +
67567 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
67568 + const struct dentry *parent,
67569 + const struct vfsmount *mnt)
67570 +{
67571 + struct name_entry *match;
67572 + struct acl_object_label *matchpo;
67573 + struct acl_subject_label *curracl;
67574 + char *path;
67575 +
67576 + if (unlikely(!(gr_status & GR_READY)))
67577 + return NULL;
67578 +
67579 + preempt_disable();
67580 + path = gr_to_filename_rbac(new_dentry, mnt);
67581 + match = lookup_name_entry_create(path);
67582 +
67583 + curracl = current->acl;
67584 +
67585 + if (match) {
67586 + read_lock(&gr_inode_lock);
67587 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
67588 + read_unlock(&gr_inode_lock);
67589 +
67590 + if (matchpo) {
67591 + preempt_enable();
67592 + return matchpo;
67593 + }
67594 + }
67595 +
67596 + // lookup parent
67597 +
67598 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
67599 +
67600 + preempt_enable();
67601 + return matchpo;
67602 +}
67603 +
67604 +__u32
67605 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
67606 + const struct vfsmount * mnt, const __u32 mode)
67607 +{
67608 + struct acl_object_label *matchpo;
67609 + __u32 retval;
67610 +
67611 + if (unlikely(!(gr_status & GR_READY)))
67612 + return (mode & ~GR_AUDITS);
67613 +
67614 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
67615 +
67616 + retval = matchpo->mode & mode;
67617 +
67618 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
67619 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67620 + __u32 new_mode = mode;
67621 +
67622 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67623 +
67624 + gr_log_learn(new_dentry, mnt, new_mode);
67625 + return new_mode;
67626 + }
67627 +
67628 + return retval;
67629 +}
67630 +
67631 +__u32
67632 +gr_check_link(const struct dentry * new_dentry,
67633 + const struct dentry * parent_dentry,
67634 + const struct vfsmount * parent_mnt,
67635 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
67636 +{
67637 + struct acl_object_label *obj;
67638 + __u32 oldmode, newmode;
67639 + __u32 needmode;
67640 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
67641 + GR_DELETE | GR_INHERIT;
67642 +
67643 + if (unlikely(!(gr_status & GR_READY)))
67644 + return (GR_CREATE | GR_LINK);
67645 +
67646 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
67647 + oldmode = obj->mode;
67648 +
67649 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
67650 + newmode = obj->mode;
67651 +
67652 + needmode = newmode & checkmodes;
67653 +
67654 + // old name for hardlink must have at least the permissions of the new name
67655 + if ((oldmode & needmode) != needmode)
67656 + goto bad;
67657 +
67658 + // if old name had restrictions/auditing, make sure the new name does as well
67659 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
67660 +
67661 + // don't allow hardlinking of suid/sgid/fcapped files without permission
67662 + if (is_privileged_binary(old_dentry))
67663 + needmode |= GR_SETID;
67664 +
67665 + if ((newmode & needmode) != needmode)
67666 + goto bad;
67667 +
67668 + // enforce minimum permissions
67669 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
67670 + return newmode;
67671 +bad:
67672 + needmode = oldmode;
67673 + if (is_privileged_binary(old_dentry))
67674 + needmode |= GR_SETID;
67675 +
67676 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
67677 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
67678 + return (GR_CREATE | GR_LINK);
67679 + } else if (newmode & GR_SUPPRESS)
67680 + return GR_SUPPRESS;
67681 + else
67682 + return 0;
67683 +}
67684 +
67685 +int
67686 +gr_check_hidden_task(const struct task_struct *task)
67687 +{
67688 + if (unlikely(!(gr_status & GR_READY)))
67689 + return 0;
67690 +
67691 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
67692 + return 1;
67693 +
67694 + return 0;
67695 +}
67696 +
67697 +int
67698 +gr_check_protected_task(const struct task_struct *task)
67699 +{
67700 + if (unlikely(!(gr_status & GR_READY) || !task))
67701 + return 0;
67702 +
67703 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67704 + task->acl != current->acl)
67705 + return 1;
67706 +
67707 + return 0;
67708 +}
67709 +
67710 +int
67711 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
67712 +{
67713 + struct task_struct *p;
67714 + int ret = 0;
67715 +
67716 + if (unlikely(!(gr_status & GR_READY) || !pid))
67717 + return ret;
67718 +
67719 + read_lock(&tasklist_lock);
67720 + do_each_pid_task(pid, type, p) {
67721 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67722 + p->acl != current->acl) {
67723 + ret = 1;
67724 + goto out;
67725 + }
67726 + } while_each_pid_task(pid, type, p);
67727 +out:
67728 + read_unlock(&tasklist_lock);
67729 +
67730 + return ret;
67731 +}
67732 +
67733 +void
67734 +gr_copy_label(struct task_struct *tsk)
67735 +{
67736 + struct task_struct *p = current;
67737 +
67738 + tsk->inherited = p->inherited;
67739 + tsk->acl_sp_role = 0;
67740 + tsk->acl_role_id = p->acl_role_id;
67741 + tsk->acl = p->acl;
67742 + tsk->role = p->role;
67743 + tsk->signal->used_accept = 0;
67744 + tsk->signal->curr_ip = p->signal->curr_ip;
67745 + tsk->signal->saved_ip = p->signal->saved_ip;
67746 + if (p->exec_file)
67747 + get_file(p->exec_file);
67748 + tsk->exec_file = p->exec_file;
67749 + tsk->is_writable = p->is_writable;
67750 + if (unlikely(p->signal->used_accept)) {
67751 + p->signal->curr_ip = 0;
67752 + p->signal->saved_ip = 0;
67753 + }
67754 +
67755 + return;
67756 +}
67757 +
67758 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
67759 +
67760 +int
67761 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
67762 +{
67763 + unsigned int i;
67764 + __u16 num;
67765 + uid_t *uidlist;
67766 + uid_t curuid;
67767 + int realok = 0;
67768 + int effectiveok = 0;
67769 + int fsok = 0;
67770 + uid_t globalreal, globaleffective, globalfs;
67771 +
67772 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
67773 + struct user_struct *user;
67774 +
67775 + if (!uid_valid(real))
67776 + goto skipit;
67777 +
67778 + /* find user based on global namespace */
67779 +
67780 + globalreal = GR_GLOBAL_UID(real);
67781 +
67782 + user = find_user(make_kuid(&init_user_ns, globalreal));
67783 + if (user == NULL)
67784 + goto skipit;
67785 +
67786 + if (gr_process_kernel_setuid_ban(user)) {
67787 + /* for find_user */
67788 + free_uid(user);
67789 + return 1;
67790 + }
67791 +
67792 + /* for find_user */
67793 + free_uid(user);
67794 +
67795 +skipit:
67796 +#endif
67797 +
67798 + if (unlikely(!(gr_status & GR_READY)))
67799 + return 0;
67800 +
67801 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67802 + gr_log_learn_uid_change(real, effective, fs);
67803 +
67804 + num = current->acl->user_trans_num;
67805 + uidlist = current->acl->user_transitions;
67806 +
67807 + if (uidlist == NULL)
67808 + return 0;
67809 +
67810 + if (!uid_valid(real)) {
67811 + realok = 1;
67812 + globalreal = (uid_t)-1;
67813 + } else {
67814 + globalreal = GR_GLOBAL_UID(real);
67815 + }
67816 + if (!uid_valid(effective)) {
67817 + effectiveok = 1;
67818 + globaleffective = (uid_t)-1;
67819 + } else {
67820 + globaleffective = GR_GLOBAL_UID(effective);
67821 + }
67822 + if (!uid_valid(fs)) {
67823 + fsok = 1;
67824 + globalfs = (uid_t)-1;
67825 + } else {
67826 + globalfs = GR_GLOBAL_UID(fs);
67827 + }
67828 +
67829 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
67830 + for (i = 0; i < num; i++) {
67831 + curuid = uidlist[i];
67832 + if (globalreal == curuid)
67833 + realok = 1;
67834 + if (globaleffective == curuid)
67835 + effectiveok = 1;
67836 + if (globalfs == curuid)
67837 + fsok = 1;
67838 + }
67839 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
67840 + for (i = 0; i < num; i++) {
67841 + curuid = uidlist[i];
67842 + if (globalreal == curuid)
67843 + break;
67844 + if (globaleffective == curuid)
67845 + break;
67846 + if (globalfs == curuid)
67847 + break;
67848 + }
67849 + /* not in deny list */
67850 + if (i == num) {
67851 + realok = 1;
67852 + effectiveok = 1;
67853 + fsok = 1;
67854 + }
67855 + }
67856 +
67857 + if (realok && effectiveok && fsok)
67858 + return 0;
67859 + else {
67860 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
67861 + return 1;
67862 + }
67863 +}
67864 +
67865 +int
67866 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
67867 +{
67868 + unsigned int i;
67869 + __u16 num;
67870 + gid_t *gidlist;
67871 + gid_t curgid;
67872 + int realok = 0;
67873 + int effectiveok = 0;
67874 + int fsok = 0;
67875 + gid_t globalreal, globaleffective, globalfs;
67876 +
67877 + if (unlikely(!(gr_status & GR_READY)))
67878 + return 0;
67879 +
67880 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67881 + gr_log_learn_gid_change(real, effective, fs);
67882 +
67883 + num = current->acl->group_trans_num;
67884 + gidlist = current->acl->group_transitions;
67885 +
67886 + if (gidlist == NULL)
67887 + return 0;
67888 +
67889 + if (!gid_valid(real)) {
67890 + realok = 1;
67891 + globalreal = (gid_t)-1;
67892 + } else {
67893 + globalreal = GR_GLOBAL_GID(real);
67894 + }
67895 + if (!gid_valid(effective)) {
67896 + effectiveok = 1;
67897 + globaleffective = (gid_t)-1;
67898 + } else {
67899 + globaleffective = GR_GLOBAL_GID(effective);
67900 + }
67901 + if (!gid_valid(fs)) {
67902 + fsok = 1;
67903 + globalfs = (gid_t)-1;
67904 + } else {
67905 + globalfs = GR_GLOBAL_GID(fs);
67906 + }
67907 +
67908 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
67909 + for (i = 0; i < num; i++) {
67910 + curgid = gidlist[i];
67911 + if (globalreal == curgid)
67912 + realok = 1;
67913 + if (globaleffective == curgid)
67914 + effectiveok = 1;
67915 + if (globalfs == curgid)
67916 + fsok = 1;
67917 + }
67918 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
67919 + for (i = 0; i < num; i++) {
67920 + curgid = gidlist[i];
67921 + if (globalreal == curgid)
67922 + break;
67923 + if (globaleffective == curgid)
67924 + break;
67925 + if (globalfs == curgid)
67926 + break;
67927 + }
67928 + /* not in deny list */
67929 + if (i == num) {
67930 + realok = 1;
67931 + effectiveok = 1;
67932 + fsok = 1;
67933 + }
67934 + }
67935 +
67936 + if (realok && effectiveok && fsok)
67937 + return 0;
67938 + else {
67939 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
67940 + return 1;
67941 + }
67942 +}
67943 +
67944 +extern int gr_acl_is_capable(const int cap);
67945 +
67946 +void
67947 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
67948 +{
67949 + struct acl_role_label *role = task->role;
67950 + struct acl_subject_label *subj = NULL;
67951 + struct acl_object_label *obj;
67952 + struct file *filp;
67953 + uid_t uid;
67954 + gid_t gid;
67955 +
67956 + if (unlikely(!(gr_status & GR_READY)))
67957 + return;
67958 +
67959 + uid = GR_GLOBAL_UID(kuid);
67960 + gid = GR_GLOBAL_GID(kgid);
67961 +
67962 + filp = task->exec_file;
67963 +
67964 + /* kernel process, we'll give them the kernel role */
67965 + if (unlikely(!filp)) {
67966 + task->role = running_polstate.kernel_role;
67967 + task->acl = running_polstate.kernel_role->root_label;
67968 + return;
67969 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
67970 + /* save the current ip at time of role lookup so that the proper
67971 + IP will be learned for role_allowed_ip */
67972 + task->signal->saved_ip = task->signal->curr_ip;
67973 + role = lookup_acl_role_label(task, uid, gid);
67974 + }
67975 +
67976 + /* don't change the role if we're not a privileged process */
67977 + if (role && task->role != role &&
67978 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
67979 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
67980 + return;
67981 +
67982 + /* perform subject lookup in possibly new role
67983 + we can use this result below in the case where role == task->role
67984 + */
67985 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
67986 +
67987 + /* if we changed uid/gid, but result in the same role
67988 + and are using inheritance, don't lose the inherited subject
67989 + if current subject is other than what normal lookup
67990 + would result in, we arrived via inheritance, don't
67991 + lose subject
67992 + */
67993 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
67994 + (subj == task->acl)))
67995 + task->acl = subj;
67996 +
67997 + /* leave task->inherited unaffected */
67998 +
67999 + task->role = role;
68000 +
68001 + task->is_writable = 0;
68002 +
68003 + /* ignore additional mmap checks for processes that are writable
68004 + by the default ACL */
68005 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68006 + if (unlikely(obj->mode & GR_WRITE))
68007 + task->is_writable = 1;
68008 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68009 + if (unlikely(obj->mode & GR_WRITE))
68010 + task->is_writable = 1;
68011 +
68012 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68013 + 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);
68014 +#endif
68015 +
68016 + gr_set_proc_res(task);
68017 +
68018 + return;
68019 +}
68020 +
68021 +int
68022 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68023 + const int unsafe_flags)
68024 +{
68025 + struct task_struct *task = current;
68026 + struct acl_subject_label *newacl;
68027 + struct acl_object_label *obj;
68028 + __u32 retmode;
68029 +
68030 + if (unlikely(!(gr_status & GR_READY)))
68031 + return 0;
68032 +
68033 + newacl = chk_subj_label(dentry, mnt, task->role);
68034 +
68035 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68036 + did an exec
68037 + */
68038 + rcu_read_lock();
68039 + read_lock(&tasklist_lock);
68040 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68041 + (task->parent->acl->mode & GR_POVERRIDE))) {
68042 + read_unlock(&tasklist_lock);
68043 + rcu_read_unlock();
68044 + goto skip_check;
68045 + }
68046 + read_unlock(&tasklist_lock);
68047 + rcu_read_unlock();
68048 +
68049 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68050 + !(task->role->roletype & GR_ROLE_GOD) &&
68051 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68052 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68053 + if (unsafe_flags & LSM_UNSAFE_SHARE)
68054 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68055 + else
68056 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68057 + return -EACCES;
68058 + }
68059 +
68060 +skip_check:
68061 +
68062 + obj = chk_obj_label(dentry, mnt, task->acl);
68063 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68064 +
68065 + if (!(task->acl->mode & GR_INHERITLEARN) &&
68066 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68067 + if (obj->nested)
68068 + task->acl = obj->nested;
68069 + else
68070 + task->acl = newacl;
68071 + task->inherited = 0;
68072 + } else {
68073 + task->inherited = 1;
68074 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68075 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68076 + }
68077 +
68078 + task->is_writable = 0;
68079 +
68080 + /* ignore additional mmap checks for processes that are writable
68081 + by the default ACL */
68082 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68083 + if (unlikely(obj->mode & GR_WRITE))
68084 + task->is_writable = 1;
68085 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
68086 + if (unlikely(obj->mode & GR_WRITE))
68087 + task->is_writable = 1;
68088 +
68089 + gr_set_proc_res(task);
68090 +
68091 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68092 + 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);
68093 +#endif
68094 + return 0;
68095 +}
68096 +
68097 +/* always called with valid inodev ptr */
68098 +static void
68099 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68100 +{
68101 + struct acl_object_label *matchpo;
68102 + struct acl_subject_label *matchps;
68103 + struct acl_subject_label *subj;
68104 + struct acl_role_label *role;
68105 + unsigned int x;
68106 +
68107 + FOR_EACH_ROLE_START(role)
68108 + FOR_EACH_SUBJECT_START(role, subj, x)
68109 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68110 + matchpo->mode |= GR_DELETED;
68111 + FOR_EACH_SUBJECT_END(subj,x)
68112 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
68113 + /* nested subjects aren't in the role's subj_hash table */
68114 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68115 + matchpo->mode |= GR_DELETED;
68116 + FOR_EACH_NESTED_SUBJECT_END(subj)
68117 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68118 + matchps->mode |= GR_DELETED;
68119 + FOR_EACH_ROLE_END(role)
68120 +
68121 + inodev->nentry->deleted = 1;
68122 +
68123 + return;
68124 +}
68125 +
68126 +void
68127 +gr_handle_delete(const ino_t ino, const dev_t dev)
68128 +{
68129 + struct inodev_entry *inodev;
68130 +
68131 + if (unlikely(!(gr_status & GR_READY)))
68132 + return;
68133 +
68134 + write_lock(&gr_inode_lock);
68135 + inodev = lookup_inodev_entry(ino, dev);
68136 + if (inodev != NULL)
68137 + do_handle_delete(inodev, ino, dev);
68138 + write_unlock(&gr_inode_lock);
68139 +
68140 + return;
68141 +}
68142 +
68143 +static void
68144 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68145 + const ino_t newinode, const dev_t newdevice,
68146 + struct acl_subject_label *subj)
68147 +{
68148 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68149 + struct acl_object_label *match;
68150 +
68151 + match = subj->obj_hash[index];
68152 +
68153 + while (match && (match->inode != oldinode ||
68154 + match->device != olddevice ||
68155 + !(match->mode & GR_DELETED)))
68156 + match = match->next;
68157 +
68158 + if (match && (match->inode == oldinode)
68159 + && (match->device == olddevice)
68160 + && (match->mode & GR_DELETED)) {
68161 + if (match->prev == NULL) {
68162 + subj->obj_hash[index] = match->next;
68163 + if (match->next != NULL)
68164 + match->next->prev = NULL;
68165 + } else {
68166 + match->prev->next = match->next;
68167 + if (match->next != NULL)
68168 + match->next->prev = match->prev;
68169 + }
68170 + match->prev = NULL;
68171 + match->next = NULL;
68172 + match->inode = newinode;
68173 + match->device = newdevice;
68174 + match->mode &= ~GR_DELETED;
68175 +
68176 + insert_acl_obj_label(match, subj);
68177 + }
68178 +
68179 + return;
68180 +}
68181 +
68182 +static void
68183 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68184 + const ino_t newinode, const dev_t newdevice,
68185 + struct acl_role_label *role)
68186 +{
68187 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68188 + struct acl_subject_label *match;
68189 +
68190 + match = role->subj_hash[index];
68191 +
68192 + while (match && (match->inode != oldinode ||
68193 + match->device != olddevice ||
68194 + !(match->mode & GR_DELETED)))
68195 + match = match->next;
68196 +
68197 + if (match && (match->inode == oldinode)
68198 + && (match->device == olddevice)
68199 + && (match->mode & GR_DELETED)) {
68200 + if (match->prev == NULL) {
68201 + role->subj_hash[index] = match->next;
68202 + if (match->next != NULL)
68203 + match->next->prev = NULL;
68204 + } else {
68205 + match->prev->next = match->next;
68206 + if (match->next != NULL)
68207 + match->next->prev = match->prev;
68208 + }
68209 + match->prev = NULL;
68210 + match->next = NULL;
68211 + match->inode = newinode;
68212 + match->device = newdevice;
68213 + match->mode &= ~GR_DELETED;
68214 +
68215 + insert_acl_subj_label(match, role);
68216 + }
68217 +
68218 + return;
68219 +}
68220 +
68221 +static void
68222 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68223 + const ino_t newinode, const dev_t newdevice)
68224 +{
68225 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68226 + struct inodev_entry *match;
68227 +
68228 + match = running_polstate.inodev_set.i_hash[index];
68229 +
68230 + while (match && (match->nentry->inode != oldinode ||
68231 + match->nentry->device != olddevice || !match->nentry->deleted))
68232 + match = match->next;
68233 +
68234 + if (match && (match->nentry->inode == oldinode)
68235 + && (match->nentry->device == olddevice) &&
68236 + match->nentry->deleted) {
68237 + if (match->prev == NULL) {
68238 + running_polstate.inodev_set.i_hash[index] = match->next;
68239 + if (match->next != NULL)
68240 + match->next->prev = NULL;
68241 + } else {
68242 + match->prev->next = match->next;
68243 + if (match->next != NULL)
68244 + match->next->prev = match->prev;
68245 + }
68246 + match->prev = NULL;
68247 + match->next = NULL;
68248 + match->nentry->inode = newinode;
68249 + match->nentry->device = newdevice;
68250 + match->nentry->deleted = 0;
68251 +
68252 + insert_inodev_entry(match);
68253 + }
68254 +
68255 + return;
68256 +}
68257 +
68258 +static void
68259 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68260 +{
68261 + struct acl_subject_label *subj;
68262 + struct acl_role_label *role;
68263 + unsigned int x;
68264 +
68265 + FOR_EACH_ROLE_START(role)
68266 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68267 +
68268 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
68269 + if ((subj->inode == ino) && (subj->device == dev)) {
68270 + subj->inode = ino;
68271 + subj->device = dev;
68272 + }
68273 + /* nested subjects aren't in the role's subj_hash table */
68274 + update_acl_obj_label(matchn->inode, matchn->device,
68275 + ino, dev, subj);
68276 + FOR_EACH_NESTED_SUBJECT_END(subj)
68277 + FOR_EACH_SUBJECT_START(role, subj, x)
68278 + update_acl_obj_label(matchn->inode, matchn->device,
68279 + ino, dev, subj);
68280 + FOR_EACH_SUBJECT_END(subj,x)
68281 + FOR_EACH_ROLE_END(role)
68282 +
68283 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68284 +
68285 + return;
68286 +}
68287 +
68288 +static void
68289 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
68290 + const struct vfsmount *mnt)
68291 +{
68292 + ino_t ino = dentry->d_inode->i_ino;
68293 + dev_t dev = __get_dev(dentry);
68294 +
68295 + __do_handle_create(matchn, ino, dev);
68296 +
68297 + return;
68298 +}
68299 +
68300 +void
68301 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68302 +{
68303 + struct name_entry *matchn;
68304 +
68305 + if (unlikely(!(gr_status & GR_READY)))
68306 + return;
68307 +
68308 + preempt_disable();
68309 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
68310 +
68311 + if (unlikely((unsigned long)matchn)) {
68312 + write_lock(&gr_inode_lock);
68313 + do_handle_create(matchn, dentry, mnt);
68314 + write_unlock(&gr_inode_lock);
68315 + }
68316 + preempt_enable();
68317 +
68318 + return;
68319 +}
68320 +
68321 +void
68322 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68323 +{
68324 + struct name_entry *matchn;
68325 +
68326 + if (unlikely(!(gr_status & GR_READY)))
68327 + return;
68328 +
68329 + preempt_disable();
68330 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
68331 +
68332 + if (unlikely((unsigned long)matchn)) {
68333 + write_lock(&gr_inode_lock);
68334 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
68335 + write_unlock(&gr_inode_lock);
68336 + }
68337 + preempt_enable();
68338 +
68339 + return;
68340 +}
68341 +
68342 +void
68343 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68344 + struct dentry *old_dentry,
68345 + struct dentry *new_dentry,
68346 + struct vfsmount *mnt, const __u8 replace)
68347 +{
68348 + struct name_entry *matchn;
68349 + struct inodev_entry *inodev;
68350 + struct inode *inode = new_dentry->d_inode;
68351 + ino_t old_ino = old_dentry->d_inode->i_ino;
68352 + dev_t old_dev = __get_dev(old_dentry);
68353 +
68354 + /* vfs_rename swaps the name and parent link for old_dentry and
68355 + new_dentry
68356 + at this point, old_dentry has the new name, parent link, and inode
68357 + for the renamed file
68358 + if a file is being replaced by a rename, new_dentry has the inode
68359 + and name for the replaced file
68360 + */
68361 +
68362 + if (unlikely(!(gr_status & GR_READY)))
68363 + return;
68364 +
68365 + preempt_disable();
68366 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
68367 +
68368 + /* we wouldn't have to check d_inode if it weren't for
68369 + NFS silly-renaming
68370 + */
68371 +
68372 + write_lock(&gr_inode_lock);
68373 + if (unlikely(replace && inode)) {
68374 + ino_t new_ino = inode->i_ino;
68375 + dev_t new_dev = __get_dev(new_dentry);
68376 +
68377 + inodev = lookup_inodev_entry(new_ino, new_dev);
68378 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
68379 + do_handle_delete(inodev, new_ino, new_dev);
68380 + }
68381 +
68382 + inodev = lookup_inodev_entry(old_ino, old_dev);
68383 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
68384 + do_handle_delete(inodev, old_ino, old_dev);
68385 +
68386 + if (unlikely((unsigned long)matchn))
68387 + do_handle_create(matchn, old_dentry, mnt);
68388 +
68389 + write_unlock(&gr_inode_lock);
68390 + preempt_enable();
68391 +
68392 + return;
68393 +}
68394 +
68395 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
68396 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
68397 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
68398 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
68399 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
68400 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
68401 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
68402 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
68403 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
68404 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
68405 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
68406 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
68407 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
68408 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
68409 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
68410 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
68411 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
68412 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
68413 +};
68414 +
68415 +void
68416 +gr_learn_resource(const struct task_struct *task,
68417 + const int res, const unsigned long wanted, const int gt)
68418 +{
68419 + struct acl_subject_label *acl;
68420 + const struct cred *cred;
68421 +
68422 + if (unlikely((gr_status & GR_READY) &&
68423 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
68424 + goto skip_reslog;
68425 +
68426 + gr_log_resource(task, res, wanted, gt);
68427 +skip_reslog:
68428 +
68429 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
68430 + return;
68431 +
68432 + acl = task->acl;
68433 +
68434 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
68435 + !(acl->resmask & (1U << (unsigned short) res))))
68436 + return;
68437 +
68438 + if (wanted >= acl->res[res].rlim_cur) {
68439 + unsigned long res_add;
68440 +
68441 + res_add = wanted + res_learn_bumps[res];
68442 +
68443 + acl->res[res].rlim_cur = res_add;
68444 +
68445 + if (wanted > acl->res[res].rlim_max)
68446 + acl->res[res].rlim_max = res_add;
68447 +
68448 + /* only log the subject filename, since resource logging is supported for
68449 + single-subject learning only */
68450 + rcu_read_lock();
68451 + cred = __task_cred(task);
68452 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68453 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
68454 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
68455 + "", (unsigned long) res, &task->signal->saved_ip);
68456 + rcu_read_unlock();
68457 + }
68458 +
68459 + return;
68460 +}
68461 +EXPORT_SYMBOL_GPL(gr_learn_resource);
68462 +#endif
68463 +
68464 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
68465 +void
68466 +pax_set_initial_flags(struct linux_binprm *bprm)
68467 +{
68468 + struct task_struct *task = current;
68469 + struct acl_subject_label *proc;
68470 + unsigned long flags;
68471 +
68472 + if (unlikely(!(gr_status & GR_READY)))
68473 + return;
68474 +
68475 + flags = pax_get_flags(task);
68476 +
68477 + proc = task->acl;
68478 +
68479 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
68480 + flags &= ~MF_PAX_PAGEEXEC;
68481 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
68482 + flags &= ~MF_PAX_SEGMEXEC;
68483 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
68484 + flags &= ~MF_PAX_RANDMMAP;
68485 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
68486 + flags &= ~MF_PAX_EMUTRAMP;
68487 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
68488 + flags &= ~MF_PAX_MPROTECT;
68489 +
68490 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
68491 + flags |= MF_PAX_PAGEEXEC;
68492 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
68493 + flags |= MF_PAX_SEGMEXEC;
68494 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
68495 + flags |= MF_PAX_RANDMMAP;
68496 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
68497 + flags |= MF_PAX_EMUTRAMP;
68498 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
68499 + flags |= MF_PAX_MPROTECT;
68500 +
68501 + pax_set_flags(task, flags);
68502 +
68503 + return;
68504 +}
68505 +#endif
68506 +
68507 +int
68508 +gr_handle_proc_ptrace(struct task_struct *task)
68509 +{
68510 + struct file *filp;
68511 + struct task_struct *tmp = task;
68512 + struct task_struct *curtemp = current;
68513 + __u32 retmode;
68514 +
68515 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68516 + if (unlikely(!(gr_status & GR_READY)))
68517 + return 0;
68518 +#endif
68519 +
68520 + read_lock(&tasklist_lock);
68521 + read_lock(&grsec_exec_file_lock);
68522 + filp = task->exec_file;
68523 +
68524 + while (task_pid_nr(tmp) > 0) {
68525 + if (tmp == curtemp)
68526 + break;
68527 + tmp = tmp->real_parent;
68528 + }
68529 +
68530 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68531 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
68532 + read_unlock(&grsec_exec_file_lock);
68533 + read_unlock(&tasklist_lock);
68534 + return 1;
68535 + }
68536 +
68537 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68538 + if (!(gr_status & GR_READY)) {
68539 + read_unlock(&grsec_exec_file_lock);
68540 + read_unlock(&tasklist_lock);
68541 + return 0;
68542 + }
68543 +#endif
68544 +
68545 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
68546 + read_unlock(&grsec_exec_file_lock);
68547 + read_unlock(&tasklist_lock);
68548 +
68549 + if (retmode & GR_NOPTRACE)
68550 + return 1;
68551 +
68552 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
68553 + && (current->acl != task->acl || (current->acl != current->role->root_label
68554 + && task_pid_nr(current) != task_pid_nr(task))))
68555 + return 1;
68556 +
68557 + return 0;
68558 +}
68559 +
68560 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
68561 +{
68562 + if (unlikely(!(gr_status & GR_READY)))
68563 + return;
68564 +
68565 + if (!(current->role->roletype & GR_ROLE_GOD))
68566 + return;
68567 +
68568 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
68569 + p->role->rolename, gr_task_roletype_to_char(p),
68570 + p->acl->filename);
68571 +}
68572 +
68573 +int
68574 +gr_handle_ptrace(struct task_struct *task, const long request)
68575 +{
68576 + struct task_struct *tmp = task;
68577 + struct task_struct *curtemp = current;
68578 + __u32 retmode;
68579 +
68580 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68581 + if (unlikely(!(gr_status & GR_READY)))
68582 + return 0;
68583 +#endif
68584 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68585 + read_lock(&tasklist_lock);
68586 + while (task_pid_nr(tmp) > 0) {
68587 + if (tmp == curtemp)
68588 + break;
68589 + tmp = tmp->real_parent;
68590 + }
68591 +
68592 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68593 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
68594 + read_unlock(&tasklist_lock);
68595 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68596 + return 1;
68597 + }
68598 + read_unlock(&tasklist_lock);
68599 + }
68600 +
68601 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68602 + if (!(gr_status & GR_READY))
68603 + return 0;
68604 +#endif
68605 +
68606 + read_lock(&grsec_exec_file_lock);
68607 + if (unlikely(!task->exec_file)) {
68608 + read_unlock(&grsec_exec_file_lock);
68609 + return 0;
68610 + }
68611 +
68612 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
68613 + read_unlock(&grsec_exec_file_lock);
68614 +
68615 + if (retmode & GR_NOPTRACE) {
68616 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68617 + return 1;
68618 + }
68619 +
68620 + if (retmode & GR_PTRACERD) {
68621 + switch (request) {
68622 + case PTRACE_SEIZE:
68623 + case PTRACE_POKETEXT:
68624 + case PTRACE_POKEDATA:
68625 + case PTRACE_POKEUSR:
68626 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
68627 + case PTRACE_SETREGS:
68628 + case PTRACE_SETFPREGS:
68629 +#endif
68630 +#ifdef CONFIG_X86
68631 + case PTRACE_SETFPXREGS:
68632 +#endif
68633 +#ifdef CONFIG_ALTIVEC
68634 + case PTRACE_SETVRREGS:
68635 +#endif
68636 + return 1;
68637 + default:
68638 + return 0;
68639 + }
68640 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
68641 + !(current->role->roletype & GR_ROLE_GOD) &&
68642 + (current->acl != task->acl)) {
68643 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68644 + return 1;
68645 + }
68646 +
68647 + return 0;
68648 +}
68649 +
68650 +static int is_writable_mmap(const struct file *filp)
68651 +{
68652 + struct task_struct *task = current;
68653 + struct acl_object_label *obj, *obj2;
68654 +
68655 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
68656 + !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))) {
68657 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68658 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
68659 + task->role->root_label);
68660 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
68661 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
68662 + return 1;
68663 + }
68664 + }
68665 + return 0;
68666 +}
68667 +
68668 +int
68669 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
68670 +{
68671 + __u32 mode;
68672 +
68673 + if (unlikely(!file || !(prot & PROT_EXEC)))
68674 + return 1;
68675 +
68676 + if (is_writable_mmap(file))
68677 + return 0;
68678 +
68679 + mode =
68680 + gr_search_file(file->f_path.dentry,
68681 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68682 + file->f_path.mnt);
68683 +
68684 + if (!gr_tpe_allow(file))
68685 + return 0;
68686 +
68687 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68688 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68689 + return 0;
68690 + } else if (unlikely(!(mode & GR_EXEC))) {
68691 + return 0;
68692 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68693 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68694 + return 1;
68695 + }
68696 +
68697 + return 1;
68698 +}
68699 +
68700 +int
68701 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
68702 +{
68703 + __u32 mode;
68704 +
68705 + if (unlikely(!file || !(prot & PROT_EXEC)))
68706 + return 1;
68707 +
68708 + if (is_writable_mmap(file))
68709 + return 0;
68710 +
68711 + mode =
68712 + gr_search_file(file->f_path.dentry,
68713 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68714 + file->f_path.mnt);
68715 +
68716 + if (!gr_tpe_allow(file))
68717 + return 0;
68718 +
68719 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68720 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68721 + return 0;
68722 + } else if (unlikely(!(mode & GR_EXEC))) {
68723 + return 0;
68724 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68725 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68726 + return 1;
68727 + }
68728 +
68729 + return 1;
68730 +}
68731 +
68732 +void
68733 +gr_acl_handle_psacct(struct task_struct *task, const long code)
68734 +{
68735 + unsigned long runtime, cputime;
68736 + cputime_t utime, stime;
68737 + unsigned int wday, cday;
68738 + __u8 whr, chr;
68739 + __u8 wmin, cmin;
68740 + __u8 wsec, csec;
68741 + struct timespec timeval;
68742 +
68743 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
68744 + !(task->acl->mode & GR_PROCACCT)))
68745 + return;
68746 +
68747 + do_posix_clock_monotonic_gettime(&timeval);
68748 + runtime = timeval.tv_sec - task->start_time.tv_sec;
68749 + wday = runtime / (60 * 60 * 24);
68750 + runtime -= wday * (60 * 60 * 24);
68751 + whr = runtime / (60 * 60);
68752 + runtime -= whr * (60 * 60);
68753 + wmin = runtime / 60;
68754 + runtime -= wmin * 60;
68755 + wsec = runtime;
68756 +
68757 + task_cputime(task, &utime, &stime);
68758 + cputime = cputime_to_secs(utime + stime);
68759 + cday = cputime / (60 * 60 * 24);
68760 + cputime -= cday * (60 * 60 * 24);
68761 + chr = cputime / (60 * 60);
68762 + cputime -= chr * (60 * 60);
68763 + cmin = cputime / 60;
68764 + cputime -= cmin * 60;
68765 + csec = cputime;
68766 +
68767 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
68768 +
68769 + return;
68770 +}
68771 +
68772 +#ifdef CONFIG_TASKSTATS
68773 +int gr_is_taskstats_denied(int pid)
68774 +{
68775 + struct task_struct *task;
68776 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68777 + const struct cred *cred;
68778 +#endif
68779 + int ret = 0;
68780 +
68781 + /* restrict taskstats viewing to un-chrooted root users
68782 + who have the 'view' subject flag if the RBAC system is enabled
68783 + */
68784 +
68785 + rcu_read_lock();
68786 + read_lock(&tasklist_lock);
68787 + task = find_task_by_vpid(pid);
68788 + if (task) {
68789 +#ifdef CONFIG_GRKERNSEC_CHROOT
68790 + if (proc_is_chrooted(task))
68791 + ret = -EACCES;
68792 +#endif
68793 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68794 + cred = __task_cred(task);
68795 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68796 + if (gr_is_global_nonroot(cred->uid))
68797 + ret = -EACCES;
68798 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68799 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
68800 + ret = -EACCES;
68801 +#endif
68802 +#endif
68803 + if (gr_status & GR_READY) {
68804 + if (!(task->acl->mode & GR_VIEW))
68805 + ret = -EACCES;
68806 + }
68807 + } else
68808 + ret = -ENOENT;
68809 +
68810 + read_unlock(&tasklist_lock);
68811 + rcu_read_unlock();
68812 +
68813 + return ret;
68814 +}
68815 +#endif
68816 +
68817 +/* AUXV entries are filled via a descendant of search_binary_handler
68818 + after we've already applied the subject for the target
68819 +*/
68820 +int gr_acl_enable_at_secure(void)
68821 +{
68822 + if (unlikely(!(gr_status & GR_READY)))
68823 + return 0;
68824 +
68825 + if (current->acl->mode & GR_ATSECURE)
68826 + return 1;
68827 +
68828 + return 0;
68829 +}
68830 +
68831 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
68832 +{
68833 + struct task_struct *task = current;
68834 + struct dentry *dentry = file->f_path.dentry;
68835 + struct vfsmount *mnt = file->f_path.mnt;
68836 + struct acl_object_label *obj, *tmp;
68837 + struct acl_subject_label *subj;
68838 + unsigned int bufsize;
68839 + int is_not_root;
68840 + char *path;
68841 + dev_t dev = __get_dev(dentry);
68842 +
68843 + if (unlikely(!(gr_status & GR_READY)))
68844 + return 1;
68845 +
68846 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68847 + return 1;
68848 +
68849 + /* ignore Eric Biederman */
68850 + if (IS_PRIVATE(dentry->d_inode))
68851 + return 1;
68852 +
68853 + subj = task->acl;
68854 + read_lock(&gr_inode_lock);
68855 + do {
68856 + obj = lookup_acl_obj_label(ino, dev, subj);
68857 + if (obj != NULL) {
68858 + read_unlock(&gr_inode_lock);
68859 + return (obj->mode & GR_FIND) ? 1 : 0;
68860 + }
68861 + } while ((subj = subj->parent_subject));
68862 + read_unlock(&gr_inode_lock);
68863 +
68864 + /* this is purely an optimization since we're looking for an object
68865 + for the directory we're doing a readdir on
68866 + if it's possible for any globbed object to match the entry we're
68867 + filling into the directory, then the object we find here will be
68868 + an anchor point with attached globbed objects
68869 + */
68870 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
68871 + if (obj->globbed == NULL)
68872 + return (obj->mode & GR_FIND) ? 1 : 0;
68873 +
68874 + is_not_root = ((obj->filename[0] == '/') &&
68875 + (obj->filename[1] == '\0')) ? 0 : 1;
68876 + bufsize = PAGE_SIZE - namelen - is_not_root;
68877 +
68878 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
68879 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
68880 + return 1;
68881 +
68882 + preempt_disable();
68883 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
68884 + bufsize);
68885 +
68886 + bufsize = strlen(path);
68887 +
68888 + /* if base is "/", don't append an additional slash */
68889 + if (is_not_root)
68890 + *(path + bufsize) = '/';
68891 + memcpy(path + bufsize + is_not_root, name, namelen);
68892 + *(path + bufsize + namelen + is_not_root) = '\0';
68893 +
68894 + tmp = obj->globbed;
68895 + while (tmp) {
68896 + if (!glob_match(tmp->filename, path)) {
68897 + preempt_enable();
68898 + return (tmp->mode & GR_FIND) ? 1 : 0;
68899 + }
68900 + tmp = tmp->next;
68901 + }
68902 + preempt_enable();
68903 + return (obj->mode & GR_FIND) ? 1 : 0;
68904 +}
68905 +
68906 +void gr_put_exec_file(struct task_struct *task)
68907 +{
68908 + struct file *filp;
68909 +
68910 + write_lock(&grsec_exec_file_lock);
68911 + filp = task->exec_file;
68912 + task->exec_file = NULL;
68913 + write_unlock(&grsec_exec_file_lock);
68914 +
68915 + if (filp)
68916 + fput(filp);
68917 +
68918 + return;
68919 +}
68920 +
68921 +
68922 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
68923 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
68924 +#endif
68925 +#ifdef CONFIG_SECURITY
68926 +EXPORT_SYMBOL_GPL(gr_check_user_change);
68927 +EXPORT_SYMBOL_GPL(gr_check_group_change);
68928 +#endif
68929 +
68930 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
68931 new file mode 100644
68932 index 0000000..18ffbbd
68933 --- /dev/null
68934 +++ b/grsecurity/gracl_alloc.c
68935 @@ -0,0 +1,105 @@
68936 +#include <linux/kernel.h>
68937 +#include <linux/mm.h>
68938 +#include <linux/slab.h>
68939 +#include <linux/vmalloc.h>
68940 +#include <linux/gracl.h>
68941 +#include <linux/grsecurity.h>
68942 +
68943 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
68944 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
68945 +
68946 +static __inline__ int
68947 +alloc_pop(void)
68948 +{
68949 + if (current_alloc_state->alloc_stack_next == 1)
68950 + return 0;
68951 +
68952 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
68953 +
68954 + current_alloc_state->alloc_stack_next--;
68955 +
68956 + return 1;
68957 +}
68958 +
68959 +static __inline__ int
68960 +alloc_push(void *buf)
68961 +{
68962 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
68963 + return 1;
68964 +
68965 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
68966 +
68967 + current_alloc_state->alloc_stack_next++;
68968 +
68969 + return 0;
68970 +}
68971 +
68972 +void *
68973 +acl_alloc(unsigned long len)
68974 +{
68975 + void *ret = NULL;
68976 +
68977 + if (!len || len > PAGE_SIZE)
68978 + goto out;
68979 +
68980 + ret = kmalloc(len, GFP_KERNEL);
68981 +
68982 + if (ret) {
68983 + if (alloc_push(ret)) {
68984 + kfree(ret);
68985 + ret = NULL;
68986 + }
68987 + }
68988 +
68989 +out:
68990 + return ret;
68991 +}
68992 +
68993 +void *
68994 +acl_alloc_num(unsigned long num, unsigned long len)
68995 +{
68996 + if (!len || (num > (PAGE_SIZE / len)))
68997 + return NULL;
68998 +
68999 + return acl_alloc(num * len);
69000 +}
69001 +
69002 +void
69003 +acl_free_all(void)
69004 +{
69005 + if (!current_alloc_state->alloc_stack)
69006 + return;
69007 +
69008 + while (alloc_pop()) ;
69009 +
69010 + if (current_alloc_state->alloc_stack) {
69011 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69012 + kfree(current_alloc_state->alloc_stack);
69013 + else
69014 + vfree(current_alloc_state->alloc_stack);
69015 + }
69016 +
69017 + current_alloc_state->alloc_stack = NULL;
69018 + current_alloc_state->alloc_stack_size = 1;
69019 + current_alloc_state->alloc_stack_next = 1;
69020 +
69021 + return;
69022 +}
69023 +
69024 +int
69025 +acl_alloc_stack_init(unsigned long size)
69026 +{
69027 + if ((size * sizeof (void *)) <= PAGE_SIZE)
69028 + current_alloc_state->alloc_stack =
69029 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69030 + else
69031 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69032 +
69033 + current_alloc_state->alloc_stack_size = size;
69034 + current_alloc_state->alloc_stack_next = 1;
69035 +
69036 + if (!current_alloc_state->alloc_stack)
69037 + return 0;
69038 + else
69039 + return 1;
69040 +}
69041 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69042 new file mode 100644
69043 index 0000000..bdd51ea
69044 --- /dev/null
69045 +++ b/grsecurity/gracl_cap.c
69046 @@ -0,0 +1,110 @@
69047 +#include <linux/kernel.h>
69048 +#include <linux/module.h>
69049 +#include <linux/sched.h>
69050 +#include <linux/gracl.h>
69051 +#include <linux/grsecurity.h>
69052 +#include <linux/grinternal.h>
69053 +
69054 +extern const char *captab_log[];
69055 +extern int captab_log_entries;
69056 +
69057 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69058 +{
69059 + struct acl_subject_label *curracl;
69060 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69061 + kernel_cap_t cap_audit = __cap_empty_set;
69062 +
69063 + if (!gr_acl_is_enabled())
69064 + return 1;
69065 +
69066 + curracl = task->acl;
69067 +
69068 + cap_drop = curracl->cap_lower;
69069 + cap_mask = curracl->cap_mask;
69070 + cap_audit = curracl->cap_invert_audit;
69071 +
69072 + while ((curracl = curracl->parent_subject)) {
69073 + /* if the cap isn't specified in the current computed mask but is specified in the
69074 + current level subject, and is lowered in the current level subject, then add
69075 + it to the set of dropped capabilities
69076 + otherwise, add the current level subject's mask to the current computed mask
69077 + */
69078 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69079 + cap_raise(cap_mask, cap);
69080 + if (cap_raised(curracl->cap_lower, cap))
69081 + cap_raise(cap_drop, cap);
69082 + if (cap_raised(curracl->cap_invert_audit, cap))
69083 + cap_raise(cap_audit, cap);
69084 + }
69085 + }
69086 +
69087 + if (!cap_raised(cap_drop, cap)) {
69088 + if (cap_raised(cap_audit, cap))
69089 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69090 + return 1;
69091 + }
69092 +
69093 + curracl = task->acl;
69094 +
69095 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69096 + && cap_raised(cred->cap_effective, cap)) {
69097 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69098 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
69099 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
69100 + gr_to_filename(task->exec_file->f_path.dentry,
69101 + task->exec_file->f_path.mnt) : curracl->filename,
69102 + curracl->filename, 0UL,
69103 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69104 + return 1;
69105 + }
69106 +
69107 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69108 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69109 +
69110 + return 0;
69111 +}
69112 +
69113 +int
69114 +gr_acl_is_capable(const int cap)
69115 +{
69116 + return gr_task_acl_is_capable(current, current_cred(), cap);
69117 +}
69118 +
69119 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69120 +{
69121 + struct acl_subject_label *curracl;
69122 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69123 +
69124 + if (!gr_acl_is_enabled())
69125 + return 1;
69126 +
69127 + curracl = task->acl;
69128 +
69129 + cap_drop = curracl->cap_lower;
69130 + cap_mask = curracl->cap_mask;
69131 +
69132 + while ((curracl = curracl->parent_subject)) {
69133 + /* if the cap isn't specified in the current computed mask but is specified in the
69134 + current level subject, and is lowered in the current level subject, then add
69135 + it to the set of dropped capabilities
69136 + otherwise, add the current level subject's mask to the current computed mask
69137 + */
69138 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69139 + cap_raise(cap_mask, cap);
69140 + if (cap_raised(curracl->cap_lower, cap))
69141 + cap_raise(cap_drop, cap);
69142 + }
69143 + }
69144 +
69145 + if (!cap_raised(cap_drop, cap))
69146 + return 1;
69147 +
69148 + return 0;
69149 +}
69150 +
69151 +int
69152 +gr_acl_is_capable_nolog(const int cap)
69153 +{
69154 + return gr_task_acl_is_capable_nolog(current, cap);
69155 +}
69156 +
69157 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69158 new file mode 100644
69159 index 0000000..ca25605
69160 --- /dev/null
69161 +++ b/grsecurity/gracl_compat.c
69162 @@ -0,0 +1,270 @@
69163 +#include <linux/kernel.h>
69164 +#include <linux/gracl.h>
69165 +#include <linux/compat.h>
69166 +#include <linux/gracl_compat.h>
69167 +
69168 +#include <asm/uaccess.h>
69169 +
69170 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69171 +{
69172 + struct gr_arg_wrapper_compat uwrapcompat;
69173 +
69174 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69175 + return -EFAULT;
69176 +
69177 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69178 + (uwrapcompat.version != 0x2901)) ||
69179 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69180 + return -EINVAL;
69181 +
69182 + uwrap->arg = compat_ptr(uwrapcompat.arg);
69183 + uwrap->version = uwrapcompat.version;
69184 + uwrap->size = sizeof(struct gr_arg);
69185 +
69186 + return 0;
69187 +}
69188 +
69189 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69190 +{
69191 + struct gr_arg_compat argcompat;
69192 +
69193 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69194 + return -EFAULT;
69195 +
69196 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69197 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69198 + arg->role_db.num_roles = argcompat.role_db.num_roles;
69199 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69200 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69201 + arg->role_db.num_objects = argcompat.role_db.num_objects;
69202 +
69203 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69204 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69205 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69206 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69207 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69208 + arg->segv_device = argcompat.segv_device;
69209 + arg->segv_inode = argcompat.segv_inode;
69210 + arg->segv_uid = argcompat.segv_uid;
69211 + arg->num_sprole_pws = argcompat.num_sprole_pws;
69212 + arg->mode = argcompat.mode;
69213 +
69214 + return 0;
69215 +}
69216 +
69217 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69218 +{
69219 + struct acl_object_label_compat objcompat;
69220 +
69221 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69222 + return -EFAULT;
69223 +
69224 + obj->filename = compat_ptr(objcompat.filename);
69225 + obj->inode = objcompat.inode;
69226 + obj->device = objcompat.device;
69227 + obj->mode = objcompat.mode;
69228 +
69229 + obj->nested = compat_ptr(objcompat.nested);
69230 + obj->globbed = compat_ptr(objcompat.globbed);
69231 +
69232 + obj->prev = compat_ptr(objcompat.prev);
69233 + obj->next = compat_ptr(objcompat.next);
69234 +
69235 + return 0;
69236 +}
69237 +
69238 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69239 +{
69240 + unsigned int i;
69241 + struct acl_subject_label_compat subjcompat;
69242 +
69243 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69244 + return -EFAULT;
69245 +
69246 + subj->filename = compat_ptr(subjcompat.filename);
69247 + subj->inode = subjcompat.inode;
69248 + subj->device = subjcompat.device;
69249 + subj->mode = subjcompat.mode;
69250 + subj->cap_mask = subjcompat.cap_mask;
69251 + subj->cap_lower = subjcompat.cap_lower;
69252 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
69253 +
69254 + for (i = 0; i < GR_NLIMITS; i++) {
69255 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69256 + subj->res[i].rlim_cur = RLIM_INFINITY;
69257 + else
69258 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69259 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69260 + subj->res[i].rlim_max = RLIM_INFINITY;
69261 + else
69262 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
69263 + }
69264 + subj->resmask = subjcompat.resmask;
69265 +
69266 + subj->user_trans_type = subjcompat.user_trans_type;
69267 + subj->group_trans_type = subjcompat.group_trans_type;
69268 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
69269 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
69270 + subj->user_trans_num = subjcompat.user_trans_num;
69271 + subj->group_trans_num = subjcompat.group_trans_num;
69272 +
69273 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
69274 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
69275 + subj->ip_type = subjcompat.ip_type;
69276 + subj->ips = compat_ptr(subjcompat.ips);
69277 + subj->ip_num = subjcompat.ip_num;
69278 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
69279 +
69280 + subj->crashes = subjcompat.crashes;
69281 + subj->expires = subjcompat.expires;
69282 +
69283 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
69284 + subj->hash = compat_ptr(subjcompat.hash);
69285 + subj->prev = compat_ptr(subjcompat.prev);
69286 + subj->next = compat_ptr(subjcompat.next);
69287 +
69288 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
69289 + subj->obj_hash_size = subjcompat.obj_hash_size;
69290 + subj->pax_flags = subjcompat.pax_flags;
69291 +
69292 + return 0;
69293 +}
69294 +
69295 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
69296 +{
69297 + struct acl_role_label_compat rolecompat;
69298 +
69299 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
69300 + return -EFAULT;
69301 +
69302 + role->rolename = compat_ptr(rolecompat.rolename);
69303 + role->uidgid = rolecompat.uidgid;
69304 + role->roletype = rolecompat.roletype;
69305 +
69306 + role->auth_attempts = rolecompat.auth_attempts;
69307 + role->expires = rolecompat.expires;
69308 +
69309 + role->root_label = compat_ptr(rolecompat.root_label);
69310 + role->hash = compat_ptr(rolecompat.hash);
69311 +
69312 + role->prev = compat_ptr(rolecompat.prev);
69313 + role->next = compat_ptr(rolecompat.next);
69314 +
69315 + role->transitions = compat_ptr(rolecompat.transitions);
69316 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
69317 + role->domain_children = compat_ptr(rolecompat.domain_children);
69318 + role->domain_child_num = rolecompat.domain_child_num;
69319 +
69320 + role->umask = rolecompat.umask;
69321 +
69322 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
69323 + role->subj_hash_size = rolecompat.subj_hash_size;
69324 +
69325 + return 0;
69326 +}
69327 +
69328 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69329 +{
69330 + struct role_allowed_ip_compat roleip_compat;
69331 +
69332 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
69333 + return -EFAULT;
69334 +
69335 + roleip->addr = roleip_compat.addr;
69336 + roleip->netmask = roleip_compat.netmask;
69337 +
69338 + roleip->prev = compat_ptr(roleip_compat.prev);
69339 + roleip->next = compat_ptr(roleip_compat.next);
69340 +
69341 + return 0;
69342 +}
69343 +
69344 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
69345 +{
69346 + struct role_transition_compat trans_compat;
69347 +
69348 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
69349 + return -EFAULT;
69350 +
69351 + trans->rolename = compat_ptr(trans_compat.rolename);
69352 +
69353 + trans->prev = compat_ptr(trans_compat.prev);
69354 + trans->next = compat_ptr(trans_compat.next);
69355 +
69356 + return 0;
69357 +
69358 +}
69359 +
69360 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69361 +{
69362 + struct gr_hash_struct_compat hash_compat;
69363 +
69364 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
69365 + return -EFAULT;
69366 +
69367 + hash->table = compat_ptr(hash_compat.table);
69368 + hash->nametable = compat_ptr(hash_compat.nametable);
69369 + hash->first = compat_ptr(hash_compat.first);
69370 +
69371 + hash->table_size = hash_compat.table_size;
69372 + hash->used_size = hash_compat.used_size;
69373 +
69374 + hash->type = hash_compat.type;
69375 +
69376 + return 0;
69377 +}
69378 +
69379 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
69380 +{
69381 + compat_uptr_t ptrcompat;
69382 +
69383 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
69384 + return -EFAULT;
69385 +
69386 + *(void **)ptr = compat_ptr(ptrcompat);
69387 +
69388 + return 0;
69389 +}
69390 +
69391 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69392 +{
69393 + struct acl_ip_label_compat ip_compat;
69394 +
69395 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
69396 + return -EFAULT;
69397 +
69398 + ip->iface = compat_ptr(ip_compat.iface);
69399 + ip->addr = ip_compat.addr;
69400 + ip->netmask = ip_compat.netmask;
69401 + ip->low = ip_compat.low;
69402 + ip->high = ip_compat.high;
69403 + ip->mode = ip_compat.mode;
69404 + ip->type = ip_compat.type;
69405 +
69406 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
69407 +
69408 + ip->prev = compat_ptr(ip_compat.prev);
69409 + ip->next = compat_ptr(ip_compat.next);
69410 +
69411 + return 0;
69412 +}
69413 +
69414 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69415 +{
69416 + struct sprole_pw_compat pw_compat;
69417 +
69418 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
69419 + return -EFAULT;
69420 +
69421 + pw->rolename = compat_ptr(pw_compat.rolename);
69422 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
69423 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
69424 +
69425 + return 0;
69426 +}
69427 +
69428 +size_t get_gr_arg_wrapper_size_compat(void)
69429 +{
69430 + return sizeof(struct gr_arg_wrapper_compat);
69431 +}
69432 +
69433 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
69434 new file mode 100644
69435 index 0000000..a89b1f4
69436 --- /dev/null
69437 +++ b/grsecurity/gracl_fs.c
69438 @@ -0,0 +1,437 @@
69439 +#include <linux/kernel.h>
69440 +#include <linux/sched.h>
69441 +#include <linux/types.h>
69442 +#include <linux/fs.h>
69443 +#include <linux/file.h>
69444 +#include <linux/stat.h>
69445 +#include <linux/grsecurity.h>
69446 +#include <linux/grinternal.h>
69447 +#include <linux/gracl.h>
69448 +
69449 +umode_t
69450 +gr_acl_umask(void)
69451 +{
69452 + if (unlikely(!gr_acl_is_enabled()))
69453 + return 0;
69454 +
69455 + return current->role->umask;
69456 +}
69457 +
69458 +__u32
69459 +gr_acl_handle_hidden_file(const struct dentry * dentry,
69460 + const struct vfsmount * mnt)
69461 +{
69462 + __u32 mode;
69463 +
69464 + if (unlikely(d_is_negative(dentry)))
69465 + return GR_FIND;
69466 +
69467 + mode =
69468 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
69469 +
69470 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
69471 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69472 + return mode;
69473 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
69474 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69475 + return 0;
69476 + } else if (unlikely(!(mode & GR_FIND)))
69477 + return 0;
69478 +
69479 + return GR_FIND;
69480 +}
69481 +
69482 +__u32
69483 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
69484 + int acc_mode)
69485 +{
69486 + __u32 reqmode = GR_FIND;
69487 + __u32 mode;
69488 +
69489 + if (unlikely(d_is_negative(dentry)))
69490 + return reqmode;
69491 +
69492 + if (acc_mode & MAY_APPEND)
69493 + reqmode |= GR_APPEND;
69494 + else if (acc_mode & MAY_WRITE)
69495 + reqmode |= GR_WRITE;
69496 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
69497 + reqmode |= GR_READ;
69498 +
69499 + mode =
69500 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69501 + mnt);
69502 +
69503 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69504 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69505 + reqmode & GR_READ ? " reading" : "",
69506 + reqmode & GR_WRITE ? " writing" : reqmode &
69507 + GR_APPEND ? " appending" : "");
69508 + return reqmode;
69509 + } else
69510 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69511 + {
69512 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69513 + reqmode & GR_READ ? " reading" : "",
69514 + reqmode & GR_WRITE ? " writing" : reqmode &
69515 + GR_APPEND ? " appending" : "");
69516 + return 0;
69517 + } else if (unlikely((mode & reqmode) != reqmode))
69518 + return 0;
69519 +
69520 + return reqmode;
69521 +}
69522 +
69523 +__u32
69524 +gr_acl_handle_creat(const struct dentry * dentry,
69525 + const struct dentry * p_dentry,
69526 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69527 + const int imode)
69528 +{
69529 + __u32 reqmode = GR_WRITE | GR_CREATE;
69530 + __u32 mode;
69531 +
69532 + if (acc_mode & MAY_APPEND)
69533 + reqmode |= GR_APPEND;
69534 + // if a directory was required or the directory already exists, then
69535 + // don't count this open as a read
69536 + if ((acc_mode & MAY_READ) &&
69537 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
69538 + reqmode |= GR_READ;
69539 + if ((open_flags & O_CREAT) &&
69540 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69541 + reqmode |= GR_SETID;
69542 +
69543 + mode =
69544 + gr_check_create(dentry, p_dentry, p_mnt,
69545 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69546 +
69547 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69548 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69549 + reqmode & GR_READ ? " reading" : "",
69550 + reqmode & GR_WRITE ? " writing" : reqmode &
69551 + GR_APPEND ? " appending" : "");
69552 + return reqmode;
69553 + } else
69554 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69555 + {
69556 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69557 + reqmode & GR_READ ? " reading" : "",
69558 + reqmode & GR_WRITE ? " writing" : reqmode &
69559 + GR_APPEND ? " appending" : "");
69560 + return 0;
69561 + } else if (unlikely((mode & reqmode) != reqmode))
69562 + return 0;
69563 +
69564 + return reqmode;
69565 +}
69566 +
69567 +__u32
69568 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
69569 + const int fmode)
69570 +{
69571 + __u32 mode, reqmode = GR_FIND;
69572 +
69573 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
69574 + reqmode |= GR_EXEC;
69575 + if (fmode & S_IWOTH)
69576 + reqmode |= GR_WRITE;
69577 + if (fmode & S_IROTH)
69578 + reqmode |= GR_READ;
69579 +
69580 + mode =
69581 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69582 + mnt);
69583 +
69584 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69585 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69586 + reqmode & GR_READ ? " reading" : "",
69587 + reqmode & GR_WRITE ? " writing" : "",
69588 + reqmode & GR_EXEC ? " executing" : "");
69589 + return reqmode;
69590 + } else
69591 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69592 + {
69593 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69594 + reqmode & GR_READ ? " reading" : "",
69595 + reqmode & GR_WRITE ? " writing" : "",
69596 + reqmode & GR_EXEC ? " executing" : "");
69597 + return 0;
69598 + } else if (unlikely((mode & reqmode) != reqmode))
69599 + return 0;
69600 +
69601 + return reqmode;
69602 +}
69603 +
69604 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
69605 +{
69606 + __u32 mode;
69607 +
69608 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
69609 +
69610 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69611 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
69612 + return mode;
69613 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69614 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
69615 + return 0;
69616 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
69617 + return 0;
69618 +
69619 + return (reqmode);
69620 +}
69621 +
69622 +__u32
69623 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
69624 +{
69625 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
69626 +}
69627 +
69628 +__u32
69629 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
69630 +{
69631 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
69632 +}
69633 +
69634 +__u32
69635 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
69636 +{
69637 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
69638 +}
69639 +
69640 +__u32
69641 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
69642 +{
69643 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
69644 +}
69645 +
69646 +__u32
69647 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
69648 + umode_t *modeptr)
69649 +{
69650 + umode_t mode;
69651 +
69652 + *modeptr &= ~gr_acl_umask();
69653 + mode = *modeptr;
69654 +
69655 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
69656 + return 1;
69657 +
69658 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
69659 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
69660 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
69661 + GR_CHMOD_ACL_MSG);
69662 + } else {
69663 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
69664 + }
69665 +}
69666 +
69667 +__u32
69668 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
69669 +{
69670 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
69671 +}
69672 +
69673 +__u32
69674 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
69675 +{
69676 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
69677 +}
69678 +
69679 +__u32
69680 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
69681 +{
69682 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
69683 +}
69684 +
69685 +__u32
69686 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
69687 +{
69688 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
69689 +}
69690 +
69691 +__u32
69692 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
69693 +{
69694 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
69695 + GR_UNIXCONNECT_ACL_MSG);
69696 +}
69697 +
69698 +/* hardlinks require at minimum create and link permission,
69699 + any additional privilege required is based on the
69700 + privilege of the file being linked to
69701 +*/
69702 +__u32
69703 +gr_acl_handle_link(const struct dentry * new_dentry,
69704 + const struct dentry * parent_dentry,
69705 + const struct vfsmount * parent_mnt,
69706 + const struct dentry * old_dentry,
69707 + const struct vfsmount * old_mnt, const struct filename *to)
69708 +{
69709 + __u32 mode;
69710 + __u32 needmode = GR_CREATE | GR_LINK;
69711 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
69712 +
69713 + mode =
69714 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
69715 + old_mnt);
69716 +
69717 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
69718 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69719 + return mode;
69720 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69721 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69722 + return 0;
69723 + } else if (unlikely((mode & needmode) != needmode))
69724 + return 0;
69725 +
69726 + return 1;
69727 +}
69728 +
69729 +__u32
69730 +gr_acl_handle_symlink(const struct dentry * new_dentry,
69731 + const struct dentry * parent_dentry,
69732 + const struct vfsmount * parent_mnt, const struct filename *from)
69733 +{
69734 + __u32 needmode = GR_WRITE | GR_CREATE;
69735 + __u32 mode;
69736 +
69737 + mode =
69738 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
69739 + GR_CREATE | GR_AUDIT_CREATE |
69740 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
69741 +
69742 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
69743 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
69744 + return mode;
69745 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69746 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
69747 + return 0;
69748 + } else if (unlikely((mode & needmode) != needmode))
69749 + return 0;
69750 +
69751 + return (GR_WRITE | GR_CREATE);
69752 +}
69753 +
69754 +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)
69755 +{
69756 + __u32 mode;
69757 +
69758 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69759 +
69760 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69761 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
69762 + return mode;
69763 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69764 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
69765 + return 0;
69766 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
69767 + return 0;
69768 +
69769 + return (reqmode);
69770 +}
69771 +
69772 +__u32
69773 +gr_acl_handle_mknod(const struct dentry * new_dentry,
69774 + const struct dentry * parent_dentry,
69775 + const struct vfsmount * parent_mnt,
69776 + const int mode)
69777 +{
69778 + __u32 reqmode = GR_WRITE | GR_CREATE;
69779 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69780 + reqmode |= GR_SETID;
69781 +
69782 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69783 + reqmode, GR_MKNOD_ACL_MSG);
69784 +}
69785 +
69786 +__u32
69787 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
69788 + const struct dentry *parent_dentry,
69789 + const struct vfsmount *parent_mnt)
69790 +{
69791 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69792 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
69793 +}
69794 +
69795 +#define RENAME_CHECK_SUCCESS(old, new) \
69796 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
69797 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
69798 +
69799 +int
69800 +gr_acl_handle_rename(struct dentry *new_dentry,
69801 + struct dentry *parent_dentry,
69802 + const struct vfsmount *parent_mnt,
69803 + struct dentry *old_dentry,
69804 + struct inode *old_parent_inode,
69805 + struct vfsmount *old_mnt, const struct filename *newname)
69806 +{
69807 + __u32 comp1, comp2;
69808 + int error = 0;
69809 +
69810 + if (unlikely(!gr_acl_is_enabled()))
69811 + return 0;
69812 +
69813 + if (d_is_negative(new_dentry)) {
69814 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
69815 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
69816 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
69817 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
69818 + GR_DELETE | GR_AUDIT_DELETE |
69819 + GR_AUDIT_READ | GR_AUDIT_WRITE |
69820 + GR_SUPPRESS, old_mnt);
69821 + } else {
69822 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
69823 + GR_CREATE | GR_DELETE |
69824 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
69825 + GR_AUDIT_READ | GR_AUDIT_WRITE |
69826 + GR_SUPPRESS, parent_mnt);
69827 + comp2 =
69828 + gr_search_file(old_dentry,
69829 + GR_READ | GR_WRITE | GR_AUDIT_READ |
69830 + GR_DELETE | GR_AUDIT_DELETE |
69831 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
69832 + }
69833 +
69834 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
69835 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
69836 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69837 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
69838 + && !(comp2 & GR_SUPPRESS)) {
69839 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69840 + error = -EACCES;
69841 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
69842 + error = -EACCES;
69843 +
69844 + return error;
69845 +}
69846 +
69847 +void
69848 +gr_acl_handle_exit(void)
69849 +{
69850 + u16 id;
69851 + char *rolename;
69852 +
69853 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
69854 + !(current->role->roletype & GR_ROLE_PERSIST))) {
69855 + id = current->acl_role_id;
69856 + rolename = current->role->rolename;
69857 + gr_set_acls(1);
69858 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
69859 + }
69860 +
69861 + gr_put_exec_file(current);
69862 + return;
69863 +}
69864 +
69865 +int
69866 +gr_acl_handle_procpidmem(const struct task_struct *task)
69867 +{
69868 + if (unlikely(!gr_acl_is_enabled()))
69869 + return 0;
69870 +
69871 + if (task != current && task->acl->mode & GR_PROTPROCFD)
69872 + return -EACCES;
69873 +
69874 + return 0;
69875 +}
69876 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
69877 new file mode 100644
69878 index 0000000..f056b81
69879 --- /dev/null
69880 +++ b/grsecurity/gracl_ip.c
69881 @@ -0,0 +1,386 @@
69882 +#include <linux/kernel.h>
69883 +#include <asm/uaccess.h>
69884 +#include <asm/errno.h>
69885 +#include <net/sock.h>
69886 +#include <linux/file.h>
69887 +#include <linux/fs.h>
69888 +#include <linux/net.h>
69889 +#include <linux/in.h>
69890 +#include <linux/skbuff.h>
69891 +#include <linux/ip.h>
69892 +#include <linux/udp.h>
69893 +#include <linux/types.h>
69894 +#include <linux/sched.h>
69895 +#include <linux/netdevice.h>
69896 +#include <linux/inetdevice.h>
69897 +#include <linux/gracl.h>
69898 +#include <linux/grsecurity.h>
69899 +#include <linux/grinternal.h>
69900 +
69901 +#define GR_BIND 0x01
69902 +#define GR_CONNECT 0x02
69903 +#define GR_INVERT 0x04
69904 +#define GR_BINDOVERRIDE 0x08
69905 +#define GR_CONNECTOVERRIDE 0x10
69906 +#define GR_SOCK_FAMILY 0x20
69907 +
69908 +static const char * gr_protocols[IPPROTO_MAX] = {
69909 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
69910 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
69911 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
69912 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
69913 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
69914 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
69915 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
69916 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
69917 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
69918 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
69919 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
69920 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
69921 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
69922 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
69923 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
69924 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
69925 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
69926 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
69927 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
69928 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
69929 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
69930 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
69931 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
69932 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
69933 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
69934 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
69935 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
69936 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
69937 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
69938 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
69939 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
69940 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
69941 + };
69942 +
69943 +static const char * gr_socktypes[SOCK_MAX] = {
69944 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
69945 + "unknown:7", "unknown:8", "unknown:9", "packet"
69946 + };
69947 +
69948 +static const char * gr_sockfamilies[AF_MAX+1] = {
69949 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
69950 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
69951 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
69952 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
69953 + };
69954 +
69955 +const char *
69956 +gr_proto_to_name(unsigned char proto)
69957 +{
69958 + return gr_protocols[proto];
69959 +}
69960 +
69961 +const char *
69962 +gr_socktype_to_name(unsigned char type)
69963 +{
69964 + return gr_socktypes[type];
69965 +}
69966 +
69967 +const char *
69968 +gr_sockfamily_to_name(unsigned char family)
69969 +{
69970 + return gr_sockfamilies[family];
69971 +}
69972 +
69973 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
69974 +
69975 +int
69976 +gr_search_socket(const int domain, const int type, const int protocol)
69977 +{
69978 + struct acl_subject_label *curr;
69979 + const struct cred *cred = current_cred();
69980 +
69981 + if (unlikely(!gr_acl_is_enabled()))
69982 + goto exit;
69983 +
69984 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
69985 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
69986 + goto exit; // let the kernel handle it
69987 +
69988 + curr = current->acl;
69989 +
69990 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
69991 + /* the family is allowed, if this is PF_INET allow it only if
69992 + the extra sock type/protocol checks pass */
69993 + if (domain == PF_INET)
69994 + goto inet_check;
69995 + goto exit;
69996 + } else {
69997 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69998 + __u32 fakeip = 0;
69999 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70000 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70001 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70002 + gr_to_filename(current->exec_file->f_path.dentry,
70003 + current->exec_file->f_path.mnt) :
70004 + curr->filename, curr->filename,
70005 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70006 + &current->signal->saved_ip);
70007 + goto exit;
70008 + }
70009 + goto exit_fail;
70010 + }
70011 +
70012 +inet_check:
70013 + /* the rest of this checking is for IPv4 only */
70014 + if (!curr->ips)
70015 + goto exit;
70016 +
70017 + if ((curr->ip_type & (1U << type)) &&
70018 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70019 + goto exit;
70020 +
70021 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70022 + /* we don't place acls on raw sockets , and sometimes
70023 + dgram/ip sockets are opened for ioctl and not
70024 + bind/connect, so we'll fake a bind learn log */
70025 + if (type == SOCK_RAW || type == SOCK_PACKET) {
70026 + __u32 fakeip = 0;
70027 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70028 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70029 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70030 + gr_to_filename(current->exec_file->f_path.dentry,
70031 + current->exec_file->f_path.mnt) :
70032 + curr->filename, curr->filename,
70033 + &fakeip, 0, type,
70034 + protocol, GR_CONNECT, &current->signal->saved_ip);
70035 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70036 + __u32 fakeip = 0;
70037 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70038 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70039 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70040 + gr_to_filename(current->exec_file->f_path.dentry,
70041 + current->exec_file->f_path.mnt) :
70042 + curr->filename, curr->filename,
70043 + &fakeip, 0, type,
70044 + protocol, GR_BIND, &current->signal->saved_ip);
70045 + }
70046 + /* we'll log when they use connect or bind */
70047 + goto exit;
70048 + }
70049 +
70050 +exit_fail:
70051 + if (domain == PF_INET)
70052 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70053 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
70054 + else if (rcu_access_pointer(net_families[domain]) != NULL)
70055 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70056 + gr_socktype_to_name(type), protocol);
70057 +
70058 + return 0;
70059 +exit:
70060 + return 1;
70061 +}
70062 +
70063 +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)
70064 +{
70065 + if ((ip->mode & mode) &&
70066 + (ip_port >= ip->low) &&
70067 + (ip_port <= ip->high) &&
70068 + ((ntohl(ip_addr) & our_netmask) ==
70069 + (ntohl(our_addr) & our_netmask))
70070 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70071 + && (ip->type & (1U << type))) {
70072 + if (ip->mode & GR_INVERT)
70073 + return 2; // specifically denied
70074 + else
70075 + return 1; // allowed
70076 + }
70077 +
70078 + return 0; // not specifically allowed, may continue parsing
70079 +}
70080 +
70081 +static int
70082 +gr_search_connectbind(const int full_mode, struct sock *sk,
70083 + struct sockaddr_in *addr, const int type)
70084 +{
70085 + char iface[IFNAMSIZ] = {0};
70086 + struct acl_subject_label *curr;
70087 + struct acl_ip_label *ip;
70088 + struct inet_sock *isk;
70089 + struct net_device *dev;
70090 + struct in_device *idev;
70091 + unsigned long i;
70092 + int ret;
70093 + int mode = full_mode & (GR_BIND | GR_CONNECT);
70094 + __u32 ip_addr = 0;
70095 + __u32 our_addr;
70096 + __u32 our_netmask;
70097 + char *p;
70098 + __u16 ip_port = 0;
70099 + const struct cred *cred = current_cred();
70100 +
70101 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70102 + return 0;
70103 +
70104 + curr = current->acl;
70105 + isk = inet_sk(sk);
70106 +
70107 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70108 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70109 + addr->sin_addr.s_addr = curr->inaddr_any_override;
70110 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70111 + struct sockaddr_in saddr;
70112 + int err;
70113 +
70114 + saddr.sin_family = AF_INET;
70115 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
70116 + saddr.sin_port = isk->inet_sport;
70117 +
70118 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70119 + if (err)
70120 + return err;
70121 +
70122 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70123 + if (err)
70124 + return err;
70125 + }
70126 +
70127 + if (!curr->ips)
70128 + return 0;
70129 +
70130 + ip_addr = addr->sin_addr.s_addr;
70131 + ip_port = ntohs(addr->sin_port);
70132 +
70133 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70134 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70135 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70136 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70137 + gr_to_filename(current->exec_file->f_path.dentry,
70138 + current->exec_file->f_path.mnt) :
70139 + curr->filename, curr->filename,
70140 + &ip_addr, ip_port, type,
70141 + sk->sk_protocol, mode, &current->signal->saved_ip);
70142 + return 0;
70143 + }
70144 +
70145 + for (i = 0; i < curr->ip_num; i++) {
70146 + ip = *(curr->ips + i);
70147 + if (ip->iface != NULL) {
70148 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
70149 + p = strchr(iface, ':');
70150 + if (p != NULL)
70151 + *p = '\0';
70152 + dev = dev_get_by_name(sock_net(sk), iface);
70153 + if (dev == NULL)
70154 + continue;
70155 + idev = in_dev_get(dev);
70156 + if (idev == NULL) {
70157 + dev_put(dev);
70158 + continue;
70159 + }
70160 + rcu_read_lock();
70161 + for_ifa(idev) {
70162 + if (!strcmp(ip->iface, ifa->ifa_label)) {
70163 + our_addr = ifa->ifa_address;
70164 + our_netmask = 0xffffffff;
70165 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70166 + if (ret == 1) {
70167 + rcu_read_unlock();
70168 + in_dev_put(idev);
70169 + dev_put(dev);
70170 + return 0;
70171 + } else if (ret == 2) {
70172 + rcu_read_unlock();
70173 + in_dev_put(idev);
70174 + dev_put(dev);
70175 + goto denied;
70176 + }
70177 + }
70178 + } endfor_ifa(idev);
70179 + rcu_read_unlock();
70180 + in_dev_put(idev);
70181 + dev_put(dev);
70182 + } else {
70183 + our_addr = ip->addr;
70184 + our_netmask = ip->netmask;
70185 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70186 + if (ret == 1)
70187 + return 0;
70188 + else if (ret == 2)
70189 + goto denied;
70190 + }
70191 + }
70192 +
70193 +denied:
70194 + if (mode == GR_BIND)
70195 + 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));
70196 + else if (mode == GR_CONNECT)
70197 + 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));
70198 +
70199 + return -EACCES;
70200 +}
70201 +
70202 +int
70203 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70204 +{
70205 + /* always allow disconnection of dgram sockets with connect */
70206 + if (addr->sin_family == AF_UNSPEC)
70207 + return 0;
70208 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70209 +}
70210 +
70211 +int
70212 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70213 +{
70214 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70215 +}
70216 +
70217 +int gr_search_listen(struct socket *sock)
70218 +{
70219 + struct sock *sk = sock->sk;
70220 + struct sockaddr_in addr;
70221 +
70222 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70223 + addr.sin_port = inet_sk(sk)->inet_sport;
70224 +
70225 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70226 +}
70227 +
70228 +int gr_search_accept(struct socket *sock)
70229 +{
70230 + struct sock *sk = sock->sk;
70231 + struct sockaddr_in addr;
70232 +
70233 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70234 + addr.sin_port = inet_sk(sk)->inet_sport;
70235 +
70236 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70237 +}
70238 +
70239 +int
70240 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70241 +{
70242 + if (addr)
70243 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70244 + else {
70245 + struct sockaddr_in sin;
70246 + const struct inet_sock *inet = inet_sk(sk);
70247 +
70248 + sin.sin_addr.s_addr = inet->inet_daddr;
70249 + sin.sin_port = inet->inet_dport;
70250 +
70251 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70252 + }
70253 +}
70254 +
70255 +int
70256 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
70257 +{
70258 + struct sockaddr_in sin;
70259 +
70260 + if (unlikely(skb->len < sizeof (struct udphdr)))
70261 + return 0; // skip this packet
70262 +
70263 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
70264 + sin.sin_port = udp_hdr(skb)->source;
70265 +
70266 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70267 +}
70268 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
70269 new file mode 100644
70270 index 0000000..25f54ef
70271 --- /dev/null
70272 +++ b/grsecurity/gracl_learn.c
70273 @@ -0,0 +1,207 @@
70274 +#include <linux/kernel.h>
70275 +#include <linux/mm.h>
70276 +#include <linux/sched.h>
70277 +#include <linux/poll.h>
70278 +#include <linux/string.h>
70279 +#include <linux/file.h>
70280 +#include <linux/types.h>
70281 +#include <linux/vmalloc.h>
70282 +#include <linux/grinternal.h>
70283 +
70284 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
70285 + size_t count, loff_t *ppos);
70286 +extern int gr_acl_is_enabled(void);
70287 +
70288 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
70289 +static int gr_learn_attached;
70290 +
70291 +/* use a 512k buffer */
70292 +#define LEARN_BUFFER_SIZE (512 * 1024)
70293 +
70294 +static DEFINE_SPINLOCK(gr_learn_lock);
70295 +static DEFINE_MUTEX(gr_learn_user_mutex);
70296 +
70297 +/* we need to maintain two buffers, so that the kernel context of grlearn
70298 + uses a semaphore around the userspace copying, and the other kernel contexts
70299 + use a spinlock when copying into the buffer, since they cannot sleep
70300 +*/
70301 +static char *learn_buffer;
70302 +static char *learn_buffer_user;
70303 +static int learn_buffer_len;
70304 +static int learn_buffer_user_len;
70305 +
70306 +static ssize_t
70307 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
70308 +{
70309 + DECLARE_WAITQUEUE(wait, current);
70310 + ssize_t retval = 0;
70311 +
70312 + add_wait_queue(&learn_wait, &wait);
70313 + set_current_state(TASK_INTERRUPTIBLE);
70314 + do {
70315 + mutex_lock(&gr_learn_user_mutex);
70316 + spin_lock(&gr_learn_lock);
70317 + if (learn_buffer_len)
70318 + break;
70319 + spin_unlock(&gr_learn_lock);
70320 + mutex_unlock(&gr_learn_user_mutex);
70321 + if (file->f_flags & O_NONBLOCK) {
70322 + retval = -EAGAIN;
70323 + goto out;
70324 + }
70325 + if (signal_pending(current)) {
70326 + retval = -ERESTARTSYS;
70327 + goto out;
70328 + }
70329 +
70330 + schedule();
70331 + } while (1);
70332 +
70333 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
70334 + learn_buffer_user_len = learn_buffer_len;
70335 + retval = learn_buffer_len;
70336 + learn_buffer_len = 0;
70337 +
70338 + spin_unlock(&gr_learn_lock);
70339 +
70340 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
70341 + retval = -EFAULT;
70342 +
70343 + mutex_unlock(&gr_learn_user_mutex);
70344 +out:
70345 + set_current_state(TASK_RUNNING);
70346 + remove_wait_queue(&learn_wait, &wait);
70347 + return retval;
70348 +}
70349 +
70350 +static unsigned int
70351 +poll_learn(struct file * file, poll_table * wait)
70352 +{
70353 + poll_wait(file, &learn_wait, wait);
70354 +
70355 + if (learn_buffer_len)
70356 + return (POLLIN | POLLRDNORM);
70357 +
70358 + return 0;
70359 +}
70360 +
70361 +void
70362 +gr_clear_learn_entries(void)
70363 +{
70364 + char *tmp;
70365 +
70366 + mutex_lock(&gr_learn_user_mutex);
70367 + spin_lock(&gr_learn_lock);
70368 + tmp = learn_buffer;
70369 + learn_buffer = NULL;
70370 + spin_unlock(&gr_learn_lock);
70371 + if (tmp)
70372 + vfree(tmp);
70373 + if (learn_buffer_user != NULL) {
70374 + vfree(learn_buffer_user);
70375 + learn_buffer_user = NULL;
70376 + }
70377 + learn_buffer_len = 0;
70378 + mutex_unlock(&gr_learn_user_mutex);
70379 +
70380 + return;
70381 +}
70382 +
70383 +void
70384 +gr_add_learn_entry(const char *fmt, ...)
70385 +{
70386 + va_list args;
70387 + unsigned int len;
70388 +
70389 + if (!gr_learn_attached)
70390 + return;
70391 +
70392 + spin_lock(&gr_learn_lock);
70393 +
70394 + /* leave a gap at the end so we know when it's "full" but don't have to
70395 + compute the exact length of the string we're trying to append
70396 + */
70397 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
70398 + spin_unlock(&gr_learn_lock);
70399 + wake_up_interruptible(&learn_wait);
70400 + return;
70401 + }
70402 + if (learn_buffer == NULL) {
70403 + spin_unlock(&gr_learn_lock);
70404 + return;
70405 + }
70406 +
70407 + va_start(args, fmt);
70408 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
70409 + va_end(args);
70410 +
70411 + learn_buffer_len += len + 1;
70412 +
70413 + spin_unlock(&gr_learn_lock);
70414 + wake_up_interruptible(&learn_wait);
70415 +
70416 + return;
70417 +}
70418 +
70419 +static int
70420 +open_learn(struct inode *inode, struct file *file)
70421 +{
70422 + if (file->f_mode & FMODE_READ && gr_learn_attached)
70423 + return -EBUSY;
70424 + if (file->f_mode & FMODE_READ) {
70425 + int retval = 0;
70426 + mutex_lock(&gr_learn_user_mutex);
70427 + if (learn_buffer == NULL)
70428 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
70429 + if (learn_buffer_user == NULL)
70430 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
70431 + if (learn_buffer == NULL) {
70432 + retval = -ENOMEM;
70433 + goto out_error;
70434 + }
70435 + if (learn_buffer_user == NULL) {
70436 + retval = -ENOMEM;
70437 + goto out_error;
70438 + }
70439 + learn_buffer_len = 0;
70440 + learn_buffer_user_len = 0;
70441 + gr_learn_attached = 1;
70442 +out_error:
70443 + mutex_unlock(&gr_learn_user_mutex);
70444 + return retval;
70445 + }
70446 + return 0;
70447 +}
70448 +
70449 +static int
70450 +close_learn(struct inode *inode, struct file *file)
70451 +{
70452 + if (file->f_mode & FMODE_READ) {
70453 + char *tmp = NULL;
70454 + mutex_lock(&gr_learn_user_mutex);
70455 + spin_lock(&gr_learn_lock);
70456 + tmp = learn_buffer;
70457 + learn_buffer = NULL;
70458 + spin_unlock(&gr_learn_lock);
70459 + if (tmp)
70460 + vfree(tmp);
70461 + if (learn_buffer_user != NULL) {
70462 + vfree(learn_buffer_user);
70463 + learn_buffer_user = NULL;
70464 + }
70465 + learn_buffer_len = 0;
70466 + learn_buffer_user_len = 0;
70467 + gr_learn_attached = 0;
70468 + mutex_unlock(&gr_learn_user_mutex);
70469 + }
70470 +
70471 + return 0;
70472 +}
70473 +
70474 +const struct file_operations grsec_fops = {
70475 + .read = read_learn,
70476 + .write = write_grsec_handler,
70477 + .open = open_learn,
70478 + .release = close_learn,
70479 + .poll = poll_learn,
70480 +};
70481 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
70482 new file mode 100644
70483 index 0000000..361a099
70484 --- /dev/null
70485 +++ b/grsecurity/gracl_policy.c
70486 @@ -0,0 +1,1782 @@
70487 +#include <linux/kernel.h>
70488 +#include <linux/module.h>
70489 +#include <linux/sched.h>
70490 +#include <linux/mm.h>
70491 +#include <linux/file.h>
70492 +#include <linux/fs.h>
70493 +#include <linux/namei.h>
70494 +#include <linux/mount.h>
70495 +#include <linux/tty.h>
70496 +#include <linux/proc_fs.h>
70497 +#include <linux/lglock.h>
70498 +#include <linux/slab.h>
70499 +#include <linux/vmalloc.h>
70500 +#include <linux/types.h>
70501 +#include <linux/sysctl.h>
70502 +#include <linux/netdevice.h>
70503 +#include <linux/ptrace.h>
70504 +#include <linux/gracl.h>
70505 +#include <linux/gralloc.h>
70506 +#include <linux/security.h>
70507 +#include <linux/grinternal.h>
70508 +#include <linux/pid_namespace.h>
70509 +#include <linux/stop_machine.h>
70510 +#include <linux/fdtable.h>
70511 +#include <linux/percpu.h>
70512 +#include <linux/lglock.h>
70513 +#include <linux/hugetlb.h>
70514 +#include <linux/posix-timers.h>
70515 +#include "../fs/mount.h"
70516 +
70517 +#include <asm/uaccess.h>
70518 +#include <asm/errno.h>
70519 +#include <asm/mman.h>
70520 +
70521 +extern struct gr_policy_state *polstate;
70522 +
70523 +#define FOR_EACH_ROLE_START(role) \
70524 + role = polstate->role_list; \
70525 + while (role) {
70526 +
70527 +#define FOR_EACH_ROLE_END(role) \
70528 + role = role->prev; \
70529 + }
70530 +
70531 +struct path gr_real_root;
70532 +
70533 +extern struct gr_alloc_state *current_alloc_state;
70534 +
70535 +u16 acl_sp_role_value;
70536 +
70537 +static DEFINE_MUTEX(gr_dev_mutex);
70538 +
70539 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
70540 +extern void gr_clear_learn_entries(void);
70541 +
70542 +static struct gr_arg gr_usermode;
70543 +static unsigned char gr_system_salt[GR_SALT_LEN];
70544 +static unsigned char gr_system_sum[GR_SHA_LEN];
70545 +
70546 +static unsigned int gr_auth_attempts = 0;
70547 +static unsigned long gr_auth_expires = 0UL;
70548 +
70549 +struct acl_object_label *fakefs_obj_rw;
70550 +struct acl_object_label *fakefs_obj_rwx;
70551 +
70552 +extern int gr_init_uidset(void);
70553 +extern void gr_free_uidset(void);
70554 +extern void gr_remove_uid(uid_t uid);
70555 +extern int gr_find_uid(uid_t uid);
70556 +
70557 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
70558 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
70559 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
70560 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
70561 +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);
70562 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
70563 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
70564 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
70565 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
70566 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70567 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70568 +extern void assign_special_role(const char *rolename);
70569 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
70570 +extern int gr_rbac_disable(void *unused);
70571 +extern void gr_enable_rbac_system(void);
70572 +
70573 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
70574 +{
70575 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
70576 + return -EFAULT;
70577 +
70578 + return 0;
70579 +}
70580 +
70581 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70582 +{
70583 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
70584 + return -EFAULT;
70585 +
70586 + return 0;
70587 +}
70588 +
70589 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70590 +{
70591 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
70592 + return -EFAULT;
70593 +
70594 + return 0;
70595 +}
70596 +
70597 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
70598 +{
70599 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
70600 + return -EFAULT;
70601 +
70602 + return 0;
70603 +}
70604 +
70605 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70606 +{
70607 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
70608 + return -EFAULT;
70609 +
70610 + return 0;
70611 +}
70612 +
70613 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70614 +{
70615 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
70616 + return -EFAULT;
70617 +
70618 + return 0;
70619 +}
70620 +
70621 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70622 +{
70623 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
70624 + return -EFAULT;
70625 +
70626 + return 0;
70627 +}
70628 +
70629 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
70630 +{
70631 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
70632 + return -EFAULT;
70633 +
70634 + return 0;
70635 +}
70636 +
70637 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
70638 +{
70639 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
70640 + return -EFAULT;
70641 +
70642 + return 0;
70643 +}
70644 +
70645 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
70646 +{
70647 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
70648 + return -EFAULT;
70649 +
70650 + if (((uwrap->version != GRSECURITY_VERSION) &&
70651 + (uwrap->version != 0x2901)) ||
70652 + (uwrap->size != sizeof(struct gr_arg)))
70653 + return -EINVAL;
70654 +
70655 + return 0;
70656 +}
70657 +
70658 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
70659 +{
70660 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
70661 + return -EFAULT;
70662 +
70663 + return 0;
70664 +}
70665 +
70666 +static size_t get_gr_arg_wrapper_size_normal(void)
70667 +{
70668 + return sizeof(struct gr_arg_wrapper);
70669 +}
70670 +
70671 +#ifdef CONFIG_COMPAT
70672 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
70673 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
70674 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
70675 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
70676 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
70677 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
70678 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
70679 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
70680 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
70681 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
70682 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
70683 +extern size_t get_gr_arg_wrapper_size_compat(void);
70684 +
70685 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
70686 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
70687 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
70688 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
70689 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
70690 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
70691 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
70692 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
70693 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
70694 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
70695 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
70696 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
70697 +
70698 +#else
70699 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
70700 +#define copy_gr_arg copy_gr_arg_normal
70701 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
70702 +#define copy_acl_object_label copy_acl_object_label_normal
70703 +#define copy_acl_subject_label copy_acl_subject_label_normal
70704 +#define copy_acl_role_label copy_acl_role_label_normal
70705 +#define copy_acl_ip_label copy_acl_ip_label_normal
70706 +#define copy_pointer_from_array copy_pointer_from_array_normal
70707 +#define copy_sprole_pw copy_sprole_pw_normal
70708 +#define copy_role_transition copy_role_transition_normal
70709 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
70710 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
70711 +#endif
70712 +
70713 +static struct acl_subject_label *
70714 +lookup_subject_map(const struct acl_subject_label *userp)
70715 +{
70716 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
70717 + struct subject_map *match;
70718 +
70719 + match = polstate->subj_map_set.s_hash[index];
70720 +
70721 + while (match && match->user != userp)
70722 + match = match->next;
70723 +
70724 + if (match != NULL)
70725 + return match->kernel;
70726 + else
70727 + return NULL;
70728 +}
70729 +
70730 +static void
70731 +insert_subj_map_entry(struct subject_map *subjmap)
70732 +{
70733 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
70734 + struct subject_map **curr;
70735 +
70736 + subjmap->prev = NULL;
70737 +
70738 + curr = &polstate->subj_map_set.s_hash[index];
70739 + if (*curr != NULL)
70740 + (*curr)->prev = subjmap;
70741 +
70742 + subjmap->next = *curr;
70743 + *curr = subjmap;
70744 +
70745 + return;
70746 +}
70747 +
70748 +static void
70749 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
70750 +{
70751 + unsigned int index =
70752 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
70753 + struct acl_role_label **curr;
70754 + struct acl_role_label *tmp, *tmp2;
70755 +
70756 + curr = &polstate->acl_role_set.r_hash[index];
70757 +
70758 + /* simple case, slot is empty, just set it to our role */
70759 + if (*curr == NULL) {
70760 + *curr = role;
70761 + } else {
70762 + /* example:
70763 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
70764 + 2 -> 3
70765 + */
70766 + /* first check to see if we can already be reached via this slot */
70767 + tmp = *curr;
70768 + while (tmp && tmp != role)
70769 + tmp = tmp->next;
70770 + if (tmp == role) {
70771 + /* we don't need to add ourselves to this slot's chain */
70772 + return;
70773 + }
70774 + /* we need to add ourselves to this chain, two cases */
70775 + if (role->next == NULL) {
70776 + /* simple case, append the current chain to our role */
70777 + role->next = *curr;
70778 + *curr = role;
70779 + } else {
70780 + /* 1 -> 2 -> 3 -> 4
70781 + 2 -> 3 -> 4
70782 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
70783 + */
70784 + /* trickier case: walk our role's chain until we find
70785 + the role for the start of the current slot's chain */
70786 + tmp = role;
70787 + tmp2 = *curr;
70788 + while (tmp->next && tmp->next != tmp2)
70789 + tmp = tmp->next;
70790 + if (tmp->next == tmp2) {
70791 + /* from example above, we found 3, so just
70792 + replace this slot's chain with ours */
70793 + *curr = role;
70794 + } else {
70795 + /* we didn't find a subset of our role's chain
70796 + in the current slot's chain, so append their
70797 + chain to ours, and set us as the first role in
70798 + the slot's chain
70799 +
70800 + we could fold this case with the case above,
70801 + but making it explicit for clarity
70802 + */
70803 + tmp->next = tmp2;
70804 + *curr = role;
70805 + }
70806 + }
70807 + }
70808 +
70809 + return;
70810 +}
70811 +
70812 +static void
70813 +insert_acl_role_label(struct acl_role_label *role)
70814 +{
70815 + int i;
70816 +
70817 + if (polstate->role_list == NULL) {
70818 + polstate->role_list = role;
70819 + role->prev = NULL;
70820 + } else {
70821 + role->prev = polstate->role_list;
70822 + polstate->role_list = role;
70823 + }
70824 +
70825 + /* used for hash chains */
70826 + role->next = NULL;
70827 +
70828 + if (role->roletype & GR_ROLE_DOMAIN) {
70829 + for (i = 0; i < role->domain_child_num; i++)
70830 + __insert_acl_role_label(role, role->domain_children[i]);
70831 + } else
70832 + __insert_acl_role_label(role, role->uidgid);
70833 +}
70834 +
70835 +static int
70836 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
70837 +{
70838 + struct name_entry **curr, *nentry;
70839 + struct inodev_entry *ientry;
70840 + unsigned int len = strlen(name);
70841 + unsigned int key = full_name_hash(name, len);
70842 + unsigned int index = key % polstate->name_set.n_size;
70843 +
70844 + curr = &polstate->name_set.n_hash[index];
70845 +
70846 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
70847 + curr = &((*curr)->next);
70848 +
70849 + if (*curr != NULL)
70850 + return 1;
70851 +
70852 + nentry = acl_alloc(sizeof (struct name_entry));
70853 + if (nentry == NULL)
70854 + return 0;
70855 + ientry = acl_alloc(sizeof (struct inodev_entry));
70856 + if (ientry == NULL)
70857 + return 0;
70858 + ientry->nentry = nentry;
70859 +
70860 + nentry->key = key;
70861 + nentry->name = name;
70862 + nentry->inode = inode;
70863 + nentry->device = device;
70864 + nentry->len = len;
70865 + nentry->deleted = deleted;
70866 +
70867 + nentry->prev = NULL;
70868 + curr = &polstate->name_set.n_hash[index];
70869 + if (*curr != NULL)
70870 + (*curr)->prev = nentry;
70871 + nentry->next = *curr;
70872 + *curr = nentry;
70873 +
70874 + /* insert us into the table searchable by inode/dev */
70875 + __insert_inodev_entry(polstate, ientry);
70876 +
70877 + return 1;
70878 +}
70879 +
70880 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
70881 +
70882 +static void *
70883 +create_table(__u32 * len, int elementsize)
70884 +{
70885 + unsigned int table_sizes[] = {
70886 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
70887 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
70888 + 4194301, 8388593, 16777213, 33554393, 67108859
70889 + };
70890 + void *newtable = NULL;
70891 + unsigned int pwr = 0;
70892 +
70893 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
70894 + table_sizes[pwr] <= *len)
70895 + pwr++;
70896 +
70897 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
70898 + return newtable;
70899 +
70900 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
70901 + newtable =
70902 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
70903 + else
70904 + newtable = vmalloc(table_sizes[pwr] * elementsize);
70905 +
70906 + *len = table_sizes[pwr];
70907 +
70908 + return newtable;
70909 +}
70910 +
70911 +static int
70912 +init_variables(const struct gr_arg *arg, bool reload)
70913 +{
70914 + struct task_struct *reaper = init_pid_ns.child_reaper;
70915 + unsigned int stacksize;
70916 +
70917 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
70918 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
70919 + polstate->name_set.n_size = arg->role_db.num_objects;
70920 + polstate->inodev_set.i_size = arg->role_db.num_objects;
70921 +
70922 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
70923 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
70924 + return 1;
70925 +
70926 + if (!reload) {
70927 + if (!gr_init_uidset())
70928 + return 1;
70929 + }
70930 +
70931 + /* set up the stack that holds allocation info */
70932 +
70933 + stacksize = arg->role_db.num_pointers + 5;
70934 +
70935 + if (!acl_alloc_stack_init(stacksize))
70936 + return 1;
70937 +
70938 + if (!reload) {
70939 + /* grab reference for the real root dentry and vfsmount */
70940 + get_fs_root(reaper->fs, &gr_real_root);
70941 +
70942 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70943 + 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);
70944 +#endif
70945 +
70946 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
70947 + if (fakefs_obj_rw == NULL)
70948 + return 1;
70949 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
70950 +
70951 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
70952 + if (fakefs_obj_rwx == NULL)
70953 + return 1;
70954 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
70955 + }
70956 +
70957 + polstate->subj_map_set.s_hash =
70958 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
70959 + polstate->acl_role_set.r_hash =
70960 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
70961 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
70962 + polstate->inodev_set.i_hash =
70963 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
70964 +
70965 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
70966 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
70967 + return 1;
70968 +
70969 + memset(polstate->subj_map_set.s_hash, 0,
70970 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
70971 + memset(polstate->acl_role_set.r_hash, 0,
70972 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
70973 + memset(polstate->name_set.n_hash, 0,
70974 + sizeof (struct name_entry *) * polstate->name_set.n_size);
70975 + memset(polstate->inodev_set.i_hash, 0,
70976 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
70977 +
70978 + return 0;
70979 +}
70980 +
70981 +/* free information not needed after startup
70982 + currently contains user->kernel pointer mappings for subjects
70983 +*/
70984 +
70985 +static void
70986 +free_init_variables(void)
70987 +{
70988 + __u32 i;
70989 +
70990 + if (polstate->subj_map_set.s_hash) {
70991 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
70992 + if (polstate->subj_map_set.s_hash[i]) {
70993 + kfree(polstate->subj_map_set.s_hash[i]);
70994 + polstate->subj_map_set.s_hash[i] = NULL;
70995 + }
70996 + }
70997 +
70998 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
70999 + PAGE_SIZE)
71000 + kfree(polstate->subj_map_set.s_hash);
71001 + else
71002 + vfree(polstate->subj_map_set.s_hash);
71003 + }
71004 +
71005 + return;
71006 +}
71007 +
71008 +static void
71009 +free_variables(bool reload)
71010 +{
71011 + struct acl_subject_label *s;
71012 + struct acl_role_label *r;
71013 + struct task_struct *task, *task2;
71014 + unsigned int x;
71015 +
71016 + if (!reload) {
71017 + gr_clear_learn_entries();
71018 +
71019 + read_lock(&tasklist_lock);
71020 + do_each_thread(task2, task) {
71021 + task->acl_sp_role = 0;
71022 + task->acl_role_id = 0;
71023 + task->inherited = 0;
71024 + task->acl = NULL;
71025 + task->role = NULL;
71026 + } while_each_thread(task2, task);
71027 + read_unlock(&tasklist_lock);
71028 +
71029 + kfree(fakefs_obj_rw);
71030 + fakefs_obj_rw = NULL;
71031 + kfree(fakefs_obj_rwx);
71032 + fakefs_obj_rwx = NULL;
71033 +
71034 + /* release the reference to the real root dentry and vfsmount */
71035 + path_put(&gr_real_root);
71036 + memset(&gr_real_root, 0, sizeof(gr_real_root));
71037 + }
71038 +
71039 + /* free all object hash tables */
71040 +
71041 + FOR_EACH_ROLE_START(r)
71042 + if (r->subj_hash == NULL)
71043 + goto next_role;
71044 + FOR_EACH_SUBJECT_START(r, s, x)
71045 + if (s->obj_hash == NULL)
71046 + break;
71047 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71048 + kfree(s->obj_hash);
71049 + else
71050 + vfree(s->obj_hash);
71051 + FOR_EACH_SUBJECT_END(s, x)
71052 + FOR_EACH_NESTED_SUBJECT_START(r, s)
71053 + if (s->obj_hash == NULL)
71054 + break;
71055 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71056 + kfree(s->obj_hash);
71057 + else
71058 + vfree(s->obj_hash);
71059 + FOR_EACH_NESTED_SUBJECT_END(s)
71060 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71061 + kfree(r->subj_hash);
71062 + else
71063 + vfree(r->subj_hash);
71064 + r->subj_hash = NULL;
71065 +next_role:
71066 + FOR_EACH_ROLE_END(r)
71067 +
71068 + acl_free_all();
71069 +
71070 + if (polstate->acl_role_set.r_hash) {
71071 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71072 + PAGE_SIZE)
71073 + kfree(polstate->acl_role_set.r_hash);
71074 + else
71075 + vfree(polstate->acl_role_set.r_hash);
71076 + }
71077 + if (polstate->name_set.n_hash) {
71078 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71079 + PAGE_SIZE)
71080 + kfree(polstate->name_set.n_hash);
71081 + else
71082 + vfree(polstate->name_set.n_hash);
71083 + }
71084 +
71085 + if (polstate->inodev_set.i_hash) {
71086 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71087 + PAGE_SIZE)
71088 + kfree(polstate->inodev_set.i_hash);
71089 + else
71090 + vfree(polstate->inodev_set.i_hash);
71091 + }
71092 +
71093 + if (!reload)
71094 + gr_free_uidset();
71095 +
71096 + memset(&polstate->name_set, 0, sizeof (struct name_db));
71097 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71098 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71099 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71100 +
71101 + polstate->default_role = NULL;
71102 + polstate->kernel_role = NULL;
71103 + polstate->role_list = NULL;
71104 +
71105 + return;
71106 +}
71107 +
71108 +static struct acl_subject_label *
71109 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71110 +
71111 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
71112 +{
71113 + unsigned int len = strnlen_user(*name, maxlen);
71114 + char *tmp;
71115 +
71116 + if (!len || len >= maxlen)
71117 + return -EINVAL;
71118 +
71119 + if ((tmp = (char *) acl_alloc(len)) == NULL)
71120 + return -ENOMEM;
71121 +
71122 + if (copy_from_user(tmp, *name, len))
71123 + return -EFAULT;
71124 +
71125 + tmp[len-1] = '\0';
71126 + *name = tmp;
71127 +
71128 + return 0;
71129 +}
71130 +
71131 +static int
71132 +copy_user_glob(struct acl_object_label *obj)
71133 +{
71134 + struct acl_object_label *g_tmp, **guser;
71135 + int error;
71136 +
71137 + if (obj->globbed == NULL)
71138 + return 0;
71139 +
71140 + guser = &obj->globbed;
71141 + while (*guser) {
71142 + g_tmp = (struct acl_object_label *)
71143 + acl_alloc(sizeof (struct acl_object_label));
71144 + if (g_tmp == NULL)
71145 + return -ENOMEM;
71146 +
71147 + if (copy_acl_object_label(g_tmp, *guser))
71148 + return -EFAULT;
71149 +
71150 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71151 + if (error)
71152 + return error;
71153 +
71154 + *guser = g_tmp;
71155 + guser = &(g_tmp->next);
71156 + }
71157 +
71158 + return 0;
71159 +}
71160 +
71161 +static int
71162 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71163 + struct acl_role_label *role)
71164 +{
71165 + struct acl_object_label *o_tmp;
71166 + int ret;
71167 +
71168 + while (userp) {
71169 + if ((o_tmp = (struct acl_object_label *)
71170 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
71171 + return -ENOMEM;
71172 +
71173 + if (copy_acl_object_label(o_tmp, userp))
71174 + return -EFAULT;
71175 +
71176 + userp = o_tmp->prev;
71177 +
71178 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71179 + if (ret)
71180 + return ret;
71181 +
71182 + insert_acl_obj_label(o_tmp, subj);
71183 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71184 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71185 + return -ENOMEM;
71186 +
71187 + ret = copy_user_glob(o_tmp);
71188 + if (ret)
71189 + return ret;
71190 +
71191 + if (o_tmp->nested) {
71192 + int already_copied;
71193 +
71194 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71195 + if (IS_ERR(o_tmp->nested))
71196 + return PTR_ERR(o_tmp->nested);
71197 +
71198 + /* insert into nested subject list if we haven't copied this one yet
71199 + to prevent duplicate entries */
71200 + if (!already_copied) {
71201 + o_tmp->nested->next = role->hash->first;
71202 + role->hash->first = o_tmp->nested;
71203 + }
71204 + }
71205 + }
71206 +
71207 + return 0;
71208 +}
71209 +
71210 +static __u32
71211 +count_user_subjs(struct acl_subject_label *userp)
71212 +{
71213 + struct acl_subject_label s_tmp;
71214 + __u32 num = 0;
71215 +
71216 + while (userp) {
71217 + if (copy_acl_subject_label(&s_tmp, userp))
71218 + break;
71219 +
71220 + userp = s_tmp.prev;
71221 + }
71222 +
71223 + return num;
71224 +}
71225 +
71226 +static int
71227 +copy_user_allowedips(struct acl_role_label *rolep)
71228 +{
71229 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71230 +
71231 + ruserip = rolep->allowed_ips;
71232 +
71233 + while (ruserip) {
71234 + rlast = rtmp;
71235 +
71236 + if ((rtmp = (struct role_allowed_ip *)
71237 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71238 + return -ENOMEM;
71239 +
71240 + if (copy_role_allowed_ip(rtmp, ruserip))
71241 + return -EFAULT;
71242 +
71243 + ruserip = rtmp->prev;
71244 +
71245 + if (!rlast) {
71246 + rtmp->prev = NULL;
71247 + rolep->allowed_ips = rtmp;
71248 + } else {
71249 + rlast->next = rtmp;
71250 + rtmp->prev = rlast;
71251 + }
71252 +
71253 + if (!ruserip)
71254 + rtmp->next = NULL;
71255 + }
71256 +
71257 + return 0;
71258 +}
71259 +
71260 +static int
71261 +copy_user_transitions(struct acl_role_label *rolep)
71262 +{
71263 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
71264 + int error;
71265 +
71266 + rusertp = rolep->transitions;
71267 +
71268 + while (rusertp) {
71269 + rlast = rtmp;
71270 +
71271 + if ((rtmp = (struct role_transition *)
71272 + acl_alloc(sizeof (struct role_transition))) == NULL)
71273 + return -ENOMEM;
71274 +
71275 + if (copy_role_transition(rtmp, rusertp))
71276 + return -EFAULT;
71277 +
71278 + rusertp = rtmp->prev;
71279 +
71280 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
71281 + if (error)
71282 + return error;
71283 +
71284 + if (!rlast) {
71285 + rtmp->prev = NULL;
71286 + rolep->transitions = rtmp;
71287 + } else {
71288 + rlast->next = rtmp;
71289 + rtmp->prev = rlast;
71290 + }
71291 +
71292 + if (!rusertp)
71293 + rtmp->next = NULL;
71294 + }
71295 +
71296 + return 0;
71297 +}
71298 +
71299 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
71300 +{
71301 + struct acl_object_label o_tmp;
71302 + __u32 num = 0;
71303 +
71304 + while (userp) {
71305 + if (copy_acl_object_label(&o_tmp, userp))
71306 + break;
71307 +
71308 + userp = o_tmp.prev;
71309 + num++;
71310 + }
71311 +
71312 + return num;
71313 +}
71314 +
71315 +static struct acl_subject_label *
71316 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
71317 +{
71318 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
71319 + __u32 num_objs;
71320 + struct acl_ip_label **i_tmp, *i_utmp2;
71321 + struct gr_hash_struct ghash;
71322 + struct subject_map *subjmap;
71323 + unsigned int i_num;
71324 + int err;
71325 +
71326 + if (already_copied != NULL)
71327 + *already_copied = 0;
71328 +
71329 + s_tmp = lookup_subject_map(userp);
71330 +
71331 + /* we've already copied this subject into the kernel, just return
71332 + the reference to it, and don't copy it over again
71333 + */
71334 + if (s_tmp) {
71335 + if (already_copied != NULL)
71336 + *already_copied = 1;
71337 + return(s_tmp);
71338 + }
71339 +
71340 + if ((s_tmp = (struct acl_subject_label *)
71341 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
71342 + return ERR_PTR(-ENOMEM);
71343 +
71344 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
71345 + if (subjmap == NULL)
71346 + return ERR_PTR(-ENOMEM);
71347 +
71348 + subjmap->user = userp;
71349 + subjmap->kernel = s_tmp;
71350 + insert_subj_map_entry(subjmap);
71351 +
71352 + if (copy_acl_subject_label(s_tmp, userp))
71353 + return ERR_PTR(-EFAULT);
71354 +
71355 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
71356 + if (err)
71357 + return ERR_PTR(err);
71358 +
71359 + if (!strcmp(s_tmp->filename, "/"))
71360 + role->root_label = s_tmp;
71361 +
71362 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
71363 + return ERR_PTR(-EFAULT);
71364 +
71365 + /* copy user and group transition tables */
71366 +
71367 + if (s_tmp->user_trans_num) {
71368 + uid_t *uidlist;
71369 +
71370 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
71371 + if (uidlist == NULL)
71372 + return ERR_PTR(-ENOMEM);
71373 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
71374 + return ERR_PTR(-EFAULT);
71375 +
71376 + s_tmp->user_transitions = uidlist;
71377 + }
71378 +
71379 + if (s_tmp->group_trans_num) {
71380 + gid_t *gidlist;
71381 +
71382 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
71383 + if (gidlist == NULL)
71384 + return ERR_PTR(-ENOMEM);
71385 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
71386 + return ERR_PTR(-EFAULT);
71387 +
71388 + s_tmp->group_transitions = gidlist;
71389 + }
71390 +
71391 + /* set up object hash table */
71392 + num_objs = count_user_objs(ghash.first);
71393 +
71394 + s_tmp->obj_hash_size = num_objs;
71395 + s_tmp->obj_hash =
71396 + (struct acl_object_label **)
71397 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
71398 +
71399 + if (!s_tmp->obj_hash)
71400 + return ERR_PTR(-ENOMEM);
71401 +
71402 + memset(s_tmp->obj_hash, 0,
71403 + s_tmp->obj_hash_size *
71404 + sizeof (struct acl_object_label *));
71405 +
71406 + /* add in objects */
71407 + err = copy_user_objs(ghash.first, s_tmp, role);
71408 +
71409 + if (err)
71410 + return ERR_PTR(err);
71411 +
71412 + /* set pointer for parent subject */
71413 + if (s_tmp->parent_subject) {
71414 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
71415 +
71416 + if (IS_ERR(s_tmp2))
71417 + return s_tmp2;
71418 +
71419 + s_tmp->parent_subject = s_tmp2;
71420 + }
71421 +
71422 + /* add in ip acls */
71423 +
71424 + if (!s_tmp->ip_num) {
71425 + s_tmp->ips = NULL;
71426 + goto insert;
71427 + }
71428 +
71429 + i_tmp =
71430 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
71431 + sizeof (struct acl_ip_label *));
71432 +
71433 + if (!i_tmp)
71434 + return ERR_PTR(-ENOMEM);
71435 +
71436 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
71437 + *(i_tmp + i_num) =
71438 + (struct acl_ip_label *)
71439 + acl_alloc(sizeof (struct acl_ip_label));
71440 + if (!*(i_tmp + i_num))
71441 + return ERR_PTR(-ENOMEM);
71442 +
71443 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
71444 + return ERR_PTR(-EFAULT);
71445 +
71446 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
71447 + return ERR_PTR(-EFAULT);
71448 +
71449 + if ((*(i_tmp + i_num))->iface == NULL)
71450 + continue;
71451 +
71452 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
71453 + if (err)
71454 + return ERR_PTR(err);
71455 + }
71456 +
71457 + s_tmp->ips = i_tmp;
71458 +
71459 +insert:
71460 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
71461 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
71462 + return ERR_PTR(-ENOMEM);
71463 +
71464 + return s_tmp;
71465 +}
71466 +
71467 +static int
71468 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
71469 +{
71470 + struct acl_subject_label s_pre;
71471 + struct acl_subject_label * ret;
71472 + int err;
71473 +
71474 + while (userp) {
71475 + if (copy_acl_subject_label(&s_pre, userp))
71476 + return -EFAULT;
71477 +
71478 + ret = do_copy_user_subj(userp, role, NULL);
71479 +
71480 + err = PTR_ERR(ret);
71481 + if (IS_ERR(ret))
71482 + return err;
71483 +
71484 + insert_acl_subj_label(ret, role);
71485 +
71486 + userp = s_pre.prev;
71487 + }
71488 +
71489 + return 0;
71490 +}
71491 +
71492 +static int
71493 +copy_user_acl(struct gr_arg *arg)
71494 +{
71495 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
71496 + struct acl_subject_label *subj_list;
71497 + struct sprole_pw *sptmp;
71498 + struct gr_hash_struct *ghash;
71499 + uid_t *domainlist;
71500 + unsigned int r_num;
71501 + int err = 0;
71502 + __u16 i;
71503 + __u32 num_subjs;
71504 +
71505 + /* we need a default and kernel role */
71506 + if (arg->role_db.num_roles < 2)
71507 + return -EINVAL;
71508 +
71509 + /* copy special role authentication info from userspace */
71510 +
71511 + polstate->num_sprole_pws = arg->num_sprole_pws;
71512 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
71513 +
71514 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
71515 + return -ENOMEM;
71516 +
71517 + for (i = 0; i < polstate->num_sprole_pws; i++) {
71518 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
71519 + if (!sptmp)
71520 + return -ENOMEM;
71521 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
71522 + return -EFAULT;
71523 +
71524 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
71525 + if (err)
71526 + return err;
71527 +
71528 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71529 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
71530 +#endif
71531 +
71532 + polstate->acl_special_roles[i] = sptmp;
71533 + }
71534 +
71535 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
71536 +
71537 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
71538 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
71539 +
71540 + if (!r_tmp)
71541 + return -ENOMEM;
71542 +
71543 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
71544 + return -EFAULT;
71545 +
71546 + if (copy_acl_role_label(r_tmp, r_utmp2))
71547 + return -EFAULT;
71548 +
71549 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
71550 + if (err)
71551 + return err;
71552 +
71553 + if (!strcmp(r_tmp->rolename, "default")
71554 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
71555 + polstate->default_role = r_tmp;
71556 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
71557 + polstate->kernel_role = r_tmp;
71558 + }
71559 +
71560 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
71561 + return -ENOMEM;
71562 +
71563 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
71564 + return -EFAULT;
71565 +
71566 + r_tmp->hash = ghash;
71567 +
71568 + num_subjs = count_user_subjs(r_tmp->hash->first);
71569 +
71570 + r_tmp->subj_hash_size = num_subjs;
71571 + r_tmp->subj_hash =
71572 + (struct acl_subject_label **)
71573 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
71574 +
71575 + if (!r_tmp->subj_hash)
71576 + return -ENOMEM;
71577 +
71578 + err = copy_user_allowedips(r_tmp);
71579 + if (err)
71580 + return err;
71581 +
71582 + /* copy domain info */
71583 + if (r_tmp->domain_children != NULL) {
71584 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
71585 + if (domainlist == NULL)
71586 + return -ENOMEM;
71587 +
71588 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
71589 + return -EFAULT;
71590 +
71591 + r_tmp->domain_children = domainlist;
71592 + }
71593 +
71594 + err = copy_user_transitions(r_tmp);
71595 + if (err)
71596 + return err;
71597 +
71598 + memset(r_tmp->subj_hash, 0,
71599 + r_tmp->subj_hash_size *
71600 + sizeof (struct acl_subject_label *));
71601 +
71602 + /* acquire the list of subjects, then NULL out
71603 + the list prior to parsing the subjects for this role,
71604 + as during this parsing the list is replaced with a list
71605 + of *nested* subjects for the role
71606 + */
71607 + subj_list = r_tmp->hash->first;
71608 +
71609 + /* set nested subject list to null */
71610 + r_tmp->hash->first = NULL;
71611 +
71612 + err = copy_user_subjs(subj_list, r_tmp);
71613 +
71614 + if (err)
71615 + return err;
71616 +
71617 + insert_acl_role_label(r_tmp);
71618 + }
71619 +
71620 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
71621 + return -EINVAL;
71622 +
71623 + return err;
71624 +}
71625 +
71626 +static int gracl_reload_apply_policies(void *reload)
71627 +{
71628 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
71629 + struct task_struct *task, *task2;
71630 + struct acl_role_label *role, *rtmp;
71631 + struct acl_subject_label *subj;
71632 + const struct cred *cred;
71633 + int role_applied;
71634 + int ret = 0;
71635 +
71636 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
71637 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
71638 +
71639 + /* first make sure we'll be able to apply the new policy cleanly */
71640 + do_each_thread(task2, task) {
71641 + if (task->exec_file == NULL)
71642 + continue;
71643 + role_applied = 0;
71644 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71645 + /* preserve special roles */
71646 + FOR_EACH_ROLE_START(role)
71647 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71648 + rtmp = task->role;
71649 + task->role = role;
71650 + role_applied = 1;
71651 + break;
71652 + }
71653 + FOR_EACH_ROLE_END(role)
71654 + }
71655 + if (!role_applied) {
71656 + cred = __task_cred(task);
71657 + rtmp = task->role;
71658 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71659 + }
71660 + /* this handles non-nested inherited subjects, nested subjects will still
71661 + be dropped currently */
71662 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71663 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
71664 + /* change the role back so that we've made no modifications to the policy */
71665 + task->role = rtmp;
71666 +
71667 + if (subj == NULL || task->tmpacl == NULL) {
71668 + ret = -EINVAL;
71669 + goto out;
71670 + }
71671 + } while_each_thread(task2, task);
71672 +
71673 + /* now actually apply the policy */
71674 +
71675 + do_each_thread(task2, task) {
71676 + if (task->exec_file) {
71677 + role_applied = 0;
71678 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71679 + /* preserve special roles */
71680 + FOR_EACH_ROLE_START(role)
71681 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71682 + task->role = role;
71683 + role_applied = 1;
71684 + break;
71685 + }
71686 + FOR_EACH_ROLE_END(role)
71687 + }
71688 + if (!role_applied) {
71689 + cred = __task_cred(task);
71690 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71691 + }
71692 + /* this handles non-nested inherited subjects, nested subjects will still
71693 + be dropped currently */
71694 + if (!reload_state->oldmode && task->inherited)
71695 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71696 + else {
71697 + /* looked up and tagged to the task previously */
71698 + subj = task->tmpacl;
71699 + }
71700 + /* subj will be non-null */
71701 + __gr_apply_subject_to_task(polstate, task, subj);
71702 + if (reload_state->oldmode) {
71703 + task->acl_role_id = 0;
71704 + task->acl_sp_role = 0;
71705 + task->inherited = 0;
71706 + }
71707 + } else {
71708 + // it's a kernel process
71709 + task->role = polstate->kernel_role;
71710 + task->acl = polstate->kernel_role->root_label;
71711 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
71712 + task->acl->mode &= ~GR_PROCFIND;
71713 +#endif
71714 + }
71715 + } while_each_thread(task2, task);
71716 +
71717 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
71718 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
71719 +
71720 +out:
71721 +
71722 + return ret;
71723 +}
71724 +
71725 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
71726 +{
71727 + struct gr_reload_state new_reload_state = { };
71728 + int err;
71729 +
71730 + new_reload_state.oldpolicy_ptr = polstate;
71731 + new_reload_state.oldalloc_ptr = current_alloc_state;
71732 + new_reload_state.oldmode = oldmode;
71733 +
71734 + current_alloc_state = &new_reload_state.newalloc;
71735 + polstate = &new_reload_state.newpolicy;
71736 +
71737 + /* everything relevant is now saved off, copy in the new policy */
71738 + if (init_variables(args, true)) {
71739 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71740 + err = -ENOMEM;
71741 + goto error;
71742 + }
71743 +
71744 + err = copy_user_acl(args);
71745 + free_init_variables();
71746 + if (err)
71747 + goto error;
71748 + /* the new policy is copied in, with the old policy available via saved_state
71749 + first go through applying roles, making sure to preserve special roles
71750 + then apply new subjects, making sure to preserve inherited and nested subjects,
71751 + though currently only inherited subjects will be preserved
71752 + */
71753 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
71754 + if (err)
71755 + goto error;
71756 +
71757 + /* we've now applied the new policy, so restore the old policy state to free it */
71758 + polstate = &new_reload_state.oldpolicy;
71759 + current_alloc_state = &new_reload_state.oldalloc;
71760 + free_variables(true);
71761 +
71762 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
71763 + to running_polstate/current_alloc_state inside stop_machine
71764 + */
71765 + err = 0;
71766 + goto out;
71767 +error:
71768 + /* on error of loading the new policy, we'll just keep the previous
71769 + policy set around
71770 + */
71771 + free_variables(true);
71772 +
71773 + /* doesn't affect runtime, but maintains consistent state */
71774 +out:
71775 + polstate = new_reload_state.oldpolicy_ptr;
71776 + current_alloc_state = new_reload_state.oldalloc_ptr;
71777 +
71778 + return err;
71779 +}
71780 +
71781 +static int
71782 +gracl_init(struct gr_arg *args)
71783 +{
71784 + int error = 0;
71785 +
71786 + memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
71787 + memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
71788 +
71789 + if (init_variables(args, false)) {
71790 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71791 + error = -ENOMEM;
71792 + goto out;
71793 + }
71794 +
71795 + error = copy_user_acl(args);
71796 + free_init_variables();
71797 + if (error)
71798 + goto out;
71799 +
71800 + error = gr_set_acls(0);
71801 + if (error)
71802 + goto out;
71803 +
71804 + gr_enable_rbac_system();
71805 +
71806 + return 0;
71807 +
71808 +out:
71809 + free_variables(false);
71810 + return error;
71811 +}
71812 +
71813 +static int
71814 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
71815 + unsigned char **sum)
71816 +{
71817 + struct acl_role_label *r;
71818 + struct role_allowed_ip *ipp;
71819 + struct role_transition *trans;
71820 + unsigned int i;
71821 + int found = 0;
71822 + u32 curr_ip = current->signal->curr_ip;
71823 +
71824 + current->signal->saved_ip = curr_ip;
71825 +
71826 + /* check transition table */
71827 +
71828 + for (trans = current->role->transitions; trans; trans = trans->next) {
71829 + if (!strcmp(rolename, trans->rolename)) {
71830 + found = 1;
71831 + break;
71832 + }
71833 + }
71834 +
71835 + if (!found)
71836 + return 0;
71837 +
71838 + /* handle special roles that do not require authentication
71839 + and check ip */
71840 +
71841 + FOR_EACH_ROLE_START(r)
71842 + if (!strcmp(rolename, r->rolename) &&
71843 + (r->roletype & GR_ROLE_SPECIAL)) {
71844 + found = 0;
71845 + if (r->allowed_ips != NULL) {
71846 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
71847 + if ((ntohl(curr_ip) & ipp->netmask) ==
71848 + (ntohl(ipp->addr) & ipp->netmask))
71849 + found = 1;
71850 + }
71851 + } else
71852 + found = 2;
71853 + if (!found)
71854 + return 0;
71855 +
71856 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
71857 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
71858 + *salt = NULL;
71859 + *sum = NULL;
71860 + return 1;
71861 + }
71862 + }
71863 + FOR_EACH_ROLE_END(r)
71864 +
71865 + for (i = 0; i < polstate->num_sprole_pws; i++) {
71866 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
71867 + *salt = polstate->acl_special_roles[i]->salt;
71868 + *sum = polstate->acl_special_roles[i]->sum;
71869 + return 1;
71870 + }
71871 + }
71872 +
71873 + return 0;
71874 +}
71875 +
71876 +int gr_check_secure_terminal(struct task_struct *task)
71877 +{
71878 + struct task_struct *p, *p2, *p3;
71879 + struct files_struct *files;
71880 + struct fdtable *fdt;
71881 + struct file *our_file = NULL, *file;
71882 + int i;
71883 +
71884 + if (task->signal->tty == NULL)
71885 + return 1;
71886 +
71887 + files = get_files_struct(task);
71888 + if (files != NULL) {
71889 + rcu_read_lock();
71890 + fdt = files_fdtable(files);
71891 + for (i=0; i < fdt->max_fds; i++) {
71892 + file = fcheck_files(files, i);
71893 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
71894 + get_file(file);
71895 + our_file = file;
71896 + }
71897 + }
71898 + rcu_read_unlock();
71899 + put_files_struct(files);
71900 + }
71901 +
71902 + if (our_file == NULL)
71903 + return 1;
71904 +
71905 + read_lock(&tasklist_lock);
71906 + do_each_thread(p2, p) {
71907 + files = get_files_struct(p);
71908 + if (files == NULL ||
71909 + (p->signal && p->signal->tty == task->signal->tty)) {
71910 + if (files != NULL)
71911 + put_files_struct(files);
71912 + continue;
71913 + }
71914 + rcu_read_lock();
71915 + fdt = files_fdtable(files);
71916 + for (i=0; i < fdt->max_fds; i++) {
71917 + file = fcheck_files(files, i);
71918 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
71919 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
71920 + p3 = task;
71921 + while (task_pid_nr(p3) > 0) {
71922 + if (p3 == p)
71923 + break;
71924 + p3 = p3->real_parent;
71925 + }
71926 + if (p3 == p)
71927 + break;
71928 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
71929 + gr_handle_alertkill(p);
71930 + rcu_read_unlock();
71931 + put_files_struct(files);
71932 + read_unlock(&tasklist_lock);
71933 + fput(our_file);
71934 + return 0;
71935 + }
71936 + }
71937 + rcu_read_unlock();
71938 + put_files_struct(files);
71939 + } while_each_thread(p2, p);
71940 + read_unlock(&tasklist_lock);
71941 +
71942 + fput(our_file);
71943 + return 1;
71944 +}
71945 +
71946 +ssize_t
71947 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
71948 +{
71949 + struct gr_arg_wrapper uwrap;
71950 + unsigned char *sprole_salt = NULL;
71951 + unsigned char *sprole_sum = NULL;
71952 + int error = 0;
71953 + int error2 = 0;
71954 + size_t req_count = 0;
71955 + unsigned char oldmode = 0;
71956 +
71957 + mutex_lock(&gr_dev_mutex);
71958 +
71959 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
71960 + error = -EPERM;
71961 + goto out;
71962 + }
71963 +
71964 +#ifdef CONFIG_COMPAT
71965 + pax_open_kernel();
71966 + if (is_compat_task()) {
71967 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
71968 + copy_gr_arg = &copy_gr_arg_compat;
71969 + copy_acl_object_label = &copy_acl_object_label_compat;
71970 + copy_acl_subject_label = &copy_acl_subject_label_compat;
71971 + copy_acl_role_label = &copy_acl_role_label_compat;
71972 + copy_acl_ip_label = &copy_acl_ip_label_compat;
71973 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
71974 + copy_role_transition = &copy_role_transition_compat;
71975 + copy_sprole_pw = &copy_sprole_pw_compat;
71976 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
71977 + copy_pointer_from_array = &copy_pointer_from_array_compat;
71978 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
71979 + } else {
71980 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
71981 + copy_gr_arg = &copy_gr_arg_normal;
71982 + copy_acl_object_label = &copy_acl_object_label_normal;
71983 + copy_acl_subject_label = &copy_acl_subject_label_normal;
71984 + copy_acl_role_label = &copy_acl_role_label_normal;
71985 + copy_acl_ip_label = &copy_acl_ip_label_normal;
71986 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
71987 + copy_role_transition = &copy_role_transition_normal;
71988 + copy_sprole_pw = &copy_sprole_pw_normal;
71989 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
71990 + copy_pointer_from_array = &copy_pointer_from_array_normal;
71991 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
71992 + }
71993 + pax_close_kernel();
71994 +#endif
71995 +
71996 + req_count = get_gr_arg_wrapper_size();
71997 +
71998 + if (count != req_count) {
71999 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72000 + error = -EINVAL;
72001 + goto out;
72002 + }
72003 +
72004 +
72005 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72006 + gr_auth_expires = 0;
72007 + gr_auth_attempts = 0;
72008 + }
72009 +
72010 + error = copy_gr_arg_wrapper(buf, &uwrap);
72011 + if (error)
72012 + goto out;
72013 +
72014 + error = copy_gr_arg(uwrap.arg, &gr_usermode);
72015 + if (error)
72016 + goto out;
72017 +
72018 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72019 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72020 + time_after(gr_auth_expires, get_seconds())) {
72021 + error = -EBUSY;
72022 + goto out;
72023 + }
72024 +
72025 + /* if non-root trying to do anything other than use a special role,
72026 + do not attempt authentication, do not count towards authentication
72027 + locking
72028 + */
72029 +
72030 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72031 + gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72032 + gr_is_global_nonroot(current_uid())) {
72033 + error = -EPERM;
72034 + goto out;
72035 + }
72036 +
72037 + /* ensure pw and special role name are null terminated */
72038 +
72039 + gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72040 + gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72041 +
72042 + /* Okay.
72043 + * We have our enough of the argument structure..(we have yet
72044 + * to copy_from_user the tables themselves) . Copy the tables
72045 + * only if we need them, i.e. for loading operations. */
72046 +
72047 + switch (gr_usermode.mode) {
72048 + case GR_STATUS:
72049 + if (gr_acl_is_enabled()) {
72050 + error = 1;
72051 + if (!gr_check_secure_terminal(current))
72052 + error = 3;
72053 + } else
72054 + error = 2;
72055 + goto out;
72056 + case GR_SHUTDOWN:
72057 + if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72058 + stop_machine(gr_rbac_disable, NULL, NULL);
72059 + free_variables(false);
72060 + memset(&gr_usermode, 0, sizeof(gr_usermode));
72061 + memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72062 + memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72063 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72064 + } else if (gr_acl_is_enabled()) {
72065 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72066 + error = -EPERM;
72067 + } else {
72068 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72069 + error = -EAGAIN;
72070 + }
72071 + break;
72072 + case GR_ENABLE:
72073 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72074 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72075 + else {
72076 + if (gr_acl_is_enabled())
72077 + error = -EAGAIN;
72078 + else
72079 + error = error2;
72080 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72081 + }
72082 + break;
72083 + case GR_OLDRELOAD:
72084 + oldmode = 1;
72085 + case GR_RELOAD:
72086 + if (!gr_acl_is_enabled()) {
72087 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72088 + error = -EAGAIN;
72089 + } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72090 + error2 = gracl_reload(&gr_usermode, oldmode);
72091 + if (!error2)
72092 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72093 + else {
72094 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72095 + error = error2;
72096 + }
72097 + } else {
72098 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72099 + error = -EPERM;
72100 + }
72101 + break;
72102 + case GR_SEGVMOD:
72103 + if (unlikely(!gr_acl_is_enabled())) {
72104 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72105 + error = -EAGAIN;
72106 + break;
72107 + }
72108 +
72109 + if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72110 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72111 + if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72112 + struct acl_subject_label *segvacl;
72113 + segvacl =
72114 + lookup_acl_subj_label(gr_usermode.segv_inode,
72115 + gr_usermode.segv_device,
72116 + current->role);
72117 + if (segvacl) {
72118 + segvacl->crashes = 0;
72119 + segvacl->expires = 0;
72120 + }
72121 + } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72122 + gr_remove_uid(gr_usermode.segv_uid);
72123 + }
72124 + } else {
72125 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72126 + error = -EPERM;
72127 + }
72128 + break;
72129 + case GR_SPROLE:
72130 + case GR_SPROLEPAM:
72131 + if (unlikely(!gr_acl_is_enabled())) {
72132 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72133 + error = -EAGAIN;
72134 + break;
72135 + }
72136 +
72137 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72138 + current->role->expires = 0;
72139 + current->role->auth_attempts = 0;
72140 + }
72141 +
72142 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72143 + time_after(current->role->expires, get_seconds())) {
72144 + error = -EBUSY;
72145 + goto out;
72146 + }
72147 +
72148 + if (lookup_special_role_auth
72149 + (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72150 + && ((!sprole_salt && !sprole_sum)
72151 + || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72152 + char *p = "";
72153 + assign_special_role(gr_usermode.sp_role);
72154 + read_lock(&tasklist_lock);
72155 + if (current->real_parent)
72156 + p = current->real_parent->role->rolename;
72157 + read_unlock(&tasklist_lock);
72158 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72159 + p, acl_sp_role_value);
72160 + } else {
72161 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72162 + error = -EPERM;
72163 + if(!(current->role->auth_attempts++))
72164 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72165 +
72166 + goto out;
72167 + }
72168 + break;
72169 + case GR_UNSPROLE:
72170 + if (unlikely(!gr_acl_is_enabled())) {
72171 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72172 + error = -EAGAIN;
72173 + break;
72174 + }
72175 +
72176 + if (current->role->roletype & GR_ROLE_SPECIAL) {
72177 + char *p = "";
72178 + int i = 0;
72179 +
72180 + read_lock(&tasklist_lock);
72181 + if (current->real_parent) {
72182 + p = current->real_parent->role->rolename;
72183 + i = current->real_parent->acl_role_id;
72184 + }
72185 + read_unlock(&tasklist_lock);
72186 +
72187 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72188 + gr_set_acls(1);
72189 + } else {
72190 + error = -EPERM;
72191 + goto out;
72192 + }
72193 + break;
72194 + default:
72195 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72196 + error = -EINVAL;
72197 + break;
72198 + }
72199 +
72200 + if (error != -EPERM)
72201 + goto out;
72202 +
72203 + if(!(gr_auth_attempts++))
72204 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72205 +
72206 + out:
72207 + mutex_unlock(&gr_dev_mutex);
72208 +
72209 + if (!error)
72210 + error = req_count;
72211 +
72212 + return error;
72213 +}
72214 +
72215 +int
72216 +gr_set_acls(const int type)
72217 +{
72218 + struct task_struct *task, *task2;
72219 + struct acl_role_label *role = current->role;
72220 + struct acl_subject_label *subj;
72221 + __u16 acl_role_id = current->acl_role_id;
72222 + const struct cred *cred;
72223 + int ret;
72224 +
72225 + rcu_read_lock();
72226 + read_lock(&tasklist_lock);
72227 + read_lock(&grsec_exec_file_lock);
72228 + do_each_thread(task2, task) {
72229 + /* check to see if we're called from the exit handler,
72230 + if so, only replace ACLs that have inherited the admin
72231 + ACL */
72232 +
72233 + if (type && (task->role != role ||
72234 + task->acl_role_id != acl_role_id))
72235 + continue;
72236 +
72237 + task->acl_role_id = 0;
72238 + task->acl_sp_role = 0;
72239 + task->inherited = 0;
72240 +
72241 + if (task->exec_file) {
72242 + cred = __task_cred(task);
72243 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72244 + subj = __gr_get_subject_for_task(polstate, task, NULL);
72245 + if (subj == NULL) {
72246 + ret = -EINVAL;
72247 + read_unlock(&grsec_exec_file_lock);
72248 + read_unlock(&tasklist_lock);
72249 + rcu_read_unlock();
72250 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72251 + return ret;
72252 + }
72253 + __gr_apply_subject_to_task(polstate, task, subj);
72254 + } else {
72255 + // it's a kernel process
72256 + task->role = polstate->kernel_role;
72257 + task->acl = polstate->kernel_role->root_label;
72258 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72259 + task->acl->mode &= ~GR_PROCFIND;
72260 +#endif
72261 + }
72262 + } while_each_thread(task2, task);
72263 + read_unlock(&grsec_exec_file_lock);
72264 + read_unlock(&tasklist_lock);
72265 + rcu_read_unlock();
72266 +
72267 + return 0;
72268 +}
72269 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
72270 new file mode 100644
72271 index 0000000..39645c9
72272 --- /dev/null
72273 +++ b/grsecurity/gracl_res.c
72274 @@ -0,0 +1,68 @@
72275 +#include <linux/kernel.h>
72276 +#include <linux/sched.h>
72277 +#include <linux/gracl.h>
72278 +#include <linux/grinternal.h>
72279 +
72280 +static const char *restab_log[] = {
72281 + [RLIMIT_CPU] = "RLIMIT_CPU",
72282 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
72283 + [RLIMIT_DATA] = "RLIMIT_DATA",
72284 + [RLIMIT_STACK] = "RLIMIT_STACK",
72285 + [RLIMIT_CORE] = "RLIMIT_CORE",
72286 + [RLIMIT_RSS] = "RLIMIT_RSS",
72287 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
72288 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
72289 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
72290 + [RLIMIT_AS] = "RLIMIT_AS",
72291 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
72292 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
72293 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
72294 + [RLIMIT_NICE] = "RLIMIT_NICE",
72295 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
72296 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
72297 + [GR_CRASH_RES] = "RLIMIT_CRASH"
72298 +};
72299 +
72300 +void
72301 +gr_log_resource(const struct task_struct *task,
72302 + const int res, const unsigned long wanted, const int gt)
72303 +{
72304 + const struct cred *cred;
72305 + unsigned long rlim;
72306 +
72307 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
72308 + return;
72309 +
72310 + // not yet supported resource
72311 + if (unlikely(!restab_log[res]))
72312 + return;
72313 +
72314 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
72315 + rlim = task_rlimit_max(task, res);
72316 + else
72317 + rlim = task_rlimit(task, res);
72318 +
72319 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
72320 + return;
72321 +
72322 + rcu_read_lock();
72323 + cred = __task_cred(task);
72324 +
72325 + if (res == RLIMIT_NPROC &&
72326 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
72327 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
72328 + goto out_rcu_unlock;
72329 + else if (res == RLIMIT_MEMLOCK &&
72330 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
72331 + goto out_rcu_unlock;
72332 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
72333 + goto out_rcu_unlock;
72334 + rcu_read_unlock();
72335 +
72336 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
72337 +
72338 + return;
72339 +out_rcu_unlock:
72340 + rcu_read_unlock();
72341 + return;
72342 +}
72343 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
72344 new file mode 100644
72345 index 0000000..2040e61
72346 --- /dev/null
72347 +++ b/grsecurity/gracl_segv.c
72348 @@ -0,0 +1,313 @@
72349 +#include <linux/kernel.h>
72350 +#include <linux/mm.h>
72351 +#include <asm/uaccess.h>
72352 +#include <asm/errno.h>
72353 +#include <asm/mman.h>
72354 +#include <net/sock.h>
72355 +#include <linux/file.h>
72356 +#include <linux/fs.h>
72357 +#include <linux/net.h>
72358 +#include <linux/in.h>
72359 +#include <linux/slab.h>
72360 +#include <linux/types.h>
72361 +#include <linux/sched.h>
72362 +#include <linux/timer.h>
72363 +#include <linux/gracl.h>
72364 +#include <linux/grsecurity.h>
72365 +#include <linux/grinternal.h>
72366 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72367 +#include <linux/magic.h>
72368 +#include <linux/pagemap.h>
72369 +#include "../fs/btrfs/async-thread.h"
72370 +#include "../fs/btrfs/ctree.h"
72371 +#include "../fs/btrfs/btrfs_inode.h"
72372 +#endif
72373 +
72374 +static struct crash_uid *uid_set;
72375 +static unsigned short uid_used;
72376 +static DEFINE_SPINLOCK(gr_uid_lock);
72377 +extern rwlock_t gr_inode_lock;
72378 +extern struct acl_subject_label *
72379 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
72380 + struct acl_role_label *role);
72381 +
72382 +static inline dev_t __get_dev(const struct dentry *dentry)
72383 +{
72384 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72385 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
72386 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
72387 + else
72388 +#endif
72389 + return dentry->d_sb->s_dev;
72390 +}
72391 +
72392 +int
72393 +gr_init_uidset(void)
72394 +{
72395 + uid_set =
72396 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
72397 + uid_used = 0;
72398 +
72399 + return uid_set ? 1 : 0;
72400 +}
72401 +
72402 +void
72403 +gr_free_uidset(void)
72404 +{
72405 + if (uid_set) {
72406 + struct crash_uid *tmpset;
72407 + spin_lock(&gr_uid_lock);
72408 + tmpset = uid_set;
72409 + uid_set = NULL;
72410 + uid_used = 0;
72411 + spin_unlock(&gr_uid_lock);
72412 + if (tmpset)
72413 + kfree(tmpset);
72414 + }
72415 +
72416 + return;
72417 +}
72418 +
72419 +int
72420 +gr_find_uid(const uid_t uid)
72421 +{
72422 + struct crash_uid *tmp = uid_set;
72423 + uid_t buid;
72424 + int low = 0, high = uid_used - 1, mid;
72425 +
72426 + while (high >= low) {
72427 + mid = (low + high) >> 1;
72428 + buid = tmp[mid].uid;
72429 + if (buid == uid)
72430 + return mid;
72431 + if (buid > uid)
72432 + high = mid - 1;
72433 + if (buid < uid)
72434 + low = mid + 1;
72435 + }
72436 +
72437 + return -1;
72438 +}
72439 +
72440 +static __inline__ void
72441 +gr_insertsort(void)
72442 +{
72443 + unsigned short i, j;
72444 + struct crash_uid index;
72445 +
72446 + for (i = 1; i < uid_used; i++) {
72447 + index = uid_set[i];
72448 + j = i;
72449 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
72450 + uid_set[j] = uid_set[j - 1];
72451 + j--;
72452 + }
72453 + uid_set[j] = index;
72454 + }
72455 +
72456 + return;
72457 +}
72458 +
72459 +static __inline__ void
72460 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
72461 +{
72462 + int loc;
72463 + uid_t uid = GR_GLOBAL_UID(kuid);
72464 +
72465 + if (uid_used == GR_UIDTABLE_MAX)
72466 + return;
72467 +
72468 + loc = gr_find_uid(uid);
72469 +
72470 + if (loc >= 0) {
72471 + uid_set[loc].expires = expires;
72472 + return;
72473 + }
72474 +
72475 + uid_set[uid_used].uid = uid;
72476 + uid_set[uid_used].expires = expires;
72477 + uid_used++;
72478 +
72479 + gr_insertsort();
72480 +
72481 + return;
72482 +}
72483 +
72484 +void
72485 +gr_remove_uid(const unsigned short loc)
72486 +{
72487 + unsigned short i;
72488 +
72489 + for (i = loc + 1; i < uid_used; i++)
72490 + uid_set[i - 1] = uid_set[i];
72491 +
72492 + uid_used--;
72493 +
72494 + return;
72495 +}
72496 +
72497 +int
72498 +gr_check_crash_uid(const kuid_t kuid)
72499 +{
72500 + int loc;
72501 + int ret = 0;
72502 + uid_t uid;
72503 +
72504 + if (unlikely(!gr_acl_is_enabled()))
72505 + return 0;
72506 +
72507 + uid = GR_GLOBAL_UID(kuid);
72508 +
72509 + spin_lock(&gr_uid_lock);
72510 + loc = gr_find_uid(uid);
72511 +
72512 + if (loc < 0)
72513 + goto out_unlock;
72514 +
72515 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
72516 + gr_remove_uid(loc);
72517 + else
72518 + ret = 1;
72519 +
72520 +out_unlock:
72521 + spin_unlock(&gr_uid_lock);
72522 + return ret;
72523 +}
72524 +
72525 +static __inline__ int
72526 +proc_is_setxid(const struct cred *cred)
72527 +{
72528 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
72529 + !uid_eq(cred->uid, cred->fsuid))
72530 + return 1;
72531 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
72532 + !gid_eq(cred->gid, cred->fsgid))
72533 + return 1;
72534 +
72535 + return 0;
72536 +}
72537 +
72538 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
72539 +
72540 +void
72541 +gr_handle_crash(struct task_struct *task, const int sig)
72542 +{
72543 + struct acl_subject_label *curr;
72544 + struct task_struct *tsk, *tsk2;
72545 + const struct cred *cred;
72546 + const struct cred *cred2;
72547 +
72548 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
72549 + return;
72550 +
72551 + if (unlikely(!gr_acl_is_enabled()))
72552 + return;
72553 +
72554 + curr = task->acl;
72555 +
72556 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
72557 + return;
72558 +
72559 + if (time_before_eq(curr->expires, get_seconds())) {
72560 + curr->expires = 0;
72561 + curr->crashes = 0;
72562 + }
72563 +
72564 + curr->crashes++;
72565 +
72566 + if (!curr->expires)
72567 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
72568 +
72569 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72570 + time_after(curr->expires, get_seconds())) {
72571 + rcu_read_lock();
72572 + cred = __task_cred(task);
72573 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
72574 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72575 + spin_lock(&gr_uid_lock);
72576 + gr_insert_uid(cred->uid, curr->expires);
72577 + spin_unlock(&gr_uid_lock);
72578 + curr->expires = 0;
72579 + curr->crashes = 0;
72580 + read_lock(&tasklist_lock);
72581 + do_each_thread(tsk2, tsk) {
72582 + cred2 = __task_cred(tsk);
72583 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
72584 + gr_fake_force_sig(SIGKILL, tsk);
72585 + } while_each_thread(tsk2, tsk);
72586 + read_unlock(&tasklist_lock);
72587 + } else {
72588 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72589 + read_lock(&tasklist_lock);
72590 + read_lock(&grsec_exec_file_lock);
72591 + do_each_thread(tsk2, tsk) {
72592 + if (likely(tsk != task)) {
72593 + // if this thread has the same subject as the one that triggered
72594 + // RES_CRASH and it's the same binary, kill it
72595 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
72596 + gr_fake_force_sig(SIGKILL, tsk);
72597 + }
72598 + } while_each_thread(tsk2, tsk);
72599 + read_unlock(&grsec_exec_file_lock);
72600 + read_unlock(&tasklist_lock);
72601 + }
72602 + rcu_read_unlock();
72603 + }
72604 +
72605 + return;
72606 +}
72607 +
72608 +int
72609 +gr_check_crash_exec(const struct file *filp)
72610 +{
72611 + struct acl_subject_label *curr;
72612 +
72613 + if (unlikely(!gr_acl_is_enabled()))
72614 + return 0;
72615 +
72616 + read_lock(&gr_inode_lock);
72617 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
72618 + __get_dev(filp->f_path.dentry),
72619 + current->role);
72620 + read_unlock(&gr_inode_lock);
72621 +
72622 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
72623 + (!curr->crashes && !curr->expires))
72624 + return 0;
72625 +
72626 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72627 + time_after(curr->expires, get_seconds()))
72628 + return 1;
72629 + else if (time_before_eq(curr->expires, get_seconds())) {
72630 + curr->crashes = 0;
72631 + curr->expires = 0;
72632 + }
72633 +
72634 + return 0;
72635 +}
72636 +
72637 +void
72638 +gr_handle_alertkill(struct task_struct *task)
72639 +{
72640 + struct acl_subject_label *curracl;
72641 + __u32 curr_ip;
72642 + struct task_struct *p, *p2;
72643 +
72644 + if (unlikely(!gr_acl_is_enabled()))
72645 + return;
72646 +
72647 + curracl = task->acl;
72648 + curr_ip = task->signal->curr_ip;
72649 +
72650 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
72651 + read_lock(&tasklist_lock);
72652 + do_each_thread(p2, p) {
72653 + if (p->signal->curr_ip == curr_ip)
72654 + gr_fake_force_sig(SIGKILL, p);
72655 + } while_each_thread(p2, p);
72656 + read_unlock(&tasklist_lock);
72657 + } else if (curracl->mode & GR_KILLPROC)
72658 + gr_fake_force_sig(SIGKILL, task);
72659 +
72660 + return;
72661 +}
72662 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
72663 new file mode 100644
72664 index 0000000..98011b0
72665 --- /dev/null
72666 +++ b/grsecurity/gracl_shm.c
72667 @@ -0,0 +1,40 @@
72668 +#include <linux/kernel.h>
72669 +#include <linux/mm.h>
72670 +#include <linux/sched.h>
72671 +#include <linux/file.h>
72672 +#include <linux/ipc.h>
72673 +#include <linux/gracl.h>
72674 +#include <linux/grsecurity.h>
72675 +#include <linux/grinternal.h>
72676 +
72677 +int
72678 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72679 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
72680 +{
72681 + struct task_struct *task;
72682 +
72683 + if (!gr_acl_is_enabled())
72684 + return 1;
72685 +
72686 + rcu_read_lock();
72687 + read_lock(&tasklist_lock);
72688 +
72689 + task = find_task_by_vpid(shm_cprid);
72690 +
72691 + if (unlikely(!task))
72692 + task = find_task_by_vpid(shm_lapid);
72693 +
72694 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
72695 + (task_pid_nr(task) == shm_lapid)) &&
72696 + (task->acl->mode & GR_PROTSHM) &&
72697 + (task->acl != current->acl))) {
72698 + read_unlock(&tasklist_lock);
72699 + rcu_read_unlock();
72700 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
72701 + return 0;
72702 + }
72703 + read_unlock(&tasklist_lock);
72704 + rcu_read_unlock();
72705 +
72706 + return 1;
72707 +}
72708 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
72709 new file mode 100644
72710 index 0000000..bc0be01
72711 --- /dev/null
72712 +++ b/grsecurity/grsec_chdir.c
72713 @@ -0,0 +1,19 @@
72714 +#include <linux/kernel.h>
72715 +#include <linux/sched.h>
72716 +#include <linux/fs.h>
72717 +#include <linux/file.h>
72718 +#include <linux/grsecurity.h>
72719 +#include <linux/grinternal.h>
72720 +
72721 +void
72722 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
72723 +{
72724 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
72725 + if ((grsec_enable_chdir && grsec_enable_group &&
72726 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
72727 + !grsec_enable_group)) {
72728 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
72729 + }
72730 +#endif
72731 + return;
72732 +}
72733 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
72734 new file mode 100644
72735 index 0000000..651d6c2
72736 --- /dev/null
72737 +++ b/grsecurity/grsec_chroot.c
72738 @@ -0,0 +1,370 @@
72739 +#include <linux/kernel.h>
72740 +#include <linux/module.h>
72741 +#include <linux/sched.h>
72742 +#include <linux/file.h>
72743 +#include <linux/fs.h>
72744 +#include <linux/mount.h>
72745 +#include <linux/types.h>
72746 +#include "../fs/mount.h"
72747 +#include <linux/grsecurity.h>
72748 +#include <linux/grinternal.h>
72749 +
72750 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72751 +int gr_init_ran;
72752 +#endif
72753 +
72754 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
72755 +{
72756 +#ifdef CONFIG_GRKERNSEC
72757 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
72758 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
72759 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72760 + && gr_init_ran
72761 +#endif
72762 + )
72763 + task->gr_is_chrooted = 1;
72764 + else {
72765 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72766 + if (task_pid_nr(task) == 1 && !gr_init_ran)
72767 + gr_init_ran = 1;
72768 +#endif
72769 + task->gr_is_chrooted = 0;
72770 + }
72771 +
72772 + task->gr_chroot_dentry = path->dentry;
72773 +#endif
72774 + return;
72775 +}
72776 +
72777 +void gr_clear_chroot_entries(struct task_struct *task)
72778 +{
72779 +#ifdef CONFIG_GRKERNSEC
72780 + task->gr_is_chrooted = 0;
72781 + task->gr_chroot_dentry = NULL;
72782 +#endif
72783 + return;
72784 +}
72785 +
72786 +int
72787 +gr_handle_chroot_unix(const pid_t pid)
72788 +{
72789 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
72790 + struct task_struct *p;
72791 +
72792 + if (unlikely(!grsec_enable_chroot_unix))
72793 + return 1;
72794 +
72795 + if (likely(!proc_is_chrooted(current)))
72796 + return 1;
72797 +
72798 + rcu_read_lock();
72799 + read_lock(&tasklist_lock);
72800 + p = find_task_by_vpid_unrestricted(pid);
72801 + if (unlikely(p && !have_same_root(current, p))) {
72802 + read_unlock(&tasklist_lock);
72803 + rcu_read_unlock();
72804 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
72805 + return 0;
72806 + }
72807 + read_unlock(&tasklist_lock);
72808 + rcu_read_unlock();
72809 +#endif
72810 + return 1;
72811 +}
72812 +
72813 +int
72814 +gr_handle_chroot_nice(void)
72815 +{
72816 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72817 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
72818 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
72819 + return -EPERM;
72820 + }
72821 +#endif
72822 + return 0;
72823 +}
72824 +
72825 +int
72826 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
72827 +{
72828 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72829 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
72830 + && proc_is_chrooted(current)) {
72831 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
72832 + return -EACCES;
72833 + }
72834 +#endif
72835 + return 0;
72836 +}
72837 +
72838 +int
72839 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
72840 +{
72841 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72842 + struct task_struct *p;
72843 + int ret = 0;
72844 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
72845 + return ret;
72846 +
72847 + read_lock(&tasklist_lock);
72848 + do_each_pid_task(pid, type, p) {
72849 + if (!have_same_root(current, p)) {
72850 + ret = 1;
72851 + goto out;
72852 + }
72853 + } while_each_pid_task(pid, type, p);
72854 +out:
72855 + read_unlock(&tasklist_lock);
72856 + return ret;
72857 +#endif
72858 + return 0;
72859 +}
72860 +
72861 +int
72862 +gr_pid_is_chrooted(struct task_struct *p)
72863 +{
72864 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72865 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
72866 + return 0;
72867 +
72868 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
72869 + !have_same_root(current, p)) {
72870 + return 1;
72871 + }
72872 +#endif
72873 + return 0;
72874 +}
72875 +
72876 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
72877 +
72878 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
72879 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
72880 +{
72881 + struct path path, currentroot;
72882 + int ret = 0;
72883 +
72884 + path.dentry = (struct dentry *)u_dentry;
72885 + path.mnt = (struct vfsmount *)u_mnt;
72886 + get_fs_root(current->fs, &currentroot);
72887 + if (path_is_under(&path, &currentroot))
72888 + ret = 1;
72889 + path_put(&currentroot);
72890 +
72891 + return ret;
72892 +}
72893 +#endif
72894 +
72895 +int
72896 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
72897 +{
72898 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
72899 + if (!grsec_enable_chroot_fchdir)
72900 + return 1;
72901 +
72902 + if (!proc_is_chrooted(current))
72903 + return 1;
72904 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
72905 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
72906 + return 0;
72907 + }
72908 +#endif
72909 + return 1;
72910 +}
72911 +
72912 +int
72913 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72914 + const time_t shm_createtime)
72915 +{
72916 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
72917 + struct task_struct *p;
72918 + time_t starttime;
72919 +
72920 + if (unlikely(!grsec_enable_chroot_shmat))
72921 + return 1;
72922 +
72923 + if (likely(!proc_is_chrooted(current)))
72924 + return 1;
72925 +
72926 + rcu_read_lock();
72927 + read_lock(&tasklist_lock);
72928 +
72929 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
72930 + starttime = p->start_time.tv_sec;
72931 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
72932 + if (have_same_root(current, p)) {
72933 + goto allow;
72934 + } else {
72935 + read_unlock(&tasklist_lock);
72936 + rcu_read_unlock();
72937 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72938 + return 0;
72939 + }
72940 + }
72941 + /* creator exited, pid reuse, fall through to next check */
72942 + }
72943 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
72944 + if (unlikely(!have_same_root(current, p))) {
72945 + read_unlock(&tasklist_lock);
72946 + rcu_read_unlock();
72947 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72948 + return 0;
72949 + }
72950 + }
72951 +
72952 +allow:
72953 + read_unlock(&tasklist_lock);
72954 + rcu_read_unlock();
72955 +#endif
72956 + return 1;
72957 +}
72958 +
72959 +void
72960 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
72961 +{
72962 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
72963 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
72964 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
72965 +#endif
72966 + return;
72967 +}
72968 +
72969 +int
72970 +gr_handle_chroot_mknod(const struct dentry *dentry,
72971 + const struct vfsmount *mnt, const int mode)
72972 +{
72973 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
72974 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
72975 + proc_is_chrooted(current)) {
72976 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
72977 + return -EPERM;
72978 + }
72979 +#endif
72980 + return 0;
72981 +}
72982 +
72983 +int
72984 +gr_handle_chroot_mount(const struct dentry *dentry,
72985 + const struct vfsmount *mnt, const char *dev_name)
72986 +{
72987 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
72988 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
72989 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
72990 + return -EPERM;
72991 + }
72992 +#endif
72993 + return 0;
72994 +}
72995 +
72996 +int
72997 +gr_handle_chroot_pivot(void)
72998 +{
72999 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73000 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73001 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73002 + return -EPERM;
73003 + }
73004 +#endif
73005 + return 0;
73006 +}
73007 +
73008 +int
73009 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73010 +{
73011 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73012 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73013 + !gr_is_outside_chroot(dentry, mnt)) {
73014 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73015 + return -EPERM;
73016 + }
73017 +#endif
73018 + return 0;
73019 +}
73020 +
73021 +extern const char *captab_log[];
73022 +extern int captab_log_entries;
73023 +
73024 +int
73025 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73026 +{
73027 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73028 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73029 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73030 + if (cap_raised(chroot_caps, cap)) {
73031 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73032 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73033 + }
73034 + return 0;
73035 + }
73036 + }
73037 +#endif
73038 + return 1;
73039 +}
73040 +
73041 +int
73042 +gr_chroot_is_capable(const int cap)
73043 +{
73044 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73045 + return gr_task_chroot_is_capable(current, current_cred(), cap);
73046 +#endif
73047 + return 1;
73048 +}
73049 +
73050 +int
73051 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73052 +{
73053 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73054 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73055 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73056 + if (cap_raised(chroot_caps, cap)) {
73057 + return 0;
73058 + }
73059 + }
73060 +#endif
73061 + return 1;
73062 +}
73063 +
73064 +int
73065 +gr_chroot_is_capable_nolog(const int cap)
73066 +{
73067 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73068 + return gr_task_chroot_is_capable_nolog(current, cap);
73069 +#endif
73070 + return 1;
73071 +}
73072 +
73073 +int
73074 +gr_handle_chroot_sysctl(const int op)
73075 +{
73076 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73077 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73078 + proc_is_chrooted(current))
73079 + return -EACCES;
73080 +#endif
73081 + return 0;
73082 +}
73083 +
73084 +void
73085 +gr_handle_chroot_chdir(const struct path *path)
73086 +{
73087 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73088 + if (grsec_enable_chroot_chdir)
73089 + set_fs_pwd(current->fs, path);
73090 +#endif
73091 + return;
73092 +}
73093 +
73094 +int
73095 +gr_handle_chroot_chmod(const struct dentry *dentry,
73096 + const struct vfsmount *mnt, const int mode)
73097 +{
73098 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73099 + /* allow chmod +s on directories, but not files */
73100 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73101 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73102 + proc_is_chrooted(current)) {
73103 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73104 + return -EPERM;
73105 + }
73106 +#endif
73107 + return 0;
73108 +}
73109 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73110 new file mode 100644
73111 index 0000000..4d6fce8
73112 --- /dev/null
73113 +++ b/grsecurity/grsec_disabled.c
73114 @@ -0,0 +1,433 @@
73115 +#include <linux/kernel.h>
73116 +#include <linux/module.h>
73117 +#include <linux/sched.h>
73118 +#include <linux/file.h>
73119 +#include <linux/fs.h>
73120 +#include <linux/kdev_t.h>
73121 +#include <linux/net.h>
73122 +#include <linux/in.h>
73123 +#include <linux/ip.h>
73124 +#include <linux/skbuff.h>
73125 +#include <linux/sysctl.h>
73126 +
73127 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73128 +void
73129 +pax_set_initial_flags(struct linux_binprm *bprm)
73130 +{
73131 + return;
73132 +}
73133 +#endif
73134 +
73135 +#ifdef CONFIG_SYSCTL
73136 +__u32
73137 +gr_handle_sysctl(const struct ctl_table * table, const int op)
73138 +{
73139 + return 0;
73140 +}
73141 +#endif
73142 +
73143 +#ifdef CONFIG_TASKSTATS
73144 +int gr_is_taskstats_denied(int pid)
73145 +{
73146 + return 0;
73147 +}
73148 +#endif
73149 +
73150 +int
73151 +gr_acl_is_enabled(void)
73152 +{
73153 + return 0;
73154 +}
73155 +
73156 +void
73157 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73158 +{
73159 + return;
73160 +}
73161 +
73162 +int
73163 +gr_handle_rawio(const struct inode *inode)
73164 +{
73165 + return 0;
73166 +}
73167 +
73168 +void
73169 +gr_acl_handle_psacct(struct task_struct *task, const long code)
73170 +{
73171 + return;
73172 +}
73173 +
73174 +int
73175 +gr_handle_ptrace(struct task_struct *task, const long request)
73176 +{
73177 + return 0;
73178 +}
73179 +
73180 +int
73181 +gr_handle_proc_ptrace(struct task_struct *task)
73182 +{
73183 + return 0;
73184 +}
73185 +
73186 +int
73187 +gr_set_acls(const int type)
73188 +{
73189 + return 0;
73190 +}
73191 +
73192 +int
73193 +gr_check_hidden_task(const struct task_struct *tsk)
73194 +{
73195 + return 0;
73196 +}
73197 +
73198 +int
73199 +gr_check_protected_task(const struct task_struct *task)
73200 +{
73201 + return 0;
73202 +}
73203 +
73204 +int
73205 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73206 +{
73207 + return 0;
73208 +}
73209 +
73210 +void
73211 +gr_copy_label(struct task_struct *tsk)
73212 +{
73213 + return;
73214 +}
73215 +
73216 +void
73217 +gr_set_pax_flags(struct task_struct *task)
73218 +{
73219 + return;
73220 +}
73221 +
73222 +int
73223 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73224 + const int unsafe_share)
73225 +{
73226 + return 0;
73227 +}
73228 +
73229 +void
73230 +gr_handle_delete(const ino_t ino, const dev_t dev)
73231 +{
73232 + return;
73233 +}
73234 +
73235 +void
73236 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73237 +{
73238 + return;
73239 +}
73240 +
73241 +void
73242 +gr_handle_crash(struct task_struct *task, const int sig)
73243 +{
73244 + return;
73245 +}
73246 +
73247 +int
73248 +gr_check_crash_exec(const struct file *filp)
73249 +{
73250 + return 0;
73251 +}
73252 +
73253 +int
73254 +gr_check_crash_uid(const kuid_t uid)
73255 +{
73256 + return 0;
73257 +}
73258 +
73259 +void
73260 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73261 + struct dentry *old_dentry,
73262 + struct dentry *new_dentry,
73263 + struct vfsmount *mnt, const __u8 replace)
73264 +{
73265 + return;
73266 +}
73267 +
73268 +int
73269 +gr_search_socket(const int family, const int type, const int protocol)
73270 +{
73271 + return 1;
73272 +}
73273 +
73274 +int
73275 +gr_search_connectbind(const int mode, const struct socket *sock,
73276 + const struct sockaddr_in *addr)
73277 +{
73278 + return 0;
73279 +}
73280 +
73281 +void
73282 +gr_handle_alertkill(struct task_struct *task)
73283 +{
73284 + return;
73285 +}
73286 +
73287 +__u32
73288 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
73289 +{
73290 + return 1;
73291 +}
73292 +
73293 +__u32
73294 +gr_acl_handle_hidden_file(const struct dentry * dentry,
73295 + const struct vfsmount * mnt)
73296 +{
73297 + return 1;
73298 +}
73299 +
73300 +__u32
73301 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73302 + int acc_mode)
73303 +{
73304 + return 1;
73305 +}
73306 +
73307 +__u32
73308 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73309 +{
73310 + return 1;
73311 +}
73312 +
73313 +__u32
73314 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
73315 +{
73316 + return 1;
73317 +}
73318 +
73319 +int
73320 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
73321 + unsigned int *vm_flags)
73322 +{
73323 + return 1;
73324 +}
73325 +
73326 +__u32
73327 +gr_acl_handle_truncate(const struct dentry * dentry,
73328 + const struct vfsmount * mnt)
73329 +{
73330 + return 1;
73331 +}
73332 +
73333 +__u32
73334 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
73335 +{
73336 + return 1;
73337 +}
73338 +
73339 +__u32
73340 +gr_acl_handle_access(const struct dentry * dentry,
73341 + const struct vfsmount * mnt, const int fmode)
73342 +{
73343 + return 1;
73344 +}
73345 +
73346 +__u32
73347 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
73348 + umode_t *mode)
73349 +{
73350 + return 1;
73351 +}
73352 +
73353 +__u32
73354 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
73355 +{
73356 + return 1;
73357 +}
73358 +
73359 +__u32
73360 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
73361 +{
73362 + return 1;
73363 +}
73364 +
73365 +__u32
73366 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
73367 +{
73368 + return 1;
73369 +}
73370 +
73371 +void
73372 +grsecurity_init(void)
73373 +{
73374 + return;
73375 +}
73376 +
73377 +umode_t gr_acl_umask(void)
73378 +{
73379 + return 0;
73380 +}
73381 +
73382 +__u32
73383 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73384 + const struct dentry * parent_dentry,
73385 + const struct vfsmount * parent_mnt,
73386 + const int mode)
73387 +{
73388 + return 1;
73389 +}
73390 +
73391 +__u32
73392 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
73393 + const struct dentry * parent_dentry,
73394 + const struct vfsmount * parent_mnt)
73395 +{
73396 + return 1;
73397 +}
73398 +
73399 +__u32
73400 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73401 + const struct dentry * parent_dentry,
73402 + const struct vfsmount * parent_mnt, const struct filename *from)
73403 +{
73404 + return 1;
73405 +}
73406 +
73407 +__u32
73408 +gr_acl_handle_link(const struct dentry * new_dentry,
73409 + const struct dentry * parent_dentry,
73410 + const struct vfsmount * parent_mnt,
73411 + const struct dentry * old_dentry,
73412 + const struct vfsmount * old_mnt, const struct filename *to)
73413 +{
73414 + return 1;
73415 +}
73416 +
73417 +int
73418 +gr_acl_handle_rename(const struct dentry *new_dentry,
73419 + const struct dentry *parent_dentry,
73420 + const struct vfsmount *parent_mnt,
73421 + const struct dentry *old_dentry,
73422 + const struct inode *old_parent_inode,
73423 + const struct vfsmount *old_mnt, const struct filename *newname)
73424 +{
73425 + return 0;
73426 +}
73427 +
73428 +int
73429 +gr_acl_handle_filldir(const struct file *file, const char *name,
73430 + const int namelen, const ino_t ino)
73431 +{
73432 + return 1;
73433 +}
73434 +
73435 +int
73436 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73437 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
73438 +{
73439 + return 1;
73440 +}
73441 +
73442 +int
73443 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
73444 +{
73445 + return 0;
73446 +}
73447 +
73448 +int
73449 +gr_search_accept(const struct socket *sock)
73450 +{
73451 + return 0;
73452 +}
73453 +
73454 +int
73455 +gr_search_listen(const struct socket *sock)
73456 +{
73457 + return 0;
73458 +}
73459 +
73460 +int
73461 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
73462 +{
73463 + return 0;
73464 +}
73465 +
73466 +__u32
73467 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
73468 +{
73469 + return 1;
73470 +}
73471 +
73472 +__u32
73473 +gr_acl_handle_creat(const struct dentry * dentry,
73474 + const struct dentry * p_dentry,
73475 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73476 + const int imode)
73477 +{
73478 + return 1;
73479 +}
73480 +
73481 +void
73482 +gr_acl_handle_exit(void)
73483 +{
73484 + return;
73485 +}
73486 +
73487 +int
73488 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
73489 +{
73490 + return 1;
73491 +}
73492 +
73493 +void
73494 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
73495 +{
73496 + return;
73497 +}
73498 +
73499 +int
73500 +gr_acl_handle_procpidmem(const struct task_struct *task)
73501 +{
73502 + return 0;
73503 +}
73504 +
73505 +int
73506 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
73507 +{
73508 + return 0;
73509 +}
73510 +
73511 +int
73512 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
73513 +{
73514 + return 0;
73515 +}
73516 +
73517 +int
73518 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
73519 +{
73520 + return 0;
73521 +}
73522 +
73523 +int
73524 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
73525 +{
73526 + return 0;
73527 +}
73528 +
73529 +int gr_acl_enable_at_secure(void)
73530 +{
73531 + return 0;
73532 +}
73533 +
73534 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
73535 +{
73536 + return dentry->d_sb->s_dev;
73537 +}
73538 +
73539 +void gr_put_exec_file(struct task_struct *task)
73540 +{
73541 + return;
73542 +}
73543 +
73544 +#ifdef CONFIG_SECURITY
73545 +EXPORT_SYMBOL_GPL(gr_check_user_change);
73546 +EXPORT_SYMBOL_GPL(gr_check_group_change);
73547 +#endif
73548 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
73549 new file mode 100644
73550 index 0000000..f35f454
73551 --- /dev/null
73552 +++ b/grsecurity/grsec_exec.c
73553 @@ -0,0 +1,187 @@
73554 +#include <linux/kernel.h>
73555 +#include <linux/sched.h>
73556 +#include <linux/file.h>
73557 +#include <linux/binfmts.h>
73558 +#include <linux/fs.h>
73559 +#include <linux/types.h>
73560 +#include <linux/grdefs.h>
73561 +#include <linux/grsecurity.h>
73562 +#include <linux/grinternal.h>
73563 +#include <linux/capability.h>
73564 +#include <linux/module.h>
73565 +#include <linux/compat.h>
73566 +
73567 +#include <asm/uaccess.h>
73568 +
73569 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73570 +static char gr_exec_arg_buf[132];
73571 +static DEFINE_MUTEX(gr_exec_arg_mutex);
73572 +#endif
73573 +
73574 +struct user_arg_ptr {
73575 +#ifdef CONFIG_COMPAT
73576 + bool is_compat;
73577 +#endif
73578 + union {
73579 + const char __user *const __user *native;
73580 +#ifdef CONFIG_COMPAT
73581 + const compat_uptr_t __user *compat;
73582 +#endif
73583 + } ptr;
73584 +};
73585 +
73586 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
73587 +
73588 +void
73589 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
73590 +{
73591 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73592 + char *grarg = gr_exec_arg_buf;
73593 + unsigned int i, x, execlen = 0;
73594 + char c;
73595 +
73596 + if (!((grsec_enable_execlog && grsec_enable_group &&
73597 + in_group_p(grsec_audit_gid))
73598 + || (grsec_enable_execlog && !grsec_enable_group)))
73599 + return;
73600 +
73601 + mutex_lock(&gr_exec_arg_mutex);
73602 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
73603 +
73604 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
73605 + const char __user *p;
73606 + unsigned int len;
73607 +
73608 + p = get_user_arg_ptr(argv, i);
73609 + if (IS_ERR(p))
73610 + goto log;
73611 +
73612 + len = strnlen_user(p, 128 - execlen);
73613 + if (len > 128 - execlen)
73614 + len = 128 - execlen;
73615 + else if (len > 0)
73616 + len--;
73617 + if (copy_from_user(grarg + execlen, p, len))
73618 + goto log;
73619 +
73620 + /* rewrite unprintable characters */
73621 + for (x = 0; x < len; x++) {
73622 + c = *(grarg + execlen + x);
73623 + if (c < 32 || c > 126)
73624 + *(grarg + execlen + x) = ' ';
73625 + }
73626 +
73627 + execlen += len;
73628 + *(grarg + execlen) = ' ';
73629 + *(grarg + execlen + 1) = '\0';
73630 + execlen++;
73631 + }
73632 +
73633 + log:
73634 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
73635 + bprm->file->f_path.mnt, grarg);
73636 + mutex_unlock(&gr_exec_arg_mutex);
73637 +#endif
73638 + return;
73639 +}
73640 +
73641 +#ifdef CONFIG_GRKERNSEC
73642 +extern int gr_acl_is_capable(const int cap);
73643 +extern int gr_acl_is_capable_nolog(const int cap);
73644 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73645 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
73646 +extern int gr_chroot_is_capable(const int cap);
73647 +extern int gr_chroot_is_capable_nolog(const int cap);
73648 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73649 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
73650 +#endif
73651 +
73652 +const char *captab_log[] = {
73653 + "CAP_CHOWN",
73654 + "CAP_DAC_OVERRIDE",
73655 + "CAP_DAC_READ_SEARCH",
73656 + "CAP_FOWNER",
73657 + "CAP_FSETID",
73658 + "CAP_KILL",
73659 + "CAP_SETGID",
73660 + "CAP_SETUID",
73661 + "CAP_SETPCAP",
73662 + "CAP_LINUX_IMMUTABLE",
73663 + "CAP_NET_BIND_SERVICE",
73664 + "CAP_NET_BROADCAST",
73665 + "CAP_NET_ADMIN",
73666 + "CAP_NET_RAW",
73667 + "CAP_IPC_LOCK",
73668 + "CAP_IPC_OWNER",
73669 + "CAP_SYS_MODULE",
73670 + "CAP_SYS_RAWIO",
73671 + "CAP_SYS_CHROOT",
73672 + "CAP_SYS_PTRACE",
73673 + "CAP_SYS_PACCT",
73674 + "CAP_SYS_ADMIN",
73675 + "CAP_SYS_BOOT",
73676 + "CAP_SYS_NICE",
73677 + "CAP_SYS_RESOURCE",
73678 + "CAP_SYS_TIME",
73679 + "CAP_SYS_TTY_CONFIG",
73680 + "CAP_MKNOD",
73681 + "CAP_LEASE",
73682 + "CAP_AUDIT_WRITE",
73683 + "CAP_AUDIT_CONTROL",
73684 + "CAP_SETFCAP",
73685 + "CAP_MAC_OVERRIDE",
73686 + "CAP_MAC_ADMIN",
73687 + "CAP_SYSLOG",
73688 + "CAP_WAKE_ALARM"
73689 +};
73690 +
73691 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
73692 +
73693 +int gr_is_capable(const int cap)
73694 +{
73695 +#ifdef CONFIG_GRKERNSEC
73696 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
73697 + return 1;
73698 + return 0;
73699 +#else
73700 + return 1;
73701 +#endif
73702 +}
73703 +
73704 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73705 +{
73706 +#ifdef CONFIG_GRKERNSEC
73707 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
73708 + return 1;
73709 + return 0;
73710 +#else
73711 + return 1;
73712 +#endif
73713 +}
73714 +
73715 +int gr_is_capable_nolog(const int cap)
73716 +{
73717 +#ifdef CONFIG_GRKERNSEC
73718 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
73719 + return 1;
73720 + return 0;
73721 +#else
73722 + return 1;
73723 +#endif
73724 +}
73725 +
73726 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
73727 +{
73728 +#ifdef CONFIG_GRKERNSEC
73729 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
73730 + return 1;
73731 + return 0;
73732 +#else
73733 + return 1;
73734 +#endif
73735 +}
73736 +
73737 +EXPORT_SYMBOL_GPL(gr_is_capable);
73738 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
73739 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
73740 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
73741 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
73742 new file mode 100644
73743 index 0000000..06cc6ea
73744 --- /dev/null
73745 +++ b/grsecurity/grsec_fifo.c
73746 @@ -0,0 +1,24 @@
73747 +#include <linux/kernel.h>
73748 +#include <linux/sched.h>
73749 +#include <linux/fs.h>
73750 +#include <linux/file.h>
73751 +#include <linux/grinternal.h>
73752 +
73753 +int
73754 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
73755 + const struct dentry *dir, const int flag, const int acc_mode)
73756 +{
73757 +#ifdef CONFIG_GRKERNSEC_FIFO
73758 + const struct cred *cred = current_cred();
73759 +
73760 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
73761 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
73762 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
73763 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
73764 + if (!inode_permission(dentry->d_inode, acc_mode))
73765 + 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));
73766 + return -EACCES;
73767 + }
73768 +#endif
73769 + return 0;
73770 +}
73771 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
73772 new file mode 100644
73773 index 0000000..8ca18bf
73774 --- /dev/null
73775 +++ b/grsecurity/grsec_fork.c
73776 @@ -0,0 +1,23 @@
73777 +#include <linux/kernel.h>
73778 +#include <linux/sched.h>
73779 +#include <linux/grsecurity.h>
73780 +#include <linux/grinternal.h>
73781 +#include <linux/errno.h>
73782 +
73783 +void
73784 +gr_log_forkfail(const int retval)
73785 +{
73786 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
73787 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
73788 + switch (retval) {
73789 + case -EAGAIN:
73790 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
73791 + break;
73792 + case -ENOMEM:
73793 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
73794 + break;
73795 + }
73796 + }
73797 +#endif
73798 + return;
73799 +}
73800 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
73801 new file mode 100644
73802 index 0000000..ae6c028
73803 --- /dev/null
73804 +++ b/grsecurity/grsec_init.c
73805 @@ -0,0 +1,272 @@
73806 +#include <linux/kernel.h>
73807 +#include <linux/sched.h>
73808 +#include <linux/mm.h>
73809 +#include <linux/gracl.h>
73810 +#include <linux/slab.h>
73811 +#include <linux/vmalloc.h>
73812 +#include <linux/percpu.h>
73813 +#include <linux/module.h>
73814 +
73815 +int grsec_enable_ptrace_readexec;
73816 +int grsec_enable_setxid;
73817 +int grsec_enable_symlinkown;
73818 +kgid_t grsec_symlinkown_gid;
73819 +int grsec_enable_brute;
73820 +int grsec_enable_link;
73821 +int grsec_enable_dmesg;
73822 +int grsec_enable_harden_ptrace;
73823 +int grsec_enable_harden_ipc;
73824 +int grsec_enable_fifo;
73825 +int grsec_enable_execlog;
73826 +int grsec_enable_signal;
73827 +int grsec_enable_forkfail;
73828 +int grsec_enable_audit_ptrace;
73829 +int grsec_enable_time;
73830 +int grsec_enable_group;
73831 +kgid_t grsec_audit_gid;
73832 +int grsec_enable_chdir;
73833 +int grsec_enable_mount;
73834 +int grsec_enable_rofs;
73835 +int grsec_deny_new_usb;
73836 +int grsec_enable_chroot_findtask;
73837 +int grsec_enable_chroot_mount;
73838 +int grsec_enable_chroot_shmat;
73839 +int grsec_enable_chroot_fchdir;
73840 +int grsec_enable_chroot_double;
73841 +int grsec_enable_chroot_pivot;
73842 +int grsec_enable_chroot_chdir;
73843 +int grsec_enable_chroot_chmod;
73844 +int grsec_enable_chroot_mknod;
73845 +int grsec_enable_chroot_nice;
73846 +int grsec_enable_chroot_execlog;
73847 +int grsec_enable_chroot_caps;
73848 +int grsec_enable_chroot_sysctl;
73849 +int grsec_enable_chroot_unix;
73850 +int grsec_enable_tpe;
73851 +kgid_t grsec_tpe_gid;
73852 +int grsec_enable_blackhole;
73853 +#ifdef CONFIG_IPV6_MODULE
73854 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
73855 +#endif
73856 +int grsec_lastack_retries;
73857 +int grsec_enable_tpe_all;
73858 +int grsec_enable_tpe_invert;
73859 +int grsec_enable_socket_all;
73860 +kgid_t grsec_socket_all_gid;
73861 +int grsec_enable_socket_client;
73862 +kgid_t grsec_socket_client_gid;
73863 +int grsec_enable_socket_server;
73864 +kgid_t grsec_socket_server_gid;
73865 +int grsec_resource_logging;
73866 +int grsec_disable_privio;
73867 +int grsec_enable_log_rwxmaps;
73868 +int grsec_lock;
73869 +
73870 +DEFINE_SPINLOCK(grsec_alert_lock);
73871 +unsigned long grsec_alert_wtime = 0;
73872 +unsigned long grsec_alert_fyet = 0;
73873 +
73874 +DEFINE_SPINLOCK(grsec_audit_lock);
73875 +
73876 +DEFINE_RWLOCK(grsec_exec_file_lock);
73877 +
73878 +char *gr_shared_page[4];
73879 +
73880 +char *gr_alert_log_fmt;
73881 +char *gr_audit_log_fmt;
73882 +char *gr_alert_log_buf;
73883 +char *gr_audit_log_buf;
73884 +
73885 +void __init
73886 +grsecurity_init(void)
73887 +{
73888 + int j;
73889 + /* create the per-cpu shared pages */
73890 +
73891 +#ifdef CONFIG_X86
73892 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
73893 +#endif
73894 +
73895 + for (j = 0; j < 4; j++) {
73896 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
73897 + if (gr_shared_page[j] == NULL) {
73898 + panic("Unable to allocate grsecurity shared page");
73899 + return;
73900 + }
73901 + }
73902 +
73903 + /* allocate log buffers */
73904 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
73905 + if (!gr_alert_log_fmt) {
73906 + panic("Unable to allocate grsecurity alert log format buffer");
73907 + return;
73908 + }
73909 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
73910 + if (!gr_audit_log_fmt) {
73911 + panic("Unable to allocate grsecurity audit log format buffer");
73912 + return;
73913 + }
73914 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
73915 + if (!gr_alert_log_buf) {
73916 + panic("Unable to allocate grsecurity alert log buffer");
73917 + return;
73918 + }
73919 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
73920 + if (!gr_audit_log_buf) {
73921 + panic("Unable to allocate grsecurity audit log buffer");
73922 + return;
73923 + }
73924 +
73925 +#ifdef CONFIG_GRKERNSEC_IO
73926 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
73927 + grsec_disable_privio = 1;
73928 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
73929 + grsec_disable_privio = 1;
73930 +#else
73931 + grsec_disable_privio = 0;
73932 +#endif
73933 +#endif
73934 +
73935 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
73936 + /* for backward compatibility, tpe_invert always defaults to on if
73937 + enabled in the kernel
73938 + */
73939 + grsec_enable_tpe_invert = 1;
73940 +#endif
73941 +
73942 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
73943 +#ifndef CONFIG_GRKERNSEC_SYSCTL
73944 + grsec_lock = 1;
73945 +#endif
73946 +
73947 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73948 + grsec_enable_log_rwxmaps = 1;
73949 +#endif
73950 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
73951 + grsec_enable_group = 1;
73952 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
73953 +#endif
73954 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
73955 + grsec_enable_ptrace_readexec = 1;
73956 +#endif
73957 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73958 + grsec_enable_chdir = 1;
73959 +#endif
73960 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
73961 + grsec_enable_harden_ptrace = 1;
73962 +#endif
73963 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
73964 + grsec_enable_harden_ipc = 1;
73965 +#endif
73966 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73967 + grsec_enable_mount = 1;
73968 +#endif
73969 +#ifdef CONFIG_GRKERNSEC_LINK
73970 + grsec_enable_link = 1;
73971 +#endif
73972 +#ifdef CONFIG_GRKERNSEC_BRUTE
73973 + grsec_enable_brute = 1;
73974 +#endif
73975 +#ifdef CONFIG_GRKERNSEC_DMESG
73976 + grsec_enable_dmesg = 1;
73977 +#endif
73978 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73979 + grsec_enable_blackhole = 1;
73980 + grsec_lastack_retries = 4;
73981 +#endif
73982 +#ifdef CONFIG_GRKERNSEC_FIFO
73983 + grsec_enable_fifo = 1;
73984 +#endif
73985 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73986 + grsec_enable_execlog = 1;
73987 +#endif
73988 +#ifdef CONFIG_GRKERNSEC_SETXID
73989 + grsec_enable_setxid = 1;
73990 +#endif
73991 +#ifdef CONFIG_GRKERNSEC_SIGNAL
73992 + grsec_enable_signal = 1;
73993 +#endif
73994 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
73995 + grsec_enable_forkfail = 1;
73996 +#endif
73997 +#ifdef CONFIG_GRKERNSEC_TIME
73998 + grsec_enable_time = 1;
73999 +#endif
74000 +#ifdef CONFIG_GRKERNSEC_RESLOG
74001 + grsec_resource_logging = 1;
74002 +#endif
74003 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74004 + grsec_enable_chroot_findtask = 1;
74005 +#endif
74006 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74007 + grsec_enable_chroot_unix = 1;
74008 +#endif
74009 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74010 + grsec_enable_chroot_mount = 1;
74011 +#endif
74012 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74013 + grsec_enable_chroot_fchdir = 1;
74014 +#endif
74015 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74016 + grsec_enable_chroot_shmat = 1;
74017 +#endif
74018 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74019 + grsec_enable_audit_ptrace = 1;
74020 +#endif
74021 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74022 + grsec_enable_chroot_double = 1;
74023 +#endif
74024 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74025 + grsec_enable_chroot_pivot = 1;
74026 +#endif
74027 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74028 + grsec_enable_chroot_chdir = 1;
74029 +#endif
74030 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74031 + grsec_enable_chroot_chmod = 1;
74032 +#endif
74033 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74034 + grsec_enable_chroot_mknod = 1;
74035 +#endif
74036 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74037 + grsec_enable_chroot_nice = 1;
74038 +#endif
74039 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74040 + grsec_enable_chroot_execlog = 1;
74041 +#endif
74042 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74043 + grsec_enable_chroot_caps = 1;
74044 +#endif
74045 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74046 + grsec_enable_chroot_sysctl = 1;
74047 +#endif
74048 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74049 + grsec_enable_symlinkown = 1;
74050 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74051 +#endif
74052 +#ifdef CONFIG_GRKERNSEC_TPE
74053 + grsec_enable_tpe = 1;
74054 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74055 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
74056 + grsec_enable_tpe_all = 1;
74057 +#endif
74058 +#endif
74059 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74060 + grsec_enable_socket_all = 1;
74061 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74062 +#endif
74063 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74064 + grsec_enable_socket_client = 1;
74065 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74066 +#endif
74067 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74068 + grsec_enable_socket_server = 1;
74069 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74070 +#endif
74071 +#endif
74072 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74073 + grsec_deny_new_usb = 1;
74074 +#endif
74075 +
74076 + return;
74077 +}
74078 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74079 new file mode 100644
74080 index 0000000..1773300
74081 --- /dev/null
74082 +++ b/grsecurity/grsec_ipc.c
74083 @@ -0,0 +1,48 @@
74084 +#include <linux/kernel.h>
74085 +#include <linux/mm.h>
74086 +#include <linux/sched.h>
74087 +#include <linux/file.h>
74088 +#include <linux/ipc.h>
74089 +#include <linux/ipc_namespace.h>
74090 +#include <linux/grsecurity.h>
74091 +#include <linux/grinternal.h>
74092 +
74093 +int
74094 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74095 +{
74096 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74097 + int write;
74098 + int orig_granted_mode;
74099 + kuid_t euid;
74100 + kgid_t egid;
74101 +
74102 + if (!grsec_enable_harden_ipc)
74103 + return 1;
74104 +
74105 + euid = current_euid();
74106 + egid = current_egid();
74107 +
74108 + write = requested_mode & 00002;
74109 + orig_granted_mode = ipcp->mode;
74110 +
74111 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74112 + orig_granted_mode >>= 6;
74113 + else {
74114 + /* if likely wrong permissions, lock to user */
74115 + if (orig_granted_mode & 0007)
74116 + orig_granted_mode = 0;
74117 + /* otherwise do a egid-only check */
74118 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74119 + orig_granted_mode >>= 3;
74120 + /* otherwise, no access */
74121 + else
74122 + orig_granted_mode = 0;
74123 + }
74124 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74125 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74126 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74127 + return 0;
74128 + }
74129 +#endif
74130 + return 1;
74131 +}
74132 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74133 new file mode 100644
74134 index 0000000..5e05e20
74135 --- /dev/null
74136 +++ b/grsecurity/grsec_link.c
74137 @@ -0,0 +1,58 @@
74138 +#include <linux/kernel.h>
74139 +#include <linux/sched.h>
74140 +#include <linux/fs.h>
74141 +#include <linux/file.h>
74142 +#include <linux/grinternal.h>
74143 +
74144 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74145 +{
74146 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74147 + const struct inode *link_inode = link->dentry->d_inode;
74148 +
74149 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74150 + /* ignore root-owned links, e.g. /proc/self */
74151 + gr_is_global_nonroot(link_inode->i_uid) && target &&
74152 + !uid_eq(link_inode->i_uid, target->i_uid)) {
74153 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74154 + return 1;
74155 + }
74156 +#endif
74157 + return 0;
74158 +}
74159 +
74160 +int
74161 +gr_handle_follow_link(const struct inode *parent,
74162 + const struct inode *inode,
74163 + const struct dentry *dentry, const struct vfsmount *mnt)
74164 +{
74165 +#ifdef CONFIG_GRKERNSEC_LINK
74166 + const struct cred *cred = current_cred();
74167 +
74168 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74169 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74170 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74171 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74172 + return -EACCES;
74173 + }
74174 +#endif
74175 + return 0;
74176 +}
74177 +
74178 +int
74179 +gr_handle_hardlink(const struct dentry *dentry,
74180 + const struct vfsmount *mnt,
74181 + struct inode *inode, const int mode, const struct filename *to)
74182 +{
74183 +#ifdef CONFIG_GRKERNSEC_LINK
74184 + const struct cred *cred = current_cred();
74185 +
74186 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74187 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74188 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74189 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74190 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74191 + return -EPERM;
74192 + }
74193 +#endif
74194 + return 0;
74195 +}
74196 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74197 new file mode 100644
74198 index 0000000..dbe0a6b
74199 --- /dev/null
74200 +++ b/grsecurity/grsec_log.c
74201 @@ -0,0 +1,341 @@
74202 +#include <linux/kernel.h>
74203 +#include <linux/sched.h>
74204 +#include <linux/file.h>
74205 +#include <linux/tty.h>
74206 +#include <linux/fs.h>
74207 +#include <linux/mm.h>
74208 +#include <linux/grinternal.h>
74209 +
74210 +#ifdef CONFIG_TREE_PREEMPT_RCU
74211 +#define DISABLE_PREEMPT() preempt_disable()
74212 +#define ENABLE_PREEMPT() preempt_enable()
74213 +#else
74214 +#define DISABLE_PREEMPT()
74215 +#define ENABLE_PREEMPT()
74216 +#endif
74217 +
74218 +#define BEGIN_LOCKS(x) \
74219 + DISABLE_PREEMPT(); \
74220 + rcu_read_lock(); \
74221 + read_lock(&tasklist_lock); \
74222 + read_lock(&grsec_exec_file_lock); \
74223 + if (x != GR_DO_AUDIT) \
74224 + spin_lock(&grsec_alert_lock); \
74225 + else \
74226 + spin_lock(&grsec_audit_lock)
74227 +
74228 +#define END_LOCKS(x) \
74229 + if (x != GR_DO_AUDIT) \
74230 + spin_unlock(&grsec_alert_lock); \
74231 + else \
74232 + spin_unlock(&grsec_audit_lock); \
74233 + read_unlock(&grsec_exec_file_lock); \
74234 + read_unlock(&tasklist_lock); \
74235 + rcu_read_unlock(); \
74236 + ENABLE_PREEMPT(); \
74237 + if (x == GR_DONT_AUDIT) \
74238 + gr_handle_alertkill(current)
74239 +
74240 +enum {
74241 + FLOODING,
74242 + NO_FLOODING
74243 +};
74244 +
74245 +extern char *gr_alert_log_fmt;
74246 +extern char *gr_audit_log_fmt;
74247 +extern char *gr_alert_log_buf;
74248 +extern char *gr_audit_log_buf;
74249 +
74250 +static int gr_log_start(int audit)
74251 +{
74252 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
74253 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
74254 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74255 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
74256 + unsigned long curr_secs = get_seconds();
74257 +
74258 + if (audit == GR_DO_AUDIT)
74259 + goto set_fmt;
74260 +
74261 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
74262 + grsec_alert_wtime = curr_secs;
74263 + grsec_alert_fyet = 0;
74264 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
74265 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
74266 + grsec_alert_fyet++;
74267 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
74268 + grsec_alert_wtime = curr_secs;
74269 + grsec_alert_fyet++;
74270 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
74271 + return FLOODING;
74272 + }
74273 + else return FLOODING;
74274 +
74275 +set_fmt:
74276 +#endif
74277 + memset(buf, 0, PAGE_SIZE);
74278 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
74279 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
74280 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74281 + } else if (current->signal->curr_ip) {
74282 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
74283 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
74284 + } else if (gr_acl_is_enabled()) {
74285 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
74286 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74287 + } else {
74288 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
74289 + strcpy(buf, fmt);
74290 + }
74291 +
74292 + return NO_FLOODING;
74293 +}
74294 +
74295 +static void gr_log_middle(int audit, const char *msg, va_list ap)
74296 + __attribute__ ((format (printf, 2, 0)));
74297 +
74298 +static void gr_log_middle(int audit, const char *msg, va_list ap)
74299 +{
74300 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74301 + unsigned int len = strlen(buf);
74302 +
74303 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74304 +
74305 + return;
74306 +}
74307 +
74308 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
74309 + __attribute__ ((format (printf, 2, 3)));
74310 +
74311 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
74312 +{
74313 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74314 + unsigned int len = strlen(buf);
74315 + va_list ap;
74316 +
74317 + va_start(ap, msg);
74318 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74319 + va_end(ap);
74320 +
74321 + return;
74322 +}
74323 +
74324 +static void gr_log_end(int audit, int append_default)
74325 +{
74326 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74327 + if (append_default) {
74328 + struct task_struct *task = current;
74329 + struct task_struct *parent = task->real_parent;
74330 + const struct cred *cred = __task_cred(task);
74331 + const struct cred *pcred = __task_cred(parent);
74332 + unsigned int len = strlen(buf);
74333 +
74334 + 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));
74335 + }
74336 +
74337 + printk("%s\n", buf);
74338 +
74339 + return;
74340 +}
74341 +
74342 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
74343 +{
74344 + int logtype;
74345 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
74346 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
74347 + void *voidptr = NULL;
74348 + int num1 = 0, num2 = 0;
74349 + unsigned long ulong1 = 0, ulong2 = 0;
74350 + struct dentry *dentry = NULL;
74351 + struct vfsmount *mnt = NULL;
74352 + struct file *file = NULL;
74353 + struct task_struct *task = NULL;
74354 + struct vm_area_struct *vma = NULL;
74355 + const struct cred *cred, *pcred;
74356 + va_list ap;
74357 +
74358 + BEGIN_LOCKS(audit);
74359 + logtype = gr_log_start(audit);
74360 + if (logtype == FLOODING) {
74361 + END_LOCKS(audit);
74362 + return;
74363 + }
74364 + va_start(ap, argtypes);
74365 + switch (argtypes) {
74366 + case GR_TTYSNIFF:
74367 + task = va_arg(ap, struct task_struct *);
74368 + 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));
74369 + break;
74370 + case GR_SYSCTL_HIDDEN:
74371 + str1 = va_arg(ap, char *);
74372 + gr_log_middle_varargs(audit, msg, result, str1);
74373 + break;
74374 + case GR_RBAC:
74375 + dentry = va_arg(ap, struct dentry *);
74376 + mnt = va_arg(ap, struct vfsmount *);
74377 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
74378 + break;
74379 + case GR_RBAC_STR:
74380 + dentry = va_arg(ap, struct dentry *);
74381 + mnt = va_arg(ap, struct vfsmount *);
74382 + str1 = va_arg(ap, char *);
74383 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
74384 + break;
74385 + case GR_STR_RBAC:
74386 + str1 = va_arg(ap, char *);
74387 + dentry = va_arg(ap, struct dentry *);
74388 + mnt = va_arg(ap, struct vfsmount *);
74389 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
74390 + break;
74391 + case GR_RBAC_MODE2:
74392 + dentry = va_arg(ap, struct dentry *);
74393 + mnt = va_arg(ap, struct vfsmount *);
74394 + str1 = va_arg(ap, char *);
74395 + str2 = va_arg(ap, char *);
74396 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
74397 + break;
74398 + case GR_RBAC_MODE3:
74399 + dentry = va_arg(ap, struct dentry *);
74400 + mnt = va_arg(ap, struct vfsmount *);
74401 + str1 = va_arg(ap, char *);
74402 + str2 = va_arg(ap, char *);
74403 + str3 = va_arg(ap, char *);
74404 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
74405 + break;
74406 + case GR_FILENAME:
74407 + dentry = va_arg(ap, struct dentry *);
74408 + mnt = va_arg(ap, struct vfsmount *);
74409 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
74410 + break;
74411 + case GR_STR_FILENAME:
74412 + str1 = va_arg(ap, char *);
74413 + dentry = va_arg(ap, struct dentry *);
74414 + mnt = va_arg(ap, struct vfsmount *);
74415 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
74416 + break;
74417 + case GR_FILENAME_STR:
74418 + dentry = va_arg(ap, struct dentry *);
74419 + mnt = va_arg(ap, struct vfsmount *);
74420 + str1 = va_arg(ap, char *);
74421 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
74422 + break;
74423 + case GR_FILENAME_TWO_INT:
74424 + dentry = va_arg(ap, struct dentry *);
74425 + mnt = va_arg(ap, struct vfsmount *);
74426 + num1 = va_arg(ap, int);
74427 + num2 = va_arg(ap, int);
74428 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
74429 + break;
74430 + case GR_FILENAME_TWO_INT_STR:
74431 + dentry = va_arg(ap, struct dentry *);
74432 + mnt = va_arg(ap, struct vfsmount *);
74433 + num1 = va_arg(ap, int);
74434 + num2 = va_arg(ap, int);
74435 + str1 = va_arg(ap, char *);
74436 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
74437 + break;
74438 + case GR_TEXTREL:
74439 + file = va_arg(ap, struct file *);
74440 + ulong1 = va_arg(ap, unsigned long);
74441 + ulong2 = va_arg(ap, unsigned long);
74442 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
74443 + break;
74444 + case GR_PTRACE:
74445 + task = va_arg(ap, struct task_struct *);
74446 + 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));
74447 + break;
74448 + case GR_RESOURCE:
74449 + task = va_arg(ap, struct task_struct *);
74450 + cred = __task_cred(task);
74451 + pcred = __task_cred(task->real_parent);
74452 + ulong1 = va_arg(ap, unsigned long);
74453 + str1 = va_arg(ap, char *);
74454 + ulong2 = va_arg(ap, unsigned long);
74455 + 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));
74456 + break;
74457 + case GR_CAP:
74458 + task = va_arg(ap, struct task_struct *);
74459 + cred = __task_cred(task);
74460 + pcred = __task_cred(task->real_parent);
74461 + str1 = va_arg(ap, char *);
74462 + 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));
74463 + break;
74464 + case GR_SIG:
74465 + str1 = va_arg(ap, char *);
74466 + voidptr = va_arg(ap, void *);
74467 + gr_log_middle_varargs(audit, msg, str1, voidptr);
74468 + break;
74469 + case GR_SIG2:
74470 + task = va_arg(ap, struct task_struct *);
74471 + cred = __task_cred(task);
74472 + pcred = __task_cred(task->real_parent);
74473 + num1 = va_arg(ap, int);
74474 + 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));
74475 + break;
74476 + case GR_CRASH1:
74477 + task = va_arg(ap, struct task_struct *);
74478 + cred = __task_cred(task);
74479 + pcred = __task_cred(task->real_parent);
74480 + ulong1 = va_arg(ap, unsigned long);
74481 + 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);
74482 + break;
74483 + case GR_CRASH2:
74484 + task = va_arg(ap, struct task_struct *);
74485 + cred = __task_cred(task);
74486 + pcred = __task_cred(task->real_parent);
74487 + ulong1 = va_arg(ap, unsigned long);
74488 + 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);
74489 + break;
74490 + case GR_RWXMAP:
74491 + file = va_arg(ap, struct file *);
74492 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
74493 + break;
74494 + case GR_RWXMAPVMA:
74495 + vma = va_arg(ap, struct vm_area_struct *);
74496 + if (vma->vm_file)
74497 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
74498 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
74499 + str1 = "<stack>";
74500 + else if (vma->vm_start <= current->mm->brk &&
74501 + vma->vm_end >= current->mm->start_brk)
74502 + str1 = "<heap>";
74503 + else
74504 + str1 = "<anonymous mapping>";
74505 + gr_log_middle_varargs(audit, msg, str1);
74506 + break;
74507 + case GR_PSACCT:
74508 + {
74509 + unsigned int wday, cday;
74510 + __u8 whr, chr;
74511 + __u8 wmin, cmin;
74512 + __u8 wsec, csec;
74513 + char cur_tty[64] = { 0 };
74514 + char parent_tty[64] = { 0 };
74515 +
74516 + task = va_arg(ap, struct task_struct *);
74517 + wday = va_arg(ap, unsigned int);
74518 + cday = va_arg(ap, unsigned int);
74519 + whr = va_arg(ap, int);
74520 + chr = va_arg(ap, int);
74521 + wmin = va_arg(ap, int);
74522 + cmin = va_arg(ap, int);
74523 + wsec = va_arg(ap, int);
74524 + csec = va_arg(ap, int);
74525 + ulong1 = va_arg(ap, unsigned long);
74526 + cred = __task_cred(task);
74527 + pcred = __task_cred(task->real_parent);
74528 +
74529 + 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));
74530 + }
74531 + break;
74532 + default:
74533 + gr_log_middle(audit, msg, ap);
74534 + }
74535 + va_end(ap);
74536 + // these don't need DEFAULTSECARGS printed on the end
74537 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
74538 + gr_log_end(audit, 0);
74539 + else
74540 + gr_log_end(audit, 1);
74541 + END_LOCKS(audit);
74542 +}
74543 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
74544 new file mode 100644
74545 index 0000000..0e39d8c
74546 --- /dev/null
74547 +++ b/grsecurity/grsec_mem.c
74548 @@ -0,0 +1,48 @@
74549 +#include <linux/kernel.h>
74550 +#include <linux/sched.h>
74551 +#include <linux/mm.h>
74552 +#include <linux/mman.h>
74553 +#include <linux/module.h>
74554 +#include <linux/grinternal.h>
74555 +
74556 +void gr_handle_msr_write(void)
74557 +{
74558 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
74559 + return;
74560 +}
74561 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
74562 +
74563 +void
74564 +gr_handle_ioperm(void)
74565 +{
74566 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
74567 + return;
74568 +}
74569 +
74570 +void
74571 +gr_handle_iopl(void)
74572 +{
74573 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
74574 + return;
74575 +}
74576 +
74577 +void
74578 +gr_handle_mem_readwrite(u64 from, u64 to)
74579 +{
74580 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
74581 + return;
74582 +}
74583 +
74584 +void
74585 +gr_handle_vm86(void)
74586 +{
74587 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
74588 + return;
74589 +}
74590 +
74591 +void
74592 +gr_log_badprocpid(const char *entry)
74593 +{
74594 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
74595 + return;
74596 +}
74597 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
74598 new file mode 100644
74599 index 0000000..cd9e124
74600 --- /dev/null
74601 +++ b/grsecurity/grsec_mount.c
74602 @@ -0,0 +1,65 @@
74603 +#include <linux/kernel.h>
74604 +#include <linux/sched.h>
74605 +#include <linux/mount.h>
74606 +#include <linux/major.h>
74607 +#include <linux/grsecurity.h>
74608 +#include <linux/grinternal.h>
74609 +
74610 +void
74611 +gr_log_remount(const char *devname, const int retval)
74612 +{
74613 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74614 + if (grsec_enable_mount && (retval >= 0))
74615 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
74616 +#endif
74617 + return;
74618 +}
74619 +
74620 +void
74621 +gr_log_unmount(const char *devname, const int retval)
74622 +{
74623 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74624 + if (grsec_enable_mount && (retval >= 0))
74625 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
74626 +#endif
74627 + return;
74628 +}
74629 +
74630 +void
74631 +gr_log_mount(const char *from, const char *to, const int retval)
74632 +{
74633 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74634 + if (grsec_enable_mount && (retval >= 0))
74635 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
74636 +#endif
74637 + return;
74638 +}
74639 +
74640 +int
74641 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
74642 +{
74643 +#ifdef CONFIG_GRKERNSEC_ROFS
74644 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
74645 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
74646 + return -EPERM;
74647 + } else
74648 + return 0;
74649 +#endif
74650 + return 0;
74651 +}
74652 +
74653 +int
74654 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
74655 +{
74656 +#ifdef CONFIG_GRKERNSEC_ROFS
74657 + struct inode *inode = dentry->d_inode;
74658 +
74659 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
74660 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
74661 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
74662 + return -EPERM;
74663 + } else
74664 + return 0;
74665 +#endif
74666 + return 0;
74667 +}
74668 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
74669 new file mode 100644
74670 index 0000000..6ee9d50
74671 --- /dev/null
74672 +++ b/grsecurity/grsec_pax.c
74673 @@ -0,0 +1,45 @@
74674 +#include <linux/kernel.h>
74675 +#include <linux/sched.h>
74676 +#include <linux/mm.h>
74677 +#include <linux/file.h>
74678 +#include <linux/grinternal.h>
74679 +#include <linux/grsecurity.h>
74680 +
74681 +void
74682 +gr_log_textrel(struct vm_area_struct * vma)
74683 +{
74684 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74685 + if (grsec_enable_log_rwxmaps)
74686 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
74687 +#endif
74688 + return;
74689 +}
74690 +
74691 +void gr_log_ptgnustack(struct file *file)
74692 +{
74693 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74694 + if (grsec_enable_log_rwxmaps)
74695 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
74696 +#endif
74697 + return;
74698 +}
74699 +
74700 +void
74701 +gr_log_rwxmmap(struct file *file)
74702 +{
74703 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74704 + if (grsec_enable_log_rwxmaps)
74705 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
74706 +#endif
74707 + return;
74708 +}
74709 +
74710 +void
74711 +gr_log_rwxmprotect(struct vm_area_struct *vma)
74712 +{
74713 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74714 + if (grsec_enable_log_rwxmaps)
74715 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
74716 +#endif
74717 + return;
74718 +}
74719 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
74720 new file mode 100644
74721 index 0000000..f7f29aa
74722 --- /dev/null
74723 +++ b/grsecurity/grsec_ptrace.c
74724 @@ -0,0 +1,30 @@
74725 +#include <linux/kernel.h>
74726 +#include <linux/sched.h>
74727 +#include <linux/grinternal.h>
74728 +#include <linux/security.h>
74729 +
74730 +void
74731 +gr_audit_ptrace(struct task_struct *task)
74732 +{
74733 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74734 + if (grsec_enable_audit_ptrace)
74735 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
74736 +#endif
74737 + return;
74738 +}
74739 +
74740 +int
74741 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
74742 +{
74743 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74744 + const struct dentry *dentry = file->f_path.dentry;
74745 + const struct vfsmount *mnt = file->f_path.mnt;
74746 +
74747 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
74748 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
74749 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
74750 + return -EACCES;
74751 + }
74752 +#endif
74753 + return 0;
74754 +}
74755 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
74756 new file mode 100644
74757 index 0000000..3860c7e
74758 --- /dev/null
74759 +++ b/grsecurity/grsec_sig.c
74760 @@ -0,0 +1,236 @@
74761 +#include <linux/kernel.h>
74762 +#include <linux/sched.h>
74763 +#include <linux/fs.h>
74764 +#include <linux/delay.h>
74765 +#include <linux/grsecurity.h>
74766 +#include <linux/grinternal.h>
74767 +#include <linux/hardirq.h>
74768 +
74769 +char *signames[] = {
74770 + [SIGSEGV] = "Segmentation fault",
74771 + [SIGILL] = "Illegal instruction",
74772 + [SIGABRT] = "Abort",
74773 + [SIGBUS] = "Invalid alignment/Bus error"
74774 +};
74775 +
74776 +void
74777 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
74778 +{
74779 +#ifdef CONFIG_GRKERNSEC_SIGNAL
74780 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
74781 + (sig == SIGABRT) || (sig == SIGBUS))) {
74782 + if (task_pid_nr(t) == task_pid_nr(current)) {
74783 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
74784 + } else {
74785 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
74786 + }
74787 + }
74788 +#endif
74789 + return;
74790 +}
74791 +
74792 +int
74793 +gr_handle_signal(const struct task_struct *p, const int sig)
74794 +{
74795 +#ifdef CONFIG_GRKERNSEC
74796 + /* ignore the 0 signal for protected task checks */
74797 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
74798 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
74799 + return -EPERM;
74800 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
74801 + return -EPERM;
74802 + }
74803 +#endif
74804 + return 0;
74805 +}
74806 +
74807 +#ifdef CONFIG_GRKERNSEC
74808 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
74809 +
74810 +int gr_fake_force_sig(int sig, struct task_struct *t)
74811 +{
74812 + unsigned long int flags;
74813 + int ret, blocked, ignored;
74814 + struct k_sigaction *action;
74815 +
74816 + spin_lock_irqsave(&t->sighand->siglock, flags);
74817 + action = &t->sighand->action[sig-1];
74818 + ignored = action->sa.sa_handler == SIG_IGN;
74819 + blocked = sigismember(&t->blocked, sig);
74820 + if (blocked || ignored) {
74821 + action->sa.sa_handler = SIG_DFL;
74822 + if (blocked) {
74823 + sigdelset(&t->blocked, sig);
74824 + recalc_sigpending_and_wake(t);
74825 + }
74826 + }
74827 + if (action->sa.sa_handler == SIG_DFL)
74828 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
74829 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
74830 +
74831 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
74832 +
74833 + return ret;
74834 +}
74835 +#endif
74836 +
74837 +#define GR_USER_BAN_TIME (15 * 60)
74838 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
74839 +
74840 +void gr_handle_brute_attach(int dumpable)
74841 +{
74842 +#ifdef CONFIG_GRKERNSEC_BRUTE
74843 + struct task_struct *p = current;
74844 + kuid_t uid = GLOBAL_ROOT_UID;
74845 + int daemon = 0;
74846 +
74847 + if (!grsec_enable_brute)
74848 + return;
74849 +
74850 + rcu_read_lock();
74851 + read_lock(&tasklist_lock);
74852 + read_lock(&grsec_exec_file_lock);
74853 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
74854 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
74855 + p->real_parent->brute = 1;
74856 + daemon = 1;
74857 + } else {
74858 + const struct cred *cred = __task_cred(p), *cred2;
74859 + struct task_struct *tsk, *tsk2;
74860 +
74861 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
74862 + struct user_struct *user;
74863 +
74864 + uid = cred->uid;
74865 +
74866 + /* this is put upon execution past expiration */
74867 + user = find_user(uid);
74868 + if (user == NULL)
74869 + goto unlock;
74870 + user->suid_banned = 1;
74871 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
74872 + if (user->suid_ban_expires == ~0UL)
74873 + user->suid_ban_expires--;
74874 +
74875 + /* only kill other threads of the same binary, from the same user */
74876 + do_each_thread(tsk2, tsk) {
74877 + cred2 = __task_cred(tsk);
74878 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
74879 + gr_fake_force_sig(SIGKILL, tsk);
74880 + } while_each_thread(tsk2, tsk);
74881 + }
74882 + }
74883 +unlock:
74884 + read_unlock(&grsec_exec_file_lock);
74885 + read_unlock(&tasklist_lock);
74886 + rcu_read_unlock();
74887 +
74888 + if (gr_is_global_nonroot(uid))
74889 + 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);
74890 + else if (daemon)
74891 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
74892 +
74893 +#endif
74894 + return;
74895 +}
74896 +
74897 +void gr_handle_brute_check(void)
74898 +{
74899 +#ifdef CONFIG_GRKERNSEC_BRUTE
74900 + struct task_struct *p = current;
74901 +
74902 + if (unlikely(p->brute)) {
74903 + if (!grsec_enable_brute)
74904 + p->brute = 0;
74905 + else if (time_before(get_seconds(), p->brute_expires))
74906 + msleep(30 * 1000);
74907 + }
74908 +#endif
74909 + return;
74910 +}
74911 +
74912 +void gr_handle_kernel_exploit(void)
74913 +{
74914 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74915 + const struct cred *cred;
74916 + struct task_struct *tsk, *tsk2;
74917 + struct user_struct *user;
74918 + kuid_t uid;
74919 +
74920 + if (in_irq() || in_serving_softirq() || in_nmi())
74921 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
74922 +
74923 + uid = current_uid();
74924 +
74925 + if (gr_is_global_root(uid))
74926 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
74927 + else {
74928 + /* kill all the processes of this user, hold a reference
74929 + to their creds struct, and prevent them from creating
74930 + another process until system reset
74931 + */
74932 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
74933 + GR_GLOBAL_UID(uid));
74934 + /* we intentionally leak this ref */
74935 + user = get_uid(current->cred->user);
74936 + if (user)
74937 + user->kernel_banned = 1;
74938 +
74939 + /* kill all processes of this user */
74940 + read_lock(&tasklist_lock);
74941 + do_each_thread(tsk2, tsk) {
74942 + cred = __task_cred(tsk);
74943 + if (uid_eq(cred->uid, uid))
74944 + gr_fake_force_sig(SIGKILL, tsk);
74945 + } while_each_thread(tsk2, tsk);
74946 + read_unlock(&tasklist_lock);
74947 + }
74948 +#endif
74949 +}
74950 +
74951 +#ifdef CONFIG_GRKERNSEC_BRUTE
74952 +static bool suid_ban_expired(struct user_struct *user)
74953 +{
74954 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
74955 + user->suid_banned = 0;
74956 + user->suid_ban_expires = 0;
74957 + free_uid(user);
74958 + return true;
74959 + }
74960 +
74961 + return false;
74962 +}
74963 +#endif
74964 +
74965 +int gr_process_kernel_exec_ban(void)
74966 +{
74967 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74968 + if (unlikely(current->cred->user->kernel_banned))
74969 + return -EPERM;
74970 +#endif
74971 + return 0;
74972 +}
74973 +
74974 +int gr_process_kernel_setuid_ban(struct user_struct *user)
74975 +{
74976 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74977 + if (unlikely(user->kernel_banned))
74978 + gr_fake_force_sig(SIGKILL, current);
74979 +#endif
74980 + return 0;
74981 +}
74982 +
74983 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
74984 +{
74985 +#ifdef CONFIG_GRKERNSEC_BRUTE
74986 + struct user_struct *user = current->cred->user;
74987 + if (unlikely(user->suid_banned)) {
74988 + if (suid_ban_expired(user))
74989 + return 0;
74990 + /* disallow execution of suid binaries only */
74991 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
74992 + return -EPERM;
74993 + }
74994 +#endif
74995 + return 0;
74996 +}
74997 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
74998 new file mode 100644
74999 index 0000000..c0aef3a
75000 --- /dev/null
75001 +++ b/grsecurity/grsec_sock.c
75002 @@ -0,0 +1,244 @@
75003 +#include <linux/kernel.h>
75004 +#include <linux/module.h>
75005 +#include <linux/sched.h>
75006 +#include <linux/file.h>
75007 +#include <linux/net.h>
75008 +#include <linux/in.h>
75009 +#include <linux/ip.h>
75010 +#include <net/sock.h>
75011 +#include <net/inet_sock.h>
75012 +#include <linux/grsecurity.h>
75013 +#include <linux/grinternal.h>
75014 +#include <linux/gracl.h>
75015 +
75016 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75017 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75018 +
75019 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75020 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75021 +
75022 +#ifdef CONFIG_UNIX_MODULE
75023 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75024 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75025 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75026 +EXPORT_SYMBOL_GPL(gr_handle_create);
75027 +#endif
75028 +
75029 +#ifdef CONFIG_GRKERNSEC
75030 +#define gr_conn_table_size 32749
75031 +struct conn_table_entry {
75032 + struct conn_table_entry *next;
75033 + struct signal_struct *sig;
75034 +};
75035 +
75036 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75037 +DEFINE_SPINLOCK(gr_conn_table_lock);
75038 +
75039 +extern const char * gr_socktype_to_name(unsigned char type);
75040 +extern const char * gr_proto_to_name(unsigned char proto);
75041 +extern const char * gr_sockfamily_to_name(unsigned char family);
75042 +
75043 +static __inline__ int
75044 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75045 +{
75046 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75047 +}
75048 +
75049 +static __inline__ int
75050 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75051 + __u16 sport, __u16 dport)
75052 +{
75053 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75054 + sig->gr_sport == sport && sig->gr_dport == dport))
75055 + return 1;
75056 + else
75057 + return 0;
75058 +}
75059 +
75060 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75061 +{
75062 + struct conn_table_entry **match;
75063 + unsigned int index;
75064 +
75065 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75066 + sig->gr_sport, sig->gr_dport,
75067 + gr_conn_table_size);
75068 +
75069 + newent->sig = sig;
75070 +
75071 + match = &gr_conn_table[index];
75072 + newent->next = *match;
75073 + *match = newent;
75074 +
75075 + return;
75076 +}
75077 +
75078 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75079 +{
75080 + struct conn_table_entry *match, *last = NULL;
75081 + unsigned int index;
75082 +
75083 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75084 + sig->gr_sport, sig->gr_dport,
75085 + gr_conn_table_size);
75086 +
75087 + match = gr_conn_table[index];
75088 + while (match && !conn_match(match->sig,
75089 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75090 + sig->gr_dport)) {
75091 + last = match;
75092 + match = match->next;
75093 + }
75094 +
75095 + if (match) {
75096 + if (last)
75097 + last->next = match->next;
75098 + else
75099 + gr_conn_table[index] = NULL;
75100 + kfree(match);
75101 + }
75102 +
75103 + return;
75104 +}
75105 +
75106 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75107 + __u16 sport, __u16 dport)
75108 +{
75109 + struct conn_table_entry *match;
75110 + unsigned int index;
75111 +
75112 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75113 +
75114 + match = gr_conn_table[index];
75115 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75116 + match = match->next;
75117 +
75118 + if (match)
75119 + return match->sig;
75120 + else
75121 + return NULL;
75122 +}
75123 +
75124 +#endif
75125 +
75126 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75127 +{
75128 +#ifdef CONFIG_GRKERNSEC
75129 + struct signal_struct *sig = task->signal;
75130 + struct conn_table_entry *newent;
75131 +
75132 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75133 + if (newent == NULL)
75134 + return;
75135 + /* no bh lock needed since we are called with bh disabled */
75136 + spin_lock(&gr_conn_table_lock);
75137 + gr_del_task_from_ip_table_nolock(sig);
75138 + sig->gr_saddr = inet->inet_rcv_saddr;
75139 + sig->gr_daddr = inet->inet_daddr;
75140 + sig->gr_sport = inet->inet_sport;
75141 + sig->gr_dport = inet->inet_dport;
75142 + gr_add_to_task_ip_table_nolock(sig, newent);
75143 + spin_unlock(&gr_conn_table_lock);
75144 +#endif
75145 + return;
75146 +}
75147 +
75148 +void gr_del_task_from_ip_table(struct task_struct *task)
75149 +{
75150 +#ifdef CONFIG_GRKERNSEC
75151 + spin_lock_bh(&gr_conn_table_lock);
75152 + gr_del_task_from_ip_table_nolock(task->signal);
75153 + spin_unlock_bh(&gr_conn_table_lock);
75154 +#endif
75155 + return;
75156 +}
75157 +
75158 +void
75159 +gr_attach_curr_ip(const struct sock *sk)
75160 +{
75161 +#ifdef CONFIG_GRKERNSEC
75162 + struct signal_struct *p, *set;
75163 + const struct inet_sock *inet = inet_sk(sk);
75164 +
75165 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75166 + return;
75167 +
75168 + set = current->signal;
75169 +
75170 + spin_lock_bh(&gr_conn_table_lock);
75171 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75172 + inet->inet_dport, inet->inet_sport);
75173 + if (unlikely(p != NULL)) {
75174 + set->curr_ip = p->curr_ip;
75175 + set->used_accept = 1;
75176 + gr_del_task_from_ip_table_nolock(p);
75177 + spin_unlock_bh(&gr_conn_table_lock);
75178 + return;
75179 + }
75180 + spin_unlock_bh(&gr_conn_table_lock);
75181 +
75182 + set->curr_ip = inet->inet_daddr;
75183 + set->used_accept = 1;
75184 +#endif
75185 + return;
75186 +}
75187 +
75188 +int
75189 +gr_handle_sock_all(const int family, const int type, const int protocol)
75190 +{
75191 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75192 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75193 + (family != AF_UNIX)) {
75194 + if (family == AF_INET)
75195 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75196 + else
75197 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75198 + return -EACCES;
75199 + }
75200 +#endif
75201 + return 0;
75202 +}
75203 +
75204 +int
75205 +gr_handle_sock_server(const struct sockaddr *sck)
75206 +{
75207 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75208 + if (grsec_enable_socket_server &&
75209 + in_group_p(grsec_socket_server_gid) &&
75210 + sck && (sck->sa_family != AF_UNIX) &&
75211 + (sck->sa_family != AF_LOCAL)) {
75212 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75213 + return -EACCES;
75214 + }
75215 +#endif
75216 + return 0;
75217 +}
75218 +
75219 +int
75220 +gr_handle_sock_server_other(const struct sock *sck)
75221 +{
75222 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75223 + if (grsec_enable_socket_server &&
75224 + in_group_p(grsec_socket_server_gid) &&
75225 + sck && (sck->sk_family != AF_UNIX) &&
75226 + (sck->sk_family != AF_LOCAL)) {
75227 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75228 + return -EACCES;
75229 + }
75230 +#endif
75231 + return 0;
75232 +}
75233 +
75234 +int
75235 +gr_handle_sock_client(const struct sockaddr *sck)
75236 +{
75237 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75238 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
75239 + sck && (sck->sa_family != AF_UNIX) &&
75240 + (sck->sa_family != AF_LOCAL)) {
75241 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
75242 + return -EACCES;
75243 + }
75244 +#endif
75245 + return 0;
75246 +}
75247 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
75248 new file mode 100644
75249 index 0000000..8159888
75250 --- /dev/null
75251 +++ b/grsecurity/grsec_sysctl.c
75252 @@ -0,0 +1,479 @@
75253 +#include <linux/kernel.h>
75254 +#include <linux/sched.h>
75255 +#include <linux/sysctl.h>
75256 +#include <linux/grsecurity.h>
75257 +#include <linux/grinternal.h>
75258 +
75259 +int
75260 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
75261 +{
75262 +#ifdef CONFIG_GRKERNSEC_SYSCTL
75263 + if (dirname == NULL || name == NULL)
75264 + return 0;
75265 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
75266 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
75267 + return -EACCES;
75268 + }
75269 +#endif
75270 + return 0;
75271 +}
75272 +
75273 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
75274 +static int __maybe_unused __read_only one = 1;
75275 +#endif
75276 +
75277 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
75278 + defined(CONFIG_GRKERNSEC_DENYUSB)
75279 +struct ctl_table grsecurity_table[] = {
75280 +#ifdef CONFIG_GRKERNSEC_SYSCTL
75281 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
75282 +#ifdef CONFIG_GRKERNSEC_IO
75283 + {
75284 + .procname = "disable_priv_io",
75285 + .data = &grsec_disable_privio,
75286 + .maxlen = sizeof(int),
75287 + .mode = 0600,
75288 + .proc_handler = &proc_dointvec,
75289 + },
75290 +#endif
75291 +#endif
75292 +#ifdef CONFIG_GRKERNSEC_LINK
75293 + {
75294 + .procname = "linking_restrictions",
75295 + .data = &grsec_enable_link,
75296 + .maxlen = sizeof(int),
75297 + .mode = 0600,
75298 + .proc_handler = &proc_dointvec,
75299 + },
75300 +#endif
75301 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75302 + {
75303 + .procname = "enforce_symlinksifowner",
75304 + .data = &grsec_enable_symlinkown,
75305 + .maxlen = sizeof(int),
75306 + .mode = 0600,
75307 + .proc_handler = &proc_dointvec,
75308 + },
75309 + {
75310 + .procname = "symlinkown_gid",
75311 + .data = &grsec_symlinkown_gid,
75312 + .maxlen = sizeof(int),
75313 + .mode = 0600,
75314 + .proc_handler = &proc_dointvec,
75315 + },
75316 +#endif
75317 +#ifdef CONFIG_GRKERNSEC_BRUTE
75318 + {
75319 + .procname = "deter_bruteforce",
75320 + .data = &grsec_enable_brute,
75321 + .maxlen = sizeof(int),
75322 + .mode = 0600,
75323 + .proc_handler = &proc_dointvec,
75324 + },
75325 +#endif
75326 +#ifdef CONFIG_GRKERNSEC_FIFO
75327 + {
75328 + .procname = "fifo_restrictions",
75329 + .data = &grsec_enable_fifo,
75330 + .maxlen = sizeof(int),
75331 + .mode = 0600,
75332 + .proc_handler = &proc_dointvec,
75333 + },
75334 +#endif
75335 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75336 + {
75337 + .procname = "ptrace_readexec",
75338 + .data = &grsec_enable_ptrace_readexec,
75339 + .maxlen = sizeof(int),
75340 + .mode = 0600,
75341 + .proc_handler = &proc_dointvec,
75342 + },
75343 +#endif
75344 +#ifdef CONFIG_GRKERNSEC_SETXID
75345 + {
75346 + .procname = "consistent_setxid",
75347 + .data = &grsec_enable_setxid,
75348 + .maxlen = sizeof(int),
75349 + .mode = 0600,
75350 + .proc_handler = &proc_dointvec,
75351 + },
75352 +#endif
75353 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75354 + {
75355 + .procname = "ip_blackhole",
75356 + .data = &grsec_enable_blackhole,
75357 + .maxlen = sizeof(int),
75358 + .mode = 0600,
75359 + .proc_handler = &proc_dointvec,
75360 + },
75361 + {
75362 + .procname = "lastack_retries",
75363 + .data = &grsec_lastack_retries,
75364 + .maxlen = sizeof(int),
75365 + .mode = 0600,
75366 + .proc_handler = &proc_dointvec,
75367 + },
75368 +#endif
75369 +#ifdef CONFIG_GRKERNSEC_EXECLOG
75370 + {
75371 + .procname = "exec_logging",
75372 + .data = &grsec_enable_execlog,
75373 + .maxlen = sizeof(int),
75374 + .mode = 0600,
75375 + .proc_handler = &proc_dointvec,
75376 + },
75377 +#endif
75378 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75379 + {
75380 + .procname = "rwxmap_logging",
75381 + .data = &grsec_enable_log_rwxmaps,
75382 + .maxlen = sizeof(int),
75383 + .mode = 0600,
75384 + .proc_handler = &proc_dointvec,
75385 + },
75386 +#endif
75387 +#ifdef CONFIG_GRKERNSEC_SIGNAL
75388 + {
75389 + .procname = "signal_logging",
75390 + .data = &grsec_enable_signal,
75391 + .maxlen = sizeof(int),
75392 + .mode = 0600,
75393 + .proc_handler = &proc_dointvec,
75394 + },
75395 +#endif
75396 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
75397 + {
75398 + .procname = "forkfail_logging",
75399 + .data = &grsec_enable_forkfail,
75400 + .maxlen = sizeof(int),
75401 + .mode = 0600,
75402 + .proc_handler = &proc_dointvec,
75403 + },
75404 +#endif
75405 +#ifdef CONFIG_GRKERNSEC_TIME
75406 + {
75407 + .procname = "timechange_logging",
75408 + .data = &grsec_enable_time,
75409 + .maxlen = sizeof(int),
75410 + .mode = 0600,
75411 + .proc_handler = &proc_dointvec,
75412 + },
75413 +#endif
75414 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75415 + {
75416 + .procname = "chroot_deny_shmat",
75417 + .data = &grsec_enable_chroot_shmat,
75418 + .maxlen = sizeof(int),
75419 + .mode = 0600,
75420 + .proc_handler = &proc_dointvec,
75421 + },
75422 +#endif
75423 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75424 + {
75425 + .procname = "chroot_deny_unix",
75426 + .data = &grsec_enable_chroot_unix,
75427 + .maxlen = sizeof(int),
75428 + .mode = 0600,
75429 + .proc_handler = &proc_dointvec,
75430 + },
75431 +#endif
75432 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75433 + {
75434 + .procname = "chroot_deny_mount",
75435 + .data = &grsec_enable_chroot_mount,
75436 + .maxlen = sizeof(int),
75437 + .mode = 0600,
75438 + .proc_handler = &proc_dointvec,
75439 + },
75440 +#endif
75441 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75442 + {
75443 + .procname = "chroot_deny_fchdir",
75444 + .data = &grsec_enable_chroot_fchdir,
75445 + .maxlen = sizeof(int),
75446 + .mode = 0600,
75447 + .proc_handler = &proc_dointvec,
75448 + },
75449 +#endif
75450 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75451 + {
75452 + .procname = "chroot_deny_chroot",
75453 + .data = &grsec_enable_chroot_double,
75454 + .maxlen = sizeof(int),
75455 + .mode = 0600,
75456 + .proc_handler = &proc_dointvec,
75457 + },
75458 +#endif
75459 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75460 + {
75461 + .procname = "chroot_deny_pivot",
75462 + .data = &grsec_enable_chroot_pivot,
75463 + .maxlen = sizeof(int),
75464 + .mode = 0600,
75465 + .proc_handler = &proc_dointvec,
75466 + },
75467 +#endif
75468 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
75469 + {
75470 + .procname = "chroot_enforce_chdir",
75471 + .data = &grsec_enable_chroot_chdir,
75472 + .maxlen = sizeof(int),
75473 + .mode = 0600,
75474 + .proc_handler = &proc_dointvec,
75475 + },
75476 +#endif
75477 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75478 + {
75479 + .procname = "chroot_deny_chmod",
75480 + .data = &grsec_enable_chroot_chmod,
75481 + .maxlen = sizeof(int),
75482 + .mode = 0600,
75483 + .proc_handler = &proc_dointvec,
75484 + },
75485 +#endif
75486 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75487 + {
75488 + .procname = "chroot_deny_mknod",
75489 + .data = &grsec_enable_chroot_mknod,
75490 + .maxlen = sizeof(int),
75491 + .mode = 0600,
75492 + .proc_handler = &proc_dointvec,
75493 + },
75494 +#endif
75495 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75496 + {
75497 + .procname = "chroot_restrict_nice",
75498 + .data = &grsec_enable_chroot_nice,
75499 + .maxlen = sizeof(int),
75500 + .mode = 0600,
75501 + .proc_handler = &proc_dointvec,
75502 + },
75503 +#endif
75504 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75505 + {
75506 + .procname = "chroot_execlog",
75507 + .data = &grsec_enable_chroot_execlog,
75508 + .maxlen = sizeof(int),
75509 + .mode = 0600,
75510 + .proc_handler = &proc_dointvec,
75511 + },
75512 +#endif
75513 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75514 + {
75515 + .procname = "chroot_caps",
75516 + .data = &grsec_enable_chroot_caps,
75517 + .maxlen = sizeof(int),
75518 + .mode = 0600,
75519 + .proc_handler = &proc_dointvec,
75520 + },
75521 +#endif
75522 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75523 + {
75524 + .procname = "chroot_deny_sysctl",
75525 + .data = &grsec_enable_chroot_sysctl,
75526 + .maxlen = sizeof(int),
75527 + .mode = 0600,
75528 + .proc_handler = &proc_dointvec,
75529 + },
75530 +#endif
75531 +#ifdef CONFIG_GRKERNSEC_TPE
75532 + {
75533 + .procname = "tpe",
75534 + .data = &grsec_enable_tpe,
75535 + .maxlen = sizeof(int),
75536 + .mode = 0600,
75537 + .proc_handler = &proc_dointvec,
75538 + },
75539 + {
75540 + .procname = "tpe_gid",
75541 + .data = &grsec_tpe_gid,
75542 + .maxlen = sizeof(int),
75543 + .mode = 0600,
75544 + .proc_handler = &proc_dointvec,
75545 + },
75546 +#endif
75547 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75548 + {
75549 + .procname = "tpe_invert",
75550 + .data = &grsec_enable_tpe_invert,
75551 + .maxlen = sizeof(int),
75552 + .mode = 0600,
75553 + .proc_handler = &proc_dointvec,
75554 + },
75555 +#endif
75556 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
75557 + {
75558 + .procname = "tpe_restrict_all",
75559 + .data = &grsec_enable_tpe_all,
75560 + .maxlen = sizeof(int),
75561 + .mode = 0600,
75562 + .proc_handler = &proc_dointvec,
75563 + },
75564 +#endif
75565 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75566 + {
75567 + .procname = "socket_all",
75568 + .data = &grsec_enable_socket_all,
75569 + .maxlen = sizeof(int),
75570 + .mode = 0600,
75571 + .proc_handler = &proc_dointvec,
75572 + },
75573 + {
75574 + .procname = "socket_all_gid",
75575 + .data = &grsec_socket_all_gid,
75576 + .maxlen = sizeof(int),
75577 + .mode = 0600,
75578 + .proc_handler = &proc_dointvec,
75579 + },
75580 +#endif
75581 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75582 + {
75583 + .procname = "socket_client",
75584 + .data = &grsec_enable_socket_client,
75585 + .maxlen = sizeof(int),
75586 + .mode = 0600,
75587 + .proc_handler = &proc_dointvec,
75588 + },
75589 + {
75590 + .procname = "socket_client_gid",
75591 + .data = &grsec_socket_client_gid,
75592 + .maxlen = sizeof(int),
75593 + .mode = 0600,
75594 + .proc_handler = &proc_dointvec,
75595 + },
75596 +#endif
75597 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75598 + {
75599 + .procname = "socket_server",
75600 + .data = &grsec_enable_socket_server,
75601 + .maxlen = sizeof(int),
75602 + .mode = 0600,
75603 + .proc_handler = &proc_dointvec,
75604 + },
75605 + {
75606 + .procname = "socket_server_gid",
75607 + .data = &grsec_socket_server_gid,
75608 + .maxlen = sizeof(int),
75609 + .mode = 0600,
75610 + .proc_handler = &proc_dointvec,
75611 + },
75612 +#endif
75613 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
75614 + {
75615 + .procname = "audit_group",
75616 + .data = &grsec_enable_group,
75617 + .maxlen = sizeof(int),
75618 + .mode = 0600,
75619 + .proc_handler = &proc_dointvec,
75620 + },
75621 + {
75622 + .procname = "audit_gid",
75623 + .data = &grsec_audit_gid,
75624 + .maxlen = sizeof(int),
75625 + .mode = 0600,
75626 + .proc_handler = &proc_dointvec,
75627 + },
75628 +#endif
75629 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75630 + {
75631 + .procname = "audit_chdir",
75632 + .data = &grsec_enable_chdir,
75633 + .maxlen = sizeof(int),
75634 + .mode = 0600,
75635 + .proc_handler = &proc_dointvec,
75636 + },
75637 +#endif
75638 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75639 + {
75640 + .procname = "audit_mount",
75641 + .data = &grsec_enable_mount,
75642 + .maxlen = sizeof(int),
75643 + .mode = 0600,
75644 + .proc_handler = &proc_dointvec,
75645 + },
75646 +#endif
75647 +#ifdef CONFIG_GRKERNSEC_DMESG
75648 + {
75649 + .procname = "dmesg",
75650 + .data = &grsec_enable_dmesg,
75651 + .maxlen = sizeof(int),
75652 + .mode = 0600,
75653 + .proc_handler = &proc_dointvec,
75654 + },
75655 +#endif
75656 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75657 + {
75658 + .procname = "chroot_findtask",
75659 + .data = &grsec_enable_chroot_findtask,
75660 + .maxlen = sizeof(int),
75661 + .mode = 0600,
75662 + .proc_handler = &proc_dointvec,
75663 + },
75664 +#endif
75665 +#ifdef CONFIG_GRKERNSEC_RESLOG
75666 + {
75667 + .procname = "resource_logging",
75668 + .data = &grsec_resource_logging,
75669 + .maxlen = sizeof(int),
75670 + .mode = 0600,
75671 + .proc_handler = &proc_dointvec,
75672 + },
75673 +#endif
75674 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75675 + {
75676 + .procname = "audit_ptrace",
75677 + .data = &grsec_enable_audit_ptrace,
75678 + .maxlen = sizeof(int),
75679 + .mode = 0600,
75680 + .proc_handler = &proc_dointvec,
75681 + },
75682 +#endif
75683 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
75684 + {
75685 + .procname = "harden_ptrace",
75686 + .data = &grsec_enable_harden_ptrace,
75687 + .maxlen = sizeof(int),
75688 + .mode = 0600,
75689 + .proc_handler = &proc_dointvec,
75690 + },
75691 +#endif
75692 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75693 + {
75694 + .procname = "harden_ipc",
75695 + .data = &grsec_enable_harden_ipc,
75696 + .maxlen = sizeof(int),
75697 + .mode = 0600,
75698 + .proc_handler = &proc_dointvec,
75699 + },
75700 +#endif
75701 + {
75702 + .procname = "grsec_lock",
75703 + .data = &grsec_lock,
75704 + .maxlen = sizeof(int),
75705 + .mode = 0600,
75706 + .proc_handler = &proc_dointvec,
75707 + },
75708 +#endif
75709 +#ifdef CONFIG_GRKERNSEC_ROFS
75710 + {
75711 + .procname = "romount_protect",
75712 + .data = &grsec_enable_rofs,
75713 + .maxlen = sizeof(int),
75714 + .mode = 0600,
75715 + .proc_handler = &proc_dointvec_minmax,
75716 + .extra1 = &one,
75717 + .extra2 = &one,
75718 + },
75719 +#endif
75720 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
75721 + {
75722 + .procname = "deny_new_usb",
75723 + .data = &grsec_deny_new_usb,
75724 + .maxlen = sizeof(int),
75725 + .mode = 0600,
75726 + .proc_handler = &proc_dointvec,
75727 + },
75728 +#endif
75729 + { }
75730 +};
75731 +#endif
75732 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
75733 new file mode 100644
75734 index 0000000..61b514e
75735 --- /dev/null
75736 +++ b/grsecurity/grsec_time.c
75737 @@ -0,0 +1,16 @@
75738 +#include <linux/kernel.h>
75739 +#include <linux/sched.h>
75740 +#include <linux/grinternal.h>
75741 +#include <linux/module.h>
75742 +
75743 +void
75744 +gr_log_timechange(void)
75745 +{
75746 +#ifdef CONFIG_GRKERNSEC_TIME
75747 + if (grsec_enable_time)
75748 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
75749 +#endif
75750 + return;
75751 +}
75752 +
75753 +EXPORT_SYMBOL_GPL(gr_log_timechange);
75754 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
75755 new file mode 100644
75756 index 0000000..ee57dcf
75757 --- /dev/null
75758 +++ b/grsecurity/grsec_tpe.c
75759 @@ -0,0 +1,73 @@
75760 +#include <linux/kernel.h>
75761 +#include <linux/sched.h>
75762 +#include <linux/file.h>
75763 +#include <linux/fs.h>
75764 +#include <linux/grinternal.h>
75765 +
75766 +extern int gr_acl_tpe_check(void);
75767 +
75768 +int
75769 +gr_tpe_allow(const struct file *file)
75770 +{
75771 +#ifdef CONFIG_GRKERNSEC
75772 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
75773 + const struct cred *cred = current_cred();
75774 + char *msg = NULL;
75775 + char *msg2 = NULL;
75776 +
75777 + // never restrict root
75778 + if (gr_is_global_root(cred->uid))
75779 + return 1;
75780 +
75781 + if (grsec_enable_tpe) {
75782 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75783 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
75784 + msg = "not being in trusted group";
75785 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
75786 + msg = "being in untrusted group";
75787 +#else
75788 + if (in_group_p(grsec_tpe_gid))
75789 + msg = "being in untrusted group";
75790 +#endif
75791 + }
75792 + if (!msg && gr_acl_tpe_check())
75793 + msg = "being in untrusted role";
75794 +
75795 + // not in any affected group/role
75796 + if (!msg)
75797 + goto next_check;
75798 +
75799 + if (gr_is_global_nonroot(inode->i_uid))
75800 + msg2 = "file in non-root-owned directory";
75801 + else if (inode->i_mode & S_IWOTH)
75802 + msg2 = "file in world-writable directory";
75803 + else if (inode->i_mode & S_IWGRP)
75804 + msg2 = "file in group-writable directory";
75805 +
75806 + if (msg && msg2) {
75807 + char fullmsg[70] = {0};
75808 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
75809 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
75810 + return 0;
75811 + }
75812 + msg = NULL;
75813 +next_check:
75814 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
75815 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
75816 + return 1;
75817 +
75818 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
75819 + msg = "directory not owned by user";
75820 + else if (inode->i_mode & S_IWOTH)
75821 + msg = "file in world-writable directory";
75822 + else if (inode->i_mode & S_IWGRP)
75823 + msg = "file in group-writable directory";
75824 +
75825 + if (msg) {
75826 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
75827 + return 0;
75828 + }
75829 +#endif
75830 +#endif
75831 + return 1;
75832 +}
75833 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
75834 new file mode 100644
75835 index 0000000..ae02d8e
75836 --- /dev/null
75837 +++ b/grsecurity/grsec_usb.c
75838 @@ -0,0 +1,15 @@
75839 +#include <linux/kernel.h>
75840 +#include <linux/grinternal.h>
75841 +#include <linux/module.h>
75842 +
75843 +int gr_handle_new_usb(void)
75844 +{
75845 +#ifdef CONFIG_GRKERNSEC_DENYUSB
75846 + if (grsec_deny_new_usb) {
75847 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
75848 + return 1;
75849 + }
75850 +#endif
75851 + return 0;
75852 +}
75853 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
75854 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
75855 new file mode 100644
75856 index 0000000..9f7b1ac
75857 --- /dev/null
75858 +++ b/grsecurity/grsum.c
75859 @@ -0,0 +1,61 @@
75860 +#include <linux/err.h>
75861 +#include <linux/kernel.h>
75862 +#include <linux/sched.h>
75863 +#include <linux/mm.h>
75864 +#include <linux/scatterlist.h>
75865 +#include <linux/crypto.h>
75866 +#include <linux/gracl.h>
75867 +
75868 +
75869 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
75870 +#error "crypto and sha256 must be built into the kernel"
75871 +#endif
75872 +
75873 +int
75874 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
75875 +{
75876 + char *p;
75877 + struct crypto_hash *tfm;
75878 + struct hash_desc desc;
75879 + struct scatterlist sg;
75880 + unsigned char temp_sum[GR_SHA_LEN];
75881 + volatile int retval = 0;
75882 + volatile int dummy = 0;
75883 + unsigned int i;
75884 +
75885 + sg_init_table(&sg, 1);
75886 +
75887 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
75888 + if (IS_ERR(tfm)) {
75889 + /* should never happen, since sha256 should be built in */
75890 + return 1;
75891 + }
75892 +
75893 + desc.tfm = tfm;
75894 + desc.flags = 0;
75895 +
75896 + crypto_hash_init(&desc);
75897 +
75898 + p = salt;
75899 + sg_set_buf(&sg, p, GR_SALT_LEN);
75900 + crypto_hash_update(&desc, &sg, sg.length);
75901 +
75902 + p = entry->pw;
75903 + sg_set_buf(&sg, p, strlen(p));
75904 +
75905 + crypto_hash_update(&desc, &sg, sg.length);
75906 +
75907 + crypto_hash_final(&desc, temp_sum);
75908 +
75909 + memset(entry->pw, 0, GR_PW_LEN);
75910 +
75911 + for (i = 0; i < GR_SHA_LEN; i++)
75912 + if (sum[i] != temp_sum[i])
75913 + retval = 1;
75914 + else
75915 + dummy = 1; // waste a cycle
75916 +
75917 + crypto_free_hash(tfm);
75918 +
75919 + return retval;
75920 +}
75921 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
75922 index 77ff547..181834f 100644
75923 --- a/include/asm-generic/4level-fixup.h
75924 +++ b/include/asm-generic/4level-fixup.h
75925 @@ -13,8 +13,10 @@
75926 #define pmd_alloc(mm, pud, address) \
75927 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
75928 NULL: pmd_offset(pud, address))
75929 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
75930
75931 #define pud_alloc(mm, pgd, address) (pgd)
75932 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
75933 #define pud_offset(pgd, start) (pgd)
75934 #define pud_none(pud) 0
75935 #define pud_bad(pud) 0
75936 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
75937 index b7babf0..97f4c4f 100644
75938 --- a/include/asm-generic/atomic-long.h
75939 +++ b/include/asm-generic/atomic-long.h
75940 @@ -22,6 +22,12 @@
75941
75942 typedef atomic64_t atomic_long_t;
75943
75944 +#ifdef CONFIG_PAX_REFCOUNT
75945 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
75946 +#else
75947 +typedef atomic64_t atomic_long_unchecked_t;
75948 +#endif
75949 +
75950 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
75951
75952 static inline long atomic_long_read(atomic_long_t *l)
75953 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
75954 return (long)atomic64_read(v);
75955 }
75956
75957 +#ifdef CONFIG_PAX_REFCOUNT
75958 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
75959 +{
75960 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75961 +
75962 + return (long)atomic64_read_unchecked(v);
75963 +}
75964 +#endif
75965 +
75966 static inline void atomic_long_set(atomic_long_t *l, long i)
75967 {
75968 atomic64_t *v = (atomic64_t *)l;
75969 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
75970 atomic64_set(v, i);
75971 }
75972
75973 +#ifdef CONFIG_PAX_REFCOUNT
75974 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
75975 +{
75976 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75977 +
75978 + atomic64_set_unchecked(v, i);
75979 +}
75980 +#endif
75981 +
75982 static inline void atomic_long_inc(atomic_long_t *l)
75983 {
75984 atomic64_t *v = (atomic64_t *)l;
75985 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
75986 atomic64_inc(v);
75987 }
75988
75989 +#ifdef CONFIG_PAX_REFCOUNT
75990 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
75991 +{
75992 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75993 +
75994 + atomic64_inc_unchecked(v);
75995 +}
75996 +#endif
75997 +
75998 static inline void atomic_long_dec(atomic_long_t *l)
75999 {
76000 atomic64_t *v = (atomic64_t *)l;
76001 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76002 atomic64_dec(v);
76003 }
76004
76005 +#ifdef CONFIG_PAX_REFCOUNT
76006 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76007 +{
76008 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76009 +
76010 + atomic64_dec_unchecked(v);
76011 +}
76012 +#endif
76013 +
76014 static inline void atomic_long_add(long i, atomic_long_t *l)
76015 {
76016 atomic64_t *v = (atomic64_t *)l;
76017 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76018 atomic64_add(i, v);
76019 }
76020
76021 +#ifdef CONFIG_PAX_REFCOUNT
76022 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76023 +{
76024 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76025 +
76026 + atomic64_add_unchecked(i, v);
76027 +}
76028 +#endif
76029 +
76030 static inline void atomic_long_sub(long i, atomic_long_t *l)
76031 {
76032 atomic64_t *v = (atomic64_t *)l;
76033 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76034 atomic64_sub(i, v);
76035 }
76036
76037 +#ifdef CONFIG_PAX_REFCOUNT
76038 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76039 +{
76040 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76041 +
76042 + atomic64_sub_unchecked(i, v);
76043 +}
76044 +#endif
76045 +
76046 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76047 {
76048 atomic64_t *v = (atomic64_t *)l;
76049 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76050 return atomic64_add_negative(i, v);
76051 }
76052
76053 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
76054 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76055 {
76056 atomic64_t *v = (atomic64_t *)l;
76057
76058 return (long)atomic64_add_return(i, v);
76059 }
76060
76061 +#ifdef CONFIG_PAX_REFCOUNT
76062 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76063 +{
76064 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76065 +
76066 + return (long)atomic64_add_return_unchecked(i, v);
76067 +}
76068 +#endif
76069 +
76070 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76071 {
76072 atomic64_t *v = (atomic64_t *)l;
76073 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76074 return (long)atomic64_inc_return(v);
76075 }
76076
76077 +#ifdef CONFIG_PAX_REFCOUNT
76078 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76079 +{
76080 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76081 +
76082 + return (long)atomic64_inc_return_unchecked(v);
76083 +}
76084 +#endif
76085 +
76086 static inline long atomic_long_dec_return(atomic_long_t *l)
76087 {
76088 atomic64_t *v = (atomic64_t *)l;
76089 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76090
76091 typedef atomic_t atomic_long_t;
76092
76093 +#ifdef CONFIG_PAX_REFCOUNT
76094 +typedef atomic_unchecked_t atomic_long_unchecked_t;
76095 +#else
76096 +typedef atomic_t atomic_long_unchecked_t;
76097 +#endif
76098 +
76099 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76100 static inline long atomic_long_read(atomic_long_t *l)
76101 {
76102 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76103 return (long)atomic_read(v);
76104 }
76105
76106 +#ifdef CONFIG_PAX_REFCOUNT
76107 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76108 +{
76109 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76110 +
76111 + return (long)atomic_read_unchecked(v);
76112 +}
76113 +#endif
76114 +
76115 static inline void atomic_long_set(atomic_long_t *l, long i)
76116 {
76117 atomic_t *v = (atomic_t *)l;
76118 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76119 atomic_set(v, i);
76120 }
76121
76122 +#ifdef CONFIG_PAX_REFCOUNT
76123 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76124 +{
76125 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76126 +
76127 + atomic_set_unchecked(v, i);
76128 +}
76129 +#endif
76130 +
76131 static inline void atomic_long_inc(atomic_long_t *l)
76132 {
76133 atomic_t *v = (atomic_t *)l;
76134 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76135 atomic_inc(v);
76136 }
76137
76138 +#ifdef CONFIG_PAX_REFCOUNT
76139 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76140 +{
76141 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76142 +
76143 + atomic_inc_unchecked(v);
76144 +}
76145 +#endif
76146 +
76147 static inline void atomic_long_dec(atomic_long_t *l)
76148 {
76149 atomic_t *v = (atomic_t *)l;
76150 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76151 atomic_dec(v);
76152 }
76153
76154 +#ifdef CONFIG_PAX_REFCOUNT
76155 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76156 +{
76157 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76158 +
76159 + atomic_dec_unchecked(v);
76160 +}
76161 +#endif
76162 +
76163 static inline void atomic_long_add(long i, atomic_long_t *l)
76164 {
76165 atomic_t *v = (atomic_t *)l;
76166 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76167 atomic_add(i, v);
76168 }
76169
76170 +#ifdef CONFIG_PAX_REFCOUNT
76171 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76172 +{
76173 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76174 +
76175 + atomic_add_unchecked(i, v);
76176 +}
76177 +#endif
76178 +
76179 static inline void atomic_long_sub(long i, atomic_long_t *l)
76180 {
76181 atomic_t *v = (atomic_t *)l;
76182 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76183 atomic_sub(i, v);
76184 }
76185
76186 +#ifdef CONFIG_PAX_REFCOUNT
76187 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76188 +{
76189 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76190 +
76191 + atomic_sub_unchecked(i, v);
76192 +}
76193 +#endif
76194 +
76195 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76196 {
76197 atomic_t *v = (atomic_t *)l;
76198 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76199 return (long)atomic_add_return(i, v);
76200 }
76201
76202 +#ifdef CONFIG_PAX_REFCOUNT
76203 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76204 +{
76205 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76206 +
76207 + return (long)atomic_add_return_unchecked(i, v);
76208 +}
76209 +
76210 +#endif
76211 +
76212 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76213 {
76214 atomic_t *v = (atomic_t *)l;
76215 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76216 return (long)atomic_inc_return(v);
76217 }
76218
76219 +#ifdef CONFIG_PAX_REFCOUNT
76220 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76221 +{
76222 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76223 +
76224 + return (long)atomic_inc_return_unchecked(v);
76225 +}
76226 +#endif
76227 +
76228 static inline long atomic_long_dec_return(atomic_long_t *l)
76229 {
76230 atomic_t *v = (atomic_t *)l;
76231 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76232
76233 #endif /* BITS_PER_LONG == 64 */
76234
76235 +#ifdef CONFIG_PAX_REFCOUNT
76236 +static inline void pax_refcount_needs_these_functions(void)
76237 +{
76238 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
76239 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
76240 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
76241 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
76242 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
76243 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
76244 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
76245 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
76246 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
76247 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
76248 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
76249 +#ifdef CONFIG_X86
76250 + atomic_clear_mask_unchecked(0, NULL);
76251 + atomic_set_mask_unchecked(0, NULL);
76252 +#endif
76253 +
76254 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
76255 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
76256 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
76257 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
76258 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
76259 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
76260 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
76261 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
76262 +}
76263 +#else
76264 +#define atomic_read_unchecked(v) atomic_read(v)
76265 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
76266 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
76267 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
76268 +#define atomic_inc_unchecked(v) atomic_inc(v)
76269 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
76270 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
76271 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
76272 +#define atomic_dec_unchecked(v) atomic_dec(v)
76273 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
76274 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
76275 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
76276 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
76277 +
76278 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
76279 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
76280 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
76281 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
76282 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
76283 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
76284 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
76285 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
76286 +#endif
76287 +
76288 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
76289 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
76290 index 33bd2de..f31bff97 100644
76291 --- a/include/asm-generic/atomic.h
76292 +++ b/include/asm-generic/atomic.h
76293 @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
76294 * Atomically clears the bits set in @mask from @v
76295 */
76296 #ifndef atomic_clear_mask
76297 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
76298 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
76299 {
76300 unsigned long flags;
76301
76302 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
76303 index b18ce4f..2ee2843 100644
76304 --- a/include/asm-generic/atomic64.h
76305 +++ b/include/asm-generic/atomic64.h
76306 @@ -16,6 +16,8 @@ typedef struct {
76307 long long counter;
76308 } atomic64_t;
76309
76310 +typedef atomic64_t atomic64_unchecked_t;
76311 +
76312 #define ATOMIC64_INIT(i) { (i) }
76313
76314 extern long long atomic64_read(const atomic64_t *v);
76315 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
76316 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
76317 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
76318
76319 +#define atomic64_read_unchecked(v) atomic64_read(v)
76320 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
76321 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
76322 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
76323 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
76324 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
76325 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
76326 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
76327 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
76328 +
76329 #endif /* _ASM_GENERIC_ATOMIC64_H */
76330 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
76331 index a60a7cc..0fe12f2 100644
76332 --- a/include/asm-generic/bitops/__fls.h
76333 +++ b/include/asm-generic/bitops/__fls.h
76334 @@ -9,7 +9,7 @@
76335 *
76336 * Undefined if no set bit exists, so code should check against 0 first.
76337 */
76338 -static __always_inline unsigned long __fls(unsigned long word)
76339 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
76340 {
76341 int num = BITS_PER_LONG - 1;
76342
76343 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
76344 index 0576d1f..dad6c71 100644
76345 --- a/include/asm-generic/bitops/fls.h
76346 +++ b/include/asm-generic/bitops/fls.h
76347 @@ -9,7 +9,7 @@
76348 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
76349 */
76350
76351 -static __always_inline int fls(int x)
76352 +static __always_inline int __intentional_overflow(-1) fls(int x)
76353 {
76354 int r = 32;
76355
76356 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
76357 index b097cf8..3d40e14 100644
76358 --- a/include/asm-generic/bitops/fls64.h
76359 +++ b/include/asm-generic/bitops/fls64.h
76360 @@ -15,7 +15,7 @@
76361 * at position 64.
76362 */
76363 #if BITS_PER_LONG == 32
76364 -static __always_inline int fls64(__u64 x)
76365 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76366 {
76367 __u32 h = x >> 32;
76368 if (h)
76369 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
76370 return fls(x);
76371 }
76372 #elif BITS_PER_LONG == 64
76373 -static __always_inline int fls64(__u64 x)
76374 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76375 {
76376 if (x == 0)
76377 return 0;
76378 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
76379 index 1bfcfe5..e04c5c9 100644
76380 --- a/include/asm-generic/cache.h
76381 +++ b/include/asm-generic/cache.h
76382 @@ -6,7 +6,7 @@
76383 * cache lines need to provide their own cache.h.
76384 */
76385
76386 -#define L1_CACHE_SHIFT 5
76387 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
76388 +#define L1_CACHE_SHIFT 5UL
76389 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
76390
76391 #endif /* __ASM_GENERIC_CACHE_H */
76392 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
76393 index 0d68a1e..b74a761 100644
76394 --- a/include/asm-generic/emergency-restart.h
76395 +++ b/include/asm-generic/emergency-restart.h
76396 @@ -1,7 +1,7 @@
76397 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
76398 #define _ASM_GENERIC_EMERGENCY_RESTART_H
76399
76400 -static inline void machine_emergency_restart(void)
76401 +static inline __noreturn void machine_emergency_restart(void)
76402 {
76403 machine_restart(NULL);
76404 }
76405 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
76406 index 90f99c7..00ce236 100644
76407 --- a/include/asm-generic/kmap_types.h
76408 +++ b/include/asm-generic/kmap_types.h
76409 @@ -2,9 +2,9 @@
76410 #define _ASM_GENERIC_KMAP_TYPES_H
76411
76412 #ifdef __WITH_KM_FENCE
76413 -# define KM_TYPE_NR 41
76414 +# define KM_TYPE_NR 42
76415 #else
76416 -# define KM_TYPE_NR 20
76417 +# define KM_TYPE_NR 21
76418 #endif
76419
76420 #endif
76421 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
76422 index 9ceb03b..62b0b8f 100644
76423 --- a/include/asm-generic/local.h
76424 +++ b/include/asm-generic/local.h
76425 @@ -23,24 +23,37 @@ typedef struct
76426 atomic_long_t a;
76427 } local_t;
76428
76429 +typedef struct {
76430 + atomic_long_unchecked_t a;
76431 +} local_unchecked_t;
76432 +
76433 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
76434
76435 #define local_read(l) atomic_long_read(&(l)->a)
76436 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
76437 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
76438 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
76439 #define local_inc(l) atomic_long_inc(&(l)->a)
76440 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
76441 #define local_dec(l) atomic_long_dec(&(l)->a)
76442 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
76443 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
76444 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
76445 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
76446 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
76447
76448 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
76449 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
76450 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
76451 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
76452 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
76453 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
76454 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
76455 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
76456 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
76457
76458 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76459 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76460 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
76461 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
76462 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
76463 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
76464 index 725612b..9cc513a 100644
76465 --- a/include/asm-generic/pgtable-nopmd.h
76466 +++ b/include/asm-generic/pgtable-nopmd.h
76467 @@ -1,14 +1,19 @@
76468 #ifndef _PGTABLE_NOPMD_H
76469 #define _PGTABLE_NOPMD_H
76470
76471 -#ifndef __ASSEMBLY__
76472 -
76473 #include <asm-generic/pgtable-nopud.h>
76474
76475 -struct mm_struct;
76476 -
76477 #define __PAGETABLE_PMD_FOLDED
76478
76479 +#define PMD_SHIFT PUD_SHIFT
76480 +#define PTRS_PER_PMD 1
76481 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
76482 +#define PMD_MASK (~(PMD_SIZE-1))
76483 +
76484 +#ifndef __ASSEMBLY__
76485 +
76486 +struct mm_struct;
76487 +
76488 /*
76489 * Having the pmd type consist of a pud gets the size right, and allows
76490 * us to conceptually access the pud entry that this pmd is folded into
76491 @@ -16,11 +21,6 @@ struct mm_struct;
76492 */
76493 typedef struct { pud_t pud; } pmd_t;
76494
76495 -#define PMD_SHIFT PUD_SHIFT
76496 -#define PTRS_PER_PMD 1
76497 -#define PMD_SIZE (1UL << PMD_SHIFT)
76498 -#define PMD_MASK (~(PMD_SIZE-1))
76499 -
76500 /*
76501 * The "pud_xxx()" functions here are trivial for a folded two-level
76502 * setup: the pmd is never bad, and a pmd always exists (as it's folded
76503 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
76504 index 810431d..0ec4804f 100644
76505 --- a/include/asm-generic/pgtable-nopud.h
76506 +++ b/include/asm-generic/pgtable-nopud.h
76507 @@ -1,10 +1,15 @@
76508 #ifndef _PGTABLE_NOPUD_H
76509 #define _PGTABLE_NOPUD_H
76510
76511 -#ifndef __ASSEMBLY__
76512 -
76513 #define __PAGETABLE_PUD_FOLDED
76514
76515 +#define PUD_SHIFT PGDIR_SHIFT
76516 +#define PTRS_PER_PUD 1
76517 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
76518 +#define PUD_MASK (~(PUD_SIZE-1))
76519 +
76520 +#ifndef __ASSEMBLY__
76521 +
76522 /*
76523 * Having the pud type consist of a pgd gets the size right, and allows
76524 * us to conceptually access the pgd entry that this pud is folded into
76525 @@ -12,11 +17,6 @@
76526 */
76527 typedef struct { pgd_t pgd; } pud_t;
76528
76529 -#define PUD_SHIFT PGDIR_SHIFT
76530 -#define PTRS_PER_PUD 1
76531 -#define PUD_SIZE (1UL << PUD_SHIFT)
76532 -#define PUD_MASK (~(PUD_SIZE-1))
76533 -
76534 /*
76535 * The "pgd_xxx()" functions here are trivial for a folded two-level
76536 * setup: the pud is never bad, and a pud always exists (as it's folded
76537 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
76538 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
76539
76540 #define pgd_populate(mm, pgd, pud) do { } while (0)
76541 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
76542 /*
76543 * (puds are folded into pgds so this doesn't get actually called,
76544 * but the define is needed for a generic inline function.)
76545 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
76546 index 34c7bdc..38d4f3b 100644
76547 --- a/include/asm-generic/pgtable.h
76548 +++ b/include/asm-generic/pgtable.h
76549 @@ -787,6 +787,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
76550 }
76551 #endif /* CONFIG_NUMA_BALANCING */
76552
76553 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
76554 +#ifdef CONFIG_PAX_KERNEXEC
76555 +#error KERNEXEC requires pax_open_kernel
76556 +#else
76557 +static inline unsigned long pax_open_kernel(void) { return 0; }
76558 +#endif
76559 +#endif
76560 +
76561 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
76562 +#ifdef CONFIG_PAX_KERNEXEC
76563 +#error KERNEXEC requires pax_close_kernel
76564 +#else
76565 +static inline unsigned long pax_close_kernel(void) { return 0; }
76566 +#endif
76567 +#endif
76568 +
76569 #endif /* CONFIG_MMU */
76570
76571 #endif /* !__ASSEMBLY__ */
76572 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
76573 index 72d8803..cb9749c 100644
76574 --- a/include/asm-generic/uaccess.h
76575 +++ b/include/asm-generic/uaccess.h
76576 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
76577 return __clear_user(to, n);
76578 }
76579
76580 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
76581 +#ifdef CONFIG_PAX_MEMORY_UDEREF
76582 +#error UDEREF requires pax_open_userland
76583 +#else
76584 +static inline unsigned long pax_open_userland(void) { return 0; }
76585 +#endif
76586 +#endif
76587 +
76588 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
76589 +#ifdef CONFIG_PAX_MEMORY_UDEREF
76590 +#error UDEREF requires pax_close_userland
76591 +#else
76592 +static inline unsigned long pax_close_userland(void) { return 0; }
76593 +#endif
76594 +#endif
76595 +
76596 #endif /* __ASM_GENERIC_UACCESS_H */
76597 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
76598 index bc2121f..2f41f9a 100644
76599 --- a/include/asm-generic/vmlinux.lds.h
76600 +++ b/include/asm-generic/vmlinux.lds.h
76601 @@ -232,6 +232,7 @@
76602 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
76603 VMLINUX_SYMBOL(__start_rodata) = .; \
76604 *(.rodata) *(.rodata.*) \
76605 + *(.data..read_only) \
76606 *(__vermagic) /* Kernel version magic */ \
76607 . = ALIGN(8); \
76608 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
76609 @@ -716,17 +717,18 @@
76610 * section in the linker script will go there too. @phdr should have
76611 * a leading colon.
76612 *
76613 - * Note that this macros defines __per_cpu_load as an absolute symbol.
76614 + * Note that this macros defines per_cpu_load as an absolute symbol.
76615 * If there is no need to put the percpu section at a predetermined
76616 * address, use PERCPU_SECTION.
76617 */
76618 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
76619 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
76620 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
76621 + per_cpu_load = .; \
76622 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
76623 - LOAD_OFFSET) { \
76624 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
76625 PERCPU_INPUT(cacheline) \
76626 } phdr \
76627 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
76628 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
76629
76630 /**
76631 * PERCPU_SECTION - define output section for percpu area, simple version
76632 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
76633 index e73c19e..5b89e00 100644
76634 --- a/include/crypto/algapi.h
76635 +++ b/include/crypto/algapi.h
76636 @@ -34,7 +34,7 @@ struct crypto_type {
76637 unsigned int maskclear;
76638 unsigned int maskset;
76639 unsigned int tfmsize;
76640 -};
76641 +} __do_const;
76642
76643 struct crypto_instance {
76644 struct crypto_alg alg;
76645 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
76646 index 04a7f31..668d424 100644
76647 --- a/include/drm/drmP.h
76648 +++ b/include/drm/drmP.h
76649 @@ -67,6 +67,7 @@
76650 #include <linux/workqueue.h>
76651 #include <linux/poll.h>
76652 #include <asm/pgalloc.h>
76653 +#include <asm/local.h>
76654 #include <drm/drm.h>
76655 #include <drm/drm_sarea.h>
76656 #include <drm/drm_vma_manager.h>
76657 @@ -297,10 +298,12 @@ do { \
76658 * \param cmd command.
76659 * \param arg argument.
76660 */
76661 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
76662 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
76663 + struct drm_file *file_priv);
76664 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
76665 struct drm_file *file_priv);
76666
76667 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76668 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
76669 unsigned long arg);
76670
76671 #define DRM_IOCTL_NR(n) _IOC_NR(n)
76672 @@ -316,10 +319,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76673 struct drm_ioctl_desc {
76674 unsigned int cmd;
76675 int flags;
76676 - drm_ioctl_t *func;
76677 + drm_ioctl_t func;
76678 unsigned int cmd_drv;
76679 const char *name;
76680 -};
76681 +} __do_const;
76682
76683 /**
76684 * Creates a driver or general drm_ioctl_desc array entry for the given
76685 @@ -1022,7 +1025,8 @@ struct drm_info_list {
76686 int (*show)(struct seq_file*, void*); /** show callback */
76687 u32 driver_features; /**< Required driver features for this entry */
76688 void *data;
76689 -};
76690 +} __do_const;
76691 +typedef struct drm_info_list __no_const drm_info_list_no_const;
76692
76693 /**
76694 * debugfs node structure. This structure represents a debugfs file.
76695 @@ -1106,7 +1110,7 @@ struct drm_device {
76696
76697 /** \name Usage Counters */
76698 /*@{ */
76699 - int open_count; /**< Outstanding files open */
76700 + local_t open_count; /**< Outstanding files open */
76701 int buf_use; /**< Buffers in use -- cannot alloc */
76702 atomic_t buf_alloc; /**< Buffer allocation in progress */
76703 /*@} */
76704 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
76705 index b1388b5..e1d1163 100644
76706 --- a/include/drm/drm_crtc_helper.h
76707 +++ b/include/drm/drm_crtc_helper.h
76708 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
76709 struct drm_connector *connector);
76710 /* disable encoder when not in use - more explicit than dpms off */
76711 void (*disable)(struct drm_encoder *encoder);
76712 -};
76713 +} __no_const;
76714
76715 /**
76716 * drm_connector_helper_funcs - helper operations for connectors
76717 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
76718 index 940ece4..8cb727f 100644
76719 --- a/include/drm/i915_pciids.h
76720 +++ b/include/drm/i915_pciids.h
76721 @@ -37,7 +37,7 @@
76722 */
76723 #define INTEL_VGA_DEVICE(id, info) { \
76724 0x8086, id, \
76725 - ~0, ~0, \
76726 + PCI_ANY_ID, PCI_ANY_ID, \
76727 0x030000, 0xff0000, \
76728 (unsigned long) info }
76729
76730 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
76731 index 72dcbe8..8db58d7 100644
76732 --- a/include/drm/ttm/ttm_memory.h
76733 +++ b/include/drm/ttm/ttm_memory.h
76734 @@ -48,7 +48,7 @@
76735
76736 struct ttm_mem_shrink {
76737 int (*do_shrink) (struct ttm_mem_shrink *);
76738 -};
76739 +} __no_const;
76740
76741 /**
76742 * struct ttm_mem_global - Global memory accounting structure.
76743 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
76744 index 49a8284..9643967 100644
76745 --- a/include/drm/ttm/ttm_page_alloc.h
76746 +++ b/include/drm/ttm/ttm_page_alloc.h
76747 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
76748 */
76749 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
76750
76751 +struct device;
76752 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
76753 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
76754
76755 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
76756 index 4b840e8..155d235 100644
76757 --- a/include/keys/asymmetric-subtype.h
76758 +++ b/include/keys/asymmetric-subtype.h
76759 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
76760 /* Verify the signature on a key of this subtype (optional) */
76761 int (*verify_signature)(const struct key *key,
76762 const struct public_key_signature *sig);
76763 -};
76764 +} __do_const;
76765
76766 /**
76767 * asymmetric_key_subtype - Get the subtype from an asymmetric key
76768 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
76769 index c1da539..1dcec55 100644
76770 --- a/include/linux/atmdev.h
76771 +++ b/include/linux/atmdev.h
76772 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
76773 #endif
76774
76775 struct k_atm_aal_stats {
76776 -#define __HANDLE_ITEM(i) atomic_t i
76777 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
76778 __AAL_STAT_ITEMS
76779 #undef __HANDLE_ITEM
76780 };
76781 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
76782 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
76783 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
76784 struct module *owner;
76785 -};
76786 +} __do_const ;
76787
76788 struct atmphy_ops {
76789 int (*start)(struct atm_dev *dev);
76790 diff --git a/include/linux/audit.h b/include/linux/audit.h
76791 index ec1464d..833274b 100644
76792 --- a/include/linux/audit.h
76793 +++ b/include/linux/audit.h
76794 @@ -196,7 +196,7 @@ static inline void audit_ptrace(struct task_struct *t)
76795 extern unsigned int audit_serial(void);
76796 extern int auditsc_get_stamp(struct audit_context *ctx,
76797 struct timespec *t, unsigned int *serial);
76798 -extern int audit_set_loginuid(kuid_t loginuid);
76799 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
76800
76801 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
76802 {
76803 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
76804 index b4a745d..e3c0942 100644
76805 --- a/include/linux/binfmts.h
76806 +++ b/include/linux/binfmts.h
76807 @@ -45,7 +45,7 @@ struct linux_binprm {
76808 unsigned interp_data;
76809 unsigned long loader, exec;
76810 char tcomm[TASK_COMM_LEN];
76811 -};
76812 +} __randomize_layout;
76813
76814 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
76815 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
76816 @@ -74,8 +74,10 @@ struct linux_binfmt {
76817 int (*load_binary)(struct linux_binprm *);
76818 int (*load_shlib)(struct file *);
76819 int (*core_dump)(struct coredump_params *cprm);
76820 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
76821 + void (*handle_mmap)(struct file *);
76822 unsigned long min_coredump; /* minimal dump size */
76823 -};
76824 +} __do_const __randomize_layout;
76825
76826 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
76827
76828 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
76829 index be5fd38..d71192a 100644
76830 --- a/include/linux/bitops.h
76831 +++ b/include/linux/bitops.h
76832 @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
76833 * @word: value to rotate
76834 * @shift: bits to roll
76835 */
76836 -static inline __u32 rol32(__u32 word, unsigned int shift)
76837 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
76838 {
76839 return (word << shift) | (word >> (32 - shift));
76840 }
76841 @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
76842 * @word: value to rotate
76843 * @shift: bits to roll
76844 */
76845 -static inline __u32 ror32(__u32 word, unsigned int shift)
76846 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
76847 {
76848 return (word >> shift) | (word << (32 - shift));
76849 }
76850 @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
76851 return (__s32)(value << shift) >> shift;
76852 }
76853
76854 -static inline unsigned fls_long(unsigned long l)
76855 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
76856 {
76857 if (sizeof(l) == 4)
76858 return fls(l);
76859 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
76860 index 4afa4f8..1ed7824 100644
76861 --- a/include/linux/blkdev.h
76862 +++ b/include/linux/blkdev.h
76863 @@ -1572,7 +1572,7 @@ struct block_device_operations {
76864 /* this callback is with swap_lock and sometimes page table lock held */
76865 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
76866 struct module *owner;
76867 -};
76868 +} __do_const;
76869
76870 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
76871 unsigned long);
76872 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
76873 index afc1343..9735539 100644
76874 --- a/include/linux/blktrace_api.h
76875 +++ b/include/linux/blktrace_api.h
76876 @@ -25,7 +25,7 @@ struct blk_trace {
76877 struct dentry *dropped_file;
76878 struct dentry *msg_file;
76879 struct list_head running_list;
76880 - atomic_t dropped;
76881 + atomic_unchecked_t dropped;
76882 };
76883
76884 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
76885 diff --git a/include/linux/cache.h b/include/linux/cache.h
76886 index 17e7e82..1d7da26 100644
76887 --- a/include/linux/cache.h
76888 +++ b/include/linux/cache.h
76889 @@ -16,6 +16,14 @@
76890 #define __read_mostly
76891 #endif
76892
76893 +#ifndef __read_only
76894 +#ifdef CONFIG_PAX_KERNEXEC
76895 +#error KERNEXEC requires __read_only
76896 +#else
76897 +#define __read_only __read_mostly
76898 +#endif
76899 +#endif
76900 +
76901 #ifndef ____cacheline_aligned
76902 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
76903 #endif
76904 diff --git a/include/linux/capability.h b/include/linux/capability.h
76905 index a6ee1f9..e1ca49d 100644
76906 --- a/include/linux/capability.h
76907 +++ b/include/linux/capability.h
76908 @@ -212,8 +212,13 @@ extern bool capable(int cap);
76909 extern bool ns_capable(struct user_namespace *ns, int cap);
76910 extern bool inode_capable(const struct inode *inode, int cap);
76911 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
76912 +extern bool capable_nolog(int cap);
76913 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
76914 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
76915
76916 /* audit system wants to get cap info from files as well */
76917 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
76918
76919 +extern int is_privileged_binary(const struct dentry *dentry);
76920 +
76921 #endif /* !_LINUX_CAPABILITY_H */
76922 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
76923 index 8609d57..86e4d79 100644
76924 --- a/include/linux/cdrom.h
76925 +++ b/include/linux/cdrom.h
76926 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
76927
76928 /* driver specifications */
76929 const int capability; /* capability flags */
76930 - int n_minors; /* number of active minor devices */
76931 /* handle uniform packets for scsi type devices (scsi,atapi) */
76932 int (*generic_packet) (struct cdrom_device_info *,
76933 struct packet_command *);
76934 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
76935 index 4ce9056..86caac6 100644
76936 --- a/include/linux/cleancache.h
76937 +++ b/include/linux/cleancache.h
76938 @@ -31,7 +31,7 @@ struct cleancache_ops {
76939 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
76940 void (*invalidate_inode)(int, struct cleancache_filekey);
76941 void (*invalidate_fs)(int);
76942 -};
76943 +} __no_const;
76944
76945 extern struct cleancache_ops *
76946 cleancache_register_ops(struct cleancache_ops *ops);
76947 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
76948 index 939533d..cf0a57c 100644
76949 --- a/include/linux/clk-provider.h
76950 +++ b/include/linux/clk-provider.h
76951 @@ -166,6 +166,7 @@ struct clk_ops {
76952 unsigned long parent_accuracy);
76953 void (*init)(struct clk_hw *hw);
76954 };
76955 +typedef struct clk_ops __no_const clk_ops_no_const;
76956
76957 /**
76958 * struct clk_init_data - holds init data that's common to all clocks and is
76959 diff --git a/include/linux/compat.h b/include/linux/compat.h
76960 index 3f448c6..df3ce1d 100644
76961 --- a/include/linux/compat.h
76962 +++ b/include/linux/compat.h
76963 @@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
76964 compat_size_t __user *len_ptr);
76965
76966 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
76967 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
76968 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
76969 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
76970 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
76971 compat_ssize_t msgsz, int msgflg);
76972 @@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
76973 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
76974 compat_ulong_t addr, compat_ulong_t data);
76975 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
76976 - compat_long_t addr, compat_long_t data);
76977 + compat_ulong_t addr, compat_ulong_t data);
76978
76979 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
76980 /*
76981 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
76982 index 2507fd2..55203f8 100644
76983 --- a/include/linux/compiler-gcc4.h
76984 +++ b/include/linux/compiler-gcc4.h
76985 @@ -39,9 +39,34 @@
76986 # define __compiletime_warning(message) __attribute__((warning(message)))
76987 # define __compiletime_error(message) __attribute__((error(message)))
76988 #endif /* __CHECKER__ */
76989 +
76990 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
76991 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
76992 +#define __bos0(ptr) __bos((ptr), 0)
76993 +#define __bos1(ptr) __bos((ptr), 1)
76994 #endif /* GCC_VERSION >= 40300 */
76995
76996 #if GCC_VERSION >= 40500
76997 +
76998 +#ifdef RANDSTRUCT_PLUGIN
76999 +#define __randomize_layout __attribute__((randomize_layout))
77000 +#define __no_randomize_layout __attribute__((no_randomize_layout))
77001 +#endif
77002 +
77003 +#ifdef CONSTIFY_PLUGIN
77004 +#define __no_const __attribute__((no_const))
77005 +#define __do_const __attribute__((do_const))
77006 +#endif
77007 +
77008 +#ifdef SIZE_OVERFLOW_PLUGIN
77009 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77010 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77011 +#endif
77012 +
77013 +#ifdef LATENT_ENTROPY_PLUGIN
77014 +#define __latent_entropy __attribute__((latent_entropy))
77015 +#endif
77016 +
77017 /*
77018 * Mark a position in code as unreachable. This can be used to
77019 * suppress control flow warnings after asm blocks that transfer
77020 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77021 index 2472740..4857634 100644
77022 --- a/include/linux/compiler.h
77023 +++ b/include/linux/compiler.h
77024 @@ -5,11 +5,14 @@
77025
77026 #ifdef __CHECKER__
77027 # define __user __attribute__((noderef, address_space(1)))
77028 +# define __force_user __force __user
77029 # define __kernel __attribute__((address_space(0)))
77030 +# define __force_kernel __force __kernel
77031 # define __safe __attribute__((safe))
77032 # define __force __attribute__((force))
77033 # define __nocast __attribute__((nocast))
77034 # define __iomem __attribute__((noderef, address_space(2)))
77035 +# define __force_iomem __force __iomem
77036 # define __must_hold(x) __attribute__((context(x,1,1)))
77037 # define __acquires(x) __attribute__((context(x,0,1)))
77038 # define __releases(x) __attribute__((context(x,1,0)))
77039 @@ -17,20 +20,37 @@
77040 # define __release(x) __context__(x,-1)
77041 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77042 # define __percpu __attribute__((noderef, address_space(3)))
77043 +# define __force_percpu __force __percpu
77044 #ifdef CONFIG_SPARSE_RCU_POINTER
77045 # define __rcu __attribute__((noderef, address_space(4)))
77046 +# define __force_rcu __force __rcu
77047 #else
77048 # define __rcu
77049 +# define __force_rcu
77050 #endif
77051 extern void __chk_user_ptr(const volatile void __user *);
77052 extern void __chk_io_ptr(const volatile void __iomem *);
77053 #else
77054 -# define __user
77055 -# define __kernel
77056 +# ifdef CHECKER_PLUGIN
77057 +//# define __user
77058 +//# define __force_user
77059 +//# define __kernel
77060 +//# define __force_kernel
77061 +# else
77062 +# ifdef STRUCTLEAK_PLUGIN
77063 +# define __user __attribute__((user))
77064 +# else
77065 +# define __user
77066 +# endif
77067 +# define __force_user
77068 +# define __kernel
77069 +# define __force_kernel
77070 +# endif
77071 # define __safe
77072 # define __force
77073 # define __nocast
77074 # define __iomem
77075 +# define __force_iomem
77076 # define __chk_user_ptr(x) (void)0
77077 # define __chk_io_ptr(x) (void)0
77078 # define __builtin_warning(x, y...) (1)
77079 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77080 # define __release(x) (void)0
77081 # define __cond_lock(x,c) (c)
77082 # define __percpu
77083 +# define __force_percpu
77084 # define __rcu
77085 +# define __force_rcu
77086 #endif
77087
77088 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77089 @@ -279,6 +301,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77090 # define __attribute_const__ /* unimplemented */
77091 #endif
77092
77093 +#ifndef __randomize_layout
77094 +# define __randomize_layout
77095 +#endif
77096 +
77097 +#ifndef __no_randomize_layout
77098 +# define __no_randomize_layout
77099 +#endif
77100 +
77101 +#ifndef __no_const
77102 +# define __no_const
77103 +#endif
77104 +
77105 +#ifndef __do_const
77106 +# define __do_const
77107 +#endif
77108 +
77109 +#ifndef __size_overflow
77110 +# define __size_overflow(...)
77111 +#endif
77112 +
77113 +#ifndef __intentional_overflow
77114 +# define __intentional_overflow(...)
77115 +#endif
77116 +
77117 +#ifndef __latent_entropy
77118 +# define __latent_entropy
77119 +#endif
77120 +
77121 /*
77122 * Tell gcc if a function is cold. The compiler will assume any path
77123 * directly leading to the call is unlikely.
77124 @@ -288,6 +338,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77125 #define __cold
77126 #endif
77127
77128 +#ifndef __alloc_size
77129 +#define __alloc_size(...)
77130 +#endif
77131 +
77132 +#ifndef __bos
77133 +#define __bos(ptr, arg)
77134 +#endif
77135 +
77136 +#ifndef __bos0
77137 +#define __bos0(ptr)
77138 +#endif
77139 +
77140 +#ifndef __bos1
77141 +#define __bos1(ptr)
77142 +#endif
77143 +
77144 /* Simple shorthand for a section definition */
77145 #ifndef __section
77146 # define __section(S) __attribute__ ((__section__(#S)))
77147 @@ -362,7 +428,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77148 * use is to mediate communication between process-level code and irq/NMI
77149 * handlers, all running on the same CPU.
77150 */
77151 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77152 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77153 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77154
77155 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77156 #ifdef CONFIG_KPROBES
77157 diff --git a/include/linux/completion.h b/include/linux/completion.h
77158 index 5d5aaae..0ea9b84 100644
77159 --- a/include/linux/completion.h
77160 +++ b/include/linux/completion.h
77161 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77162
77163 extern void wait_for_completion(struct completion *);
77164 extern void wait_for_completion_io(struct completion *);
77165 -extern int wait_for_completion_interruptible(struct completion *x);
77166 -extern int wait_for_completion_killable(struct completion *x);
77167 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77168 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77169 extern unsigned long wait_for_completion_timeout(struct completion *x,
77170 - unsigned long timeout);
77171 + unsigned long timeout) __intentional_overflow(-1);
77172 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77173 - unsigned long timeout);
77174 + unsigned long timeout) __intentional_overflow(-1);
77175 extern long wait_for_completion_interruptible_timeout(
77176 - struct completion *x, unsigned long timeout);
77177 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77178 extern long wait_for_completion_killable_timeout(
77179 - struct completion *x, unsigned long timeout);
77180 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77181 extern bool try_wait_for_completion(struct completion *x);
77182 extern bool completion_done(struct completion *x);
77183
77184 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
77185 index 34025df..d94bbbc 100644
77186 --- a/include/linux/configfs.h
77187 +++ b/include/linux/configfs.h
77188 @@ -125,7 +125,7 @@ struct configfs_attribute {
77189 const char *ca_name;
77190 struct module *ca_owner;
77191 umode_t ca_mode;
77192 -};
77193 +} __do_const;
77194
77195 /*
77196 * Users often need to create attribute structures for their configurable
77197 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
77198 index 4d89e0e..5281847 100644
77199 --- a/include/linux/cpufreq.h
77200 +++ b/include/linux/cpufreq.h
77201 @@ -191,6 +191,7 @@ struct global_attr {
77202 ssize_t (*store)(struct kobject *a, struct attribute *b,
77203 const char *c, size_t count);
77204 };
77205 +typedef struct global_attr __no_const global_attr_no_const;
77206
77207 #define define_one_global_ro(_name) \
77208 static struct global_attr _name = \
77209 @@ -232,7 +233,7 @@ struct cpufreq_driver {
77210 bool boost_supported;
77211 bool boost_enabled;
77212 int (*set_boost) (int state);
77213 -};
77214 +} __do_const;
77215
77216 /* flags */
77217 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
77218 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
77219 index 50fcbb0..9d2dbd9 100644
77220 --- a/include/linux/cpuidle.h
77221 +++ b/include/linux/cpuidle.h
77222 @@ -50,7 +50,8 @@ struct cpuidle_state {
77223 int index);
77224
77225 int (*enter_dead) (struct cpuidle_device *dev, int index);
77226 -};
77227 +} __do_const;
77228 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
77229
77230 /* Idle State Flags */
77231 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
77232 @@ -192,7 +193,7 @@ struct cpuidle_governor {
77233 void (*reflect) (struct cpuidle_device *dev, int index);
77234
77235 struct module *owner;
77236 -};
77237 +} __do_const;
77238
77239 #ifdef CONFIG_CPU_IDLE
77240 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
77241 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
77242 index d08e4d2..95fad61 100644
77243 --- a/include/linux/cpumask.h
77244 +++ b/include/linux/cpumask.h
77245 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77246 }
77247
77248 /* Valid inputs for n are -1 and 0. */
77249 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77250 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77251 {
77252 return n+1;
77253 }
77254
77255 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77256 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77257 {
77258 return n+1;
77259 }
77260
77261 -static inline unsigned int cpumask_next_and(int n,
77262 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
77263 const struct cpumask *srcp,
77264 const struct cpumask *andp)
77265 {
77266 @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77267 *
77268 * Returns >= nr_cpu_ids if no further cpus set.
77269 */
77270 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77271 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77272 {
77273 /* -1 is a legal arg here. */
77274 if (n != -1)
77275 @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77276 *
77277 * Returns >= nr_cpu_ids if no further cpus unset.
77278 */
77279 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77280 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77281 {
77282 /* -1 is a legal arg here. */
77283 if (n != -1)
77284 @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77285 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
77286 }
77287
77288 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
77289 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
77290 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
77291
77292 /**
77293 diff --git a/include/linux/cred.h b/include/linux/cred.h
77294 index 04421e8..117e17a 100644
77295 --- a/include/linux/cred.h
77296 +++ b/include/linux/cred.h
77297 @@ -35,7 +35,7 @@ struct group_info {
77298 int nblocks;
77299 kgid_t small_block[NGROUPS_SMALL];
77300 kgid_t *blocks[0];
77301 -};
77302 +} __randomize_layout;
77303
77304 /**
77305 * get_group_info - Get a reference to a group info structure
77306 @@ -136,7 +136,7 @@ struct cred {
77307 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
77308 struct group_info *group_info; /* supplementary groups for euid/fsgid */
77309 struct rcu_head rcu; /* RCU deletion hook */
77310 -};
77311 +} __randomize_layout;
77312
77313 extern void __put_cred(struct cred *);
77314 extern void exit_creds(struct task_struct *);
77315 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
77316 static inline void validate_process_creds(void)
77317 {
77318 }
77319 +static inline void validate_task_creds(struct task_struct *task)
77320 +{
77321 +}
77322 #endif
77323
77324 /**
77325 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
77326 index b92eadf..b4ecdc1 100644
77327 --- a/include/linux/crypto.h
77328 +++ b/include/linux/crypto.h
77329 @@ -373,7 +373,7 @@ struct cipher_tfm {
77330 const u8 *key, unsigned int keylen);
77331 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77332 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77333 -};
77334 +} __no_const;
77335
77336 struct hash_tfm {
77337 int (*init)(struct hash_desc *desc);
77338 @@ -394,13 +394,13 @@ struct compress_tfm {
77339 int (*cot_decompress)(struct crypto_tfm *tfm,
77340 const u8 *src, unsigned int slen,
77341 u8 *dst, unsigned int *dlen);
77342 -};
77343 +} __no_const;
77344
77345 struct rng_tfm {
77346 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
77347 unsigned int dlen);
77348 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
77349 -};
77350 +} __no_const;
77351
77352 #define crt_ablkcipher crt_u.ablkcipher
77353 #define crt_aead crt_u.aead
77354 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
77355 index 653589e..4ef254a 100644
77356 --- a/include/linux/ctype.h
77357 +++ b/include/linux/ctype.h
77358 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
77359 * Fast implementation of tolower() for internal usage. Do not use in your
77360 * code.
77361 */
77362 -static inline char _tolower(const char c)
77363 +static inline unsigned char _tolower(const unsigned char c)
77364 {
77365 return c | 0x20;
77366 }
77367 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
77368 index bf72e9a..4ca7927 100644
77369 --- a/include/linux/dcache.h
77370 +++ b/include/linux/dcache.h
77371 @@ -133,7 +133,7 @@ struct dentry {
77372 } d_u;
77373 struct list_head d_subdirs; /* our children */
77374 struct hlist_node d_alias; /* inode alias list */
77375 -};
77376 +} __randomize_layout;
77377
77378 /*
77379 * dentry->d_lock spinlock nesting subclasses:
77380 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
77381 index 7925bf0..d5143d2 100644
77382 --- a/include/linux/decompress/mm.h
77383 +++ b/include/linux/decompress/mm.h
77384 @@ -77,7 +77,7 @@ static void free(void *where)
77385 * warnings when not needed (indeed large_malloc / large_free are not
77386 * needed by inflate */
77387
77388 -#define malloc(a) kmalloc(a, GFP_KERNEL)
77389 +#define malloc(a) kmalloc((a), GFP_KERNEL)
77390 #define free(a) kfree(a)
77391
77392 #define large_malloc(a) vmalloc(a)
77393 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
77394 index d48dc00..211ee54 100644
77395 --- a/include/linux/devfreq.h
77396 +++ b/include/linux/devfreq.h
77397 @@ -114,7 +114,7 @@ struct devfreq_governor {
77398 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
77399 int (*event_handler)(struct devfreq *devfreq,
77400 unsigned int event, void *data);
77401 -};
77402 +} __do_const;
77403
77404 /**
77405 * struct devfreq - Device devfreq structure
77406 diff --git a/include/linux/device.h b/include/linux/device.h
77407 index 952b010..d5b7691 100644
77408 --- a/include/linux/device.h
77409 +++ b/include/linux/device.h
77410 @@ -310,7 +310,7 @@ struct subsys_interface {
77411 struct list_head node;
77412 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
77413 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
77414 -};
77415 +} __do_const;
77416
77417 int subsys_interface_register(struct subsys_interface *sif);
77418 void subsys_interface_unregister(struct subsys_interface *sif);
77419 @@ -506,7 +506,7 @@ struct device_type {
77420 void (*release)(struct device *dev);
77421
77422 const struct dev_pm_ops *pm;
77423 -};
77424 +} __do_const;
77425
77426 /* interface for exporting device attributes */
77427 struct device_attribute {
77428 @@ -516,11 +516,12 @@ struct device_attribute {
77429 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
77430 const char *buf, size_t count);
77431 };
77432 +typedef struct device_attribute __no_const device_attribute_no_const;
77433
77434 struct dev_ext_attribute {
77435 struct device_attribute attr;
77436 void *var;
77437 -};
77438 +} __do_const;
77439
77440 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
77441 char *buf);
77442 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
77443 index fd4aee2..1f28db9 100644
77444 --- a/include/linux/dma-mapping.h
77445 +++ b/include/linux/dma-mapping.h
77446 @@ -54,7 +54,7 @@ struct dma_map_ops {
77447 u64 (*get_required_mask)(struct device *dev);
77448 #endif
77449 int is_phys;
77450 -};
77451 +} __do_const;
77452
77453 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
77454
77455 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
77456 index c5c92d5..6a5c2b2 100644
77457 --- a/include/linux/dmaengine.h
77458 +++ b/include/linux/dmaengine.h
77459 @@ -1150,9 +1150,9 @@ struct dma_pinned_list {
77460 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
77461 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
77462
77463 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77464 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77465 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
77466 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77467 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77468 struct dma_pinned_list *pinned_list, struct page *page,
77469 unsigned int offset, size_t len);
77470
77471 diff --git a/include/linux/efi.h b/include/linux/efi.h
77472 index 0a819e7..8ed47f1 100644
77473 --- a/include/linux/efi.h
77474 +++ b/include/linux/efi.h
77475 @@ -768,6 +768,7 @@ struct efivar_operations {
77476 efi_set_variable_t *set_variable;
77477 efi_query_variable_store_t *query_variable_store;
77478 };
77479 +typedef struct efivar_operations __no_const efivar_operations_no_const;
77480
77481 struct efivars {
77482 /*
77483 diff --git a/include/linux/elf.h b/include/linux/elf.h
77484 index 67a5fa7..b817372 100644
77485 --- a/include/linux/elf.h
77486 +++ b/include/linux/elf.h
77487 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
77488 #define elf_note elf32_note
77489 #define elf_addr_t Elf32_Off
77490 #define Elf_Half Elf32_Half
77491 +#define elf_dyn Elf32_Dyn
77492
77493 #else
77494
77495 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
77496 #define elf_note elf64_note
77497 #define elf_addr_t Elf64_Off
77498 #define Elf_Half Elf64_Half
77499 +#define elf_dyn Elf64_Dyn
77500
77501 #endif
77502
77503 diff --git a/include/linux/err.h b/include/linux/err.h
77504 index 15f92e0..e825a8e 100644
77505 --- a/include/linux/err.h
77506 +++ b/include/linux/err.h
77507 @@ -19,12 +19,12 @@
77508
77509 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
77510
77511 -static inline void * __must_check ERR_PTR(long error)
77512 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
77513 {
77514 return (void *) error;
77515 }
77516
77517 -static inline long __must_check PTR_ERR(__force const void *ptr)
77518 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
77519 {
77520 return (long) ptr;
77521 }
77522 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
77523 index 21c59af..6057a03 100644
77524 --- a/include/linux/extcon.h
77525 +++ b/include/linux/extcon.h
77526 @@ -135,7 +135,7 @@ struct extcon_dev {
77527 /* /sys/class/extcon/.../mutually_exclusive/... */
77528 struct attribute_group attr_g_muex;
77529 struct attribute **attrs_muex;
77530 - struct device_attribute *d_attrs_muex;
77531 + device_attribute_no_const *d_attrs_muex;
77532 };
77533
77534 /**
77535 diff --git a/include/linux/fb.h b/include/linux/fb.h
77536 index fe6ac95..898d41d 100644
77537 --- a/include/linux/fb.h
77538 +++ b/include/linux/fb.h
77539 @@ -304,7 +304,7 @@ struct fb_ops {
77540 /* called at KDB enter and leave time to prepare the console */
77541 int (*fb_debug_enter)(struct fb_info *info);
77542 int (*fb_debug_leave)(struct fb_info *info);
77543 -};
77544 +} __do_const;
77545
77546 #ifdef CONFIG_FB_TILEBLITTING
77547 #define FB_TILE_CURSOR_NONE 0
77548 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
77549 index 70e8e21..1939916 100644
77550 --- a/include/linux/fdtable.h
77551 +++ b/include/linux/fdtable.h
77552 @@ -102,7 +102,7 @@ struct files_struct *get_files_struct(struct task_struct *);
77553 void put_files_struct(struct files_struct *fs);
77554 void reset_files_struct(struct files_struct *);
77555 int unshare_files(struct files_struct **);
77556 -struct files_struct *dup_fd(struct files_struct *, int *);
77557 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
77558 void do_close_on_exec(struct files_struct *);
77559 int iterate_fd(struct files_struct *, unsigned,
77560 int (*)(const void *, struct file *, unsigned),
77561 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
77562 index 8293262..2b3b8bd 100644
77563 --- a/include/linux/frontswap.h
77564 +++ b/include/linux/frontswap.h
77565 @@ -11,7 +11,7 @@ struct frontswap_ops {
77566 int (*load)(unsigned, pgoff_t, struct page *);
77567 void (*invalidate_page)(unsigned, pgoff_t);
77568 void (*invalidate_area)(unsigned);
77569 -};
77570 +} __no_const;
77571
77572 extern bool frontswap_enabled;
77573 extern struct frontswap_ops *
77574 diff --git a/include/linux/fs.h b/include/linux/fs.h
77575 index 23b2a35..8764ab7 100644
77576 --- a/include/linux/fs.h
77577 +++ b/include/linux/fs.h
77578 @@ -426,7 +426,7 @@ struct address_space {
77579 spinlock_t private_lock; /* for use by the address_space */
77580 struct list_head private_list; /* ditto */
77581 void *private_data; /* ditto */
77582 -} __attribute__((aligned(sizeof(long))));
77583 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
77584 /*
77585 * On most architectures that alignment is already the case; but
77586 * must be enforced here for CRIS, to let the least significant bit
77587 @@ -469,7 +469,7 @@ struct block_device {
77588 int bd_fsfreeze_count;
77589 /* Mutex for freeze */
77590 struct mutex bd_fsfreeze_mutex;
77591 -};
77592 +} __randomize_layout;
77593
77594 /*
77595 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
77596 @@ -613,7 +613,7 @@ struct inode {
77597 atomic_t i_readcount; /* struct files open RO */
77598 #endif
77599 void *i_private; /* fs or device private pointer */
77600 -};
77601 +} __randomize_layout;
77602
77603 static inline int inode_unhashed(struct inode *inode)
77604 {
77605 @@ -812,7 +812,7 @@ struct file {
77606 #ifdef CONFIG_DEBUG_WRITECOUNT
77607 unsigned long f_mnt_write_state;
77608 #endif
77609 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
77610 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
77611
77612 struct file_handle {
77613 __u32 handle_bytes;
77614 @@ -982,7 +982,7 @@ struct file_lock {
77615 int state; /* state of grant or error if -ve */
77616 } afs;
77617 } fl_u;
77618 -};
77619 +} __randomize_layout;
77620
77621 /* The following constant reflects the upper bound of the file/locking space */
77622 #ifndef OFFSET_MAX
77623 @@ -1329,7 +1329,7 @@ struct super_block {
77624 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
77625 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
77626 struct rcu_head rcu;
77627 -};
77628 +} __randomize_layout;
77629
77630 extern struct timespec current_fs_time(struct super_block *sb);
77631
77632 @@ -1551,7 +1551,8 @@ struct file_operations {
77633 long (*fallocate)(struct file *file, int mode, loff_t offset,
77634 loff_t len);
77635 int (*show_fdinfo)(struct seq_file *m, struct file *f);
77636 -};
77637 +} __do_const __randomize_layout;
77638 +typedef struct file_operations __no_const file_operations_no_const;
77639
77640 struct inode_operations {
77641 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
77642 @@ -2820,4 +2821,14 @@ static inline bool dir_relax(struct inode *inode)
77643 return !IS_DEADDIR(inode);
77644 }
77645
77646 +static inline bool is_sidechannel_device(const struct inode *inode)
77647 +{
77648 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
77649 + umode_t mode = inode->i_mode;
77650 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
77651 +#else
77652 + return false;
77653 +#endif
77654 +}
77655 +
77656 #endif /* _LINUX_FS_H */
77657 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
77658 index 0efc3e6..fd23610 100644
77659 --- a/include/linux/fs_struct.h
77660 +++ b/include/linux/fs_struct.h
77661 @@ -6,13 +6,13 @@
77662 #include <linux/seqlock.h>
77663
77664 struct fs_struct {
77665 - int users;
77666 + atomic_t users;
77667 spinlock_t lock;
77668 seqcount_t seq;
77669 int umask;
77670 int in_exec;
77671 struct path root, pwd;
77672 -};
77673 +} __randomize_layout;
77674
77675 extern struct kmem_cache *fs_cachep;
77676
77677 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
77678 index 7714849..a4a5c7a 100644
77679 --- a/include/linux/fscache-cache.h
77680 +++ b/include/linux/fscache-cache.h
77681 @@ -113,7 +113,7 @@ struct fscache_operation {
77682 fscache_operation_release_t release;
77683 };
77684
77685 -extern atomic_t fscache_op_debug_id;
77686 +extern atomic_unchecked_t fscache_op_debug_id;
77687 extern void fscache_op_work_func(struct work_struct *work);
77688
77689 extern void fscache_enqueue_operation(struct fscache_operation *);
77690 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
77691 INIT_WORK(&op->work, fscache_op_work_func);
77692 atomic_set(&op->usage, 1);
77693 op->state = FSCACHE_OP_ST_INITIALISED;
77694 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
77695 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
77696 op->processor = processor;
77697 op->release = release;
77698 INIT_LIST_HEAD(&op->pend_link);
77699 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
77700 index 115bb81..e7b812b 100644
77701 --- a/include/linux/fscache.h
77702 +++ b/include/linux/fscache.h
77703 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
77704 * - this is mandatory for any object that may have data
77705 */
77706 void (*now_uncached)(void *cookie_netfs_data);
77707 -};
77708 +} __do_const;
77709
77710 /*
77711 * fscache cached network filesystem type
77712 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
77713 index 1c804b0..1432c2b 100644
77714 --- a/include/linux/fsnotify.h
77715 +++ b/include/linux/fsnotify.h
77716 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
77717 struct inode *inode = file_inode(file);
77718 __u32 mask = FS_ACCESS;
77719
77720 + if (is_sidechannel_device(inode))
77721 + return;
77722 +
77723 if (S_ISDIR(inode->i_mode))
77724 mask |= FS_ISDIR;
77725
77726 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
77727 struct inode *inode = file_inode(file);
77728 __u32 mask = FS_MODIFY;
77729
77730 + if (is_sidechannel_device(inode))
77731 + return;
77732 +
77733 if (S_ISDIR(inode->i_mode))
77734 mask |= FS_ISDIR;
77735
77736 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
77737 */
77738 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
77739 {
77740 - return kstrdup(name, GFP_KERNEL);
77741 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
77742 }
77743
77744 /*
77745 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
77746 index 9f3c275..8bdff5d 100644
77747 --- a/include/linux/genhd.h
77748 +++ b/include/linux/genhd.h
77749 @@ -194,7 +194,7 @@ struct gendisk {
77750 struct kobject *slave_dir;
77751
77752 struct timer_rand_state *random;
77753 - atomic_t sync_io; /* RAID */
77754 + atomic_unchecked_t sync_io; /* RAID */
77755 struct disk_events *ev;
77756 #ifdef CONFIG_BLK_DEV_INTEGRITY
77757 struct blk_integrity *integrity;
77758 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
77759 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
77760
77761 /* drivers/char/random.c */
77762 -extern void add_disk_randomness(struct gendisk *disk);
77763 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
77764 extern void rand_initialize_disk(struct gendisk *disk);
77765
77766 static inline sector_t get_start_sect(struct block_device *bdev)
77767 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
77768 index c0894dd..2fbf10c 100644
77769 --- a/include/linux/genl_magic_func.h
77770 +++ b/include/linux/genl_magic_func.h
77771 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
77772 },
77773
77774 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
77775 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
77776 +static struct genl_ops ZZZ_genl_ops[] = {
77777 #include GENL_MAGIC_INCLUDE_FILE
77778 };
77779
77780 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
77781 index 39b81dc..819dc51 100644
77782 --- a/include/linux/gfp.h
77783 +++ b/include/linux/gfp.h
77784 @@ -36,6 +36,13 @@ struct vm_area_struct;
77785 #define ___GFP_NO_KSWAPD 0x400000u
77786 #define ___GFP_OTHER_NODE 0x800000u
77787 #define ___GFP_WRITE 0x1000000u
77788 +
77789 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77790 +#define ___GFP_USERCOPY 0x2000000u
77791 +#else
77792 +#define ___GFP_USERCOPY 0
77793 +#endif
77794 +
77795 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
77796
77797 /*
77798 @@ -93,6 +100,7 @@ struct vm_area_struct;
77799 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
77800 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
77801 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
77802 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
77803
77804 /*
77805 * This may seem redundant, but it's a way of annotating false positives vs.
77806 @@ -100,7 +108,7 @@ struct vm_area_struct;
77807 */
77808 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
77809
77810 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
77811 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
77812 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
77813
77814 /* This equals 0, but use constants in case they ever change */
77815 @@ -158,6 +166,8 @@ struct vm_area_struct;
77816 /* 4GB DMA on some platforms */
77817 #define GFP_DMA32 __GFP_DMA32
77818
77819 +#define GFP_USERCOPY __GFP_USERCOPY
77820 +
77821 /* Convert GFP flags to their corresponding migrate type */
77822 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
77823 {
77824 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
77825 new file mode 100644
77826 index 0000000..edb2cb6
77827 --- /dev/null
77828 +++ b/include/linux/gracl.h
77829 @@ -0,0 +1,340 @@
77830 +#ifndef GR_ACL_H
77831 +#define GR_ACL_H
77832 +
77833 +#include <linux/grdefs.h>
77834 +#include <linux/resource.h>
77835 +#include <linux/capability.h>
77836 +#include <linux/dcache.h>
77837 +#include <asm/resource.h>
77838 +
77839 +/* Major status information */
77840 +
77841 +#define GR_VERSION "grsecurity 3.0"
77842 +#define GRSECURITY_VERSION 0x3000
77843 +
77844 +enum {
77845 + GR_SHUTDOWN = 0,
77846 + GR_ENABLE = 1,
77847 + GR_SPROLE = 2,
77848 + GR_OLDRELOAD = 3,
77849 + GR_SEGVMOD = 4,
77850 + GR_STATUS = 5,
77851 + GR_UNSPROLE = 6,
77852 + GR_PASSSET = 7,
77853 + GR_SPROLEPAM = 8,
77854 + GR_RELOAD = 9,
77855 +};
77856 +
77857 +/* Password setup definitions
77858 + * kernel/grhash.c */
77859 +enum {
77860 + GR_PW_LEN = 128,
77861 + GR_SALT_LEN = 16,
77862 + GR_SHA_LEN = 32,
77863 +};
77864 +
77865 +enum {
77866 + GR_SPROLE_LEN = 64,
77867 +};
77868 +
77869 +enum {
77870 + GR_NO_GLOB = 0,
77871 + GR_REG_GLOB,
77872 + GR_CREATE_GLOB
77873 +};
77874 +
77875 +#define GR_NLIMITS 32
77876 +
77877 +/* Begin Data Structures */
77878 +
77879 +struct sprole_pw {
77880 + unsigned char *rolename;
77881 + unsigned char salt[GR_SALT_LEN];
77882 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
77883 +};
77884 +
77885 +struct name_entry {
77886 + __u32 key;
77887 + ino_t inode;
77888 + dev_t device;
77889 + char *name;
77890 + __u16 len;
77891 + __u8 deleted;
77892 + struct name_entry *prev;
77893 + struct name_entry *next;
77894 +};
77895 +
77896 +struct inodev_entry {
77897 + struct name_entry *nentry;
77898 + struct inodev_entry *prev;
77899 + struct inodev_entry *next;
77900 +};
77901 +
77902 +struct acl_role_db {
77903 + struct acl_role_label **r_hash;
77904 + __u32 r_size;
77905 +};
77906 +
77907 +struct inodev_db {
77908 + struct inodev_entry **i_hash;
77909 + __u32 i_size;
77910 +};
77911 +
77912 +struct name_db {
77913 + struct name_entry **n_hash;
77914 + __u32 n_size;
77915 +};
77916 +
77917 +struct crash_uid {
77918 + uid_t uid;
77919 + unsigned long expires;
77920 +};
77921 +
77922 +struct gr_hash_struct {
77923 + void **table;
77924 + void **nametable;
77925 + void *first;
77926 + __u32 table_size;
77927 + __u32 used_size;
77928 + int type;
77929 +};
77930 +
77931 +/* Userspace Grsecurity ACL data structures */
77932 +
77933 +struct acl_subject_label {
77934 + char *filename;
77935 + ino_t inode;
77936 + dev_t device;
77937 + __u32 mode;
77938 + kernel_cap_t cap_mask;
77939 + kernel_cap_t cap_lower;
77940 + kernel_cap_t cap_invert_audit;
77941 +
77942 + struct rlimit res[GR_NLIMITS];
77943 + __u32 resmask;
77944 +
77945 + __u8 user_trans_type;
77946 + __u8 group_trans_type;
77947 + uid_t *user_transitions;
77948 + gid_t *group_transitions;
77949 + __u16 user_trans_num;
77950 + __u16 group_trans_num;
77951 +
77952 + __u32 sock_families[2];
77953 + __u32 ip_proto[8];
77954 + __u32 ip_type;
77955 + struct acl_ip_label **ips;
77956 + __u32 ip_num;
77957 + __u32 inaddr_any_override;
77958 +
77959 + __u32 crashes;
77960 + unsigned long expires;
77961 +
77962 + struct acl_subject_label *parent_subject;
77963 + struct gr_hash_struct *hash;
77964 + struct acl_subject_label *prev;
77965 + struct acl_subject_label *next;
77966 +
77967 + struct acl_object_label **obj_hash;
77968 + __u32 obj_hash_size;
77969 + __u16 pax_flags;
77970 +};
77971 +
77972 +struct role_allowed_ip {
77973 + __u32 addr;
77974 + __u32 netmask;
77975 +
77976 + struct role_allowed_ip *prev;
77977 + struct role_allowed_ip *next;
77978 +};
77979 +
77980 +struct role_transition {
77981 + char *rolename;
77982 +
77983 + struct role_transition *prev;
77984 + struct role_transition *next;
77985 +};
77986 +
77987 +struct acl_role_label {
77988 + char *rolename;
77989 + uid_t uidgid;
77990 + __u16 roletype;
77991 +
77992 + __u16 auth_attempts;
77993 + unsigned long expires;
77994 +
77995 + struct acl_subject_label *root_label;
77996 + struct gr_hash_struct *hash;
77997 +
77998 + struct acl_role_label *prev;
77999 + struct acl_role_label *next;
78000 +
78001 + struct role_transition *transitions;
78002 + struct role_allowed_ip *allowed_ips;
78003 + uid_t *domain_children;
78004 + __u16 domain_child_num;
78005 +
78006 + umode_t umask;
78007 +
78008 + struct acl_subject_label **subj_hash;
78009 + __u32 subj_hash_size;
78010 +};
78011 +
78012 +struct user_acl_role_db {
78013 + struct acl_role_label **r_table;
78014 + __u32 num_pointers; /* Number of allocations to track */
78015 + __u32 num_roles; /* Number of roles */
78016 + __u32 num_domain_children; /* Number of domain children */
78017 + __u32 num_subjects; /* Number of subjects */
78018 + __u32 num_objects; /* Number of objects */
78019 +};
78020 +
78021 +struct acl_object_label {
78022 + char *filename;
78023 + ino_t inode;
78024 + dev_t device;
78025 + __u32 mode;
78026 +
78027 + struct acl_subject_label *nested;
78028 + struct acl_object_label *globbed;
78029 +
78030 + /* next two structures not used */
78031 +
78032 + struct acl_object_label *prev;
78033 + struct acl_object_label *next;
78034 +};
78035 +
78036 +struct acl_ip_label {
78037 + char *iface;
78038 + __u32 addr;
78039 + __u32 netmask;
78040 + __u16 low, high;
78041 + __u8 mode;
78042 + __u32 type;
78043 + __u32 proto[8];
78044 +
78045 + /* next two structures not used */
78046 +
78047 + struct acl_ip_label *prev;
78048 + struct acl_ip_label *next;
78049 +};
78050 +
78051 +struct gr_arg {
78052 + struct user_acl_role_db role_db;
78053 + unsigned char pw[GR_PW_LEN];
78054 + unsigned char salt[GR_SALT_LEN];
78055 + unsigned char sum[GR_SHA_LEN];
78056 + unsigned char sp_role[GR_SPROLE_LEN];
78057 + struct sprole_pw *sprole_pws;
78058 + dev_t segv_device;
78059 + ino_t segv_inode;
78060 + uid_t segv_uid;
78061 + __u16 num_sprole_pws;
78062 + __u16 mode;
78063 +};
78064 +
78065 +struct gr_arg_wrapper {
78066 + struct gr_arg *arg;
78067 + __u32 version;
78068 + __u32 size;
78069 +};
78070 +
78071 +struct subject_map {
78072 + struct acl_subject_label *user;
78073 + struct acl_subject_label *kernel;
78074 + struct subject_map *prev;
78075 + struct subject_map *next;
78076 +};
78077 +
78078 +struct acl_subj_map_db {
78079 + struct subject_map **s_hash;
78080 + __u32 s_size;
78081 +};
78082 +
78083 +struct gr_policy_state {
78084 + struct sprole_pw **acl_special_roles;
78085 + __u16 num_sprole_pws;
78086 + struct acl_role_label *kernel_role;
78087 + struct acl_role_label *role_list;
78088 + struct acl_role_label *default_role;
78089 + struct acl_role_db acl_role_set;
78090 + struct acl_subj_map_db subj_map_set;
78091 + struct name_db name_set;
78092 + struct inodev_db inodev_set;
78093 +};
78094 +
78095 +struct gr_alloc_state {
78096 + unsigned long alloc_stack_next;
78097 + unsigned long alloc_stack_size;
78098 + void **alloc_stack;
78099 +};
78100 +
78101 +struct gr_reload_state {
78102 + struct gr_policy_state oldpolicy;
78103 + struct gr_alloc_state oldalloc;
78104 + struct gr_policy_state newpolicy;
78105 + struct gr_alloc_state newalloc;
78106 + struct gr_policy_state *oldpolicy_ptr;
78107 + struct gr_alloc_state *oldalloc_ptr;
78108 + unsigned char oldmode;
78109 +};
78110 +
78111 +/* End Data Structures Section */
78112 +
78113 +/* Hash functions generated by empirical testing by Brad Spengler
78114 + Makes good use of the low bits of the inode. Generally 0-1 times
78115 + in loop for successful match. 0-3 for unsuccessful match.
78116 + Shift/add algorithm with modulus of table size and an XOR*/
78117 +
78118 +static __inline__ unsigned int
78119 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78120 +{
78121 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
78122 +}
78123 +
78124 + static __inline__ unsigned int
78125 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78126 +{
78127 + return ((const unsigned long)userp % sz);
78128 +}
78129 +
78130 +static __inline__ unsigned int
78131 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78132 +{
78133 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78134 +}
78135 +
78136 +static __inline__ unsigned int
78137 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78138 +{
78139 + return full_name_hash((const unsigned char *)name, len) % sz;
78140 +}
78141 +
78142 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78143 + subj = NULL; \
78144 + iter = 0; \
78145 + while (iter < role->subj_hash_size) { \
78146 + if (subj == NULL) \
78147 + subj = role->subj_hash[iter]; \
78148 + if (subj == NULL) { \
78149 + iter++; \
78150 + continue; \
78151 + }
78152 +
78153 +#define FOR_EACH_SUBJECT_END(subj,iter) \
78154 + subj = subj->next; \
78155 + if (subj == NULL) \
78156 + iter++; \
78157 + }
78158 +
78159 +
78160 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78161 + subj = role->hash->first; \
78162 + while (subj != NULL) {
78163 +
78164 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78165 + subj = subj->next; \
78166 + }
78167 +
78168 +#endif
78169 +
78170 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
78171 new file mode 100644
78172 index 0000000..33ebd1f
78173 --- /dev/null
78174 +++ b/include/linux/gracl_compat.h
78175 @@ -0,0 +1,156 @@
78176 +#ifndef GR_ACL_COMPAT_H
78177 +#define GR_ACL_COMPAT_H
78178 +
78179 +#include <linux/resource.h>
78180 +#include <asm/resource.h>
78181 +
78182 +struct sprole_pw_compat {
78183 + compat_uptr_t rolename;
78184 + unsigned char salt[GR_SALT_LEN];
78185 + unsigned char sum[GR_SHA_LEN];
78186 +};
78187 +
78188 +struct gr_hash_struct_compat {
78189 + compat_uptr_t table;
78190 + compat_uptr_t nametable;
78191 + compat_uptr_t first;
78192 + __u32 table_size;
78193 + __u32 used_size;
78194 + int type;
78195 +};
78196 +
78197 +struct acl_subject_label_compat {
78198 + compat_uptr_t filename;
78199 + compat_ino_t inode;
78200 + __u32 device;
78201 + __u32 mode;
78202 + kernel_cap_t cap_mask;
78203 + kernel_cap_t cap_lower;
78204 + kernel_cap_t cap_invert_audit;
78205 +
78206 + struct compat_rlimit res[GR_NLIMITS];
78207 + __u32 resmask;
78208 +
78209 + __u8 user_trans_type;
78210 + __u8 group_trans_type;
78211 + compat_uptr_t user_transitions;
78212 + compat_uptr_t group_transitions;
78213 + __u16 user_trans_num;
78214 + __u16 group_trans_num;
78215 +
78216 + __u32 sock_families[2];
78217 + __u32 ip_proto[8];
78218 + __u32 ip_type;
78219 + compat_uptr_t ips;
78220 + __u32 ip_num;
78221 + __u32 inaddr_any_override;
78222 +
78223 + __u32 crashes;
78224 + compat_ulong_t expires;
78225 +
78226 + compat_uptr_t parent_subject;
78227 + compat_uptr_t hash;
78228 + compat_uptr_t prev;
78229 + compat_uptr_t next;
78230 +
78231 + compat_uptr_t obj_hash;
78232 + __u32 obj_hash_size;
78233 + __u16 pax_flags;
78234 +};
78235 +
78236 +struct role_allowed_ip_compat {
78237 + __u32 addr;
78238 + __u32 netmask;
78239 +
78240 + compat_uptr_t prev;
78241 + compat_uptr_t next;
78242 +};
78243 +
78244 +struct role_transition_compat {
78245 + compat_uptr_t rolename;
78246 +
78247 + compat_uptr_t prev;
78248 + compat_uptr_t next;
78249 +};
78250 +
78251 +struct acl_role_label_compat {
78252 + compat_uptr_t rolename;
78253 + uid_t uidgid;
78254 + __u16 roletype;
78255 +
78256 + __u16 auth_attempts;
78257 + compat_ulong_t expires;
78258 +
78259 + compat_uptr_t root_label;
78260 + compat_uptr_t hash;
78261 +
78262 + compat_uptr_t prev;
78263 + compat_uptr_t next;
78264 +
78265 + compat_uptr_t transitions;
78266 + compat_uptr_t allowed_ips;
78267 + compat_uptr_t domain_children;
78268 + __u16 domain_child_num;
78269 +
78270 + umode_t umask;
78271 +
78272 + compat_uptr_t subj_hash;
78273 + __u32 subj_hash_size;
78274 +};
78275 +
78276 +struct user_acl_role_db_compat {
78277 + compat_uptr_t r_table;
78278 + __u32 num_pointers;
78279 + __u32 num_roles;
78280 + __u32 num_domain_children;
78281 + __u32 num_subjects;
78282 + __u32 num_objects;
78283 +};
78284 +
78285 +struct acl_object_label_compat {
78286 + compat_uptr_t filename;
78287 + compat_ino_t inode;
78288 + __u32 device;
78289 + __u32 mode;
78290 +
78291 + compat_uptr_t nested;
78292 + compat_uptr_t globbed;
78293 +
78294 + compat_uptr_t prev;
78295 + compat_uptr_t next;
78296 +};
78297 +
78298 +struct acl_ip_label_compat {
78299 + compat_uptr_t iface;
78300 + __u32 addr;
78301 + __u32 netmask;
78302 + __u16 low, high;
78303 + __u8 mode;
78304 + __u32 type;
78305 + __u32 proto[8];
78306 +
78307 + compat_uptr_t prev;
78308 + compat_uptr_t next;
78309 +};
78310 +
78311 +struct gr_arg_compat {
78312 + struct user_acl_role_db_compat role_db;
78313 + unsigned char pw[GR_PW_LEN];
78314 + unsigned char salt[GR_SALT_LEN];
78315 + unsigned char sum[GR_SHA_LEN];
78316 + unsigned char sp_role[GR_SPROLE_LEN];
78317 + compat_uptr_t sprole_pws;
78318 + __u32 segv_device;
78319 + compat_ino_t segv_inode;
78320 + uid_t segv_uid;
78321 + __u16 num_sprole_pws;
78322 + __u16 mode;
78323 +};
78324 +
78325 +struct gr_arg_wrapper_compat {
78326 + compat_uptr_t arg;
78327 + __u32 version;
78328 + __u32 size;
78329 +};
78330 +
78331 +#endif
78332 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
78333 new file mode 100644
78334 index 0000000..323ecf2
78335 --- /dev/null
78336 +++ b/include/linux/gralloc.h
78337 @@ -0,0 +1,9 @@
78338 +#ifndef __GRALLOC_H
78339 +#define __GRALLOC_H
78340 +
78341 +void acl_free_all(void);
78342 +int acl_alloc_stack_init(unsigned long size);
78343 +void *acl_alloc(unsigned long len);
78344 +void *acl_alloc_num(unsigned long num, unsigned long len);
78345 +
78346 +#endif
78347 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
78348 new file mode 100644
78349 index 0000000..be66033
78350 --- /dev/null
78351 +++ b/include/linux/grdefs.h
78352 @@ -0,0 +1,140 @@
78353 +#ifndef GRDEFS_H
78354 +#define GRDEFS_H
78355 +
78356 +/* Begin grsecurity status declarations */
78357 +
78358 +enum {
78359 + GR_READY = 0x01,
78360 + GR_STATUS_INIT = 0x00 // disabled state
78361 +};
78362 +
78363 +/* Begin ACL declarations */
78364 +
78365 +/* Role flags */
78366 +
78367 +enum {
78368 + GR_ROLE_USER = 0x0001,
78369 + GR_ROLE_GROUP = 0x0002,
78370 + GR_ROLE_DEFAULT = 0x0004,
78371 + GR_ROLE_SPECIAL = 0x0008,
78372 + GR_ROLE_AUTH = 0x0010,
78373 + GR_ROLE_NOPW = 0x0020,
78374 + GR_ROLE_GOD = 0x0040,
78375 + GR_ROLE_LEARN = 0x0080,
78376 + GR_ROLE_TPE = 0x0100,
78377 + GR_ROLE_DOMAIN = 0x0200,
78378 + GR_ROLE_PAM = 0x0400,
78379 + GR_ROLE_PERSIST = 0x0800
78380 +};
78381 +
78382 +/* ACL Subject and Object mode flags */
78383 +enum {
78384 + GR_DELETED = 0x80000000
78385 +};
78386 +
78387 +/* ACL Object-only mode flags */
78388 +enum {
78389 + GR_READ = 0x00000001,
78390 + GR_APPEND = 0x00000002,
78391 + GR_WRITE = 0x00000004,
78392 + GR_EXEC = 0x00000008,
78393 + GR_FIND = 0x00000010,
78394 + GR_INHERIT = 0x00000020,
78395 + GR_SETID = 0x00000040,
78396 + GR_CREATE = 0x00000080,
78397 + GR_DELETE = 0x00000100,
78398 + GR_LINK = 0x00000200,
78399 + GR_AUDIT_READ = 0x00000400,
78400 + GR_AUDIT_APPEND = 0x00000800,
78401 + GR_AUDIT_WRITE = 0x00001000,
78402 + GR_AUDIT_EXEC = 0x00002000,
78403 + GR_AUDIT_FIND = 0x00004000,
78404 + GR_AUDIT_INHERIT= 0x00008000,
78405 + GR_AUDIT_SETID = 0x00010000,
78406 + GR_AUDIT_CREATE = 0x00020000,
78407 + GR_AUDIT_DELETE = 0x00040000,
78408 + GR_AUDIT_LINK = 0x00080000,
78409 + GR_PTRACERD = 0x00100000,
78410 + GR_NOPTRACE = 0x00200000,
78411 + GR_SUPPRESS = 0x00400000,
78412 + GR_NOLEARN = 0x00800000,
78413 + GR_INIT_TRANSFER= 0x01000000
78414 +};
78415 +
78416 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
78417 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
78418 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
78419 +
78420 +/* ACL subject-only mode flags */
78421 +enum {
78422 + GR_KILL = 0x00000001,
78423 + GR_VIEW = 0x00000002,
78424 + GR_PROTECTED = 0x00000004,
78425 + GR_LEARN = 0x00000008,
78426 + GR_OVERRIDE = 0x00000010,
78427 + /* just a placeholder, this mode is only used in userspace */
78428 + GR_DUMMY = 0x00000020,
78429 + GR_PROTSHM = 0x00000040,
78430 + GR_KILLPROC = 0x00000080,
78431 + GR_KILLIPPROC = 0x00000100,
78432 + /* just a placeholder, this mode is only used in userspace */
78433 + GR_NOTROJAN = 0x00000200,
78434 + GR_PROTPROCFD = 0x00000400,
78435 + GR_PROCACCT = 0x00000800,
78436 + GR_RELAXPTRACE = 0x00001000,
78437 + //GR_NESTED = 0x00002000,
78438 + GR_INHERITLEARN = 0x00004000,
78439 + GR_PROCFIND = 0x00008000,
78440 + GR_POVERRIDE = 0x00010000,
78441 + GR_KERNELAUTH = 0x00020000,
78442 + GR_ATSECURE = 0x00040000,
78443 + GR_SHMEXEC = 0x00080000
78444 +};
78445 +
78446 +enum {
78447 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
78448 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
78449 + GR_PAX_ENABLE_MPROTECT = 0x0004,
78450 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
78451 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
78452 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
78453 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
78454 + GR_PAX_DISABLE_MPROTECT = 0x0400,
78455 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
78456 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
78457 +};
78458 +
78459 +enum {
78460 + GR_ID_USER = 0x01,
78461 + GR_ID_GROUP = 0x02,
78462 +};
78463 +
78464 +enum {
78465 + GR_ID_ALLOW = 0x01,
78466 + GR_ID_DENY = 0x02,
78467 +};
78468 +
78469 +#define GR_CRASH_RES 31
78470 +#define GR_UIDTABLE_MAX 500
78471 +
78472 +/* begin resource learning section */
78473 +enum {
78474 + GR_RLIM_CPU_BUMP = 60,
78475 + GR_RLIM_FSIZE_BUMP = 50000,
78476 + GR_RLIM_DATA_BUMP = 10000,
78477 + GR_RLIM_STACK_BUMP = 1000,
78478 + GR_RLIM_CORE_BUMP = 10000,
78479 + GR_RLIM_RSS_BUMP = 500000,
78480 + GR_RLIM_NPROC_BUMP = 1,
78481 + GR_RLIM_NOFILE_BUMP = 5,
78482 + GR_RLIM_MEMLOCK_BUMP = 50000,
78483 + GR_RLIM_AS_BUMP = 500000,
78484 + GR_RLIM_LOCKS_BUMP = 2,
78485 + GR_RLIM_SIGPENDING_BUMP = 5,
78486 + GR_RLIM_MSGQUEUE_BUMP = 10000,
78487 + GR_RLIM_NICE_BUMP = 1,
78488 + GR_RLIM_RTPRIO_BUMP = 1,
78489 + GR_RLIM_RTTIME_BUMP = 1000000
78490 +};
78491 +
78492 +#endif
78493 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
78494 new file mode 100644
78495 index 0000000..d25522e
78496 --- /dev/null
78497 +++ b/include/linux/grinternal.h
78498 @@ -0,0 +1,229 @@
78499 +#ifndef __GRINTERNAL_H
78500 +#define __GRINTERNAL_H
78501 +
78502 +#ifdef CONFIG_GRKERNSEC
78503 +
78504 +#include <linux/fs.h>
78505 +#include <linux/mnt_namespace.h>
78506 +#include <linux/nsproxy.h>
78507 +#include <linux/gracl.h>
78508 +#include <linux/grdefs.h>
78509 +#include <linux/grmsg.h>
78510 +
78511 +void gr_add_learn_entry(const char *fmt, ...)
78512 + __attribute__ ((format (printf, 1, 2)));
78513 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
78514 + const struct vfsmount *mnt);
78515 +__u32 gr_check_create(const struct dentry *new_dentry,
78516 + const struct dentry *parent,
78517 + const struct vfsmount *mnt, const __u32 mode);
78518 +int gr_check_protected_task(const struct task_struct *task);
78519 +__u32 to_gr_audit(const __u32 reqmode);
78520 +int gr_set_acls(const int type);
78521 +int gr_acl_is_enabled(void);
78522 +char gr_roletype_to_char(void);
78523 +
78524 +void gr_handle_alertkill(struct task_struct *task);
78525 +char *gr_to_filename(const struct dentry *dentry,
78526 + const struct vfsmount *mnt);
78527 +char *gr_to_filename1(const struct dentry *dentry,
78528 + const struct vfsmount *mnt);
78529 +char *gr_to_filename2(const struct dentry *dentry,
78530 + const struct vfsmount *mnt);
78531 +char *gr_to_filename3(const struct dentry *dentry,
78532 + const struct vfsmount *mnt);
78533 +
78534 +extern int grsec_enable_ptrace_readexec;
78535 +extern int grsec_enable_harden_ptrace;
78536 +extern int grsec_enable_link;
78537 +extern int grsec_enable_fifo;
78538 +extern int grsec_enable_execve;
78539 +extern int grsec_enable_shm;
78540 +extern int grsec_enable_execlog;
78541 +extern int grsec_enable_signal;
78542 +extern int grsec_enable_audit_ptrace;
78543 +extern int grsec_enable_forkfail;
78544 +extern int grsec_enable_time;
78545 +extern int grsec_enable_rofs;
78546 +extern int grsec_deny_new_usb;
78547 +extern int grsec_enable_chroot_shmat;
78548 +extern int grsec_enable_chroot_mount;
78549 +extern int grsec_enable_chroot_double;
78550 +extern int grsec_enable_chroot_pivot;
78551 +extern int grsec_enable_chroot_chdir;
78552 +extern int grsec_enable_chroot_chmod;
78553 +extern int grsec_enable_chroot_mknod;
78554 +extern int grsec_enable_chroot_fchdir;
78555 +extern int grsec_enable_chroot_nice;
78556 +extern int grsec_enable_chroot_execlog;
78557 +extern int grsec_enable_chroot_caps;
78558 +extern int grsec_enable_chroot_sysctl;
78559 +extern int grsec_enable_chroot_unix;
78560 +extern int grsec_enable_symlinkown;
78561 +extern kgid_t grsec_symlinkown_gid;
78562 +extern int grsec_enable_tpe;
78563 +extern kgid_t grsec_tpe_gid;
78564 +extern int grsec_enable_tpe_all;
78565 +extern int grsec_enable_tpe_invert;
78566 +extern int grsec_enable_socket_all;
78567 +extern kgid_t grsec_socket_all_gid;
78568 +extern int grsec_enable_socket_client;
78569 +extern kgid_t grsec_socket_client_gid;
78570 +extern int grsec_enable_socket_server;
78571 +extern kgid_t grsec_socket_server_gid;
78572 +extern kgid_t grsec_audit_gid;
78573 +extern int grsec_enable_group;
78574 +extern int grsec_enable_log_rwxmaps;
78575 +extern int grsec_enable_mount;
78576 +extern int grsec_enable_chdir;
78577 +extern int grsec_resource_logging;
78578 +extern int grsec_enable_blackhole;
78579 +extern int grsec_lastack_retries;
78580 +extern int grsec_enable_brute;
78581 +extern int grsec_enable_harden_ipc;
78582 +extern int grsec_lock;
78583 +
78584 +extern spinlock_t grsec_alert_lock;
78585 +extern unsigned long grsec_alert_wtime;
78586 +extern unsigned long grsec_alert_fyet;
78587 +
78588 +extern spinlock_t grsec_audit_lock;
78589 +
78590 +extern rwlock_t grsec_exec_file_lock;
78591 +
78592 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
78593 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
78594 + (tsk)->exec_file->f_path.mnt) : "/")
78595 +
78596 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
78597 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
78598 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78599 +
78600 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
78601 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
78602 + (tsk)->exec_file->f_path.mnt) : "/")
78603 +
78604 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
78605 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
78606 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78607 +
78608 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
78609 +
78610 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
78611 +
78612 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
78613 +{
78614 + if (file1 && file2) {
78615 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
78616 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
78617 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
78618 + return true;
78619 + }
78620 +
78621 + return false;
78622 +}
78623 +
78624 +#define GR_CHROOT_CAPS {{ \
78625 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
78626 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
78627 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
78628 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
78629 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
78630 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
78631 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
78632 +
78633 +#define security_learn(normal_msg,args...) \
78634 +({ \
78635 + read_lock(&grsec_exec_file_lock); \
78636 + gr_add_learn_entry(normal_msg "\n", ## args); \
78637 + read_unlock(&grsec_exec_file_lock); \
78638 +})
78639 +
78640 +enum {
78641 + GR_DO_AUDIT,
78642 + GR_DONT_AUDIT,
78643 + /* used for non-audit messages that we shouldn't kill the task on */
78644 + GR_DONT_AUDIT_GOOD
78645 +};
78646 +
78647 +enum {
78648 + GR_TTYSNIFF,
78649 + GR_RBAC,
78650 + GR_RBAC_STR,
78651 + GR_STR_RBAC,
78652 + GR_RBAC_MODE2,
78653 + GR_RBAC_MODE3,
78654 + GR_FILENAME,
78655 + GR_SYSCTL_HIDDEN,
78656 + GR_NOARGS,
78657 + GR_ONE_INT,
78658 + GR_ONE_INT_TWO_STR,
78659 + GR_ONE_STR,
78660 + GR_STR_INT,
78661 + GR_TWO_STR_INT,
78662 + GR_TWO_INT,
78663 + GR_TWO_U64,
78664 + GR_THREE_INT,
78665 + GR_FIVE_INT_TWO_STR,
78666 + GR_TWO_STR,
78667 + GR_THREE_STR,
78668 + GR_FOUR_STR,
78669 + GR_STR_FILENAME,
78670 + GR_FILENAME_STR,
78671 + GR_FILENAME_TWO_INT,
78672 + GR_FILENAME_TWO_INT_STR,
78673 + GR_TEXTREL,
78674 + GR_PTRACE,
78675 + GR_RESOURCE,
78676 + GR_CAP,
78677 + GR_SIG,
78678 + GR_SIG2,
78679 + GR_CRASH1,
78680 + GR_CRASH2,
78681 + GR_PSACCT,
78682 + GR_RWXMAP,
78683 + GR_RWXMAPVMA
78684 +};
78685 +
78686 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
78687 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
78688 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
78689 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
78690 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
78691 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
78692 +#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)
78693 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
78694 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
78695 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
78696 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
78697 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
78698 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
78699 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
78700 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
78701 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
78702 +#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)
78703 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
78704 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
78705 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
78706 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
78707 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
78708 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
78709 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
78710 +#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)
78711 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
78712 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
78713 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
78714 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
78715 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
78716 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
78717 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
78718 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
78719 +#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)
78720 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
78721 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
78722 +
78723 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
78724 +
78725 +#endif
78726 +
78727 +#endif
78728 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
78729 new file mode 100644
78730 index 0000000..ba93581
78731 --- /dev/null
78732 +++ b/include/linux/grmsg.h
78733 @@ -0,0 +1,116 @@
78734 +#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"
78735 +#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"
78736 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
78737 +#define GR_STOPMOD_MSG "denied modification of module state by "
78738 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
78739 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
78740 +#define GR_IOPERM_MSG "denied use of ioperm() by "
78741 +#define GR_IOPL_MSG "denied use of iopl() by "
78742 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
78743 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
78744 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
78745 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
78746 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
78747 +#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"
78748 +#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"
78749 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
78750 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
78751 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
78752 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
78753 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
78754 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
78755 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
78756 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
78757 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
78758 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
78759 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
78760 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
78761 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
78762 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
78763 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
78764 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
78765 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
78766 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
78767 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
78768 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
78769 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
78770 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
78771 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
78772 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
78773 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
78774 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
78775 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
78776 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
78777 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
78778 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
78779 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
78780 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
78781 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
78782 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
78783 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
78784 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
78785 +#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"
78786 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
78787 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
78788 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
78789 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
78790 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
78791 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
78792 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
78793 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
78794 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
78795 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
78796 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
78797 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
78798 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
78799 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
78800 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
78801 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
78802 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
78803 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
78804 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
78805 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
78806 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
78807 +#define GR_NICE_CHROOT_MSG "denied priority change by "
78808 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
78809 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
78810 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
78811 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
78812 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
78813 +#define GR_TIME_MSG "time set by "
78814 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
78815 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
78816 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
78817 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
78818 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
78819 +#define GR_BIND_MSG "denied bind() by "
78820 +#define GR_CONNECT_MSG "denied connect() by "
78821 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
78822 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
78823 +#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"
78824 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
78825 +#define GR_CAP_ACL_MSG "use of %s denied for "
78826 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
78827 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
78828 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
78829 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
78830 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
78831 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
78832 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
78833 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
78834 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
78835 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
78836 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
78837 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
78838 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
78839 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
78840 +#define GR_VM86_MSG "denied use of vm86 by "
78841 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
78842 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
78843 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
78844 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
78845 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
78846 +#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 "
78847 +#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 "
78848 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
78849 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
78850 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
78851 new file mode 100644
78852 index 0000000..8108301
78853 --- /dev/null
78854 +++ b/include/linux/grsecurity.h
78855 @@ -0,0 +1,246 @@
78856 +#ifndef GR_SECURITY_H
78857 +#define GR_SECURITY_H
78858 +#include <linux/fs.h>
78859 +#include <linux/fs_struct.h>
78860 +#include <linux/binfmts.h>
78861 +#include <linux/gracl.h>
78862 +
78863 +/* notify of brain-dead configs */
78864 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78865 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
78866 +#endif
78867 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
78868 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
78869 +#endif
78870 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
78871 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
78872 +#endif
78873 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
78874 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
78875 +#endif
78876 +
78877 +int gr_handle_new_usb(void);
78878 +
78879 +void gr_handle_brute_attach(int dumpable);
78880 +void gr_handle_brute_check(void);
78881 +void gr_handle_kernel_exploit(void);
78882 +
78883 +char gr_roletype_to_char(void);
78884 +
78885 +int gr_acl_enable_at_secure(void);
78886 +
78887 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
78888 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
78889 +
78890 +void gr_del_task_from_ip_table(struct task_struct *p);
78891 +
78892 +int gr_pid_is_chrooted(struct task_struct *p);
78893 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
78894 +int gr_handle_chroot_nice(void);
78895 +int gr_handle_chroot_sysctl(const int op);
78896 +int gr_handle_chroot_setpriority(struct task_struct *p,
78897 + const int niceval);
78898 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
78899 +int gr_handle_chroot_chroot(const struct dentry *dentry,
78900 + const struct vfsmount *mnt);
78901 +void gr_handle_chroot_chdir(const struct path *path);
78902 +int gr_handle_chroot_chmod(const struct dentry *dentry,
78903 + const struct vfsmount *mnt, const int mode);
78904 +int gr_handle_chroot_mknod(const struct dentry *dentry,
78905 + const struct vfsmount *mnt, const int mode);
78906 +int gr_handle_chroot_mount(const struct dentry *dentry,
78907 + const struct vfsmount *mnt,
78908 + const char *dev_name);
78909 +int gr_handle_chroot_pivot(void);
78910 +int gr_handle_chroot_unix(const pid_t pid);
78911 +
78912 +int gr_handle_rawio(const struct inode *inode);
78913 +
78914 +void gr_handle_ioperm(void);
78915 +void gr_handle_iopl(void);
78916 +void gr_handle_msr_write(void);
78917 +
78918 +umode_t gr_acl_umask(void);
78919 +
78920 +int gr_tpe_allow(const struct file *file);
78921 +
78922 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
78923 +void gr_clear_chroot_entries(struct task_struct *task);
78924 +
78925 +void gr_log_forkfail(const int retval);
78926 +void gr_log_timechange(void);
78927 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
78928 +void gr_log_chdir(const struct dentry *dentry,
78929 + const struct vfsmount *mnt);
78930 +void gr_log_chroot_exec(const struct dentry *dentry,
78931 + const struct vfsmount *mnt);
78932 +void gr_log_remount(const char *devname, const int retval);
78933 +void gr_log_unmount(const char *devname, const int retval);
78934 +void gr_log_mount(const char *from, const char *to, const int retval);
78935 +void gr_log_textrel(struct vm_area_struct *vma);
78936 +void gr_log_ptgnustack(struct file *file);
78937 +void gr_log_rwxmmap(struct file *file);
78938 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
78939 +
78940 +int gr_handle_follow_link(const struct inode *parent,
78941 + const struct inode *inode,
78942 + const struct dentry *dentry,
78943 + const struct vfsmount *mnt);
78944 +int gr_handle_fifo(const struct dentry *dentry,
78945 + const struct vfsmount *mnt,
78946 + const struct dentry *dir, const int flag,
78947 + const int acc_mode);
78948 +int gr_handle_hardlink(const struct dentry *dentry,
78949 + const struct vfsmount *mnt,
78950 + struct inode *inode,
78951 + const int mode, const struct filename *to);
78952 +
78953 +int gr_is_capable(const int cap);
78954 +int gr_is_capable_nolog(const int cap);
78955 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
78956 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
78957 +
78958 +void gr_copy_label(struct task_struct *tsk);
78959 +void gr_handle_crash(struct task_struct *task, const int sig);
78960 +int gr_handle_signal(const struct task_struct *p, const int sig);
78961 +int gr_check_crash_uid(const kuid_t uid);
78962 +int gr_check_protected_task(const struct task_struct *task);
78963 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
78964 +int gr_acl_handle_mmap(const struct file *file,
78965 + const unsigned long prot);
78966 +int gr_acl_handle_mprotect(const struct file *file,
78967 + const unsigned long prot);
78968 +int gr_check_hidden_task(const struct task_struct *tsk);
78969 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
78970 + const struct vfsmount *mnt);
78971 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
78972 + const struct vfsmount *mnt);
78973 +__u32 gr_acl_handle_access(const struct dentry *dentry,
78974 + const struct vfsmount *mnt, const int fmode);
78975 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
78976 + const struct vfsmount *mnt, umode_t *mode);
78977 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
78978 + const struct vfsmount *mnt);
78979 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
78980 + const struct vfsmount *mnt);
78981 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
78982 + const struct vfsmount *mnt);
78983 +int gr_handle_ptrace(struct task_struct *task, const long request);
78984 +int gr_handle_proc_ptrace(struct task_struct *task);
78985 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
78986 + const struct vfsmount *mnt);
78987 +int gr_check_crash_exec(const struct file *filp);
78988 +int gr_acl_is_enabled(void);
78989 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
78990 + const kgid_t gid);
78991 +int gr_set_proc_label(const struct dentry *dentry,
78992 + const struct vfsmount *mnt,
78993 + const int unsafe_flags);
78994 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
78995 + const struct vfsmount *mnt);
78996 +__u32 gr_acl_handle_open(const struct dentry *dentry,
78997 + const struct vfsmount *mnt, int acc_mode);
78998 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
78999 + const struct dentry *p_dentry,
79000 + const struct vfsmount *p_mnt,
79001 + int open_flags, int acc_mode, const int imode);
79002 +void gr_handle_create(const struct dentry *dentry,
79003 + const struct vfsmount *mnt);
79004 +void gr_handle_proc_create(const struct dentry *dentry,
79005 + const struct inode *inode);
79006 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79007 + const struct dentry *parent_dentry,
79008 + const struct vfsmount *parent_mnt,
79009 + const int mode);
79010 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79011 + const struct dentry *parent_dentry,
79012 + const struct vfsmount *parent_mnt);
79013 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79014 + const struct vfsmount *mnt);
79015 +void gr_handle_delete(const ino_t ino, const dev_t dev);
79016 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79017 + const struct vfsmount *mnt);
79018 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79019 + const struct dentry *parent_dentry,
79020 + const struct vfsmount *parent_mnt,
79021 + const struct filename *from);
79022 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79023 + const struct dentry *parent_dentry,
79024 + const struct vfsmount *parent_mnt,
79025 + const struct dentry *old_dentry,
79026 + const struct vfsmount *old_mnt, const struct filename *to);
79027 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79028 +int gr_acl_handle_rename(struct dentry *new_dentry,
79029 + struct dentry *parent_dentry,
79030 + const struct vfsmount *parent_mnt,
79031 + struct dentry *old_dentry,
79032 + struct inode *old_parent_inode,
79033 + struct vfsmount *old_mnt, const struct filename *newname);
79034 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79035 + struct dentry *old_dentry,
79036 + struct dentry *new_dentry,
79037 + struct vfsmount *mnt, const __u8 replace);
79038 +__u32 gr_check_link(const struct dentry *new_dentry,
79039 + const struct dentry *parent_dentry,
79040 + const struct vfsmount *parent_mnt,
79041 + const struct dentry *old_dentry,
79042 + const struct vfsmount *old_mnt);
79043 +int gr_acl_handle_filldir(const struct file *file, const char *name,
79044 + const unsigned int namelen, const ino_t ino);
79045 +
79046 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
79047 + const struct vfsmount *mnt);
79048 +void gr_acl_handle_exit(void);
79049 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
79050 +int gr_acl_handle_procpidmem(const struct task_struct *task);
79051 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79052 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79053 +void gr_audit_ptrace(struct task_struct *task);
79054 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79055 +void gr_put_exec_file(struct task_struct *task);
79056 +
79057 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79058 +
79059 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79060 +extern void gr_learn_resource(const struct task_struct *task, const int res,
79061 + const unsigned long wanted, const int gt);
79062 +#else
79063 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
79064 + const unsigned long wanted, const int gt)
79065 +{
79066 +}
79067 +#endif
79068 +
79069 +#ifdef CONFIG_GRKERNSEC_RESLOG
79070 +extern void gr_log_resource(const struct task_struct *task, const int res,
79071 + const unsigned long wanted, const int gt);
79072 +#else
79073 +static inline void gr_log_resource(const struct task_struct *task, const int res,
79074 + const unsigned long wanted, const int gt)
79075 +{
79076 +}
79077 +#endif
79078 +
79079 +#ifdef CONFIG_GRKERNSEC
79080 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79081 +void gr_handle_vm86(void);
79082 +void gr_handle_mem_readwrite(u64 from, u64 to);
79083 +
79084 +void gr_log_badprocpid(const char *entry);
79085 +
79086 +extern int grsec_enable_dmesg;
79087 +extern int grsec_disable_privio;
79088 +
79089 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79090 +extern kgid_t grsec_proc_gid;
79091 +#endif
79092 +
79093 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79094 +extern int grsec_enable_chroot_findtask;
79095 +#endif
79096 +#ifdef CONFIG_GRKERNSEC_SETXID
79097 +extern int grsec_enable_setxid;
79098 +#endif
79099 +#endif
79100 +
79101 +#endif
79102 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79103 new file mode 100644
79104 index 0000000..e7ffaaf
79105 --- /dev/null
79106 +++ b/include/linux/grsock.h
79107 @@ -0,0 +1,19 @@
79108 +#ifndef __GRSOCK_H
79109 +#define __GRSOCK_H
79110 +
79111 +extern void gr_attach_curr_ip(const struct sock *sk);
79112 +extern int gr_handle_sock_all(const int family, const int type,
79113 + const int protocol);
79114 +extern int gr_handle_sock_server(const struct sockaddr *sck);
79115 +extern int gr_handle_sock_server_other(const struct sock *sck);
79116 +extern int gr_handle_sock_client(const struct sockaddr *sck);
79117 +extern int gr_search_connect(struct socket * sock,
79118 + struct sockaddr_in * addr);
79119 +extern int gr_search_bind(struct socket * sock,
79120 + struct sockaddr_in * addr);
79121 +extern int gr_search_listen(struct socket * sock);
79122 +extern int gr_search_accept(struct socket * sock);
79123 +extern int gr_search_socket(const int domain, const int type,
79124 + const int protocol);
79125 +
79126 +#endif
79127 diff --git a/include/linux/hash.h b/include/linux/hash.h
79128 index bd1754c..8240892 100644
79129 --- a/include/linux/hash.h
79130 +++ b/include/linux/hash.h
79131 @@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
79132 struct fast_hash_ops {
79133 u32 (*hash)(const void *data, u32 len, u32 seed);
79134 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
79135 -};
79136 +} __no_const;
79137
79138 /**
79139 * arch_fast_hash - Caclulates a hash over a given buffer that can have
79140 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79141 index 7fb31da..08b5114 100644
79142 --- a/include/linux/highmem.h
79143 +++ b/include/linux/highmem.h
79144 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79145 kunmap_atomic(kaddr);
79146 }
79147
79148 +static inline void sanitize_highpage(struct page *page)
79149 +{
79150 + void *kaddr;
79151 + unsigned long flags;
79152 +
79153 + local_irq_save(flags);
79154 + kaddr = kmap_atomic(page);
79155 + clear_page(kaddr);
79156 + kunmap_atomic(kaddr);
79157 + local_irq_restore(flags);
79158 +}
79159 +
79160 static inline void zero_user_segments(struct page *page,
79161 unsigned start1, unsigned end1,
79162 unsigned start2, unsigned end2)
79163 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79164 index 1c7b89a..7dda400 100644
79165 --- a/include/linux/hwmon-sysfs.h
79166 +++ b/include/linux/hwmon-sysfs.h
79167 @@ -25,7 +25,8 @@
79168 struct sensor_device_attribute{
79169 struct device_attribute dev_attr;
79170 int index;
79171 -};
79172 +} __do_const;
79173 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
79174 #define to_sensor_dev_attr(_dev_attr) \
79175 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
79176
79177 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
79178 struct device_attribute dev_attr;
79179 u8 index;
79180 u8 nr;
79181 -};
79182 +} __do_const;
79183 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
79184 #define to_sensor_dev_attr_2(_dev_attr) \
79185 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
79186
79187 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
79188 index deddeb8..bcaf62d 100644
79189 --- a/include/linux/i2c.h
79190 +++ b/include/linux/i2c.h
79191 @@ -378,6 +378,7 @@ struct i2c_algorithm {
79192 /* To determine what the adapter supports */
79193 u32 (*functionality) (struct i2c_adapter *);
79194 };
79195 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
79196
79197 /**
79198 * struct i2c_bus_recovery_info - I2C bus recovery information
79199 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
79200 index d23c3c2..eb63c81 100644
79201 --- a/include/linux/i2o.h
79202 +++ b/include/linux/i2o.h
79203 @@ -565,7 +565,7 @@ struct i2o_controller {
79204 struct i2o_device *exec; /* Executive */
79205 #if BITS_PER_LONG == 64
79206 spinlock_t context_list_lock; /* lock for context_list */
79207 - atomic_t context_list_counter; /* needed for unique contexts */
79208 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
79209 struct list_head context_list; /* list of context id's
79210 and pointers */
79211 #endif
79212 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
79213 index aff7ad8..3942bbd 100644
79214 --- a/include/linux/if_pppox.h
79215 +++ b/include/linux/if_pppox.h
79216 @@ -76,7 +76,7 @@ struct pppox_proto {
79217 int (*ioctl)(struct socket *sock, unsigned int cmd,
79218 unsigned long arg);
79219 struct module *owner;
79220 -};
79221 +} __do_const;
79222
79223 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
79224 extern void unregister_pppox_proto(int proto_num);
79225 diff --git a/include/linux/init.h b/include/linux/init.h
79226 index e168880..d9b489d 100644
79227 --- a/include/linux/init.h
79228 +++ b/include/linux/init.h
79229 @@ -37,9 +37,17 @@
79230 * section.
79231 */
79232
79233 +#define add_init_latent_entropy __latent_entropy
79234 +
79235 +#ifdef CONFIG_MEMORY_HOTPLUG
79236 +#define add_meminit_latent_entropy
79237 +#else
79238 +#define add_meminit_latent_entropy __latent_entropy
79239 +#endif
79240 +
79241 /* These are for everybody (although not all archs will actually
79242 discard it in modules) */
79243 -#define __init __section(.init.text) __cold notrace
79244 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
79245 #define __initdata __section(.init.data)
79246 #define __initconst __constsection(.init.rodata)
79247 #define __exitdata __section(.exit.data)
79248 @@ -100,7 +108,7 @@
79249 #define __cpuexitconst
79250
79251 /* Used for MEMORY_HOTPLUG */
79252 -#define __meminit __section(.meminit.text) __cold notrace
79253 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
79254 #define __meminitdata __section(.meminit.data)
79255 #define __meminitconst __constsection(.meminit.rodata)
79256 #define __memexit __section(.memexit.text) __exitused __cold notrace
79257 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
79258 index 6df7f9f..d0bf699 100644
79259 --- a/include/linux/init_task.h
79260 +++ b/include/linux/init_task.h
79261 @@ -156,6 +156,12 @@ extern struct task_group root_task_group;
79262
79263 #define INIT_TASK_COMM "swapper"
79264
79265 +#ifdef CONFIG_X86
79266 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
79267 +#else
79268 +#define INIT_TASK_THREAD_INFO
79269 +#endif
79270 +
79271 #ifdef CONFIG_RT_MUTEXES
79272 # define INIT_RT_MUTEXES(tsk) \
79273 .pi_waiters = RB_ROOT, \
79274 @@ -203,6 +209,7 @@ extern struct task_group root_task_group;
79275 RCU_POINTER_INITIALIZER(cred, &init_cred), \
79276 .comm = INIT_TASK_COMM, \
79277 .thread = INIT_THREAD, \
79278 + INIT_TASK_THREAD_INFO \
79279 .fs = &init_fs, \
79280 .files = &init_files, \
79281 .signal = &init_signals, \
79282 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
79283 index a2678d3..e411b1b 100644
79284 --- a/include/linux/interrupt.h
79285 +++ b/include/linux/interrupt.h
79286 @@ -373,8 +373,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
79287
79288 struct softirq_action
79289 {
79290 - void (*action)(struct softirq_action *);
79291 -};
79292 + void (*action)(void);
79293 +} __no_const;
79294
79295 asmlinkage void do_softirq(void);
79296 asmlinkage void __do_softirq(void);
79297 @@ -388,7 +388,7 @@ static inline void do_softirq_own_stack(void)
79298 }
79299 #endif
79300
79301 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
79302 +extern void open_softirq(int nr, void (*action)(void));
79303 extern void softirq_init(void);
79304 extern void __raise_softirq_irqoff(unsigned int nr);
79305
79306 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
79307 index b96a5b2..2732d1c 100644
79308 --- a/include/linux/iommu.h
79309 +++ b/include/linux/iommu.h
79310 @@ -131,7 +131,7 @@ struct iommu_ops {
79311 u32 (*domain_get_windows)(struct iommu_domain *domain);
79312
79313 unsigned long pgsize_bitmap;
79314 -};
79315 +} __do_const;
79316
79317 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
79318 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
79319 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
79320 index 89b7c24..382af74 100644
79321 --- a/include/linux/ioport.h
79322 +++ b/include/linux/ioport.h
79323 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
79324 int adjust_resource(struct resource *res, resource_size_t start,
79325 resource_size_t size);
79326 resource_size_t resource_alignment(struct resource *res);
79327 -static inline resource_size_t resource_size(const struct resource *res)
79328 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
79329 {
79330 return res->end - res->start + 1;
79331 }
79332 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
79333 index 35e7eca..6afb7ad 100644
79334 --- a/include/linux/ipc_namespace.h
79335 +++ b/include/linux/ipc_namespace.h
79336 @@ -69,7 +69,7 @@ struct ipc_namespace {
79337 struct user_namespace *user_ns;
79338
79339 unsigned int proc_inum;
79340 -};
79341 +} __randomize_layout;
79342
79343 extern struct ipc_namespace init_ipc_ns;
79344 extern atomic_t nr_ipc_ns;
79345 diff --git a/include/linux/irq.h b/include/linux/irq.h
79346 index 7dc1003..407327b 100644
79347 --- a/include/linux/irq.h
79348 +++ b/include/linux/irq.h
79349 @@ -338,7 +338,8 @@ struct irq_chip {
79350 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
79351
79352 unsigned long flags;
79353 -};
79354 +} __do_const;
79355 +typedef struct irq_chip __no_const irq_chip_no_const;
79356
79357 /*
79358 * irq_chip specific flags
79359 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
79360 index 0ceb389..eed3fb8 100644
79361 --- a/include/linux/irqchip/arm-gic.h
79362 +++ b/include/linux/irqchip/arm-gic.h
79363 @@ -73,9 +73,11 @@
79364
79365 #ifndef __ASSEMBLY__
79366
79367 +#include <linux/irq.h>
79368 +
79369 struct device_node;
79370
79371 -extern struct irq_chip gic_arch_extn;
79372 +extern irq_chip_no_const gic_arch_extn;
79373
79374 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
79375 u32 offset, struct device_node *);
79376 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
79377 index 1f44466..b481806 100644
79378 --- a/include/linux/jiffies.h
79379 +++ b/include/linux/jiffies.h
79380 @@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
79381 /*
79382 * Convert various time units to each other:
79383 */
79384 -extern unsigned int jiffies_to_msecs(const unsigned long j);
79385 -extern unsigned int jiffies_to_usecs(const unsigned long j);
79386 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
79387 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
79388
79389 -static inline u64 jiffies_to_nsecs(const unsigned long j)
79390 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
79391 {
79392 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
79393 }
79394
79395 -extern unsigned long msecs_to_jiffies(const unsigned int m);
79396 -extern unsigned long usecs_to_jiffies(const unsigned int u);
79397 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
79398 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
79399 extern unsigned long timespec_to_jiffies(const struct timespec *value);
79400 extern void jiffies_to_timespec(const unsigned long jiffies,
79401 - struct timespec *value);
79402 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
79403 + struct timespec *value) __intentional_overflow(-1);
79404 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
79405 extern void jiffies_to_timeval(const unsigned long jiffies,
79406 struct timeval *value);
79407
79408 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
79409 index 6883e19..e854fcb 100644
79410 --- a/include/linux/kallsyms.h
79411 +++ b/include/linux/kallsyms.h
79412 @@ -15,7 +15,8 @@
79413
79414 struct module;
79415
79416 -#ifdef CONFIG_KALLSYMS
79417 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
79418 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
79419 /* Lookup the address for a symbol. Returns 0 if not found. */
79420 unsigned long kallsyms_lookup_name(const char *name);
79421
79422 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
79423 /* Stupid that this does nothing, but I didn't create this mess. */
79424 #define __print_symbol(fmt, addr)
79425 #endif /*CONFIG_KALLSYMS*/
79426 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
79427 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
79428 +extern unsigned long kallsyms_lookup_name(const char *name);
79429 +extern void __print_symbol(const char *fmt, unsigned long address);
79430 +extern int sprint_backtrace(char *buffer, unsigned long address);
79431 +extern int sprint_symbol(char *buffer, unsigned long address);
79432 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
79433 +const char *kallsyms_lookup(unsigned long addr,
79434 + unsigned long *symbolsize,
79435 + unsigned long *offset,
79436 + char **modname, char *namebuf);
79437 +extern int kallsyms_lookup_size_offset(unsigned long addr,
79438 + unsigned long *symbolsize,
79439 + unsigned long *offset);
79440 +#endif
79441
79442 /* This macro allows us to keep printk typechecking */
79443 static __printf(1, 2)
79444 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
79445 index a74c3a8..28d3f21 100644
79446 --- a/include/linux/key-type.h
79447 +++ b/include/linux/key-type.h
79448 @@ -131,7 +131,7 @@ struct key_type {
79449 /* internal fields */
79450 struct list_head link; /* link in types list */
79451 struct lock_class_key lock_class; /* key->sem lock class */
79452 -};
79453 +} __do_const;
79454
79455 extern struct key_type key_type_keyring;
79456
79457 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
79458 index 6b06d37..c134867 100644
79459 --- a/include/linux/kgdb.h
79460 +++ b/include/linux/kgdb.h
79461 @@ -52,7 +52,7 @@ extern int kgdb_connected;
79462 extern int kgdb_io_module_registered;
79463
79464 extern atomic_t kgdb_setting_breakpoint;
79465 -extern atomic_t kgdb_cpu_doing_single_step;
79466 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
79467
79468 extern struct task_struct *kgdb_usethread;
79469 extern struct task_struct *kgdb_contthread;
79470 @@ -254,7 +254,7 @@ struct kgdb_arch {
79471 void (*correct_hw_break)(void);
79472
79473 void (*enable_nmi)(bool on);
79474 -};
79475 +} __do_const;
79476
79477 /**
79478 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
79479 @@ -279,7 +279,7 @@ struct kgdb_io {
79480 void (*pre_exception) (void);
79481 void (*post_exception) (void);
79482 int is_console;
79483 -};
79484 +} __do_const;
79485
79486 extern struct kgdb_arch arch_kgdb_ops;
79487
79488 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
79489 index 0555cc6..40116ce 100644
79490 --- a/include/linux/kmod.h
79491 +++ b/include/linux/kmod.h
79492 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
79493 * usually useless though. */
79494 extern __printf(2, 3)
79495 int __request_module(bool wait, const char *name, ...);
79496 +extern __printf(3, 4)
79497 +int ___request_module(bool wait, char *param_name, const char *name, ...);
79498 #define request_module(mod...) __request_module(true, mod)
79499 #define request_module_nowait(mod...) __request_module(false, mod)
79500 #define try_then_request_module(x, mod...) \
79501 @@ -57,6 +59,9 @@ struct subprocess_info {
79502 struct work_struct work;
79503 struct completion *complete;
79504 char *path;
79505 +#ifdef CONFIG_GRKERNSEC
79506 + char *origpath;
79507 +#endif
79508 char **argv;
79509 char **envp;
79510 int wait;
79511 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
79512 index 926afb6..58dd6e5 100644
79513 --- a/include/linux/kobject.h
79514 +++ b/include/linux/kobject.h
79515 @@ -116,7 +116,7 @@ struct kobj_type {
79516 struct attribute **default_attrs;
79517 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
79518 const void *(*namespace)(struct kobject *kobj);
79519 -};
79520 +} __do_const;
79521
79522 struct kobj_uevent_env {
79523 char *envp[UEVENT_NUM_ENVP];
79524 @@ -139,6 +139,7 @@ struct kobj_attribute {
79525 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
79526 const char *buf, size_t count);
79527 };
79528 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
79529
79530 extern const struct sysfs_ops kobj_sysfs_ops;
79531
79532 @@ -166,7 +167,7 @@ struct kset {
79533 spinlock_t list_lock;
79534 struct kobject kobj;
79535 const struct kset_uevent_ops *uevent_ops;
79536 -};
79537 +} __randomize_layout;
79538
79539 extern void kset_init(struct kset *kset);
79540 extern int __must_check kset_register(struct kset *kset);
79541 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
79542 index df32d25..fb52e27 100644
79543 --- a/include/linux/kobject_ns.h
79544 +++ b/include/linux/kobject_ns.h
79545 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
79546 const void *(*netlink_ns)(struct sock *sk);
79547 const void *(*initial_ns)(void);
79548 void (*drop_ns)(void *);
79549 -};
79550 +} __do_const;
79551
79552 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
79553 int kobj_ns_type_registered(enum kobj_ns_type type);
79554 diff --git a/include/linux/kref.h b/include/linux/kref.h
79555 index 484604d..0f6c5b6 100644
79556 --- a/include/linux/kref.h
79557 +++ b/include/linux/kref.h
79558 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
79559 static inline int kref_sub(struct kref *kref, unsigned int count,
79560 void (*release)(struct kref *kref))
79561 {
79562 - WARN_ON(release == NULL);
79563 + BUG_ON(release == NULL);
79564
79565 if (atomic_sub_and_test((int) count, &kref->refcount)) {
79566 release(kref);
79567 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
79568 index b8e9a43..632678d 100644
79569 --- a/include/linux/kvm_host.h
79570 +++ b/include/linux/kvm_host.h
79571 @@ -455,7 +455,7 @@ static inline void kvm_irqfd_exit(void)
79572 {
79573 }
79574 #endif
79575 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79576 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79577 struct module *module);
79578 void kvm_exit(void);
79579
79580 @@ -621,7 +621,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
79581 struct kvm_guest_debug *dbg);
79582 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
79583
79584 -int kvm_arch_init(void *opaque);
79585 +int kvm_arch_init(const void *opaque);
79586 void kvm_arch_exit(void);
79587
79588 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
79589 diff --git a/include/linux/libata.h b/include/linux/libata.h
79590 index bec6dbe..2873d64 100644
79591 --- a/include/linux/libata.h
79592 +++ b/include/linux/libata.h
79593 @@ -975,7 +975,7 @@ struct ata_port_operations {
79594 * fields must be pointers.
79595 */
79596 const struct ata_port_operations *inherits;
79597 -};
79598 +} __do_const;
79599
79600 struct ata_port_info {
79601 unsigned long flags;
79602 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
79603 index a6a42dd..6c5ebce 100644
79604 --- a/include/linux/linkage.h
79605 +++ b/include/linux/linkage.h
79606 @@ -36,6 +36,7 @@
79607 #endif
79608
79609 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
79610 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
79611 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
79612
79613 /*
79614 diff --git a/include/linux/list.h b/include/linux/list.h
79615 index ef95941..82db65a 100644
79616 --- a/include/linux/list.h
79617 +++ b/include/linux/list.h
79618 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
79619 extern void list_del(struct list_head *entry);
79620 #endif
79621
79622 +extern void __pax_list_add(struct list_head *new,
79623 + struct list_head *prev,
79624 + struct list_head *next);
79625 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
79626 +{
79627 + __pax_list_add(new, head, head->next);
79628 +}
79629 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
79630 +{
79631 + __pax_list_add(new, head->prev, head);
79632 +}
79633 +extern void pax_list_del(struct list_head *entry);
79634 +
79635 /**
79636 * list_replace - replace old entry by new one
79637 * @old : the element to be replaced
79638 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
79639 INIT_LIST_HEAD(entry);
79640 }
79641
79642 +extern void pax_list_del_init(struct list_head *entry);
79643 +
79644 /**
79645 * list_move - delete from one list and add as another's head
79646 * @list: the entry to move
79647 diff --git a/include/linux/math64.h b/include/linux/math64.h
79648 index c45c089..298841c 100644
79649 --- a/include/linux/math64.h
79650 +++ b/include/linux/math64.h
79651 @@ -15,7 +15,7 @@
79652 * This is commonly provided by 32bit archs to provide an optimized 64bit
79653 * divide.
79654 */
79655 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79656 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79657 {
79658 *remainder = dividend % divisor;
79659 return dividend / divisor;
79660 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
79661 /**
79662 * div64_u64 - unsigned 64bit divide with 64bit divisor
79663 */
79664 -static inline u64 div64_u64(u64 dividend, u64 divisor)
79665 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
79666 {
79667 return dividend / divisor;
79668 }
79669 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
79670 #define div64_ul(x, y) div_u64((x), (y))
79671
79672 #ifndef div_u64_rem
79673 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79674 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79675 {
79676 *remainder = do_div(dividend, divisor);
79677 return dividend;
79678 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
79679 #endif
79680
79681 #ifndef div64_u64
79682 -extern u64 div64_u64(u64 dividend, u64 divisor);
79683 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
79684 #endif
79685
79686 #ifndef div64_s64
79687 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
79688 * divide.
79689 */
79690 #ifndef div_u64
79691 -static inline u64 div_u64(u64 dividend, u32 divisor)
79692 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
79693 {
79694 u32 remainder;
79695 return div_u64_rem(dividend, divisor, &remainder);
79696 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
79697 index 5f1ea75..5125ac5 100644
79698 --- a/include/linux/mempolicy.h
79699 +++ b/include/linux/mempolicy.h
79700 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
79701 }
79702
79703 #define vma_policy(vma) ((vma)->vm_policy)
79704 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79705 +{
79706 + vma->vm_policy = pol;
79707 +}
79708
79709 static inline void mpol_get(struct mempolicy *pol)
79710 {
79711 @@ -223,6 +227,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
79712 }
79713
79714 #define vma_policy(vma) NULL
79715 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79716 +{
79717 +}
79718
79719 static inline int
79720 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
79721 diff --git a/include/linux/mm.h b/include/linux/mm.h
79722 index c1b7414..5ea2ad8 100644
79723 --- a/include/linux/mm.h
79724 +++ b/include/linux/mm.h
79725 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
79726 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
79727 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
79728 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
79729 +
79730 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
79731 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
79732 +#endif
79733 +
79734 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
79735
79736 #ifdef CONFIG_MEM_SOFT_DIRTY
79737 @@ -229,8 +234,8 @@ struct vm_operations_struct {
79738 /* called by access_process_vm when get_user_pages() fails, typically
79739 * for use by special VMAs that can switch between memory and hardware
79740 */
79741 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
79742 - void *buf, int len, int write);
79743 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
79744 + void *buf, size_t len, int write);
79745 #ifdef CONFIG_NUMA
79746 /*
79747 * set_policy() op must add a reference to any non-NULL @new mempolicy
79748 @@ -260,6 +265,7 @@ struct vm_operations_struct {
79749 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
79750 unsigned long size, pgoff_t pgoff);
79751 };
79752 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
79753
79754 struct mmu_gather;
79755 struct inode;
79756 @@ -1112,8 +1118,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
79757 unsigned long *pfn);
79758 int follow_phys(struct vm_area_struct *vma, unsigned long address,
79759 unsigned int flags, unsigned long *prot, resource_size_t *phys);
79760 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
79761 - void *buf, int len, int write);
79762 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
79763 + void *buf, size_t len, int write);
79764
79765 static inline void unmap_shared_mapping_range(struct address_space *mapping,
79766 loff_t const holebegin, loff_t const holelen)
79767 @@ -1152,9 +1158,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
79768 }
79769 #endif
79770
79771 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
79772 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
79773 - void *buf, int len, int write);
79774 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
79775 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
79776 + void *buf, size_t len, int write);
79777
79778 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79779 unsigned long start, unsigned long nr_pages,
79780 @@ -1186,34 +1192,6 @@ int set_page_dirty(struct page *page);
79781 int set_page_dirty_lock(struct page *page);
79782 int clear_page_dirty_for_io(struct page *page);
79783
79784 -/* Is the vma a continuation of the stack vma above it? */
79785 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
79786 -{
79787 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
79788 -}
79789 -
79790 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
79791 - unsigned long addr)
79792 -{
79793 - return (vma->vm_flags & VM_GROWSDOWN) &&
79794 - (vma->vm_start == addr) &&
79795 - !vma_growsdown(vma->vm_prev, addr);
79796 -}
79797 -
79798 -/* Is the vma a continuation of the stack vma below it? */
79799 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
79800 -{
79801 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
79802 -}
79803 -
79804 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
79805 - unsigned long addr)
79806 -{
79807 - return (vma->vm_flags & VM_GROWSUP) &&
79808 - (vma->vm_end == addr) &&
79809 - !vma_growsup(vma->vm_next, addr);
79810 -}
79811 -
79812 extern pid_t
79813 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
79814
79815 @@ -1313,6 +1291,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
79816 }
79817 #endif
79818
79819 +#ifdef CONFIG_MMU
79820 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
79821 +#else
79822 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
79823 +{
79824 + return __pgprot(0);
79825 +}
79826 +#endif
79827 +
79828 int vma_wants_writenotify(struct vm_area_struct *vma);
79829
79830 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
79831 @@ -1331,8 +1318,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
79832 {
79833 return 0;
79834 }
79835 +
79836 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
79837 + unsigned long address)
79838 +{
79839 + return 0;
79840 +}
79841 #else
79842 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79843 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79844 #endif
79845
79846 #ifdef __PAGETABLE_PMD_FOLDED
79847 @@ -1341,8 +1335,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
79848 {
79849 return 0;
79850 }
79851 +
79852 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
79853 + unsigned long address)
79854 +{
79855 + return 0;
79856 +}
79857 #else
79858 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
79859 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
79860 #endif
79861
79862 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
79863 @@ -1360,11 +1361,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
79864 NULL: pud_offset(pgd, address);
79865 }
79866
79867 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79868 +{
79869 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
79870 + NULL: pud_offset(pgd, address);
79871 +}
79872 +
79873 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
79874 {
79875 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
79876 NULL: pmd_offset(pud, address);
79877 }
79878 +
79879 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
79880 +{
79881 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
79882 + NULL: pmd_offset(pud, address);
79883 +}
79884 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
79885
79886 #if USE_SPLIT_PTE_PTLOCKS
79887 @@ -1754,7 +1767,7 @@ extern int install_special_mapping(struct mm_struct *mm,
79888 unsigned long addr, unsigned long len,
79889 unsigned long flags, struct page **pages);
79890
79891 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
79892 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
79893
79894 extern unsigned long mmap_region(struct file *file, unsigned long addr,
79895 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
79896 @@ -1762,6 +1775,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
79897 unsigned long len, unsigned long prot, unsigned long flags,
79898 unsigned long pgoff, unsigned long *populate);
79899 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
79900 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
79901
79902 #ifdef CONFIG_MMU
79903 extern int __mm_populate(unsigned long addr, unsigned long len,
79904 @@ -1790,10 +1804,11 @@ struct vm_unmapped_area_info {
79905 unsigned long high_limit;
79906 unsigned long align_mask;
79907 unsigned long align_offset;
79908 + unsigned long threadstack_offset;
79909 };
79910
79911 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
79912 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
79913 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
79914 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
79915
79916 /*
79917 * Search for an unmapped address range.
79918 @@ -1805,7 +1820,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
79919 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
79920 */
79921 static inline unsigned long
79922 -vm_unmapped_area(struct vm_unmapped_area_info *info)
79923 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
79924 {
79925 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
79926 return unmapped_area(info);
79927 @@ -1868,6 +1883,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
79928 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
79929 struct vm_area_struct **pprev);
79930
79931 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
79932 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
79933 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
79934 +
79935 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
79936 NULL if none. Assume start_addr < end_addr. */
79937 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
79938 @@ -1896,15 +1915,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
79939 return vma;
79940 }
79941
79942 -#ifdef CONFIG_MMU
79943 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
79944 -#else
79945 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
79946 -{
79947 - return __pgprot(0);
79948 -}
79949 -#endif
79950 -
79951 #ifdef CONFIG_NUMA_BALANCING
79952 unsigned long change_prot_numa(struct vm_area_struct *vma,
79953 unsigned long start, unsigned long end);
79954 @@ -1956,6 +1966,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
79955 static inline void vm_stat_account(struct mm_struct *mm,
79956 unsigned long flags, struct file *file, long pages)
79957 {
79958 +
79959 +#ifdef CONFIG_PAX_RANDMMAP
79960 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
79961 +#endif
79962 +
79963 mm->total_vm += pages;
79964 }
79965 #endif /* CONFIG_PROC_FS */
79966 @@ -2037,7 +2052,7 @@ extern int unpoison_memory(unsigned long pfn);
79967 extern int sysctl_memory_failure_early_kill;
79968 extern int sysctl_memory_failure_recovery;
79969 extern void shake_page(struct page *p, int access);
79970 -extern atomic_long_t num_poisoned_pages;
79971 +extern atomic_long_unchecked_t num_poisoned_pages;
79972 extern int soft_offline_page(struct page *page, int flags);
79973
79974 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
79975 @@ -2072,5 +2087,11 @@ void __init setup_nr_node_ids(void);
79976 static inline void setup_nr_node_ids(void) {}
79977 #endif
79978
79979 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
79980 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
79981 +#else
79982 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
79983 +#endif
79984 +
79985 #endif /* __KERNEL__ */
79986 #endif /* _LINUX_MM_H */
79987 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
79988 index 290901a..e99b01c 100644
79989 --- a/include/linux/mm_types.h
79990 +++ b/include/linux/mm_types.h
79991 @@ -307,7 +307,9 @@ struct vm_area_struct {
79992 #ifdef CONFIG_NUMA
79993 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
79994 #endif
79995 -};
79996 +
79997 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
79998 +} __randomize_layout;
79999
80000 struct core_thread {
80001 struct task_struct *task;
80002 @@ -453,7 +455,25 @@ struct mm_struct {
80003 bool tlb_flush_pending;
80004 #endif
80005 struct uprobes_state uprobes_state;
80006 -};
80007 +
80008 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80009 + unsigned long pax_flags;
80010 +#endif
80011 +
80012 +#ifdef CONFIG_PAX_DLRESOLVE
80013 + unsigned long call_dl_resolve;
80014 +#endif
80015 +
80016 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80017 + unsigned long call_syscall;
80018 +#endif
80019 +
80020 +#ifdef CONFIG_PAX_ASLR
80021 + unsigned long delta_mmap; /* randomized offset */
80022 + unsigned long delta_stack; /* randomized offset */
80023 +#endif
80024 +
80025 +} __randomize_layout;
80026
80027 static inline void mm_init_cpumask(struct mm_struct *mm)
80028 {
80029 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80030 index c5d5278..f0b68c8 100644
80031 --- a/include/linux/mmiotrace.h
80032 +++ b/include/linux/mmiotrace.h
80033 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80034 /* Called from ioremap.c */
80035 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80036 void __iomem *addr);
80037 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
80038 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80039
80040 /* For anyone to insert markers. Remember trailing newline. */
80041 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80042 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80043 {
80044 }
80045
80046 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80047 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80048 {
80049 }
80050
80051 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80052 index 9b61b9b..52147d6b 100644
80053 --- a/include/linux/mmzone.h
80054 +++ b/include/linux/mmzone.h
80055 @@ -396,7 +396,7 @@ struct zone {
80056 unsigned long flags; /* zone flags, see below */
80057
80058 /* Zone statistics */
80059 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80060 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80061
80062 /*
80063 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80064 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80065 index 45e9214..a7227d6 100644
80066 --- a/include/linux/mod_devicetable.h
80067 +++ b/include/linux/mod_devicetable.h
80068 @@ -13,7 +13,7 @@
80069 typedef unsigned long kernel_ulong_t;
80070 #endif
80071
80072 -#define PCI_ANY_ID (~0)
80073 +#define PCI_ANY_ID ((__u16)~0)
80074
80075 struct pci_device_id {
80076 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
80077 @@ -139,7 +139,7 @@ struct usb_device_id {
80078 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80079 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80080
80081 -#define HID_ANY_ID (~0)
80082 +#define HID_ANY_ID (~0U)
80083 #define HID_BUS_ANY 0xffff
80084 #define HID_GROUP_ANY 0x0000
80085
80086 @@ -467,7 +467,7 @@ struct dmi_system_id {
80087 const char *ident;
80088 struct dmi_strmatch matches[4];
80089 void *driver_data;
80090 -};
80091 +} __do_const;
80092 /*
80093 * struct dmi_device_id appears during expansion of
80094 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80095 diff --git a/include/linux/module.h b/include/linux/module.h
80096 index eaf60ff..641979a 100644
80097 --- a/include/linux/module.h
80098 +++ b/include/linux/module.h
80099 @@ -17,9 +17,11 @@
80100 #include <linux/moduleparam.h>
80101 #include <linux/tracepoint.h>
80102 #include <linux/export.h>
80103 +#include <linux/fs.h>
80104
80105 #include <linux/percpu.h>
80106 #include <asm/module.h>
80107 +#include <asm/pgtable.h>
80108
80109 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80110 #define MODULE_SIG_STRING "~Module signature appended~\n"
80111 @@ -42,7 +44,7 @@ struct module_kobject {
80112 struct kobject *drivers_dir;
80113 struct module_param_attrs *mp;
80114 struct completion *kobj_completion;
80115 -};
80116 +} __randomize_layout;
80117
80118 struct module_attribute {
80119 struct attribute attr;
80120 @@ -54,12 +56,13 @@ struct module_attribute {
80121 int (*test)(struct module *);
80122 void (*free)(struct module *);
80123 };
80124 +typedef struct module_attribute __no_const module_attribute_no_const;
80125
80126 struct module_version_attribute {
80127 struct module_attribute mattr;
80128 const char *module_name;
80129 const char *version;
80130 -} __attribute__ ((__aligned__(sizeof(void *))));
80131 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80132
80133 extern ssize_t __modver_version_show(struct module_attribute *,
80134 struct module_kobject *, char *);
80135 @@ -238,7 +241,7 @@ struct module {
80136
80137 /* Sysfs stuff. */
80138 struct module_kobject mkobj;
80139 - struct module_attribute *modinfo_attrs;
80140 + module_attribute_no_const *modinfo_attrs;
80141 const char *version;
80142 const char *srcversion;
80143 struct kobject *holders_dir;
80144 @@ -287,19 +290,16 @@ struct module {
80145 int (*init)(void);
80146
80147 /* If this is non-NULL, vfree after init() returns */
80148 - void *module_init;
80149 + void *module_init_rx, *module_init_rw;
80150
80151 /* Here is the actual code + data, vfree'd on unload. */
80152 - void *module_core;
80153 + void *module_core_rx, *module_core_rw;
80154
80155 /* Here are the sizes of the init and core sections */
80156 - unsigned int init_size, core_size;
80157 + unsigned int init_size_rw, core_size_rw;
80158
80159 /* The size of the executable code in each section. */
80160 - unsigned int init_text_size, core_text_size;
80161 -
80162 - /* Size of RO sections of the module (text+rodata) */
80163 - unsigned int init_ro_size, core_ro_size;
80164 + unsigned int init_size_rx, core_size_rx;
80165
80166 /* Arch-specific module values */
80167 struct mod_arch_specific arch;
80168 @@ -355,6 +355,10 @@ struct module {
80169 #ifdef CONFIG_EVENT_TRACING
80170 struct ftrace_event_call **trace_events;
80171 unsigned int num_trace_events;
80172 + struct file_operations trace_id;
80173 + struct file_operations trace_enable;
80174 + struct file_operations trace_format;
80175 + struct file_operations trace_filter;
80176 #endif
80177 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
80178 unsigned int num_ftrace_callsites;
80179 @@ -378,7 +382,7 @@ struct module {
80180 ctor_fn_t *ctors;
80181 unsigned int num_ctors;
80182 #endif
80183 -};
80184 +} __randomize_layout;
80185 #ifndef MODULE_ARCH_INIT
80186 #define MODULE_ARCH_INIT {}
80187 #endif
80188 @@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
80189 bool is_module_percpu_address(unsigned long addr);
80190 bool is_module_text_address(unsigned long addr);
80191
80192 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
80193 +{
80194 +
80195 +#ifdef CONFIG_PAX_KERNEXEC
80196 + if (ktla_ktva(addr) >= (unsigned long)start &&
80197 + ktla_ktva(addr) < (unsigned long)start + size)
80198 + return 1;
80199 +#endif
80200 +
80201 + return ((void *)addr >= start && (void *)addr < start + size);
80202 +}
80203 +
80204 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
80205 +{
80206 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
80207 +}
80208 +
80209 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
80210 +{
80211 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
80212 +}
80213 +
80214 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
80215 +{
80216 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
80217 +}
80218 +
80219 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
80220 +{
80221 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
80222 +}
80223 +
80224 static inline int within_module_core(unsigned long addr, const struct module *mod)
80225 {
80226 - return (unsigned long)mod->module_core <= addr &&
80227 - addr < (unsigned long)mod->module_core + mod->core_size;
80228 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
80229 }
80230
80231 static inline int within_module_init(unsigned long addr, const struct module *mod)
80232 {
80233 - return (unsigned long)mod->module_init <= addr &&
80234 - addr < (unsigned long)mod->module_init + mod->init_size;
80235 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
80236 }
80237
80238 /* Search for module by name: must hold module_mutex. */
80239 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
80240 index 560ca53..ef621ef 100644
80241 --- a/include/linux/moduleloader.h
80242 +++ b/include/linux/moduleloader.h
80243 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
80244 sections. Returns NULL on failure. */
80245 void *module_alloc(unsigned long size);
80246
80247 +#ifdef CONFIG_PAX_KERNEXEC
80248 +void *module_alloc_exec(unsigned long size);
80249 +#else
80250 +#define module_alloc_exec(x) module_alloc(x)
80251 +#endif
80252 +
80253 /* Free memory returned from module_alloc. */
80254 void module_free(struct module *mod, void *module_region);
80255
80256 +#ifdef CONFIG_PAX_KERNEXEC
80257 +void module_free_exec(struct module *mod, void *module_region);
80258 +#else
80259 +#define module_free_exec(x, y) module_free((x), (y))
80260 +#endif
80261 +
80262 /*
80263 * Apply the given relocation to the (simplified) ELF. Return -error
80264 * or 0.
80265 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
80266 unsigned int relsec,
80267 struct module *me)
80268 {
80269 +#ifdef CONFIG_MODULES
80270 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80271 +#endif
80272 return -ENOEXEC;
80273 }
80274 #endif
80275 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
80276 unsigned int relsec,
80277 struct module *me)
80278 {
80279 +#ifdef CONFIG_MODULES
80280 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80281 +#endif
80282 return -ENOEXEC;
80283 }
80284 #endif
80285 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
80286 index c3eb102..073c4a6 100644
80287 --- a/include/linux/moduleparam.h
80288 +++ b/include/linux/moduleparam.h
80289 @@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
80290 * @len is usually just sizeof(string).
80291 */
80292 #define module_param_string(name, string, len, perm) \
80293 - static const struct kparam_string __param_string_##name \
80294 + static const struct kparam_string __param_string_##name __used \
80295 = { len, string }; \
80296 __module_param_call(MODULE_PARAM_PREFIX, name, \
80297 &param_ops_string, \
80298 @@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
80299 */
80300 #define module_param_array_named(name, array, type, nump, perm) \
80301 param_check_##type(name, &(array)[0]); \
80302 - static const struct kparam_array __param_arr_##name \
80303 + static const struct kparam_array __param_arr_##name __used \
80304 = { .max = ARRAY_SIZE(array), .num = nump, \
80305 .ops = &param_ops_##type, \
80306 .elemsize = sizeof(array[0]), .elem = array }; \
80307 diff --git a/include/linux/mount.h b/include/linux/mount.h
80308 index 371d346..fba2819 100644
80309 --- a/include/linux/mount.h
80310 +++ b/include/linux/mount.h
80311 @@ -56,7 +56,7 @@ struct vfsmount {
80312 struct dentry *mnt_root; /* root of the mounted tree */
80313 struct super_block *mnt_sb; /* pointer to superblock */
80314 int mnt_flags;
80315 -};
80316 +} __randomize_layout;
80317
80318 struct file; /* forward dec */
80319
80320 diff --git a/include/linux/namei.h b/include/linux/namei.h
80321 index 492de72..1bddcd4 100644
80322 --- a/include/linux/namei.h
80323 +++ b/include/linux/namei.h
80324 @@ -19,7 +19,7 @@ struct nameidata {
80325 unsigned seq, m_seq;
80326 int last_type;
80327 unsigned depth;
80328 - char *saved_names[MAX_NESTED_LINKS + 1];
80329 + const char *saved_names[MAX_NESTED_LINKS + 1];
80330 };
80331
80332 /*
80333 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
80334
80335 extern void nd_jump_link(struct nameidata *nd, struct path *path);
80336
80337 -static inline void nd_set_link(struct nameidata *nd, char *path)
80338 +static inline void nd_set_link(struct nameidata *nd, const char *path)
80339 {
80340 nd->saved_names[nd->depth] = path;
80341 }
80342
80343 -static inline char *nd_get_link(struct nameidata *nd)
80344 +static inline const char *nd_get_link(const struct nameidata *nd)
80345 {
80346 return nd->saved_names[nd->depth];
80347 }
80348 diff --git a/include/linux/net.h b/include/linux/net.h
80349 index 94734a6..d8d6931 100644
80350 --- a/include/linux/net.h
80351 +++ b/include/linux/net.h
80352 @@ -192,7 +192,7 @@ struct net_proto_family {
80353 int (*create)(struct net *net, struct socket *sock,
80354 int protocol, int kern);
80355 struct module *owner;
80356 -};
80357 +} __do_const;
80358
80359 struct iovec;
80360 struct kvec;
80361 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
80362 index daafd95..74c5d1e 100644
80363 --- a/include/linux/netdevice.h
80364 +++ b/include/linux/netdevice.h
80365 @@ -1146,6 +1146,7 @@ struct net_device_ops {
80366 struct net_device *dev,
80367 void *priv);
80368 };
80369 +typedef struct net_device_ops __no_const net_device_ops_no_const;
80370
80371 /*
80372 * The DEVICE structure.
80373 @@ -1228,7 +1229,7 @@ struct net_device {
80374 int iflink;
80375
80376 struct net_device_stats stats;
80377 - atomic_long_t rx_dropped; /* dropped packets by core network
80378 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
80379 * Do not use this in drivers.
80380 */
80381
80382 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
80383 index 2077489..a15e561 100644
80384 --- a/include/linux/netfilter.h
80385 +++ b/include/linux/netfilter.h
80386 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
80387 #endif
80388 /* Use the module struct to lock set/get code in place */
80389 struct module *owner;
80390 -};
80391 +} __do_const;
80392
80393 /* Function to register/unregister hook points. */
80394 int nf_register_hook(struct nf_hook_ops *reg);
80395 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
80396 index 28c7436..2d6156a 100644
80397 --- a/include/linux/netfilter/nfnetlink.h
80398 +++ b/include/linux/netfilter/nfnetlink.h
80399 @@ -19,7 +19,7 @@ struct nfnl_callback {
80400 const struct nlattr * const cda[]);
80401 const struct nla_policy *policy; /* netlink attribute policy */
80402 const u_int16_t attr_count; /* number of nlattr's */
80403 -};
80404 +} __do_const;
80405
80406 struct nfnetlink_subsystem {
80407 const char *name;
80408 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
80409 new file mode 100644
80410 index 0000000..33f4af8
80411 --- /dev/null
80412 +++ b/include/linux/netfilter/xt_gradm.h
80413 @@ -0,0 +1,9 @@
80414 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
80415 +#define _LINUX_NETFILTER_XT_GRADM_H 1
80416 +
80417 +struct xt_gradm_mtinfo {
80418 + __u16 flags;
80419 + __u16 invflags;
80420 +};
80421 +
80422 +#endif
80423 diff --git a/include/linux/nls.h b/include/linux/nls.h
80424 index 520681b..1d67ed2 100644
80425 --- a/include/linux/nls.h
80426 +++ b/include/linux/nls.h
80427 @@ -31,7 +31,7 @@ struct nls_table {
80428 const unsigned char *charset2upper;
80429 struct module *owner;
80430 struct nls_table *next;
80431 -};
80432 +} __do_const;
80433
80434 /* this value hold the maximum octet of charset */
80435 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
80436 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
80437 index d14a4c3..a078786 100644
80438 --- a/include/linux/notifier.h
80439 +++ b/include/linux/notifier.h
80440 @@ -54,7 +54,8 @@ struct notifier_block {
80441 notifier_fn_t notifier_call;
80442 struct notifier_block __rcu *next;
80443 int priority;
80444 -};
80445 +} __do_const;
80446 +typedef struct notifier_block __no_const notifier_block_no_const;
80447
80448 struct atomic_notifier_head {
80449 spinlock_t lock;
80450 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
80451 index b2a0f15..4d7da32 100644
80452 --- a/include/linux/oprofile.h
80453 +++ b/include/linux/oprofile.h
80454 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
80455 int oprofilefs_create_ro_ulong(struct dentry * root,
80456 char const * name, ulong * val);
80457
80458 -/** Create a file for read-only access to an atomic_t. */
80459 +/** Create a file for read-only access to an atomic_unchecked_t. */
80460 int oprofilefs_create_ro_atomic(struct dentry * root,
80461 - char const * name, atomic_t * val);
80462 + char const * name, atomic_unchecked_t * val);
80463
80464 /** create a directory */
80465 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
80466 diff --git a/include/linux/padata.h b/include/linux/padata.h
80467 index 4386946..f50c615 100644
80468 --- a/include/linux/padata.h
80469 +++ b/include/linux/padata.h
80470 @@ -129,7 +129,7 @@ struct parallel_data {
80471 struct padata_serial_queue __percpu *squeue;
80472 atomic_t reorder_objects;
80473 atomic_t refcnt;
80474 - atomic_t seq_nr;
80475 + atomic_unchecked_t seq_nr;
80476 struct padata_cpumask cpumask;
80477 spinlock_t lock ____cacheline_aligned;
80478 unsigned int processed;
80479 diff --git a/include/linux/path.h b/include/linux/path.h
80480 index d137218..be0c176 100644
80481 --- a/include/linux/path.h
80482 +++ b/include/linux/path.h
80483 @@ -1,13 +1,15 @@
80484 #ifndef _LINUX_PATH_H
80485 #define _LINUX_PATH_H
80486
80487 +#include <linux/compiler.h>
80488 +
80489 struct dentry;
80490 struct vfsmount;
80491
80492 struct path {
80493 struct vfsmount *mnt;
80494 struct dentry *dentry;
80495 -};
80496 +} __randomize_layout;
80497
80498 extern void path_get(const struct path *);
80499 extern void path_put(const struct path *);
80500 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
80501 index 5f2e559..7d59314 100644
80502 --- a/include/linux/pci_hotplug.h
80503 +++ b/include/linux/pci_hotplug.h
80504 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
80505 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
80506 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
80507 int (*reset_slot) (struct hotplug_slot *slot, int probe);
80508 -};
80509 +} __do_const;
80510 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
80511
80512 /**
80513 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
80514 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
80515 index e56b07f..aef789b 100644
80516 --- a/include/linux/perf_event.h
80517 +++ b/include/linux/perf_event.h
80518 @@ -328,8 +328,8 @@ struct perf_event {
80519
80520 enum perf_event_active_state state;
80521 unsigned int attach_state;
80522 - local64_t count;
80523 - atomic64_t child_count;
80524 + local64_t count; /* PaX: fix it one day */
80525 + atomic64_unchecked_t child_count;
80526
80527 /*
80528 * These are the total time in nanoseconds that the event
80529 @@ -380,8 +380,8 @@ struct perf_event {
80530 * These accumulate total time (in nanoseconds) that children
80531 * events have been enabled and running, respectively.
80532 */
80533 - atomic64_t child_total_time_enabled;
80534 - atomic64_t child_total_time_running;
80535 + atomic64_unchecked_t child_total_time_enabled;
80536 + atomic64_unchecked_t child_total_time_running;
80537
80538 /*
80539 * Protect attach/detach and child_list:
80540 @@ -708,7 +708,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
80541 entry->ip[entry->nr++] = ip;
80542 }
80543
80544 -extern int sysctl_perf_event_paranoid;
80545 +extern int sysctl_perf_event_legitimately_concerned;
80546 extern int sysctl_perf_event_mlock;
80547 extern int sysctl_perf_event_sample_rate;
80548 extern int sysctl_perf_cpu_time_max_percent;
80549 @@ -723,19 +723,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
80550 loff_t *ppos);
80551
80552
80553 +static inline bool perf_paranoid_any(void)
80554 +{
80555 + return sysctl_perf_event_legitimately_concerned > 2;
80556 +}
80557 +
80558 static inline bool perf_paranoid_tracepoint_raw(void)
80559 {
80560 - return sysctl_perf_event_paranoid > -1;
80561 + return sysctl_perf_event_legitimately_concerned > -1;
80562 }
80563
80564 static inline bool perf_paranoid_cpu(void)
80565 {
80566 - return sysctl_perf_event_paranoid > 0;
80567 + return sysctl_perf_event_legitimately_concerned > 0;
80568 }
80569
80570 static inline bool perf_paranoid_kernel(void)
80571 {
80572 - return sysctl_perf_event_paranoid > 1;
80573 + return sysctl_perf_event_legitimately_concerned > 1;
80574 }
80575
80576 extern void perf_event_init(void);
80577 @@ -851,7 +856,7 @@ struct perf_pmu_events_attr {
80578 struct device_attribute attr;
80579 u64 id;
80580 const char *event_str;
80581 -};
80582 +} __do_const;
80583
80584 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
80585 static struct perf_pmu_events_attr _var = { \
80586 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
80587 index 7246ef3..1539ea4 100644
80588 --- a/include/linux/pid_namespace.h
80589 +++ b/include/linux/pid_namespace.h
80590 @@ -43,7 +43,7 @@ struct pid_namespace {
80591 int hide_pid;
80592 int reboot; /* group exit code if this pidns was rebooted */
80593 unsigned int proc_inum;
80594 -};
80595 +} __randomize_layout;
80596
80597 extern struct pid_namespace init_pid_ns;
80598
80599 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
80600 index ab57526..94598804 100644
80601 --- a/include/linux/pipe_fs_i.h
80602 +++ b/include/linux/pipe_fs_i.h
80603 @@ -47,10 +47,10 @@ struct pipe_inode_info {
80604 struct mutex mutex;
80605 wait_queue_head_t wait;
80606 unsigned int nrbufs, curbuf, buffers;
80607 - unsigned int readers;
80608 - unsigned int writers;
80609 - unsigned int files;
80610 - unsigned int waiting_writers;
80611 + atomic_t readers;
80612 + atomic_t writers;
80613 + atomic_t files;
80614 + atomic_t waiting_writers;
80615 unsigned int r_counter;
80616 unsigned int w_counter;
80617 struct page *tmp_page;
80618 diff --git a/include/linux/pm.h b/include/linux/pm.h
80619 index 8c6583a..febb84c 100644
80620 --- a/include/linux/pm.h
80621 +++ b/include/linux/pm.h
80622 @@ -597,6 +597,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
80623 struct dev_pm_domain {
80624 struct dev_pm_ops ops;
80625 };
80626 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
80627
80628 /*
80629 * The PM_EVENT_ messages are also used by drivers implementing the legacy
80630 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
80631 index 7c1d252..0e7061d 100644
80632 --- a/include/linux/pm_domain.h
80633 +++ b/include/linux/pm_domain.h
80634 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
80635 int (*thaw_early)(struct device *dev);
80636 int (*thaw)(struct device *dev);
80637 bool (*active_wakeup)(struct device *dev);
80638 -};
80639 +} __no_const;
80640
80641 struct gpd_cpu_data {
80642 unsigned int saved_exit_latency;
80643 - struct cpuidle_state *idle_state;
80644 + cpuidle_state_no_const *idle_state;
80645 };
80646
80647 struct generic_pm_domain {
80648 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
80649 index 16c9a62..f9f0838 100644
80650 --- a/include/linux/pm_runtime.h
80651 +++ b/include/linux/pm_runtime.h
80652 @@ -109,7 +109,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
80653
80654 static inline void pm_runtime_mark_last_busy(struct device *dev)
80655 {
80656 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
80657 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
80658 }
80659
80660 #else /* !CONFIG_PM_RUNTIME */
80661 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
80662 index 195aafc..49a7bc2 100644
80663 --- a/include/linux/pnp.h
80664 +++ b/include/linux/pnp.h
80665 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
80666 struct pnp_fixup {
80667 char id[7];
80668 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
80669 -};
80670 +} __do_const;
80671
80672 /* config parameters */
80673 #define PNP_CONFIG_NORMAL 0x0001
80674 diff --git a/include/linux/poison.h b/include/linux/poison.h
80675 index 2110a81..13a11bb 100644
80676 --- a/include/linux/poison.h
80677 +++ b/include/linux/poison.h
80678 @@ -19,8 +19,8 @@
80679 * under normal circumstances, used to verify that nobody uses
80680 * non-initialized list entries.
80681 */
80682 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
80683 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
80684 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
80685 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
80686
80687 /********** include/linux/timer.h **********/
80688 /*
80689 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
80690 index d8b187c3..9a9257a 100644
80691 --- a/include/linux/power/smartreflex.h
80692 +++ b/include/linux/power/smartreflex.h
80693 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
80694 int (*notify)(struct omap_sr *sr, u32 status);
80695 u8 notify_flags;
80696 u8 class_type;
80697 -};
80698 +} __do_const;
80699
80700 /**
80701 * struct omap_sr_nvalue_table - Smartreflex n-target value info
80702 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
80703 index 4ea1d37..80f4b33 100644
80704 --- a/include/linux/ppp-comp.h
80705 +++ b/include/linux/ppp-comp.h
80706 @@ -84,7 +84,7 @@ struct compressor {
80707 struct module *owner;
80708 /* Extra skb space needed by the compressor algorithm */
80709 unsigned int comp_extra;
80710 -};
80711 +} __do_const;
80712
80713 /*
80714 * The return value from decompress routine is the length of the
80715 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
80716 index de83b4e..c4b997d 100644
80717 --- a/include/linux/preempt.h
80718 +++ b/include/linux/preempt.h
80719 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
80720 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
80721 #endif
80722
80723 +#define raw_preempt_count_add(val) __preempt_count_add(val)
80724 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
80725 +
80726 #define __preempt_count_inc() __preempt_count_add(1)
80727 #define __preempt_count_dec() __preempt_count_sub(1)
80728
80729 #define preempt_count_inc() preempt_count_add(1)
80730 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
80731 #define preempt_count_dec() preempt_count_sub(1)
80732 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
80733
80734 #ifdef CONFIG_PREEMPT_COUNT
80735
80736 @@ -41,6 +46,12 @@ do { \
80737 barrier(); \
80738 } while (0)
80739
80740 +#define raw_preempt_disable() \
80741 +do { \
80742 + raw_preempt_count_inc(); \
80743 + barrier(); \
80744 +} while (0)
80745 +
80746 #define sched_preempt_enable_no_resched() \
80747 do { \
80748 barrier(); \
80749 @@ -49,6 +60,12 @@ do { \
80750
80751 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
80752
80753 +#define raw_preempt_enable_no_resched() \
80754 +do { \
80755 + barrier(); \
80756 + raw_preempt_count_dec(); \
80757 +} while (0)
80758 +
80759 #ifdef CONFIG_PREEMPT
80760 #define preempt_enable() \
80761 do { \
80762 @@ -113,8 +130,10 @@ do { \
80763 * region.
80764 */
80765 #define preempt_disable() barrier()
80766 +#define raw_preempt_disable() barrier()
80767 #define sched_preempt_enable_no_resched() barrier()
80768 #define preempt_enable_no_resched() barrier()
80769 +#define raw_preempt_enable_no_resched() barrier()
80770 #define preempt_enable() barrier()
80771 #define preempt_check_resched() do { } while (0)
80772
80773 @@ -128,11 +147,13 @@ do { \
80774 /*
80775 * Modules have no business playing preemption tricks.
80776 */
80777 +#ifndef CONFIG_PAX_KERNEXEC
80778 #undef sched_preempt_enable_no_resched
80779 #undef preempt_enable_no_resched
80780 #undef preempt_enable_no_resched_notrace
80781 #undef preempt_check_resched
80782 #endif
80783 +#endif
80784
80785 #define preempt_set_need_resched() \
80786 do { \
80787 diff --git a/include/linux/printk.h b/include/linux/printk.h
80788 index fa47e27..c08e034 100644
80789 --- a/include/linux/printk.h
80790 +++ b/include/linux/printk.h
80791 @@ -114,6 +114,8 @@ static inline __printf(1, 2) __cold
80792 void early_printk(const char *s, ...) { }
80793 #endif
80794
80795 +extern int kptr_restrict;
80796 +
80797 #ifdef CONFIG_PRINTK
80798 asmlinkage __printf(5, 0)
80799 int vprintk_emit(int facility, int level,
80800 @@ -148,7 +150,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
80801
80802 extern int printk_delay_msec;
80803 extern int dmesg_restrict;
80804 -extern int kptr_restrict;
80805
80806 extern void wake_up_klogd(void);
80807
80808 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
80809 index 608e60a..c26f864 100644
80810 --- a/include/linux/proc_fs.h
80811 +++ b/include/linux/proc_fs.h
80812 @@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
80813 return proc_create_data(name, mode, parent, proc_fops, NULL);
80814 }
80815
80816 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
80817 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
80818 +{
80819 +#ifdef CONFIG_GRKERNSEC_PROC_USER
80820 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
80821 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
80822 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
80823 +#else
80824 + return proc_create_data(name, mode, parent, proc_fops, NULL);
80825 +#endif
80826 +}
80827 +
80828 +
80829 extern void proc_set_size(struct proc_dir_entry *, loff_t);
80830 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
80831 extern void *PDE_DATA(const struct inode *);
80832 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
80833 index 34a1e10..70f6bde 100644
80834 --- a/include/linux/proc_ns.h
80835 +++ b/include/linux/proc_ns.h
80836 @@ -14,7 +14,7 @@ struct proc_ns_operations {
80837 void (*put)(void *ns);
80838 int (*install)(struct nsproxy *nsproxy, void *ns);
80839 unsigned int (*inum)(void *ns);
80840 -};
80841 +} __do_const __randomize_layout;
80842
80843 struct proc_ns {
80844 void *ns;
80845 diff --git a/include/linux/quota.h b/include/linux/quota.h
80846 index cc7494a..1e27036 100644
80847 --- a/include/linux/quota.h
80848 +++ b/include/linux/quota.h
80849 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
80850
80851 extern bool qid_eq(struct kqid left, struct kqid right);
80852 extern bool qid_lt(struct kqid left, struct kqid right);
80853 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
80854 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
80855 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
80856 extern bool qid_valid(struct kqid qid);
80857
80858 diff --git a/include/linux/random.h b/include/linux/random.h
80859 index 1cfce0e..b0b9235 100644
80860 --- a/include/linux/random.h
80861 +++ b/include/linux/random.h
80862 @@ -9,9 +9,19 @@
80863 #include <uapi/linux/random.h>
80864
80865 extern void add_device_randomness(const void *, unsigned int);
80866 +
80867 +static inline void add_latent_entropy(void)
80868 +{
80869 +
80870 +#ifdef LATENT_ENTROPY_PLUGIN
80871 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
80872 +#endif
80873 +
80874 +}
80875 +
80876 extern void add_input_randomness(unsigned int type, unsigned int code,
80877 - unsigned int value);
80878 -extern void add_interrupt_randomness(int irq, int irq_flags);
80879 + unsigned int value) __latent_entropy;
80880 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
80881
80882 extern void get_random_bytes(void *buf, int nbytes);
80883 extern void get_random_bytes_arch(void *buf, int nbytes);
80884 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
80885 extern const struct file_operations random_fops, urandom_fops;
80886 #endif
80887
80888 -unsigned int get_random_int(void);
80889 +unsigned int __intentional_overflow(-1) get_random_int(void);
80890 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
80891
80892 -u32 prandom_u32(void);
80893 +u32 prandom_u32(void) __intentional_overflow(-1);
80894 void prandom_bytes(void *buf, int nbytes);
80895 void prandom_seed(u32 seed);
80896 void prandom_reseed_late(void);
80897 @@ -37,6 +47,11 @@ struct rnd_state {
80898 u32 prandom_u32_state(struct rnd_state *state);
80899 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
80900
80901 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
80902 +{
80903 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
80904 +}
80905 +
80906 /**
80907 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
80908 * @ep_ro: right open interval endpoint
80909 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
80910 index fea49b5..2ac22bb 100644
80911 --- a/include/linux/rbtree_augmented.h
80912 +++ b/include/linux/rbtree_augmented.h
80913 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
80914 old->rbaugmented = rbcompute(old); \
80915 } \
80916 rbstatic const struct rb_augment_callbacks rbname = { \
80917 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
80918 + .propagate = rbname ## _propagate, \
80919 + .copy = rbname ## _copy, \
80920 + .rotate = rbname ## _rotate \
80921 };
80922
80923
80924 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
80925 index dbaf990..52e07b8 100644
80926 --- a/include/linux/rculist.h
80927 +++ b/include/linux/rculist.h
80928 @@ -29,8 +29,8 @@
80929 */
80930 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
80931 {
80932 - ACCESS_ONCE(list->next) = list;
80933 - ACCESS_ONCE(list->prev) = list;
80934 + ACCESS_ONCE_RW(list->next) = list;
80935 + ACCESS_ONCE_RW(list->prev) = list;
80936 }
80937
80938 /*
80939 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
80940 struct list_head *prev, struct list_head *next);
80941 #endif
80942
80943 +void __pax_list_add_rcu(struct list_head *new,
80944 + struct list_head *prev, struct list_head *next);
80945 +
80946 /**
80947 * list_add_rcu - add a new entry to rcu-protected list
80948 * @new: new entry to be added
80949 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
80950 __list_add_rcu(new, head, head->next);
80951 }
80952
80953 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
80954 +{
80955 + __pax_list_add_rcu(new, head, head->next);
80956 +}
80957 +
80958 /**
80959 * list_add_tail_rcu - add a new entry to rcu-protected list
80960 * @new: new entry to be added
80961 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
80962 __list_add_rcu(new, head->prev, head);
80963 }
80964
80965 +static inline void pax_list_add_tail_rcu(struct list_head *new,
80966 + struct list_head *head)
80967 +{
80968 + __pax_list_add_rcu(new, head->prev, head);
80969 +}
80970 +
80971 /**
80972 * list_del_rcu - deletes entry from list without re-initialization
80973 * @entry: the element to delete from the list.
80974 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
80975 entry->prev = LIST_POISON2;
80976 }
80977
80978 +extern void pax_list_del_rcu(struct list_head *entry);
80979 +
80980 /**
80981 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
80982 * @n: the element to delete from the hash list.
80983 diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
80984 index 72bf3a0..853347f 100644
80985 --- a/include/linux/rcupdate.h
80986 +++ b/include/linux/rcupdate.h
80987 @@ -588,7 +588,7 @@ static inline void rcu_preempt_sleep_check(void)
80988 #define rcu_assign_pointer(p, v) \
80989 do { \
80990 smp_wmb(); \
80991 - ACCESS_ONCE(p) = RCU_INITIALIZER(v); \
80992 + ACCESS_ONCE_RW(p) = RCU_INITIALIZER(v); \
80993 } while (0)
80994
80995
80996 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
80997 index 9e7db9e..7d4fd72 100644
80998 --- a/include/linux/reboot.h
80999 +++ b/include/linux/reboot.h
81000 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81001 */
81002
81003 extern void migrate_to_reboot_cpu(void);
81004 -extern void machine_restart(char *cmd);
81005 -extern void machine_halt(void);
81006 -extern void machine_power_off(void);
81007 +extern void machine_restart(char *cmd) __noreturn;
81008 +extern void machine_halt(void) __noreturn;
81009 +extern void machine_power_off(void) __noreturn;
81010
81011 extern void machine_shutdown(void);
81012 struct pt_regs;
81013 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81014 */
81015
81016 extern void kernel_restart_prepare(char *cmd);
81017 -extern void kernel_restart(char *cmd);
81018 -extern void kernel_halt(void);
81019 -extern void kernel_power_off(void);
81020 +extern void kernel_restart(char *cmd) __noreturn;
81021 +extern void kernel_halt(void) __noreturn;
81022 +extern void kernel_power_off(void) __noreturn;
81023
81024 extern int C_A_D; /* for sysctl */
81025 void ctrl_alt_del(void);
81026 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81027 * Emergency restart, callable from an interrupt handler.
81028 */
81029
81030 -extern void emergency_restart(void);
81031 +extern void emergency_restart(void) __noreturn;
81032 #include <asm/emergency-restart.h>
81033
81034 #endif /* _LINUX_REBOOT_H */
81035 diff --git a/include/linux/regset.h b/include/linux/regset.h
81036 index 8e0c9fe..ac4d221 100644
81037 --- a/include/linux/regset.h
81038 +++ b/include/linux/regset.h
81039 @@ -161,7 +161,8 @@ struct user_regset {
81040 unsigned int align;
81041 unsigned int bias;
81042 unsigned int core_note_type;
81043 -};
81044 +} __do_const;
81045 +typedef struct user_regset __no_const user_regset_no_const;
81046
81047 /**
81048 * struct user_regset_view - available regsets
81049 diff --git a/include/linux/relay.h b/include/linux/relay.h
81050 index d7c8359..818daf5 100644
81051 --- a/include/linux/relay.h
81052 +++ b/include/linux/relay.h
81053 @@ -157,7 +157,7 @@ struct rchan_callbacks
81054 * The callback should return 0 if successful, negative if not.
81055 */
81056 int (*remove_buf_file)(struct dentry *dentry);
81057 -};
81058 +} __no_const;
81059
81060 /*
81061 * CONFIG_RELAY kernel API, kernel/relay.c
81062 diff --git a/include/linux/rio.h b/include/linux/rio.h
81063 index b71d573..2f940bd 100644
81064 --- a/include/linux/rio.h
81065 +++ b/include/linux/rio.h
81066 @@ -355,7 +355,7 @@ struct rio_ops {
81067 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81068 u64 rstart, u32 size, u32 flags);
81069 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81070 -};
81071 +} __no_const;
81072
81073 #define RIO_RESOURCE_MEM 0x00000100
81074 #define RIO_RESOURCE_DOORBELL 0x00000200
81075 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81076 index b66c211..13d2915 100644
81077 --- a/include/linux/rmap.h
81078 +++ b/include/linux/rmap.h
81079 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81080 void anon_vma_init(void); /* create anon_vma_cachep */
81081 int anon_vma_prepare(struct vm_area_struct *);
81082 void unlink_anon_vmas(struct vm_area_struct *);
81083 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81084 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81085 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
81086 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
81087
81088 static inline void anon_vma_merge(struct vm_area_struct *vma,
81089 struct vm_area_struct *next)
81090 diff --git a/include/linux/sched.h b/include/linux/sched.h
81091 index a781dec..be1d2a3 100644
81092 --- a/include/linux/sched.h
81093 +++ b/include/linux/sched.h
81094 @@ -129,6 +129,7 @@ struct fs_struct;
81095 struct perf_event_context;
81096 struct blk_plug;
81097 struct filename;
81098 +struct linux_binprm;
81099
81100 /*
81101 * List of flags we want to share for kernel threads,
81102 @@ -369,7 +370,7 @@ extern char __sched_text_start[], __sched_text_end[];
81103 extern int in_sched_functions(unsigned long addr);
81104
81105 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
81106 -extern signed long schedule_timeout(signed long timeout);
81107 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
81108 extern signed long schedule_timeout_interruptible(signed long timeout);
81109 extern signed long schedule_timeout_killable(signed long timeout);
81110 extern signed long schedule_timeout_uninterruptible(signed long timeout);
81111 @@ -380,6 +381,19 @@ struct nsproxy;
81112 struct user_namespace;
81113
81114 #ifdef CONFIG_MMU
81115 +
81116 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81117 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
81118 +#else
81119 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81120 +{
81121 + return 0;
81122 +}
81123 +#endif
81124 +
81125 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
81126 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
81127 +
81128 extern void arch_pick_mmap_layout(struct mm_struct *mm);
81129 extern unsigned long
81130 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
81131 @@ -677,6 +691,17 @@ struct signal_struct {
81132 #ifdef CONFIG_TASKSTATS
81133 struct taskstats *stats;
81134 #endif
81135 +
81136 +#ifdef CONFIG_GRKERNSEC
81137 + u32 curr_ip;
81138 + u32 saved_ip;
81139 + u32 gr_saddr;
81140 + u32 gr_daddr;
81141 + u16 gr_sport;
81142 + u16 gr_dport;
81143 + u8 used_accept:1;
81144 +#endif
81145 +
81146 #ifdef CONFIG_AUDIT
81147 unsigned audit_tty;
81148 unsigned audit_tty_log_passwd;
81149 @@ -703,7 +728,7 @@ struct signal_struct {
81150 struct mutex cred_guard_mutex; /* guard against foreign influences on
81151 * credential calculations
81152 * (notably. ptrace) */
81153 -};
81154 +} __randomize_layout;
81155
81156 /*
81157 * Bits in flags field of signal_struct.
81158 @@ -757,6 +782,14 @@ struct user_struct {
81159 struct key *session_keyring; /* UID's default session keyring */
81160 #endif
81161
81162 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
81163 + unsigned char kernel_banned;
81164 +#endif
81165 +#ifdef CONFIG_GRKERNSEC_BRUTE
81166 + unsigned char suid_banned;
81167 + unsigned long suid_ban_expires;
81168 +#endif
81169 +
81170 /* Hash table maintenance information */
81171 struct hlist_node uidhash_node;
81172 kuid_t uid;
81173 @@ -764,7 +797,7 @@ struct user_struct {
81174 #ifdef CONFIG_PERF_EVENTS
81175 atomic_long_t locked_vm;
81176 #endif
81177 -};
81178 +} __randomize_layout;
81179
81180 extern int uids_sysfs_init(void);
81181
81182 @@ -1286,8 +1319,8 @@ struct task_struct {
81183 struct list_head thread_node;
81184
81185 struct completion *vfork_done; /* for vfork() */
81186 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
81187 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81188 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
81189 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81190
81191 cputime_t utime, stime, utimescaled, stimescaled;
81192 cputime_t gtime;
81193 @@ -1312,11 +1345,6 @@ struct task_struct {
81194 struct task_cputime cputime_expires;
81195 struct list_head cpu_timers[3];
81196
81197 -/* process credentials */
81198 - const struct cred __rcu *real_cred; /* objective and real subjective task
81199 - * credentials (COW) */
81200 - const struct cred __rcu *cred; /* effective (overridable) subjective task
81201 - * credentials (COW) */
81202 char comm[TASK_COMM_LEN]; /* executable name excluding path
81203 - access with [gs]et_task_comm (which lock
81204 it with task_lock())
81205 @@ -1333,6 +1361,10 @@ struct task_struct {
81206 #endif
81207 /* CPU-specific state of this task */
81208 struct thread_struct thread;
81209 +/* thread_info moved to task_struct */
81210 +#ifdef CONFIG_X86
81211 + struct thread_info tinfo;
81212 +#endif
81213 /* filesystem information */
81214 struct fs_struct *fs;
81215 /* open file information */
81216 @@ -1409,6 +1441,10 @@ struct task_struct {
81217 gfp_t lockdep_reclaim_gfp;
81218 #endif
81219
81220 +/* process credentials */
81221 + const struct cred __rcu *real_cred; /* objective and real subjective task
81222 + * credentials (COW) */
81223 +
81224 /* journalling filesystem info */
81225 void *journal_info;
81226
81227 @@ -1447,6 +1483,10 @@ struct task_struct {
81228 /* cg_list protected by css_set_lock and tsk->alloc_lock */
81229 struct list_head cg_list;
81230 #endif
81231 +
81232 + const struct cred __rcu *cred; /* effective (overridable) subjective task
81233 + * credentials (COW) */
81234 +
81235 #ifdef CONFIG_FUTEX
81236 struct robust_list_head __user *robust_list;
81237 #ifdef CONFIG_COMPAT
81238 @@ -1581,7 +1621,78 @@ struct task_struct {
81239 unsigned int sequential_io;
81240 unsigned int sequential_io_avg;
81241 #endif
81242 -};
81243 +
81244 +#ifdef CONFIG_GRKERNSEC
81245 + /* grsecurity */
81246 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81247 + u64 exec_id;
81248 +#endif
81249 +#ifdef CONFIG_GRKERNSEC_SETXID
81250 + const struct cred *delayed_cred;
81251 +#endif
81252 + struct dentry *gr_chroot_dentry;
81253 + struct acl_subject_label *acl;
81254 + struct acl_subject_label *tmpacl;
81255 + struct acl_role_label *role;
81256 + struct file *exec_file;
81257 + unsigned long brute_expires;
81258 + u16 acl_role_id;
81259 + u8 inherited;
81260 + /* is this the task that authenticated to the special role */
81261 + u8 acl_sp_role;
81262 + u8 is_writable;
81263 + u8 brute;
81264 + u8 gr_is_chrooted;
81265 +#endif
81266 +
81267 +} __randomize_layout;
81268 +
81269 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
81270 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
81271 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
81272 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
81273 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
81274 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
81275 +
81276 +#ifdef CONFIG_PAX_SOFTMODE
81277 +extern int pax_softmode;
81278 +#endif
81279 +
81280 +extern int pax_check_flags(unsigned long *);
81281 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
81282 +
81283 +/* if tsk != current then task_lock must be held on it */
81284 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81285 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
81286 +{
81287 + if (likely(tsk->mm))
81288 + return tsk->mm->pax_flags;
81289 + else
81290 + return 0UL;
81291 +}
81292 +
81293 +/* if tsk != current then task_lock must be held on it */
81294 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
81295 +{
81296 + if (likely(tsk->mm)) {
81297 + tsk->mm->pax_flags = flags;
81298 + return 0;
81299 + }
81300 + return -EINVAL;
81301 +}
81302 +#endif
81303 +
81304 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
81305 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
81306 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
81307 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
81308 +#endif
81309 +
81310 +struct path;
81311 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
81312 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
81313 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
81314 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
81315
81316 /* Future-safe accessor for struct task_struct's cpus_allowed. */
81317 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
81318 @@ -1658,7 +1769,7 @@ struct pid_namespace;
81319 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
81320 struct pid_namespace *ns);
81321
81322 -static inline pid_t task_pid_nr(struct task_struct *tsk)
81323 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
81324 {
81325 return tsk->pid;
81326 }
81327 @@ -2112,7 +2223,9 @@ void yield(void);
81328 extern struct exec_domain default_exec_domain;
81329
81330 union thread_union {
81331 +#ifndef CONFIG_X86
81332 struct thread_info thread_info;
81333 +#endif
81334 unsigned long stack[THREAD_SIZE/sizeof(long)];
81335 };
81336
81337 @@ -2145,6 +2258,7 @@ extern struct pid_namespace init_pid_ns;
81338 */
81339
81340 extern struct task_struct *find_task_by_vpid(pid_t nr);
81341 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
81342 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
81343 struct pid_namespace *ns);
81344
81345 @@ -2307,7 +2421,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
81346 extern void exit_itimers(struct signal_struct *);
81347 extern void flush_itimer_signals(void);
81348
81349 -extern void do_group_exit(int);
81350 +extern __noreturn void do_group_exit(int);
81351
81352 extern int allow_signal(int);
81353 extern int disallow_signal(int);
81354 @@ -2508,9 +2622,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
81355
81356 #endif
81357
81358 -static inline int object_is_on_stack(void *obj)
81359 +static inline int object_starts_on_stack(void *obj)
81360 {
81361 - void *stack = task_stack_page(current);
81362 + const void *stack = task_stack_page(current);
81363
81364 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
81365 }
81366 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
81367 index 8045a55..c959cd5 100644
81368 --- a/include/linux/sched/sysctl.h
81369 +++ b/include/linux/sched/sysctl.h
81370 @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
81371 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
81372
81373 extern int sysctl_max_map_count;
81374 +extern unsigned long sysctl_heap_stack_gap;
81375
81376 extern unsigned int sysctl_sched_latency;
81377 extern unsigned int sysctl_sched_min_granularity;
81378 diff --git a/include/linux/security.h b/include/linux/security.h
81379 index 2fc42d1..4d802f2 100644
81380 --- a/include/linux/security.h
81381 +++ b/include/linux/security.h
81382 @@ -27,6 +27,7 @@
81383 #include <linux/slab.h>
81384 #include <linux/err.h>
81385 #include <linux/string.h>
81386 +#include <linux/grsecurity.h>
81387
81388 struct linux_binprm;
81389 struct cred;
81390 @@ -116,8 +117,6 @@ struct seq_file;
81391
81392 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
81393
81394 -void reset_security_ops(void);
81395 -
81396 #ifdef CONFIG_MMU
81397 extern unsigned long mmap_min_addr;
81398 extern unsigned long dac_mmap_min_addr;
81399 @@ -1719,7 +1718,7 @@ struct security_operations {
81400 struct audit_context *actx);
81401 void (*audit_rule_free) (void *lsmrule);
81402 #endif /* CONFIG_AUDIT */
81403 -};
81404 +} __randomize_layout;
81405
81406 /* prototypes */
81407 extern int security_init(void);
81408 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
81409 index dc368b8..e895209 100644
81410 --- a/include/linux/semaphore.h
81411 +++ b/include/linux/semaphore.h
81412 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
81413 }
81414
81415 extern void down(struct semaphore *sem);
81416 -extern int __must_check down_interruptible(struct semaphore *sem);
81417 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
81418 extern int __must_check down_killable(struct semaphore *sem);
81419 extern int __must_check down_trylock(struct semaphore *sem);
81420 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
81421 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
81422 index 52e0097..09625ef 100644
81423 --- a/include/linux/seq_file.h
81424 +++ b/include/linux/seq_file.h
81425 @@ -27,6 +27,9 @@ struct seq_file {
81426 struct mutex lock;
81427 const struct seq_operations *op;
81428 int poll_event;
81429 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81430 + u64 exec_id;
81431 +#endif
81432 #ifdef CONFIG_USER_NS
81433 struct user_namespace *user_ns;
81434 #endif
81435 @@ -39,6 +42,7 @@ struct seq_operations {
81436 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
81437 int (*show) (struct seq_file *m, void *v);
81438 };
81439 +typedef struct seq_operations __no_const seq_operations_no_const;
81440
81441 #define SEQ_SKIP 1
81442
81443 diff --git a/include/linux/shm.h b/include/linux/shm.h
81444 index 1e2cd2e..0288750 100644
81445 --- a/include/linux/shm.h
81446 +++ b/include/linux/shm.h
81447 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
81448
81449 /* The task created the shm object. NULL if the task is dead. */
81450 struct task_struct *shm_creator;
81451 +#ifdef CONFIG_GRKERNSEC
81452 + time_t shm_createtime;
81453 + pid_t shm_lapid;
81454 +#endif
81455 };
81456
81457 /* shm_mode upper byte flags */
81458 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
81459 index 15ede6a..80161c3 100644
81460 --- a/include/linux/skbuff.h
81461 +++ b/include/linux/skbuff.h
81462 @@ -662,7 +662,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
81463 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
81464 int node);
81465 struct sk_buff *build_skb(void *data, unsigned int frag_size);
81466 -static inline struct sk_buff *alloc_skb(unsigned int size,
81467 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
81468 gfp_t priority)
81469 {
81470 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
81471 @@ -1768,7 +1768,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
81472 return skb->inner_transport_header - skb->inner_network_header;
81473 }
81474
81475 -static inline int skb_network_offset(const struct sk_buff *skb)
81476 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
81477 {
81478 return skb_network_header(skb) - skb->data;
81479 }
81480 @@ -1828,7 +1828,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
81481 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
81482 */
81483 #ifndef NET_SKB_PAD
81484 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
81485 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
81486 #endif
81487
81488 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
81489 @@ -2427,7 +2427,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
81490 int *err);
81491 unsigned int datagram_poll(struct file *file, struct socket *sock,
81492 struct poll_table_struct *wait);
81493 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81494 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81495 struct iovec *to, int size);
81496 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
81497 struct iovec *iov);
81498 @@ -2721,6 +2721,9 @@ static inline void nf_reset(struct sk_buff *skb)
81499 nf_bridge_put(skb->nf_bridge);
81500 skb->nf_bridge = NULL;
81501 #endif
81502 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
81503 + skb->nf_trace = 0;
81504 +#endif
81505 }
81506
81507 static inline void nf_reset_trace(struct sk_buff *skb)
81508 diff --git a/include/linux/slab.h b/include/linux/slab.h
81509 index b5b2df6..69f5734 100644
81510 --- a/include/linux/slab.h
81511 +++ b/include/linux/slab.h
81512 @@ -14,15 +14,29 @@
81513 #include <linux/gfp.h>
81514 #include <linux/types.h>
81515 #include <linux/workqueue.h>
81516 -
81517 +#include <linux/err.h>
81518
81519 /*
81520 * Flags to pass to kmem_cache_create().
81521 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
81522 */
81523 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
81524 +
81525 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81526 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
81527 +#else
81528 +#define SLAB_USERCOPY 0x00000000UL
81529 +#endif
81530 +
81531 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
81532 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
81533 +
81534 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81535 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
81536 +#else
81537 +#define SLAB_NO_SANITIZE 0x00000000UL
81538 +#endif
81539 +
81540 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
81541 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
81542 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
81543 @@ -98,10 +112,13 @@
81544 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
81545 * Both make kfree a no-op.
81546 */
81547 -#define ZERO_SIZE_PTR ((void *)16)
81548 +#define ZERO_SIZE_PTR \
81549 +({ \
81550 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
81551 + (void *)(-MAX_ERRNO-1L); \
81552 +})
81553
81554 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
81555 - (unsigned long)ZERO_SIZE_PTR)
81556 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
81557
81558 #include <linux/kmemleak.h>
81559
81560 @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
81561 void kfree(const void *);
81562 void kzfree(const void *);
81563 size_t ksize(const void *);
81564 +const char *check_heap_object(const void *ptr, unsigned long n);
81565 +bool is_usercopy_object(const void *ptr);
81566
81567 /*
81568 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
81569 @@ -174,7 +193,7 @@ struct kmem_cache {
81570 unsigned int align; /* Alignment as calculated */
81571 unsigned long flags; /* Active flags on the slab */
81572 const char *name; /* Slab name for sysfs */
81573 - int refcount; /* Use counter */
81574 + atomic_t refcount; /* Use counter */
81575 void (*ctor)(void *); /* Called on object slot creation */
81576 struct list_head list; /* List of all slab caches on the system */
81577 };
81578 @@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
81579 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81580 #endif
81581
81582 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81583 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
81584 +#endif
81585 +
81586 /*
81587 * Figure out which kmalloc slab an allocation of a certain size
81588 * belongs to.
81589 @@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81590 * 2 = 120 .. 192 bytes
81591 * n = 2^(n-1) .. 2^n -1
81592 */
81593 -static __always_inline int kmalloc_index(size_t size)
81594 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
81595 {
81596 if (!size)
81597 return 0;
81598 @@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
81599 }
81600 #endif /* !CONFIG_SLOB */
81601
81602 -void *__kmalloc(size_t size, gfp_t flags);
81603 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
81604 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
81605
81606 #ifdef CONFIG_NUMA
81607 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
81608 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
81609 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
81610 #else
81611 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
81612 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
81613 index 8235dfb..47ce586 100644
81614 --- a/include/linux/slab_def.h
81615 +++ b/include/linux/slab_def.h
81616 @@ -38,7 +38,7 @@ struct kmem_cache {
81617 /* 4) cache creation/removal */
81618 const char *name;
81619 struct list_head list;
81620 - int refcount;
81621 + atomic_t refcount;
81622 int object_size;
81623 int align;
81624
81625 @@ -54,10 +54,14 @@ struct kmem_cache {
81626 unsigned long node_allocs;
81627 unsigned long node_frees;
81628 unsigned long node_overflow;
81629 - atomic_t allochit;
81630 - atomic_t allocmiss;
81631 - atomic_t freehit;
81632 - atomic_t freemiss;
81633 + atomic_unchecked_t allochit;
81634 + atomic_unchecked_t allocmiss;
81635 + atomic_unchecked_t freehit;
81636 + atomic_unchecked_t freemiss;
81637 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81638 + atomic_unchecked_t sanitized;
81639 + atomic_unchecked_t not_sanitized;
81640 +#endif
81641
81642 /*
81643 * If debugging is enabled, then the allocator can add additional
81644 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
81645 index f56bfa9..8378a26 100644
81646 --- a/include/linux/slub_def.h
81647 +++ b/include/linux/slub_def.h
81648 @@ -74,7 +74,7 @@ struct kmem_cache {
81649 struct kmem_cache_order_objects max;
81650 struct kmem_cache_order_objects min;
81651 gfp_t allocflags; /* gfp flags to use on each alloc */
81652 - int refcount; /* Refcount for slab cache destroy */
81653 + atomic_t refcount; /* Refcount for slab cache destroy */
81654 void (*ctor)(void *);
81655 int inuse; /* Offset to metadata */
81656 int align; /* Alignment */
81657 diff --git a/include/linux/smp.h b/include/linux/smp.h
81658 index 6ae004e..2743532 100644
81659 --- a/include/linux/smp.h
81660 +++ b/include/linux/smp.h
81661 @@ -180,7 +180,9 @@ static inline void kick_all_cpus_sync(void) { }
81662 #endif
81663
81664 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
81665 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
81666 #define put_cpu() preempt_enable()
81667 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
81668
81669 /*
81670 * Callback to arch code if there's nosmp or maxcpus=0 on the
81671 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
81672 index 54f91d3..be2c379 100644
81673 --- a/include/linux/sock_diag.h
81674 +++ b/include/linux/sock_diag.h
81675 @@ -11,7 +11,7 @@ struct sock;
81676 struct sock_diag_handler {
81677 __u8 family;
81678 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
81679 -};
81680 +} __do_const;
81681
81682 int sock_diag_register(const struct sock_diag_handler *h);
81683 void sock_diag_unregister(const struct sock_diag_handler *h);
81684 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
81685 index 680f9a3..f13aeb0 100644
81686 --- a/include/linux/sonet.h
81687 +++ b/include/linux/sonet.h
81688 @@ -7,7 +7,7 @@
81689 #include <uapi/linux/sonet.h>
81690
81691 struct k_sonet_stats {
81692 -#define __HANDLE_ITEM(i) atomic_t i
81693 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
81694 __SONET_ITEMS
81695 #undef __HANDLE_ITEM
81696 };
81697 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
81698 index 07d8e53..dc934c9 100644
81699 --- a/include/linux/sunrpc/addr.h
81700 +++ b/include/linux/sunrpc/addr.h
81701 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
81702 {
81703 switch (sap->sa_family) {
81704 case AF_INET:
81705 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
81706 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
81707 case AF_INET6:
81708 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
81709 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
81710 }
81711 return 0;
81712 }
81713 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
81714 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
81715 const struct sockaddr *src)
81716 {
81717 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
81718 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
81719 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
81720
81721 dsin->sin_family = ssin->sin_family;
81722 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
81723 if (sa->sa_family != AF_INET6)
81724 return 0;
81725
81726 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
81727 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
81728 }
81729
81730 #endif /* _LINUX_SUNRPC_ADDR_H */
81731 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
81732 index 8af2804..c7414ef 100644
81733 --- a/include/linux/sunrpc/clnt.h
81734 +++ b/include/linux/sunrpc/clnt.h
81735 @@ -97,7 +97,7 @@ struct rpc_procinfo {
81736 unsigned int p_timer; /* Which RTT timer to use */
81737 u32 p_statidx; /* Which procedure to account */
81738 const char * p_name; /* name of procedure */
81739 -};
81740 +} __do_const;
81741
81742 #ifdef __KERNEL__
81743
81744 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
81745 index 04e7632..2e2a8a3 100644
81746 --- a/include/linux/sunrpc/svc.h
81747 +++ b/include/linux/sunrpc/svc.h
81748 @@ -412,7 +412,7 @@ struct svc_procedure {
81749 unsigned int pc_count; /* call count */
81750 unsigned int pc_cachetype; /* cache info (NFS) */
81751 unsigned int pc_xdrressize; /* maximum size of XDR reply */
81752 -};
81753 +} __do_const;
81754
81755 /*
81756 * Function prototypes.
81757 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
81758 index 0b8e3e6..33e0a01 100644
81759 --- a/include/linux/sunrpc/svc_rdma.h
81760 +++ b/include/linux/sunrpc/svc_rdma.h
81761 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
81762 extern unsigned int svcrdma_max_requests;
81763 extern unsigned int svcrdma_max_req_size;
81764
81765 -extern atomic_t rdma_stat_recv;
81766 -extern atomic_t rdma_stat_read;
81767 -extern atomic_t rdma_stat_write;
81768 -extern atomic_t rdma_stat_sq_starve;
81769 -extern atomic_t rdma_stat_rq_starve;
81770 -extern atomic_t rdma_stat_rq_poll;
81771 -extern atomic_t rdma_stat_rq_prod;
81772 -extern atomic_t rdma_stat_sq_poll;
81773 -extern atomic_t rdma_stat_sq_prod;
81774 +extern atomic_unchecked_t rdma_stat_recv;
81775 +extern atomic_unchecked_t rdma_stat_read;
81776 +extern atomic_unchecked_t rdma_stat_write;
81777 +extern atomic_unchecked_t rdma_stat_sq_starve;
81778 +extern atomic_unchecked_t rdma_stat_rq_starve;
81779 +extern atomic_unchecked_t rdma_stat_rq_poll;
81780 +extern atomic_unchecked_t rdma_stat_rq_prod;
81781 +extern atomic_unchecked_t rdma_stat_sq_poll;
81782 +extern atomic_unchecked_t rdma_stat_sq_prod;
81783
81784 #define RPCRDMA_VERSION 1
81785
81786 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
81787 index 8d71d65..f79586e 100644
81788 --- a/include/linux/sunrpc/svcauth.h
81789 +++ b/include/linux/sunrpc/svcauth.h
81790 @@ -120,7 +120,7 @@ struct auth_ops {
81791 int (*release)(struct svc_rqst *rq);
81792 void (*domain_release)(struct auth_domain *);
81793 int (*set_client)(struct svc_rqst *rq);
81794 -};
81795 +} __do_const;
81796
81797 #define SVC_GARBAGE 1
81798 #define SVC_SYSERR 2
81799 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
81800 index a5ffd32..0935dea 100644
81801 --- a/include/linux/swiotlb.h
81802 +++ b/include/linux/swiotlb.h
81803 @@ -60,7 +60,8 @@ extern void
81804
81805 extern void
81806 swiotlb_free_coherent(struct device *hwdev, size_t size,
81807 - void *vaddr, dma_addr_t dma_handle);
81808 + void *vaddr, dma_addr_t dma_handle,
81809 + struct dma_attrs *attrs);
81810
81811 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
81812 unsigned long offset, size_t size,
81813 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
81814 index a747a77..9e14df7 100644
81815 --- a/include/linux/syscalls.h
81816 +++ b/include/linux/syscalls.h
81817 @@ -98,8 +98,14 @@ struct sigaltstack;
81818 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
81819
81820 #define __SC_DECL(t, a) t a
81821 +#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))
81822 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
81823 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
81824 +#define __SC_LONG(t, a) __typeof( \
81825 + __builtin_choose_expr( \
81826 + sizeof(t) > sizeof(int), \
81827 + (t) 0, \
81828 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
81829 + )) a
81830 #define __SC_CAST(t, a) (t) a
81831 #define __SC_ARGS(t, a) a
81832 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
81833 @@ -371,11 +377,11 @@ asmlinkage long sys_sync(void);
81834 asmlinkage long sys_fsync(unsigned int fd);
81835 asmlinkage long sys_fdatasync(unsigned int fd);
81836 asmlinkage long sys_bdflush(int func, long data);
81837 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
81838 - char __user *type, unsigned long flags,
81839 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
81840 + const char __user *type, unsigned long flags,
81841 void __user *data);
81842 -asmlinkage long sys_umount(char __user *name, int flags);
81843 -asmlinkage long sys_oldumount(char __user *name);
81844 +asmlinkage long sys_umount(const char __user *name, int flags);
81845 +asmlinkage long sys_oldumount(const char __user *name);
81846 asmlinkage long sys_truncate(const char __user *path, long length);
81847 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
81848 asmlinkage long sys_stat(const char __user *filename,
81849 @@ -587,7 +593,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
81850 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
81851 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
81852 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
81853 - struct sockaddr __user *, int);
81854 + struct sockaddr __user *, int) __intentional_overflow(0);
81855 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
81856 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
81857 unsigned int vlen, unsigned flags);
81858 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
81859 index 27b3b0b..e093dd9 100644
81860 --- a/include/linux/syscore_ops.h
81861 +++ b/include/linux/syscore_ops.h
81862 @@ -16,7 +16,7 @@ struct syscore_ops {
81863 int (*suspend)(void);
81864 void (*resume)(void);
81865 void (*shutdown)(void);
81866 -};
81867 +} __do_const;
81868
81869 extern void register_syscore_ops(struct syscore_ops *ops);
81870 extern void unregister_syscore_ops(struct syscore_ops *ops);
81871 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
81872 index 14a8ff2..fa95f3a 100644
81873 --- a/include/linux/sysctl.h
81874 +++ b/include/linux/sysctl.h
81875 @@ -34,13 +34,13 @@ struct ctl_table_root;
81876 struct ctl_table_header;
81877 struct ctl_dir;
81878
81879 -typedef struct ctl_table ctl_table;
81880 -
81881 typedef int proc_handler (struct ctl_table *ctl, int write,
81882 void __user *buffer, size_t *lenp, loff_t *ppos);
81883
81884 extern int proc_dostring(struct ctl_table *, int,
81885 void __user *, size_t *, loff_t *);
81886 +extern int proc_dostring_modpriv(struct ctl_table *, int,
81887 + void __user *, size_t *, loff_t *);
81888 extern int proc_dointvec(struct ctl_table *, int,
81889 void __user *, size_t *, loff_t *);
81890 extern int proc_dointvec_minmax(struct ctl_table *, int,
81891 @@ -115,7 +115,9 @@ struct ctl_table
81892 struct ctl_table_poll *poll;
81893 void *extra1;
81894 void *extra2;
81895 -};
81896 +} __do_const __randomize_layout;
81897 +typedef struct ctl_table __no_const ctl_table_no_const;
81898 +typedef struct ctl_table ctl_table;
81899
81900 struct ctl_node {
81901 struct rb_node node;
81902 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
81903 index 30b2ebe..37412ef 100644
81904 --- a/include/linux/sysfs.h
81905 +++ b/include/linux/sysfs.h
81906 @@ -34,7 +34,8 @@ struct attribute {
81907 struct lock_class_key *key;
81908 struct lock_class_key skey;
81909 #endif
81910 -};
81911 +} __do_const;
81912 +typedef struct attribute __no_const attribute_no_const;
81913
81914 /**
81915 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
81916 @@ -63,7 +64,8 @@ struct attribute_group {
81917 struct attribute *, int);
81918 struct attribute **attrs;
81919 struct bin_attribute **bin_attrs;
81920 -};
81921 +} __do_const;
81922 +typedef struct attribute_group __no_const attribute_group_no_const;
81923
81924 /**
81925 * Use these macros to make defining attributes easier. See include/linux/device.h
81926 @@ -127,7 +129,8 @@ struct bin_attribute {
81927 char *, loff_t, size_t);
81928 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
81929 struct vm_area_struct *vma);
81930 -};
81931 +} __do_const;
81932 +typedef struct bin_attribute __no_const bin_attribute_no_const;
81933
81934 /**
81935 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
81936 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
81937 index 387fa7d..3fcde6b 100644
81938 --- a/include/linux/sysrq.h
81939 +++ b/include/linux/sysrq.h
81940 @@ -16,6 +16,7 @@
81941
81942 #include <linux/errno.h>
81943 #include <linux/types.h>
81944 +#include <linux/compiler.h>
81945
81946 /* Possible values of bitmask for enabling sysrq functions */
81947 /* 0x0001 is reserved for enable everything */
81948 @@ -33,7 +34,7 @@ struct sysrq_key_op {
81949 char *help_msg;
81950 char *action_msg;
81951 int enable_mask;
81952 -};
81953 +} __do_const;
81954
81955 #ifdef CONFIG_MAGIC_SYSRQ
81956
81957 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
81958 index fddbe20..0312de8 100644
81959 --- a/include/linux/thread_info.h
81960 +++ b/include/linux/thread_info.h
81961 @@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
81962 #error "no set_restore_sigmask() provided and default one won't work"
81963 #endif
81964
81965 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
81966 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
81967 +{
81968 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
81969 + if (!__builtin_constant_p(n))
81970 +#endif
81971 + __check_object_size(ptr, n, to_user);
81972 +}
81973 +
81974 #endif /* __KERNEL__ */
81975
81976 #endif /* _LINUX_THREAD_INFO_H */
81977 diff --git a/include/linux/tty.h b/include/linux/tty.h
81978 index 90b4fdc..58a731d 100644
81979 --- a/include/linux/tty.h
81980 +++ b/include/linux/tty.h
81981 @@ -202,7 +202,7 @@ struct tty_port {
81982 const struct tty_port_operations *ops; /* Port operations */
81983 spinlock_t lock; /* Lock protecting tty field */
81984 int blocked_open; /* Waiting to open */
81985 - int count; /* Usage count */
81986 + atomic_t count; /* Usage count */
81987 wait_queue_head_t open_wait; /* Open waiters */
81988 wait_queue_head_t close_wait; /* Close waiters */
81989 wait_queue_head_t delta_msr_wait; /* Modem status change */
81990 @@ -284,7 +284,7 @@ struct tty_struct {
81991 /* If the tty has a pending do_SAK, queue it here - akpm */
81992 struct work_struct SAK_work;
81993 struct tty_port *port;
81994 -};
81995 +} __randomize_layout;
81996
81997 /* Each of a tty's open files has private_data pointing to tty_file_private */
81998 struct tty_file_private {
81999 @@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
82000 struct tty_struct *tty, struct file *filp);
82001 static inline int tty_port_users(struct tty_port *port)
82002 {
82003 - return port->count + port->blocked_open;
82004 + return atomic_read(&port->count) + port->blocked_open;
82005 }
82006
82007 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82008 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82009 index 756a609..89db85e 100644
82010 --- a/include/linux/tty_driver.h
82011 +++ b/include/linux/tty_driver.h
82012 @@ -285,7 +285,7 @@ struct tty_operations {
82013 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82014 #endif
82015 const struct file_operations *proc_fops;
82016 -};
82017 +} __do_const __randomize_layout;
82018
82019 struct tty_driver {
82020 int magic; /* magic number for this structure */
82021 @@ -319,7 +319,7 @@ struct tty_driver {
82022
82023 const struct tty_operations *ops;
82024 struct list_head tty_drivers;
82025 -};
82026 +} __randomize_layout;
82027
82028 extern struct list_head tty_drivers;
82029
82030 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82031 index b8347c2..85d8b0f 100644
82032 --- a/include/linux/tty_ldisc.h
82033 +++ b/include/linux/tty_ldisc.h
82034 @@ -213,7 +213,7 @@ struct tty_ldisc_ops {
82035
82036 struct module *owner;
82037
82038 - int refcount;
82039 + atomic_t refcount;
82040 };
82041
82042 struct tty_ldisc {
82043 diff --git a/include/linux/types.h b/include/linux/types.h
82044 index 4d118ba..c3ee9bf 100644
82045 --- a/include/linux/types.h
82046 +++ b/include/linux/types.h
82047 @@ -176,10 +176,26 @@ typedef struct {
82048 int counter;
82049 } atomic_t;
82050
82051 +#ifdef CONFIG_PAX_REFCOUNT
82052 +typedef struct {
82053 + int counter;
82054 +} atomic_unchecked_t;
82055 +#else
82056 +typedef atomic_t atomic_unchecked_t;
82057 +#endif
82058 +
82059 #ifdef CONFIG_64BIT
82060 typedef struct {
82061 long counter;
82062 } atomic64_t;
82063 +
82064 +#ifdef CONFIG_PAX_REFCOUNT
82065 +typedef struct {
82066 + long counter;
82067 +} atomic64_unchecked_t;
82068 +#else
82069 +typedef atomic64_t atomic64_unchecked_t;
82070 +#endif
82071 #endif
82072
82073 struct list_head {
82074 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
82075 index ecd3319..8a36ded 100644
82076 --- a/include/linux/uaccess.h
82077 +++ b/include/linux/uaccess.h
82078 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
82079 long ret; \
82080 mm_segment_t old_fs = get_fs(); \
82081 \
82082 - set_fs(KERNEL_DS); \
82083 pagefault_disable(); \
82084 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
82085 - pagefault_enable(); \
82086 + set_fs(KERNEL_DS); \
82087 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
82088 set_fs(old_fs); \
82089 + pagefault_enable(); \
82090 ret; \
82091 })
82092
82093 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
82094 index 2d1f9b6..d7a9fce 100644
82095 --- a/include/linux/uidgid.h
82096 +++ b/include/linux/uidgid.h
82097 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
82098
82099 #endif /* CONFIG_USER_NS */
82100
82101 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
82102 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
82103 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
82104 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
82105 +
82106 #endif /* _LINUX_UIDGID_H */
82107 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
82108 index 99c1b4d..562e6f3 100644
82109 --- a/include/linux/unaligned/access_ok.h
82110 +++ b/include/linux/unaligned/access_ok.h
82111 @@ -4,34 +4,34 @@
82112 #include <linux/kernel.h>
82113 #include <asm/byteorder.h>
82114
82115 -static inline u16 get_unaligned_le16(const void *p)
82116 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
82117 {
82118 - return le16_to_cpup((__le16 *)p);
82119 + return le16_to_cpup((const __le16 *)p);
82120 }
82121
82122 -static inline u32 get_unaligned_le32(const void *p)
82123 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
82124 {
82125 - return le32_to_cpup((__le32 *)p);
82126 + return le32_to_cpup((const __le32 *)p);
82127 }
82128
82129 -static inline u64 get_unaligned_le64(const void *p)
82130 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
82131 {
82132 - return le64_to_cpup((__le64 *)p);
82133 + return le64_to_cpup((const __le64 *)p);
82134 }
82135
82136 -static inline u16 get_unaligned_be16(const void *p)
82137 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
82138 {
82139 - return be16_to_cpup((__be16 *)p);
82140 + return be16_to_cpup((const __be16 *)p);
82141 }
82142
82143 -static inline u32 get_unaligned_be32(const void *p)
82144 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
82145 {
82146 - return be32_to_cpup((__be32 *)p);
82147 + return be32_to_cpup((const __be32 *)p);
82148 }
82149
82150 -static inline u64 get_unaligned_be64(const void *p)
82151 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
82152 {
82153 - return be64_to_cpup((__be64 *)p);
82154 + return be64_to_cpup((const __be64 *)p);
82155 }
82156
82157 static inline void put_unaligned_le16(u16 val, void *p)
82158 diff --git a/include/linux/usb.h b/include/linux/usb.h
82159 index 7f6eb85..656e806 100644
82160 --- a/include/linux/usb.h
82161 +++ b/include/linux/usb.h
82162 @@ -563,7 +563,7 @@ struct usb_device {
82163 int maxchild;
82164
82165 u32 quirks;
82166 - atomic_t urbnum;
82167 + atomic_unchecked_t urbnum;
82168
82169 unsigned long active_duration;
82170
82171 @@ -1642,7 +1642,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
82172
82173 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
82174 __u8 request, __u8 requesttype, __u16 value, __u16 index,
82175 - void *data, __u16 size, int timeout);
82176 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
82177 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
82178 void *data, int len, int *actual_length, int timeout);
82179 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
82180 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
82181 index e452ba6..78f8e80 100644
82182 --- a/include/linux/usb/renesas_usbhs.h
82183 +++ b/include/linux/usb/renesas_usbhs.h
82184 @@ -39,7 +39,7 @@ enum {
82185 */
82186 struct renesas_usbhs_driver_callback {
82187 int (*notify_hotplug)(struct platform_device *pdev);
82188 -};
82189 +} __no_const;
82190
82191 /*
82192 * callback functions for platform
82193 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
82194 index 4836ba3..603f6ee 100644
82195 --- a/include/linux/user_namespace.h
82196 +++ b/include/linux/user_namespace.h
82197 @@ -33,7 +33,7 @@ struct user_namespace {
82198 struct key *persistent_keyring_register;
82199 struct rw_semaphore persistent_keyring_register_sem;
82200 #endif
82201 -};
82202 +} __randomize_layout;
82203
82204 extern struct user_namespace init_user_ns;
82205
82206 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
82207 index 239e277..22a5cf5 100644
82208 --- a/include/linux/utsname.h
82209 +++ b/include/linux/utsname.h
82210 @@ -24,7 +24,7 @@ struct uts_namespace {
82211 struct new_utsname name;
82212 struct user_namespace *user_ns;
82213 unsigned int proc_inum;
82214 -};
82215 +} __randomize_layout;
82216 extern struct uts_namespace init_uts_ns;
82217
82218 #ifdef CONFIG_UTS_NS
82219 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
82220 index 6f8fbcf..4efc177 100644
82221 --- a/include/linux/vermagic.h
82222 +++ b/include/linux/vermagic.h
82223 @@ -25,9 +25,42 @@
82224 #define MODULE_ARCH_VERMAGIC ""
82225 #endif
82226
82227 +#ifdef CONFIG_PAX_REFCOUNT
82228 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
82229 +#else
82230 +#define MODULE_PAX_REFCOUNT ""
82231 +#endif
82232 +
82233 +#ifdef CONSTIFY_PLUGIN
82234 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
82235 +#else
82236 +#define MODULE_CONSTIFY_PLUGIN ""
82237 +#endif
82238 +
82239 +#ifdef STACKLEAK_PLUGIN
82240 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
82241 +#else
82242 +#define MODULE_STACKLEAK_PLUGIN ""
82243 +#endif
82244 +
82245 +#ifdef RANDSTRUCT_PLUGIN
82246 +#include <generated/randomize_layout_hash.h>
82247 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
82248 +#else
82249 +#define MODULE_RANDSTRUCT_PLUGIN
82250 +#endif
82251 +
82252 +#ifdef CONFIG_GRKERNSEC
82253 +#define MODULE_GRSEC "GRSEC "
82254 +#else
82255 +#define MODULE_GRSEC ""
82256 +#endif
82257 +
82258 #define VERMAGIC_STRING \
82259 UTS_RELEASE " " \
82260 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
82261 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
82262 - MODULE_ARCH_VERMAGIC
82263 + MODULE_ARCH_VERMAGIC \
82264 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
82265 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
82266
82267 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
82268 index 502073a..a7de024 100644
82269 --- a/include/linux/vga_switcheroo.h
82270 +++ b/include/linux/vga_switcheroo.h
82271 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
82272
82273 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
82274
82275 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
82276 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
82277 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
82278 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
82279 #else
82280
82281 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
82282 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
82283
82284 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
82285
82286 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82287 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82288 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82289 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82290
82291 #endif
82292 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
82293 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
82294 index 4b8a891..cb8df6e 100644
82295 --- a/include/linux/vmalloc.h
82296 +++ b/include/linux/vmalloc.h
82297 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
82298 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
82299 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
82300 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
82301 +
82302 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
82303 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
82304 +#endif
82305 +
82306 /* bits [20..32] reserved for arch specific ioremap internals */
82307
82308 /*
82309 @@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
82310
82311 /* for /dev/kmem */
82312 extern long vread(char *buf, char *addr, unsigned long count);
82313 -extern long vwrite(char *buf, char *addr, unsigned long count);
82314 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
82315
82316 /*
82317 * Internals. Dont't use..
82318 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
82319 index 67ce70c..d540954 100644
82320 --- a/include/linux/vmstat.h
82321 +++ b/include/linux/vmstat.h
82322 @@ -98,18 +98,18 @@ static inline void vm_events_fold_cpu(int cpu)
82323 /*
82324 * Zone based page accounting with per cpu differentials.
82325 */
82326 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82327 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82328
82329 static inline void zone_page_state_add(long x, struct zone *zone,
82330 enum zone_stat_item item)
82331 {
82332 - atomic_long_add(x, &zone->vm_stat[item]);
82333 - atomic_long_add(x, &vm_stat[item]);
82334 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
82335 + atomic_long_add_unchecked(x, &vm_stat[item]);
82336 }
82337
82338 -static inline unsigned long global_page_state(enum zone_stat_item item)
82339 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
82340 {
82341 - long x = atomic_long_read(&vm_stat[item]);
82342 + long x = atomic_long_read_unchecked(&vm_stat[item]);
82343 #ifdef CONFIG_SMP
82344 if (x < 0)
82345 x = 0;
82346 @@ -117,10 +117,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
82347 return x;
82348 }
82349
82350 -static inline unsigned long zone_page_state(struct zone *zone,
82351 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
82352 enum zone_stat_item item)
82353 {
82354 - long x = atomic_long_read(&zone->vm_stat[item]);
82355 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82356 #ifdef CONFIG_SMP
82357 if (x < 0)
82358 x = 0;
82359 @@ -137,7 +137,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
82360 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
82361 enum zone_stat_item item)
82362 {
82363 - long x = atomic_long_read(&zone->vm_stat[item]);
82364 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82365
82366 #ifdef CONFIG_SMP
82367 int cpu;
82368 @@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
82369
82370 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
82371 {
82372 - atomic_long_inc(&zone->vm_stat[item]);
82373 - atomic_long_inc(&vm_stat[item]);
82374 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
82375 + atomic_long_inc_unchecked(&vm_stat[item]);
82376 }
82377
82378 static inline void __inc_zone_page_state(struct page *page,
82379 @@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
82380
82381 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
82382 {
82383 - atomic_long_dec(&zone->vm_stat[item]);
82384 - atomic_long_dec(&vm_stat[item]);
82385 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
82386 + atomic_long_dec_unchecked(&vm_stat[item]);
82387 }
82388
82389 static inline void __dec_zone_page_state(struct page *page,
82390 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
82391 index 91b0a68..0e9adf6 100644
82392 --- a/include/linux/xattr.h
82393 +++ b/include/linux/xattr.h
82394 @@ -28,7 +28,7 @@ struct xattr_handler {
82395 size_t size, int handler_flags);
82396 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
82397 size_t size, int flags, int handler_flags);
82398 -};
82399 +} __do_const;
82400
82401 struct xattr {
82402 const char *name;
82403 @@ -37,6 +37,9 @@ struct xattr {
82404 };
82405
82406 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
82407 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82408 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
82409 +#endif
82410 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
82411 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
82412 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
82413 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
82414 index 9c5a6b4..09c9438 100644
82415 --- a/include/linux/zlib.h
82416 +++ b/include/linux/zlib.h
82417 @@ -31,6 +31,7 @@
82418 #define _ZLIB_H
82419
82420 #include <linux/zconf.h>
82421 +#include <linux/compiler.h>
82422
82423 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
82424 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
82425 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
82426
82427 /* basic functions */
82428
82429 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
82430 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
82431 /*
82432 Returns the number of bytes that needs to be allocated for a per-
82433 stream workspace with the specified parameters. A pointer to this
82434 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
82435 index c768c9f..bdcaa5a 100644
82436 --- a/include/media/v4l2-dev.h
82437 +++ b/include/media/v4l2-dev.h
82438 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
82439 int (*mmap) (struct file *, struct vm_area_struct *);
82440 int (*open) (struct file *);
82441 int (*release) (struct file *);
82442 -};
82443 +} __do_const;
82444
82445 /*
82446 * Newer version of video_device, handled by videodev2.c
82447 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
82448 index c9b1593..a572459 100644
82449 --- a/include/media/v4l2-device.h
82450 +++ b/include/media/v4l2-device.h
82451 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
82452 this function returns 0. If the name ends with a digit (e.g. cx18),
82453 then the name will be set to cx18-0 since cx180 looks really odd. */
82454 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
82455 - atomic_t *instance);
82456 + atomic_unchecked_t *instance);
82457
82458 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
82459 Since the parent disappears this ensures that v4l2_dev doesn't have an
82460 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
82461 index 9a36d92..0aafe2a 100644
82462 --- a/include/net/9p/transport.h
82463 +++ b/include/net/9p/transport.h
82464 @@ -60,7 +60,7 @@ struct p9_trans_module {
82465 int (*cancel) (struct p9_client *, struct p9_req_t *req);
82466 int (*zc_request)(struct p9_client *, struct p9_req_t *,
82467 char *, char *, int , int, int, int);
82468 -};
82469 +} __do_const;
82470
82471 void v9fs_register_trans(struct p9_trans_module *m);
82472 void v9fs_unregister_trans(struct p9_trans_module *m);
82473 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
82474 index a175ba4..196eb82 100644
82475 --- a/include/net/af_unix.h
82476 +++ b/include/net/af_unix.h
82477 @@ -36,7 +36,7 @@ struct unix_skb_parms {
82478 u32 secid; /* Security ID */
82479 #endif
82480 u32 consumed;
82481 -};
82482 +} __randomize_layout;
82483
82484 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
82485 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
82486 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
82487 index dbc4a89..4a59b5d 100644
82488 --- a/include/net/bluetooth/l2cap.h
82489 +++ b/include/net/bluetooth/l2cap.h
82490 @@ -600,7 +600,7 @@ struct l2cap_ops {
82491 long (*get_sndtimeo) (struct l2cap_chan *chan);
82492 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
82493 unsigned long len, int nb);
82494 -};
82495 +} __do_const;
82496
82497 struct l2cap_conn {
82498 struct hci_conn *hcon;
82499 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
82500 index f2ae33d..c457cf0 100644
82501 --- a/include/net/caif/cfctrl.h
82502 +++ b/include/net/caif/cfctrl.h
82503 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
82504 void (*radioset_rsp)(void);
82505 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
82506 struct cflayer *client_layer);
82507 -};
82508 +} __no_const;
82509
82510 /* Link Setup Parameters for CAIF-Links. */
82511 struct cfctrl_link_param {
82512 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
82513 struct cfctrl {
82514 struct cfsrvl serv;
82515 struct cfctrl_rsp res;
82516 - atomic_t req_seq_no;
82517 - atomic_t rsp_seq_no;
82518 + atomic_unchecked_t req_seq_no;
82519 + atomic_unchecked_t rsp_seq_no;
82520 struct list_head list;
82521 /* Protects from simultaneous access to first_req list */
82522 spinlock_t info_list_lock;
82523 diff --git a/include/net/flow.h b/include/net/flow.h
82524 index d23e7fa..e188307 100644
82525 --- a/include/net/flow.h
82526 +++ b/include/net/flow.h
82527 @@ -221,6 +221,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
82528
82529 void flow_cache_flush(void);
82530 void flow_cache_flush_deferred(void);
82531 -extern atomic_t flow_cache_genid;
82532 +extern atomic_unchecked_t flow_cache_genid;
82533
82534 #endif
82535 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
82536 index 93695f0..766d71c 100644
82537 --- a/include/net/genetlink.h
82538 +++ b/include/net/genetlink.h
82539 @@ -120,7 +120,7 @@ struct genl_ops {
82540 u8 cmd;
82541 u8 internal_flags;
82542 u8 flags;
82543 -};
82544 +} __do_const;
82545
82546 int __genl_register_family(struct genl_family *family);
82547
82548 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
82549 index 734d9b5..48a9a4b 100644
82550 --- a/include/net/gro_cells.h
82551 +++ b/include/net/gro_cells.h
82552 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
82553 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
82554
82555 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
82556 - atomic_long_inc(&dev->rx_dropped);
82557 + atomic_long_inc_unchecked(&dev->rx_dropped);
82558 kfree_skb(skb);
82559 return;
82560 }
82561 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
82562 index c55aeed..b3393f4 100644
82563 --- a/include/net/inet_connection_sock.h
82564 +++ b/include/net/inet_connection_sock.h
82565 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
82566 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
82567 int (*bind_conflict)(const struct sock *sk,
82568 const struct inet_bind_bucket *tb, bool relax);
82569 -};
82570 +} __do_const;
82571
82572 /** inet_connection_sock - INET connection oriented sock
82573 *
82574 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
82575 index 6efe73c..fa94270 100644
82576 --- a/include/net/inetpeer.h
82577 +++ b/include/net/inetpeer.h
82578 @@ -47,8 +47,8 @@ struct inet_peer {
82579 */
82580 union {
82581 struct {
82582 - atomic_t rid; /* Frag reception counter */
82583 - atomic_t ip_id_count; /* IP ID for the next packet */
82584 + atomic_unchecked_t rid; /* Frag reception counter */
82585 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
82586 };
82587 struct rcu_head rcu;
82588 struct inet_peer *gc_next;
82589 @@ -177,16 +177,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
82590 /* can be called with or without local BH being disabled */
82591 static inline int inet_getid(struct inet_peer *p, int more)
82592 {
82593 - int old, new;
82594 + int id;
82595 more++;
82596 inet_peer_refcheck(p);
82597 - do {
82598 - old = atomic_read(&p->ip_id_count);
82599 - new = old + more;
82600 - if (!new)
82601 - new = 1;
82602 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
82603 - return new;
82604 + id = atomic_add_return_unchecked(more, &p->ip_id_count);
82605 + if (!id)
82606 + id = atomic_inc_return_unchecked(&p->ip_id_count);
82607 + return id;
82608 }
82609
82610 #endif /* _NET_INETPEER_H */
82611 diff --git a/include/net/ip.h b/include/net/ip.h
82612 index 23be0fd..0cb3e2c 100644
82613 --- a/include/net/ip.h
82614 +++ b/include/net/ip.h
82615 @@ -214,7 +214,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
82616
82617 void inet_get_local_port_range(struct net *net, int *low, int *high);
82618
82619 -extern unsigned long *sysctl_local_reserved_ports;
82620 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
82621 static inline int inet_is_reserved_local_port(int port)
82622 {
82623 return test_bit(port, sysctl_local_reserved_ports);
82624 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
82625 index 9922093..a1755d6 100644
82626 --- a/include/net/ip_fib.h
82627 +++ b/include/net/ip_fib.h
82628 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
82629
82630 #define FIB_RES_SADDR(net, res) \
82631 ((FIB_RES_NH(res).nh_saddr_genid == \
82632 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
82633 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
82634 FIB_RES_NH(res).nh_saddr : \
82635 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
82636 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
82637 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
82638 index 5679d92..2e7a690 100644
82639 --- a/include/net/ip_vs.h
82640 +++ b/include/net/ip_vs.h
82641 @@ -558,7 +558,7 @@ struct ip_vs_conn {
82642 struct ip_vs_conn *control; /* Master control connection */
82643 atomic_t n_control; /* Number of controlled ones */
82644 struct ip_vs_dest *dest; /* real server */
82645 - atomic_t in_pkts; /* incoming packet counter */
82646 + atomic_unchecked_t in_pkts; /* incoming packet counter */
82647
82648 /* packet transmitter for different forwarding methods. If it
82649 mangles the packet, it must return NF_DROP or better NF_STOLEN,
82650 @@ -705,7 +705,7 @@ struct ip_vs_dest {
82651 __be16 port; /* port number of the server */
82652 union nf_inet_addr addr; /* IP address of the server */
82653 volatile unsigned int flags; /* dest status flags */
82654 - atomic_t conn_flags; /* flags to copy to conn */
82655 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
82656 atomic_t weight; /* server weight */
82657
82658 atomic_t refcnt; /* reference counter */
82659 @@ -960,11 +960,11 @@ struct netns_ipvs {
82660 /* ip_vs_lblc */
82661 int sysctl_lblc_expiration;
82662 struct ctl_table_header *lblc_ctl_header;
82663 - struct ctl_table *lblc_ctl_table;
82664 + ctl_table_no_const *lblc_ctl_table;
82665 /* ip_vs_lblcr */
82666 int sysctl_lblcr_expiration;
82667 struct ctl_table_header *lblcr_ctl_header;
82668 - struct ctl_table *lblcr_ctl_table;
82669 + ctl_table_no_const *lblcr_ctl_table;
82670 /* ip_vs_est */
82671 struct list_head est_list; /* estimator list */
82672 spinlock_t est_lock;
82673 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
82674 index 8d4f588..2e37ad2 100644
82675 --- a/include/net/irda/ircomm_tty.h
82676 +++ b/include/net/irda/ircomm_tty.h
82677 @@ -33,6 +33,7 @@
82678 #include <linux/termios.h>
82679 #include <linux/timer.h>
82680 #include <linux/tty.h> /* struct tty_struct */
82681 +#include <asm/local.h>
82682
82683 #include <net/irda/irias_object.h>
82684 #include <net/irda/ircomm_core.h>
82685 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
82686 index 714cc9a..ea05f3e 100644
82687 --- a/include/net/iucv/af_iucv.h
82688 +++ b/include/net/iucv/af_iucv.h
82689 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
82690 struct iucv_sock_list {
82691 struct hlist_head head;
82692 rwlock_t lock;
82693 - atomic_t autobind_name;
82694 + atomic_unchecked_t autobind_name;
82695 };
82696
82697 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
82698 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
82699 index f3be818..bf46196 100644
82700 --- a/include/net/llc_c_ac.h
82701 +++ b/include/net/llc_c_ac.h
82702 @@ -87,7 +87,7 @@
82703 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
82704 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
82705
82706 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82707 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82708
82709 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
82710 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
82711 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
82712 index 3948cf1..83b28c4 100644
82713 --- a/include/net/llc_c_ev.h
82714 +++ b/include/net/llc_c_ev.h
82715 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
82716 return (struct llc_conn_state_ev *)skb->cb;
82717 }
82718
82719 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82720 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82721 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82722 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82723
82724 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
82725 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
82726 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
82727 index 0e79cfb..f46db31 100644
82728 --- a/include/net/llc_c_st.h
82729 +++ b/include/net/llc_c_st.h
82730 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
82731 u8 next_state;
82732 llc_conn_ev_qfyr_t *ev_qualifiers;
82733 llc_conn_action_t *ev_actions;
82734 -};
82735 +} __do_const;
82736
82737 struct llc_conn_state {
82738 u8 current_state;
82739 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
82740 index a61b98c..aade1eb 100644
82741 --- a/include/net/llc_s_ac.h
82742 +++ b/include/net/llc_s_ac.h
82743 @@ -23,7 +23,7 @@
82744 #define SAP_ACT_TEST_IND 9
82745
82746 /* All action functions must look like this */
82747 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82748 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82749
82750 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
82751 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
82752 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
82753 index 567c681..cd73ac0 100644
82754 --- a/include/net/llc_s_st.h
82755 +++ b/include/net/llc_s_st.h
82756 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
82757 llc_sap_ev_t ev;
82758 u8 next_state;
82759 llc_sap_action_t *ev_actions;
82760 -};
82761 +} __do_const;
82762
82763 struct llc_sap_state {
82764 u8 curr_state;
82765 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
82766 index f4ab2fb..71a85ba 100644
82767 --- a/include/net/mac80211.h
82768 +++ b/include/net/mac80211.h
82769 @@ -4476,7 +4476,7 @@ struct rate_control_ops {
82770 void (*add_sta_debugfs)(void *priv, void *priv_sta,
82771 struct dentry *dir);
82772 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
82773 -};
82774 +} __do_const;
82775
82776 static inline int rate_supported(struct ieee80211_sta *sta,
82777 enum ieee80211_band band,
82778 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
82779 index 7277caf..fd095bc 100644
82780 --- a/include/net/neighbour.h
82781 +++ b/include/net/neighbour.h
82782 @@ -163,7 +163,7 @@ struct neigh_ops {
82783 void (*error_report)(struct neighbour *, struct sk_buff *);
82784 int (*output)(struct neighbour *, struct sk_buff *);
82785 int (*connected_output)(struct neighbour *, struct sk_buff *);
82786 -};
82787 +} __do_const;
82788
82789 struct pneigh_entry {
82790 struct pneigh_entry *next;
82791 @@ -203,7 +203,6 @@ struct neigh_table {
82792 void (*proxy_redo)(struct sk_buff *skb);
82793 char *id;
82794 struct neigh_parms parms;
82795 - /* HACK. gc_* should follow parms without a gap! */
82796 int gc_interval;
82797 int gc_thresh1;
82798 int gc_thresh2;
82799 @@ -218,7 +217,7 @@ struct neigh_table {
82800 struct neigh_statistics __percpu *stats;
82801 struct neigh_hash_table __rcu *nht;
82802 struct pneigh_entry **phash_buckets;
82803 -};
82804 +} __randomize_layout;
82805
82806 static inline int neigh_parms_family(struct neigh_parms *p)
82807 {
82808 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
82809 index 991dcd9..ab58d00 100644
82810 --- a/include/net/net_namespace.h
82811 +++ b/include/net/net_namespace.h
82812 @@ -124,8 +124,8 @@ struct net {
82813 struct netns_ipvs *ipvs;
82814 #endif
82815 struct sock *diag_nlsk;
82816 - atomic_t fnhe_genid;
82817 -};
82818 + atomic_unchecked_t fnhe_genid;
82819 +} __randomize_layout;
82820
82821 /*
82822 * ifindex generation is per-net namespace, and loopback is
82823 @@ -289,7 +289,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
82824 #define __net_init __init
82825 #define __net_exit __exit_refok
82826 #define __net_initdata __initdata
82827 +#ifdef CONSTIFY_PLUGIN
82828 #define __net_initconst __initconst
82829 +#else
82830 +#define __net_initconst __initdata
82831 +#endif
82832 #endif
82833
82834 struct pernet_operations {
82835 @@ -299,7 +303,7 @@ struct pernet_operations {
82836 void (*exit_batch)(struct list_head *net_exit_list);
82837 int *id;
82838 size_t size;
82839 -};
82840 +} __do_const;
82841
82842 /*
82843 * Use these carefully. If you implement a network device and it
82844 @@ -347,23 +351,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
82845
82846 static inline int rt_genid_ipv4(struct net *net)
82847 {
82848 - return atomic_read(&net->ipv4.rt_genid);
82849 + return atomic_read_unchecked(&net->ipv4.rt_genid);
82850 }
82851
82852 static inline void rt_genid_bump_ipv4(struct net *net)
82853 {
82854 - atomic_inc(&net->ipv4.rt_genid);
82855 + atomic_inc_unchecked(&net->ipv4.rt_genid);
82856 }
82857
82858 #if IS_ENABLED(CONFIG_IPV6)
82859 static inline int rt_genid_ipv6(struct net *net)
82860 {
82861 - return atomic_read(&net->ipv6.rt_genid);
82862 + return atomic_read_unchecked(&net->ipv6.rt_genid);
82863 }
82864
82865 static inline void rt_genid_bump_ipv6(struct net *net)
82866 {
82867 - atomic_inc(&net->ipv6.rt_genid);
82868 + atomic_inc_unchecked(&net->ipv6.rt_genid);
82869 }
82870 #else
82871 static inline int rt_genid_ipv6(struct net *net)
82872 @@ -385,12 +389,12 @@ static inline void rt_genid_bump_all(struct net *net)
82873
82874 static inline int fnhe_genid(struct net *net)
82875 {
82876 - return atomic_read(&net->fnhe_genid);
82877 + return atomic_read_unchecked(&net->fnhe_genid);
82878 }
82879
82880 static inline void fnhe_genid_bump(struct net *net)
82881 {
82882 - atomic_inc(&net->fnhe_genid);
82883 + atomic_inc_unchecked(&net->fnhe_genid);
82884 }
82885
82886 #endif /* __NET_NET_NAMESPACE_H */
82887 diff --git a/include/net/netdma.h b/include/net/netdma.h
82888 index 8ba8ce2..99b7fff 100644
82889 --- a/include/net/netdma.h
82890 +++ b/include/net/netdma.h
82891 @@ -24,7 +24,7 @@
82892 #include <linux/dmaengine.h>
82893 #include <linux/skbuff.h>
82894
82895 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
82896 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
82897 struct sk_buff *skb, int offset, struct iovec *to,
82898 size_t len, struct dma_pinned_list *pinned_list);
82899
82900 diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
82901 index 956b175..55d1504 100644
82902 --- a/include/net/netfilter/nf_conntrack_extend.h
82903 +++ b/include/net/netfilter/nf_conntrack_extend.h
82904 @@ -47,8 +47,8 @@ enum nf_ct_ext_id {
82905 /* Extensions: optional stuff which isn't permanently in struct. */
82906 struct nf_ct_ext {
82907 struct rcu_head rcu;
82908 - u8 offset[NF_CT_EXT_NUM];
82909 - u8 len;
82910 + u16 offset[NF_CT_EXT_NUM];
82911 + u16 len;
82912 char data[0];
82913 };
82914
82915 diff --git a/include/net/netlink.h b/include/net/netlink.h
82916 index 2b47eaa..6d5bcc2 100644
82917 --- a/include/net/netlink.h
82918 +++ b/include/net/netlink.h
82919 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
82920 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
82921 {
82922 if (mark)
82923 - skb_trim(skb, (unsigned char *) mark - skb->data);
82924 + skb_trim(skb, (const unsigned char *) mark - skb->data);
82925 }
82926
82927 /**
82928 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
82929 index fbcc7fa..03c7e51 100644
82930 --- a/include/net/netns/conntrack.h
82931 +++ b/include/net/netns/conntrack.h
82932 @@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
82933 struct nf_proto_net {
82934 #ifdef CONFIG_SYSCTL
82935 struct ctl_table_header *ctl_table_header;
82936 - struct ctl_table *ctl_table;
82937 + ctl_table_no_const *ctl_table;
82938 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
82939 struct ctl_table_header *ctl_compat_header;
82940 - struct ctl_table *ctl_compat_table;
82941 + ctl_table_no_const *ctl_compat_table;
82942 #endif
82943 #endif
82944 unsigned int users;
82945 @@ -58,7 +58,7 @@ struct nf_ip_net {
82946 struct nf_icmp_net icmpv6;
82947 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
82948 struct ctl_table_header *ctl_table_header;
82949 - struct ctl_table *ctl_table;
82950 + ctl_table_no_const *ctl_table;
82951 #endif
82952 };
82953
82954 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
82955 index 80f500a..f0c23c2 100644
82956 --- a/include/net/netns/ipv4.h
82957 +++ b/include/net/netns/ipv4.h
82958 @@ -74,7 +74,7 @@ struct netns_ipv4 {
82959
82960 kgid_t sysctl_ping_group_range[2];
82961
82962 - atomic_t dev_addr_genid;
82963 + atomic_unchecked_t dev_addr_genid;
82964
82965 #ifdef CONFIG_IP_MROUTE
82966 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
82967 @@ -84,6 +84,6 @@ struct netns_ipv4 {
82968 struct fib_rules_ops *mr_rules_ops;
82969 #endif
82970 #endif
82971 - atomic_t rt_genid;
82972 + atomic_unchecked_t rt_genid;
82973 };
82974 #endif
82975 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
82976 index 21edaf1..4c5faae 100644
82977 --- a/include/net/netns/ipv6.h
82978 +++ b/include/net/netns/ipv6.h
82979 @@ -73,8 +73,8 @@ struct netns_ipv6 {
82980 struct fib_rules_ops *mr6_rules_ops;
82981 #endif
82982 #endif
82983 - atomic_t dev_addr_genid;
82984 - atomic_t rt_genid;
82985 + atomic_unchecked_t dev_addr_genid;
82986 + atomic_unchecked_t rt_genid;
82987 };
82988
82989 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
82990 diff --git a/include/net/ping.h b/include/net/ping.h
82991 index 026479b..d9b2829 100644
82992 --- a/include/net/ping.h
82993 +++ b/include/net/ping.h
82994 @@ -54,7 +54,7 @@ struct ping_iter_state {
82995
82996 extern struct proto ping_prot;
82997 #if IS_ENABLED(CONFIG_IPV6)
82998 -extern struct pingv6_ops pingv6_ops;
82999 +extern struct pingv6_ops *pingv6_ops;
83000 #endif
83001
83002 struct pingfakehdr {
83003 diff --git a/include/net/protocol.h b/include/net/protocol.h
83004 index a7e986b..dc67bce 100644
83005 --- a/include/net/protocol.h
83006 +++ b/include/net/protocol.h
83007 @@ -49,7 +49,7 @@ struct net_protocol {
83008 * socket lookup?
83009 */
83010 icmp_strict_tag_validation:1;
83011 -};
83012 +} __do_const;
83013
83014 #if IS_ENABLED(CONFIG_IPV6)
83015 struct inet6_protocol {
83016 @@ -62,7 +62,7 @@ struct inet6_protocol {
83017 u8 type, u8 code, int offset,
83018 __be32 info);
83019 unsigned int flags; /* INET6_PROTO_xxx */
83020 -};
83021 +} __do_const;
83022
83023 #define INET6_PROTO_NOPOLICY 0x1
83024 #define INET6_PROTO_FINAL 0x2
83025 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83026 index 661e45d..54c39df 100644
83027 --- a/include/net/rtnetlink.h
83028 +++ b/include/net/rtnetlink.h
83029 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
83030 int (*fill_slave_info)(struct sk_buff *skb,
83031 const struct net_device *dev,
83032 const struct net_device *slave_dev);
83033 -};
83034 +} __do_const;
83035
83036 int __rtnl_link_register(struct rtnl_link_ops *ops);
83037 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83038 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83039 index 4a5b9a3..ca27d73 100644
83040 --- a/include/net/sctp/checksum.h
83041 +++ b/include/net/sctp/checksum.h
83042 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83043 unsigned int offset)
83044 {
83045 struct sctphdr *sh = sctp_hdr(skb);
83046 - __le32 ret, old = sh->checksum;
83047 - const struct skb_checksum_ops ops = {
83048 + __le32 ret, old = sh->checksum;
83049 + static const struct skb_checksum_ops ops = {
83050 .update = sctp_csum_update,
83051 .combine = sctp_csum_combine,
83052 };
83053 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83054 index 7f4eeb3..37e8fe1 100644
83055 --- a/include/net/sctp/sm.h
83056 +++ b/include/net/sctp/sm.h
83057 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83058 typedef struct {
83059 sctp_state_fn_t *fn;
83060 const char *name;
83061 -} sctp_sm_table_entry_t;
83062 +} __do_const sctp_sm_table_entry_t;
83063
83064 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
83065 * currently in use.
83066 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
83067 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
83068
83069 /* Extern declarations for major data structures. */
83070 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83071 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83072
83073
83074 /* Get the size of a DATA chunk payload. */
83075 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
83076 index 6ee76c8..45f2609 100644
83077 --- a/include/net/sctp/structs.h
83078 +++ b/include/net/sctp/structs.h
83079 @@ -507,7 +507,7 @@ struct sctp_pf {
83080 struct sctp_association *asoc);
83081 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
83082 struct sctp_af *af;
83083 -};
83084 +} __do_const;
83085
83086
83087 /* Structure to track chunk fragments that have been acked, but peer
83088 diff --git a/include/net/sock.h b/include/net/sock.h
83089 index b9586a1..b2948c0 100644
83090 --- a/include/net/sock.h
83091 +++ b/include/net/sock.h
83092 @@ -348,7 +348,7 @@ struct sock {
83093 unsigned int sk_napi_id;
83094 unsigned int sk_ll_usec;
83095 #endif
83096 - atomic_t sk_drops;
83097 + atomic_unchecked_t sk_drops;
83098 int sk_rcvbuf;
83099
83100 struct sk_filter __rcu *sk_filter;
83101 @@ -1036,7 +1036,7 @@ struct proto {
83102 void (*destroy_cgroup)(struct mem_cgroup *memcg);
83103 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
83104 #endif
83105 -};
83106 +} __randomize_layout;
83107
83108 /*
83109 * Bits in struct cg_proto.flags
83110 @@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
83111 return ret >> PAGE_SHIFT;
83112 }
83113
83114 -static inline long
83115 +static inline long __intentional_overflow(-1)
83116 sk_memory_allocated(const struct sock *sk)
83117 {
83118 struct proto *prot = sk->sk_prot;
83119 @@ -1368,7 +1368,7 @@ struct sock_iocb {
83120 struct scm_cookie *scm;
83121 struct msghdr *msg, async_msg;
83122 struct kiocb *kiocb;
83123 -};
83124 +} __randomize_layout;
83125
83126 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
83127 {
83128 @@ -1830,7 +1830,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
83129 }
83130
83131 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
83132 - char __user *from, char *to,
83133 + char __user *from, unsigned char *to,
83134 int copy, int offset)
83135 {
83136 if (skb->ip_summed == CHECKSUM_NONE) {
83137 @@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
83138 }
83139 }
83140
83141 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83142 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83143
83144 /**
83145 * sk_page_frag - return an appropriate page_frag
83146 diff --git a/include/net/tcp.h b/include/net/tcp.h
83147 index 743acce..44a58b0 100644
83148 --- a/include/net/tcp.h
83149 +++ b/include/net/tcp.h
83150 @@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
83151 void tcp_xmit_retransmit_queue(struct sock *);
83152 void tcp_simple_retransmit(struct sock *);
83153 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
83154 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83155 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83156
83157 void tcp_send_probe0(struct sock *);
83158 void tcp_send_partial(struct sock *);
83159 @@ -710,8 +710,8 @@ struct tcp_skb_cb {
83160 struct inet6_skb_parm h6;
83161 #endif
83162 } header; /* For incoming frames */
83163 - __u32 seq; /* Starting sequence number */
83164 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
83165 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
83166 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
83167 __u32 when; /* used to compute rtt's */
83168 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
83169
83170 @@ -725,7 +725,7 @@ struct tcp_skb_cb {
83171
83172 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
83173 /* 1 byte hole */
83174 - __u32 ack_seq; /* Sequence number ACK'd */
83175 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
83176 };
83177
83178 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
83179 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
83180 index fb5654a..4457522 100644
83181 --- a/include/net/xfrm.h
83182 +++ b/include/net/xfrm.h
83183 @@ -286,7 +286,6 @@ struct xfrm_dst;
83184 struct xfrm_policy_afinfo {
83185 unsigned short family;
83186 struct dst_ops *dst_ops;
83187 - void (*garbage_collect)(struct net *net);
83188 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
83189 const xfrm_address_t *saddr,
83190 const xfrm_address_t *daddr);
83191 @@ -304,7 +303,7 @@ struct xfrm_policy_afinfo {
83192 struct net_device *dev,
83193 const struct flowi *fl);
83194 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
83195 -};
83196 +} __do_const;
83197
83198 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
83199 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
83200 @@ -343,7 +342,7 @@ struct xfrm_state_afinfo {
83201 int (*transport_finish)(struct sk_buff *skb,
83202 int async);
83203 void (*local_error)(struct sk_buff *skb, u32 mtu);
83204 -};
83205 +} __do_const;
83206
83207 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
83208 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
83209 @@ -428,7 +427,7 @@ struct xfrm_mode {
83210 struct module *owner;
83211 unsigned int encap;
83212 int flags;
83213 -};
83214 +} __do_const;
83215
83216 /* Flags for xfrm_mode. */
83217 enum {
83218 @@ -525,7 +524,7 @@ struct xfrm_policy {
83219 struct timer_list timer;
83220
83221 struct flow_cache_object flo;
83222 - atomic_t genid;
83223 + atomic_unchecked_t genid;
83224 u32 priority;
83225 u32 index;
83226 struct xfrm_mark mark;
83227 @@ -1165,6 +1164,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
83228 }
83229
83230 void xfrm_garbage_collect(struct net *net);
83231 +void xfrm_garbage_collect_deferred(struct net *net);
83232
83233 #else
83234
83235 @@ -1203,6 +1203,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
83236 static inline void xfrm_garbage_collect(struct net *net)
83237 {
83238 }
83239 +static inline void xfrm_garbage_collect_deferred(struct net *net)
83240 +{
83241 +}
83242 #endif
83243
83244 static __inline__
83245 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
83246 index 1017e0b..227aa4d 100644
83247 --- a/include/rdma/iw_cm.h
83248 +++ b/include/rdma/iw_cm.h
83249 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
83250 int backlog);
83251
83252 int (*destroy_listen)(struct iw_cm_id *cm_id);
83253 -};
83254 +} __no_const;
83255
83256 /**
83257 * iw_create_cm_id - Create an IW CM identifier.
83258 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
83259 index 52beadf..598734c 100644
83260 --- a/include/scsi/libfc.h
83261 +++ b/include/scsi/libfc.h
83262 @@ -771,6 +771,7 @@ struct libfc_function_template {
83263 */
83264 void (*disc_stop_final) (struct fc_lport *);
83265 };
83266 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
83267
83268 /**
83269 * struct fc_disc - Discovery context
83270 @@ -875,7 +876,7 @@ struct fc_lport {
83271 struct fc_vport *vport;
83272
83273 /* Operational Information */
83274 - struct libfc_function_template tt;
83275 + libfc_function_template_no_const tt;
83276 u8 link_up;
83277 u8 qfull;
83278 enum fc_lport_state state;
83279 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
83280 index d65fbec..f80fef2 100644
83281 --- a/include/scsi/scsi_device.h
83282 +++ b/include/scsi/scsi_device.h
83283 @@ -180,9 +180,9 @@ struct scsi_device {
83284 unsigned int max_device_blocked; /* what device_blocked counts down from */
83285 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
83286
83287 - atomic_t iorequest_cnt;
83288 - atomic_t iodone_cnt;
83289 - atomic_t ioerr_cnt;
83290 + atomic_unchecked_t iorequest_cnt;
83291 + atomic_unchecked_t iodone_cnt;
83292 + atomic_unchecked_t ioerr_cnt;
83293
83294 struct device sdev_gendev,
83295 sdev_dev;
83296 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
83297 index b797e8f..8e2c3aa 100644
83298 --- a/include/scsi/scsi_transport_fc.h
83299 +++ b/include/scsi/scsi_transport_fc.h
83300 @@ -751,7 +751,8 @@ struct fc_function_template {
83301 unsigned long show_host_system_hostname:1;
83302
83303 unsigned long disable_target_scan:1;
83304 -};
83305 +} __do_const;
83306 +typedef struct fc_function_template __no_const fc_function_template_no_const;
83307
83308
83309 /**
83310 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
83311 index ae6c3b8..fd748ac 100644
83312 --- a/include/sound/compress_driver.h
83313 +++ b/include/sound/compress_driver.h
83314 @@ -128,7 +128,7 @@ struct snd_compr_ops {
83315 struct snd_compr_caps *caps);
83316 int (*get_codec_caps) (struct snd_compr_stream *stream,
83317 struct snd_compr_codec_caps *codec);
83318 -};
83319 +} __no_const;
83320
83321 /**
83322 * struct snd_compr: Compressed device
83323 diff --git a/include/sound/soc.h b/include/sound/soc.h
83324 index 9a00147..d814573 100644
83325 --- a/include/sound/soc.h
83326 +++ b/include/sound/soc.h
83327 @@ -770,7 +770,7 @@ struct snd_soc_codec_driver {
83328 /* probe ordering - for components with runtime dependencies */
83329 int probe_order;
83330 int remove_order;
83331 -};
83332 +} __do_const;
83333
83334 /* SoC platform interface */
83335 struct snd_soc_platform_driver {
83336 @@ -816,7 +816,7 @@ struct snd_soc_platform_driver {
83337 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
83338 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
83339 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
83340 -};
83341 +} __do_const;
83342
83343 struct snd_soc_platform {
83344 const char *name;
83345 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
83346 index 1772fad..282e3e2 100644
83347 --- a/include/target/target_core_base.h
83348 +++ b/include/target/target_core_base.h
83349 @@ -754,7 +754,7 @@ struct se_device {
83350 atomic_long_t write_bytes;
83351 /* Active commands on this virtual SE device */
83352 atomic_t simple_cmds;
83353 - atomic_t dev_ordered_id;
83354 + atomic_unchecked_t dev_ordered_id;
83355 atomic_t dev_ordered_sync;
83356 atomic_t dev_qf_count;
83357 int export_count;
83358 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
83359 new file mode 100644
83360 index 0000000..fb634b7
83361 --- /dev/null
83362 +++ b/include/trace/events/fs.h
83363 @@ -0,0 +1,53 @@
83364 +#undef TRACE_SYSTEM
83365 +#define TRACE_SYSTEM fs
83366 +
83367 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
83368 +#define _TRACE_FS_H
83369 +
83370 +#include <linux/fs.h>
83371 +#include <linux/tracepoint.h>
83372 +
83373 +TRACE_EVENT(do_sys_open,
83374 +
83375 + TP_PROTO(const char *filename, int flags, int mode),
83376 +
83377 + TP_ARGS(filename, flags, mode),
83378 +
83379 + TP_STRUCT__entry(
83380 + __string( filename, filename )
83381 + __field( int, flags )
83382 + __field( int, mode )
83383 + ),
83384 +
83385 + TP_fast_assign(
83386 + __assign_str(filename, filename);
83387 + __entry->flags = flags;
83388 + __entry->mode = mode;
83389 + ),
83390 +
83391 + TP_printk("\"%s\" %x %o",
83392 + __get_str(filename), __entry->flags, __entry->mode)
83393 +);
83394 +
83395 +TRACE_EVENT(open_exec,
83396 +
83397 + TP_PROTO(const char *filename),
83398 +
83399 + TP_ARGS(filename),
83400 +
83401 + TP_STRUCT__entry(
83402 + __string( filename, filename )
83403 + ),
83404 +
83405 + TP_fast_assign(
83406 + __assign_str(filename, filename);
83407 + ),
83408 +
83409 + TP_printk("\"%s\"",
83410 + __get_str(filename))
83411 +);
83412 +
83413 +#endif /* _TRACE_FS_H */
83414 +
83415 +/* This part must be outside protection */
83416 +#include <trace/define_trace.h>
83417 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
83418 index 1c09820..7f5ec79 100644
83419 --- a/include/trace/events/irq.h
83420 +++ b/include/trace/events/irq.h
83421 @@ -36,7 +36,7 @@ struct softirq_action;
83422 */
83423 TRACE_EVENT(irq_handler_entry,
83424
83425 - TP_PROTO(int irq, struct irqaction *action),
83426 + TP_PROTO(int irq, const struct irqaction *action),
83427
83428 TP_ARGS(irq, action),
83429
83430 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
83431 */
83432 TRACE_EVENT(irq_handler_exit,
83433
83434 - TP_PROTO(int irq, struct irqaction *action, int ret),
83435 + TP_PROTO(int irq, const struct irqaction *action, int ret),
83436
83437 TP_ARGS(irq, action, ret),
83438
83439 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
83440 index 7caf44c..23c6f27 100644
83441 --- a/include/uapi/linux/a.out.h
83442 +++ b/include/uapi/linux/a.out.h
83443 @@ -39,6 +39,14 @@ enum machine_type {
83444 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
83445 };
83446
83447 +/* Constants for the N_FLAGS field */
83448 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83449 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
83450 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
83451 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
83452 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83453 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83454 +
83455 #if !defined (N_MAGIC)
83456 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
83457 #endif
83458 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
83459 index 22b6ad3..aeba37e 100644
83460 --- a/include/uapi/linux/bcache.h
83461 +++ b/include/uapi/linux/bcache.h
83462 @@ -5,6 +5,7 @@
83463 * Bcache on disk data structures
83464 */
83465
83466 +#include <linux/compiler.h>
83467 #include <asm/types.h>
83468
83469 #define BITMASK(name, type, field, offset, size) \
83470 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
83471 /* Btree keys - all units are in sectors */
83472
83473 struct bkey {
83474 - __u64 high;
83475 - __u64 low;
83476 + __u64 high __intentional_overflow(-1);
83477 + __u64 low __intentional_overflow(-1);
83478 __u64 ptr[];
83479 };
83480
83481 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
83482 index d876736..ccce5c0 100644
83483 --- a/include/uapi/linux/byteorder/little_endian.h
83484 +++ b/include/uapi/linux/byteorder/little_endian.h
83485 @@ -42,51 +42,51 @@
83486
83487 static inline __le64 __cpu_to_le64p(const __u64 *p)
83488 {
83489 - return (__force __le64)*p;
83490 + return (__force const __le64)*p;
83491 }
83492 -static inline __u64 __le64_to_cpup(const __le64 *p)
83493 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
83494 {
83495 - return (__force __u64)*p;
83496 + return (__force const __u64)*p;
83497 }
83498 static inline __le32 __cpu_to_le32p(const __u32 *p)
83499 {
83500 - return (__force __le32)*p;
83501 + return (__force const __le32)*p;
83502 }
83503 static inline __u32 __le32_to_cpup(const __le32 *p)
83504 {
83505 - return (__force __u32)*p;
83506 + return (__force const __u32)*p;
83507 }
83508 static inline __le16 __cpu_to_le16p(const __u16 *p)
83509 {
83510 - return (__force __le16)*p;
83511 + return (__force const __le16)*p;
83512 }
83513 static inline __u16 __le16_to_cpup(const __le16 *p)
83514 {
83515 - return (__force __u16)*p;
83516 + return (__force const __u16)*p;
83517 }
83518 static inline __be64 __cpu_to_be64p(const __u64 *p)
83519 {
83520 - return (__force __be64)__swab64p(p);
83521 + return (__force const __be64)__swab64p(p);
83522 }
83523 static inline __u64 __be64_to_cpup(const __be64 *p)
83524 {
83525 - return __swab64p((__u64 *)p);
83526 + return __swab64p((const __u64 *)p);
83527 }
83528 static inline __be32 __cpu_to_be32p(const __u32 *p)
83529 {
83530 - return (__force __be32)__swab32p(p);
83531 + return (__force const __be32)__swab32p(p);
83532 }
83533 -static inline __u32 __be32_to_cpup(const __be32 *p)
83534 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
83535 {
83536 - return __swab32p((__u32 *)p);
83537 + return __swab32p((const __u32 *)p);
83538 }
83539 static inline __be16 __cpu_to_be16p(const __u16 *p)
83540 {
83541 - return (__force __be16)__swab16p(p);
83542 + return (__force const __be16)__swab16p(p);
83543 }
83544 static inline __u16 __be16_to_cpup(const __be16 *p)
83545 {
83546 - return __swab16p((__u16 *)p);
83547 + return __swab16p((const __u16 *)p);
83548 }
83549 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
83550 #define __le64_to_cpus(x) do { (void)(x); } while (0)
83551 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
83552 index ef6103b..d4e65dd 100644
83553 --- a/include/uapi/linux/elf.h
83554 +++ b/include/uapi/linux/elf.h
83555 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
83556 #define PT_GNU_EH_FRAME 0x6474e550
83557
83558 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
83559 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
83560 +
83561 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
83562 +
83563 +/* Constants for the e_flags field */
83564 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83565 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
83566 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
83567 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
83568 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83569 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83570
83571 /*
83572 * Extended Numbering
83573 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
83574 #define DT_DEBUG 21
83575 #define DT_TEXTREL 22
83576 #define DT_JMPREL 23
83577 +#define DT_FLAGS 30
83578 + #define DF_TEXTREL 0x00000004
83579 #define DT_ENCODING 32
83580 #define OLD_DT_LOOS 0x60000000
83581 #define DT_LOOS 0x6000000d
83582 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
83583 #define PF_W 0x2
83584 #define PF_X 0x1
83585
83586 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
83587 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
83588 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
83589 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
83590 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
83591 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
83592 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
83593 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
83594 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
83595 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
83596 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
83597 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
83598 +
83599 typedef struct elf32_phdr{
83600 Elf32_Word p_type;
83601 Elf32_Off p_offset;
83602 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
83603 #define EI_OSABI 7
83604 #define EI_PAD 8
83605
83606 +#define EI_PAX 14
83607 +
83608 #define ELFMAG0 0x7f /* EI_MAG */
83609 #define ELFMAG1 'E'
83610 #define ELFMAG2 'L'
83611 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
83612 index aa169c4..6a2771d 100644
83613 --- a/include/uapi/linux/personality.h
83614 +++ b/include/uapi/linux/personality.h
83615 @@ -30,6 +30,7 @@ enum {
83616 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
83617 ADDR_NO_RANDOMIZE | \
83618 ADDR_COMPAT_LAYOUT | \
83619 + ADDR_LIMIT_3GB | \
83620 MMAP_PAGE_ZERO)
83621
83622 /*
83623 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
83624 index 7530e74..e714828 100644
83625 --- a/include/uapi/linux/screen_info.h
83626 +++ b/include/uapi/linux/screen_info.h
83627 @@ -43,7 +43,8 @@ struct screen_info {
83628 __u16 pages; /* 0x32 */
83629 __u16 vesa_attributes; /* 0x34 */
83630 __u32 capabilities; /* 0x36 */
83631 - __u8 _reserved[6]; /* 0x3a */
83632 + __u16 vesapm_size; /* 0x3a */
83633 + __u8 _reserved[4]; /* 0x3c */
83634 } __attribute__((packed));
83635
83636 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
83637 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
83638 index 0e011eb..82681b1 100644
83639 --- a/include/uapi/linux/swab.h
83640 +++ b/include/uapi/linux/swab.h
83641 @@ -43,7 +43,7 @@
83642 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
83643 */
83644
83645 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
83646 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
83647 {
83648 #ifdef __HAVE_BUILTIN_BSWAP16__
83649 return __builtin_bswap16(val);
83650 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
83651 #endif
83652 }
83653
83654 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
83655 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
83656 {
83657 #ifdef __HAVE_BUILTIN_BSWAP32__
83658 return __builtin_bswap32(val);
83659 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
83660 #endif
83661 }
83662
83663 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
83664 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
83665 {
83666 #ifdef __HAVE_BUILTIN_BSWAP64__
83667 return __builtin_bswap64(val);
83668 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
83669 index 6d67213..552fdd9 100644
83670 --- a/include/uapi/linux/sysctl.h
83671 +++ b/include/uapi/linux/sysctl.h
83672 @@ -155,8 +155,6 @@ enum
83673 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
83674 };
83675
83676 -
83677 -
83678 /* CTL_VM names: */
83679 enum
83680 {
83681 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
83682 index 6ae7bbe..1e487fe 100644
83683 --- a/include/uapi/linux/videodev2.h
83684 +++ b/include/uapi/linux/videodev2.h
83685 @@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
83686 union {
83687 __s32 value;
83688 __s64 value64;
83689 - char *string;
83690 + char __user *string;
83691 };
83692 } __attribute__ ((packed));
83693
83694 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
83695 index 40bbc04..e30d9a2 100644
83696 --- a/include/uapi/linux/xattr.h
83697 +++ b/include/uapi/linux/xattr.h
83698 @@ -66,5 +66,9 @@
83699 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
83700 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
83701
83702 +/* User namespace */
83703 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
83704 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
83705 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
83706
83707 #endif /* _UAPI_LINUX_XATTR_H */
83708 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
83709 index f9466fa..f4e2b81 100644
83710 --- a/include/video/udlfb.h
83711 +++ b/include/video/udlfb.h
83712 @@ -53,10 +53,10 @@ struct dlfb_data {
83713 u32 pseudo_palette[256];
83714 int blank_mode; /*one of FB_BLANK_ */
83715 /* blit-only rendering path metrics, exposed through sysfs */
83716 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83717 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
83718 - atomic_t bytes_sent; /* to usb, after compression including overhead */
83719 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
83720 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83721 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
83722 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
83723 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
83724 };
83725
83726 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
83727 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
83728 index 30f5362..8ed8ac9 100644
83729 --- a/include/video/uvesafb.h
83730 +++ b/include/video/uvesafb.h
83731 @@ -122,6 +122,7 @@ struct uvesafb_par {
83732 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
83733 u8 pmi_setpal; /* PMI for palette changes */
83734 u16 *pmi_base; /* protected mode interface location */
83735 + u8 *pmi_code; /* protected mode code location */
83736 void *pmi_start;
83737 void *pmi_pal;
83738 u8 *vbe_state_orig; /*
83739 diff --git a/init/Kconfig b/init/Kconfig
83740 index d56cb03..7e6d5dc 100644
83741 --- a/init/Kconfig
83742 +++ b/init/Kconfig
83743 @@ -1079,6 +1079,7 @@ endif # CGROUPS
83744
83745 config CHECKPOINT_RESTORE
83746 bool "Checkpoint/restore support" if EXPERT
83747 + depends on !GRKERNSEC
83748 default n
83749 help
83750 Enables additional kernel features in a sake of checkpoint/restore.
83751 @@ -1545,7 +1546,7 @@ config SLUB_DEBUG
83752
83753 config COMPAT_BRK
83754 bool "Disable heap randomization"
83755 - default y
83756 + default n
83757 help
83758 Randomizing heap placement makes heap exploits harder, but it
83759 also breaks ancient binaries (including anything libc5 based).
83760 @@ -1833,7 +1834,7 @@ config INIT_ALL_POSSIBLE
83761 config STOP_MACHINE
83762 bool
83763 default y
83764 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
83765 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
83766 help
83767 Need stop_machine() primitive.
83768
83769 diff --git a/init/Makefile b/init/Makefile
83770 index 7bc47ee..6da2dc7 100644
83771 --- a/init/Makefile
83772 +++ b/init/Makefile
83773 @@ -2,6 +2,9 @@
83774 # Makefile for the linux kernel.
83775 #
83776
83777 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
83778 +asflags-y := $(GCC_PLUGINS_AFLAGS)
83779 +
83780 obj-y := main.o version.o mounts.o
83781 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
83782 obj-y += noinitramfs.o
83783 diff --git a/init/do_mounts.c b/init/do_mounts.c
83784 index 8e5addc..c96ea61 100644
83785 --- a/init/do_mounts.c
83786 +++ b/init/do_mounts.c
83787 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
83788 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
83789 {
83790 struct super_block *s;
83791 - int err = sys_mount(name, "/root", fs, flags, data);
83792 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
83793 if (err)
83794 return err;
83795
83796 - sys_chdir("/root");
83797 + sys_chdir((const char __force_user *)"/root");
83798 s = current->fs->pwd.dentry->d_sb;
83799 ROOT_DEV = s->s_dev;
83800 printk(KERN_INFO
83801 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
83802 va_start(args, fmt);
83803 vsprintf(buf, fmt, args);
83804 va_end(args);
83805 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
83806 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
83807 if (fd >= 0) {
83808 sys_ioctl(fd, FDEJECT, 0);
83809 sys_close(fd);
83810 }
83811 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
83812 - fd = sys_open("/dev/console", O_RDWR, 0);
83813 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
83814 if (fd >= 0) {
83815 sys_ioctl(fd, TCGETS, (long)&termios);
83816 termios.c_lflag &= ~ICANON;
83817 sys_ioctl(fd, TCSETSF, (long)&termios);
83818 - sys_read(fd, &c, 1);
83819 + sys_read(fd, (char __user *)&c, 1);
83820 termios.c_lflag |= ICANON;
83821 sys_ioctl(fd, TCSETSF, (long)&termios);
83822 sys_close(fd);
83823 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
83824 mount_root();
83825 out:
83826 devtmpfs_mount("dev");
83827 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
83828 - sys_chroot(".");
83829 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
83830 + sys_chroot((const char __force_user *)".");
83831 }
83832
83833 static bool is_tmpfs;
83834 diff --git a/init/do_mounts.h b/init/do_mounts.h
83835 index f5b978a..69dbfe8 100644
83836 --- a/init/do_mounts.h
83837 +++ b/init/do_mounts.h
83838 @@ -15,15 +15,15 @@ extern int root_mountflags;
83839
83840 static inline int create_dev(char *name, dev_t dev)
83841 {
83842 - sys_unlink(name);
83843 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
83844 + sys_unlink((char __force_user *)name);
83845 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
83846 }
83847
83848 #if BITS_PER_LONG == 32
83849 static inline u32 bstat(char *name)
83850 {
83851 struct stat64 stat;
83852 - if (sys_stat64(name, &stat) != 0)
83853 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
83854 return 0;
83855 if (!S_ISBLK(stat.st_mode))
83856 return 0;
83857 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
83858 static inline u32 bstat(char *name)
83859 {
83860 struct stat stat;
83861 - if (sys_newstat(name, &stat) != 0)
83862 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
83863 return 0;
83864 if (!S_ISBLK(stat.st_mode))
83865 return 0;
83866 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
83867 index 3e0878e..8a9d7a0 100644
83868 --- a/init/do_mounts_initrd.c
83869 +++ b/init/do_mounts_initrd.c
83870 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
83871 {
83872 sys_unshare(CLONE_FS | CLONE_FILES);
83873 /* stdin/stdout/stderr for /linuxrc */
83874 - sys_open("/dev/console", O_RDWR, 0);
83875 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
83876 sys_dup(0);
83877 sys_dup(0);
83878 /* move initrd over / and chdir/chroot in initrd root */
83879 - sys_chdir("/root");
83880 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
83881 - sys_chroot(".");
83882 + sys_chdir((const char __force_user *)"/root");
83883 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
83884 + sys_chroot((const char __force_user *)".");
83885 sys_setsid();
83886 return 0;
83887 }
83888 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
83889 create_dev("/dev/root.old", Root_RAM0);
83890 /* mount initrd on rootfs' /root */
83891 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
83892 - sys_mkdir("/old", 0700);
83893 - sys_chdir("/old");
83894 + sys_mkdir((const char __force_user *)"/old", 0700);
83895 + sys_chdir((const char __force_user *)"/old");
83896
83897 /* try loading default modules from initrd */
83898 load_default_modules();
83899 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
83900 current->flags &= ~PF_FREEZER_SKIP;
83901
83902 /* move initrd to rootfs' /old */
83903 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
83904 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
83905 /* switch root and cwd back to / of rootfs */
83906 - sys_chroot("..");
83907 + sys_chroot((const char __force_user *)"..");
83908
83909 if (new_decode_dev(real_root_dev) == Root_RAM0) {
83910 - sys_chdir("/old");
83911 + sys_chdir((const char __force_user *)"/old");
83912 return;
83913 }
83914
83915 - sys_chdir("/");
83916 + sys_chdir((const char __force_user *)"/");
83917 ROOT_DEV = new_decode_dev(real_root_dev);
83918 mount_root();
83919
83920 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
83921 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
83922 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
83923 if (!error)
83924 printk("okay\n");
83925 else {
83926 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
83927 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
83928 if (error == -ENOENT)
83929 printk("/initrd does not exist. Ignored.\n");
83930 else
83931 printk("failed\n");
83932 printk(KERN_NOTICE "Unmounting old root\n");
83933 - sys_umount("/old", MNT_DETACH);
83934 + sys_umount((char __force_user *)"/old", MNT_DETACH);
83935 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
83936 if (fd < 0) {
83937 error = fd;
83938 @@ -127,11 +127,11 @@ int __init initrd_load(void)
83939 * mounted in the normal path.
83940 */
83941 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
83942 - sys_unlink("/initrd.image");
83943 + sys_unlink((const char __force_user *)"/initrd.image");
83944 handle_initrd();
83945 return 1;
83946 }
83947 }
83948 - sys_unlink("/initrd.image");
83949 + sys_unlink((const char __force_user *)"/initrd.image");
83950 return 0;
83951 }
83952 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
83953 index 8cb6db5..d729f50 100644
83954 --- a/init/do_mounts_md.c
83955 +++ b/init/do_mounts_md.c
83956 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
83957 partitioned ? "_d" : "", minor,
83958 md_setup_args[ent].device_names);
83959
83960 - fd = sys_open(name, 0, 0);
83961 + fd = sys_open((char __force_user *)name, 0, 0);
83962 if (fd < 0) {
83963 printk(KERN_ERR "md: open failed - cannot start "
83964 "array %s\n", name);
83965 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
83966 * array without it
83967 */
83968 sys_close(fd);
83969 - fd = sys_open(name, 0, 0);
83970 + fd = sys_open((char __force_user *)name, 0, 0);
83971 sys_ioctl(fd, BLKRRPART, 0);
83972 }
83973 sys_close(fd);
83974 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
83975
83976 wait_for_device_probe();
83977
83978 - fd = sys_open("/dev/md0", 0, 0);
83979 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
83980 if (fd >= 0) {
83981 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
83982 sys_close(fd);
83983 diff --git a/init/init_task.c b/init/init_task.c
83984 index ba0a7f36..2bcf1d5 100644
83985 --- a/init/init_task.c
83986 +++ b/init/init_task.c
83987 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
83988 * Initial thread structure. Alignment of this is handled by a special
83989 * linker map entry.
83990 */
83991 +#ifdef CONFIG_X86
83992 +union thread_union init_thread_union __init_task_data;
83993 +#else
83994 union thread_union init_thread_union __init_task_data =
83995 { INIT_THREAD_INFO(init_task) };
83996 +#endif
83997 diff --git a/init/initramfs.c b/init/initramfs.c
83998 index 93b6139..8d628b7 100644
83999 --- a/init/initramfs.c
84000 +++ b/init/initramfs.c
84001 @@ -84,7 +84,7 @@ static void __init free_hash(void)
84002 }
84003 }
84004
84005 -static long __init do_utime(char *filename, time_t mtime)
84006 +static long __init do_utime(char __force_user *filename, time_t mtime)
84007 {
84008 struct timespec t[2];
84009
84010 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
84011 struct dir_entry *de, *tmp;
84012 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84013 list_del(&de->list);
84014 - do_utime(de->name, de->mtime);
84015 + do_utime((char __force_user *)de->name, de->mtime);
84016 kfree(de->name);
84017 kfree(de);
84018 }
84019 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
84020 if (nlink >= 2) {
84021 char *old = find_link(major, minor, ino, mode, collected);
84022 if (old)
84023 - return (sys_link(old, collected) < 0) ? -1 : 1;
84024 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84025 }
84026 return 0;
84027 }
84028 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84029 {
84030 struct stat st;
84031
84032 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84033 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84034 if (S_ISDIR(st.st_mode))
84035 - sys_rmdir(path);
84036 + sys_rmdir((char __force_user *)path);
84037 else
84038 - sys_unlink(path);
84039 + sys_unlink((char __force_user *)path);
84040 }
84041 }
84042
84043 @@ -315,7 +315,7 @@ static int __init do_name(void)
84044 int openflags = O_WRONLY|O_CREAT;
84045 if (ml != 1)
84046 openflags |= O_TRUNC;
84047 - wfd = sys_open(collected, openflags, mode);
84048 + wfd = sys_open((char __force_user *)collected, openflags, mode);
84049
84050 if (wfd >= 0) {
84051 sys_fchown(wfd, uid, gid);
84052 @@ -327,17 +327,17 @@ static int __init do_name(void)
84053 }
84054 }
84055 } else if (S_ISDIR(mode)) {
84056 - sys_mkdir(collected, mode);
84057 - sys_chown(collected, uid, gid);
84058 - sys_chmod(collected, mode);
84059 + sys_mkdir((char __force_user *)collected, mode);
84060 + sys_chown((char __force_user *)collected, uid, gid);
84061 + sys_chmod((char __force_user *)collected, mode);
84062 dir_add(collected, mtime);
84063 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
84064 S_ISFIFO(mode) || S_ISSOCK(mode)) {
84065 if (maybe_link() == 0) {
84066 - sys_mknod(collected, mode, rdev);
84067 - sys_chown(collected, uid, gid);
84068 - sys_chmod(collected, mode);
84069 - do_utime(collected, mtime);
84070 + sys_mknod((char __force_user *)collected, mode, rdev);
84071 + sys_chown((char __force_user *)collected, uid, gid);
84072 + sys_chmod((char __force_user *)collected, mode);
84073 + do_utime((char __force_user *)collected, mtime);
84074 }
84075 }
84076 return 0;
84077 @@ -346,15 +346,15 @@ static int __init do_name(void)
84078 static int __init do_copy(void)
84079 {
84080 if (count >= body_len) {
84081 - sys_write(wfd, victim, body_len);
84082 + sys_write(wfd, (char __force_user *)victim, body_len);
84083 sys_close(wfd);
84084 - do_utime(vcollected, mtime);
84085 + do_utime((char __force_user *)vcollected, mtime);
84086 kfree(vcollected);
84087 eat(body_len);
84088 state = SkipIt;
84089 return 0;
84090 } else {
84091 - sys_write(wfd, victim, count);
84092 + sys_write(wfd, (char __force_user *)victim, count);
84093 body_len -= count;
84094 eat(count);
84095 return 1;
84096 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
84097 {
84098 collected[N_ALIGN(name_len) + body_len] = '\0';
84099 clean_path(collected, 0);
84100 - sys_symlink(collected + N_ALIGN(name_len), collected);
84101 - sys_lchown(collected, uid, gid);
84102 - do_utime(collected, mtime);
84103 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
84104 + sys_lchown((char __force_user *)collected, uid, gid);
84105 + do_utime((char __force_user *)collected, mtime);
84106 state = SkipIt;
84107 next_state = Reset;
84108 return 0;
84109 diff --git a/init/main.c b/init/main.c
84110 index 9c7fd4c..650b4f1 100644
84111 --- a/init/main.c
84112 +++ b/init/main.c
84113 @@ -97,6 +97,8 @@ extern void radix_tree_init(void);
84114 static inline void mark_rodata_ro(void) { }
84115 #endif
84116
84117 +extern void grsecurity_init(void);
84118 +
84119 /*
84120 * Debug helper: via this flag we know that we are in 'early bootup code'
84121 * where only the boot processor is running with IRQ disabled. This means
84122 @@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
84123
84124 __setup("reset_devices", set_reset_devices);
84125
84126 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84127 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
84128 +static int __init setup_grsec_proc_gid(char *str)
84129 +{
84130 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
84131 + return 1;
84132 +}
84133 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
84134 +#endif
84135 +
84136 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
84137 +unsigned long pax_user_shadow_base __read_only;
84138 +EXPORT_SYMBOL(pax_user_shadow_base);
84139 +extern char pax_enter_kernel_user[];
84140 +extern char pax_exit_kernel_user[];
84141 +#endif
84142 +
84143 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
84144 +static int __init setup_pax_nouderef(char *str)
84145 +{
84146 +#ifdef CONFIG_X86_32
84147 + unsigned int cpu;
84148 + struct desc_struct *gdt;
84149 +
84150 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
84151 + gdt = get_cpu_gdt_table(cpu);
84152 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
84153 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
84154 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
84155 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
84156 + }
84157 + loadsegment(ds, __KERNEL_DS);
84158 + loadsegment(es, __KERNEL_DS);
84159 + loadsegment(ss, __KERNEL_DS);
84160 +#else
84161 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
84162 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
84163 + clone_pgd_mask = ~(pgdval_t)0UL;
84164 + pax_user_shadow_base = 0UL;
84165 + setup_clear_cpu_cap(X86_FEATURE_PCID);
84166 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
84167 +#endif
84168 +
84169 + return 0;
84170 +}
84171 +early_param("pax_nouderef", setup_pax_nouderef);
84172 +
84173 +#ifdef CONFIG_X86_64
84174 +static int __init setup_pax_weakuderef(char *str)
84175 +{
84176 + if (clone_pgd_mask != ~(pgdval_t)0UL)
84177 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
84178 + return 1;
84179 +}
84180 +__setup("pax_weakuderef", setup_pax_weakuderef);
84181 +#endif
84182 +#endif
84183 +
84184 +#ifdef CONFIG_PAX_SOFTMODE
84185 +int pax_softmode;
84186 +
84187 +static int __init setup_pax_softmode(char *str)
84188 +{
84189 + get_option(&str, &pax_softmode);
84190 + return 1;
84191 +}
84192 +__setup("pax_softmode=", setup_pax_softmode);
84193 +#endif
84194 +
84195 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
84196 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
84197 static const char *panic_later, *panic_param;
84198 @@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
84199 {
84200 int count = preempt_count();
84201 int ret;
84202 - char msgbuf[64];
84203 + const char *msg1 = "", *msg2 = "";
84204
84205 if (initcall_debug)
84206 ret = do_one_initcall_debug(fn);
84207 else
84208 ret = fn();
84209
84210 - msgbuf[0] = 0;
84211 -
84212 if (preempt_count() != count) {
84213 - sprintf(msgbuf, "preemption imbalance ");
84214 + msg1 = " preemption imbalance";
84215 preempt_count_set(count);
84216 }
84217 if (irqs_disabled()) {
84218 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
84219 + msg2 = " disabled interrupts";
84220 local_irq_enable();
84221 }
84222 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
84223 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
84224
84225 + add_latent_entropy();
84226 return ret;
84227 }
84228
84229 @@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
84230 {
84231 argv_init[0] = init_filename;
84232 return do_execve(getname_kernel(init_filename),
84233 - (const char __user *const __user *)argv_init,
84234 - (const char __user *const __user *)envp_init);
84235 + (const char __user *const __force_user *)argv_init,
84236 + (const char __user *const __force_user *)envp_init);
84237 }
84238
84239 static int try_to_run_init_process(const char *init_filename)
84240 @@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
84241 return ret;
84242 }
84243
84244 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84245 +extern int gr_init_ran;
84246 +#endif
84247 +
84248 static noinline void __init kernel_init_freeable(void);
84249
84250 static int __ref kernel_init(void *unused)
84251 @@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
84252 ramdisk_execute_command, ret);
84253 }
84254
84255 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84256 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
84257 + gr_init_ran = 1;
84258 +#endif
84259 +
84260 /*
84261 * We try each of these until one succeeds.
84262 *
84263 @@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
84264 do_basic_setup();
84265
84266 /* Open the /dev/console on the rootfs, this should never fail */
84267 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
84268 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
84269 pr_err("Warning: unable to open an initial console.\n");
84270
84271 (void) sys_dup(0);
84272 @@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
84273 if (!ramdisk_execute_command)
84274 ramdisk_execute_command = "/init";
84275
84276 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
84277 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
84278 ramdisk_execute_command = NULL;
84279 prepare_namespace();
84280 }
84281
84282 + grsecurity_init();
84283 +
84284 /*
84285 * Ok, we have completed the initial bootup, and
84286 * we're essentially up and running. Get rid of the
84287 diff --git a/ipc/compat.c b/ipc/compat.c
84288 index f486b00..442867f 100644
84289 --- a/ipc/compat.c
84290 +++ b/ipc/compat.c
84291 @@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
84292 COMPAT_SHMLBA);
84293 if (err < 0)
84294 return err;
84295 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
84296 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
84297 }
84298 case SHMDT:
84299 return sys_shmdt(compat_ptr(ptr));
84300 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
84301 index 1702864..797fa84 100644
84302 --- a/ipc/ipc_sysctl.c
84303 +++ b/ipc/ipc_sysctl.c
84304 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
84305 static int proc_ipc_dointvec(ctl_table *table, int write,
84306 void __user *buffer, size_t *lenp, loff_t *ppos)
84307 {
84308 - struct ctl_table ipc_table;
84309 + ctl_table_no_const ipc_table;
84310
84311 memcpy(&ipc_table, table, sizeof(ipc_table));
84312 ipc_table.data = get_ipc(table);
84313 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
84314 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
84315 void __user *buffer, size_t *lenp, loff_t *ppos)
84316 {
84317 - struct ctl_table ipc_table;
84318 + ctl_table_no_const ipc_table;
84319
84320 memcpy(&ipc_table, table, sizeof(ipc_table));
84321 ipc_table.data = get_ipc(table);
84322 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
84323 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84324 void __user *buffer, size_t *lenp, loff_t *ppos)
84325 {
84326 - struct ctl_table ipc_table;
84327 + ctl_table_no_const ipc_table;
84328 size_t lenp_bef = *lenp;
84329 int rc;
84330
84331 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84332 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
84333 void __user *buffer, size_t *lenp, loff_t *ppos)
84334 {
84335 - struct ctl_table ipc_table;
84336 + ctl_table_no_const ipc_table;
84337 memcpy(&ipc_table, table, sizeof(ipc_table));
84338 ipc_table.data = get_ipc(table);
84339
84340 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
84341 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
84342 void __user *buffer, size_t *lenp, loff_t *ppos)
84343 {
84344 - struct ctl_table ipc_table;
84345 + ctl_table_no_const ipc_table;
84346 size_t lenp_bef = *lenp;
84347 int oldval;
84348 int rc;
84349 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
84350 index 5bb8bfe..a38ec05 100644
84351 --- a/ipc/mq_sysctl.c
84352 +++ b/ipc/mq_sysctl.c
84353 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
84354 static int proc_mq_dointvec(ctl_table *table, int write,
84355 void __user *buffer, size_t *lenp, loff_t *ppos)
84356 {
84357 - struct ctl_table mq_table;
84358 + ctl_table_no_const mq_table;
84359 memcpy(&mq_table, table, sizeof(mq_table));
84360 mq_table.data = get_mq(table);
84361
84362 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
84363 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
84364 void __user *buffer, size_t *lenp, loff_t *ppos)
84365 {
84366 - struct ctl_table mq_table;
84367 + ctl_table_no_const mq_table;
84368 memcpy(&mq_table, table, sizeof(mq_table));
84369 mq_table.data = get_mq(table);
84370
84371 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
84372 index c3b3117..1efa933 100644
84373 --- a/ipc/mqueue.c
84374 +++ b/ipc/mqueue.c
84375 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
84376 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
84377 info->attr.mq_msgsize);
84378
84379 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
84380 spin_lock(&mq_lock);
84381 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
84382 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
84383 diff --git a/ipc/msg.c b/ipc/msg.c
84384 index 6498531..b0ff3c8 100644
84385 --- a/ipc/msg.c
84386 +++ b/ipc/msg.c
84387 @@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
84388 return security_msg_queue_associate(msq, msgflg);
84389 }
84390
84391 +static struct ipc_ops msg_ops = {
84392 + .getnew = newque,
84393 + .associate = msg_security,
84394 + .more_checks = NULL
84395 +};
84396 +
84397 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
84398 {
84399 struct ipc_namespace *ns;
84400 - struct ipc_ops msg_ops;
84401 struct ipc_params msg_params;
84402
84403 ns = current->nsproxy->ipc_ns;
84404
84405 - msg_ops.getnew = newque;
84406 - msg_ops.associate = msg_security;
84407 - msg_ops.more_checks = NULL;
84408 -
84409 msg_params.key = key;
84410 msg_params.flg = msgflg;
84411
84412 diff --git a/ipc/sem.c b/ipc/sem.c
84413 index bee5554..e9af81dd 100644
84414 --- a/ipc/sem.c
84415 +++ b/ipc/sem.c
84416 @@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
84417 return 0;
84418 }
84419
84420 +static struct ipc_ops sem_ops = {
84421 + .getnew = newary,
84422 + .associate = sem_security,
84423 + .more_checks = sem_more_checks
84424 +};
84425 +
84426 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84427 {
84428 struct ipc_namespace *ns;
84429 - struct ipc_ops sem_ops;
84430 struct ipc_params sem_params;
84431
84432 ns = current->nsproxy->ipc_ns;
84433 @@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84434 if (nsems < 0 || nsems > ns->sc_semmsl)
84435 return -EINVAL;
84436
84437 - sem_ops.getnew = newary;
84438 - sem_ops.associate = sem_security;
84439 - sem_ops.more_checks = sem_more_checks;
84440 -
84441 sem_params.key = key;
84442 sem_params.flg = semflg;
84443 sem_params.u.nsems = nsems;
84444 diff --git a/ipc/shm.c b/ipc/shm.c
84445 index 7645961..afc7f02 100644
84446 --- a/ipc/shm.c
84447 +++ b/ipc/shm.c
84448 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
84449 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
84450 #endif
84451
84452 +#ifdef CONFIG_GRKERNSEC
84453 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84454 + const time_t shm_createtime, const kuid_t cuid,
84455 + const int shmid);
84456 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84457 + const time_t shm_createtime);
84458 +#endif
84459 +
84460 void shm_init_ns(struct ipc_namespace *ns)
84461 {
84462 ns->shm_ctlmax = SHMMAX;
84463 @@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
84464 shp->shm_lprid = 0;
84465 shp->shm_atim = shp->shm_dtim = 0;
84466 shp->shm_ctim = get_seconds();
84467 +#ifdef CONFIG_GRKERNSEC
84468 + {
84469 + struct timespec timeval;
84470 + do_posix_clock_monotonic_gettime(&timeval);
84471 +
84472 + shp->shm_createtime = timeval.tv_sec;
84473 + }
84474 +#endif
84475 shp->shm_segsz = size;
84476 shp->shm_nattch = 0;
84477 shp->shm_file = file;
84478 @@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
84479 return 0;
84480 }
84481
84482 +static struct ipc_ops shm_ops = {
84483 + .getnew = newseg,
84484 + .associate = shm_security,
84485 + .more_checks = shm_more_checks
84486 +};
84487 +
84488 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
84489 {
84490 struct ipc_namespace *ns;
84491 - struct ipc_ops shm_ops;
84492 struct ipc_params shm_params;
84493
84494 ns = current->nsproxy->ipc_ns;
84495
84496 - shm_ops.getnew = newseg;
84497 - shm_ops.associate = shm_security;
84498 - shm_ops.more_checks = shm_more_checks;
84499 -
84500 shm_params.key = key;
84501 shm_params.flg = shmflg;
84502 shm_params.u.size = size;
84503 @@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84504 f_mode = FMODE_READ | FMODE_WRITE;
84505 }
84506 if (shmflg & SHM_EXEC) {
84507 +
84508 +#ifdef CONFIG_PAX_MPROTECT
84509 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
84510 + goto out;
84511 +#endif
84512 +
84513 prot |= PROT_EXEC;
84514 acc_mode |= S_IXUGO;
84515 }
84516 @@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84517 if (err)
84518 goto out_unlock;
84519
84520 +#ifdef CONFIG_GRKERNSEC
84521 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
84522 + shp->shm_perm.cuid, shmid) ||
84523 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
84524 + err = -EACCES;
84525 + goto out_unlock;
84526 + }
84527 +#endif
84528 +
84529 ipc_lock_object(&shp->shm_perm);
84530
84531 /* check if shm_destroy() is tearing down shp */
84532 @@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84533 path = shp->shm_file->f_path;
84534 path_get(&path);
84535 shp->shm_nattch++;
84536 +#ifdef CONFIG_GRKERNSEC
84537 + shp->shm_lapid = current->pid;
84538 +#endif
84539 size = i_size_read(path.dentry->d_inode);
84540 ipc_unlock_object(&shp->shm_perm);
84541 rcu_read_unlock();
84542 diff --git a/ipc/util.c b/ipc/util.c
84543 index e1b4c6d..8174204 100644
84544 --- a/ipc/util.c
84545 +++ b/ipc/util.c
84546 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
84547 int (*show)(struct seq_file *, void *);
84548 };
84549
84550 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
84551 +
84552 static void ipc_memory_notifier(struct work_struct *work)
84553 {
84554 ipcns_notify(IPCNS_MEMCHANGED);
84555 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
84556 granted_mode >>= 6;
84557 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
84558 granted_mode >>= 3;
84559 +
84560 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
84561 + return -1;
84562 +
84563 /* is there some bit set in requested_mode but not in granted_mode? */
84564 if ((requested_mode & ~granted_mode & 0007) &&
84565 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
84566 diff --git a/kernel/acct.c b/kernel/acct.c
84567 index 8d6e145..33e0b1e 100644
84568 --- a/kernel/acct.c
84569 +++ b/kernel/acct.c
84570 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
84571 */
84572 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
84573 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
84574 - file->f_op->write(file, (char *)&ac,
84575 + file->f_op->write(file, (char __force_user *)&ac,
84576 sizeof(acct_t), &file->f_pos);
84577 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
84578 set_fs(fs);
84579 diff --git a/kernel/audit.c b/kernel/audit.c
84580 index 95a20f3..e1cb300 100644
84581 --- a/kernel/audit.c
84582 +++ b/kernel/audit.c
84583 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
84584 3) suppressed due to audit_rate_limit
84585 4) suppressed due to audit_backlog_limit
84586 */
84587 -static atomic_t audit_lost = ATOMIC_INIT(0);
84588 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
84589
84590 /* The netlink socket. */
84591 static struct sock *audit_sock;
84592 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
84593 unsigned long now;
84594 int print;
84595
84596 - atomic_inc(&audit_lost);
84597 + atomic_inc_unchecked(&audit_lost);
84598
84599 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
84600
84601 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
84602 if (print) {
84603 if (printk_ratelimit())
84604 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
84605 - atomic_read(&audit_lost),
84606 + atomic_read_unchecked(&audit_lost),
84607 audit_rate_limit,
84608 audit_backlog_limit);
84609 audit_panic(message);
84610 @@ -803,7 +803,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84611 s.pid = audit_pid;
84612 s.rate_limit = audit_rate_limit;
84613 s.backlog_limit = audit_backlog_limit;
84614 - s.lost = atomic_read(&audit_lost);
84615 + s.lost = atomic_read_unchecked(&audit_lost);
84616 s.backlog = skb_queue_len(&audit_skb_queue);
84617 s.version = AUDIT_VERSION_LATEST;
84618 s.backlog_wait_time = audit_backlog_wait_time;
84619 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
84620 index 7aef2f4..db6ced2 100644
84621 --- a/kernel/auditsc.c
84622 +++ b/kernel/auditsc.c
84623 @@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
84624 }
84625
84626 /* global counter which is incremented every time something logs in */
84627 -static atomic_t session_id = ATOMIC_INIT(0);
84628 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
84629
84630 static int audit_set_loginuid_perm(kuid_t loginuid)
84631 {
84632 @@ -2014,7 +2014,7 @@ int audit_set_loginuid(kuid_t loginuid)
84633
84634 /* are we setting or clearing? */
84635 if (uid_valid(loginuid))
84636 - sessionid = (unsigned int)atomic_inc_return(&session_id);
84637 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
84638
84639 task->sessionid = sessionid;
84640 task->loginuid = loginuid;
84641 diff --git a/kernel/capability.c b/kernel/capability.c
84642 index 34019c5..363f279 100644
84643 --- a/kernel/capability.c
84644 +++ b/kernel/capability.c
84645 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
84646 * before modification is attempted and the application
84647 * fails.
84648 */
84649 + if (tocopy > ARRAY_SIZE(kdata))
84650 + return -EFAULT;
84651 +
84652 if (copy_to_user(dataptr, kdata, tocopy
84653 * sizeof(struct __user_cap_data_struct))) {
84654 return -EFAULT;
84655 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
84656 int ret;
84657
84658 rcu_read_lock();
84659 - ret = security_capable(__task_cred(t), ns, cap);
84660 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
84661 + gr_task_is_capable(t, __task_cred(t), cap);
84662 rcu_read_unlock();
84663
84664 - return (ret == 0);
84665 + return ret;
84666 }
84667
84668 /**
84669 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
84670 int ret;
84671
84672 rcu_read_lock();
84673 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
84674 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
84675 rcu_read_unlock();
84676
84677 - return (ret == 0);
84678 + return ret;
84679 }
84680
84681 /**
84682 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
84683 BUG();
84684 }
84685
84686 - if (security_capable(current_cred(), ns, cap) == 0) {
84687 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
84688 current->flags |= PF_SUPERPRIV;
84689 return true;
84690 }
84691 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
84692 }
84693 EXPORT_SYMBOL(ns_capable);
84694
84695 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
84696 +{
84697 + if (unlikely(!cap_valid(cap))) {
84698 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
84699 + BUG();
84700 + }
84701 +
84702 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
84703 + current->flags |= PF_SUPERPRIV;
84704 + return true;
84705 + }
84706 + return false;
84707 +}
84708 +EXPORT_SYMBOL(ns_capable_nolog);
84709 +
84710 /**
84711 * file_ns_capable - Determine if the file's opener had a capability in effect
84712 * @file: The file we want to check
84713 @@ -432,6 +451,12 @@ bool capable(int cap)
84714 }
84715 EXPORT_SYMBOL(capable);
84716
84717 +bool capable_nolog(int cap)
84718 +{
84719 + return ns_capable_nolog(&init_user_ns, cap);
84720 +}
84721 +EXPORT_SYMBOL(capable_nolog);
84722 +
84723 /**
84724 * inode_capable - Check superior capability over inode
84725 * @inode: The inode in question
84726 @@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
84727 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84728 }
84729 EXPORT_SYMBOL(inode_capable);
84730 +
84731 +bool inode_capable_nolog(const struct inode *inode, int cap)
84732 +{
84733 + struct user_namespace *ns = current_user_ns();
84734 +
84735 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84736 +}
84737 +EXPORT_SYMBOL(inode_capable_nolog);
84738 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
84739 index 0c753dd..dd7d3d6 100644
84740 --- a/kernel/cgroup.c
84741 +++ b/kernel/cgroup.c
84742 @@ -5372,7 +5372,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
84743 struct css_set *cset = link->cset;
84744 struct task_struct *task;
84745 int count = 0;
84746 - seq_printf(seq, "css_set %p\n", cset);
84747 + seq_printf(seq, "css_set %pK\n", cset);
84748 list_for_each_entry(task, &cset->tasks, cg_list) {
84749 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
84750 seq_puts(seq, " ...\n");
84751 diff --git a/kernel/compat.c b/kernel/compat.c
84752 index 0a09e48..b46b3d78 100644
84753 --- a/kernel/compat.c
84754 +++ b/kernel/compat.c
84755 @@ -13,6 +13,7 @@
84756
84757 #include <linux/linkage.h>
84758 #include <linux/compat.h>
84759 +#include <linux/module.h>
84760 #include <linux/errno.h>
84761 #include <linux/time.h>
84762 #include <linux/signal.h>
84763 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
84764 mm_segment_t oldfs;
84765 long ret;
84766
84767 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
84768 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
84769 oldfs = get_fs();
84770 set_fs(KERNEL_DS);
84771 ret = hrtimer_nanosleep_restart(restart);
84772 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
84773 oldfs = get_fs();
84774 set_fs(KERNEL_DS);
84775 ret = hrtimer_nanosleep(&tu,
84776 - rmtp ? (struct timespec __user *)&rmt : NULL,
84777 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
84778 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
84779 set_fs(oldfs);
84780
84781 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
84782 mm_segment_t old_fs = get_fs();
84783
84784 set_fs(KERNEL_DS);
84785 - ret = sys_sigpending((old_sigset_t __user *) &s);
84786 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
84787 set_fs(old_fs);
84788 if (ret == 0)
84789 ret = put_user(s, set);
84790 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
84791 mm_segment_t old_fs = get_fs();
84792
84793 set_fs(KERNEL_DS);
84794 - ret = sys_old_getrlimit(resource, &r);
84795 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
84796 set_fs(old_fs);
84797
84798 if (!ret) {
84799 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
84800 set_fs (KERNEL_DS);
84801 ret = sys_wait4(pid,
84802 (stat_addr ?
84803 - (unsigned int __user *) &status : NULL),
84804 - options, (struct rusage __user *) &r);
84805 + (unsigned int __force_user *) &status : NULL),
84806 + options, (struct rusage __force_user *) &r);
84807 set_fs (old_fs);
84808
84809 if (ret > 0) {
84810 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
84811 memset(&info, 0, sizeof(info));
84812
84813 set_fs(KERNEL_DS);
84814 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
84815 - uru ? (struct rusage __user *)&ru : NULL);
84816 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
84817 + uru ? (struct rusage __force_user *)&ru : NULL);
84818 set_fs(old_fs);
84819
84820 if ((ret < 0) || (info.si_signo == 0))
84821 @@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
84822 oldfs = get_fs();
84823 set_fs(KERNEL_DS);
84824 err = sys_timer_settime(timer_id, flags,
84825 - (struct itimerspec __user *) &newts,
84826 - (struct itimerspec __user *) &oldts);
84827 + (struct itimerspec __force_user *) &newts,
84828 + (struct itimerspec __force_user *) &oldts);
84829 set_fs(oldfs);
84830 if (!err && old && put_compat_itimerspec(old, &oldts))
84831 return -EFAULT;
84832 @@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
84833 oldfs = get_fs();
84834 set_fs(KERNEL_DS);
84835 err = sys_timer_gettime(timer_id,
84836 - (struct itimerspec __user *) &ts);
84837 + (struct itimerspec __force_user *) &ts);
84838 set_fs(oldfs);
84839 if (!err && put_compat_itimerspec(setting, &ts))
84840 return -EFAULT;
84841 @@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
84842 oldfs = get_fs();
84843 set_fs(KERNEL_DS);
84844 err = sys_clock_settime(which_clock,
84845 - (struct timespec __user *) &ts);
84846 + (struct timespec __force_user *) &ts);
84847 set_fs(oldfs);
84848 return err;
84849 }
84850 @@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
84851 oldfs = get_fs();
84852 set_fs(KERNEL_DS);
84853 err = sys_clock_gettime(which_clock,
84854 - (struct timespec __user *) &ts);
84855 + (struct timespec __force_user *) &ts);
84856 set_fs(oldfs);
84857 if (!err && put_compat_timespec(&ts, tp))
84858 return -EFAULT;
84859 @@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
84860
84861 oldfs = get_fs();
84862 set_fs(KERNEL_DS);
84863 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
84864 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
84865 set_fs(oldfs);
84866
84867 err = compat_put_timex(utp, &txc);
84868 @@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
84869 oldfs = get_fs();
84870 set_fs(KERNEL_DS);
84871 err = sys_clock_getres(which_clock,
84872 - (struct timespec __user *) &ts);
84873 + (struct timespec __force_user *) &ts);
84874 set_fs(oldfs);
84875 if (!err && tp && put_compat_timespec(&ts, tp))
84876 return -EFAULT;
84877 @@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
84878 long err;
84879 mm_segment_t oldfs;
84880 struct timespec tu;
84881 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
84882 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
84883
84884 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
84885 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
84886 oldfs = get_fs();
84887 set_fs(KERNEL_DS);
84888 err = clock_nanosleep_restart(restart);
84889 @@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
84890 oldfs = get_fs();
84891 set_fs(KERNEL_DS);
84892 err = sys_clock_nanosleep(which_clock, flags,
84893 - (struct timespec __user *) &in,
84894 - (struct timespec __user *) &out);
84895 + (struct timespec __force_user *) &in,
84896 + (struct timespec __force_user *) &out);
84897 set_fs(oldfs);
84898
84899 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
84900 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
84901 mm_segment_t old_fs = get_fs();
84902
84903 set_fs(KERNEL_DS);
84904 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
84905 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
84906 set_fs(old_fs);
84907 if (put_compat_timespec(&t, interval))
84908 return -EFAULT;
84909 diff --git a/kernel/configs.c b/kernel/configs.c
84910 index c18b1f1..b9a0132 100644
84911 --- a/kernel/configs.c
84912 +++ b/kernel/configs.c
84913 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
84914 struct proc_dir_entry *entry;
84915
84916 /* create the current config file */
84917 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
84918 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
84919 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
84920 + &ikconfig_file_ops);
84921 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84922 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
84923 + &ikconfig_file_ops);
84924 +#endif
84925 +#else
84926 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
84927 &ikconfig_file_ops);
84928 +#endif
84929 +
84930 if (!entry)
84931 return -ENOMEM;
84932
84933 diff --git a/kernel/cred.c b/kernel/cred.c
84934 index e0573a4..3874e41 100644
84935 --- a/kernel/cred.c
84936 +++ b/kernel/cred.c
84937 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
84938 validate_creds(cred);
84939 alter_cred_subscribers(cred, -1);
84940 put_cred(cred);
84941 +
84942 +#ifdef CONFIG_GRKERNSEC_SETXID
84943 + cred = (struct cred *) tsk->delayed_cred;
84944 + if (cred != NULL) {
84945 + tsk->delayed_cred = NULL;
84946 + validate_creds(cred);
84947 + alter_cred_subscribers(cred, -1);
84948 + put_cred(cred);
84949 + }
84950 +#endif
84951 }
84952
84953 /**
84954 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
84955 * Always returns 0 thus allowing this function to be tail-called at the end
84956 * of, say, sys_setgid().
84957 */
84958 -int commit_creds(struct cred *new)
84959 +static int __commit_creds(struct cred *new)
84960 {
84961 struct task_struct *task = current;
84962 const struct cred *old = task->real_cred;
84963 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
84964
84965 get_cred(new); /* we will require a ref for the subj creds too */
84966
84967 + gr_set_role_label(task, new->uid, new->gid);
84968 +
84969 /* dumpability changes */
84970 if (!uid_eq(old->euid, new->euid) ||
84971 !gid_eq(old->egid, new->egid) ||
84972 @@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
84973 put_cred(old);
84974 return 0;
84975 }
84976 +#ifdef CONFIG_GRKERNSEC_SETXID
84977 +extern int set_user(struct cred *new);
84978 +
84979 +void gr_delayed_cred_worker(void)
84980 +{
84981 + const struct cred *new = current->delayed_cred;
84982 + struct cred *ncred;
84983 +
84984 + current->delayed_cred = NULL;
84985 +
84986 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
84987 + // from doing get_cred on it when queueing this
84988 + put_cred(new);
84989 + return;
84990 + } else if (new == NULL)
84991 + return;
84992 +
84993 + ncred = prepare_creds();
84994 + if (!ncred)
84995 + goto die;
84996 + // uids
84997 + ncred->uid = new->uid;
84998 + ncred->euid = new->euid;
84999 + ncred->suid = new->suid;
85000 + ncred->fsuid = new->fsuid;
85001 + // gids
85002 + ncred->gid = new->gid;
85003 + ncred->egid = new->egid;
85004 + ncred->sgid = new->sgid;
85005 + ncred->fsgid = new->fsgid;
85006 + // groups
85007 + if (set_groups(ncred, new->group_info) < 0) {
85008 + abort_creds(ncred);
85009 + goto die;
85010 + }
85011 + // caps
85012 + ncred->securebits = new->securebits;
85013 + ncred->cap_inheritable = new->cap_inheritable;
85014 + ncred->cap_permitted = new->cap_permitted;
85015 + ncred->cap_effective = new->cap_effective;
85016 + ncred->cap_bset = new->cap_bset;
85017 +
85018 + if (set_user(ncred)) {
85019 + abort_creds(ncred);
85020 + goto die;
85021 + }
85022 +
85023 + // from doing get_cred on it when queueing this
85024 + put_cred(new);
85025 +
85026 + __commit_creds(ncred);
85027 + return;
85028 +die:
85029 + // from doing get_cred on it when queueing this
85030 + put_cred(new);
85031 + do_group_exit(SIGKILL);
85032 +}
85033 +#endif
85034 +
85035 +int commit_creds(struct cred *new)
85036 +{
85037 +#ifdef CONFIG_GRKERNSEC_SETXID
85038 + int ret;
85039 + int schedule_it = 0;
85040 + struct task_struct *t;
85041 +
85042 + /* we won't get called with tasklist_lock held for writing
85043 + and interrupts disabled as the cred struct in that case is
85044 + init_cred
85045 + */
85046 + if (grsec_enable_setxid && !current_is_single_threaded() &&
85047 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85048 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85049 + schedule_it = 1;
85050 + }
85051 + ret = __commit_creds(new);
85052 + if (schedule_it) {
85053 + rcu_read_lock();
85054 + read_lock(&tasklist_lock);
85055 + for (t = next_thread(current); t != current;
85056 + t = next_thread(t)) {
85057 + if (t->delayed_cred == NULL) {
85058 + t->delayed_cred = get_cred(new);
85059 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
85060 + set_tsk_need_resched(t);
85061 + }
85062 + }
85063 + read_unlock(&tasklist_lock);
85064 + rcu_read_unlock();
85065 + }
85066 + return ret;
85067 +#else
85068 + return __commit_creds(new);
85069 +#endif
85070 +}
85071 +
85072 EXPORT_SYMBOL(commit_creds);
85073
85074 /**
85075 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
85076 index 334b398..9145fb1 100644
85077 --- a/kernel/debug/debug_core.c
85078 +++ b/kernel/debug/debug_core.c
85079 @@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
85080 */
85081 static atomic_t masters_in_kgdb;
85082 static atomic_t slaves_in_kgdb;
85083 -static atomic_t kgdb_break_tasklet_var;
85084 +static atomic_unchecked_t kgdb_break_tasklet_var;
85085 atomic_t kgdb_setting_breakpoint;
85086
85087 struct task_struct *kgdb_usethread;
85088 @@ -133,7 +133,7 @@ int kgdb_single_step;
85089 static pid_t kgdb_sstep_pid;
85090
85091 /* to keep track of the CPU which is doing the single stepping*/
85092 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85093 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85094
85095 /*
85096 * If you are debugging a problem where roundup (the collection of
85097 @@ -541,7 +541,7 @@ return_normal:
85098 * kernel will only try for the value of sstep_tries before
85099 * giving up and continuing on.
85100 */
85101 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
85102 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
85103 (kgdb_info[cpu].task &&
85104 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
85105 atomic_set(&kgdb_active, -1);
85106 @@ -639,8 +639,8 @@ cpu_master_loop:
85107 }
85108
85109 kgdb_restore:
85110 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
85111 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
85112 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
85113 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
85114 if (kgdb_info[sstep_cpu].task)
85115 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
85116 else
85117 @@ -917,18 +917,18 @@ static void kgdb_unregister_callbacks(void)
85118 static void kgdb_tasklet_bpt(unsigned long ing)
85119 {
85120 kgdb_breakpoint();
85121 - atomic_set(&kgdb_break_tasklet_var, 0);
85122 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
85123 }
85124
85125 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
85126
85127 void kgdb_schedule_breakpoint(void)
85128 {
85129 - if (atomic_read(&kgdb_break_tasklet_var) ||
85130 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
85131 atomic_read(&kgdb_active) != -1 ||
85132 atomic_read(&kgdb_setting_breakpoint))
85133 return;
85134 - atomic_inc(&kgdb_break_tasklet_var);
85135 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
85136 tasklet_schedule(&kgdb_tasklet_breakpoint);
85137 }
85138 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
85139 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
85140 index 0b097c8..11dd5c5 100644
85141 --- a/kernel/debug/kdb/kdb_main.c
85142 +++ b/kernel/debug/kdb/kdb_main.c
85143 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
85144 continue;
85145
85146 kdb_printf("%-20s%8u 0x%p ", mod->name,
85147 - mod->core_size, (void *)mod);
85148 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
85149 #ifdef CONFIG_MODULE_UNLOAD
85150 kdb_printf("%4ld ", module_refcount(mod));
85151 #endif
85152 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
85153 kdb_printf(" (Loading)");
85154 else
85155 kdb_printf(" (Live)");
85156 - kdb_printf(" 0x%p", mod->module_core);
85157 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
85158
85159 #ifdef CONFIG_MODULE_UNLOAD
85160 {
85161 diff --git a/kernel/events/core.c b/kernel/events/core.c
85162 index fa0b2d4..67a1c7a 100644
85163 --- a/kernel/events/core.c
85164 +++ b/kernel/events/core.c
85165 @@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
85166 * 0 - disallow raw tracepoint access for unpriv
85167 * 1 - disallow cpu events for unpriv
85168 * 2 - disallow kernel profiling for unpriv
85169 + * 3 - disallow all unpriv perf event use
85170 */
85171 -int sysctl_perf_event_paranoid __read_mostly = 1;
85172 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85173 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
85174 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
85175 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
85176 +#else
85177 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
85178 +#endif
85179
85180 /* Minimum for 512 kiB + 1 user control page */
85181 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
85182 @@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
85183
85184 tmp *= sysctl_perf_cpu_time_max_percent;
85185 do_div(tmp, 100);
85186 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
85187 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
85188 }
85189
85190 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
85191 @@ -272,7 +279,7 @@ void perf_sample_event_took(u64 sample_len_ns)
85192 update_perf_cpu_limits();
85193 }
85194
85195 -static atomic64_t perf_event_id;
85196 +static atomic64_unchecked_t perf_event_id;
85197
85198 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
85199 enum event_type_t event_type);
85200 @@ -2986,7 +2993,7 @@ static void __perf_event_read(void *info)
85201
85202 static inline u64 perf_event_count(struct perf_event *event)
85203 {
85204 - return local64_read(&event->count) + atomic64_read(&event->child_count);
85205 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
85206 }
85207
85208 static u64 perf_event_read(struct perf_event *event)
85209 @@ -3354,9 +3361,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
85210 mutex_lock(&event->child_mutex);
85211 total += perf_event_read(event);
85212 *enabled += event->total_time_enabled +
85213 - atomic64_read(&event->child_total_time_enabled);
85214 + atomic64_read_unchecked(&event->child_total_time_enabled);
85215 *running += event->total_time_running +
85216 - atomic64_read(&event->child_total_time_running);
85217 + atomic64_read_unchecked(&event->child_total_time_running);
85218
85219 list_for_each_entry(child, &event->child_list, child_list) {
85220 total += perf_event_read(child);
85221 @@ -3785,10 +3792,10 @@ void perf_event_update_userpage(struct perf_event *event)
85222 userpg->offset -= local64_read(&event->hw.prev_count);
85223
85224 userpg->time_enabled = enabled +
85225 - atomic64_read(&event->child_total_time_enabled);
85226 + atomic64_read_unchecked(&event->child_total_time_enabled);
85227
85228 userpg->time_running = running +
85229 - atomic64_read(&event->child_total_time_running);
85230 + atomic64_read_unchecked(&event->child_total_time_running);
85231
85232 arch_perf_update_userpage(userpg, now);
85233
85234 @@ -4339,7 +4346,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
85235
85236 /* Data. */
85237 sp = perf_user_stack_pointer(regs);
85238 - rem = __output_copy_user(handle, (void *) sp, dump_size);
85239 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
85240 dyn_size = dump_size - rem;
85241
85242 perf_output_skip(handle, rem);
85243 @@ -4430,11 +4437,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
85244 values[n++] = perf_event_count(event);
85245 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
85246 values[n++] = enabled +
85247 - atomic64_read(&event->child_total_time_enabled);
85248 + atomic64_read_unchecked(&event->child_total_time_enabled);
85249 }
85250 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
85251 values[n++] = running +
85252 - atomic64_read(&event->child_total_time_running);
85253 + atomic64_read_unchecked(&event->child_total_time_running);
85254 }
85255 if (read_format & PERF_FORMAT_ID)
85256 values[n++] = primary_event_id(event);
85257 @@ -6704,7 +6711,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
85258 event->parent = parent_event;
85259
85260 event->ns = get_pid_ns(task_active_pid_ns(current));
85261 - event->id = atomic64_inc_return(&perf_event_id);
85262 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
85263
85264 event->state = PERF_EVENT_STATE_INACTIVE;
85265
85266 @@ -7004,6 +7011,11 @@ SYSCALL_DEFINE5(perf_event_open,
85267 if (flags & ~PERF_FLAG_ALL)
85268 return -EINVAL;
85269
85270 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85271 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
85272 + return -EACCES;
85273 +#endif
85274 +
85275 err = perf_copy_attr(attr_uptr, &attr);
85276 if (err)
85277 return err;
85278 @@ -7339,10 +7351,10 @@ static void sync_child_event(struct perf_event *child_event,
85279 /*
85280 * Add back the child's count to the parent's count:
85281 */
85282 - atomic64_add(child_val, &parent_event->child_count);
85283 - atomic64_add(child_event->total_time_enabled,
85284 + atomic64_add_unchecked(child_val, &parent_event->child_count);
85285 + atomic64_add_unchecked(child_event->total_time_enabled,
85286 &parent_event->child_total_time_enabled);
85287 - atomic64_add(child_event->total_time_running,
85288 + atomic64_add_unchecked(child_event->total_time_running,
85289 &parent_event->child_total_time_running);
85290
85291 /*
85292 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
85293 index 569b2187..19940d9 100644
85294 --- a/kernel/events/internal.h
85295 +++ b/kernel/events/internal.h
85296 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
85297 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
85298 }
85299
85300 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
85301 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
85302 static inline unsigned long \
85303 func_name(struct perf_output_handle *handle, \
85304 - const void *buf, unsigned long len) \
85305 + const void user *buf, unsigned long len) \
85306 { \
85307 unsigned long size, written; \
85308 \
85309 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
85310 return 0;
85311 }
85312
85313 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
85314 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
85315
85316 static inline unsigned long
85317 memcpy_skip(void *dst, const void *src, unsigned long n)
85318 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
85319 return 0;
85320 }
85321
85322 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
85323 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
85324
85325 #ifndef arch_perf_out_copy_user
85326 #define arch_perf_out_copy_user arch_perf_out_copy_user
85327 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
85328 }
85329 #endif
85330
85331 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
85332 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
85333
85334 /* Callchain handling */
85335 extern struct perf_callchain_entry *
85336 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
85337 index 307d87c..6466cbe 100644
85338 --- a/kernel/events/uprobes.c
85339 +++ b/kernel/events/uprobes.c
85340 @@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
85341 {
85342 struct page *page;
85343 uprobe_opcode_t opcode;
85344 - int result;
85345 + long result;
85346
85347 pagefault_disable();
85348 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
85349 diff --git a/kernel/exit.c b/kernel/exit.c
85350 index 1e77fc6..6fd7391 100644
85351 --- a/kernel/exit.c
85352 +++ b/kernel/exit.c
85353 @@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
85354 struct task_struct *leader;
85355 int zap_leader;
85356 repeat:
85357 +#ifdef CONFIG_NET
85358 + gr_del_task_from_ip_table(p);
85359 +#endif
85360 +
85361 /* don't need to get the RCU readlock here - the process is dead and
85362 * can't be modifying its own credentials. But shut RCU-lockdep up */
85363 rcu_read_lock();
85364 @@ -330,7 +334,7 @@ int allow_signal(int sig)
85365 * know it'll be handled, so that they don't get converted to
85366 * SIGKILL or just silently dropped.
85367 */
85368 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
85369 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
85370 recalc_sigpending();
85371 spin_unlock_irq(&current->sighand->siglock);
85372 return 0;
85373 @@ -699,6 +703,8 @@ void do_exit(long code)
85374 struct task_struct *tsk = current;
85375 int group_dead;
85376
85377 + set_fs(USER_DS);
85378 +
85379 profile_task_exit(tsk);
85380
85381 WARN_ON(blk_needs_flush_plug(tsk));
85382 @@ -715,7 +721,6 @@ void do_exit(long code)
85383 * mm_release()->clear_child_tid() from writing to a user-controlled
85384 * kernel address.
85385 */
85386 - set_fs(USER_DS);
85387
85388 ptrace_event(PTRACE_EVENT_EXIT, code);
85389
85390 @@ -774,6 +779,9 @@ void do_exit(long code)
85391 tsk->exit_code = code;
85392 taskstats_exit(tsk, group_dead);
85393
85394 + gr_acl_handle_psacct(tsk, code);
85395 + gr_acl_handle_exit();
85396 +
85397 exit_mm(tsk);
85398
85399 if (group_dead)
85400 @@ -895,7 +903,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
85401 * Take down every thread in the group. This is called by fatal signals
85402 * as well as by sys_exit_group (below).
85403 */
85404 -void
85405 +__noreturn void
85406 do_group_exit(int exit_code)
85407 {
85408 struct signal_struct *sig = current->signal;
85409 diff --git a/kernel/fork.c b/kernel/fork.c
85410 index a17621c..b77fef8 100644
85411 --- a/kernel/fork.c
85412 +++ b/kernel/fork.c
85413 @@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
85414 *stackend = STACK_END_MAGIC; /* for overflow detection */
85415
85416 #ifdef CONFIG_CC_STACKPROTECTOR
85417 - tsk->stack_canary = get_random_int();
85418 + tsk->stack_canary = pax_get_random_long();
85419 #endif
85420
85421 /*
85422 @@ -345,12 +345,80 @@ free_tsk:
85423 }
85424
85425 #ifdef CONFIG_MMU
85426 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85427 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
85428 +{
85429 + struct vm_area_struct *tmp;
85430 + unsigned long charge;
85431 + struct file *file;
85432 + int retval;
85433 +
85434 + charge = 0;
85435 + if (mpnt->vm_flags & VM_ACCOUNT) {
85436 + unsigned long len = vma_pages(mpnt);
85437 +
85438 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85439 + goto fail_nomem;
85440 + charge = len;
85441 + }
85442 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85443 + if (!tmp)
85444 + goto fail_nomem;
85445 + *tmp = *mpnt;
85446 + tmp->vm_mm = mm;
85447 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
85448 + retval = vma_dup_policy(mpnt, tmp);
85449 + if (retval)
85450 + goto fail_nomem_policy;
85451 + if (anon_vma_fork(tmp, mpnt))
85452 + goto fail_nomem_anon_vma_fork;
85453 + tmp->vm_flags &= ~VM_LOCKED;
85454 + tmp->vm_next = tmp->vm_prev = NULL;
85455 + tmp->vm_mirror = NULL;
85456 + file = tmp->vm_file;
85457 + if (file) {
85458 + struct inode *inode = file_inode(file);
85459 + struct address_space *mapping = file->f_mapping;
85460 +
85461 + get_file(file);
85462 + if (tmp->vm_flags & VM_DENYWRITE)
85463 + atomic_dec(&inode->i_writecount);
85464 + mutex_lock(&mapping->i_mmap_mutex);
85465 + if (tmp->vm_flags & VM_SHARED)
85466 + mapping->i_mmap_writable++;
85467 + flush_dcache_mmap_lock(mapping);
85468 + /* insert tmp into the share list, just after mpnt */
85469 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85470 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
85471 + else
85472 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
85473 + flush_dcache_mmap_unlock(mapping);
85474 + mutex_unlock(&mapping->i_mmap_mutex);
85475 + }
85476 +
85477 + /*
85478 + * Clear hugetlb-related page reserves for children. This only
85479 + * affects MAP_PRIVATE mappings. Faults generated by the child
85480 + * are not guaranteed to succeed, even if read-only
85481 + */
85482 + if (is_vm_hugetlb_page(tmp))
85483 + reset_vma_resv_huge_pages(tmp);
85484 +
85485 + return tmp;
85486 +
85487 +fail_nomem_anon_vma_fork:
85488 + mpol_put(vma_policy(tmp));
85489 +fail_nomem_policy:
85490 + kmem_cache_free(vm_area_cachep, tmp);
85491 +fail_nomem:
85492 + vm_unacct_memory(charge);
85493 + return NULL;
85494 +}
85495 +
85496 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85497 {
85498 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
85499 struct rb_node **rb_link, *rb_parent;
85500 int retval;
85501 - unsigned long charge;
85502
85503 uprobe_start_dup_mmap();
85504 down_write(&oldmm->mmap_sem);
85505 @@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85506
85507 prev = NULL;
85508 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
85509 - struct file *file;
85510 -
85511 if (mpnt->vm_flags & VM_DONTCOPY) {
85512 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
85513 -vma_pages(mpnt));
85514 continue;
85515 }
85516 - charge = 0;
85517 - if (mpnt->vm_flags & VM_ACCOUNT) {
85518 - unsigned long len = vma_pages(mpnt);
85519 -
85520 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85521 - goto fail_nomem;
85522 - charge = len;
85523 - }
85524 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85525 - if (!tmp)
85526 - goto fail_nomem;
85527 - *tmp = *mpnt;
85528 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
85529 - retval = vma_dup_policy(mpnt, tmp);
85530 - if (retval)
85531 - goto fail_nomem_policy;
85532 - tmp->vm_mm = mm;
85533 - if (anon_vma_fork(tmp, mpnt))
85534 - goto fail_nomem_anon_vma_fork;
85535 - tmp->vm_flags &= ~VM_LOCKED;
85536 - tmp->vm_next = tmp->vm_prev = NULL;
85537 - file = tmp->vm_file;
85538 - if (file) {
85539 - struct inode *inode = file_inode(file);
85540 - struct address_space *mapping = file->f_mapping;
85541 -
85542 - get_file(file);
85543 - if (tmp->vm_flags & VM_DENYWRITE)
85544 - atomic_dec(&inode->i_writecount);
85545 - mutex_lock(&mapping->i_mmap_mutex);
85546 - if (tmp->vm_flags & VM_SHARED)
85547 - mapping->i_mmap_writable++;
85548 - flush_dcache_mmap_lock(mapping);
85549 - /* insert tmp into the share list, just after mpnt */
85550 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85551 - vma_nonlinear_insert(tmp,
85552 - &mapping->i_mmap_nonlinear);
85553 - else
85554 - vma_interval_tree_insert_after(tmp, mpnt,
85555 - &mapping->i_mmap);
85556 - flush_dcache_mmap_unlock(mapping);
85557 - mutex_unlock(&mapping->i_mmap_mutex);
85558 + tmp = dup_vma(mm, oldmm, mpnt);
85559 + if (!tmp) {
85560 + retval = -ENOMEM;
85561 + goto out;
85562 }
85563
85564 /*
85565 @@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85566 if (retval)
85567 goto out;
85568 }
85569 +
85570 +#ifdef CONFIG_PAX_SEGMEXEC
85571 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
85572 + struct vm_area_struct *mpnt_m;
85573 +
85574 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
85575 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
85576 +
85577 + if (!mpnt->vm_mirror)
85578 + continue;
85579 +
85580 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
85581 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
85582 + mpnt->vm_mirror = mpnt_m;
85583 + } else {
85584 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
85585 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
85586 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
85587 + mpnt->vm_mirror->vm_mirror = mpnt;
85588 + }
85589 + }
85590 + BUG_ON(mpnt_m);
85591 + }
85592 +#endif
85593 +
85594 /* a new mm has just been created */
85595 arch_dup_mmap(oldmm, mm);
85596 retval = 0;
85597 @@ -468,14 +521,6 @@ out:
85598 up_write(&oldmm->mmap_sem);
85599 uprobe_end_dup_mmap();
85600 return retval;
85601 -fail_nomem_anon_vma_fork:
85602 - mpol_put(vma_policy(tmp));
85603 -fail_nomem_policy:
85604 - kmem_cache_free(vm_area_cachep, tmp);
85605 -fail_nomem:
85606 - retval = -ENOMEM;
85607 - vm_unacct_memory(charge);
85608 - goto out;
85609 }
85610
85611 static inline int mm_alloc_pgd(struct mm_struct *mm)
85612 @@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
85613 return ERR_PTR(err);
85614
85615 mm = get_task_mm(task);
85616 - if (mm && mm != current->mm &&
85617 - !ptrace_may_access(task, mode)) {
85618 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
85619 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
85620 mmput(mm);
85621 mm = ERR_PTR(-EACCES);
85622 }
85623 @@ -906,13 +951,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
85624 spin_unlock(&fs->lock);
85625 return -EAGAIN;
85626 }
85627 - fs->users++;
85628 + atomic_inc(&fs->users);
85629 spin_unlock(&fs->lock);
85630 return 0;
85631 }
85632 tsk->fs = copy_fs_struct(fs);
85633 if (!tsk->fs)
85634 return -ENOMEM;
85635 + /* Carry through gr_chroot_dentry and is_chrooted instead
85636 + of recomputing it here. Already copied when the task struct
85637 + is duplicated. This allows pivot_root to not be treated as
85638 + a chroot
85639 + */
85640 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
85641 +
85642 return 0;
85643 }
85644
85645 @@ -1130,7 +1182,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
85646 * parts of the process environment (as per the clone
85647 * flags). The actual kick-off is left to the caller.
85648 */
85649 -static struct task_struct *copy_process(unsigned long clone_flags,
85650 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
85651 unsigned long stack_start,
85652 unsigned long stack_size,
85653 int __user *child_tidptr,
85654 @@ -1202,6 +1254,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85655 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
85656 #endif
85657 retval = -EAGAIN;
85658 +
85659 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
85660 +
85661 if (atomic_read(&p->real_cred->user->processes) >=
85662 task_rlimit(p, RLIMIT_NPROC)) {
85663 if (p->real_cred->user != INIT_USER &&
85664 @@ -1449,6 +1504,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85665 goto bad_fork_free_pid;
85666 }
85667
85668 + /* synchronizes with gr_set_acls()
85669 + we need to call this past the point of no return for fork()
85670 + */
85671 + gr_copy_label(p);
85672 +
85673 if (likely(p->pid)) {
85674 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
85675
85676 @@ -1537,6 +1597,8 @@ bad_fork_cleanup_count:
85677 bad_fork_free:
85678 free_task(p);
85679 fork_out:
85680 + gr_log_forkfail(retval);
85681 +
85682 return ERR_PTR(retval);
85683 }
85684
85685 @@ -1598,6 +1660,7 @@ long do_fork(unsigned long clone_flags,
85686
85687 p = copy_process(clone_flags, stack_start, stack_size,
85688 child_tidptr, NULL, trace);
85689 + add_latent_entropy();
85690 /*
85691 * Do this prior waking up the new thread - the thread pointer
85692 * might get invalid after that point, if the thread exits quickly.
85693 @@ -1612,6 +1675,8 @@ long do_fork(unsigned long clone_flags,
85694 if (clone_flags & CLONE_PARENT_SETTID)
85695 put_user(nr, parent_tidptr);
85696
85697 + gr_handle_brute_check();
85698 +
85699 if (clone_flags & CLONE_VFORK) {
85700 p->vfork_done = &vfork;
85701 init_completion(&vfork);
85702 @@ -1728,7 +1793,7 @@ void __init proc_caches_init(void)
85703 mm_cachep = kmem_cache_create("mm_struct",
85704 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
85705 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
85706 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
85707 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
85708 mmap_init();
85709 nsproxy_cache_init();
85710 }
85711 @@ -1768,7 +1833,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
85712 return 0;
85713
85714 /* don't need lock here; in the worst case we'll do useless copy */
85715 - if (fs->users == 1)
85716 + if (atomic_read(&fs->users) == 1)
85717 return 0;
85718
85719 *new_fsp = copy_fs_struct(fs);
85720 @@ -1875,7 +1940,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
85721 fs = current->fs;
85722 spin_lock(&fs->lock);
85723 current->fs = new_fs;
85724 - if (--fs->users)
85725 + gr_set_chroot_entries(current, &current->fs->root);
85726 + if (atomic_dec_return(&fs->users))
85727 new_fs = NULL;
85728 else
85729 new_fs = fs;
85730 diff --git a/kernel/futex.c b/kernel/futex.c
85731 index 6801b37..bb6becca 100644
85732 --- a/kernel/futex.c
85733 +++ b/kernel/futex.c
85734 @@ -54,6 +54,7 @@
85735 #include <linux/mount.h>
85736 #include <linux/pagemap.h>
85737 #include <linux/syscalls.h>
85738 +#include <linux/ptrace.h>
85739 #include <linux/signal.h>
85740 #include <linux/export.h>
85741 #include <linux/magic.h>
85742 @@ -380,6 +381,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
85743 struct page *page, *page_head;
85744 int err, ro = 0;
85745
85746 +#ifdef CONFIG_PAX_SEGMEXEC
85747 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
85748 + return -EFAULT;
85749 +#endif
85750 +
85751 /*
85752 * The futex address must be "naturally" aligned.
85753 */
85754 @@ -579,7 +585,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
85755
85756 static int get_futex_value_locked(u32 *dest, u32 __user *from)
85757 {
85758 - int ret;
85759 + unsigned long ret;
85760
85761 pagefault_disable();
85762 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
85763 @@ -2886,6 +2892,7 @@ static void __init futex_detect_cmpxchg(void)
85764 {
85765 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
85766 u32 curval;
85767 + mm_segment_t oldfs;
85768
85769 /*
85770 * This will fail and we want it. Some arch implementations do
85771 @@ -2897,8 +2904,11 @@ static void __init futex_detect_cmpxchg(void)
85772 * implementation, the non-functional ones will return
85773 * -ENOSYS.
85774 */
85775 + oldfs = get_fs();
85776 + set_fs(USER_DS);
85777 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
85778 futex_cmpxchg_enabled = 1;
85779 + set_fs(oldfs);
85780 #endif
85781 }
85782
85783 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
85784 index f9f44fd..29885e4 100644
85785 --- a/kernel/futex_compat.c
85786 +++ b/kernel/futex_compat.c
85787 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
85788 return 0;
85789 }
85790
85791 -static void __user *futex_uaddr(struct robust_list __user *entry,
85792 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
85793 compat_long_t futex_offset)
85794 {
85795 compat_uptr_t base = ptr_to_compat(entry);
85796 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
85797 index f45b75b..bfac6d5 100644
85798 --- a/kernel/gcov/base.c
85799 +++ b/kernel/gcov/base.c
85800 @@ -108,11 +108,6 @@ void gcov_enable_events(void)
85801 }
85802
85803 #ifdef CONFIG_MODULES
85804 -static inline int within(void *addr, void *start, unsigned long size)
85805 -{
85806 - return ((addr >= start) && (addr < start + size));
85807 -}
85808 -
85809 /* Update list and generate events when modules are unloaded. */
85810 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
85811 void *data)
85812 @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
85813
85814 /* Remove entries located in module from linked list. */
85815 while ((info = gcov_info_next(info))) {
85816 - if (within(info, mod->module_core, mod->core_size)) {
85817 + if (within_module_core_rw((unsigned long)info, mod)) {
85818 gcov_info_unlink(prev, info);
85819 if (gcov_events_enabled)
85820 gcov_event(GCOV_REMOVE, info);
85821 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
85822 index 0909436..6037d22 100644
85823 --- a/kernel/hrtimer.c
85824 +++ b/kernel/hrtimer.c
85825 @@ -1439,7 +1439,7 @@ void hrtimer_peek_ahead_timers(void)
85826 local_irq_restore(flags);
85827 }
85828
85829 -static void run_hrtimer_softirq(struct softirq_action *h)
85830 +static __latent_entropy void run_hrtimer_softirq(void)
85831 {
85832 hrtimer_peek_ahead_timers();
85833 }
85834 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
85835 index 55fcce6..0e4cf34 100644
85836 --- a/kernel/irq_work.c
85837 +++ b/kernel/irq_work.c
85838 @@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
85839 return NOTIFY_OK;
85840 }
85841
85842 -static struct notifier_block cpu_notify;
85843 +static struct notifier_block cpu_notify = {
85844 + .notifier_call = irq_work_cpu_notify,
85845 + .priority = 0,
85846 +};
85847
85848 static __init int irq_work_init_cpu_notifier(void)
85849 {
85850 - cpu_notify.notifier_call = irq_work_cpu_notify;
85851 - cpu_notify.priority = 0;
85852 register_cpu_notifier(&cpu_notify);
85853 return 0;
85854 }
85855 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
85856 index 9019f15..9a3c42e 100644
85857 --- a/kernel/jump_label.c
85858 +++ b/kernel/jump_label.c
85859 @@ -14,6 +14,7 @@
85860 #include <linux/err.h>
85861 #include <linux/static_key.h>
85862 #include <linux/jump_label_ratelimit.h>
85863 +#include <linux/mm.h>
85864
85865 #ifdef HAVE_JUMP_LABEL
85866
85867 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
85868
85869 size = (((unsigned long)stop - (unsigned long)start)
85870 / sizeof(struct jump_entry));
85871 + pax_open_kernel();
85872 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
85873 + pax_close_kernel();
85874 }
85875
85876 static void jump_label_update(struct static_key *key, int enable);
85877 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
85878 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
85879 struct jump_entry *iter;
85880
85881 + pax_open_kernel();
85882 for (iter = iter_start; iter < iter_stop; iter++) {
85883 if (within_module_init(iter->code, mod))
85884 iter->code = 0;
85885 }
85886 + pax_close_kernel();
85887 }
85888
85889 static int
85890 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
85891 index 3127ad5..159d880 100644
85892 --- a/kernel/kallsyms.c
85893 +++ b/kernel/kallsyms.c
85894 @@ -11,6 +11,9 @@
85895 * Changed the compression method from stem compression to "table lookup"
85896 * compression (see scripts/kallsyms.c for a more complete description)
85897 */
85898 +#ifdef CONFIG_GRKERNSEC_HIDESYM
85899 +#define __INCLUDED_BY_HIDESYM 1
85900 +#endif
85901 #include <linux/kallsyms.h>
85902 #include <linux/module.h>
85903 #include <linux/init.h>
85904 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
85905
85906 static inline int is_kernel_inittext(unsigned long addr)
85907 {
85908 + if (system_state != SYSTEM_BOOTING)
85909 + return 0;
85910 +
85911 if (addr >= (unsigned long)_sinittext
85912 && addr <= (unsigned long)_einittext)
85913 return 1;
85914 return 0;
85915 }
85916
85917 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85918 +#ifdef CONFIG_MODULES
85919 +static inline int is_module_text(unsigned long addr)
85920 +{
85921 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
85922 + return 1;
85923 +
85924 + addr = ktla_ktva(addr);
85925 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
85926 +}
85927 +#else
85928 +static inline int is_module_text(unsigned long addr)
85929 +{
85930 + return 0;
85931 +}
85932 +#endif
85933 +#endif
85934 +
85935 static inline int is_kernel_text(unsigned long addr)
85936 {
85937 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
85938 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
85939
85940 static inline int is_kernel(unsigned long addr)
85941 {
85942 +
85943 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85944 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
85945 + return 1;
85946 +
85947 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
85948 +#else
85949 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
85950 +#endif
85951 +
85952 return 1;
85953 return in_gate_area_no_mm(addr);
85954 }
85955
85956 static int is_ksym_addr(unsigned long addr)
85957 {
85958 +
85959 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85960 + if (is_module_text(addr))
85961 + return 0;
85962 +#endif
85963 +
85964 if (all_var)
85965 return is_kernel(addr);
85966
85967 @@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
85968
85969 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
85970 {
85971 - iter->name[0] = '\0';
85972 iter->nameoff = get_symbol_offset(new_pos);
85973 iter->pos = new_pos;
85974 }
85975 @@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
85976 {
85977 struct kallsym_iter *iter = m->private;
85978
85979 +#ifdef CONFIG_GRKERNSEC_HIDESYM
85980 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
85981 + return 0;
85982 +#endif
85983 +
85984 /* Some debugging symbols have no name. Ignore them. */
85985 if (!iter->name[0])
85986 return 0;
85987 @@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
85988 */
85989 type = iter->exported ? toupper(iter->type) :
85990 tolower(iter->type);
85991 +
85992 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
85993 type, iter->name, iter->module_name);
85994 } else
85995 @@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
85996 struct kallsym_iter *iter;
85997 int ret;
85998
85999 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
86000 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
86001 if (!iter)
86002 return -ENOMEM;
86003 reset_iter(iter, 0);
86004 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
86005 index e30ac0f..3528cac 100644
86006 --- a/kernel/kcmp.c
86007 +++ b/kernel/kcmp.c
86008 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
86009 struct task_struct *task1, *task2;
86010 int ret;
86011
86012 +#ifdef CONFIG_GRKERNSEC
86013 + return -ENOSYS;
86014 +#endif
86015 +
86016 rcu_read_lock();
86017
86018 /*
86019 diff --git a/kernel/kexec.c b/kernel/kexec.c
86020 index 60bafbe..a120f4f 100644
86021 --- a/kernel/kexec.c
86022 +++ b/kernel/kexec.c
86023 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
86024 unsigned long flags)
86025 {
86026 struct compat_kexec_segment in;
86027 - struct kexec_segment out, __user *ksegments;
86028 + struct kexec_segment out;
86029 + struct kexec_segment __user *ksegments;
86030 unsigned long i, result;
86031
86032 /* Don't allow clients that don't understand the native
86033 diff --git a/kernel/kmod.c b/kernel/kmod.c
86034 index 6b375af..eaff670 100644
86035 --- a/kernel/kmod.c
86036 +++ b/kernel/kmod.c
86037 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
86038 kfree(info->argv);
86039 }
86040
86041 -static int call_modprobe(char *module_name, int wait)
86042 +static int call_modprobe(char *module_name, char *module_param, int wait)
86043 {
86044 struct subprocess_info *info;
86045 static char *envp[] = {
86046 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86047 NULL
86048 };
86049
86050 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86051 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86052 if (!argv)
86053 goto out;
86054
86055 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
86056 argv[1] = "-q";
86057 argv[2] = "--";
86058 argv[3] = module_name; /* check free_modprobe_argv() */
86059 - argv[4] = NULL;
86060 + argv[4] = module_param;
86061 + argv[5] = NULL;
86062
86063 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
86064 NULL, free_modprobe_argv, NULL);
86065 @@ -129,9 +130,8 @@ out:
86066 * If module auto-loading support is disabled then this function
86067 * becomes a no-operation.
86068 */
86069 -int __request_module(bool wait, const char *fmt, ...)
86070 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
86071 {
86072 - va_list args;
86073 char module_name[MODULE_NAME_LEN];
86074 unsigned int max_modprobes;
86075 int ret;
86076 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
86077 if (!modprobe_path[0])
86078 return 0;
86079
86080 - va_start(args, fmt);
86081 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
86082 - va_end(args);
86083 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
86084 if (ret >= MODULE_NAME_LEN)
86085 return -ENAMETOOLONG;
86086
86087 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
86088 if (ret)
86089 return ret;
86090
86091 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86092 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86093 + /* hack to workaround consolekit/udisks stupidity */
86094 + read_lock(&tasklist_lock);
86095 + if (!strcmp(current->comm, "mount") &&
86096 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
86097 + read_unlock(&tasklist_lock);
86098 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
86099 + return -EPERM;
86100 + }
86101 + read_unlock(&tasklist_lock);
86102 + }
86103 +#endif
86104 +
86105 /* If modprobe needs a service that is in a module, we get a recursive
86106 * loop. Limit the number of running kmod threads to max_threads/2 or
86107 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
86108 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
86109
86110 trace_module_request(module_name, wait, _RET_IP_);
86111
86112 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86113 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86114
86115 atomic_dec(&kmod_concurrent);
86116 return ret;
86117 }
86118 +
86119 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
86120 +{
86121 + va_list args;
86122 + int ret;
86123 +
86124 + va_start(args, fmt);
86125 + ret = ____request_module(wait, module_param, fmt, args);
86126 + va_end(args);
86127 +
86128 + return ret;
86129 +}
86130 +
86131 +int __request_module(bool wait, const char *fmt, ...)
86132 +{
86133 + va_list args;
86134 + int ret;
86135 +
86136 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86137 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86138 + char module_param[MODULE_NAME_LEN];
86139 +
86140 + memset(module_param, 0, sizeof(module_param));
86141 +
86142 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
86143 +
86144 + va_start(args, fmt);
86145 + ret = ____request_module(wait, module_param, fmt, args);
86146 + va_end(args);
86147 +
86148 + return ret;
86149 + }
86150 +#endif
86151 +
86152 + va_start(args, fmt);
86153 + ret = ____request_module(wait, NULL, fmt, args);
86154 + va_end(args);
86155 +
86156 + return ret;
86157 +}
86158 +
86159 EXPORT_SYMBOL(__request_module);
86160 #endif /* CONFIG_MODULES */
86161
86162 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
86163 */
86164 set_user_nice(current, 0);
86165
86166 +#ifdef CONFIG_GRKERNSEC
86167 + /* this is race-free as far as userland is concerned as we copied
86168 + out the path to be used prior to this point and are now operating
86169 + on that copy
86170 + */
86171 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
86172 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
86173 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
86174 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
86175 + retval = -EPERM;
86176 + goto fail;
86177 + }
86178 +#endif
86179 +
86180 retval = -ENOMEM;
86181 new = prepare_kernel_cred(current);
86182 if (!new)
86183 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
86184 commit_creds(new);
86185
86186 retval = do_execve(getname_kernel(sub_info->path),
86187 - (const char __user *const __user *)sub_info->argv,
86188 - (const char __user *const __user *)sub_info->envp);
86189 + (const char __user *const __force_user *)sub_info->argv,
86190 + (const char __user *const __force_user *)sub_info->envp);
86191 if (!retval)
86192 return 0;
86193
86194 @@ -260,6 +327,10 @@ static int call_helper(void *data)
86195
86196 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
86197 {
86198 +#ifdef CONFIG_GRKERNSEC
86199 + kfree(info->path);
86200 + info->path = info->origpath;
86201 +#endif
86202 if (info->cleanup)
86203 (*info->cleanup)(info);
86204 kfree(info);
86205 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
86206 *
86207 * Thus the __user pointer cast is valid here.
86208 */
86209 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
86210 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
86211
86212 /*
86213 * If ret is 0, either ____call_usermodehelper failed and the
86214 @@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
86215 goto out;
86216
86217 INIT_WORK(&sub_info->work, __call_usermodehelper);
86218 +#ifdef CONFIG_GRKERNSEC
86219 + sub_info->origpath = path;
86220 + sub_info->path = kstrdup(path, gfp_mask);
86221 +#else
86222 sub_info->path = path;
86223 +#endif
86224 sub_info->argv = argv;
86225 sub_info->envp = envp;
86226
86227 @@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
86228 static int proc_cap_handler(struct ctl_table *table, int write,
86229 void __user *buffer, size_t *lenp, loff_t *ppos)
86230 {
86231 - struct ctl_table t;
86232 + ctl_table_no_const t;
86233 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
86234 kernel_cap_t new_cap;
86235 int err, i;
86236 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
86237 index ceeadfc..11c18b6 100644
86238 --- a/kernel/kprobes.c
86239 +++ b/kernel/kprobes.c
86240 @@ -31,6 +31,9 @@
86241 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
86242 * <prasanna@in.ibm.com> added function-return probes.
86243 */
86244 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86245 +#define __INCLUDED_BY_HIDESYM 1
86246 +#endif
86247 #include <linux/kprobes.h>
86248 #include <linux/hash.h>
86249 #include <linux/init.h>
86250 @@ -135,12 +138,12 @@ enum kprobe_slot_state {
86251
86252 static void *alloc_insn_page(void)
86253 {
86254 - return module_alloc(PAGE_SIZE);
86255 + return module_alloc_exec(PAGE_SIZE);
86256 }
86257
86258 static void free_insn_page(void *page)
86259 {
86260 - module_free(NULL, page);
86261 + module_free_exec(NULL, page);
86262 }
86263
86264 struct kprobe_insn_cache kprobe_insn_slots = {
86265 @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
86266 kprobe_type = "k";
86267
86268 if (sym)
86269 - seq_printf(pi, "%p %s %s+0x%x %s ",
86270 + seq_printf(pi, "%pK %s %s+0x%x %s ",
86271 p->addr, kprobe_type, sym, offset,
86272 (modname ? modname : " "));
86273 else
86274 - seq_printf(pi, "%p %s %p ",
86275 + seq_printf(pi, "%pK %s %pK ",
86276 p->addr, kprobe_type, p->addr);
86277
86278 if (!pp)
86279 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
86280 index d945a94..0b7f45f 100644
86281 --- a/kernel/ksysfs.c
86282 +++ b/kernel/ksysfs.c
86283 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
86284 {
86285 if (count+1 > UEVENT_HELPER_PATH_LEN)
86286 return -ENOENT;
86287 + if (!capable(CAP_SYS_ADMIN))
86288 + return -EPERM;
86289 memcpy(uevent_helper, buf, count);
86290 uevent_helper[count] = '\0';
86291 if (count && uevent_helper[count-1] == '\n')
86292 @@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
86293 return count;
86294 }
86295
86296 -static struct bin_attribute notes_attr = {
86297 +static bin_attribute_no_const notes_attr __read_only = {
86298 .attr = {
86299 .name = "notes",
86300 .mode = S_IRUGO,
86301 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
86302 index eb8a547..321d8e1 100644
86303 --- a/kernel/locking/lockdep.c
86304 +++ b/kernel/locking/lockdep.c
86305 @@ -597,6 +597,10 @@ static int static_obj(void *obj)
86306 end = (unsigned long) &_end,
86307 addr = (unsigned long) obj;
86308
86309 +#ifdef CONFIG_PAX_KERNEXEC
86310 + start = ktla_ktva(start);
86311 +#endif
86312 +
86313 /*
86314 * static variable?
86315 */
86316 @@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
86317 if (!static_obj(lock->key)) {
86318 debug_locks_off();
86319 printk("INFO: trying to register non-static key.\n");
86320 + printk("lock:%pS key:%pS.\n", lock, lock->key);
86321 printk("the code is fine but needs lockdep annotation.\n");
86322 printk("turning off the locking correctness validator.\n");
86323 dump_stack();
86324 @@ -3082,7 +3087,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
86325 if (!class)
86326 return 0;
86327 }
86328 - atomic_inc((atomic_t *)&class->ops);
86329 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
86330 if (very_verbose(class)) {
86331 printk("\nacquire class [%p] %s", class->key, class->name);
86332 if (class->name_version > 1)
86333 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
86334 index ef43ac4..2720dfa 100644
86335 --- a/kernel/locking/lockdep_proc.c
86336 +++ b/kernel/locking/lockdep_proc.c
86337 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
86338 return 0;
86339 }
86340
86341 - seq_printf(m, "%p", class->key);
86342 + seq_printf(m, "%pK", class->key);
86343 #ifdef CONFIG_DEBUG_LOCKDEP
86344 seq_printf(m, " OPS:%8ld", class->ops);
86345 #endif
86346 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
86347
86348 list_for_each_entry(entry, &class->locks_after, entry) {
86349 if (entry->distance == 1) {
86350 - seq_printf(m, " -> [%p] ", entry->class->key);
86351 + seq_printf(m, " -> [%pK] ", entry->class->key);
86352 print_name(m, entry->class);
86353 seq_puts(m, "\n");
86354 }
86355 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
86356 if (!class->key)
86357 continue;
86358
86359 - seq_printf(m, "[%p] ", class->key);
86360 + seq_printf(m, "[%pK] ", class->key);
86361 print_name(m, class);
86362 seq_puts(m, "\n");
86363 }
86364 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86365 if (!i)
86366 seq_line(m, '-', 40-namelen, namelen);
86367
86368 - snprintf(ip, sizeof(ip), "[<%p>]",
86369 + snprintf(ip, sizeof(ip), "[<%pK>]",
86370 (void *)class->contention_point[i]);
86371 seq_printf(m, "%40s %14lu %29s %pS\n",
86372 name, stats->contention_point[i],
86373 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86374 if (!i)
86375 seq_line(m, '-', 40-namelen, namelen);
86376
86377 - snprintf(ip, sizeof(ip), "[<%p>]",
86378 + snprintf(ip, sizeof(ip), "[<%pK>]",
86379 (void *)class->contending_point[i]);
86380 seq_printf(m, "%40s %14lu %29s %pS\n",
86381 name, stats->contending_point[i],
86382 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
86383 index faf6f5b..dc9070a 100644
86384 --- a/kernel/locking/mutex-debug.c
86385 +++ b/kernel/locking/mutex-debug.c
86386 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
86387 }
86388
86389 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86390 - struct thread_info *ti)
86391 + struct task_struct *task)
86392 {
86393 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
86394
86395 /* Mark the current thread as blocked on the lock: */
86396 - ti->task->blocked_on = waiter;
86397 + task->blocked_on = waiter;
86398 }
86399
86400 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86401 - struct thread_info *ti)
86402 + struct task_struct *task)
86403 {
86404 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
86405 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
86406 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
86407 - ti->task->blocked_on = NULL;
86408 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
86409 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
86410 + task->blocked_on = NULL;
86411
86412 list_del_init(&waiter->list);
86413 waiter->task = NULL;
86414 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
86415 index 0799fd3..d06ae3b 100644
86416 --- a/kernel/locking/mutex-debug.h
86417 +++ b/kernel/locking/mutex-debug.h
86418 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
86419 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
86420 extern void debug_mutex_add_waiter(struct mutex *lock,
86421 struct mutex_waiter *waiter,
86422 - struct thread_info *ti);
86423 + struct task_struct *task);
86424 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86425 - struct thread_info *ti);
86426 + struct task_struct *task);
86427 extern void debug_mutex_unlock(struct mutex *lock);
86428 extern void debug_mutex_init(struct mutex *lock, const char *name,
86429 struct lock_class_key *key);
86430 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
86431 index 4dd6e4c..df52693 100644
86432 --- a/kernel/locking/mutex.c
86433 +++ b/kernel/locking/mutex.c
86434 @@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
86435 node->locked = 1;
86436 return;
86437 }
86438 - ACCESS_ONCE(prev->next) = node;
86439 + ACCESS_ONCE_RW(prev->next) = node;
86440 smp_wmb();
86441 /* Wait until the lock holder passes the lock down */
86442 while (!ACCESS_ONCE(node->locked))
86443 @@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
86444 while (!(next = ACCESS_ONCE(node->next)))
86445 arch_mutex_cpu_relax();
86446 }
86447 - ACCESS_ONCE(next->locked) = 1;
86448 + ACCESS_ONCE_RW(next->locked) = 1;
86449 smp_wmb();
86450 }
86451
86452 @@ -520,7 +520,7 @@ slowpath:
86453 goto skip_wait;
86454
86455 debug_mutex_lock_common(lock, &waiter);
86456 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
86457 + debug_mutex_add_waiter(lock, &waiter, task);
86458
86459 /* add waiting tasks to the end of the waitqueue (FIFO): */
86460 list_add_tail(&waiter.list, &lock->wait_list);
86461 @@ -564,7 +564,7 @@ slowpath:
86462 schedule_preempt_disabled();
86463 spin_lock_mutex(&lock->wait_lock, flags);
86464 }
86465 - mutex_remove_waiter(lock, &waiter, current_thread_info());
86466 + mutex_remove_waiter(lock, &waiter, task);
86467 /* set it to 0 if there are no waiters left: */
86468 if (likely(list_empty(&lock->wait_list)))
86469 atomic_set(&lock->count, 0);
86470 @@ -601,7 +601,7 @@ skip_wait:
86471 return 0;
86472
86473 err:
86474 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
86475 + mutex_remove_waiter(lock, &waiter, task);
86476 spin_unlock_mutex(&lock->wait_lock, flags);
86477 debug_mutex_free_waiter(&waiter);
86478 mutex_release(&lock->dep_map, 1, ip);
86479 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
86480 index 1d96dd0..994ff19 100644
86481 --- a/kernel/locking/rtmutex-tester.c
86482 +++ b/kernel/locking/rtmutex-tester.c
86483 @@ -22,7 +22,7 @@
86484 #define MAX_RT_TEST_MUTEXES 8
86485
86486 static spinlock_t rttest_lock;
86487 -static atomic_t rttest_event;
86488 +static atomic_unchecked_t rttest_event;
86489
86490 struct test_thread_data {
86491 int opcode;
86492 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86493
86494 case RTTEST_LOCKCONT:
86495 td->mutexes[td->opdata] = 1;
86496 - td->event = atomic_add_return(1, &rttest_event);
86497 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86498 return 0;
86499
86500 case RTTEST_RESET:
86501 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86502 return 0;
86503
86504 case RTTEST_RESETEVENT:
86505 - atomic_set(&rttest_event, 0);
86506 + atomic_set_unchecked(&rttest_event, 0);
86507 return 0;
86508
86509 default:
86510 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86511 return ret;
86512
86513 td->mutexes[id] = 1;
86514 - td->event = atomic_add_return(1, &rttest_event);
86515 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86516 rt_mutex_lock(&mutexes[id]);
86517 - td->event = atomic_add_return(1, &rttest_event);
86518 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86519 td->mutexes[id] = 4;
86520 return 0;
86521
86522 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86523 return ret;
86524
86525 td->mutexes[id] = 1;
86526 - td->event = atomic_add_return(1, &rttest_event);
86527 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86528 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
86529 - td->event = atomic_add_return(1, &rttest_event);
86530 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86531 td->mutexes[id] = ret ? 0 : 4;
86532 return ret ? -EINTR : 0;
86533
86534 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86535 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
86536 return ret;
86537
86538 - td->event = atomic_add_return(1, &rttest_event);
86539 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86540 rt_mutex_unlock(&mutexes[id]);
86541 - td->event = atomic_add_return(1, &rttest_event);
86542 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86543 td->mutexes[id] = 0;
86544 return 0;
86545
86546 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86547 break;
86548
86549 td->mutexes[dat] = 2;
86550 - td->event = atomic_add_return(1, &rttest_event);
86551 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86552 break;
86553
86554 default:
86555 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86556 return;
86557
86558 td->mutexes[dat] = 3;
86559 - td->event = atomic_add_return(1, &rttest_event);
86560 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86561 break;
86562
86563 case RTTEST_LOCKNOWAIT:
86564 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86565 return;
86566
86567 td->mutexes[dat] = 1;
86568 - td->event = atomic_add_return(1, &rttest_event);
86569 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86570 return;
86571
86572 default:
86573 diff --git a/kernel/module.c b/kernel/module.c
86574 index d24fcf2..2af3fd9 100644
86575 --- a/kernel/module.c
86576 +++ b/kernel/module.c
86577 @@ -61,6 +61,7 @@
86578 #include <linux/pfn.h>
86579 #include <linux/bsearch.h>
86580 #include <linux/fips.h>
86581 +#include <linux/grsecurity.h>
86582 #include <uapi/linux/module.h>
86583 #include "module-internal.h"
86584
86585 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
86586
86587 /* Bounds of module allocation, for speeding __module_address.
86588 * Protected by module_mutex. */
86589 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
86590 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
86591 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
86592
86593 int register_module_notifier(struct notifier_block * nb)
86594 {
86595 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86596 return true;
86597
86598 list_for_each_entry_rcu(mod, &modules, list) {
86599 - struct symsearch arr[] = {
86600 + struct symsearch modarr[] = {
86601 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
86602 NOT_GPL_ONLY, false },
86603 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
86604 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86605 if (mod->state == MODULE_STATE_UNFORMED)
86606 continue;
86607
86608 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
86609 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
86610 return true;
86611 }
86612 return false;
86613 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
86614 if (!pcpusec->sh_size)
86615 return 0;
86616
86617 - if (align > PAGE_SIZE) {
86618 + if (align-1 >= PAGE_SIZE) {
86619 pr_warn("%s: per-cpu alignment %li > %li\n",
86620 mod->name, align, PAGE_SIZE);
86621 align = PAGE_SIZE;
86622 @@ -1062,7 +1064,7 @@ struct module_attribute module_uevent =
86623 static ssize_t show_coresize(struct module_attribute *mattr,
86624 struct module_kobject *mk, char *buffer)
86625 {
86626 - return sprintf(buffer, "%u\n", mk->mod->core_size);
86627 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
86628 }
86629
86630 static struct module_attribute modinfo_coresize =
86631 @@ -1071,7 +1073,7 @@ static struct module_attribute modinfo_coresize =
86632 static ssize_t show_initsize(struct module_attribute *mattr,
86633 struct module_kobject *mk, char *buffer)
86634 {
86635 - return sprintf(buffer, "%u\n", mk->mod->init_size);
86636 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
86637 }
86638
86639 static struct module_attribute modinfo_initsize =
86640 @@ -1163,12 +1165,29 @@ static int check_version(Elf_Shdr *sechdrs,
86641 goto bad_version;
86642 }
86643
86644 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86645 + /*
86646 + * avoid potentially printing jibberish on attempted load
86647 + * of a module randomized with a different seed
86648 + */
86649 + pr_warn("no symbol version for %s\n", symname);
86650 +#else
86651 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
86652 +#endif
86653 return 0;
86654
86655 bad_version:
86656 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86657 + /*
86658 + * avoid potentially printing jibberish on attempted load
86659 + * of a module randomized with a different seed
86660 + */
86661 + printk("attempted module disagrees about version of symbol %s\n",
86662 + symname);
86663 +#else
86664 printk("%s: disagrees about version of symbol %s\n",
86665 mod->name, symname);
86666 +#endif
86667 return 0;
86668 }
86669
86670 @@ -1284,7 +1303,7 @@ resolve_symbol_wait(struct module *mod,
86671 */
86672 #ifdef CONFIG_SYSFS
86673
86674 -#ifdef CONFIG_KALLSYMS
86675 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
86676 static inline bool sect_empty(const Elf_Shdr *sect)
86677 {
86678 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
86679 @@ -1424,7 +1443,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
86680 {
86681 unsigned int notes, loaded, i;
86682 struct module_notes_attrs *notes_attrs;
86683 - struct bin_attribute *nattr;
86684 + bin_attribute_no_const *nattr;
86685
86686 /* failed to create section attributes, so can't create notes */
86687 if (!mod->sect_attrs)
86688 @@ -1536,7 +1555,7 @@ static void del_usage_links(struct module *mod)
86689 static int module_add_modinfo_attrs(struct module *mod)
86690 {
86691 struct module_attribute *attr;
86692 - struct module_attribute *temp_attr;
86693 + module_attribute_no_const *temp_attr;
86694 int error = 0;
86695 int i;
86696
86697 @@ -1757,21 +1776,21 @@ static void set_section_ro_nx(void *base,
86698
86699 static void unset_module_core_ro_nx(struct module *mod)
86700 {
86701 - set_page_attributes(mod->module_core + mod->core_text_size,
86702 - mod->module_core + mod->core_size,
86703 + set_page_attributes(mod->module_core_rw,
86704 + mod->module_core_rw + mod->core_size_rw,
86705 set_memory_x);
86706 - set_page_attributes(mod->module_core,
86707 - mod->module_core + mod->core_ro_size,
86708 + set_page_attributes(mod->module_core_rx,
86709 + mod->module_core_rx + mod->core_size_rx,
86710 set_memory_rw);
86711 }
86712
86713 static void unset_module_init_ro_nx(struct module *mod)
86714 {
86715 - set_page_attributes(mod->module_init + mod->init_text_size,
86716 - mod->module_init + mod->init_size,
86717 + set_page_attributes(mod->module_init_rw,
86718 + mod->module_init_rw + mod->init_size_rw,
86719 set_memory_x);
86720 - set_page_attributes(mod->module_init,
86721 - mod->module_init + mod->init_ro_size,
86722 + set_page_attributes(mod->module_init_rx,
86723 + mod->module_init_rx + mod->init_size_rx,
86724 set_memory_rw);
86725 }
86726
86727 @@ -1784,14 +1803,14 @@ void set_all_modules_text_rw(void)
86728 list_for_each_entry_rcu(mod, &modules, list) {
86729 if (mod->state == MODULE_STATE_UNFORMED)
86730 continue;
86731 - if ((mod->module_core) && (mod->core_text_size)) {
86732 - set_page_attributes(mod->module_core,
86733 - mod->module_core + mod->core_text_size,
86734 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
86735 + set_page_attributes(mod->module_core_rx,
86736 + mod->module_core_rx + mod->core_size_rx,
86737 set_memory_rw);
86738 }
86739 - if ((mod->module_init) && (mod->init_text_size)) {
86740 - set_page_attributes(mod->module_init,
86741 - mod->module_init + mod->init_text_size,
86742 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
86743 + set_page_attributes(mod->module_init_rx,
86744 + mod->module_init_rx + mod->init_size_rx,
86745 set_memory_rw);
86746 }
86747 }
86748 @@ -1807,14 +1826,14 @@ void set_all_modules_text_ro(void)
86749 list_for_each_entry_rcu(mod, &modules, list) {
86750 if (mod->state == MODULE_STATE_UNFORMED)
86751 continue;
86752 - if ((mod->module_core) && (mod->core_text_size)) {
86753 - set_page_attributes(mod->module_core,
86754 - mod->module_core + mod->core_text_size,
86755 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
86756 + set_page_attributes(mod->module_core_rx,
86757 + mod->module_core_rx + mod->core_size_rx,
86758 set_memory_ro);
86759 }
86760 - if ((mod->module_init) && (mod->init_text_size)) {
86761 - set_page_attributes(mod->module_init,
86762 - mod->module_init + mod->init_text_size,
86763 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
86764 + set_page_attributes(mod->module_init_rx,
86765 + mod->module_init_rx + mod->init_size_rx,
86766 set_memory_ro);
86767 }
86768 }
86769 @@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
86770
86771 /* This may be NULL, but that's OK */
86772 unset_module_init_ro_nx(mod);
86773 - module_free(mod, mod->module_init);
86774 + module_free(mod, mod->module_init_rw);
86775 + module_free_exec(mod, mod->module_init_rx);
86776 kfree(mod->args);
86777 percpu_modfree(mod);
86778
86779 /* Free lock-classes: */
86780 - lockdep_free_key_range(mod->module_core, mod->core_size);
86781 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
86782 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
86783
86784 /* Finally, free the core (containing the module structure) */
86785 unset_module_core_ro_nx(mod);
86786 - module_free(mod, mod->module_core);
86787 + module_free_exec(mod, mod->module_core_rx);
86788 + module_free(mod, mod->module_core_rw);
86789
86790 #ifdef CONFIG_MPU
86791 update_protections(current->mm);
86792 @@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86793 int ret = 0;
86794 const struct kernel_symbol *ksym;
86795
86796 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86797 + int is_fs_load = 0;
86798 + int register_filesystem_found = 0;
86799 + char *p;
86800 +
86801 + p = strstr(mod->args, "grsec_modharden_fs");
86802 + if (p) {
86803 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
86804 + /* copy \0 as well */
86805 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
86806 + is_fs_load = 1;
86807 + }
86808 +#endif
86809 +
86810 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
86811 const char *name = info->strtab + sym[i].st_name;
86812
86813 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86814 + /* it's a real shame this will never get ripped and copied
86815 + upstream! ;(
86816 + */
86817 + if (is_fs_load && !strcmp(name, "register_filesystem"))
86818 + register_filesystem_found = 1;
86819 +#endif
86820 +
86821 switch (sym[i].st_shndx) {
86822 case SHN_COMMON:
86823 /* We compiled with -fno-common. These are not
86824 @@ -1966,7 +2010,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86825 ksym = resolve_symbol_wait(mod, info, name);
86826 /* Ok if resolved. */
86827 if (ksym && !IS_ERR(ksym)) {
86828 + pax_open_kernel();
86829 sym[i].st_value = ksym->value;
86830 + pax_close_kernel();
86831 break;
86832 }
86833
86834 @@ -1985,11 +2031,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86835 secbase = (unsigned long)mod_percpu(mod);
86836 else
86837 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
86838 + pax_open_kernel();
86839 sym[i].st_value += secbase;
86840 + pax_close_kernel();
86841 break;
86842 }
86843 }
86844
86845 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86846 + if (is_fs_load && !register_filesystem_found) {
86847 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
86848 + ret = -EPERM;
86849 + }
86850 +#endif
86851 +
86852 return ret;
86853 }
86854
86855 @@ -2073,22 +2128,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
86856 || s->sh_entsize != ~0UL
86857 || strstarts(sname, ".init"))
86858 continue;
86859 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
86860 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
86861 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
86862 + else
86863 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
86864 pr_debug("\t%s\n", sname);
86865 }
86866 - switch (m) {
86867 - case 0: /* executable */
86868 - mod->core_size = debug_align(mod->core_size);
86869 - mod->core_text_size = mod->core_size;
86870 - break;
86871 - case 1: /* RO: text and ro-data */
86872 - mod->core_size = debug_align(mod->core_size);
86873 - mod->core_ro_size = mod->core_size;
86874 - break;
86875 - case 3: /* whole core */
86876 - mod->core_size = debug_align(mod->core_size);
86877 - break;
86878 - }
86879 }
86880
86881 pr_debug("Init section allocation order:\n");
86882 @@ -2102,23 +2147,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
86883 || s->sh_entsize != ~0UL
86884 || !strstarts(sname, ".init"))
86885 continue;
86886 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
86887 - | INIT_OFFSET_MASK);
86888 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
86889 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
86890 + else
86891 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
86892 + s->sh_entsize |= INIT_OFFSET_MASK;
86893 pr_debug("\t%s\n", sname);
86894 }
86895 - switch (m) {
86896 - case 0: /* executable */
86897 - mod->init_size = debug_align(mod->init_size);
86898 - mod->init_text_size = mod->init_size;
86899 - break;
86900 - case 1: /* RO: text and ro-data */
86901 - mod->init_size = debug_align(mod->init_size);
86902 - mod->init_ro_size = mod->init_size;
86903 - break;
86904 - case 3: /* whole init */
86905 - mod->init_size = debug_align(mod->init_size);
86906 - break;
86907 - }
86908 }
86909 }
86910
86911 @@ -2291,7 +2326,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
86912
86913 /* Put symbol section at end of init part of module. */
86914 symsect->sh_flags |= SHF_ALLOC;
86915 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
86916 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
86917 info->index.sym) | INIT_OFFSET_MASK;
86918 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
86919
86920 @@ -2308,13 +2343,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
86921 }
86922
86923 /* Append room for core symbols at end of core part. */
86924 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
86925 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
86926 - mod->core_size += strtab_size;
86927 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
86928 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
86929 + mod->core_size_rx += strtab_size;
86930
86931 /* Put string table section at end of init part of module. */
86932 strsect->sh_flags |= SHF_ALLOC;
86933 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
86934 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
86935 info->index.str) | INIT_OFFSET_MASK;
86936 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
86937 }
86938 @@ -2332,12 +2367,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
86939 /* Make sure we get permanent strtab: don't use info->strtab. */
86940 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
86941
86942 + pax_open_kernel();
86943 +
86944 /* Set types up while we still have access to sections. */
86945 for (i = 0; i < mod->num_symtab; i++)
86946 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
86947
86948 - mod->core_symtab = dst = mod->module_core + info->symoffs;
86949 - mod->core_strtab = s = mod->module_core + info->stroffs;
86950 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
86951 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
86952 src = mod->symtab;
86953 for (ndst = i = 0; i < mod->num_symtab; i++) {
86954 if (i == 0 ||
86955 @@ -2349,6 +2386,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
86956 }
86957 }
86958 mod->core_num_syms = ndst;
86959 +
86960 + pax_close_kernel();
86961 }
86962 #else
86963 static inline void layout_symtab(struct module *mod, struct load_info *info)
86964 @@ -2382,17 +2421,33 @@ void * __weak module_alloc(unsigned long size)
86965 return vmalloc_exec(size);
86966 }
86967
86968 -static void *module_alloc_update_bounds(unsigned long size)
86969 +static void *module_alloc_update_bounds_rw(unsigned long size)
86970 {
86971 void *ret = module_alloc(size);
86972
86973 if (ret) {
86974 mutex_lock(&module_mutex);
86975 /* Update module bounds. */
86976 - if ((unsigned long)ret < module_addr_min)
86977 - module_addr_min = (unsigned long)ret;
86978 - if ((unsigned long)ret + size > module_addr_max)
86979 - module_addr_max = (unsigned long)ret + size;
86980 + if ((unsigned long)ret < module_addr_min_rw)
86981 + module_addr_min_rw = (unsigned long)ret;
86982 + if ((unsigned long)ret + size > module_addr_max_rw)
86983 + module_addr_max_rw = (unsigned long)ret + size;
86984 + mutex_unlock(&module_mutex);
86985 + }
86986 + return ret;
86987 +}
86988 +
86989 +static void *module_alloc_update_bounds_rx(unsigned long size)
86990 +{
86991 + void *ret = module_alloc_exec(size);
86992 +
86993 + if (ret) {
86994 + mutex_lock(&module_mutex);
86995 + /* Update module bounds. */
86996 + if ((unsigned long)ret < module_addr_min_rx)
86997 + module_addr_min_rx = (unsigned long)ret;
86998 + if ((unsigned long)ret + size > module_addr_max_rx)
86999 + module_addr_max_rx = (unsigned long)ret + size;
87000 mutex_unlock(&module_mutex);
87001 }
87002 return ret;
87003 @@ -2649,7 +2704,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87004 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
87005
87006 if (info->index.sym == 0) {
87007 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87008 + /*
87009 + * avoid potentially printing jibberish on attempted load
87010 + * of a module randomized with a different seed
87011 + */
87012 + pr_warn("module has no symbols (stripped?)\n");
87013 +#else
87014 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
87015 +#endif
87016 return ERR_PTR(-ENOEXEC);
87017 }
87018
87019 @@ -2665,8 +2728,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87020 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87021 {
87022 const char *modmagic = get_modinfo(info, "vermagic");
87023 + const char *license = get_modinfo(info, "license");
87024 int err;
87025
87026 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
87027 + if (!license || !license_is_gpl_compatible(license))
87028 + return -ENOEXEC;
87029 +#endif
87030 +
87031 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
87032 modmagic = NULL;
87033
87034 @@ -2691,7 +2760,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87035 }
87036
87037 /* Set up license info based on the info section */
87038 - set_license(mod, get_modinfo(info, "license"));
87039 + set_license(mod, license);
87040
87041 return 0;
87042 }
87043 @@ -2785,7 +2854,7 @@ static int move_module(struct module *mod, struct load_info *info)
87044 void *ptr;
87045
87046 /* Do the allocs. */
87047 - ptr = module_alloc_update_bounds(mod->core_size);
87048 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
87049 /*
87050 * The pointer to this block is stored in the module structure
87051 * which is inside the block. Just mark it as not being a
87052 @@ -2795,11 +2864,11 @@ static int move_module(struct module *mod, struct load_info *info)
87053 if (!ptr)
87054 return -ENOMEM;
87055
87056 - memset(ptr, 0, mod->core_size);
87057 - mod->module_core = ptr;
87058 + memset(ptr, 0, mod->core_size_rw);
87059 + mod->module_core_rw = ptr;
87060
87061 - if (mod->init_size) {
87062 - ptr = module_alloc_update_bounds(mod->init_size);
87063 + if (mod->init_size_rw) {
87064 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
87065 /*
87066 * The pointer to this block is stored in the module structure
87067 * which is inside the block. This block doesn't need to be
87068 @@ -2808,13 +2877,45 @@ static int move_module(struct module *mod, struct load_info *info)
87069 */
87070 kmemleak_ignore(ptr);
87071 if (!ptr) {
87072 - module_free(mod, mod->module_core);
87073 + module_free(mod, mod->module_core_rw);
87074 return -ENOMEM;
87075 }
87076 - memset(ptr, 0, mod->init_size);
87077 - mod->module_init = ptr;
87078 + memset(ptr, 0, mod->init_size_rw);
87079 + mod->module_init_rw = ptr;
87080 } else
87081 - mod->module_init = NULL;
87082 + mod->module_init_rw = NULL;
87083 +
87084 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
87085 + kmemleak_not_leak(ptr);
87086 + if (!ptr) {
87087 + if (mod->module_init_rw)
87088 + module_free(mod, mod->module_init_rw);
87089 + module_free(mod, mod->module_core_rw);
87090 + return -ENOMEM;
87091 + }
87092 +
87093 + pax_open_kernel();
87094 + memset(ptr, 0, mod->core_size_rx);
87095 + pax_close_kernel();
87096 + mod->module_core_rx = ptr;
87097 +
87098 + if (mod->init_size_rx) {
87099 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
87100 + kmemleak_ignore(ptr);
87101 + if (!ptr && mod->init_size_rx) {
87102 + module_free_exec(mod, mod->module_core_rx);
87103 + if (mod->module_init_rw)
87104 + module_free(mod, mod->module_init_rw);
87105 + module_free(mod, mod->module_core_rw);
87106 + return -ENOMEM;
87107 + }
87108 +
87109 + pax_open_kernel();
87110 + memset(ptr, 0, mod->init_size_rx);
87111 + pax_close_kernel();
87112 + mod->module_init_rx = ptr;
87113 + } else
87114 + mod->module_init_rx = NULL;
87115
87116 /* Transfer each section which specifies SHF_ALLOC */
87117 pr_debug("final section addresses:\n");
87118 @@ -2825,16 +2926,45 @@ static int move_module(struct module *mod, struct load_info *info)
87119 if (!(shdr->sh_flags & SHF_ALLOC))
87120 continue;
87121
87122 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
87123 - dest = mod->module_init
87124 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87125 - else
87126 - dest = mod->module_core + shdr->sh_entsize;
87127 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
87128 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87129 + dest = mod->module_init_rw
87130 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87131 + else
87132 + dest = mod->module_init_rx
87133 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87134 + } else {
87135 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87136 + dest = mod->module_core_rw + shdr->sh_entsize;
87137 + else
87138 + dest = mod->module_core_rx + shdr->sh_entsize;
87139 + }
87140 +
87141 + if (shdr->sh_type != SHT_NOBITS) {
87142 +
87143 +#ifdef CONFIG_PAX_KERNEXEC
87144 +#ifdef CONFIG_X86_64
87145 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
87146 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
87147 +#endif
87148 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
87149 + pax_open_kernel();
87150 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87151 + pax_close_kernel();
87152 + } else
87153 +#endif
87154
87155 - if (shdr->sh_type != SHT_NOBITS)
87156 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87157 + }
87158 /* Update sh_addr to point to copy in image. */
87159 - shdr->sh_addr = (unsigned long)dest;
87160 +
87161 +#ifdef CONFIG_PAX_KERNEXEC
87162 + if (shdr->sh_flags & SHF_EXECINSTR)
87163 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
87164 + else
87165 +#endif
87166 +
87167 + shdr->sh_addr = (unsigned long)dest;
87168 pr_debug("\t0x%lx %s\n",
87169 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
87170 }
87171 @@ -2891,12 +3021,12 @@ static void flush_module_icache(const struct module *mod)
87172 * Do it before processing of module parameters, so the module
87173 * can provide parameter accessor functions of its own.
87174 */
87175 - if (mod->module_init)
87176 - flush_icache_range((unsigned long)mod->module_init,
87177 - (unsigned long)mod->module_init
87178 - + mod->init_size);
87179 - flush_icache_range((unsigned long)mod->module_core,
87180 - (unsigned long)mod->module_core + mod->core_size);
87181 + if (mod->module_init_rx)
87182 + flush_icache_range((unsigned long)mod->module_init_rx,
87183 + (unsigned long)mod->module_init_rx
87184 + + mod->init_size_rx);
87185 + flush_icache_range((unsigned long)mod->module_core_rx,
87186 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
87187
87188 set_fs(old_fs);
87189 }
87190 @@ -2953,8 +3083,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
87191 static void module_deallocate(struct module *mod, struct load_info *info)
87192 {
87193 percpu_modfree(mod);
87194 - module_free(mod, mod->module_init);
87195 - module_free(mod, mod->module_core);
87196 + module_free_exec(mod, mod->module_init_rx);
87197 + module_free_exec(mod, mod->module_core_rx);
87198 + module_free(mod, mod->module_init_rw);
87199 + module_free(mod, mod->module_core_rw);
87200 }
87201
87202 int __weak module_finalize(const Elf_Ehdr *hdr,
87203 @@ -2967,7 +3099,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
87204 static int post_relocation(struct module *mod, const struct load_info *info)
87205 {
87206 /* Sort exception table now relocations are done. */
87207 + pax_open_kernel();
87208 sort_extable(mod->extable, mod->extable + mod->num_exentries);
87209 + pax_close_kernel();
87210
87211 /* Copy relocated percpu area over. */
87212 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
87213 @@ -3021,16 +3155,16 @@ static int do_init_module(struct module *mod)
87214 MODULE_STATE_COMING, mod);
87215
87216 /* Set RO and NX regions for core */
87217 - set_section_ro_nx(mod->module_core,
87218 - mod->core_text_size,
87219 - mod->core_ro_size,
87220 - mod->core_size);
87221 + set_section_ro_nx(mod->module_core_rx,
87222 + mod->core_size_rx,
87223 + mod->core_size_rx,
87224 + mod->core_size_rx);
87225
87226 /* Set RO and NX regions for init */
87227 - set_section_ro_nx(mod->module_init,
87228 - mod->init_text_size,
87229 - mod->init_ro_size,
87230 - mod->init_size);
87231 + set_section_ro_nx(mod->module_init_rx,
87232 + mod->init_size_rx,
87233 + mod->init_size_rx,
87234 + mod->init_size_rx);
87235
87236 do_mod_ctors(mod);
87237 /* Start the module */
87238 @@ -3091,11 +3225,12 @@ static int do_init_module(struct module *mod)
87239 mod->strtab = mod->core_strtab;
87240 #endif
87241 unset_module_init_ro_nx(mod);
87242 - module_free(mod, mod->module_init);
87243 - mod->module_init = NULL;
87244 - mod->init_size = 0;
87245 - mod->init_ro_size = 0;
87246 - mod->init_text_size = 0;
87247 + module_free(mod, mod->module_init_rw);
87248 + module_free_exec(mod, mod->module_init_rx);
87249 + mod->module_init_rw = NULL;
87250 + mod->module_init_rx = NULL;
87251 + mod->init_size_rw = 0;
87252 + mod->init_size_rx = 0;
87253 mutex_unlock(&module_mutex);
87254 wake_up_all(&module_wq);
87255
87256 @@ -3238,9 +3373,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
87257 if (err)
87258 goto free_unload;
87259
87260 + /* Now copy in args */
87261 + mod->args = strndup_user(uargs, ~0UL >> 1);
87262 + if (IS_ERR(mod->args)) {
87263 + err = PTR_ERR(mod->args);
87264 + goto free_unload;
87265 + }
87266 +
87267 /* Set up MODINFO_ATTR fields */
87268 setup_modinfo(mod, info);
87269
87270 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87271 + {
87272 + char *p, *p2;
87273 +
87274 + if (strstr(mod->args, "grsec_modharden_netdev")) {
87275 + 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);
87276 + err = -EPERM;
87277 + goto free_modinfo;
87278 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
87279 + p += sizeof("grsec_modharden_normal") - 1;
87280 + p2 = strstr(p, "_");
87281 + if (p2) {
87282 + *p2 = '\0';
87283 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
87284 + *p2 = '_';
87285 + }
87286 + err = -EPERM;
87287 + goto free_modinfo;
87288 + }
87289 + }
87290 +#endif
87291 +
87292 /* Fix up syms, so that st_value is a pointer to location. */
87293 err = simplify_symbols(mod, info);
87294 if (err < 0)
87295 @@ -3256,13 +3420,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
87296
87297 flush_module_icache(mod);
87298
87299 - /* Now copy in args */
87300 - mod->args = strndup_user(uargs, ~0UL >> 1);
87301 - if (IS_ERR(mod->args)) {
87302 - err = PTR_ERR(mod->args);
87303 - goto free_arch_cleanup;
87304 - }
87305 -
87306 dynamic_debug_setup(info->debug, info->num_debug);
87307
87308 /* Finally it's fully formed, ready to start executing. */
87309 @@ -3297,11 +3454,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
87310 ddebug_cleanup:
87311 dynamic_debug_remove(info->debug);
87312 synchronize_sched();
87313 - kfree(mod->args);
87314 - free_arch_cleanup:
87315 module_arch_cleanup(mod);
87316 free_modinfo:
87317 free_modinfo(mod);
87318 + kfree(mod->args);
87319 free_unload:
87320 module_unload_free(mod);
87321 unlink_mod:
87322 @@ -3384,10 +3540,16 @@ static const char *get_ksymbol(struct module *mod,
87323 unsigned long nextval;
87324
87325 /* At worse, next value is at end of module */
87326 - if (within_module_init(addr, mod))
87327 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
87328 + if (within_module_init_rx(addr, mod))
87329 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
87330 + else if (within_module_init_rw(addr, mod))
87331 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
87332 + else if (within_module_core_rx(addr, mod))
87333 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
87334 + else if (within_module_core_rw(addr, mod))
87335 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
87336 else
87337 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
87338 + return NULL;
87339
87340 /* Scan for closest preceding symbol, and next symbol. (ELF
87341 starts real symbols at 1). */
87342 @@ -3638,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
87343 return 0;
87344
87345 seq_printf(m, "%s %u",
87346 - mod->name, mod->init_size + mod->core_size);
87347 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
87348 print_unload_info(m, mod);
87349
87350 /* Informative for users. */
87351 @@ -3647,7 +3809,7 @@ static int m_show(struct seq_file *m, void *p)
87352 mod->state == MODULE_STATE_COMING ? "Loading":
87353 "Live");
87354 /* Used by oprofile and other similar tools. */
87355 - seq_printf(m, " 0x%pK", mod->module_core);
87356 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
87357
87358 /* Taints info */
87359 if (mod->taints)
87360 @@ -3683,7 +3845,17 @@ static const struct file_operations proc_modules_operations = {
87361
87362 static int __init proc_modules_init(void)
87363 {
87364 +#ifndef CONFIG_GRKERNSEC_HIDESYM
87365 +#ifdef CONFIG_GRKERNSEC_PROC_USER
87366 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87367 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87368 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
87369 +#else
87370 proc_create("modules", 0, NULL, &proc_modules_operations);
87371 +#endif
87372 +#else
87373 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87374 +#endif
87375 return 0;
87376 }
87377 module_init(proc_modules_init);
87378 @@ -3744,14 +3916,14 @@ struct module *__module_address(unsigned long addr)
87379 {
87380 struct module *mod;
87381
87382 - if (addr < module_addr_min || addr > module_addr_max)
87383 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
87384 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
87385 return NULL;
87386
87387 list_for_each_entry_rcu(mod, &modules, list) {
87388 if (mod->state == MODULE_STATE_UNFORMED)
87389 continue;
87390 - if (within_module_core(addr, mod)
87391 - || within_module_init(addr, mod))
87392 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
87393 return mod;
87394 }
87395 return NULL;
87396 @@ -3786,11 +3958,20 @@ bool is_module_text_address(unsigned long addr)
87397 */
87398 struct module *__module_text_address(unsigned long addr)
87399 {
87400 - struct module *mod = __module_address(addr);
87401 + struct module *mod;
87402 +
87403 +#ifdef CONFIG_X86_32
87404 + addr = ktla_ktva(addr);
87405 +#endif
87406 +
87407 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
87408 + return NULL;
87409 +
87410 + mod = __module_address(addr);
87411 +
87412 if (mod) {
87413 /* Make sure it's within the text section. */
87414 - if (!within(addr, mod->module_init, mod->init_text_size)
87415 - && !within(addr, mod->module_core, mod->core_text_size))
87416 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
87417 mod = NULL;
87418 }
87419 return mod;
87420 diff --git a/kernel/notifier.c b/kernel/notifier.c
87421 index 2d5cc4c..d9ea600 100644
87422 --- a/kernel/notifier.c
87423 +++ b/kernel/notifier.c
87424 @@ -5,6 +5,7 @@
87425 #include <linux/rcupdate.h>
87426 #include <linux/vmalloc.h>
87427 #include <linux/reboot.h>
87428 +#include <linux/mm.h>
87429
87430 /*
87431 * Notifier list for kernel code which wants to be called
87432 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
87433 while ((*nl) != NULL) {
87434 if (n->priority > (*nl)->priority)
87435 break;
87436 - nl = &((*nl)->next);
87437 + nl = (struct notifier_block **)&((*nl)->next);
87438 }
87439 - n->next = *nl;
87440 + pax_open_kernel();
87441 + *(const void **)&n->next = *nl;
87442 rcu_assign_pointer(*nl, n);
87443 + pax_close_kernel();
87444 return 0;
87445 }
87446
87447 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
87448 return 0;
87449 if (n->priority > (*nl)->priority)
87450 break;
87451 - nl = &((*nl)->next);
87452 + nl = (struct notifier_block **)&((*nl)->next);
87453 }
87454 - n->next = *nl;
87455 + pax_open_kernel();
87456 + *(const void **)&n->next = *nl;
87457 rcu_assign_pointer(*nl, n);
87458 + pax_close_kernel();
87459 return 0;
87460 }
87461
87462 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
87463 {
87464 while ((*nl) != NULL) {
87465 if ((*nl) == n) {
87466 + pax_open_kernel();
87467 rcu_assign_pointer(*nl, n->next);
87468 + pax_close_kernel();
87469 return 0;
87470 }
87471 - nl = &((*nl)->next);
87472 + nl = (struct notifier_block **)&((*nl)->next);
87473 }
87474 return -ENOENT;
87475 }
87476 diff --git a/kernel/padata.c b/kernel/padata.c
87477 index 161402f..598814c 100644
87478 --- a/kernel/padata.c
87479 +++ b/kernel/padata.c
87480 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
87481 * seq_nr mod. number of cpus in use.
87482 */
87483
87484 - seq_nr = atomic_inc_return(&pd->seq_nr);
87485 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
87486 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
87487
87488 return padata_index_to_cpu(pd, cpu_index);
87489 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
87490 padata_init_pqueues(pd);
87491 padata_init_squeues(pd);
87492 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
87493 - atomic_set(&pd->seq_nr, -1);
87494 + atomic_set_unchecked(&pd->seq_nr, -1);
87495 atomic_set(&pd->reorder_objects, 0);
87496 atomic_set(&pd->refcnt, 0);
87497 pd->pinst = pinst;
87498 diff --git a/kernel/panic.c b/kernel/panic.c
87499 index 6d63003..486a109 100644
87500 --- a/kernel/panic.c
87501 +++ b/kernel/panic.c
87502 @@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
87503 /*
87504 * Stop ourself in panic -- architecture code may override this
87505 */
87506 -void __weak panic_smp_self_stop(void)
87507 +void __weak __noreturn panic_smp_self_stop(void)
87508 {
87509 while (1)
87510 cpu_relax();
87511 @@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
87512 disable_trace_on_warning();
87513
87514 pr_warn("------------[ cut here ]------------\n");
87515 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
87516 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
87517 raw_smp_processor_id(), current->pid, file, line, caller);
87518
87519 if (args)
87520 @@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
87521 */
87522 void __stack_chk_fail(void)
87523 {
87524 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
87525 + dump_stack();
87526 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
87527 __builtin_return_address(0));
87528 }
87529 EXPORT_SYMBOL(__stack_chk_fail);
87530 diff --git a/kernel/pid.c b/kernel/pid.c
87531 index 9b9a266..c20ef80 100644
87532 --- a/kernel/pid.c
87533 +++ b/kernel/pid.c
87534 @@ -33,6 +33,7 @@
87535 #include <linux/rculist.h>
87536 #include <linux/bootmem.h>
87537 #include <linux/hash.h>
87538 +#include <linux/security.h>
87539 #include <linux/pid_namespace.h>
87540 #include <linux/init_task.h>
87541 #include <linux/syscalls.h>
87542 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
87543
87544 int pid_max = PID_MAX_DEFAULT;
87545
87546 -#define RESERVED_PIDS 300
87547 +#define RESERVED_PIDS 500
87548
87549 int pid_max_min = RESERVED_PIDS + 1;
87550 int pid_max_max = PID_MAX_LIMIT;
87551 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
87552 */
87553 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
87554 {
87555 + struct task_struct *task;
87556 +
87557 rcu_lockdep_assert(rcu_read_lock_held(),
87558 "find_task_by_pid_ns() needs rcu_read_lock()"
87559 " protection");
87560 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87561 +
87562 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87563 +
87564 + if (gr_pid_is_chrooted(task))
87565 + return NULL;
87566 +
87567 + return task;
87568 }
87569
87570 struct task_struct *find_task_by_vpid(pid_t vnr)
87571 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
87572 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
87573 }
87574
87575 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
87576 +{
87577 + rcu_lockdep_assert(rcu_read_lock_held(),
87578 + "find_task_by_pid_ns() needs rcu_read_lock()"
87579 + " protection");
87580 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
87581 +}
87582 +
87583 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
87584 {
87585 struct pid *pid;
87586 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
87587 index 06c62de..a0ca23f 100644
87588 --- a/kernel/pid_namespace.c
87589 +++ b/kernel/pid_namespace.c
87590 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
87591 void __user *buffer, size_t *lenp, loff_t *ppos)
87592 {
87593 struct pid_namespace *pid_ns = task_active_pid_ns(current);
87594 - struct ctl_table tmp = *table;
87595 + ctl_table_no_const tmp = *table;
87596
87597 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
87598 return -EPERM;
87599 @@ -318,7 +318,9 @@ static void *pidns_get(struct task_struct *task)
87600 struct pid_namespace *ns;
87601
87602 rcu_read_lock();
87603 - ns = get_pid_ns(task_active_pid_ns(task));
87604 + ns = task_active_pid_ns(task);
87605 + if (ns)
87606 + get_pid_ns(ns);
87607 rcu_read_unlock();
87608
87609 return ns;
87610 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
87611 index 3b89464..5e38379 100644
87612 --- a/kernel/posix-cpu-timers.c
87613 +++ b/kernel/posix-cpu-timers.c
87614 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
87615
87616 static __init int init_posix_cpu_timers(void)
87617 {
87618 - struct k_clock process = {
87619 + static struct k_clock process = {
87620 .clock_getres = process_cpu_clock_getres,
87621 .clock_get = process_cpu_clock_get,
87622 .timer_create = process_cpu_timer_create,
87623 .nsleep = process_cpu_nsleep,
87624 .nsleep_restart = process_cpu_nsleep_restart,
87625 };
87626 - struct k_clock thread = {
87627 + static struct k_clock thread = {
87628 .clock_getres = thread_cpu_clock_getres,
87629 .clock_get = thread_cpu_clock_get,
87630 .timer_create = thread_cpu_timer_create,
87631 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
87632 index 424c2d4..679242f 100644
87633 --- a/kernel/posix-timers.c
87634 +++ b/kernel/posix-timers.c
87635 @@ -43,6 +43,7 @@
87636 #include <linux/hash.h>
87637 #include <linux/posix-clock.h>
87638 #include <linux/posix-timers.h>
87639 +#include <linux/grsecurity.h>
87640 #include <linux/syscalls.h>
87641 #include <linux/wait.h>
87642 #include <linux/workqueue.h>
87643 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
87644 * which we beg off on and pass to do_sys_settimeofday().
87645 */
87646
87647 -static struct k_clock posix_clocks[MAX_CLOCKS];
87648 +static struct k_clock *posix_clocks[MAX_CLOCKS];
87649
87650 /*
87651 * These ones are defined below.
87652 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
87653 */
87654 static __init int init_posix_timers(void)
87655 {
87656 - struct k_clock clock_realtime = {
87657 + static struct k_clock clock_realtime = {
87658 .clock_getres = hrtimer_get_res,
87659 .clock_get = posix_clock_realtime_get,
87660 .clock_set = posix_clock_realtime_set,
87661 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
87662 .timer_get = common_timer_get,
87663 .timer_del = common_timer_del,
87664 };
87665 - struct k_clock clock_monotonic = {
87666 + static struct k_clock clock_monotonic = {
87667 .clock_getres = hrtimer_get_res,
87668 .clock_get = posix_ktime_get_ts,
87669 .nsleep = common_nsleep,
87670 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
87671 .timer_get = common_timer_get,
87672 .timer_del = common_timer_del,
87673 };
87674 - struct k_clock clock_monotonic_raw = {
87675 + static struct k_clock clock_monotonic_raw = {
87676 .clock_getres = hrtimer_get_res,
87677 .clock_get = posix_get_monotonic_raw,
87678 };
87679 - struct k_clock clock_realtime_coarse = {
87680 + static struct k_clock clock_realtime_coarse = {
87681 .clock_getres = posix_get_coarse_res,
87682 .clock_get = posix_get_realtime_coarse,
87683 };
87684 - struct k_clock clock_monotonic_coarse = {
87685 + static struct k_clock clock_monotonic_coarse = {
87686 .clock_getres = posix_get_coarse_res,
87687 .clock_get = posix_get_monotonic_coarse,
87688 };
87689 - struct k_clock clock_tai = {
87690 + static struct k_clock clock_tai = {
87691 .clock_getres = hrtimer_get_res,
87692 .clock_get = posix_get_tai,
87693 .nsleep = common_nsleep,
87694 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
87695 .timer_get = common_timer_get,
87696 .timer_del = common_timer_del,
87697 };
87698 - struct k_clock clock_boottime = {
87699 + static struct k_clock clock_boottime = {
87700 .clock_getres = hrtimer_get_res,
87701 .clock_get = posix_get_boottime,
87702 .nsleep = common_nsleep,
87703 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
87704 return;
87705 }
87706
87707 - posix_clocks[clock_id] = *new_clock;
87708 + posix_clocks[clock_id] = new_clock;
87709 }
87710 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
87711
87712 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
87713 return (id & CLOCKFD_MASK) == CLOCKFD ?
87714 &clock_posix_dynamic : &clock_posix_cpu;
87715
87716 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
87717 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
87718 return NULL;
87719 - return &posix_clocks[id];
87720 + return posix_clocks[id];
87721 }
87722
87723 static int common_timer_create(struct k_itimer *new_timer)
87724 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
87725 struct k_clock *kc = clockid_to_kclock(which_clock);
87726 struct k_itimer *new_timer;
87727 int error, new_timer_id;
87728 - sigevent_t event;
87729 + sigevent_t event = { };
87730 int it_id_set = IT_ID_NOT_SET;
87731
87732 if (!kc)
87733 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
87734 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
87735 return -EFAULT;
87736
87737 + /* only the CLOCK_REALTIME clock can be set, all other clocks
87738 + have their clock_set fptr set to a nosettime dummy function
87739 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
87740 + call common_clock_set, which calls do_sys_settimeofday, which
87741 + we hook
87742 + */
87743 +
87744 return kc->clock_set(which_clock, &new_tp);
87745 }
87746
87747 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
87748 index 2fac9cc..56fef29 100644
87749 --- a/kernel/power/Kconfig
87750 +++ b/kernel/power/Kconfig
87751 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
87752 config HIBERNATION
87753 bool "Hibernation (aka 'suspend to disk')"
87754 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
87755 + depends on !GRKERNSEC_KMEM
87756 + depends on !PAX_MEMORY_SANITIZE
87757 select HIBERNATE_CALLBACKS
87758 select LZO_COMPRESS
87759 select LZO_DECOMPRESS
87760 diff --git a/kernel/power/process.c b/kernel/power/process.c
87761 index 06ec886..9dba35e 100644
87762 --- a/kernel/power/process.c
87763 +++ b/kernel/power/process.c
87764 @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
87765 unsigned int elapsed_msecs;
87766 bool wakeup = false;
87767 int sleep_usecs = USEC_PER_MSEC;
87768 + bool timedout = false;
87769
87770 do_gettimeofday(&start);
87771
87772 @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
87773
87774 while (true) {
87775 todo = 0;
87776 + if (time_after(jiffies, end_time))
87777 + timedout = true;
87778 read_lock(&tasklist_lock);
87779 do_each_thread(g, p) {
87780 if (p == current || !freeze_task(p))
87781 continue;
87782
87783 - if (!freezer_should_skip(p))
87784 + if (!freezer_should_skip(p)) {
87785 todo++;
87786 + if (timedout) {
87787 + printk(KERN_ERR "Task refusing to freeze:\n");
87788 + sched_show_task(p);
87789 + }
87790 + }
87791 } while_each_thread(g, p);
87792 read_unlock(&tasklist_lock);
87793
87794 @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
87795 todo += wq_busy;
87796 }
87797
87798 - if (!todo || time_after(jiffies, end_time))
87799 + if (!todo || timedout)
87800 break;
87801
87802 if (pm_wakeup_pending()) {
87803 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
87804 index 4dae9cb..039ffbb 100644
87805 --- a/kernel/printk/printk.c
87806 +++ b/kernel/printk/printk.c
87807 @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
87808 if (from_file && type != SYSLOG_ACTION_OPEN)
87809 return 0;
87810
87811 +#ifdef CONFIG_GRKERNSEC_DMESG
87812 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
87813 + return -EPERM;
87814 +#endif
87815 +
87816 if (syslog_action_restricted(type)) {
87817 if (capable(CAP_SYSLOG))
87818 return 0;
87819 diff --git a/kernel/profile.c b/kernel/profile.c
87820 index ebdd9c1..612ee05 100644
87821 --- a/kernel/profile.c
87822 +++ b/kernel/profile.c
87823 @@ -37,7 +37,7 @@ struct profile_hit {
87824 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
87825 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
87826
87827 -static atomic_t *prof_buffer;
87828 +static atomic_unchecked_t *prof_buffer;
87829 static unsigned long prof_len, prof_shift;
87830
87831 int prof_on __read_mostly;
87832 @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
87833 hits[i].pc = 0;
87834 continue;
87835 }
87836 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
87837 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
87838 hits[i].hits = hits[i].pc = 0;
87839 }
87840 }
87841 @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
87842 * Add the current hit(s) and flush the write-queue out
87843 * to the global buffer:
87844 */
87845 - atomic_add(nr_hits, &prof_buffer[pc]);
87846 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
87847 for (i = 0; i < NR_PROFILE_HIT; ++i) {
87848 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
87849 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
87850 hits[i].pc = hits[i].hits = 0;
87851 }
87852 out:
87853 @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
87854 {
87855 unsigned long pc;
87856 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
87857 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
87858 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
87859 }
87860 #endif /* !CONFIG_SMP */
87861
87862 @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
87863 return -EFAULT;
87864 buf++; p++; count--; read++;
87865 }
87866 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
87867 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
87868 if (copy_to_user(buf, (void *)pnt, count))
87869 return -EFAULT;
87870 read += count;
87871 @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
87872 }
87873 #endif
87874 profile_discard_flip_buffers();
87875 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
87876 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
87877 return count;
87878 }
87879
87880 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
87881 index 1f4bcb3..99cf7ab 100644
87882 --- a/kernel/ptrace.c
87883 +++ b/kernel/ptrace.c
87884 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
87885 if (seize)
87886 flags |= PT_SEIZED;
87887 rcu_read_lock();
87888 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
87889 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
87890 flags |= PT_PTRACE_CAP;
87891 rcu_read_unlock();
87892 task->ptrace = flags;
87893 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
87894 break;
87895 return -EIO;
87896 }
87897 - if (copy_to_user(dst, buf, retval))
87898 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
87899 return -EFAULT;
87900 copied += retval;
87901 src += retval;
87902 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
87903 bool seized = child->ptrace & PT_SEIZED;
87904 int ret = -EIO;
87905 siginfo_t siginfo, *si;
87906 - void __user *datavp = (void __user *) data;
87907 + void __user *datavp = (__force void __user *) data;
87908 unsigned long __user *datalp = datavp;
87909 unsigned long flags;
87910
87911 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
87912 goto out;
87913 }
87914
87915 + if (gr_handle_ptrace(child, request)) {
87916 + ret = -EPERM;
87917 + goto out_put_task_struct;
87918 + }
87919 +
87920 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
87921 ret = ptrace_attach(child, request, addr, data);
87922 /*
87923 * Some architectures need to do book-keeping after
87924 * a ptrace attach.
87925 */
87926 - if (!ret)
87927 + if (!ret) {
87928 arch_ptrace_attach(child);
87929 + gr_audit_ptrace(child);
87930 + }
87931 goto out_put_task_struct;
87932 }
87933
87934 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
87935 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
87936 if (copied != sizeof(tmp))
87937 return -EIO;
87938 - return put_user(tmp, (unsigned long __user *)data);
87939 + return put_user(tmp, (__force unsigned long __user *)data);
87940 }
87941
87942 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
87943 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
87944 }
87945
87946 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
87947 - compat_long_t addr, compat_long_t data)
87948 + compat_ulong_t addr, compat_ulong_t data)
87949 {
87950 struct task_struct *child;
87951 long ret;
87952 @@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
87953 goto out;
87954 }
87955
87956 + if (gr_handle_ptrace(child, request)) {
87957 + ret = -EPERM;
87958 + goto out_put_task_struct;
87959 + }
87960 +
87961 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
87962 ret = ptrace_attach(child, request, addr, data);
87963 /*
87964 * Some architectures need to do book-keeping after
87965 * a ptrace attach.
87966 */
87967 - if (!ret)
87968 + if (!ret) {
87969 arch_ptrace_attach(child);
87970 + gr_audit_ptrace(child);
87971 + }
87972 goto out_put_task_struct;
87973 }
87974
87975 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
87976 index 3318d82..1a5b2d1 100644
87977 --- a/kernel/rcu/srcu.c
87978 +++ b/kernel/rcu/srcu.c
87979 @@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
87980
87981 idx = ACCESS_ONCE(sp->completed) & 0x1;
87982 preempt_disable();
87983 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
87984 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
87985 smp_mb(); /* B */ /* Avoid leaking the critical section. */
87986 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
87987 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
87988 preempt_enable();
87989 return idx;
87990 }
87991 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
87992 index 1254f31..16258dc 100644
87993 --- a/kernel/rcu/tiny.c
87994 +++ b/kernel/rcu/tiny.c
87995 @@ -46,7 +46,7 @@
87996 /* Forward declarations for tiny_plugin.h. */
87997 struct rcu_ctrlblk;
87998 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
87999 -static void rcu_process_callbacks(struct softirq_action *unused);
88000 +static void rcu_process_callbacks(void);
88001 static void __call_rcu(struct rcu_head *head,
88002 void (*func)(struct rcu_head *rcu),
88003 struct rcu_ctrlblk *rcp);
88004 @@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
88005 false));
88006 }
88007
88008 -static void rcu_process_callbacks(struct softirq_action *unused)
88009 +static __latent_entropy void rcu_process_callbacks(void)
88010 {
88011 __rcu_process_callbacks(&rcu_sched_ctrlblk);
88012 __rcu_process_callbacks(&rcu_bh_ctrlblk);
88013 diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
88014 index 732f8ae..9984c27 100644
88015 --- a/kernel/rcu/torture.c
88016 +++ b/kernel/rcu/torture.c
88017 @@ -174,12 +174,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
88018 { 0 };
88019 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
88020 { 0 };
88021 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88022 -static atomic_t n_rcu_torture_alloc;
88023 -static atomic_t n_rcu_torture_alloc_fail;
88024 -static atomic_t n_rcu_torture_free;
88025 -static atomic_t n_rcu_torture_mberror;
88026 -static atomic_t n_rcu_torture_error;
88027 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88028 +static atomic_unchecked_t n_rcu_torture_alloc;
88029 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
88030 +static atomic_unchecked_t n_rcu_torture_free;
88031 +static atomic_unchecked_t n_rcu_torture_mberror;
88032 +static atomic_unchecked_t n_rcu_torture_error;
88033 static long n_rcu_torture_barrier_error;
88034 static long n_rcu_torture_boost_ktrerror;
88035 static long n_rcu_torture_boost_rterror;
88036 @@ -297,11 +297,11 @@ rcu_torture_alloc(void)
88037
88038 spin_lock_bh(&rcu_torture_lock);
88039 if (list_empty(&rcu_torture_freelist)) {
88040 - atomic_inc(&n_rcu_torture_alloc_fail);
88041 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88042 spin_unlock_bh(&rcu_torture_lock);
88043 return NULL;
88044 }
88045 - atomic_inc(&n_rcu_torture_alloc);
88046 + atomic_inc_unchecked(&n_rcu_torture_alloc);
88047 p = rcu_torture_freelist.next;
88048 list_del_init(p);
88049 spin_unlock_bh(&rcu_torture_lock);
88050 @@ -314,7 +314,7 @@ rcu_torture_alloc(void)
88051 static void
88052 rcu_torture_free(struct rcu_torture *p)
88053 {
88054 - atomic_inc(&n_rcu_torture_free);
88055 + atomic_inc_unchecked(&n_rcu_torture_free);
88056 spin_lock_bh(&rcu_torture_lock);
88057 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88058 spin_unlock_bh(&rcu_torture_lock);
88059 @@ -435,7 +435,7 @@ rcu_torture_cb(struct rcu_head *p)
88060 i = rp->rtort_pipe_count;
88061 if (i > RCU_TORTURE_PIPE_LEN)
88062 i = RCU_TORTURE_PIPE_LEN;
88063 - atomic_inc(&rcu_torture_wcount[i]);
88064 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88065 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
88066 rp->rtort_mbtest = 0;
88067 rcu_torture_free(rp);
88068 @@ -823,7 +823,7 @@ rcu_torture_writer(void *arg)
88069 i = old_rp->rtort_pipe_count;
88070 if (i > RCU_TORTURE_PIPE_LEN)
88071 i = RCU_TORTURE_PIPE_LEN;
88072 - atomic_inc(&rcu_torture_wcount[i]);
88073 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88074 old_rp->rtort_pipe_count++;
88075 if (gp_normal == gp_exp)
88076 exp = !!(rcu_random(&rand) & 0x80);
88077 @@ -841,7 +841,7 @@ rcu_torture_writer(void *arg)
88078 i = rp->rtort_pipe_count;
88079 if (i > RCU_TORTURE_PIPE_LEN)
88080 i = RCU_TORTURE_PIPE_LEN;
88081 - atomic_inc(&rcu_torture_wcount[i]);
88082 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88083 if (++rp->rtort_pipe_count >=
88084 RCU_TORTURE_PIPE_LEN) {
88085 rp->rtort_mbtest = 0;
88086 @@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
88087 return;
88088 }
88089 if (p->rtort_mbtest == 0)
88090 - atomic_inc(&n_rcu_torture_mberror);
88091 + atomic_inc_unchecked(&n_rcu_torture_mberror);
88092 spin_lock(&rand_lock);
88093 cur_ops->read_delay(&rand);
88094 n_rcu_torture_timers++;
88095 @@ -1010,7 +1010,7 @@ rcu_torture_reader(void *arg)
88096 continue;
88097 }
88098 if (p->rtort_mbtest == 0)
88099 - atomic_inc(&n_rcu_torture_mberror);
88100 + atomic_inc_unchecked(&n_rcu_torture_mberror);
88101 cur_ops->read_delay(&rand);
88102 preempt_disable();
88103 pipe_count = p->rtort_pipe_count;
88104 @@ -1072,11 +1072,11 @@ rcu_torture_printk(char *page)
88105 rcu_torture_current,
88106 rcu_torture_current_version,
88107 list_empty(&rcu_torture_freelist),
88108 - atomic_read(&n_rcu_torture_alloc),
88109 - atomic_read(&n_rcu_torture_alloc_fail),
88110 - atomic_read(&n_rcu_torture_free));
88111 + atomic_read_unchecked(&n_rcu_torture_alloc),
88112 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
88113 + atomic_read_unchecked(&n_rcu_torture_free));
88114 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
88115 - atomic_read(&n_rcu_torture_mberror),
88116 + atomic_read_unchecked(&n_rcu_torture_mberror),
88117 n_rcu_torture_boost_ktrerror,
88118 n_rcu_torture_boost_rterror);
88119 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
88120 @@ -1095,14 +1095,14 @@ rcu_torture_printk(char *page)
88121 n_barrier_attempts,
88122 n_rcu_torture_barrier_error);
88123 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
88124 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
88125 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
88126 n_rcu_torture_barrier_error != 0 ||
88127 n_rcu_torture_boost_ktrerror != 0 ||
88128 n_rcu_torture_boost_rterror != 0 ||
88129 n_rcu_torture_boost_failure != 0 ||
88130 i > 1) {
88131 page += sprintf(page, "!!! ");
88132 - atomic_inc(&n_rcu_torture_error);
88133 + atomic_inc_unchecked(&n_rcu_torture_error);
88134 WARN_ON_ONCE(1);
88135 }
88136 page += sprintf(page, "Reader Pipe: ");
88137 @@ -1116,7 +1116,7 @@ rcu_torture_printk(char *page)
88138 page += sprintf(page, "Free-Block Circulation: ");
88139 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88140 page += sprintf(page, " %d",
88141 - atomic_read(&rcu_torture_wcount[i]));
88142 + atomic_read_unchecked(&rcu_torture_wcount[i]));
88143 }
88144 page += sprintf(page, "\n");
88145 if (cur_ops->stats)
88146 @@ -1839,7 +1839,7 @@ rcu_torture_cleanup(void)
88147
88148 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
88149
88150 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88151 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88152 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
88153 else if (n_online_successes != n_online_attempts ||
88154 n_offline_successes != n_offline_attempts)
88155 @@ -1961,18 +1961,18 @@ rcu_torture_init(void)
88156
88157 rcu_torture_current = NULL;
88158 rcu_torture_current_version = 0;
88159 - atomic_set(&n_rcu_torture_alloc, 0);
88160 - atomic_set(&n_rcu_torture_alloc_fail, 0);
88161 - atomic_set(&n_rcu_torture_free, 0);
88162 - atomic_set(&n_rcu_torture_mberror, 0);
88163 - atomic_set(&n_rcu_torture_error, 0);
88164 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
88165 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
88166 + atomic_set_unchecked(&n_rcu_torture_free, 0);
88167 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
88168 + atomic_set_unchecked(&n_rcu_torture_error, 0);
88169 n_rcu_torture_barrier_error = 0;
88170 n_rcu_torture_boost_ktrerror = 0;
88171 n_rcu_torture_boost_rterror = 0;
88172 n_rcu_torture_boost_failure = 0;
88173 n_rcu_torture_boosts = 0;
88174 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
88175 - atomic_set(&rcu_torture_wcount[i], 0);
88176 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
88177 for_each_possible_cpu(cpu) {
88178 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88179 per_cpu(rcu_torture_count, cpu)[i] = 0;
88180 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
88181 index b3d116c..ebf6598 100644
88182 --- a/kernel/rcu/tree.c
88183 +++ b/kernel/rcu/tree.c
88184 @@ -390,9 +390,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
88185 rcu_prepare_for_idle(smp_processor_id());
88186 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88187 smp_mb__before_atomic_inc(); /* See above. */
88188 - atomic_inc(&rdtp->dynticks);
88189 + atomic_inc_unchecked(&rdtp->dynticks);
88190 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
88191 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88192 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88193
88194 /*
88195 * It is illegal to enter an extended quiescent state while
88196 @@ -510,10 +510,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
88197 int user)
88198 {
88199 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
88200 - atomic_inc(&rdtp->dynticks);
88201 + atomic_inc_unchecked(&rdtp->dynticks);
88202 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88203 smp_mb__after_atomic_inc(); /* See above. */
88204 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88205 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88206 rcu_cleanup_after_idle(smp_processor_id());
88207 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
88208 if (!user && !is_idle_task(current)) {
88209 @@ -634,14 +634,14 @@ void rcu_nmi_enter(void)
88210 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
88211
88212 if (rdtp->dynticks_nmi_nesting == 0 &&
88213 - (atomic_read(&rdtp->dynticks) & 0x1))
88214 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
88215 return;
88216 rdtp->dynticks_nmi_nesting++;
88217 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
88218 - atomic_inc(&rdtp->dynticks);
88219 + atomic_inc_unchecked(&rdtp->dynticks);
88220 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88221 smp_mb__after_atomic_inc(); /* See above. */
88222 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88223 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88224 }
88225
88226 /**
88227 @@ -660,9 +660,9 @@ void rcu_nmi_exit(void)
88228 return;
88229 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88230 smp_mb__before_atomic_inc(); /* See above. */
88231 - atomic_inc(&rdtp->dynticks);
88232 + atomic_inc_unchecked(&rdtp->dynticks);
88233 smp_mb__after_atomic_inc(); /* Force delay to next write. */
88234 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88235 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88236 }
88237
88238 /**
88239 @@ -675,7 +675,7 @@ void rcu_nmi_exit(void)
88240 */
88241 bool notrace __rcu_is_watching(void)
88242 {
88243 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88244 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88245 }
88246
88247 /**
88248 @@ -758,7 +758,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
88249 static int dyntick_save_progress_counter(struct rcu_data *rdp,
88250 bool *isidle, unsigned long *maxj)
88251 {
88252 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
88253 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88254 rcu_sysidle_check_cpu(rdp, isidle, maxj);
88255 return (rdp->dynticks_snap & 0x1) == 0;
88256 }
88257 @@ -781,7 +781,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
88258 unsigned int curr;
88259 unsigned int snap;
88260
88261 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
88262 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88263 snap = (unsigned int)rdp->dynticks_snap;
88264
88265 /*
88266 @@ -1450,9 +1450,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
88267 rdp = this_cpu_ptr(rsp->rda);
88268 rcu_preempt_check_blocked_tasks(rnp);
88269 rnp->qsmask = rnp->qsmaskinit;
88270 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
88271 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
88272 WARN_ON_ONCE(rnp->completed != rsp->completed);
88273 - ACCESS_ONCE(rnp->completed) = rsp->completed;
88274 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
88275 if (rnp == rdp->mynode)
88276 __note_gp_changes(rsp, rnp, rdp);
88277 rcu_preempt_boost_start_gp(rnp);
88278 @@ -1546,7 +1546,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
88279 rcu_for_each_node_breadth_first(rsp, rnp) {
88280 raw_spin_lock_irq(&rnp->lock);
88281 smp_mb__after_unlock_lock();
88282 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
88283 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
88284 rdp = this_cpu_ptr(rsp->rda);
88285 if (rnp == rdp->mynode)
88286 __note_gp_changes(rsp, rnp, rdp);
88287 @@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
88288 rsp->qlen += rdp->qlen;
88289 rdp->n_cbs_orphaned += rdp->qlen;
88290 rdp->qlen_lazy = 0;
88291 - ACCESS_ONCE(rdp->qlen) = 0;
88292 + ACCESS_ONCE_RW(rdp->qlen) = 0;
88293 }
88294
88295 /*
88296 @@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
88297 }
88298 smp_mb(); /* List handling before counting for rcu_barrier(). */
88299 rdp->qlen_lazy -= count_lazy;
88300 - ACCESS_ONCE(rdp->qlen) -= count;
88301 + ACCESS_ONCE_RW(rdp->qlen) -= count;
88302 rdp->n_cbs_invoked += count;
88303
88304 /* Reinstate batch limit if we have worked down the excess. */
88305 @@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
88306 /*
88307 * Do RCU core processing for the current CPU.
88308 */
88309 -static void rcu_process_callbacks(struct softirq_action *unused)
88310 +static void rcu_process_callbacks(void)
88311 {
88312 struct rcu_state *rsp;
88313
88314 @@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88315 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
88316 if (debug_rcu_head_queue(head)) {
88317 /* Probable double call_rcu(), so leak the callback. */
88318 - ACCESS_ONCE(head->func) = rcu_leak_callback;
88319 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
88320 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
88321 return;
88322 }
88323 @@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88324 local_irq_restore(flags);
88325 return;
88326 }
88327 - ACCESS_ONCE(rdp->qlen)++;
88328 + ACCESS_ONCE_RW(rdp->qlen)++;
88329 if (lazy)
88330 rdp->qlen_lazy++;
88331 else
88332 @@ -2707,11 +2707,11 @@ void synchronize_sched_expedited(void)
88333 * counter wrap on a 32-bit system. Quite a few more CPUs would of
88334 * course be required on a 64-bit system.
88335 */
88336 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
88337 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
88338 (ulong)atomic_long_read(&rsp->expedited_done) +
88339 ULONG_MAX / 8)) {
88340 synchronize_sched();
88341 - atomic_long_inc(&rsp->expedited_wrap);
88342 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
88343 return;
88344 }
88345
88346 @@ -2719,7 +2719,7 @@ void synchronize_sched_expedited(void)
88347 * Take a ticket. Note that atomic_inc_return() implies a
88348 * full memory barrier.
88349 */
88350 - snap = atomic_long_inc_return(&rsp->expedited_start);
88351 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
88352 firstsnap = snap;
88353 get_online_cpus();
88354 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
88355 @@ -2732,14 +2732,14 @@ void synchronize_sched_expedited(void)
88356 synchronize_sched_expedited_cpu_stop,
88357 NULL) == -EAGAIN) {
88358 put_online_cpus();
88359 - atomic_long_inc(&rsp->expedited_tryfail);
88360 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
88361
88362 /* Check to see if someone else did our work for us. */
88363 s = atomic_long_read(&rsp->expedited_done);
88364 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88365 /* ensure test happens before caller kfree */
88366 smp_mb__before_atomic_inc(); /* ^^^ */
88367 - atomic_long_inc(&rsp->expedited_workdone1);
88368 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
88369 return;
88370 }
88371
88372 @@ -2748,7 +2748,7 @@ void synchronize_sched_expedited(void)
88373 udelay(trycount * num_online_cpus());
88374 } else {
88375 wait_rcu_gp(call_rcu_sched);
88376 - atomic_long_inc(&rsp->expedited_normal);
88377 + atomic_long_inc_unchecked(&rsp->expedited_normal);
88378 return;
88379 }
88380
88381 @@ -2757,7 +2757,7 @@ void synchronize_sched_expedited(void)
88382 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88383 /* ensure test happens before caller kfree */
88384 smp_mb__before_atomic_inc(); /* ^^^ */
88385 - atomic_long_inc(&rsp->expedited_workdone2);
88386 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
88387 return;
88388 }
88389
88390 @@ -2769,10 +2769,10 @@ void synchronize_sched_expedited(void)
88391 * period works for us.
88392 */
88393 get_online_cpus();
88394 - snap = atomic_long_read(&rsp->expedited_start);
88395 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
88396 smp_mb(); /* ensure read is before try_stop_cpus(). */
88397 }
88398 - atomic_long_inc(&rsp->expedited_stoppedcpus);
88399 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
88400
88401 /*
88402 * Everyone up to our most recent fetch is covered by our grace
88403 @@ -2781,16 +2781,16 @@ void synchronize_sched_expedited(void)
88404 * than we did already did their update.
88405 */
88406 do {
88407 - atomic_long_inc(&rsp->expedited_done_tries);
88408 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
88409 s = atomic_long_read(&rsp->expedited_done);
88410 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
88411 /* ensure test happens before caller kfree */
88412 smp_mb__before_atomic_inc(); /* ^^^ */
88413 - atomic_long_inc(&rsp->expedited_done_lost);
88414 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
88415 break;
88416 }
88417 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
88418 - atomic_long_inc(&rsp->expedited_done_exit);
88419 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
88420
88421 put_online_cpus();
88422 }
88423 @@ -2996,7 +2996,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88424 * ACCESS_ONCE() to prevent the compiler from speculating
88425 * the increment to precede the early-exit check.
88426 */
88427 - ACCESS_ONCE(rsp->n_barrier_done)++;
88428 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88429 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
88430 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
88431 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
88432 @@ -3046,7 +3046,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88433
88434 /* Increment ->n_barrier_done to prevent duplicate work. */
88435 smp_mb(); /* Keep increment after above mechanism. */
88436 - ACCESS_ONCE(rsp->n_barrier_done)++;
88437 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88438 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
88439 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
88440 smp_mb(); /* Keep increment before caller's subsequent code. */
88441 @@ -3091,10 +3091,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
88442 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
88443 init_callback_list(rdp);
88444 rdp->qlen_lazy = 0;
88445 - ACCESS_ONCE(rdp->qlen) = 0;
88446 + ACCESS_ONCE_RW(rdp->qlen) = 0;
88447 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
88448 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
88449 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
88450 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
88451 rdp->cpu = cpu;
88452 rdp->rsp = rsp;
88453 rcu_boot_init_nocb_percpu_data(rdp);
88454 @@ -3128,8 +3128,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
88455 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
88456 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
88457 rcu_sysidle_init_percpu_data(rdp->dynticks);
88458 - atomic_set(&rdp->dynticks->dynticks,
88459 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
88460 + atomic_set_unchecked(&rdp->dynticks->dynticks,
88461 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
88462 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
88463
88464 /* Add CPU to rcu_node bitmasks. */
88465 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
88466 index 8c19873..bf83c57 100644
88467 --- a/kernel/rcu/tree.h
88468 +++ b/kernel/rcu/tree.h
88469 @@ -87,11 +87,11 @@ struct rcu_dynticks {
88470 long long dynticks_nesting; /* Track irq/process nesting level. */
88471 /* Process level is worth LLONG_MAX/2. */
88472 int dynticks_nmi_nesting; /* Track NMI nesting level. */
88473 - atomic_t dynticks; /* Even value for idle, else odd. */
88474 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
88475 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
88476 long long dynticks_idle_nesting;
88477 /* irq/process nesting level from idle. */
88478 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
88479 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
88480 /* "Idle" excludes userspace execution. */
88481 unsigned long dynticks_idle_jiffies;
88482 /* End of last non-NMI non-idle period. */
88483 @@ -431,17 +431,17 @@ struct rcu_state {
88484 /* _rcu_barrier(). */
88485 /* End of fields guarded by barrier_mutex. */
88486
88487 - atomic_long_t expedited_start; /* Starting ticket. */
88488 - atomic_long_t expedited_done; /* Done ticket. */
88489 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
88490 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
88491 - atomic_long_t expedited_workdone1; /* # done by others #1. */
88492 - atomic_long_t expedited_workdone2; /* # done by others #2. */
88493 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
88494 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
88495 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
88496 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
88497 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
88498 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
88499 + atomic_long_t expedited_done; /* Done ticket. */
88500 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
88501 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
88502 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
88503 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
88504 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
88505 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
88506 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
88507 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
88508 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
88509
88510 unsigned long jiffies_force_qs; /* Time at which to invoke */
88511 /* force_quiescent_state(). */
88512 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
88513 index 6e2ef4b..c15df94 100644
88514 --- a/kernel/rcu/tree_plugin.h
88515 +++ b/kernel/rcu/tree_plugin.h
88516 @@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
88517 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
88518 {
88519 return !rcu_preempted_readers_exp(rnp) &&
88520 - ACCESS_ONCE(rnp->expmask) == 0;
88521 + ACCESS_ONCE_RW(rnp->expmask) == 0;
88522 }
88523
88524 /*
88525 @@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
88526
88527 /* Clean up and exit. */
88528 smp_mb(); /* ensure expedited GP seen before counter increment. */
88529 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
88530 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
88531 unlock_mb_ret:
88532 mutex_unlock(&sync_rcu_preempt_exp_mutex);
88533 mb_ret:
88534 @@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
88535 free_cpumask_var(cm);
88536 }
88537
88538 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
88539 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
88540 .store = &rcu_cpu_kthread_task,
88541 .thread_should_run = rcu_cpu_kthread_should_run,
88542 .thread_fn = rcu_cpu_kthread,
88543 @@ -1965,7 +1965,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
88544 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
88545 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
88546 cpu, ticks_value, ticks_title,
88547 - atomic_read(&rdtp->dynticks) & 0xfff,
88548 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
88549 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
88550 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
88551 fast_no_hz);
88552 @@ -2129,7 +2129,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
88553
88554 /* Enqueue the callback on the nocb list and update counts. */
88555 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
88556 - ACCESS_ONCE(*old_rhpp) = rhp;
88557 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
88558 atomic_long_add(rhcount, &rdp->nocb_q_count);
88559 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
88560
88561 @@ -2302,12 +2302,12 @@ static int rcu_nocb_kthread(void *arg)
88562 * Extract queued callbacks, update counts, and wait
88563 * for a grace period to elapse.
88564 */
88565 - ACCESS_ONCE(rdp->nocb_head) = NULL;
88566 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
88567 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
88568 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
88569 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
88570 - ACCESS_ONCE(rdp->nocb_p_count) += c;
88571 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
88572 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
88573 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
88574 rcu_nocb_wait_gp(rdp);
88575
88576 /* Each pass through the following loop invokes a callback. */
88577 @@ -2333,8 +2333,8 @@ static int rcu_nocb_kthread(void *arg)
88578 list = next;
88579 }
88580 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
88581 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
88582 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
88583 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
88584 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
88585 rdp->n_nocbs_invoked += c;
88586 }
88587 return 0;
88588 @@ -2351,7 +2351,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
88589 {
88590 if (!rcu_nocb_need_deferred_wakeup(rdp))
88591 return;
88592 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
88593 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
88594 wake_up(&rdp->nocb_wq);
88595 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
88596 }
88597 @@ -2377,7 +2377,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
88598 t = kthread_run(rcu_nocb_kthread, rdp,
88599 "rcuo%c/%d", rsp->abbr, cpu);
88600 BUG_ON(IS_ERR(t));
88601 - ACCESS_ONCE(rdp->nocb_kthread) = t;
88602 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
88603 }
88604 }
88605
88606 @@ -2513,11 +2513,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
88607
88608 /* Record start of fully idle period. */
88609 j = jiffies;
88610 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
88611 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
88612 smp_mb__before_atomic_inc();
88613 - atomic_inc(&rdtp->dynticks_idle);
88614 + atomic_inc_unchecked(&rdtp->dynticks_idle);
88615 smp_mb__after_atomic_inc();
88616 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
88617 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
88618 }
88619
88620 /*
88621 @@ -2582,9 +2582,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
88622
88623 /* Record end of idle period. */
88624 smp_mb__before_atomic_inc();
88625 - atomic_inc(&rdtp->dynticks_idle);
88626 + atomic_inc_unchecked(&rdtp->dynticks_idle);
88627 smp_mb__after_atomic_inc();
88628 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
88629 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
88630
88631 /*
88632 * If we are the timekeeping CPU, we are permitted to be non-idle
88633 @@ -2625,7 +2625,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
88634 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
88635
88636 /* Pick up current idle and NMI-nesting counter and check. */
88637 - cur = atomic_read(&rdtp->dynticks_idle);
88638 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
88639 if (cur & 0x1) {
88640 *isidle = false; /* We are not idle! */
88641 return;
88642 @@ -2688,7 +2688,7 @@ static void rcu_sysidle(unsigned long j)
88643 case RCU_SYSIDLE_NOT:
88644
88645 /* First time all are idle, so note a short idle period. */
88646 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88647 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88648 break;
88649
88650 case RCU_SYSIDLE_SHORT:
88651 @@ -2725,7 +2725,7 @@ static void rcu_sysidle(unsigned long j)
88652 static void rcu_sysidle_cancel(void)
88653 {
88654 smp_mb();
88655 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
88656 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
88657 }
88658
88659 /*
88660 @@ -2773,7 +2773,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
88661 smp_mb(); /* grace period precedes setting inuse. */
88662
88663 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
88664 - ACCESS_ONCE(rshp->inuse) = 0;
88665 + ACCESS_ONCE_RW(rshp->inuse) = 0;
88666 }
88667
88668 /*
88669 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
88670 index 4def475..8ffddde 100644
88671 --- a/kernel/rcu/tree_trace.c
88672 +++ b/kernel/rcu/tree_trace.c
88673 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
88674 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
88675 rdp->passed_quiesce, rdp->qs_pending);
88676 seq_printf(m, " dt=%d/%llx/%d df=%lu",
88677 - atomic_read(&rdp->dynticks->dynticks),
88678 + atomic_read_unchecked(&rdp->dynticks->dynticks),
88679 rdp->dynticks->dynticks_nesting,
88680 rdp->dynticks->dynticks_nmi_nesting,
88681 rdp->dynticks_fqs);
88682 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
88683 struct rcu_state *rsp = (struct rcu_state *)m->private;
88684
88685 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",
88686 - atomic_long_read(&rsp->expedited_start),
88687 + atomic_long_read_unchecked(&rsp->expedited_start),
88688 atomic_long_read(&rsp->expedited_done),
88689 - atomic_long_read(&rsp->expedited_wrap),
88690 - atomic_long_read(&rsp->expedited_tryfail),
88691 - atomic_long_read(&rsp->expedited_workdone1),
88692 - atomic_long_read(&rsp->expedited_workdone2),
88693 - atomic_long_read(&rsp->expedited_normal),
88694 - atomic_long_read(&rsp->expedited_stoppedcpus),
88695 - atomic_long_read(&rsp->expedited_done_tries),
88696 - atomic_long_read(&rsp->expedited_done_lost),
88697 - atomic_long_read(&rsp->expedited_done_exit));
88698 + atomic_long_read_unchecked(&rsp->expedited_wrap),
88699 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
88700 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
88701 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
88702 + atomic_long_read_unchecked(&rsp->expedited_normal),
88703 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
88704 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
88705 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
88706 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
88707 return 0;
88708 }
88709
88710 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
88711 index c54609f..2e8829c 100644
88712 --- a/kernel/rcu/update.c
88713 +++ b/kernel/rcu/update.c
88714 @@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
88715 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
88716 */
88717 if (till_stall_check < 3) {
88718 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
88719 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
88720 till_stall_check = 3;
88721 } else if (till_stall_check > 300) {
88722 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
88723 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
88724 till_stall_check = 300;
88725 }
88726 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
88727 diff --git a/kernel/resource.c b/kernel/resource.c
88728 index 3f285dc..5755f62 100644
88729 --- a/kernel/resource.c
88730 +++ b/kernel/resource.c
88731 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
88732
88733 static int __init ioresources_init(void)
88734 {
88735 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
88736 +#ifdef CONFIG_GRKERNSEC_PROC_USER
88737 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
88738 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
88739 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88740 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
88741 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
88742 +#endif
88743 +#else
88744 proc_create("ioports", 0, NULL, &proc_ioports_operations);
88745 proc_create("iomem", 0, NULL, &proc_iomem_operations);
88746 +#endif
88747 return 0;
88748 }
88749 __initcall(ioresources_init);
88750 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
88751 index 4a07353..66b5291 100644
88752 --- a/kernel/sched/auto_group.c
88753 +++ b/kernel/sched/auto_group.c
88754 @@ -11,7 +11,7 @@
88755
88756 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
88757 static struct autogroup autogroup_default;
88758 -static atomic_t autogroup_seq_nr;
88759 +static atomic_unchecked_t autogroup_seq_nr;
88760
88761 void __init autogroup_init(struct task_struct *init_task)
88762 {
88763 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
88764
88765 kref_init(&ag->kref);
88766 init_rwsem(&ag->lock);
88767 - ag->id = atomic_inc_return(&autogroup_seq_nr);
88768 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
88769 ag->tg = tg;
88770 #ifdef CONFIG_RT_GROUP_SCHED
88771 /*
88772 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
88773 index a63f4dc..349bbb0 100644
88774 --- a/kernel/sched/completion.c
88775 +++ b/kernel/sched/completion.c
88776 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
88777 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
88778 * or number of jiffies left till timeout) if completed.
88779 */
88780 -long __sched
88781 +long __sched __intentional_overflow(-1)
88782 wait_for_completion_interruptible_timeout(struct completion *x,
88783 unsigned long timeout)
88784 {
88785 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
88786 *
88787 * Return: -ERESTARTSYS if interrupted, 0 if completed.
88788 */
88789 -int __sched wait_for_completion_killable(struct completion *x)
88790 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
88791 {
88792 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
88793 if (t == -ERESTARTSYS)
88794 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
88795 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
88796 * or number of jiffies left till timeout) if completed.
88797 */
88798 -long __sched
88799 +long __sched __intentional_overflow(-1)
88800 wait_for_completion_killable_timeout(struct completion *x,
88801 unsigned long timeout)
88802 {
88803 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
88804 index f5c6635..ab9f223 100644
88805 --- a/kernel/sched/core.c
88806 +++ b/kernel/sched/core.c
88807 @@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
88808 int sysctl_numa_balancing(struct ctl_table *table, int write,
88809 void __user *buffer, size_t *lenp, loff_t *ppos)
88810 {
88811 - struct ctl_table t;
88812 + ctl_table_no_const t;
88813 int err;
88814 int state = numabalancing_enabled;
88815
88816 @@ -3049,6 +3049,8 @@ int can_nice(const struct task_struct *p, const int nice)
88817 /* convert nice value [19,-20] to rlimit style value [1,40] */
88818 int nice_rlim = 20 - nice;
88819
88820 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
88821 +
88822 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
88823 capable(CAP_SYS_NICE));
88824 }
88825 @@ -3082,7 +3084,8 @@ SYSCALL_DEFINE1(nice, int, increment)
88826 if (nice > 19)
88827 nice = 19;
88828
88829 - if (increment < 0 && !can_nice(current, nice))
88830 + if (increment < 0 && (!can_nice(current, nice) ||
88831 + gr_handle_chroot_nice()))
88832 return -EPERM;
88833
88834 retval = security_task_setnice(current, nice);
88835 @@ -3332,6 +3335,7 @@ recheck:
88836 if (policy != p->policy && !rlim_rtprio)
88837 return -EPERM;
88838
88839 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
88840 /* can't increase priority */
88841 if (attr->sched_priority > p->rt_priority &&
88842 attr->sched_priority > rlim_rtprio)
88843 @@ -4781,7 +4785,7 @@ static void migrate_tasks(unsigned int dead_cpu)
88844
88845 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
88846
88847 -static struct ctl_table sd_ctl_dir[] = {
88848 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
88849 {
88850 .procname = "sched_domain",
88851 .mode = 0555,
88852 @@ -4798,17 +4802,17 @@ static struct ctl_table sd_ctl_root[] = {
88853 {}
88854 };
88855
88856 -static struct ctl_table *sd_alloc_ctl_entry(int n)
88857 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
88858 {
88859 - struct ctl_table *entry =
88860 + ctl_table_no_const *entry =
88861 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
88862
88863 return entry;
88864 }
88865
88866 -static void sd_free_ctl_entry(struct ctl_table **tablep)
88867 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
88868 {
88869 - struct ctl_table *entry;
88870 + ctl_table_no_const *entry;
88871
88872 /*
88873 * In the intermediate directories, both the child directory and
88874 @@ -4816,22 +4820,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
88875 * will always be set. In the lowest directory the names are
88876 * static strings and all have proc handlers.
88877 */
88878 - for (entry = *tablep; entry->mode; entry++) {
88879 - if (entry->child)
88880 - sd_free_ctl_entry(&entry->child);
88881 + for (entry = tablep; entry->mode; entry++) {
88882 + if (entry->child) {
88883 + sd_free_ctl_entry(entry->child);
88884 + pax_open_kernel();
88885 + entry->child = NULL;
88886 + pax_close_kernel();
88887 + }
88888 if (entry->proc_handler == NULL)
88889 kfree(entry->procname);
88890 }
88891
88892 - kfree(*tablep);
88893 - *tablep = NULL;
88894 + kfree(tablep);
88895 }
88896
88897 static int min_load_idx = 0;
88898 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
88899
88900 static void
88901 -set_table_entry(struct ctl_table *entry,
88902 +set_table_entry(ctl_table_no_const *entry,
88903 const char *procname, void *data, int maxlen,
88904 umode_t mode, proc_handler *proc_handler,
88905 bool load_idx)
88906 @@ -4851,7 +4858,7 @@ set_table_entry(struct ctl_table *entry,
88907 static struct ctl_table *
88908 sd_alloc_ctl_domain_table(struct sched_domain *sd)
88909 {
88910 - struct ctl_table *table = sd_alloc_ctl_entry(13);
88911 + ctl_table_no_const *table = sd_alloc_ctl_entry(13);
88912
88913 if (table == NULL)
88914 return NULL;
88915 @@ -4886,9 +4893,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
88916 return table;
88917 }
88918
88919 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
88920 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
88921 {
88922 - struct ctl_table *entry, *table;
88923 + ctl_table_no_const *entry, *table;
88924 struct sched_domain *sd;
88925 int domain_num = 0, i;
88926 char buf[32];
88927 @@ -4915,11 +4922,13 @@ static struct ctl_table_header *sd_sysctl_header;
88928 static void register_sched_domain_sysctl(void)
88929 {
88930 int i, cpu_num = num_possible_cpus();
88931 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
88932 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
88933 char buf[32];
88934
88935 WARN_ON(sd_ctl_dir[0].child);
88936 + pax_open_kernel();
88937 sd_ctl_dir[0].child = entry;
88938 + pax_close_kernel();
88939
88940 if (entry == NULL)
88941 return;
88942 @@ -4942,8 +4951,12 @@ static void unregister_sched_domain_sysctl(void)
88943 if (sd_sysctl_header)
88944 unregister_sysctl_table(sd_sysctl_header);
88945 sd_sysctl_header = NULL;
88946 - if (sd_ctl_dir[0].child)
88947 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
88948 + if (sd_ctl_dir[0].child) {
88949 + sd_free_ctl_entry(sd_ctl_dir[0].child);
88950 + pax_open_kernel();
88951 + sd_ctl_dir[0].child = NULL;
88952 + pax_close_kernel();
88953 + }
88954 }
88955 #else
88956 static void register_sched_domain_sysctl(void)
88957 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
88958 index 9b4c4f3..665489b 100644
88959 --- a/kernel/sched/fair.c
88960 +++ b/kernel/sched/fair.c
88961 @@ -1647,7 +1647,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
88962
88963 static void reset_ptenuma_scan(struct task_struct *p)
88964 {
88965 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
88966 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
88967 p->mm->numa_scan_offset = 0;
88968 }
88969
88970 @@ -6851,7 +6851,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
88971 * run_rebalance_domains is triggered when needed from the scheduler tick.
88972 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
88973 */
88974 -static void run_rebalance_domains(struct softirq_action *h)
88975 +static __latent_entropy void run_rebalance_domains(void)
88976 {
88977 struct rq *this_rq = this_rq();
88978 enum cpu_idle_type idle = this_rq->idle_balance ?
88979 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
88980 index f964add..dcd823d 100644
88981 --- a/kernel/sched/sched.h
88982 +++ b/kernel/sched/sched.h
88983 @@ -1157,7 +1157,7 @@ struct sched_class {
88984 #ifdef CONFIG_FAIR_GROUP_SCHED
88985 void (*task_move_group) (struct task_struct *p, int on_rq);
88986 #endif
88987 -};
88988 +} __do_const;
88989
88990 #define sched_class_highest (&stop_sched_class)
88991 #define for_each_class(class) \
88992 diff --git a/kernel/signal.c b/kernel/signal.c
88993 index 52f881d..1e9f941 100644
88994 --- a/kernel/signal.c
88995 +++ b/kernel/signal.c
88996 @@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
88997
88998 int print_fatal_signals __read_mostly;
88999
89000 -static void __user *sig_handler(struct task_struct *t, int sig)
89001 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
89002 {
89003 return t->sighand->action[sig - 1].sa.sa_handler;
89004 }
89005
89006 -static int sig_handler_ignored(void __user *handler, int sig)
89007 +static int sig_handler_ignored(__sighandler_t handler, int sig)
89008 {
89009 /* Is it explicitly or implicitly ignored? */
89010 return handler == SIG_IGN ||
89011 @@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
89012
89013 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
89014 {
89015 - void __user *handler;
89016 + __sighandler_t handler;
89017
89018 handler = sig_handler(t, sig);
89019
89020 @@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
89021 atomic_inc(&user->sigpending);
89022 rcu_read_unlock();
89023
89024 + if (!override_rlimit)
89025 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
89026 +
89027 if (override_rlimit ||
89028 atomic_read(&user->sigpending) <=
89029 task_rlimit(t, RLIMIT_SIGPENDING)) {
89030 @@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
89031
89032 int unhandled_signal(struct task_struct *tsk, int sig)
89033 {
89034 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
89035 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
89036 if (is_global_init(tsk))
89037 return 1;
89038 if (handler != SIG_IGN && handler != SIG_DFL)
89039 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
89040 }
89041 }
89042
89043 + /* allow glibc communication via tgkill to other threads in our
89044 + thread group */
89045 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
89046 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
89047 + && gr_handle_signal(t, sig))
89048 + return -EPERM;
89049 +
89050 return security_task_kill(t, info, sig, 0);
89051 }
89052
89053 @@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89054 return send_signal(sig, info, p, 1);
89055 }
89056
89057 -static int
89058 +int
89059 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89060 {
89061 return send_signal(sig, info, t, 0);
89062 @@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89063 unsigned long int flags;
89064 int ret, blocked, ignored;
89065 struct k_sigaction *action;
89066 + int is_unhandled = 0;
89067
89068 spin_lock_irqsave(&t->sighand->siglock, flags);
89069 action = &t->sighand->action[sig-1];
89070 @@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89071 }
89072 if (action->sa.sa_handler == SIG_DFL)
89073 t->signal->flags &= ~SIGNAL_UNKILLABLE;
89074 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
89075 + is_unhandled = 1;
89076 ret = specific_send_sig_info(sig, info, t);
89077 spin_unlock_irqrestore(&t->sighand->siglock, flags);
89078
89079 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
89080 + normal operation */
89081 + if (is_unhandled) {
89082 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
89083 + gr_handle_crash(t, sig);
89084 + }
89085 +
89086 return ret;
89087 }
89088
89089 @@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89090 ret = check_kill_permission(sig, info, p);
89091 rcu_read_unlock();
89092
89093 - if (!ret && sig)
89094 + if (!ret && sig) {
89095 ret = do_send_sig_info(sig, info, p, true);
89096 + if (!ret)
89097 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
89098 + }
89099
89100 return ret;
89101 }
89102 @@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
89103 int error = -ESRCH;
89104
89105 rcu_read_lock();
89106 - p = find_task_by_vpid(pid);
89107 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
89108 + /* allow glibc communication via tgkill to other threads in our
89109 + thread group */
89110 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
89111 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
89112 + p = find_task_by_vpid_unrestricted(pid);
89113 + else
89114 +#endif
89115 + p = find_task_by_vpid(pid);
89116 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
89117 error = check_kill_permission(sig, info, p);
89118 /*
89119 @@ -3239,8 +3270,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
89120 }
89121 seg = get_fs();
89122 set_fs(KERNEL_DS);
89123 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
89124 - (stack_t __force __user *) &uoss,
89125 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
89126 + (stack_t __force_user *) &uoss,
89127 compat_user_stack_pointer());
89128 set_fs(seg);
89129 if (ret >= 0 && uoss_ptr) {
89130 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
89131 index eb89e18..a4e6792 100644
89132 --- a/kernel/smpboot.c
89133 +++ b/kernel/smpboot.c
89134 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
89135 }
89136 smpboot_unpark_thread(plug_thread, cpu);
89137 }
89138 - list_add(&plug_thread->list, &hotplug_threads);
89139 + pax_list_add(&plug_thread->list, &hotplug_threads);
89140 out:
89141 mutex_unlock(&smpboot_threads_lock);
89142 return ret;
89143 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
89144 {
89145 get_online_cpus();
89146 mutex_lock(&smpboot_threads_lock);
89147 - list_del(&plug_thread->list);
89148 + pax_list_del(&plug_thread->list);
89149 smpboot_destroy_threads(plug_thread);
89150 mutex_unlock(&smpboot_threads_lock);
89151 put_online_cpus();
89152 diff --git a/kernel/softirq.c b/kernel/softirq.c
89153 index 490fcbb..1e502c6 100644
89154 --- a/kernel/softirq.c
89155 +++ b/kernel/softirq.c
89156 @@ -52,7 +52,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
89157 EXPORT_SYMBOL(irq_stat);
89158 #endif
89159
89160 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
89161 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
89162
89163 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
89164
89165 @@ -267,7 +267,7 @@ restart:
89166 kstat_incr_softirqs_this_cpu(vec_nr);
89167
89168 trace_softirq_entry(vec_nr);
89169 - h->action(h);
89170 + h->action();
89171 trace_softirq_exit(vec_nr);
89172 if (unlikely(prev_count != preempt_count())) {
89173 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
89174 @@ -427,7 +427,7 @@ void __raise_softirq_irqoff(unsigned int nr)
89175 or_softirq_pending(1UL << nr);
89176 }
89177
89178 -void open_softirq(int nr, void (*action)(struct softirq_action *))
89179 +void __init open_softirq(int nr, void (*action)(void))
89180 {
89181 softirq_vec[nr].action = action;
89182 }
89183 @@ -479,7 +479,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
89184 }
89185 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
89186
89187 -static void tasklet_action(struct softirq_action *a)
89188 +static void tasklet_action(void)
89189 {
89190 struct tasklet_struct *list;
89191
89192 @@ -515,7 +515,7 @@ static void tasklet_action(struct softirq_action *a)
89193 }
89194 }
89195
89196 -static void tasklet_hi_action(struct softirq_action *a)
89197 +static __latent_entropy void tasklet_hi_action(void)
89198 {
89199 struct tasklet_struct *list;
89200
89201 @@ -742,7 +742,7 @@ static struct notifier_block cpu_nfb = {
89202 .notifier_call = cpu_callback
89203 };
89204
89205 -static struct smp_hotplug_thread softirq_threads = {
89206 +static struct smp_hotplug_thread softirq_threads __read_only = {
89207 .store = &ksoftirqd,
89208 .thread_should_run = ksoftirqd_should_run,
89209 .thread_fn = run_ksoftirqd,
89210 diff --git a/kernel/sys.c b/kernel/sys.c
89211 index c0a58be..784c618 100644
89212 --- a/kernel/sys.c
89213 +++ b/kernel/sys.c
89214 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
89215 error = -EACCES;
89216 goto out;
89217 }
89218 +
89219 + if (gr_handle_chroot_setpriority(p, niceval)) {
89220 + error = -EACCES;
89221 + goto out;
89222 + }
89223 +
89224 no_nice = security_task_setnice(p, niceval);
89225 if (no_nice) {
89226 error = no_nice;
89227 @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
89228 goto error;
89229 }
89230
89231 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
89232 + goto error;
89233 +
89234 if (rgid != (gid_t) -1 ||
89235 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
89236 new->sgid = new->egid;
89237 @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
89238 old = current_cred();
89239
89240 retval = -EPERM;
89241 +
89242 + if (gr_check_group_change(kgid, kgid, kgid))
89243 + goto error;
89244 +
89245 if (ns_capable(old->user_ns, CAP_SETGID))
89246 new->gid = new->egid = new->sgid = new->fsgid = kgid;
89247 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
89248 @@ -403,7 +416,7 @@ error:
89249 /*
89250 * change the user struct in a credentials set to match the new UID
89251 */
89252 -static int set_user(struct cred *new)
89253 +int set_user(struct cred *new)
89254 {
89255 struct user_struct *new_user;
89256
89257 @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
89258 goto error;
89259 }
89260
89261 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
89262 + goto error;
89263 +
89264 if (!uid_eq(new->uid, old->uid)) {
89265 retval = set_user(new);
89266 if (retval < 0)
89267 @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
89268 old = current_cred();
89269
89270 retval = -EPERM;
89271 +
89272 + if (gr_check_crash_uid(kuid))
89273 + goto error;
89274 + if (gr_check_user_change(kuid, kuid, kuid))
89275 + goto error;
89276 +
89277 if (ns_capable(old->user_ns, CAP_SETUID)) {
89278 new->suid = new->uid = kuid;
89279 if (!uid_eq(kuid, old->uid)) {
89280 @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
89281 goto error;
89282 }
89283
89284 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
89285 + goto error;
89286 +
89287 if (ruid != (uid_t) -1) {
89288 new->uid = kruid;
89289 if (!uid_eq(kruid, old->uid)) {
89290 @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
89291 goto error;
89292 }
89293
89294 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
89295 + goto error;
89296 +
89297 if (rgid != (gid_t) -1)
89298 new->gid = krgid;
89299 if (egid != (gid_t) -1)
89300 @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
89301 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
89302 ns_capable(old->user_ns, CAP_SETUID)) {
89303 if (!uid_eq(kuid, old->fsuid)) {
89304 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
89305 + goto error;
89306 +
89307 new->fsuid = kuid;
89308 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
89309 goto change_okay;
89310 }
89311 }
89312
89313 +error:
89314 abort_creds(new);
89315 return old_fsuid;
89316
89317 @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
89318 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
89319 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
89320 ns_capable(old->user_ns, CAP_SETGID)) {
89321 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
89322 + goto error;
89323 +
89324 if (!gid_eq(kgid, old->fsgid)) {
89325 new->fsgid = kgid;
89326 goto change_okay;
89327 }
89328 }
89329
89330 +error:
89331 abort_creds(new);
89332 return old_fsgid;
89333
89334 @@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
89335 return -EFAULT;
89336
89337 down_read(&uts_sem);
89338 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
89339 + error = __copy_to_user(name->sysname, &utsname()->sysname,
89340 __OLD_UTS_LEN);
89341 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
89342 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
89343 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
89344 __OLD_UTS_LEN);
89345 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
89346 - error |= __copy_to_user(&name->release, &utsname()->release,
89347 + error |= __copy_to_user(name->release, &utsname()->release,
89348 __OLD_UTS_LEN);
89349 error |= __put_user(0, name->release + __OLD_UTS_LEN);
89350 - error |= __copy_to_user(&name->version, &utsname()->version,
89351 + error |= __copy_to_user(name->version, &utsname()->version,
89352 __OLD_UTS_LEN);
89353 error |= __put_user(0, name->version + __OLD_UTS_LEN);
89354 - error |= __copy_to_user(&name->machine, &utsname()->machine,
89355 + error |= __copy_to_user(name->machine, &utsname()->machine,
89356 __OLD_UTS_LEN);
89357 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
89358 up_read(&uts_sem);
89359 @@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
89360 */
89361 new_rlim->rlim_cur = 1;
89362 }
89363 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
89364 + is changed to a lower value. Since tasks can be created by the same
89365 + user in between this limit change and an execve by this task, force
89366 + a recheck only for this task by setting PF_NPROC_EXCEEDED
89367 + */
89368 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
89369 + tsk->flags |= PF_NPROC_EXCEEDED;
89370 }
89371 if (!retval) {
89372 if (old_rlim)
89373 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
89374 index 49e13e1..8dbc052 100644
89375 --- a/kernel/sysctl.c
89376 +++ b/kernel/sysctl.c
89377 @@ -94,7 +94,6 @@
89378
89379
89380 #if defined(CONFIG_SYSCTL)
89381 -
89382 /* External variables not in a header file. */
89383 extern int max_threads;
89384 extern int suid_dumpable;
89385 @@ -118,19 +117,18 @@ extern int blk_iopoll_enabled;
89386
89387 /* Constants used for minimum and maximum */
89388 #ifdef CONFIG_LOCKUP_DETECTOR
89389 -static int sixty = 60;
89390 +static int sixty __read_only = 60;
89391 #endif
89392
89393 -static int __maybe_unused neg_one = -1;
89394 -
89395 -static int zero;
89396 -static int __maybe_unused one = 1;
89397 -static int __maybe_unused two = 2;
89398 -static int __maybe_unused three = 3;
89399 -static unsigned long one_ul = 1;
89400 -static int one_hundred = 100;
89401 +static int __maybe_unused neg_one __read_only = -1;
89402 +static int zero __read_only = 0;
89403 +static int __maybe_unused one __read_only = 1;
89404 +static int __maybe_unused two __read_only = 2;
89405 +static int __maybe_unused three __read_only = 3;
89406 +static unsigned long one_ul __read_only = 1;
89407 +static int one_hundred __read_only = 100;
89408 #ifdef CONFIG_PRINTK
89409 -static int ten_thousand = 10000;
89410 +static int ten_thousand __read_only = 10000;
89411 #endif
89412
89413 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
89414 @@ -177,10 +175,8 @@ static int proc_taint(struct ctl_table *table, int write,
89415 void __user *buffer, size_t *lenp, loff_t *ppos);
89416 #endif
89417
89418 -#ifdef CONFIG_PRINTK
89419 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89420 void __user *buffer, size_t *lenp, loff_t *ppos);
89421 -#endif
89422
89423 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
89424 void __user *buffer, size_t *lenp, loff_t *ppos);
89425 @@ -211,6 +207,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
89426
89427 #endif
89428
89429 +extern struct ctl_table grsecurity_table[];
89430 +
89431 static struct ctl_table kern_table[];
89432 static struct ctl_table vm_table[];
89433 static struct ctl_table fs_table[];
89434 @@ -225,6 +223,20 @@ extern struct ctl_table epoll_table[];
89435 int sysctl_legacy_va_layout;
89436 #endif
89437
89438 +#ifdef CONFIG_PAX_SOFTMODE
89439 +static ctl_table pax_table[] = {
89440 + {
89441 + .procname = "softmode",
89442 + .data = &pax_softmode,
89443 + .maxlen = sizeof(unsigned int),
89444 + .mode = 0600,
89445 + .proc_handler = &proc_dointvec,
89446 + },
89447 +
89448 + { }
89449 +};
89450 +#endif
89451 +
89452 /* The default sysctl tables: */
89453
89454 static struct ctl_table sysctl_base_table[] = {
89455 @@ -273,6 +285,22 @@ static int max_extfrag_threshold = 1000;
89456 #endif
89457
89458 static struct ctl_table kern_table[] = {
89459 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
89460 + {
89461 + .procname = "grsecurity",
89462 + .mode = 0500,
89463 + .child = grsecurity_table,
89464 + },
89465 +#endif
89466 +
89467 +#ifdef CONFIG_PAX_SOFTMODE
89468 + {
89469 + .procname = "pax",
89470 + .mode = 0500,
89471 + .child = pax_table,
89472 + },
89473 +#endif
89474 +
89475 {
89476 .procname = "sched_child_runs_first",
89477 .data = &sysctl_sched_child_runs_first,
89478 @@ -635,7 +663,7 @@ static struct ctl_table kern_table[] = {
89479 .data = &modprobe_path,
89480 .maxlen = KMOD_PATH_LEN,
89481 .mode = 0644,
89482 - .proc_handler = proc_dostring,
89483 + .proc_handler = proc_dostring_modpriv,
89484 },
89485 {
89486 .procname = "modules_disabled",
89487 @@ -802,16 +830,20 @@ static struct ctl_table kern_table[] = {
89488 .extra1 = &zero,
89489 .extra2 = &one,
89490 },
89491 +#endif
89492 {
89493 .procname = "kptr_restrict",
89494 .data = &kptr_restrict,
89495 .maxlen = sizeof(int),
89496 .mode = 0644,
89497 .proc_handler = proc_dointvec_minmax_sysadmin,
89498 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89499 + .extra1 = &two,
89500 +#else
89501 .extra1 = &zero,
89502 +#endif
89503 .extra2 = &two,
89504 },
89505 -#endif
89506 {
89507 .procname = "ngroups_max",
89508 .data = &ngroups_max,
89509 @@ -1055,10 +1087,17 @@ static struct ctl_table kern_table[] = {
89510 */
89511 {
89512 .procname = "perf_event_paranoid",
89513 - .data = &sysctl_perf_event_paranoid,
89514 - .maxlen = sizeof(sysctl_perf_event_paranoid),
89515 + .data = &sysctl_perf_event_legitimately_concerned,
89516 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
89517 .mode = 0644,
89518 - .proc_handler = proc_dointvec,
89519 + /* go ahead, be a hero */
89520 + .proc_handler = proc_dointvec_minmax_sysadmin,
89521 + .extra1 = &neg_one,
89522 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89523 + .extra2 = &three,
89524 +#else
89525 + .extra2 = &two,
89526 +#endif
89527 },
89528 {
89529 .procname = "perf_event_mlock_kb",
89530 @@ -1329,6 +1368,13 @@ static struct ctl_table vm_table[] = {
89531 .proc_handler = proc_dointvec_minmax,
89532 .extra1 = &zero,
89533 },
89534 + {
89535 + .procname = "heap_stack_gap",
89536 + .data = &sysctl_heap_stack_gap,
89537 + .maxlen = sizeof(sysctl_heap_stack_gap),
89538 + .mode = 0644,
89539 + .proc_handler = proc_doulongvec_minmax,
89540 + },
89541 #else
89542 {
89543 .procname = "nr_trim_pages",
89544 @@ -1793,6 +1839,16 @@ int proc_dostring(struct ctl_table *table, int write,
89545 buffer, lenp, ppos);
89546 }
89547
89548 +int proc_dostring_modpriv(struct ctl_table *table, int write,
89549 + void __user *buffer, size_t *lenp, loff_t *ppos)
89550 +{
89551 + if (write && !capable(CAP_SYS_MODULE))
89552 + return -EPERM;
89553 +
89554 + return _proc_do_string(table->data, table->maxlen, write,
89555 + buffer, lenp, ppos);
89556 +}
89557 +
89558 static size_t proc_skip_spaces(char **buf)
89559 {
89560 size_t ret;
89561 @@ -1898,6 +1954,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
89562 len = strlen(tmp);
89563 if (len > *size)
89564 len = *size;
89565 + if (len > sizeof(tmp))
89566 + len = sizeof(tmp);
89567 if (copy_to_user(*buf, tmp, len))
89568 return -EFAULT;
89569 *size -= len;
89570 @@ -2062,7 +2120,7 @@ int proc_dointvec(struct ctl_table *table, int write,
89571 static int proc_taint(struct ctl_table *table, int write,
89572 void __user *buffer, size_t *lenp, loff_t *ppos)
89573 {
89574 - struct ctl_table t;
89575 + ctl_table_no_const t;
89576 unsigned long tmptaint = get_taint();
89577 int err;
89578
89579 @@ -2090,7 +2148,6 @@ static int proc_taint(struct ctl_table *table, int write,
89580 return err;
89581 }
89582
89583 -#ifdef CONFIG_PRINTK
89584 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89585 void __user *buffer, size_t *lenp, loff_t *ppos)
89586 {
89587 @@ -2099,7 +2156,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89588
89589 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
89590 }
89591 -#endif
89592
89593 struct do_proc_dointvec_minmax_conv_param {
89594 int *min;
89595 @@ -2646,6 +2702,12 @@ int proc_dostring(struct ctl_table *table, int write,
89596 return -ENOSYS;
89597 }
89598
89599 +int proc_dostring_modpriv(struct ctl_table *table, int write,
89600 + void __user *buffer, size_t *lenp, loff_t *ppos)
89601 +{
89602 + return -ENOSYS;
89603 +}
89604 +
89605 int proc_dointvec(struct ctl_table *table, int write,
89606 void __user *buffer, size_t *lenp, loff_t *ppos)
89607 {
89608 @@ -2702,5 +2764,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
89609 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
89610 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
89611 EXPORT_SYMBOL(proc_dostring);
89612 +EXPORT_SYMBOL(proc_dostring_modpriv);
89613 EXPORT_SYMBOL(proc_doulongvec_minmax);
89614 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
89615 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
89616 index 13d2f7c..c93d0b0 100644
89617 --- a/kernel/taskstats.c
89618 +++ b/kernel/taskstats.c
89619 @@ -28,9 +28,12 @@
89620 #include <linux/fs.h>
89621 #include <linux/file.h>
89622 #include <linux/pid_namespace.h>
89623 +#include <linux/grsecurity.h>
89624 #include <net/genetlink.h>
89625 #include <linux/atomic.h>
89626
89627 +extern int gr_is_taskstats_denied(int pid);
89628 +
89629 /*
89630 * Maximum length of a cpumask that can be specified in
89631 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
89632 @@ -576,6 +579,9 @@ err:
89633
89634 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
89635 {
89636 + if (gr_is_taskstats_denied(current->pid))
89637 + return -EACCES;
89638 +
89639 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
89640 return cmd_attr_register_cpumask(info);
89641 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
89642 diff --git a/kernel/time.c b/kernel/time.c
89643 index 7c7964c..2a0d412 100644
89644 --- a/kernel/time.c
89645 +++ b/kernel/time.c
89646 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
89647 return error;
89648
89649 if (tz) {
89650 + /* we log in do_settimeofday called below, so don't log twice
89651 + */
89652 + if (!tv)
89653 + gr_log_timechange();
89654 +
89655 sys_tz = *tz;
89656 update_vsyscall_tz();
89657 if (firsttime) {
89658 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
89659 index 88c9c65..7497ebc 100644
89660 --- a/kernel/time/alarmtimer.c
89661 +++ b/kernel/time/alarmtimer.c
89662 @@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
89663 struct platform_device *pdev;
89664 int error = 0;
89665 int i;
89666 - struct k_clock alarm_clock = {
89667 + static struct k_clock alarm_clock = {
89668 .clock_getres = alarm_clock_getres,
89669 .clock_get = alarm_clock_get,
89670 .timer_create = alarm_timer_create,
89671 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
89672 index 5b40279..81e58db 100644
89673 --- a/kernel/time/timekeeping.c
89674 +++ b/kernel/time/timekeeping.c
89675 @@ -15,6 +15,7 @@
89676 #include <linux/init.h>
89677 #include <linux/mm.h>
89678 #include <linux/sched.h>
89679 +#include <linux/grsecurity.h>
89680 #include <linux/syscore_ops.h>
89681 #include <linux/clocksource.h>
89682 #include <linux/jiffies.h>
89683 @@ -501,6 +502,8 @@ int do_settimeofday(const struct timespec *tv)
89684 if (!timespec_valid_strict(tv))
89685 return -EINVAL;
89686
89687 + gr_log_timechange();
89688 +
89689 raw_spin_lock_irqsave(&timekeeper_lock, flags);
89690 write_seqcount_begin(&timekeeper_seq);
89691
89692 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
89693 index 61ed862..3b52c65 100644
89694 --- a/kernel/time/timer_list.c
89695 +++ b/kernel/time/timer_list.c
89696 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
89697
89698 static void print_name_offset(struct seq_file *m, void *sym)
89699 {
89700 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89701 + SEQ_printf(m, "<%p>", NULL);
89702 +#else
89703 char symname[KSYM_NAME_LEN];
89704
89705 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
89706 SEQ_printf(m, "<%pK>", sym);
89707 else
89708 SEQ_printf(m, "%s", symname);
89709 +#endif
89710 }
89711
89712 static void
89713 @@ -119,7 +123,11 @@ next_one:
89714 static void
89715 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
89716 {
89717 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89718 + SEQ_printf(m, " .base: %p\n", NULL);
89719 +#else
89720 SEQ_printf(m, " .base: %pK\n", base);
89721 +#endif
89722 SEQ_printf(m, " .index: %d\n",
89723 base->index);
89724 SEQ_printf(m, " .resolution: %Lu nsecs\n",
89725 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
89726 {
89727 struct proc_dir_entry *pe;
89728
89729 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
89730 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
89731 +#else
89732 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
89733 +#endif
89734 if (!pe)
89735 return -ENOMEM;
89736 return 0;
89737 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
89738 index 1fb08f2..ca4bb1e 100644
89739 --- a/kernel/time/timer_stats.c
89740 +++ b/kernel/time/timer_stats.c
89741 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
89742 static unsigned long nr_entries;
89743 static struct entry entries[MAX_ENTRIES];
89744
89745 -static atomic_t overflow_count;
89746 +static atomic_unchecked_t overflow_count;
89747
89748 /*
89749 * The entries are in a hash-table, for fast lookup:
89750 @@ -140,7 +140,7 @@ static void reset_entries(void)
89751 nr_entries = 0;
89752 memset(entries, 0, sizeof(entries));
89753 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
89754 - atomic_set(&overflow_count, 0);
89755 + atomic_set_unchecked(&overflow_count, 0);
89756 }
89757
89758 static struct entry *alloc_entry(void)
89759 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
89760 if (likely(entry))
89761 entry->count++;
89762 else
89763 - atomic_inc(&overflow_count);
89764 + atomic_inc_unchecked(&overflow_count);
89765
89766 out_unlock:
89767 raw_spin_unlock_irqrestore(lock, flags);
89768 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
89769
89770 static void print_name_offset(struct seq_file *m, unsigned long addr)
89771 {
89772 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89773 + seq_printf(m, "<%p>", NULL);
89774 +#else
89775 char symname[KSYM_NAME_LEN];
89776
89777 if (lookup_symbol_name(addr, symname) < 0)
89778 - seq_printf(m, "<%p>", (void *)addr);
89779 + seq_printf(m, "<%pK>", (void *)addr);
89780 else
89781 seq_printf(m, "%s", symname);
89782 +#endif
89783 }
89784
89785 static int tstats_show(struct seq_file *m, void *v)
89786 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
89787
89788 seq_puts(m, "Timer Stats Version: v0.3\n");
89789 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
89790 - if (atomic_read(&overflow_count))
89791 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
89792 + if (atomic_read_unchecked(&overflow_count))
89793 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
89794 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
89795
89796 for (i = 0; i < nr_entries; i++) {
89797 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
89798 {
89799 struct proc_dir_entry *pe;
89800
89801 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
89802 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
89803 +#else
89804 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
89805 +#endif
89806 if (!pe)
89807 return -ENOMEM;
89808 return 0;
89809 diff --git a/kernel/timer.c b/kernel/timer.c
89810 index accfd24..e00f0c0 100644
89811 --- a/kernel/timer.c
89812 +++ b/kernel/timer.c
89813 @@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
89814 /*
89815 * This function runs timers and the timer-tq in bottom half context.
89816 */
89817 -static void run_timer_softirq(struct softirq_action *h)
89818 +static __latent_entropy void run_timer_softirq(void)
89819 {
89820 struct tvec_base *base = __this_cpu_read(tvec_bases);
89821
89822 @@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
89823 *
89824 * In all cases the return value is guaranteed to be non-negative.
89825 */
89826 -signed long __sched schedule_timeout(signed long timeout)
89827 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
89828 {
89829 struct timer_list timer;
89830 unsigned long expire;
89831 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
89832 index b418cb0..f879a3d 100644
89833 --- a/kernel/trace/blktrace.c
89834 +++ b/kernel/trace/blktrace.c
89835 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
89836 struct blk_trace *bt = filp->private_data;
89837 char buf[16];
89838
89839 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
89840 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
89841
89842 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
89843 }
89844 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
89845 return 1;
89846
89847 bt = buf->chan->private_data;
89848 - atomic_inc(&bt->dropped);
89849 + atomic_inc_unchecked(&bt->dropped);
89850 return 0;
89851 }
89852
89853 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
89854
89855 bt->dir = dir;
89856 bt->dev = dev;
89857 - atomic_set(&bt->dropped, 0);
89858 + atomic_set_unchecked(&bt->dropped, 0);
89859 INIT_LIST_HEAD(&bt->running_list);
89860
89861 ret = -EIO;
89862 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
89863 index cd7f76d..553c805 100644
89864 --- a/kernel/trace/ftrace.c
89865 +++ b/kernel/trace/ftrace.c
89866 @@ -1965,12 +1965,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
89867 if (unlikely(ftrace_disabled))
89868 return 0;
89869
89870 + ret = ftrace_arch_code_modify_prepare();
89871 + FTRACE_WARN_ON(ret);
89872 + if (ret)
89873 + return 0;
89874 +
89875 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
89876 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
89877 if (ret) {
89878 ftrace_bug(ret, ip);
89879 - return 0;
89880 }
89881 - return 1;
89882 + return ret ? 0 : 1;
89883 }
89884
89885 /*
89886 @@ -4177,8 +4182,10 @@ static int ftrace_process_locs(struct module *mod,
89887 if (!count)
89888 return 0;
89889
89890 + pax_open_kernel();
89891 sort(start, count, sizeof(*start),
89892 ftrace_cmp_ips, ftrace_swap_ips);
89893 + pax_close_kernel();
89894
89895 start_pg = ftrace_allocate_pages(count);
89896 if (!start_pg)
89897 @@ -4909,8 +4916,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
89898 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
89899
89900 static int ftrace_graph_active;
89901 -static struct notifier_block ftrace_suspend_notifier;
89902 -
89903 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
89904 {
89905 return 0;
89906 @@ -5086,6 +5091,10 @@ static void update_function_graph_func(void)
89907 ftrace_graph_entry = ftrace_graph_entry_test;
89908 }
89909
89910 +static struct notifier_block ftrace_suspend_notifier = {
89911 + .notifier_call = ftrace_suspend_notifier_call
89912 +};
89913 +
89914 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
89915 trace_func_graph_ent_t entryfunc)
89916 {
89917 @@ -5099,7 +5108,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
89918 goto out;
89919 }
89920
89921 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
89922 register_pm_notifier(&ftrace_suspend_notifier);
89923
89924 ftrace_graph_active++;
89925 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
89926 index fc4da2d..f3e800b 100644
89927 --- a/kernel/trace/ring_buffer.c
89928 +++ b/kernel/trace/ring_buffer.c
89929 @@ -352,9 +352,9 @@ struct buffer_data_page {
89930 */
89931 struct buffer_page {
89932 struct list_head list; /* list of buffer pages */
89933 - local_t write; /* index for next write */
89934 + local_unchecked_t write; /* index for next write */
89935 unsigned read; /* index for next read */
89936 - local_t entries; /* entries on this page */
89937 + local_unchecked_t entries; /* entries on this page */
89938 unsigned long real_end; /* real end of data */
89939 struct buffer_data_page *page; /* Actual data page */
89940 };
89941 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
89942 unsigned long last_overrun;
89943 local_t entries_bytes;
89944 local_t entries;
89945 - local_t overrun;
89946 - local_t commit_overrun;
89947 + local_unchecked_t overrun;
89948 + local_unchecked_t commit_overrun;
89949 local_t dropped_events;
89950 local_t committing;
89951 local_t commits;
89952 @@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
89953 *
89954 * We add a counter to the write field to denote this.
89955 */
89956 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
89957 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
89958 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
89959 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
89960
89961 /*
89962 * Just make sure we have seen our old_write and synchronize
89963 @@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
89964 * cmpxchg to only update if an interrupt did not already
89965 * do it for us. If the cmpxchg fails, we don't care.
89966 */
89967 - (void)local_cmpxchg(&next_page->write, old_write, val);
89968 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
89969 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
89970 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
89971
89972 /*
89973 * No need to worry about races with clearing out the commit.
89974 @@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
89975
89976 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
89977 {
89978 - return local_read(&bpage->entries) & RB_WRITE_MASK;
89979 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
89980 }
89981
89982 static inline unsigned long rb_page_write(struct buffer_page *bpage)
89983 {
89984 - return local_read(&bpage->write) & RB_WRITE_MASK;
89985 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
89986 }
89987
89988 static int
89989 @@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
89990 * bytes consumed in ring buffer from here.
89991 * Increment overrun to account for the lost events.
89992 */
89993 - local_add(page_entries, &cpu_buffer->overrun);
89994 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
89995 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
89996 }
89997
89998 @@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
89999 * it is our responsibility to update
90000 * the counters.
90001 */
90002 - local_add(entries, &cpu_buffer->overrun);
90003 + local_add_unchecked(entries, &cpu_buffer->overrun);
90004 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90005
90006 /*
90007 @@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90008 if (tail == BUF_PAGE_SIZE)
90009 tail_page->real_end = 0;
90010
90011 - local_sub(length, &tail_page->write);
90012 + local_sub_unchecked(length, &tail_page->write);
90013 return;
90014 }
90015
90016 @@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90017 rb_event_set_padding(event);
90018
90019 /* Set the write back to the previous setting */
90020 - local_sub(length, &tail_page->write);
90021 + local_sub_unchecked(length, &tail_page->write);
90022 return;
90023 }
90024
90025 @@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90026
90027 /* Set write to end of buffer */
90028 length = (tail + length) - BUF_PAGE_SIZE;
90029 - local_sub(length, &tail_page->write);
90030 + local_sub_unchecked(length, &tail_page->write);
90031 }
90032
90033 /*
90034 @@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90035 * about it.
90036 */
90037 if (unlikely(next_page == commit_page)) {
90038 - local_inc(&cpu_buffer->commit_overrun);
90039 + local_inc_unchecked(&cpu_buffer->commit_overrun);
90040 goto out_reset;
90041 }
90042
90043 @@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90044 cpu_buffer->tail_page) &&
90045 (cpu_buffer->commit_page ==
90046 cpu_buffer->reader_page))) {
90047 - local_inc(&cpu_buffer->commit_overrun);
90048 + local_inc_unchecked(&cpu_buffer->commit_overrun);
90049 goto out_reset;
90050 }
90051 }
90052 @@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90053 length += RB_LEN_TIME_EXTEND;
90054
90055 tail_page = cpu_buffer->tail_page;
90056 - write = local_add_return(length, &tail_page->write);
90057 + write = local_add_return_unchecked(length, &tail_page->write);
90058
90059 /* set write to only the index of the write */
90060 write &= RB_WRITE_MASK;
90061 @@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90062 kmemcheck_annotate_bitfield(event, bitfield);
90063 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
90064
90065 - local_inc(&tail_page->entries);
90066 + local_inc_unchecked(&tail_page->entries);
90067
90068 /*
90069 * If this is the first commit on the page, then update
90070 @@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90071
90072 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
90073 unsigned long write_mask =
90074 - local_read(&bpage->write) & ~RB_WRITE_MASK;
90075 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
90076 unsigned long event_length = rb_event_length(event);
90077 /*
90078 * This is on the tail page. It is possible that
90079 @@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90080 */
90081 old_index += write_mask;
90082 new_index += write_mask;
90083 - index = local_cmpxchg(&bpage->write, old_index, new_index);
90084 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
90085 if (index == old_index) {
90086 /* update counters */
90087 local_sub(event_length, &cpu_buffer->entries_bytes);
90088 @@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90089
90090 /* Do the likely case first */
90091 if (likely(bpage->page == (void *)addr)) {
90092 - local_dec(&bpage->entries);
90093 + local_dec_unchecked(&bpage->entries);
90094 return;
90095 }
90096
90097 @@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90098 start = bpage;
90099 do {
90100 if (bpage->page == (void *)addr) {
90101 - local_dec(&bpage->entries);
90102 + local_dec_unchecked(&bpage->entries);
90103 return;
90104 }
90105 rb_inc_page(cpu_buffer, &bpage);
90106 @@ -3146,7 +3146,7 @@ static inline unsigned long
90107 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
90108 {
90109 return local_read(&cpu_buffer->entries) -
90110 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
90111 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
90112 }
90113
90114 /**
90115 @@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
90116 return 0;
90117
90118 cpu_buffer = buffer->buffers[cpu];
90119 - ret = local_read(&cpu_buffer->overrun);
90120 + ret = local_read_unchecked(&cpu_buffer->overrun);
90121
90122 return ret;
90123 }
90124 @@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
90125 return 0;
90126
90127 cpu_buffer = buffer->buffers[cpu];
90128 - ret = local_read(&cpu_buffer->commit_overrun);
90129 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
90130
90131 return ret;
90132 }
90133 @@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
90134 /* if you care about this being correct, lock the buffer */
90135 for_each_buffer_cpu(buffer, cpu) {
90136 cpu_buffer = buffer->buffers[cpu];
90137 - overruns += local_read(&cpu_buffer->overrun);
90138 + overruns += local_read_unchecked(&cpu_buffer->overrun);
90139 }
90140
90141 return overruns;
90142 @@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90143 /*
90144 * Reset the reader page to size zero.
90145 */
90146 - local_set(&cpu_buffer->reader_page->write, 0);
90147 - local_set(&cpu_buffer->reader_page->entries, 0);
90148 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90149 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90150 local_set(&cpu_buffer->reader_page->page->commit, 0);
90151 cpu_buffer->reader_page->real_end = 0;
90152
90153 @@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90154 * want to compare with the last_overrun.
90155 */
90156 smp_mb();
90157 - overwrite = local_read(&(cpu_buffer->overrun));
90158 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
90159
90160 /*
90161 * Here's the tricky part.
90162 @@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90163
90164 cpu_buffer->head_page
90165 = list_entry(cpu_buffer->pages, struct buffer_page, list);
90166 - local_set(&cpu_buffer->head_page->write, 0);
90167 - local_set(&cpu_buffer->head_page->entries, 0);
90168 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
90169 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
90170 local_set(&cpu_buffer->head_page->page->commit, 0);
90171
90172 cpu_buffer->head_page->read = 0;
90173 @@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90174
90175 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
90176 INIT_LIST_HEAD(&cpu_buffer->new_pages);
90177 - local_set(&cpu_buffer->reader_page->write, 0);
90178 - local_set(&cpu_buffer->reader_page->entries, 0);
90179 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90180 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90181 local_set(&cpu_buffer->reader_page->page->commit, 0);
90182 cpu_buffer->reader_page->read = 0;
90183
90184 local_set(&cpu_buffer->entries_bytes, 0);
90185 - local_set(&cpu_buffer->overrun, 0);
90186 - local_set(&cpu_buffer->commit_overrun, 0);
90187 + local_set_unchecked(&cpu_buffer->overrun, 0);
90188 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
90189 local_set(&cpu_buffer->dropped_events, 0);
90190 local_set(&cpu_buffer->entries, 0);
90191 local_set(&cpu_buffer->committing, 0);
90192 @@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
90193 rb_init_page(bpage);
90194 bpage = reader->page;
90195 reader->page = *data_page;
90196 - local_set(&reader->write, 0);
90197 - local_set(&reader->entries, 0);
90198 + local_set_unchecked(&reader->write, 0);
90199 + local_set_unchecked(&reader->entries, 0);
90200 reader->read = 0;
90201 *data_page = bpage;
90202
90203 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
90204 index 24c1f23..781fd73f 100644
90205 --- a/kernel/trace/trace.c
90206 +++ b/kernel/trace/trace.c
90207 @@ -3399,7 +3399,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
90208 return 0;
90209 }
90210
90211 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
90212 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
90213 {
90214 /* do nothing if flag is already set */
90215 if (!!(trace_flags & mask) == !!enabled)
90216 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
90217 index 02b592f..f971546 100644
90218 --- a/kernel/trace/trace.h
90219 +++ b/kernel/trace/trace.h
90220 @@ -1233,7 +1233,7 @@ extern const char *__stop___tracepoint_str[];
90221 void trace_printk_init_buffers(void);
90222 void trace_printk_start_comm(void);
90223 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
90224 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
90225 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
90226
90227 /*
90228 * Normal trace_printk() and friends allocates special buffers
90229 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
90230 index 26dc348..8708ca7 100644
90231 --- a/kernel/trace/trace_clock.c
90232 +++ b/kernel/trace/trace_clock.c
90233 @@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
90234 return now;
90235 }
90236
90237 -static atomic64_t trace_counter;
90238 +static atomic64_unchecked_t trace_counter;
90239
90240 /*
90241 * trace_clock_counter(): simply an atomic counter.
90242 @@ -132,5 +132,5 @@ static atomic64_t trace_counter;
90243 */
90244 u64 notrace trace_clock_counter(void)
90245 {
90246 - return atomic64_add_return(1, &trace_counter);
90247 + return atomic64_inc_return_unchecked(&trace_counter);
90248 }
90249 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
90250 index 7b16d40..1b2875d 100644
90251 --- a/kernel/trace/trace_events.c
90252 +++ b/kernel/trace/trace_events.c
90253 @@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
90254 return 0;
90255 }
90256
90257 -struct ftrace_module_file_ops;
90258 static void __add_event_to_tracers(struct ftrace_event_call *call);
90259
90260 /* Add an additional event_call dynamically */
90261 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
90262 index 0abd9b8..6a663a2 100644
90263 --- a/kernel/trace/trace_mmiotrace.c
90264 +++ b/kernel/trace/trace_mmiotrace.c
90265 @@ -24,7 +24,7 @@ struct header_iter {
90266 static struct trace_array *mmio_trace_array;
90267 static bool overrun_detected;
90268 static unsigned long prev_overruns;
90269 -static atomic_t dropped_count;
90270 +static atomic_unchecked_t dropped_count;
90271
90272 static void mmio_reset_data(struct trace_array *tr)
90273 {
90274 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
90275
90276 static unsigned long count_overruns(struct trace_iterator *iter)
90277 {
90278 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
90279 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
90280 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
90281
90282 if (over > prev_overruns)
90283 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
90284 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
90285 sizeof(*entry), 0, pc);
90286 if (!event) {
90287 - atomic_inc(&dropped_count);
90288 + atomic_inc_unchecked(&dropped_count);
90289 return;
90290 }
90291 entry = ring_buffer_event_data(event);
90292 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
90293 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
90294 sizeof(*entry), 0, pc);
90295 if (!event) {
90296 - atomic_inc(&dropped_count);
90297 + atomic_inc_unchecked(&dropped_count);
90298 return;
90299 }
90300 entry = ring_buffer_event_data(event);
90301 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
90302 index ed32284..884d6c3 100644
90303 --- a/kernel/trace/trace_output.c
90304 +++ b/kernel/trace/trace_output.c
90305 @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
90306
90307 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
90308 if (!IS_ERR(p)) {
90309 - p = mangle_path(s->buffer + s->len, p, "\n");
90310 + p = mangle_path(s->buffer + s->len, p, "\n\\");
90311 if (p) {
90312 s->len = p - s->buffer;
90313 return 1;
90314 @@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
90315 goto out;
90316 }
90317
90318 + pax_open_kernel();
90319 if (event->funcs->trace == NULL)
90320 - event->funcs->trace = trace_nop_print;
90321 + *(void **)&event->funcs->trace = trace_nop_print;
90322 if (event->funcs->raw == NULL)
90323 - event->funcs->raw = trace_nop_print;
90324 + *(void **)&event->funcs->raw = trace_nop_print;
90325 if (event->funcs->hex == NULL)
90326 - event->funcs->hex = trace_nop_print;
90327 + *(void **)&event->funcs->hex = trace_nop_print;
90328 if (event->funcs->binary == NULL)
90329 - event->funcs->binary = trace_nop_print;
90330 + *(void **)&event->funcs->binary = trace_nop_print;
90331 + pax_close_kernel();
90332
90333 key = event->type & (EVENT_HASHSIZE - 1);
90334
90335 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
90336 index e6be585..d73ae5e 100644
90337 --- a/kernel/trace/trace_stack.c
90338 +++ b/kernel/trace/trace_stack.c
90339 @@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
90340 return;
90341
90342 /* we do not handle interrupt stacks yet */
90343 - if (!object_is_on_stack(stack))
90344 + if (!object_starts_on_stack(stack))
90345 return;
90346
90347 local_irq_save(flags);
90348 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
90349 index dd06439..9e77bce 100644
90350 --- a/kernel/user_namespace.c
90351 +++ b/kernel/user_namespace.c
90352 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
90353 !kgid_has_mapping(parent_ns, group))
90354 return -EPERM;
90355
90356 +#ifdef CONFIG_GRKERNSEC
90357 + /*
90358 + * This doesn't really inspire confidence:
90359 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
90360 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
90361 + * Increases kernel attack surface in areas developers
90362 + * previously cared little about ("low importance due
90363 + * to requiring "root" capability")
90364 + * To be removed when this code receives *proper* review
90365 + */
90366 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
90367 + !capable(CAP_SETGID))
90368 + return -EPERM;
90369 +#endif
90370 +
90371 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
90372 if (!ns)
90373 return -ENOMEM;
90374 @@ -866,7 +881,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
90375 if (atomic_read(&current->mm->mm_users) > 1)
90376 return -EINVAL;
90377
90378 - if (current->fs->users != 1)
90379 + if (atomic_read(&current->fs->users) != 1)
90380 return -EINVAL;
90381
90382 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
90383 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
90384 index 4f69f9a..7c6f8f8 100644
90385 --- a/kernel/utsname_sysctl.c
90386 +++ b/kernel/utsname_sysctl.c
90387 @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
90388 static int proc_do_uts_string(ctl_table *table, int write,
90389 void __user *buffer, size_t *lenp, loff_t *ppos)
90390 {
90391 - struct ctl_table uts_table;
90392 + ctl_table_no_const uts_table;
90393 int r;
90394 memcpy(&uts_table, table, sizeof(uts_table));
90395 uts_table.data = get_uts(table, write);
90396 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
90397 index 4431610..4265616 100644
90398 --- a/kernel/watchdog.c
90399 +++ b/kernel/watchdog.c
90400 @@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
90401 static void watchdog_nmi_disable(unsigned int cpu) { return; }
90402 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
90403
90404 -static struct smp_hotplug_thread watchdog_threads = {
90405 +static struct smp_hotplug_thread watchdog_threads __read_only = {
90406 .store = &softlockup_watchdog,
90407 .thread_should_run = watchdog_should_run,
90408 .thread_fn = watchdog,
90409 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
90410 index 193e977..26dd63f 100644
90411 --- a/kernel/workqueue.c
90412 +++ b/kernel/workqueue.c
90413 @@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
90414 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
90415 worker_flags |= WORKER_REBOUND;
90416 worker_flags &= ~WORKER_UNBOUND;
90417 - ACCESS_ONCE(worker->flags) = worker_flags;
90418 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
90419 }
90420
90421 spin_unlock_irq(&pool->lock);
90422 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
90423 index a48abea..e108def 100644
90424 --- a/lib/Kconfig.debug
90425 +++ b/lib/Kconfig.debug
90426 @@ -854,7 +854,7 @@ config DEBUG_MUTEXES
90427
90428 config DEBUG_WW_MUTEX_SLOWPATH
90429 bool "Wait/wound mutex debugging: Slowpath testing"
90430 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90431 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90432 select DEBUG_LOCK_ALLOC
90433 select DEBUG_SPINLOCK
90434 select DEBUG_MUTEXES
90435 @@ -867,7 +867,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
90436
90437 config DEBUG_LOCK_ALLOC
90438 bool "Lock debugging: detect incorrect freeing of live locks"
90439 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90440 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90441 select DEBUG_SPINLOCK
90442 select DEBUG_MUTEXES
90443 select LOCKDEP
90444 @@ -881,7 +881,7 @@ config DEBUG_LOCK_ALLOC
90445
90446 config PROVE_LOCKING
90447 bool "Lock debugging: prove locking correctness"
90448 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90449 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90450 select LOCKDEP
90451 select DEBUG_SPINLOCK
90452 select DEBUG_MUTEXES
90453 @@ -932,7 +932,7 @@ config LOCKDEP
90454
90455 config LOCK_STAT
90456 bool "Lock usage statistics"
90457 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90458 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90459 select LOCKDEP
90460 select DEBUG_SPINLOCK
90461 select DEBUG_MUTEXES
90462 @@ -1394,6 +1394,7 @@ config LATENCYTOP
90463 depends on DEBUG_KERNEL
90464 depends on STACKTRACE_SUPPORT
90465 depends on PROC_FS
90466 + depends on !GRKERNSEC_HIDESYM
90467 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
90468 select KALLSYMS
90469 select KALLSYMS_ALL
90470 @@ -1410,7 +1411,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90471 config DEBUG_STRICT_USER_COPY_CHECKS
90472 bool "Strict user copy size checks"
90473 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90474 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
90475 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
90476 help
90477 Enabling this option turns a certain set of sanity checks for user
90478 copy operations into compile time failures.
90479 @@ -1529,7 +1530,7 @@ endmenu # runtime tests
90480
90481 config PROVIDE_OHCI1394_DMA_INIT
90482 bool "Remote debugging over FireWire early on boot"
90483 - depends on PCI && X86
90484 + depends on PCI && X86 && !GRKERNSEC
90485 help
90486 If you want to debug problems which hang or crash the kernel early
90487 on boot and the crashing machine has a FireWire port, you can use
90488 diff --git a/lib/Makefile b/lib/Makefile
90489 index 48140e3..de854e5 100644
90490 --- a/lib/Makefile
90491 +++ b/lib/Makefile
90492 @@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
90493 obj-$(CONFIG_BTREE) += btree.o
90494 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
90495 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
90496 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
90497 +obj-y += list_debug.o
90498 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
90499
90500 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
90501 diff --git a/lib/average.c b/lib/average.c
90502 index 114d1be..ab0350c 100644
90503 --- a/lib/average.c
90504 +++ b/lib/average.c
90505 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
90506 {
90507 unsigned long internal = ACCESS_ONCE(avg->internal);
90508
90509 - ACCESS_ONCE(avg->internal) = internal ?
90510 + ACCESS_ONCE_RW(avg->internal) = internal ?
90511 (((internal << avg->weight) - internal) +
90512 (val << avg->factor)) >> avg->weight :
90513 (val << avg->factor);
90514 diff --git a/lib/bitmap.c b/lib/bitmap.c
90515 index 06f7e4f..f3cf2b0 100644
90516 --- a/lib/bitmap.c
90517 +++ b/lib/bitmap.c
90518 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
90519 {
90520 int c, old_c, totaldigits, ndigits, nchunks, nbits;
90521 u32 chunk;
90522 - const char __user __force *ubuf = (const char __user __force *)buf;
90523 + const char __user *ubuf = (const char __force_user *)buf;
90524
90525 bitmap_zero(maskp, nmaskbits);
90526
90527 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
90528 {
90529 if (!access_ok(VERIFY_READ, ubuf, ulen))
90530 return -EFAULT;
90531 - return __bitmap_parse((const char __force *)ubuf,
90532 + return __bitmap_parse((const char __force_kernel *)ubuf,
90533 ulen, 1, maskp, nmaskbits);
90534
90535 }
90536 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
90537 {
90538 unsigned a, b;
90539 int c, old_c, totaldigits;
90540 - const char __user __force *ubuf = (const char __user __force *)buf;
90541 + const char __user *ubuf = (const char __force_user *)buf;
90542 int exp_digit, in_range;
90543
90544 totaldigits = c = 0;
90545 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
90546 {
90547 if (!access_ok(VERIFY_READ, ubuf, ulen))
90548 return -EFAULT;
90549 - return __bitmap_parselist((const char __force *)ubuf,
90550 + return __bitmap_parselist((const char __force_kernel *)ubuf,
90551 ulen, 1, maskp, nmaskbits);
90552 }
90553 EXPORT_SYMBOL(bitmap_parselist_user);
90554 diff --git a/lib/bug.c b/lib/bug.c
90555 index 1686034..a9c00c8 100644
90556 --- a/lib/bug.c
90557 +++ b/lib/bug.c
90558 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
90559 return BUG_TRAP_TYPE_NONE;
90560
90561 bug = find_bug(bugaddr);
90562 + if (!bug)
90563 + return BUG_TRAP_TYPE_NONE;
90564
90565 file = NULL;
90566 line = 0;
90567 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
90568 index e0731c3..ad66444 100644
90569 --- a/lib/debugobjects.c
90570 +++ b/lib/debugobjects.c
90571 @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
90572 if (limit > 4)
90573 return;
90574
90575 - is_on_stack = object_is_on_stack(addr);
90576 + is_on_stack = object_starts_on_stack(addr);
90577 if (is_on_stack == onstack)
90578 return;
90579
90580 diff --git a/lib/devres.c b/lib/devres.c
90581 index 8235331..5881053 100644
90582 --- a/lib/devres.c
90583 +++ b/lib/devres.c
90584 @@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
90585 void devm_iounmap(struct device *dev, void __iomem *addr)
90586 {
90587 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
90588 - (void *)addr));
90589 + (void __force *)addr));
90590 iounmap(addr);
90591 }
90592 EXPORT_SYMBOL(devm_iounmap);
90593 @@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
90594 {
90595 ioport_unmap(addr);
90596 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
90597 - devm_ioport_map_match, (void *)addr));
90598 + devm_ioport_map_match, (void __force *)addr));
90599 }
90600 EXPORT_SYMBOL(devm_ioport_unmap);
90601 #endif /* CONFIG_HAS_IOPORT */
90602 diff --git a/lib/div64.c b/lib/div64.c
90603 index 4382ad7..08aa558 100644
90604 --- a/lib/div64.c
90605 +++ b/lib/div64.c
90606 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
90607 EXPORT_SYMBOL(__div64_32);
90608
90609 #ifndef div_s64_rem
90610 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90611 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90612 {
90613 u64 quotient;
90614
90615 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
90616 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
90617 */
90618 #ifndef div64_u64
90619 -u64 div64_u64(u64 dividend, u64 divisor)
90620 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
90621 {
90622 u32 high = divisor >> 32;
90623 u64 quot;
90624 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
90625 index 98f2d7e..899da5c 100644
90626 --- a/lib/dma-debug.c
90627 +++ b/lib/dma-debug.c
90628 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
90629
90630 void dma_debug_add_bus(struct bus_type *bus)
90631 {
90632 - struct notifier_block *nb;
90633 + notifier_block_no_const *nb;
90634
90635 if (global_disable)
90636 return;
90637 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
90638
90639 static void check_for_stack(struct device *dev, void *addr)
90640 {
90641 - if (object_is_on_stack(addr))
90642 + if (object_starts_on_stack(addr))
90643 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
90644 "stack [addr=%p]\n", addr);
90645 }
90646 diff --git a/lib/hash.c b/lib/hash.c
90647 index fea973f..386626f 100644
90648 --- a/lib/hash.c
90649 +++ b/lib/hash.c
90650 @@ -14,7 +14,7 @@
90651 #include <linux/hash.h>
90652 #include <linux/cache.h>
90653
90654 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
90655 +static struct fast_hash_ops arch_hash_ops __read_only = {
90656 .hash = jhash,
90657 .hash2 = jhash2,
90658 };
90659 diff --git a/lib/inflate.c b/lib/inflate.c
90660 index 013a761..c28f3fc 100644
90661 --- a/lib/inflate.c
90662 +++ b/lib/inflate.c
90663 @@ -269,7 +269,7 @@ static void free(void *where)
90664 malloc_ptr = free_mem_ptr;
90665 }
90666 #else
90667 -#define malloc(a) kmalloc(a, GFP_KERNEL)
90668 +#define malloc(a) kmalloc((a), GFP_KERNEL)
90669 #define free(a) kfree(a)
90670 #endif
90671
90672 diff --git a/lib/ioremap.c b/lib/ioremap.c
90673 index 0c9216c..863bd89 100644
90674 --- a/lib/ioremap.c
90675 +++ b/lib/ioremap.c
90676 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
90677 unsigned long next;
90678
90679 phys_addr -= addr;
90680 - pmd = pmd_alloc(&init_mm, pud, addr);
90681 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90682 if (!pmd)
90683 return -ENOMEM;
90684 do {
90685 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
90686 unsigned long next;
90687
90688 phys_addr -= addr;
90689 - pud = pud_alloc(&init_mm, pgd, addr);
90690 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
90691 if (!pud)
90692 return -ENOMEM;
90693 do {
90694 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
90695 index bd2bea9..6b3c95e 100644
90696 --- a/lib/is_single_threaded.c
90697 +++ b/lib/is_single_threaded.c
90698 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
90699 struct task_struct *p, *t;
90700 bool ret;
90701
90702 + if (!mm)
90703 + return true;
90704 +
90705 if (atomic_read(&task->signal->live) != 1)
90706 return false;
90707
90708 diff --git a/lib/kobject.c b/lib/kobject.c
90709 index cb14aea..8c53cdb 100644
90710 --- a/lib/kobject.c
90711 +++ b/lib/kobject.c
90712 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
90713
90714
90715 static DEFINE_SPINLOCK(kobj_ns_type_lock);
90716 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
90717 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
90718
90719 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90720 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90721 {
90722 enum kobj_ns_type type = ops->type;
90723 int error;
90724 diff --git a/lib/list_debug.c b/lib/list_debug.c
90725 index c24c2f7..f0296f4 100644
90726 --- a/lib/list_debug.c
90727 +++ b/lib/list_debug.c
90728 @@ -11,7 +11,9 @@
90729 #include <linux/bug.h>
90730 #include <linux/kernel.h>
90731 #include <linux/rculist.h>
90732 +#include <linux/mm.h>
90733
90734 +#ifdef CONFIG_DEBUG_LIST
90735 /*
90736 * Insert a new entry between two known consecutive entries.
90737 *
90738 @@ -19,21 +21,40 @@
90739 * the prev/next entries already!
90740 */
90741
90742 +static bool __list_add_debug(struct list_head *new,
90743 + struct list_head *prev,
90744 + struct list_head *next)
90745 +{
90746 + if (unlikely(next->prev != prev)) {
90747 + printk(KERN_ERR "list_add corruption. next->prev should be "
90748 + "prev (%p), but was %p. (next=%p).\n",
90749 + prev, next->prev, next);
90750 + BUG();
90751 + return false;
90752 + }
90753 + if (unlikely(prev->next != next)) {
90754 + printk(KERN_ERR "list_add corruption. prev->next should be "
90755 + "next (%p), but was %p. (prev=%p).\n",
90756 + next, prev->next, prev);
90757 + BUG();
90758 + return false;
90759 + }
90760 + if (unlikely(new == prev || new == next)) {
90761 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
90762 + new, prev, next);
90763 + BUG();
90764 + return false;
90765 + }
90766 + return true;
90767 +}
90768 +
90769 void __list_add(struct list_head *new,
90770 - struct list_head *prev,
90771 - struct list_head *next)
90772 + struct list_head *prev,
90773 + struct list_head *next)
90774 {
90775 - WARN(next->prev != prev,
90776 - "list_add corruption. next->prev should be "
90777 - "prev (%p), but was %p. (next=%p).\n",
90778 - prev, next->prev, next);
90779 - WARN(prev->next != next,
90780 - "list_add corruption. prev->next should be "
90781 - "next (%p), but was %p. (prev=%p).\n",
90782 - next, prev->next, prev);
90783 - WARN(new == prev || new == next,
90784 - "list_add double add: new=%p, prev=%p, next=%p.\n",
90785 - new, prev, next);
90786 + if (!__list_add_debug(new, prev, next))
90787 + return;
90788 +
90789 next->prev = new;
90790 new->next = next;
90791 new->prev = prev;
90792 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
90793 }
90794 EXPORT_SYMBOL(__list_add);
90795
90796 -void __list_del_entry(struct list_head *entry)
90797 +static bool __list_del_entry_debug(struct list_head *entry)
90798 {
90799 struct list_head *prev, *next;
90800
90801 prev = entry->prev;
90802 next = entry->next;
90803
90804 - if (WARN(next == LIST_POISON1,
90805 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
90806 - entry, LIST_POISON1) ||
90807 - WARN(prev == LIST_POISON2,
90808 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
90809 - entry, LIST_POISON2) ||
90810 - WARN(prev->next != entry,
90811 - "list_del corruption. prev->next should be %p, "
90812 - "but was %p\n", entry, prev->next) ||
90813 - WARN(next->prev != entry,
90814 - "list_del corruption. next->prev should be %p, "
90815 - "but was %p\n", entry, next->prev))
90816 + if (unlikely(next == LIST_POISON1)) {
90817 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
90818 + entry, LIST_POISON1);
90819 + BUG();
90820 + return false;
90821 + }
90822 + if (unlikely(prev == LIST_POISON2)) {
90823 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
90824 + entry, LIST_POISON2);
90825 + BUG();
90826 + return false;
90827 + }
90828 + if (unlikely(entry->prev->next != entry)) {
90829 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
90830 + "but was %p\n", entry, prev->next);
90831 + BUG();
90832 + return false;
90833 + }
90834 + if (unlikely(entry->next->prev != entry)) {
90835 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
90836 + "but was %p\n", entry, next->prev);
90837 + BUG();
90838 + return false;
90839 + }
90840 + return true;
90841 +}
90842 +
90843 +void __list_del_entry(struct list_head *entry)
90844 +{
90845 + if (!__list_del_entry_debug(entry))
90846 return;
90847
90848 - __list_del(prev, next);
90849 + __list_del(entry->prev, entry->next);
90850 }
90851 EXPORT_SYMBOL(__list_del_entry);
90852
90853 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
90854 void __list_add_rcu(struct list_head *new,
90855 struct list_head *prev, struct list_head *next)
90856 {
90857 - WARN(next->prev != prev,
90858 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
90859 - prev, next->prev, next);
90860 - WARN(prev->next != next,
90861 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
90862 - next, prev->next, prev);
90863 + if (!__list_add_debug(new, prev, next))
90864 + return;
90865 +
90866 new->next = next;
90867 new->prev = prev;
90868 rcu_assign_pointer(list_next_rcu(prev), new);
90869 next->prev = new;
90870 }
90871 EXPORT_SYMBOL(__list_add_rcu);
90872 +#endif
90873 +
90874 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
90875 +{
90876 +#ifdef CONFIG_DEBUG_LIST
90877 + if (!__list_add_debug(new, prev, next))
90878 + return;
90879 +#endif
90880 +
90881 + pax_open_kernel();
90882 + next->prev = new;
90883 + new->next = next;
90884 + new->prev = prev;
90885 + prev->next = new;
90886 + pax_close_kernel();
90887 +}
90888 +EXPORT_SYMBOL(__pax_list_add);
90889 +
90890 +void pax_list_del(struct list_head *entry)
90891 +{
90892 +#ifdef CONFIG_DEBUG_LIST
90893 + if (!__list_del_entry_debug(entry))
90894 + return;
90895 +#endif
90896 +
90897 + pax_open_kernel();
90898 + __list_del(entry->prev, entry->next);
90899 + entry->next = LIST_POISON1;
90900 + entry->prev = LIST_POISON2;
90901 + pax_close_kernel();
90902 +}
90903 +EXPORT_SYMBOL(pax_list_del);
90904 +
90905 +void pax_list_del_init(struct list_head *entry)
90906 +{
90907 + pax_open_kernel();
90908 + __list_del(entry->prev, entry->next);
90909 + INIT_LIST_HEAD(entry);
90910 + pax_close_kernel();
90911 +}
90912 +EXPORT_SYMBOL(pax_list_del_init);
90913 +
90914 +void __pax_list_add_rcu(struct list_head *new,
90915 + struct list_head *prev, struct list_head *next)
90916 +{
90917 +#ifdef CONFIG_DEBUG_LIST
90918 + if (!__list_add_debug(new, prev, next))
90919 + return;
90920 +#endif
90921 +
90922 + pax_open_kernel();
90923 + new->next = next;
90924 + new->prev = prev;
90925 + rcu_assign_pointer(list_next_rcu(prev), new);
90926 + next->prev = new;
90927 + pax_close_kernel();
90928 +}
90929 +EXPORT_SYMBOL(__pax_list_add_rcu);
90930 +
90931 +void pax_list_del_rcu(struct list_head *entry)
90932 +{
90933 +#ifdef CONFIG_DEBUG_LIST
90934 + if (!__list_del_entry_debug(entry))
90935 + return;
90936 +#endif
90937 +
90938 + pax_open_kernel();
90939 + __list_del(entry->prev, entry->next);
90940 + entry->next = LIST_POISON1;
90941 + entry->prev = LIST_POISON2;
90942 + pax_close_kernel();
90943 +}
90944 +EXPORT_SYMBOL(pax_list_del_rcu);
90945 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
90946 index 963b703..438bc51 100644
90947 --- a/lib/percpu-refcount.c
90948 +++ b/lib/percpu-refcount.c
90949 @@ -29,7 +29,7 @@
90950 * can't hit 0 before we've added up all the percpu refs.
90951 */
90952
90953 -#define PCPU_COUNT_BIAS (1U << 31)
90954 +#define PCPU_COUNT_BIAS (1U << 30)
90955
90956 /**
90957 * percpu_ref_init - initialize a percpu refcount
90958 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
90959 index bd4a8df..9e4804f 100644
90960 --- a/lib/radix-tree.c
90961 +++ b/lib/radix-tree.c
90962 @@ -93,7 +93,7 @@ struct radix_tree_preload {
90963 int nr;
90964 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
90965 };
90966 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
90967 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
90968
90969 static inline void *ptr_to_indirect(void *ptr)
90970 {
90971 diff --git a/lib/random32.c b/lib/random32.c
90972 index 6148967..009bfe8 100644
90973 --- a/lib/random32.c
90974 +++ b/lib/random32.c
90975 @@ -44,7 +44,7 @@
90976 static void __init prandom_state_selftest(void);
90977 #endif
90978
90979 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
90980 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
90981
90982 /**
90983 * prandom_u32_state - seeded pseudo-random number generator.
90984 diff --git a/lib/rbtree.c b/lib/rbtree.c
90985 index 65f4eff..2cfa167 100644
90986 --- a/lib/rbtree.c
90987 +++ b/lib/rbtree.c
90988 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
90989 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
90990
90991 static const struct rb_augment_callbacks dummy_callbacks = {
90992 - dummy_propagate, dummy_copy, dummy_rotate
90993 + .propagate = dummy_propagate,
90994 + .copy = dummy_copy,
90995 + .rotate = dummy_rotate
90996 };
90997
90998 void rb_insert_color(struct rb_node *node, struct rb_root *root)
90999 diff --git a/lib/show_mem.c b/lib/show_mem.c
91000 index 0922579..9d7adb9 100644
91001 --- a/lib/show_mem.c
91002 +++ b/lib/show_mem.c
91003 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
91004 quicklist_total_size());
91005 #endif
91006 #ifdef CONFIG_MEMORY_FAILURE
91007 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
91008 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
91009 #endif
91010 }
91011 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
91012 index bb2b201..46abaf9 100644
91013 --- a/lib/strncpy_from_user.c
91014 +++ b/lib/strncpy_from_user.c
91015 @@ -21,7 +21,7 @@
91016 */
91017 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
91018 {
91019 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91020 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91021 long res = 0;
91022
91023 /*
91024 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
91025 index a28df52..3d55877 100644
91026 --- a/lib/strnlen_user.c
91027 +++ b/lib/strnlen_user.c
91028 @@ -26,7 +26,7 @@
91029 */
91030 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
91031 {
91032 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91033 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91034 long align, res = 0;
91035 unsigned long c;
91036
91037 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
91038 index b604b83..c0547f6 100644
91039 --- a/lib/swiotlb.c
91040 +++ b/lib/swiotlb.c
91041 @@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
91042
91043 void
91044 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
91045 - dma_addr_t dev_addr)
91046 + dma_addr_t dev_addr, struct dma_attrs *attrs)
91047 {
91048 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
91049
91050 diff --git a/lib/usercopy.c b/lib/usercopy.c
91051 index 4f5b1dd..7cab418 100644
91052 --- a/lib/usercopy.c
91053 +++ b/lib/usercopy.c
91054 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
91055 WARN(1, "Buffer overflow detected!\n");
91056 }
91057 EXPORT_SYMBOL(copy_from_user_overflow);
91058 +
91059 +void copy_to_user_overflow(void)
91060 +{
91061 + WARN(1, "Buffer overflow detected!\n");
91062 +}
91063 +EXPORT_SYMBOL(copy_to_user_overflow);
91064 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
91065 index 185b6d3..823c48c 100644
91066 --- a/lib/vsprintf.c
91067 +++ b/lib/vsprintf.c
91068 @@ -16,6 +16,9 @@
91069 * - scnprintf and vscnprintf
91070 */
91071
91072 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91073 +#define __INCLUDED_BY_HIDESYM 1
91074 +#endif
91075 #include <stdarg.h>
91076 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
91077 #include <linux/types.h>
91078 @@ -1179,7 +1182,11 @@ char *address_val(char *buf, char *end, const void *addr,
91079 return number(buf, end, num, spec);
91080 }
91081
91082 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91083 +int kptr_restrict __read_mostly = 2;
91084 +#else
91085 int kptr_restrict __read_mostly;
91086 +#endif
91087
91088 /*
91089 * Show a '%p' thing. A kernel extension is that the '%p' is followed
91090 @@ -1192,6 +1199,7 @@ int kptr_restrict __read_mostly;
91091 * - 'f' For simple symbolic function names without offset
91092 * - 'S' For symbolic direct pointers with offset
91093 * - 's' For symbolic direct pointers without offset
91094 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
91095 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
91096 * - 'B' For backtraced symbolic direct pointers with offset
91097 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
91098 @@ -1259,12 +1267,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91099
91100 if (!ptr && *fmt != 'K') {
91101 /*
91102 - * Print (null) with the same width as a pointer so it makes
91103 + * Print (nil) with the same width as a pointer so it makes
91104 * tabular output look nice.
91105 */
91106 if (spec.field_width == -1)
91107 spec.field_width = default_width;
91108 - return string(buf, end, "(null)", spec);
91109 + return string(buf, end, "(nil)", spec);
91110 }
91111
91112 switch (*fmt) {
91113 @@ -1274,6 +1282,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91114 /* Fallthrough */
91115 case 'S':
91116 case 's':
91117 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91118 + break;
91119 +#else
91120 + return symbol_string(buf, end, ptr, spec, fmt);
91121 +#endif
91122 + case 'A':
91123 case 'B':
91124 return symbol_string(buf, end, ptr, spec, fmt);
91125 case 'R':
91126 @@ -1329,6 +1343,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91127 va_end(va);
91128 return buf;
91129 }
91130 + case 'P':
91131 + break;
91132 case 'K':
91133 /*
91134 * %pK cannot be used in IRQ context because its test
91135 @@ -1386,6 +1402,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91136 ((const struct file *)ptr)->f_path.dentry,
91137 spec, fmt);
91138 }
91139 +
91140 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91141 + /* 'P' = approved pointers to copy to userland,
91142 + as in the /proc/kallsyms case, as we make it display nothing
91143 + for non-root users, and the real contents for root users
91144 + Also ignore 'K' pointers, since we force their NULLing for non-root users
91145 + above
91146 + */
91147 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
91148 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
91149 + dump_stack();
91150 + ptr = NULL;
91151 + }
91152 +#endif
91153 +
91154 spec.flags |= SMALL;
91155 if (spec.field_width == -1) {
91156 spec.field_width = default_width;
91157 @@ -2107,11 +2138,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91158 typeof(type) value; \
91159 if (sizeof(type) == 8) { \
91160 args = PTR_ALIGN(args, sizeof(u32)); \
91161 - *(u32 *)&value = *(u32 *)args; \
91162 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
91163 + *(u32 *)&value = *(const u32 *)args; \
91164 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
91165 } else { \
91166 args = PTR_ALIGN(args, sizeof(type)); \
91167 - value = *(typeof(type) *)args; \
91168 + value = *(const typeof(type) *)args; \
91169 } \
91170 args += sizeof(type); \
91171 value; \
91172 @@ -2174,7 +2205,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91173 case FORMAT_TYPE_STR: {
91174 const char *str_arg = args;
91175 args += strlen(str_arg) + 1;
91176 - str = string(str, end, (char *)str_arg, spec);
91177 + str = string(str, end, str_arg, spec);
91178 break;
91179 }
91180
91181 diff --git a/localversion-grsec b/localversion-grsec
91182 new file mode 100644
91183 index 0000000..7cd6065
91184 --- /dev/null
91185 +++ b/localversion-grsec
91186 @@ -0,0 +1 @@
91187 +-grsec
91188 diff --git a/mm/Kconfig b/mm/Kconfig
91189 index 2888024..c15a810 100644
91190 --- a/mm/Kconfig
91191 +++ b/mm/Kconfig
91192 @@ -326,10 +326,11 @@ config KSM
91193 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
91194
91195 config DEFAULT_MMAP_MIN_ADDR
91196 - int "Low address space to protect from user allocation"
91197 + int "Low address space to protect from user allocation"
91198 depends on MMU
91199 - default 4096
91200 - help
91201 + default 32768 if ALPHA || ARM || PARISC || SPARC32
91202 + default 65536
91203 + help
91204 This is the portion of low virtual memory which should be protected
91205 from userspace allocation. Keeping a user from writing to low pages
91206 can help reduce the impact of kernel NULL pointer bugs.
91207 @@ -360,7 +361,7 @@ config MEMORY_FAILURE
91208
91209 config HWPOISON_INJECT
91210 tristate "HWPoison pages injector"
91211 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
91212 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
91213 select PROC_PAGE_MONITOR
91214
91215 config NOMMU_INITIAL_TRIM_EXCESS
91216 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
91217 index ce682f7..1fb54f9 100644
91218 --- a/mm/backing-dev.c
91219 +++ b/mm/backing-dev.c
91220 @@ -12,7 +12,7 @@
91221 #include <linux/device.h>
91222 #include <trace/events/writeback.h>
91223
91224 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
91225 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
91226
91227 struct backing_dev_info default_backing_dev_info = {
91228 .name = "default",
91229 @@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
91230 return err;
91231
91232 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
91233 - atomic_long_inc_return(&bdi_seq));
91234 + atomic_long_inc_return_unchecked(&bdi_seq));
91235 if (err) {
91236 bdi_destroy(bdi);
91237 return err;
91238 diff --git a/mm/filemap.c b/mm/filemap.c
91239 index 7a13f6a..e52e841 100644
91240 --- a/mm/filemap.c
91241 +++ b/mm/filemap.c
91242 @@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
91243 struct address_space *mapping = file->f_mapping;
91244
91245 if (!mapping->a_ops->readpage)
91246 - return -ENOEXEC;
91247 + return -ENODEV;
91248 file_accessed(file);
91249 vma->vm_ops = &generic_file_vm_ops;
91250 return 0;
91251 @@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
91252
91253 while (bytes) {
91254 char __user *buf = iov->iov_base + base;
91255 - int copy = min(bytes, iov->iov_len - base);
91256 + size_t copy = min(bytes, iov->iov_len - base);
91257
91258 base = 0;
91259 left = __copy_from_user_inatomic(vaddr, buf, copy);
91260 @@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
91261 BUG_ON(!in_atomic());
91262 kaddr = kmap_atomic(page);
91263 if (likely(i->nr_segs == 1)) {
91264 - int left;
91265 + size_t left;
91266 char __user *buf = i->iov->iov_base + i->iov_offset;
91267 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
91268 copied = bytes - left;
91269 @@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
91270
91271 kaddr = kmap(page);
91272 if (likely(i->nr_segs == 1)) {
91273 - int left;
91274 + size_t left;
91275 char __user *buf = i->iov->iov_base + i->iov_offset;
91276 left = __copy_from_user(kaddr + offset, buf, bytes);
91277 copied = bytes - left;
91278 @@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
91279 * zero-length segments (without overruning the iovec).
91280 */
91281 while (bytes || unlikely(i->count && !iov->iov_len)) {
91282 - int copy;
91283 + size_t copy;
91284
91285 copy = min(bytes, iov->iov_len - base);
91286 BUG_ON(!i->count || i->count < copy);
91287 @@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
91288 *pos = i_size_read(inode);
91289
91290 if (limit != RLIM_INFINITY) {
91291 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
91292 if (*pos >= limit) {
91293 send_sig(SIGXFSZ, current, 0);
91294 return -EFBIG;
91295 diff --git a/mm/fremap.c b/mm/fremap.c
91296 index 34feba6..315fe78 100644
91297 --- a/mm/fremap.c
91298 +++ b/mm/fremap.c
91299 @@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
91300 retry:
91301 vma = find_vma(mm, start);
91302
91303 +#ifdef CONFIG_PAX_SEGMEXEC
91304 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
91305 + goto out;
91306 +#endif
91307 +
91308 /*
91309 * Make sure the vma is shared, that it supports prefaulting,
91310 * and that the remapped range is valid and fully within
91311 diff --git a/mm/highmem.c b/mm/highmem.c
91312 index b32b70c..e512eb0 100644
91313 --- a/mm/highmem.c
91314 +++ b/mm/highmem.c
91315 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
91316 * So no dangers, even with speculative execution.
91317 */
91318 page = pte_page(pkmap_page_table[i]);
91319 + pax_open_kernel();
91320 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
91321 -
91322 + pax_close_kernel();
91323 set_page_address(page, NULL);
91324 need_flush = 1;
91325 }
91326 @@ -198,9 +199,11 @@ start:
91327 }
91328 }
91329 vaddr = PKMAP_ADDR(last_pkmap_nr);
91330 +
91331 + pax_open_kernel();
91332 set_pte_at(&init_mm, vaddr,
91333 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
91334 -
91335 + pax_close_kernel();
91336 pkmap_count[last_pkmap_nr] = 1;
91337 set_page_address(page, (void *)vaddr);
91338
91339 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
91340 index c01cb9f..ac0f58e 100644
91341 --- a/mm/hugetlb.c
91342 +++ b/mm/hugetlb.c
91343 @@ -2068,15 +2068,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
91344 struct hstate *h = &default_hstate;
91345 unsigned long tmp;
91346 int ret;
91347 + ctl_table_no_const hugetlb_table;
91348
91349 tmp = h->max_huge_pages;
91350
91351 if (write && h->order >= MAX_ORDER)
91352 return -EINVAL;
91353
91354 - table->data = &tmp;
91355 - table->maxlen = sizeof(unsigned long);
91356 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91357 + hugetlb_table = *table;
91358 + hugetlb_table.data = &tmp;
91359 + hugetlb_table.maxlen = sizeof(unsigned long);
91360 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91361 if (ret)
91362 goto out;
91363
91364 @@ -2121,15 +2123,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
91365 struct hstate *h = &default_hstate;
91366 unsigned long tmp;
91367 int ret;
91368 + ctl_table_no_const hugetlb_table;
91369
91370 tmp = h->nr_overcommit_huge_pages;
91371
91372 if (write && h->order >= MAX_ORDER)
91373 return -EINVAL;
91374
91375 - table->data = &tmp;
91376 - table->maxlen = sizeof(unsigned long);
91377 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91378 + hugetlb_table = *table;
91379 + hugetlb_table.data = &tmp;
91380 + hugetlb_table.maxlen = sizeof(unsigned long);
91381 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91382 if (ret)
91383 goto out;
91384
91385 @@ -2598,6 +2602,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
91386 return 1;
91387 }
91388
91389 +#ifdef CONFIG_PAX_SEGMEXEC
91390 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
91391 +{
91392 + struct mm_struct *mm = vma->vm_mm;
91393 + struct vm_area_struct *vma_m;
91394 + unsigned long address_m;
91395 + pte_t *ptep_m;
91396 +
91397 + vma_m = pax_find_mirror_vma(vma);
91398 + if (!vma_m)
91399 + return;
91400 +
91401 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91402 + address_m = address + SEGMEXEC_TASK_SIZE;
91403 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
91404 + get_page(page_m);
91405 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
91406 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
91407 +}
91408 +#endif
91409 +
91410 /*
91411 * Hugetlb_cow() should be called with page lock of the original hugepage held.
91412 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
91413 @@ -2714,6 +2739,11 @@ retry_avoidcopy:
91414 make_huge_pte(vma, new_page, 1));
91415 page_remove_rmap(old_page);
91416 hugepage_add_new_anon_rmap(new_page, vma, address);
91417 +
91418 +#ifdef CONFIG_PAX_SEGMEXEC
91419 + pax_mirror_huge_pte(vma, address, new_page);
91420 +#endif
91421 +
91422 /* Make the old page be freed below */
91423 new_page = old_page;
91424 }
91425 @@ -2878,6 +2908,10 @@ retry:
91426 && (vma->vm_flags & VM_SHARED)));
91427 set_huge_pte_at(mm, address, ptep, new_pte);
91428
91429 +#ifdef CONFIG_PAX_SEGMEXEC
91430 + pax_mirror_huge_pte(vma, address, page);
91431 +#endif
91432 +
91433 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
91434 /* Optimization, do the COW without a second fault */
91435 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
91436 @@ -2908,6 +2942,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91437 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
91438 struct hstate *h = hstate_vma(vma);
91439
91440 +#ifdef CONFIG_PAX_SEGMEXEC
91441 + struct vm_area_struct *vma_m;
91442 +#endif
91443 +
91444 address &= huge_page_mask(h);
91445
91446 ptep = huge_pte_offset(mm, address);
91447 @@ -2921,6 +2959,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91448 VM_FAULT_SET_HINDEX(hstate_index(h));
91449 }
91450
91451 +#ifdef CONFIG_PAX_SEGMEXEC
91452 + vma_m = pax_find_mirror_vma(vma);
91453 + if (vma_m) {
91454 + unsigned long address_m;
91455 +
91456 + if (vma->vm_start > vma_m->vm_start) {
91457 + address_m = address;
91458 + address -= SEGMEXEC_TASK_SIZE;
91459 + vma = vma_m;
91460 + h = hstate_vma(vma);
91461 + } else
91462 + address_m = address + SEGMEXEC_TASK_SIZE;
91463 +
91464 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
91465 + return VM_FAULT_OOM;
91466 + address_m &= HPAGE_MASK;
91467 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
91468 + }
91469 +#endif
91470 +
91471 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
91472 if (!ptep)
91473 return VM_FAULT_OOM;
91474 diff --git a/mm/internal.h b/mm/internal.h
91475 index 29e1e76..fc3ff04 100644
91476 --- a/mm/internal.h
91477 +++ b/mm/internal.h
91478 @@ -94,6 +94,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
91479 * in mm/page_alloc.c
91480 */
91481 extern void __free_pages_bootmem(struct page *page, unsigned int order);
91482 +extern void free_compound_page(struct page *page);
91483 extern void prep_compound_page(struct page *page, unsigned long order);
91484 #ifdef CONFIG_MEMORY_FAILURE
91485 extern bool is_free_buddy_page(struct page *page);
91486 @@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
91487
91488 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
91489 unsigned long, unsigned long,
91490 - unsigned long, unsigned long);
91491 + unsigned long, unsigned long) __intentional_overflow(-1);
91492
91493 extern void set_pageblock_order(void);
91494 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
91495 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
91496 index 31f01c5..7015178 100644
91497 --- a/mm/kmemleak.c
91498 +++ b/mm/kmemleak.c
91499 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
91500
91501 for (i = 0; i < object->trace_len; i++) {
91502 void *ptr = (void *)object->trace[i];
91503 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
91504 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
91505 }
91506 }
91507
91508 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
91509 return -ENOMEM;
91510 }
91511
91512 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
91513 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
91514 &kmemleak_fops);
91515 if (!dentry)
91516 pr_warning("Failed to create the debugfs kmemleak file\n");
91517 diff --git a/mm/maccess.c b/mm/maccess.c
91518 index d53adf9..03a24bf 100644
91519 --- a/mm/maccess.c
91520 +++ b/mm/maccess.c
91521 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
91522 set_fs(KERNEL_DS);
91523 pagefault_disable();
91524 ret = __copy_from_user_inatomic(dst,
91525 - (__force const void __user *)src, size);
91526 + (const void __force_user *)src, size);
91527 pagefault_enable();
91528 set_fs(old_fs);
91529
91530 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
91531
91532 set_fs(KERNEL_DS);
91533 pagefault_disable();
91534 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
91535 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
91536 pagefault_enable();
91537 set_fs(old_fs);
91538
91539 diff --git a/mm/madvise.c b/mm/madvise.c
91540 index 539eeb9..e24a987 100644
91541 --- a/mm/madvise.c
91542 +++ b/mm/madvise.c
91543 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
91544 pgoff_t pgoff;
91545 unsigned long new_flags = vma->vm_flags;
91546
91547 +#ifdef CONFIG_PAX_SEGMEXEC
91548 + struct vm_area_struct *vma_m;
91549 +#endif
91550 +
91551 switch (behavior) {
91552 case MADV_NORMAL:
91553 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
91554 @@ -126,6 +130,13 @@ success:
91555 /*
91556 * vm_flags is protected by the mmap_sem held in write mode.
91557 */
91558 +
91559 +#ifdef CONFIG_PAX_SEGMEXEC
91560 + vma_m = pax_find_mirror_vma(vma);
91561 + if (vma_m)
91562 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
91563 +#endif
91564 +
91565 vma->vm_flags = new_flags;
91566
91567 out:
91568 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91569 struct vm_area_struct **prev,
91570 unsigned long start, unsigned long end)
91571 {
91572 +
91573 +#ifdef CONFIG_PAX_SEGMEXEC
91574 + struct vm_area_struct *vma_m;
91575 +#endif
91576 +
91577 *prev = vma;
91578 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
91579 return -EINVAL;
91580 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91581 zap_page_range(vma, start, end - start, &details);
91582 } else
91583 zap_page_range(vma, start, end - start, NULL);
91584 +
91585 +#ifdef CONFIG_PAX_SEGMEXEC
91586 + vma_m = pax_find_mirror_vma(vma);
91587 + if (vma_m) {
91588 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
91589 + struct zap_details details = {
91590 + .nonlinear_vma = vma_m,
91591 + .last_index = ULONG_MAX,
91592 + };
91593 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
91594 + } else
91595 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
91596 + }
91597 +#endif
91598 +
91599 return 0;
91600 }
91601
91602 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
91603 if (end < start)
91604 return error;
91605
91606 +#ifdef CONFIG_PAX_SEGMEXEC
91607 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
91608 + if (end > SEGMEXEC_TASK_SIZE)
91609 + return error;
91610 + } else
91611 +#endif
91612 +
91613 + if (end > TASK_SIZE)
91614 + return error;
91615 +
91616 error = 0;
91617 if (end == start)
91618 return error;
91619 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
91620 index 90002ea..db1452d 100644
91621 --- a/mm/memory-failure.c
91622 +++ b/mm/memory-failure.c
91623 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
91624
91625 int sysctl_memory_failure_recovery __read_mostly = 1;
91626
91627 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91628 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91629
91630 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
91631
91632 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
91633 pfn, t->comm, t->pid);
91634 si.si_signo = SIGBUS;
91635 si.si_errno = 0;
91636 - si.si_addr = (void *)addr;
91637 + si.si_addr = (void __user *)addr;
91638 #ifdef __ARCH_SI_TRAPNO
91639 si.si_trapno = trapno;
91640 #endif
91641 @@ -762,7 +762,7 @@ static struct page_state {
91642 unsigned long res;
91643 char *msg;
91644 int (*action)(struct page *p, unsigned long pfn);
91645 -} error_states[] = {
91646 +} __do_const error_states[] = {
91647 { reserved, reserved, "reserved kernel", me_kernel },
91648 /*
91649 * free pages are specially detected outside this table:
91650 @@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91651 nr_pages = 1 << compound_order(hpage);
91652 else /* normal page or thp */
91653 nr_pages = 1;
91654 - atomic_long_add(nr_pages, &num_poisoned_pages);
91655 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
91656
91657 /*
91658 * We need/can do nothing about count=0 pages.
91659 @@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91660 if (!PageHWPoison(hpage)
91661 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
91662 || (p != hpage && TestSetPageHWPoison(hpage))) {
91663 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91664 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91665 return 0;
91666 }
91667 set_page_hwpoison_huge_page(hpage);
91668 @@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91669 }
91670 if (hwpoison_filter(p)) {
91671 if (TestClearPageHWPoison(p))
91672 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91673 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91674 unlock_page(hpage);
91675 put_page(hpage);
91676 return 0;
91677 @@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
91678 return 0;
91679 }
91680 if (TestClearPageHWPoison(p))
91681 - atomic_long_dec(&num_poisoned_pages);
91682 + atomic_long_dec_unchecked(&num_poisoned_pages);
91683 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
91684 return 0;
91685 }
91686 @@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
91687 */
91688 if (TestClearPageHWPoison(page)) {
91689 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
91690 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91691 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91692 freeit = 1;
91693 if (PageHuge(page))
91694 clear_page_hwpoison_huge_page(page);
91695 @@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
91696 if (PageHuge(page)) {
91697 set_page_hwpoison_huge_page(hpage);
91698 dequeue_hwpoisoned_huge_page(hpage);
91699 - atomic_long_add(1 << compound_order(hpage),
91700 + atomic_long_add_unchecked(1 << compound_order(hpage),
91701 &num_poisoned_pages);
91702 } else {
91703 SetPageHWPoison(page);
91704 - atomic_long_inc(&num_poisoned_pages);
91705 + atomic_long_inc_unchecked(&num_poisoned_pages);
91706 }
91707 }
91708 return ret;
91709 @@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
91710 put_page(page);
91711 pr_info("soft_offline: %#lx: invalidated\n", pfn);
91712 SetPageHWPoison(page);
91713 - atomic_long_inc(&num_poisoned_pages);
91714 + atomic_long_inc_unchecked(&num_poisoned_pages);
91715 return 0;
91716 }
91717
91718 @@ -1616,7 +1616,7 @@ static int __soft_offline_page(struct page *page, int flags)
91719 if (!is_free_buddy_page(page))
91720 pr_info("soft offline: %#lx: page leaked\n",
91721 pfn);
91722 - atomic_long_inc(&num_poisoned_pages);
91723 + atomic_long_inc_unchecked(&num_poisoned_pages);
91724 }
91725 } else {
91726 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
91727 @@ -1690,11 +1690,11 @@ int soft_offline_page(struct page *page, int flags)
91728 if (PageHuge(page)) {
91729 set_page_hwpoison_huge_page(hpage);
91730 dequeue_hwpoisoned_huge_page(hpage);
91731 - atomic_long_add(1 << compound_order(hpage),
91732 + atomic_long_add_unchecked(1 << compound_order(hpage),
91733 &num_poisoned_pages);
91734 } else {
91735 SetPageHWPoison(page);
91736 - atomic_long_inc(&num_poisoned_pages);
91737 + atomic_long_inc_unchecked(&num_poisoned_pages);
91738 }
91739 }
91740 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
91741 diff --git a/mm/memory.c b/mm/memory.c
91742 index 22dfa61..e8a9ac2 100644
91743 --- a/mm/memory.c
91744 +++ b/mm/memory.c
91745 @@ -403,6 +403,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
91746 free_pte_range(tlb, pmd, addr);
91747 } while (pmd++, addr = next, addr != end);
91748
91749 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
91750 start &= PUD_MASK;
91751 if (start < floor)
91752 return;
91753 @@ -417,6 +418,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
91754 pmd = pmd_offset(pud, start);
91755 pud_clear(pud);
91756 pmd_free_tlb(tlb, pmd, start);
91757 +#endif
91758 +
91759 }
91760
91761 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91762 @@ -436,6 +439,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91763 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
91764 } while (pud++, addr = next, addr != end);
91765
91766 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
91767 start &= PGDIR_MASK;
91768 if (start < floor)
91769 return;
91770 @@ -450,6 +454,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91771 pud = pud_offset(pgd, start);
91772 pgd_clear(pgd);
91773 pud_free_tlb(tlb, pud, start);
91774 +#endif
91775 +
91776 }
91777
91778 /*
91779 @@ -1636,12 +1642,6 @@ no_page_table:
91780 return page;
91781 }
91782
91783 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
91784 -{
91785 - return stack_guard_page_start(vma, addr) ||
91786 - stack_guard_page_end(vma, addr+PAGE_SIZE);
91787 -}
91788 -
91789 /**
91790 * __get_user_pages() - pin user pages in memory
91791 * @tsk: task_struct of target task
91792 @@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91793
91794 i = 0;
91795
91796 - do {
91797 + while (nr_pages) {
91798 struct vm_area_struct *vma;
91799
91800 - vma = find_extend_vma(mm, start);
91801 + vma = find_vma(mm, start);
91802 if (!vma && in_gate_area(mm, start)) {
91803 unsigned long pg = start & PAGE_MASK;
91804 pgd_t *pgd;
91805 @@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91806 goto next_page;
91807 }
91808
91809 - if (!vma ||
91810 + if (!vma || start < vma->vm_start ||
91811 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
91812 !(vm_flags & vma->vm_flags))
91813 return i ? : -EFAULT;
91814 @@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91815 int ret;
91816 unsigned int fault_flags = 0;
91817
91818 - /* For mlock, just skip the stack guard page. */
91819 - if (foll_flags & FOLL_MLOCK) {
91820 - if (stack_guard_page(vma, start))
91821 - goto next_page;
91822 - }
91823 if (foll_flags & FOLL_WRITE)
91824 fault_flags |= FAULT_FLAG_WRITE;
91825 if (nonblocking)
91826 @@ -1893,7 +1888,7 @@ next_page:
91827 start += page_increm * PAGE_SIZE;
91828 nr_pages -= page_increm;
91829 } while (nr_pages && start < vma->vm_end);
91830 - } while (nr_pages);
91831 + }
91832 return i;
91833 }
91834 EXPORT_SYMBOL(__get_user_pages);
91835 @@ -2100,6 +2095,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
91836 page_add_file_rmap(page);
91837 set_pte_at(mm, addr, pte, mk_pte(page, prot));
91838
91839 +#ifdef CONFIG_PAX_SEGMEXEC
91840 + pax_mirror_file_pte(vma, addr, page, ptl);
91841 +#endif
91842 +
91843 retval = 0;
91844 pte_unmap_unlock(pte, ptl);
91845 return retval;
91846 @@ -2144,9 +2143,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
91847 if (!page_count(page))
91848 return -EINVAL;
91849 if (!(vma->vm_flags & VM_MIXEDMAP)) {
91850 +
91851 +#ifdef CONFIG_PAX_SEGMEXEC
91852 + struct vm_area_struct *vma_m;
91853 +#endif
91854 +
91855 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
91856 BUG_ON(vma->vm_flags & VM_PFNMAP);
91857 vma->vm_flags |= VM_MIXEDMAP;
91858 +
91859 +#ifdef CONFIG_PAX_SEGMEXEC
91860 + vma_m = pax_find_mirror_vma(vma);
91861 + if (vma_m)
91862 + vma_m->vm_flags |= VM_MIXEDMAP;
91863 +#endif
91864 +
91865 }
91866 return insert_page(vma, addr, page, vma->vm_page_prot);
91867 }
91868 @@ -2229,6 +2240,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
91869 unsigned long pfn)
91870 {
91871 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
91872 + BUG_ON(vma->vm_mirror);
91873
91874 if (addr < vma->vm_start || addr >= vma->vm_end)
91875 return -EFAULT;
91876 @@ -2476,7 +2488,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
91877
91878 BUG_ON(pud_huge(*pud));
91879
91880 - pmd = pmd_alloc(mm, pud, addr);
91881 + pmd = (mm == &init_mm) ?
91882 + pmd_alloc_kernel(mm, pud, addr) :
91883 + pmd_alloc(mm, pud, addr);
91884 if (!pmd)
91885 return -ENOMEM;
91886 do {
91887 @@ -2496,7 +2510,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
91888 unsigned long next;
91889 int err;
91890
91891 - pud = pud_alloc(mm, pgd, addr);
91892 + pud = (mm == &init_mm) ?
91893 + pud_alloc_kernel(mm, pgd, addr) :
91894 + pud_alloc(mm, pgd, addr);
91895 if (!pud)
91896 return -ENOMEM;
91897 do {
91898 @@ -2586,6 +2602,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
91899 copy_user_highpage(dst, src, va, vma);
91900 }
91901
91902 +#ifdef CONFIG_PAX_SEGMEXEC
91903 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
91904 +{
91905 + struct mm_struct *mm = vma->vm_mm;
91906 + spinlock_t *ptl;
91907 + pte_t *pte, entry;
91908 +
91909 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
91910 + entry = *pte;
91911 + if (!pte_present(entry)) {
91912 + if (!pte_none(entry)) {
91913 + BUG_ON(pte_file(entry));
91914 + free_swap_and_cache(pte_to_swp_entry(entry));
91915 + pte_clear_not_present_full(mm, address, pte, 0);
91916 + }
91917 + } else {
91918 + struct page *page;
91919 +
91920 + flush_cache_page(vma, address, pte_pfn(entry));
91921 + entry = ptep_clear_flush(vma, address, pte);
91922 + BUG_ON(pte_dirty(entry));
91923 + page = vm_normal_page(vma, address, entry);
91924 + if (page) {
91925 + update_hiwater_rss(mm);
91926 + if (PageAnon(page))
91927 + dec_mm_counter_fast(mm, MM_ANONPAGES);
91928 + else
91929 + dec_mm_counter_fast(mm, MM_FILEPAGES);
91930 + page_remove_rmap(page);
91931 + page_cache_release(page);
91932 + }
91933 + }
91934 + pte_unmap_unlock(pte, ptl);
91935 +}
91936 +
91937 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
91938 + *
91939 + * the ptl of the lower mapped page is held on entry and is not released on exit
91940 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
91941 + */
91942 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
91943 +{
91944 + struct mm_struct *mm = vma->vm_mm;
91945 + unsigned long address_m;
91946 + spinlock_t *ptl_m;
91947 + struct vm_area_struct *vma_m;
91948 + pmd_t *pmd_m;
91949 + pte_t *pte_m, entry_m;
91950 +
91951 + BUG_ON(!page_m || !PageAnon(page_m));
91952 +
91953 + vma_m = pax_find_mirror_vma(vma);
91954 + if (!vma_m)
91955 + return;
91956 +
91957 + BUG_ON(!PageLocked(page_m));
91958 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91959 + address_m = address + SEGMEXEC_TASK_SIZE;
91960 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
91961 + pte_m = pte_offset_map(pmd_m, address_m);
91962 + ptl_m = pte_lockptr(mm, pmd_m);
91963 + if (ptl != ptl_m) {
91964 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
91965 + if (!pte_none(*pte_m))
91966 + goto out;
91967 + }
91968 +
91969 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
91970 + page_cache_get(page_m);
91971 + page_add_anon_rmap(page_m, vma_m, address_m);
91972 + inc_mm_counter_fast(mm, MM_ANONPAGES);
91973 + set_pte_at(mm, address_m, pte_m, entry_m);
91974 + update_mmu_cache(vma_m, address_m, pte_m);
91975 +out:
91976 + if (ptl != ptl_m)
91977 + spin_unlock(ptl_m);
91978 + pte_unmap(pte_m);
91979 + unlock_page(page_m);
91980 +}
91981 +
91982 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
91983 +{
91984 + struct mm_struct *mm = vma->vm_mm;
91985 + unsigned long address_m;
91986 + spinlock_t *ptl_m;
91987 + struct vm_area_struct *vma_m;
91988 + pmd_t *pmd_m;
91989 + pte_t *pte_m, entry_m;
91990 +
91991 + BUG_ON(!page_m || PageAnon(page_m));
91992 +
91993 + vma_m = pax_find_mirror_vma(vma);
91994 + if (!vma_m)
91995 + return;
91996 +
91997 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91998 + address_m = address + SEGMEXEC_TASK_SIZE;
91999 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92000 + pte_m = pte_offset_map(pmd_m, address_m);
92001 + ptl_m = pte_lockptr(mm, pmd_m);
92002 + if (ptl != ptl_m) {
92003 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92004 + if (!pte_none(*pte_m))
92005 + goto out;
92006 + }
92007 +
92008 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92009 + page_cache_get(page_m);
92010 + page_add_file_rmap(page_m);
92011 + inc_mm_counter_fast(mm, MM_FILEPAGES);
92012 + set_pte_at(mm, address_m, pte_m, entry_m);
92013 + update_mmu_cache(vma_m, address_m, pte_m);
92014 +out:
92015 + if (ptl != ptl_m)
92016 + spin_unlock(ptl_m);
92017 + pte_unmap(pte_m);
92018 +}
92019 +
92020 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
92021 +{
92022 + struct mm_struct *mm = vma->vm_mm;
92023 + unsigned long address_m;
92024 + spinlock_t *ptl_m;
92025 + struct vm_area_struct *vma_m;
92026 + pmd_t *pmd_m;
92027 + pte_t *pte_m, entry_m;
92028 +
92029 + vma_m = pax_find_mirror_vma(vma);
92030 + if (!vma_m)
92031 + return;
92032 +
92033 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92034 + address_m = address + SEGMEXEC_TASK_SIZE;
92035 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92036 + pte_m = pte_offset_map(pmd_m, address_m);
92037 + ptl_m = pte_lockptr(mm, pmd_m);
92038 + if (ptl != ptl_m) {
92039 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92040 + if (!pte_none(*pte_m))
92041 + goto out;
92042 + }
92043 +
92044 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
92045 + set_pte_at(mm, address_m, pte_m, entry_m);
92046 +out:
92047 + if (ptl != ptl_m)
92048 + spin_unlock(ptl_m);
92049 + pte_unmap(pte_m);
92050 +}
92051 +
92052 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
92053 +{
92054 + struct page *page_m;
92055 + pte_t entry;
92056 +
92057 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
92058 + goto out;
92059 +
92060 + entry = *pte;
92061 + page_m = vm_normal_page(vma, address, entry);
92062 + if (!page_m)
92063 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
92064 + else if (PageAnon(page_m)) {
92065 + if (pax_find_mirror_vma(vma)) {
92066 + pte_unmap_unlock(pte, ptl);
92067 + lock_page(page_m);
92068 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
92069 + if (pte_same(entry, *pte))
92070 + pax_mirror_anon_pte(vma, address, page_m, ptl);
92071 + else
92072 + unlock_page(page_m);
92073 + }
92074 + } else
92075 + pax_mirror_file_pte(vma, address, page_m, ptl);
92076 +
92077 +out:
92078 + pte_unmap_unlock(pte, ptl);
92079 +}
92080 +#endif
92081 +
92082 /*
92083 * This routine handles present pages, when users try to write
92084 * to a shared page. It is done by copying the page to a new address
92085 @@ -2810,6 +3006,12 @@ gotten:
92086 */
92087 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92088 if (likely(pte_same(*page_table, orig_pte))) {
92089 +
92090 +#ifdef CONFIG_PAX_SEGMEXEC
92091 + if (pax_find_mirror_vma(vma))
92092 + BUG_ON(!trylock_page(new_page));
92093 +#endif
92094 +
92095 if (old_page) {
92096 if (!PageAnon(old_page)) {
92097 dec_mm_counter_fast(mm, MM_FILEPAGES);
92098 @@ -2861,6 +3063,10 @@ gotten:
92099 page_remove_rmap(old_page);
92100 }
92101
92102 +#ifdef CONFIG_PAX_SEGMEXEC
92103 + pax_mirror_anon_pte(vma, address, new_page, ptl);
92104 +#endif
92105 +
92106 /* Free the old page.. */
92107 new_page = old_page;
92108 ret |= VM_FAULT_WRITE;
92109 @@ -3138,6 +3344,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92110 swap_free(entry);
92111 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
92112 try_to_free_swap(page);
92113 +
92114 +#ifdef CONFIG_PAX_SEGMEXEC
92115 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
92116 +#endif
92117 +
92118 unlock_page(page);
92119 if (page != swapcache) {
92120 /*
92121 @@ -3161,6 +3372,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92122
92123 /* No need to invalidate - it was non-present before */
92124 update_mmu_cache(vma, address, page_table);
92125 +
92126 +#ifdef CONFIG_PAX_SEGMEXEC
92127 + pax_mirror_anon_pte(vma, address, page, ptl);
92128 +#endif
92129 +
92130 unlock:
92131 pte_unmap_unlock(page_table, ptl);
92132 out:
92133 @@ -3180,40 +3396,6 @@ out_release:
92134 }
92135
92136 /*
92137 - * This is like a special single-page "expand_{down|up}wards()",
92138 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
92139 - * doesn't hit another vma.
92140 - */
92141 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
92142 -{
92143 - address &= PAGE_MASK;
92144 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
92145 - struct vm_area_struct *prev = vma->vm_prev;
92146 -
92147 - /*
92148 - * Is there a mapping abutting this one below?
92149 - *
92150 - * That's only ok if it's the same stack mapping
92151 - * that has gotten split..
92152 - */
92153 - if (prev && prev->vm_end == address)
92154 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
92155 -
92156 - expand_downwards(vma, address - PAGE_SIZE);
92157 - }
92158 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
92159 - struct vm_area_struct *next = vma->vm_next;
92160 -
92161 - /* As VM_GROWSDOWN but s/below/above/ */
92162 - if (next && next->vm_start == address + PAGE_SIZE)
92163 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
92164 -
92165 - expand_upwards(vma, address + PAGE_SIZE);
92166 - }
92167 - return 0;
92168 -}
92169 -
92170 -/*
92171 * We enter with non-exclusive mmap_sem (to exclude vma changes,
92172 * but allow concurrent faults), and pte mapped but not yet locked.
92173 * We return with mmap_sem still held, but pte unmapped and unlocked.
92174 @@ -3222,27 +3404,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92175 unsigned long address, pte_t *page_table, pmd_t *pmd,
92176 unsigned int flags)
92177 {
92178 - struct page *page;
92179 + struct page *page = NULL;
92180 spinlock_t *ptl;
92181 pte_t entry;
92182
92183 - pte_unmap(page_table);
92184 -
92185 - /* Check if we need to add a guard page to the stack */
92186 - if (check_stack_guard_page(vma, address) < 0)
92187 - return VM_FAULT_SIGBUS;
92188 -
92189 - /* Use the zero-page for reads */
92190 if (!(flags & FAULT_FLAG_WRITE)) {
92191 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
92192 vma->vm_page_prot));
92193 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92194 + ptl = pte_lockptr(mm, pmd);
92195 + spin_lock(ptl);
92196 if (!pte_none(*page_table))
92197 goto unlock;
92198 goto setpte;
92199 }
92200
92201 /* Allocate our own private page. */
92202 + pte_unmap(page_table);
92203 +
92204 if (unlikely(anon_vma_prepare(vma)))
92205 goto oom;
92206 page = alloc_zeroed_user_highpage_movable(vma, address);
92207 @@ -3266,6 +3444,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92208 if (!pte_none(*page_table))
92209 goto release;
92210
92211 +#ifdef CONFIG_PAX_SEGMEXEC
92212 + if (pax_find_mirror_vma(vma))
92213 + BUG_ON(!trylock_page(page));
92214 +#endif
92215 +
92216 inc_mm_counter_fast(mm, MM_ANONPAGES);
92217 page_add_new_anon_rmap(page, vma, address);
92218 setpte:
92219 @@ -3273,6 +3456,12 @@ setpte:
92220
92221 /* No need to invalidate - it was non-present before */
92222 update_mmu_cache(vma, address, page_table);
92223 +
92224 +#ifdef CONFIG_PAX_SEGMEXEC
92225 + if (page)
92226 + pax_mirror_anon_pte(vma, address, page, ptl);
92227 +#endif
92228 +
92229 unlock:
92230 pte_unmap_unlock(page_table, ptl);
92231 return 0;
92232 @@ -3417,6 +3606,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92233 */
92234 /* Only go through if we didn't race with anybody else... */
92235 if (likely(pte_same(*page_table, orig_pte))) {
92236 +
92237 +#ifdef CONFIG_PAX_SEGMEXEC
92238 + if (anon && pax_find_mirror_vma(vma))
92239 + BUG_ON(!trylock_page(page));
92240 +#endif
92241 +
92242 flush_icache_page(vma, page);
92243 entry = mk_pte(page, vma->vm_page_prot);
92244 if (flags & FAULT_FLAG_WRITE)
92245 @@ -3438,6 +3633,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92246
92247 /* no need to invalidate: a not-present page won't be cached */
92248 update_mmu_cache(vma, address, page_table);
92249 +
92250 +#ifdef CONFIG_PAX_SEGMEXEC
92251 + if (anon)
92252 + pax_mirror_anon_pte(vma, address, page, ptl);
92253 + else
92254 + pax_mirror_file_pte(vma, address, page, ptl);
92255 +#endif
92256 +
92257 } else {
92258 if (cow_page)
92259 mem_cgroup_uncharge_page(cow_page);
92260 @@ -3685,6 +3888,12 @@ static int handle_pte_fault(struct mm_struct *mm,
92261 if (flags & FAULT_FLAG_WRITE)
92262 flush_tlb_fix_spurious_fault(vma, address);
92263 }
92264 +
92265 +#ifdef CONFIG_PAX_SEGMEXEC
92266 + pax_mirror_pte(vma, address, pte, pmd, ptl);
92267 + return 0;
92268 +#endif
92269 +
92270 unlock:
92271 pte_unmap_unlock(pte, ptl);
92272 return 0;
92273 @@ -3701,9 +3910,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92274 pmd_t *pmd;
92275 pte_t *pte;
92276
92277 +#ifdef CONFIG_PAX_SEGMEXEC
92278 + struct vm_area_struct *vma_m;
92279 +#endif
92280 +
92281 if (unlikely(is_vm_hugetlb_page(vma)))
92282 return hugetlb_fault(mm, vma, address, flags);
92283
92284 +#ifdef CONFIG_PAX_SEGMEXEC
92285 + vma_m = pax_find_mirror_vma(vma);
92286 + if (vma_m) {
92287 + unsigned long address_m;
92288 + pgd_t *pgd_m;
92289 + pud_t *pud_m;
92290 + pmd_t *pmd_m;
92291 +
92292 + if (vma->vm_start > vma_m->vm_start) {
92293 + address_m = address;
92294 + address -= SEGMEXEC_TASK_SIZE;
92295 + vma = vma_m;
92296 + } else
92297 + address_m = address + SEGMEXEC_TASK_SIZE;
92298 +
92299 + pgd_m = pgd_offset(mm, address_m);
92300 + pud_m = pud_alloc(mm, pgd_m, address_m);
92301 + if (!pud_m)
92302 + return VM_FAULT_OOM;
92303 + pmd_m = pmd_alloc(mm, pud_m, address_m);
92304 + if (!pmd_m)
92305 + return VM_FAULT_OOM;
92306 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
92307 + return VM_FAULT_OOM;
92308 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
92309 + }
92310 +#endif
92311 +
92312 pgd = pgd_offset(mm, address);
92313 pud = pud_alloc(mm, pgd, address);
92314 if (!pud)
92315 @@ -3834,6 +4075,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92316 spin_unlock(&mm->page_table_lock);
92317 return 0;
92318 }
92319 +
92320 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92321 +{
92322 + pud_t *new = pud_alloc_one(mm, address);
92323 + if (!new)
92324 + return -ENOMEM;
92325 +
92326 + smp_wmb(); /* See comment in __pte_alloc */
92327 +
92328 + spin_lock(&mm->page_table_lock);
92329 + if (pgd_present(*pgd)) /* Another has populated it */
92330 + pud_free(mm, new);
92331 + else
92332 + pgd_populate_kernel(mm, pgd, new);
92333 + spin_unlock(&mm->page_table_lock);
92334 + return 0;
92335 +}
92336 #endif /* __PAGETABLE_PUD_FOLDED */
92337
92338 #ifndef __PAGETABLE_PMD_FOLDED
92339 @@ -3864,6 +4122,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
92340 spin_unlock(&mm->page_table_lock);
92341 return 0;
92342 }
92343 +
92344 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
92345 +{
92346 + pmd_t *new = pmd_alloc_one(mm, address);
92347 + if (!new)
92348 + return -ENOMEM;
92349 +
92350 + smp_wmb(); /* See comment in __pte_alloc */
92351 +
92352 + spin_lock(&mm->page_table_lock);
92353 +#ifndef __ARCH_HAS_4LEVEL_HACK
92354 + if (pud_present(*pud)) /* Another has populated it */
92355 + pmd_free(mm, new);
92356 + else
92357 + pud_populate_kernel(mm, pud, new);
92358 +#else
92359 + if (pgd_present(*pud)) /* Another has populated it */
92360 + pmd_free(mm, new);
92361 + else
92362 + pgd_populate_kernel(mm, pud, new);
92363 +#endif /* __ARCH_HAS_4LEVEL_HACK */
92364 + spin_unlock(&mm->page_table_lock);
92365 + return 0;
92366 +}
92367 #endif /* __PAGETABLE_PMD_FOLDED */
92368
92369 #if !defined(__HAVE_ARCH_GATE_AREA)
92370 @@ -3877,7 +4159,7 @@ static int __init gate_vma_init(void)
92371 gate_vma.vm_start = FIXADDR_USER_START;
92372 gate_vma.vm_end = FIXADDR_USER_END;
92373 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
92374 - gate_vma.vm_page_prot = __P101;
92375 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
92376
92377 return 0;
92378 }
92379 @@ -4011,8 +4293,8 @@ out:
92380 return ret;
92381 }
92382
92383 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92384 - void *buf, int len, int write)
92385 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92386 + void *buf, size_t len, int write)
92387 {
92388 resource_size_t phys_addr;
92389 unsigned long prot = 0;
92390 @@ -4038,8 +4320,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
92391 * Access another process' address space as given in mm. If non-NULL, use the
92392 * given task for page fault accounting.
92393 */
92394 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92395 - unsigned long addr, void *buf, int len, int write)
92396 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92397 + unsigned long addr, void *buf, size_t len, int write)
92398 {
92399 struct vm_area_struct *vma;
92400 void *old_buf = buf;
92401 @@ -4047,7 +4329,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92402 down_read(&mm->mmap_sem);
92403 /* ignore errors, just check how much was successfully transferred */
92404 while (len) {
92405 - int bytes, ret, offset;
92406 + ssize_t bytes, ret, offset;
92407 void *maddr;
92408 struct page *page = NULL;
92409
92410 @@ -4106,8 +4388,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92411 *
92412 * The caller must hold a reference on @mm.
92413 */
92414 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92415 - void *buf, int len, int write)
92416 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
92417 + void *buf, size_t len, int write)
92418 {
92419 return __access_remote_vm(NULL, mm, addr, buf, len, write);
92420 }
92421 @@ -4117,11 +4399,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92422 * Source/target buffer must be kernel space,
92423 * Do not walk the page table directly, use get_user_pages
92424 */
92425 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
92426 - void *buf, int len, int write)
92427 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
92428 + void *buf, size_t len, int write)
92429 {
92430 struct mm_struct *mm;
92431 - int ret;
92432 + ssize_t ret;
92433
92434 mm = get_task_mm(tsk);
92435 if (!mm)
92436 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
92437 index ae3c8f3..fa4ee8e 100644
92438 --- a/mm/mempolicy.c
92439 +++ b/mm/mempolicy.c
92440 @@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92441 unsigned long vmstart;
92442 unsigned long vmend;
92443
92444 +#ifdef CONFIG_PAX_SEGMEXEC
92445 + struct vm_area_struct *vma_m;
92446 +#endif
92447 +
92448 vma = find_vma(mm, start);
92449 if (!vma || vma->vm_start > start)
92450 return -EFAULT;
92451 @@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92452 err = vma_replace_policy(vma, new_pol);
92453 if (err)
92454 goto out;
92455 +
92456 +#ifdef CONFIG_PAX_SEGMEXEC
92457 + vma_m = pax_find_mirror_vma(vma);
92458 + if (vma_m) {
92459 + err = vma_replace_policy(vma_m, new_pol);
92460 + if (err)
92461 + goto out;
92462 + }
92463 +#endif
92464 +
92465 }
92466
92467 out:
92468 @@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
92469
92470 if (end < start)
92471 return -EINVAL;
92472 +
92473 +#ifdef CONFIG_PAX_SEGMEXEC
92474 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92475 + if (end > SEGMEXEC_TASK_SIZE)
92476 + return -EINVAL;
92477 + } else
92478 +#endif
92479 +
92480 + if (end > TASK_SIZE)
92481 + return -EINVAL;
92482 +
92483 if (end == start)
92484 return 0;
92485
92486 @@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92487 */
92488 tcred = __task_cred(task);
92489 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92490 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92491 - !capable(CAP_SYS_NICE)) {
92492 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92493 rcu_read_unlock();
92494 err = -EPERM;
92495 goto out_put;
92496 @@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92497 goto out;
92498 }
92499
92500 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
92501 + if (mm != current->mm &&
92502 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
92503 + mmput(mm);
92504 + err = -EPERM;
92505 + goto out;
92506 + }
92507 +#endif
92508 +
92509 err = do_migrate_pages(mm, old, new,
92510 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
92511
92512 diff --git a/mm/migrate.c b/mm/migrate.c
92513 index bed4880..a493f67 100644
92514 --- a/mm/migrate.c
92515 +++ b/mm/migrate.c
92516 @@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
92517 */
92518 tcred = __task_cred(task);
92519 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92520 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92521 - !capable(CAP_SYS_NICE)) {
92522 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92523 rcu_read_unlock();
92524 err = -EPERM;
92525 goto out;
92526 diff --git a/mm/mlock.c b/mm/mlock.c
92527 index 4e1a6816..9683079 100644
92528 --- a/mm/mlock.c
92529 +++ b/mm/mlock.c
92530 @@ -14,6 +14,7 @@
92531 #include <linux/pagevec.h>
92532 #include <linux/mempolicy.h>
92533 #include <linux/syscalls.h>
92534 +#include <linux/security.h>
92535 #include <linux/sched.h>
92536 #include <linux/export.h>
92537 #include <linux/rmap.h>
92538 @@ -604,7 +605,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
92539 {
92540 unsigned long nstart, end, tmp;
92541 struct vm_area_struct * vma, * prev;
92542 - int error;
92543 + int error = 0;
92544
92545 VM_BUG_ON(start & ~PAGE_MASK);
92546 VM_BUG_ON(len != PAGE_ALIGN(len));
92547 @@ -613,6 +614,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
92548 return -EINVAL;
92549 if (end == start)
92550 return 0;
92551 + if (end > TASK_SIZE)
92552 + return -EINVAL;
92553 +
92554 vma = find_vma(current->mm, start);
92555 if (!vma || vma->vm_start > start)
92556 return -ENOMEM;
92557 @@ -624,6 +628,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
92558 for (nstart = start ; ; ) {
92559 vm_flags_t newflags;
92560
92561 +#ifdef CONFIG_PAX_SEGMEXEC
92562 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92563 + break;
92564 +#endif
92565 +
92566 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
92567
92568 newflags = vma->vm_flags & ~VM_LOCKED;
92569 @@ -737,6 +746,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
92570 locked += current->mm->locked_vm;
92571
92572 /* check against resource limits */
92573 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
92574 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
92575 error = do_mlock(start, len, 1);
92576
92577 @@ -774,6 +784,11 @@ static int do_mlockall(int flags)
92578 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
92579 vm_flags_t newflags;
92580
92581 +#ifdef CONFIG_PAX_SEGMEXEC
92582 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92583 + break;
92584 +#endif
92585 +
92586 newflags = vma->vm_flags & ~VM_LOCKED;
92587 if (flags & MCL_CURRENT)
92588 newflags |= VM_LOCKED;
92589 @@ -805,8 +820,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
92590 lock_limit >>= PAGE_SHIFT;
92591
92592 ret = -ENOMEM;
92593 +
92594 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
92595 +
92596 down_write(&current->mm->mmap_sem);
92597 -
92598 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
92599 capable(CAP_IPC_LOCK))
92600 ret = do_mlockall(flags);
92601 diff --git a/mm/mmap.c b/mm/mmap.c
92602 index 20ff0c3..a9eda98 100644
92603 --- a/mm/mmap.c
92604 +++ b/mm/mmap.c
92605 @@ -36,6 +36,7 @@
92606 #include <linux/sched/sysctl.h>
92607 #include <linux/notifier.h>
92608 #include <linux/memory.h>
92609 +#include <linux/random.h>
92610
92611 #include <asm/uaccess.h>
92612 #include <asm/cacheflush.h>
92613 @@ -52,6 +53,16 @@
92614 #define arch_rebalance_pgtables(addr, len) (addr)
92615 #endif
92616
92617 +static inline void verify_mm_writelocked(struct mm_struct *mm)
92618 +{
92619 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
92620 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
92621 + up_read(&mm->mmap_sem);
92622 + BUG();
92623 + }
92624 +#endif
92625 +}
92626 +
92627 static void unmap_region(struct mm_struct *mm,
92628 struct vm_area_struct *vma, struct vm_area_struct *prev,
92629 unsigned long start, unsigned long end);
92630 @@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
92631 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
92632 *
92633 */
92634 -pgprot_t protection_map[16] = {
92635 +pgprot_t protection_map[16] __read_only = {
92636 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
92637 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
92638 };
92639
92640 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
92641 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
92642 {
92643 - return __pgprot(pgprot_val(protection_map[vm_flags &
92644 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
92645 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
92646 pgprot_val(arch_vm_get_page_prot(vm_flags)));
92647 +
92648 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92649 + if (!(__supported_pte_mask & _PAGE_NX) &&
92650 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
92651 + (vm_flags & (VM_READ | VM_WRITE)))
92652 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
92653 +#endif
92654 +
92655 + return prot;
92656 }
92657 EXPORT_SYMBOL(vm_get_page_prot);
92658
92659 @@ -90,6 +110,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
92660 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
92661 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
92662 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
92663 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
92664 /*
92665 * Make sure vm_committed_as in one cacheline and not cacheline shared with
92666 * other variables. It can be updated by several CPUs frequently.
92667 @@ -246,6 +267,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
92668 struct vm_area_struct *next = vma->vm_next;
92669
92670 might_sleep();
92671 + BUG_ON(vma->vm_mirror);
92672 if (vma->vm_ops && vma->vm_ops->close)
92673 vma->vm_ops->close(vma);
92674 if (vma->vm_file)
92675 @@ -290,6 +312,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
92676 * not page aligned -Ram Gupta
92677 */
92678 rlim = rlimit(RLIMIT_DATA);
92679 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
92680 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
92681 (mm->end_data - mm->start_data) > rlim)
92682 goto out;
92683 @@ -940,6 +963,12 @@ static int
92684 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
92685 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92686 {
92687 +
92688 +#ifdef CONFIG_PAX_SEGMEXEC
92689 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
92690 + return 0;
92691 +#endif
92692 +
92693 if (is_mergeable_vma(vma, file, vm_flags) &&
92694 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92695 if (vma->vm_pgoff == vm_pgoff)
92696 @@ -959,6 +988,12 @@ static int
92697 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92698 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92699 {
92700 +
92701 +#ifdef CONFIG_PAX_SEGMEXEC
92702 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
92703 + return 0;
92704 +#endif
92705 +
92706 if (is_mergeable_vma(vma, file, vm_flags) &&
92707 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92708 pgoff_t vm_pglen;
92709 @@ -1001,13 +1036,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92710 struct vm_area_struct *vma_merge(struct mm_struct *mm,
92711 struct vm_area_struct *prev, unsigned long addr,
92712 unsigned long end, unsigned long vm_flags,
92713 - struct anon_vma *anon_vma, struct file *file,
92714 + struct anon_vma *anon_vma, struct file *file,
92715 pgoff_t pgoff, struct mempolicy *policy)
92716 {
92717 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
92718 struct vm_area_struct *area, *next;
92719 int err;
92720
92721 +#ifdef CONFIG_PAX_SEGMEXEC
92722 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
92723 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
92724 +
92725 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
92726 +#endif
92727 +
92728 /*
92729 * We later require that vma->vm_flags == vm_flags,
92730 * so this tests vma->vm_flags & VM_SPECIAL, too.
92731 @@ -1023,6 +1065,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92732 if (next && next->vm_end == end) /* cases 6, 7, 8 */
92733 next = next->vm_next;
92734
92735 +#ifdef CONFIG_PAX_SEGMEXEC
92736 + if (prev)
92737 + prev_m = pax_find_mirror_vma(prev);
92738 + if (area)
92739 + area_m = pax_find_mirror_vma(area);
92740 + if (next)
92741 + next_m = pax_find_mirror_vma(next);
92742 +#endif
92743 +
92744 /*
92745 * Can it merge with the predecessor?
92746 */
92747 @@ -1042,9 +1093,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92748 /* cases 1, 6 */
92749 err = vma_adjust(prev, prev->vm_start,
92750 next->vm_end, prev->vm_pgoff, NULL);
92751 - } else /* cases 2, 5, 7 */
92752 +
92753 +#ifdef CONFIG_PAX_SEGMEXEC
92754 + if (!err && prev_m)
92755 + err = vma_adjust(prev_m, prev_m->vm_start,
92756 + next_m->vm_end, prev_m->vm_pgoff, NULL);
92757 +#endif
92758 +
92759 + } else { /* cases 2, 5, 7 */
92760 err = vma_adjust(prev, prev->vm_start,
92761 end, prev->vm_pgoff, NULL);
92762 +
92763 +#ifdef CONFIG_PAX_SEGMEXEC
92764 + if (!err && prev_m)
92765 + err = vma_adjust(prev_m, prev_m->vm_start,
92766 + end_m, prev_m->vm_pgoff, NULL);
92767 +#endif
92768 +
92769 + }
92770 if (err)
92771 return NULL;
92772 khugepaged_enter_vma_merge(prev);
92773 @@ -1058,12 +1124,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92774 mpol_equal(policy, vma_policy(next)) &&
92775 can_vma_merge_before(next, vm_flags,
92776 anon_vma, file, pgoff+pglen)) {
92777 - if (prev && addr < prev->vm_end) /* case 4 */
92778 + if (prev && addr < prev->vm_end) { /* case 4 */
92779 err = vma_adjust(prev, prev->vm_start,
92780 addr, prev->vm_pgoff, NULL);
92781 - else /* cases 3, 8 */
92782 +
92783 +#ifdef CONFIG_PAX_SEGMEXEC
92784 + if (!err && prev_m)
92785 + err = vma_adjust(prev_m, prev_m->vm_start,
92786 + addr_m, prev_m->vm_pgoff, NULL);
92787 +#endif
92788 +
92789 + } else { /* cases 3, 8 */
92790 err = vma_adjust(area, addr, next->vm_end,
92791 next->vm_pgoff - pglen, NULL);
92792 +
92793 +#ifdef CONFIG_PAX_SEGMEXEC
92794 + if (!err && area_m)
92795 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
92796 + next_m->vm_pgoff - pglen, NULL);
92797 +#endif
92798 +
92799 + }
92800 if (err)
92801 return NULL;
92802 khugepaged_enter_vma_merge(area);
92803 @@ -1172,8 +1253,10 @@ none:
92804 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
92805 struct file *file, long pages)
92806 {
92807 - const unsigned long stack_flags
92808 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
92809 +
92810 +#ifdef CONFIG_PAX_RANDMMAP
92811 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
92812 +#endif
92813
92814 mm->total_vm += pages;
92815
92816 @@ -1181,7 +1264,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
92817 mm->shared_vm += pages;
92818 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
92819 mm->exec_vm += pages;
92820 - } else if (flags & stack_flags)
92821 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
92822 mm->stack_vm += pages;
92823 }
92824 #endif /* CONFIG_PROC_FS */
92825 @@ -1211,6 +1294,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
92826 locked += mm->locked_vm;
92827 lock_limit = rlimit(RLIMIT_MEMLOCK);
92828 lock_limit >>= PAGE_SHIFT;
92829 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
92830 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
92831 return -EAGAIN;
92832 }
92833 @@ -1237,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92834 * (the exception is when the underlying filesystem is noexec
92835 * mounted, in which case we dont add PROT_EXEC.)
92836 */
92837 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
92838 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
92839 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
92840 prot |= PROT_EXEC;
92841
92842 @@ -1263,7 +1347,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92843 /* Obtain the address to map to. we verify (or select) it and ensure
92844 * that it represents a valid section of the address space.
92845 */
92846 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
92847 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
92848 if (addr & ~PAGE_MASK)
92849 return addr;
92850
92851 @@ -1274,6 +1358,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92852 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
92853 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
92854
92855 +#ifdef CONFIG_PAX_MPROTECT
92856 + if (mm->pax_flags & MF_PAX_MPROTECT) {
92857 +
92858 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
92859 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
92860 + mm->binfmt->handle_mmap)
92861 + mm->binfmt->handle_mmap(file);
92862 +#endif
92863 +
92864 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
92865 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
92866 + gr_log_rwxmmap(file);
92867 +
92868 +#ifdef CONFIG_PAX_EMUPLT
92869 + vm_flags &= ~VM_EXEC;
92870 +#else
92871 + return -EPERM;
92872 +#endif
92873 +
92874 + }
92875 +
92876 + if (!(vm_flags & VM_EXEC))
92877 + vm_flags &= ~VM_MAYEXEC;
92878 +#else
92879 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
92880 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
92881 +#endif
92882 + else
92883 + vm_flags &= ~VM_MAYWRITE;
92884 + }
92885 +#endif
92886 +
92887 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92888 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
92889 + vm_flags &= ~VM_PAGEEXEC;
92890 +#endif
92891 +
92892 if (flags & MAP_LOCKED)
92893 if (!can_do_mlock())
92894 return -EPERM;
92895 @@ -1361,6 +1482,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92896 vm_flags |= VM_NORESERVE;
92897 }
92898
92899 + if (!gr_acl_handle_mmap(file, prot))
92900 + return -EACCES;
92901 +
92902 addr = mmap_region(file, addr, len, vm_flags, pgoff);
92903 if (!IS_ERR_VALUE(addr) &&
92904 ((vm_flags & VM_LOCKED) ||
92905 @@ -1454,7 +1578,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
92906 vm_flags_t vm_flags = vma->vm_flags;
92907
92908 /* If it was private or non-writable, the write bit is already clear */
92909 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
92910 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
92911 return 0;
92912
92913 /* The backer wishes to know when pages are first written to? */
92914 @@ -1500,7 +1624,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
92915 struct rb_node **rb_link, *rb_parent;
92916 unsigned long charged = 0;
92917
92918 +#ifdef CONFIG_PAX_SEGMEXEC
92919 + struct vm_area_struct *vma_m = NULL;
92920 +#endif
92921 +
92922 + /*
92923 + * mm->mmap_sem is required to protect against another thread
92924 + * changing the mappings in case we sleep.
92925 + */
92926 + verify_mm_writelocked(mm);
92927 +
92928 /* Check against address space limit. */
92929 +
92930 +#ifdef CONFIG_PAX_RANDMMAP
92931 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
92932 +#endif
92933 +
92934 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
92935 unsigned long nr_pages;
92936
92937 @@ -1519,11 +1658,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
92938
92939 /* Clear old maps */
92940 error = -ENOMEM;
92941 -munmap_back:
92942 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
92943 if (do_munmap(mm, addr, len))
92944 return -ENOMEM;
92945 - goto munmap_back;
92946 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
92947 }
92948
92949 /*
92950 @@ -1554,6 +1692,16 @@ munmap_back:
92951 goto unacct_error;
92952 }
92953
92954 +#ifdef CONFIG_PAX_SEGMEXEC
92955 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
92956 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92957 + if (!vma_m) {
92958 + error = -ENOMEM;
92959 + goto free_vma;
92960 + }
92961 + }
92962 +#endif
92963 +
92964 vma->vm_mm = mm;
92965 vma->vm_start = addr;
92966 vma->vm_end = addr + len;
92967 @@ -1573,6 +1721,13 @@ munmap_back:
92968 if (error)
92969 goto unmap_and_free_vma;
92970
92971 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92972 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
92973 + vma->vm_flags |= VM_PAGEEXEC;
92974 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
92975 + }
92976 +#endif
92977 +
92978 /* Can addr have changed??
92979 *
92980 * Answer: Yes, several device drivers can do it in their
92981 @@ -1606,6 +1761,12 @@ munmap_back:
92982 }
92983
92984 vma_link(mm, vma, prev, rb_link, rb_parent);
92985 +
92986 +#ifdef CONFIG_PAX_SEGMEXEC
92987 + if (vma_m)
92988 + BUG_ON(pax_mirror_vma(vma_m, vma));
92989 +#endif
92990 +
92991 /* Once vma denies write, undo our temporary denial count */
92992 if (vm_flags & VM_DENYWRITE)
92993 allow_write_access(file);
92994 @@ -1614,6 +1775,7 @@ out:
92995 perf_event_mmap(vma);
92996
92997 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
92998 + track_exec_limit(mm, addr, addr + len, vm_flags);
92999 if (vm_flags & VM_LOCKED) {
93000 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
93001 vma == get_gate_vma(current->mm)))
93002 @@ -1646,6 +1808,12 @@ unmap_and_free_vma:
93003 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
93004 charged = 0;
93005 free_vma:
93006 +
93007 +#ifdef CONFIG_PAX_SEGMEXEC
93008 + if (vma_m)
93009 + kmem_cache_free(vm_area_cachep, vma_m);
93010 +#endif
93011 +
93012 kmem_cache_free(vm_area_cachep, vma);
93013 unacct_error:
93014 if (charged)
93015 @@ -1653,7 +1821,63 @@ unacct_error:
93016 return error;
93017 }
93018
93019 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93020 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
93021 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
93022 +{
93023 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
93024 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
93025 +
93026 + return 0;
93027 +}
93028 +#endif
93029 +
93030 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
93031 +{
93032 + if (!vma) {
93033 +#ifdef CONFIG_STACK_GROWSUP
93034 + if (addr > sysctl_heap_stack_gap)
93035 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
93036 + else
93037 + vma = find_vma(current->mm, 0);
93038 + if (vma && (vma->vm_flags & VM_GROWSUP))
93039 + return false;
93040 +#endif
93041 + return true;
93042 + }
93043 +
93044 + if (addr + len > vma->vm_start)
93045 + return false;
93046 +
93047 + if (vma->vm_flags & VM_GROWSDOWN)
93048 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
93049 +#ifdef CONFIG_STACK_GROWSUP
93050 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
93051 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
93052 +#endif
93053 + else if (offset)
93054 + return offset <= vma->vm_start - addr - len;
93055 +
93056 + return true;
93057 +}
93058 +
93059 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
93060 +{
93061 + if (vma->vm_start < len)
93062 + return -ENOMEM;
93063 +
93064 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
93065 + if (offset <= vma->vm_start - len)
93066 + return vma->vm_start - len - offset;
93067 + else
93068 + return -ENOMEM;
93069 + }
93070 +
93071 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
93072 + return vma->vm_start - len - sysctl_heap_stack_gap;
93073 + return -ENOMEM;
93074 +}
93075 +
93076 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
93077 {
93078 /*
93079 * We implement the search by looking for an rbtree node that
93080 @@ -1701,11 +1925,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93081 }
93082 }
93083
93084 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
93085 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
93086 check_current:
93087 /* Check if current node has a suitable gap */
93088 if (gap_start > high_limit)
93089 return -ENOMEM;
93090 +
93091 + if (gap_end - gap_start > info->threadstack_offset)
93092 + gap_start += info->threadstack_offset;
93093 + else
93094 + gap_start = gap_end;
93095 +
93096 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93097 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93098 + gap_start += sysctl_heap_stack_gap;
93099 + else
93100 + gap_start = gap_end;
93101 + }
93102 + if (vma->vm_flags & VM_GROWSDOWN) {
93103 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93104 + gap_end -= sysctl_heap_stack_gap;
93105 + else
93106 + gap_end = gap_start;
93107 + }
93108 if (gap_end >= low_limit && gap_end - gap_start >= length)
93109 goto found;
93110
93111 @@ -1755,7 +1997,7 @@ found:
93112 return gap_start;
93113 }
93114
93115 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
93116 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
93117 {
93118 struct mm_struct *mm = current->mm;
93119 struct vm_area_struct *vma;
93120 @@ -1809,6 +2051,24 @@ check_current:
93121 gap_end = vma->vm_start;
93122 if (gap_end < low_limit)
93123 return -ENOMEM;
93124 +
93125 + if (gap_end - gap_start > info->threadstack_offset)
93126 + gap_end -= info->threadstack_offset;
93127 + else
93128 + gap_end = gap_start;
93129 +
93130 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93131 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93132 + gap_start += sysctl_heap_stack_gap;
93133 + else
93134 + gap_start = gap_end;
93135 + }
93136 + if (vma->vm_flags & VM_GROWSDOWN) {
93137 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93138 + gap_end -= sysctl_heap_stack_gap;
93139 + else
93140 + gap_end = gap_start;
93141 + }
93142 if (gap_start <= high_limit && gap_end - gap_start >= length)
93143 goto found;
93144
93145 @@ -1872,6 +2132,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93146 struct mm_struct *mm = current->mm;
93147 struct vm_area_struct *vma;
93148 struct vm_unmapped_area_info info;
93149 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93150
93151 if (len > TASK_SIZE - mmap_min_addr)
93152 return -ENOMEM;
93153 @@ -1879,11 +2140,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93154 if (flags & MAP_FIXED)
93155 return addr;
93156
93157 +#ifdef CONFIG_PAX_RANDMMAP
93158 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93159 +#endif
93160 +
93161 if (addr) {
93162 addr = PAGE_ALIGN(addr);
93163 vma = find_vma(mm, addr);
93164 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93165 - (!vma || addr + len <= vma->vm_start))
93166 + check_heap_stack_gap(vma, addr, len, offset))
93167 return addr;
93168 }
93169
93170 @@ -1892,6 +2157,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93171 info.low_limit = mm->mmap_base;
93172 info.high_limit = TASK_SIZE;
93173 info.align_mask = 0;
93174 + info.threadstack_offset = offset;
93175 return vm_unmapped_area(&info);
93176 }
93177 #endif
93178 @@ -1910,6 +2176,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93179 struct mm_struct *mm = current->mm;
93180 unsigned long addr = addr0;
93181 struct vm_unmapped_area_info info;
93182 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93183
93184 /* requested length too big for entire address space */
93185 if (len > TASK_SIZE - mmap_min_addr)
93186 @@ -1918,12 +2185,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93187 if (flags & MAP_FIXED)
93188 return addr;
93189
93190 +#ifdef CONFIG_PAX_RANDMMAP
93191 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93192 +#endif
93193 +
93194 /* requesting a specific address */
93195 if (addr) {
93196 addr = PAGE_ALIGN(addr);
93197 vma = find_vma(mm, addr);
93198 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93199 - (!vma || addr + len <= vma->vm_start))
93200 + check_heap_stack_gap(vma, addr, len, offset))
93201 return addr;
93202 }
93203
93204 @@ -1932,6 +2203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93205 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
93206 info.high_limit = mm->mmap_base;
93207 info.align_mask = 0;
93208 + info.threadstack_offset = offset;
93209 addr = vm_unmapped_area(&info);
93210
93211 /*
93212 @@ -1944,6 +2216,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93213 VM_BUG_ON(addr != -ENOMEM);
93214 info.flags = 0;
93215 info.low_limit = TASK_UNMAPPED_BASE;
93216 +
93217 +#ifdef CONFIG_PAX_RANDMMAP
93218 + if (mm->pax_flags & MF_PAX_RANDMMAP)
93219 + info.low_limit += mm->delta_mmap;
93220 +#endif
93221 +
93222 info.high_limit = TASK_SIZE;
93223 addr = vm_unmapped_area(&info);
93224 }
93225 @@ -2045,6 +2323,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
93226 return vma;
93227 }
93228
93229 +#ifdef CONFIG_PAX_SEGMEXEC
93230 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
93231 +{
93232 + struct vm_area_struct *vma_m;
93233 +
93234 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
93235 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
93236 + BUG_ON(vma->vm_mirror);
93237 + return NULL;
93238 + }
93239 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
93240 + vma_m = vma->vm_mirror;
93241 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
93242 + BUG_ON(vma->vm_file != vma_m->vm_file);
93243 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
93244 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
93245 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
93246 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
93247 + return vma_m;
93248 +}
93249 +#endif
93250 +
93251 /*
93252 * Verify that the stack growth is acceptable and
93253 * update accounting. This is shared with both the
93254 @@ -2061,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93255 return -ENOMEM;
93256
93257 /* Stack limit test */
93258 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
93259 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
93260 return -ENOMEM;
93261
93262 @@ -2071,6 +2372,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93263 locked = mm->locked_vm + grow;
93264 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
93265 limit >>= PAGE_SHIFT;
93266 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93267 if (locked > limit && !capable(CAP_IPC_LOCK))
93268 return -ENOMEM;
93269 }
93270 @@ -2100,37 +2402,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93271 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
93272 * vma is the last one with address > vma->vm_end. Have to extend vma.
93273 */
93274 +#ifndef CONFIG_IA64
93275 +static
93276 +#endif
93277 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93278 {
93279 int error;
93280 + bool locknext;
93281
93282 if (!(vma->vm_flags & VM_GROWSUP))
93283 return -EFAULT;
93284
93285 + /* Also guard against wrapping around to address 0. */
93286 + if (address < PAGE_ALIGN(address+1))
93287 + address = PAGE_ALIGN(address+1);
93288 + else
93289 + return -ENOMEM;
93290 +
93291 /*
93292 * We must make sure the anon_vma is allocated
93293 * so that the anon_vma locking is not a noop.
93294 */
93295 if (unlikely(anon_vma_prepare(vma)))
93296 return -ENOMEM;
93297 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
93298 + if (locknext && anon_vma_prepare(vma->vm_next))
93299 + return -ENOMEM;
93300 vma_lock_anon_vma(vma);
93301 + if (locknext)
93302 + vma_lock_anon_vma(vma->vm_next);
93303
93304 /*
93305 * vma->vm_start/vm_end cannot change under us because the caller
93306 * is required to hold the mmap_sem in read mode. We need the
93307 - * anon_vma lock to serialize against concurrent expand_stacks.
93308 - * Also guard against wrapping around to address 0.
93309 + * anon_vma locks to serialize against concurrent expand_stacks
93310 + * and expand_upwards.
93311 */
93312 - if (address < PAGE_ALIGN(address+4))
93313 - address = PAGE_ALIGN(address+4);
93314 - else {
93315 - vma_unlock_anon_vma(vma);
93316 - return -ENOMEM;
93317 - }
93318 error = 0;
93319
93320 /* Somebody else might have raced and expanded it already */
93321 - if (address > vma->vm_end) {
93322 + 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)
93323 + error = -ENOMEM;
93324 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
93325 unsigned long size, grow;
93326
93327 size = address - vma->vm_start;
93328 @@ -2165,6 +2478,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93329 }
93330 }
93331 }
93332 + if (locknext)
93333 + vma_unlock_anon_vma(vma->vm_next);
93334 vma_unlock_anon_vma(vma);
93335 khugepaged_enter_vma_merge(vma);
93336 validate_mm(vma->vm_mm);
93337 @@ -2179,6 +2494,8 @@ int expand_downwards(struct vm_area_struct *vma,
93338 unsigned long address)
93339 {
93340 int error;
93341 + bool lockprev = false;
93342 + struct vm_area_struct *prev;
93343
93344 /*
93345 * We must make sure the anon_vma is allocated
93346 @@ -2192,6 +2509,15 @@ int expand_downwards(struct vm_area_struct *vma,
93347 if (error)
93348 return error;
93349
93350 + prev = vma->vm_prev;
93351 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
93352 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
93353 +#endif
93354 + if (lockprev && anon_vma_prepare(prev))
93355 + return -ENOMEM;
93356 + if (lockprev)
93357 + vma_lock_anon_vma(prev);
93358 +
93359 vma_lock_anon_vma(vma);
93360
93361 /*
93362 @@ -2201,9 +2527,17 @@ int expand_downwards(struct vm_area_struct *vma,
93363 */
93364
93365 /* Somebody else might have raced and expanded it already */
93366 - if (address < vma->vm_start) {
93367 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
93368 + error = -ENOMEM;
93369 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
93370 unsigned long size, grow;
93371
93372 +#ifdef CONFIG_PAX_SEGMEXEC
93373 + struct vm_area_struct *vma_m;
93374 +
93375 + vma_m = pax_find_mirror_vma(vma);
93376 +#endif
93377 +
93378 size = vma->vm_end - address;
93379 grow = (vma->vm_start - address) >> PAGE_SHIFT;
93380
93381 @@ -2228,13 +2562,27 @@ int expand_downwards(struct vm_area_struct *vma,
93382 vma->vm_pgoff -= grow;
93383 anon_vma_interval_tree_post_update_vma(vma);
93384 vma_gap_update(vma);
93385 +
93386 +#ifdef CONFIG_PAX_SEGMEXEC
93387 + if (vma_m) {
93388 + anon_vma_interval_tree_pre_update_vma(vma_m);
93389 + vma_m->vm_start -= grow << PAGE_SHIFT;
93390 + vma_m->vm_pgoff -= grow;
93391 + anon_vma_interval_tree_post_update_vma(vma_m);
93392 + vma_gap_update(vma_m);
93393 + }
93394 +#endif
93395 +
93396 spin_unlock(&vma->vm_mm->page_table_lock);
93397
93398 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
93399 perf_event_mmap(vma);
93400 }
93401 }
93402 }
93403 vma_unlock_anon_vma(vma);
93404 + if (lockprev)
93405 + vma_unlock_anon_vma(prev);
93406 khugepaged_enter_vma_merge(vma);
93407 validate_mm(vma->vm_mm);
93408 return error;
93409 @@ -2332,6 +2680,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
93410 do {
93411 long nrpages = vma_pages(vma);
93412
93413 +#ifdef CONFIG_PAX_SEGMEXEC
93414 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
93415 + vma = remove_vma(vma);
93416 + continue;
93417 + }
93418 +#endif
93419 +
93420 if (vma->vm_flags & VM_ACCOUNT)
93421 nr_accounted += nrpages;
93422 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
93423 @@ -2376,6 +2731,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
93424 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
93425 vma->vm_prev = NULL;
93426 do {
93427 +
93428 +#ifdef CONFIG_PAX_SEGMEXEC
93429 + if (vma->vm_mirror) {
93430 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
93431 + vma->vm_mirror->vm_mirror = NULL;
93432 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
93433 + vma->vm_mirror = NULL;
93434 + }
93435 +#endif
93436 +
93437 vma_rb_erase(vma, &mm->mm_rb);
93438 mm->map_count--;
93439 tail_vma = vma;
93440 @@ -2401,14 +2766,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93441 struct vm_area_struct *new;
93442 int err = -ENOMEM;
93443
93444 +#ifdef CONFIG_PAX_SEGMEXEC
93445 + struct vm_area_struct *vma_m, *new_m = NULL;
93446 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
93447 +#endif
93448 +
93449 if (is_vm_hugetlb_page(vma) && (addr &
93450 ~(huge_page_mask(hstate_vma(vma)))))
93451 return -EINVAL;
93452
93453 +#ifdef CONFIG_PAX_SEGMEXEC
93454 + vma_m = pax_find_mirror_vma(vma);
93455 +#endif
93456 +
93457 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93458 if (!new)
93459 goto out_err;
93460
93461 +#ifdef CONFIG_PAX_SEGMEXEC
93462 + if (vma_m) {
93463 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93464 + if (!new_m) {
93465 + kmem_cache_free(vm_area_cachep, new);
93466 + goto out_err;
93467 + }
93468 + }
93469 +#endif
93470 +
93471 /* most fields are the same, copy all, and then fixup */
93472 *new = *vma;
93473
93474 @@ -2421,6 +2805,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93475 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
93476 }
93477
93478 +#ifdef CONFIG_PAX_SEGMEXEC
93479 + if (vma_m) {
93480 + *new_m = *vma_m;
93481 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
93482 + new_m->vm_mirror = new;
93483 + new->vm_mirror = new_m;
93484 +
93485 + if (new_below)
93486 + new_m->vm_end = addr_m;
93487 + else {
93488 + new_m->vm_start = addr_m;
93489 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
93490 + }
93491 + }
93492 +#endif
93493 +
93494 err = vma_dup_policy(vma, new);
93495 if (err)
93496 goto out_free_vma;
93497 @@ -2440,6 +2840,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93498 else
93499 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
93500
93501 +#ifdef CONFIG_PAX_SEGMEXEC
93502 + if (!err && vma_m) {
93503 + struct mempolicy *pol = vma_policy(new);
93504 +
93505 + if (anon_vma_clone(new_m, vma_m))
93506 + goto out_free_mpol;
93507 +
93508 + mpol_get(pol);
93509 + set_vma_policy(new_m, pol);
93510 +
93511 + if (new_m->vm_file)
93512 + get_file(new_m->vm_file);
93513 +
93514 + if (new_m->vm_ops && new_m->vm_ops->open)
93515 + new_m->vm_ops->open(new_m);
93516 +
93517 + if (new_below)
93518 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
93519 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
93520 + else
93521 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
93522 +
93523 + if (err) {
93524 + if (new_m->vm_ops && new_m->vm_ops->close)
93525 + new_m->vm_ops->close(new_m);
93526 + if (new_m->vm_file)
93527 + fput(new_m->vm_file);
93528 + mpol_put(pol);
93529 + }
93530 + }
93531 +#endif
93532 +
93533 /* Success. */
93534 if (!err)
93535 return 0;
93536 @@ -2449,10 +2881,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93537 new->vm_ops->close(new);
93538 if (new->vm_file)
93539 fput(new->vm_file);
93540 - unlink_anon_vmas(new);
93541 out_free_mpol:
93542 mpol_put(vma_policy(new));
93543 out_free_vma:
93544 +
93545 +#ifdef CONFIG_PAX_SEGMEXEC
93546 + if (new_m) {
93547 + unlink_anon_vmas(new_m);
93548 + kmem_cache_free(vm_area_cachep, new_m);
93549 + }
93550 +#endif
93551 +
93552 + unlink_anon_vmas(new);
93553 kmem_cache_free(vm_area_cachep, new);
93554 out_err:
93555 return err;
93556 @@ -2465,6 +2905,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93557 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93558 unsigned long addr, int new_below)
93559 {
93560 +
93561 +#ifdef CONFIG_PAX_SEGMEXEC
93562 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93563 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
93564 + if (mm->map_count >= sysctl_max_map_count-1)
93565 + return -ENOMEM;
93566 + } else
93567 +#endif
93568 +
93569 if (mm->map_count >= sysctl_max_map_count)
93570 return -ENOMEM;
93571
93572 @@ -2476,11 +2925,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93573 * work. This now handles partial unmappings.
93574 * Jeremy Fitzhardinge <jeremy@goop.org>
93575 */
93576 +#ifdef CONFIG_PAX_SEGMEXEC
93577 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93578 {
93579 + int ret = __do_munmap(mm, start, len);
93580 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
93581 + return ret;
93582 +
93583 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
93584 +}
93585 +
93586 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93587 +#else
93588 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93589 +#endif
93590 +{
93591 unsigned long end;
93592 struct vm_area_struct *vma, *prev, *last;
93593
93594 + /*
93595 + * mm->mmap_sem is required to protect against another thread
93596 + * changing the mappings in case we sleep.
93597 + */
93598 + verify_mm_writelocked(mm);
93599 +
93600 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
93601 return -EINVAL;
93602
93603 @@ -2555,6 +3023,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93604 /* Fix up all other VM information */
93605 remove_vma_list(mm, vma);
93606
93607 + track_exec_limit(mm, start, end, 0UL);
93608 +
93609 return 0;
93610 }
93611
93612 @@ -2563,6 +3033,13 @@ int vm_munmap(unsigned long start, size_t len)
93613 int ret;
93614 struct mm_struct *mm = current->mm;
93615
93616 +
93617 +#ifdef CONFIG_PAX_SEGMEXEC
93618 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
93619 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
93620 + return -EINVAL;
93621 +#endif
93622 +
93623 down_write(&mm->mmap_sem);
93624 ret = do_munmap(mm, start, len);
93625 up_write(&mm->mmap_sem);
93626 @@ -2576,16 +3053,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
93627 return vm_munmap(addr, len);
93628 }
93629
93630 -static inline void verify_mm_writelocked(struct mm_struct *mm)
93631 -{
93632 -#ifdef CONFIG_DEBUG_VM
93633 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93634 - WARN_ON(1);
93635 - up_read(&mm->mmap_sem);
93636 - }
93637 -#endif
93638 -}
93639 -
93640 /*
93641 * this is really a simplified "do_mmap". it only handles
93642 * anonymous maps. eventually we may be able to do some
93643 @@ -2599,6 +3066,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93644 struct rb_node ** rb_link, * rb_parent;
93645 pgoff_t pgoff = addr >> PAGE_SHIFT;
93646 int error;
93647 + unsigned long charged;
93648
93649 len = PAGE_ALIGN(len);
93650 if (!len)
93651 @@ -2606,10 +3074,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93652
93653 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
93654
93655 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
93656 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
93657 + flags &= ~VM_EXEC;
93658 +
93659 +#ifdef CONFIG_PAX_MPROTECT
93660 + if (mm->pax_flags & MF_PAX_MPROTECT)
93661 + flags &= ~VM_MAYEXEC;
93662 +#endif
93663 +
93664 + }
93665 +#endif
93666 +
93667 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
93668 if (error & ~PAGE_MASK)
93669 return error;
93670
93671 + charged = len >> PAGE_SHIFT;
93672 +
93673 error = mlock_future_check(mm, mm->def_flags, len);
93674 if (error)
93675 return error;
93676 @@ -2623,21 +3105,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93677 /*
93678 * Clear old maps. this also does some error checking for us
93679 */
93680 - munmap_back:
93681 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93682 if (do_munmap(mm, addr, len))
93683 return -ENOMEM;
93684 - goto munmap_back;
93685 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93686 }
93687
93688 /* Check against address space limits *after* clearing old maps... */
93689 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
93690 + if (!may_expand_vm(mm, charged))
93691 return -ENOMEM;
93692
93693 if (mm->map_count > sysctl_max_map_count)
93694 return -ENOMEM;
93695
93696 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
93697 + if (security_vm_enough_memory_mm(mm, charged))
93698 return -ENOMEM;
93699
93700 /* Can we just expand an old private anonymous mapping? */
93701 @@ -2651,7 +3132,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93702 */
93703 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93704 if (!vma) {
93705 - vm_unacct_memory(len >> PAGE_SHIFT);
93706 + vm_unacct_memory(charged);
93707 return -ENOMEM;
93708 }
93709
93710 @@ -2665,10 +3146,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93711 vma_link(mm, vma, prev, rb_link, rb_parent);
93712 out:
93713 perf_event_mmap(vma);
93714 - mm->total_vm += len >> PAGE_SHIFT;
93715 + mm->total_vm += charged;
93716 if (flags & VM_LOCKED)
93717 - mm->locked_vm += (len >> PAGE_SHIFT);
93718 + mm->locked_vm += charged;
93719 vma->vm_flags |= VM_SOFTDIRTY;
93720 + track_exec_limit(mm, addr, addr + len, flags);
93721 return addr;
93722 }
93723
93724 @@ -2730,6 +3212,7 @@ void exit_mmap(struct mm_struct *mm)
93725 while (vma) {
93726 if (vma->vm_flags & VM_ACCOUNT)
93727 nr_accounted += vma_pages(vma);
93728 + vma->vm_mirror = NULL;
93729 vma = remove_vma(vma);
93730 }
93731 vm_unacct_memory(nr_accounted);
93732 @@ -2747,6 +3230,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93733 struct vm_area_struct *prev;
93734 struct rb_node **rb_link, *rb_parent;
93735
93736 +#ifdef CONFIG_PAX_SEGMEXEC
93737 + struct vm_area_struct *vma_m = NULL;
93738 +#endif
93739 +
93740 + if (security_mmap_addr(vma->vm_start))
93741 + return -EPERM;
93742 +
93743 /*
93744 * The vm_pgoff of a purely anonymous vma should be irrelevant
93745 * until its first write fault, when page's anon_vma and index
93746 @@ -2770,7 +3260,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93747 security_vm_enough_memory_mm(mm, vma_pages(vma)))
93748 return -ENOMEM;
93749
93750 +#ifdef CONFIG_PAX_SEGMEXEC
93751 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
93752 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93753 + if (!vma_m)
93754 + return -ENOMEM;
93755 + }
93756 +#endif
93757 +
93758 vma_link(mm, vma, prev, rb_link, rb_parent);
93759 +
93760 +#ifdef CONFIG_PAX_SEGMEXEC
93761 + if (vma_m)
93762 + BUG_ON(pax_mirror_vma(vma_m, vma));
93763 +#endif
93764 +
93765 return 0;
93766 }
93767
93768 @@ -2789,6 +3293,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
93769 struct rb_node **rb_link, *rb_parent;
93770 bool faulted_in_anon_vma = true;
93771
93772 + BUG_ON(vma->vm_mirror);
93773 +
93774 /*
93775 * If anonymous vma has not yet been faulted, update new pgoff
93776 * to match new location, to increase its chance of merging.
93777 @@ -2853,6 +3359,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
93778 return NULL;
93779 }
93780
93781 +#ifdef CONFIG_PAX_SEGMEXEC
93782 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
93783 +{
93784 + struct vm_area_struct *prev_m;
93785 + struct rb_node **rb_link_m, *rb_parent_m;
93786 + struct mempolicy *pol_m;
93787 +
93788 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
93789 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
93790 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
93791 + *vma_m = *vma;
93792 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
93793 + if (anon_vma_clone(vma_m, vma))
93794 + return -ENOMEM;
93795 + pol_m = vma_policy(vma_m);
93796 + mpol_get(pol_m);
93797 + set_vma_policy(vma_m, pol_m);
93798 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
93799 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
93800 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
93801 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
93802 + if (vma_m->vm_file)
93803 + get_file(vma_m->vm_file);
93804 + if (vma_m->vm_ops && vma_m->vm_ops->open)
93805 + vma_m->vm_ops->open(vma_m);
93806 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
93807 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
93808 + vma_m->vm_mirror = vma;
93809 + vma->vm_mirror = vma_m;
93810 + return 0;
93811 +}
93812 +#endif
93813 +
93814 /*
93815 * Return true if the calling process may expand its vm space by the passed
93816 * number of pages
93817 @@ -2864,6 +3403,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
93818
93819 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
93820
93821 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
93822 if (cur + npages > lim)
93823 return 0;
93824 return 1;
93825 @@ -2934,6 +3474,22 @@ int install_special_mapping(struct mm_struct *mm,
93826 vma->vm_start = addr;
93827 vma->vm_end = addr + len;
93828
93829 +#ifdef CONFIG_PAX_MPROTECT
93830 + if (mm->pax_flags & MF_PAX_MPROTECT) {
93831 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
93832 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
93833 + return -EPERM;
93834 + if (!(vm_flags & VM_EXEC))
93835 + vm_flags &= ~VM_MAYEXEC;
93836 +#else
93837 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93838 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93839 +#endif
93840 + else
93841 + vm_flags &= ~VM_MAYWRITE;
93842 + }
93843 +#endif
93844 +
93845 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
93846 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93847
93848 diff --git a/mm/mprotect.c b/mm/mprotect.c
93849 index 769a67a..414d24f 100644
93850 --- a/mm/mprotect.c
93851 +++ b/mm/mprotect.c
93852 @@ -24,10 +24,18 @@
93853 #include <linux/migrate.h>
93854 #include <linux/perf_event.h>
93855 #include <linux/ksm.h>
93856 +#include <linux/sched/sysctl.h>
93857 +
93858 +#ifdef CONFIG_PAX_MPROTECT
93859 +#include <linux/elf.h>
93860 +#include <linux/binfmts.h>
93861 +#endif
93862 +
93863 #include <asm/uaccess.h>
93864 #include <asm/pgtable.h>
93865 #include <asm/cacheflush.h>
93866 #include <asm/tlbflush.h>
93867 +#include <asm/mmu_context.h>
93868
93869 #ifndef pgprot_modify
93870 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
93871 @@ -214,6 +222,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
93872 return pages;
93873 }
93874
93875 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
93876 +/* called while holding the mmap semaphor for writing except stack expansion */
93877 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
93878 +{
93879 + unsigned long oldlimit, newlimit = 0UL;
93880 +
93881 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
93882 + return;
93883 +
93884 + spin_lock(&mm->page_table_lock);
93885 + oldlimit = mm->context.user_cs_limit;
93886 + if ((prot & VM_EXEC) && oldlimit < end)
93887 + /* USER_CS limit moved up */
93888 + newlimit = end;
93889 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
93890 + /* USER_CS limit moved down */
93891 + newlimit = start;
93892 +
93893 + if (newlimit) {
93894 + mm->context.user_cs_limit = newlimit;
93895 +
93896 +#ifdef CONFIG_SMP
93897 + wmb();
93898 + cpus_clear(mm->context.cpu_user_cs_mask);
93899 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
93900 +#endif
93901 +
93902 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
93903 + }
93904 + spin_unlock(&mm->page_table_lock);
93905 + if (newlimit == end) {
93906 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
93907 +
93908 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
93909 + if (is_vm_hugetlb_page(vma))
93910 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
93911 + else
93912 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
93913 + }
93914 +}
93915 +#endif
93916 +
93917 int
93918 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93919 unsigned long start, unsigned long end, unsigned long newflags)
93920 @@ -226,11 +276,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93921 int error;
93922 int dirty_accountable = 0;
93923
93924 +#ifdef CONFIG_PAX_SEGMEXEC
93925 + struct vm_area_struct *vma_m = NULL;
93926 + unsigned long start_m, end_m;
93927 +
93928 + start_m = start + SEGMEXEC_TASK_SIZE;
93929 + end_m = end + SEGMEXEC_TASK_SIZE;
93930 +#endif
93931 +
93932 if (newflags == oldflags) {
93933 *pprev = vma;
93934 return 0;
93935 }
93936
93937 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
93938 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
93939 +
93940 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
93941 + return -ENOMEM;
93942 +
93943 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
93944 + return -ENOMEM;
93945 + }
93946 +
93947 /*
93948 * If we make a private mapping writable we increase our commit;
93949 * but (without finer accounting) cannot reduce our commit if we
93950 @@ -247,6 +315,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93951 }
93952 }
93953
93954 +#ifdef CONFIG_PAX_SEGMEXEC
93955 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
93956 + if (start != vma->vm_start) {
93957 + error = split_vma(mm, vma, start, 1);
93958 + if (error)
93959 + goto fail;
93960 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
93961 + *pprev = (*pprev)->vm_next;
93962 + }
93963 +
93964 + if (end != vma->vm_end) {
93965 + error = split_vma(mm, vma, end, 0);
93966 + if (error)
93967 + goto fail;
93968 + }
93969 +
93970 + if (pax_find_mirror_vma(vma)) {
93971 + error = __do_munmap(mm, start_m, end_m - start_m);
93972 + if (error)
93973 + goto fail;
93974 + } else {
93975 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93976 + if (!vma_m) {
93977 + error = -ENOMEM;
93978 + goto fail;
93979 + }
93980 + vma->vm_flags = newflags;
93981 + error = pax_mirror_vma(vma_m, vma);
93982 + if (error) {
93983 + vma->vm_flags = oldflags;
93984 + goto fail;
93985 + }
93986 + }
93987 + }
93988 +#endif
93989 +
93990 /*
93991 * First try to merge with previous and/or next vma.
93992 */
93993 @@ -277,9 +381,21 @@ success:
93994 * vm_flags and vm_page_prot are protected by the mmap_sem
93995 * held in write mode.
93996 */
93997 +
93998 +#ifdef CONFIG_PAX_SEGMEXEC
93999 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
94000 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
94001 +#endif
94002 +
94003 vma->vm_flags = newflags;
94004 +
94005 +#ifdef CONFIG_PAX_MPROTECT
94006 + if (mm->binfmt && mm->binfmt->handle_mprotect)
94007 + mm->binfmt->handle_mprotect(vma, newflags);
94008 +#endif
94009 +
94010 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
94011 - vm_get_page_prot(newflags));
94012 + vm_get_page_prot(vma->vm_flags));
94013
94014 if (vma_wants_writenotify(vma)) {
94015 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
94016 @@ -318,6 +434,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94017 end = start + len;
94018 if (end <= start)
94019 return -ENOMEM;
94020 +
94021 +#ifdef CONFIG_PAX_SEGMEXEC
94022 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
94023 + if (end > SEGMEXEC_TASK_SIZE)
94024 + return -EINVAL;
94025 + } else
94026 +#endif
94027 +
94028 + if (end > TASK_SIZE)
94029 + return -EINVAL;
94030 +
94031 if (!arch_validate_prot(prot))
94032 return -EINVAL;
94033
94034 @@ -325,7 +452,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94035 /*
94036 * Does the application expect PROT_READ to imply PROT_EXEC:
94037 */
94038 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94039 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94040 prot |= PROT_EXEC;
94041
94042 vm_flags = calc_vm_prot_bits(prot);
94043 @@ -357,6 +484,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94044 if (start > vma->vm_start)
94045 prev = vma;
94046
94047 +#ifdef CONFIG_PAX_MPROTECT
94048 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
94049 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
94050 +#endif
94051 +
94052 for (nstart = start ; ; ) {
94053 unsigned long newflags;
94054
94055 @@ -367,6 +499,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94056
94057 /* newflags >> 4 shift VM_MAY% in place of VM_% */
94058 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
94059 + if (prot & (PROT_WRITE | PROT_EXEC))
94060 + gr_log_rwxmprotect(vma);
94061 +
94062 + error = -EACCES;
94063 + goto out;
94064 + }
94065 +
94066 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
94067 error = -EACCES;
94068 goto out;
94069 }
94070 @@ -381,6 +521,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94071 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
94072 if (error)
94073 goto out;
94074 +
94075 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
94076 +
94077 nstart = tmp;
94078
94079 if (nstart < prev->vm_end)
94080 diff --git a/mm/mremap.c b/mm/mremap.c
94081 index 0843feb..4f5b2e6 100644
94082 --- a/mm/mremap.c
94083 +++ b/mm/mremap.c
94084 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
94085 continue;
94086 pte = ptep_get_and_clear(mm, old_addr, old_pte);
94087 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
94088 +
94089 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94090 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
94091 + pte = pte_exprotect(pte);
94092 +#endif
94093 +
94094 pte = move_soft_dirty_pte(pte);
94095 set_pte_at(mm, new_addr, new_pte, pte);
94096 }
94097 @@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
94098 if (is_vm_hugetlb_page(vma))
94099 goto Einval;
94100
94101 +#ifdef CONFIG_PAX_SEGMEXEC
94102 + if (pax_find_mirror_vma(vma))
94103 + goto Einval;
94104 +#endif
94105 +
94106 /* We can't remap across vm area boundaries */
94107 if (old_len > vma->vm_end - addr)
94108 goto Efault;
94109 @@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
94110 unsigned long ret = -EINVAL;
94111 unsigned long charged = 0;
94112 unsigned long map_flags;
94113 + unsigned long pax_task_size = TASK_SIZE;
94114
94115 if (new_addr & ~PAGE_MASK)
94116 goto out;
94117
94118 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
94119 +#ifdef CONFIG_PAX_SEGMEXEC
94120 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
94121 + pax_task_size = SEGMEXEC_TASK_SIZE;
94122 +#endif
94123 +
94124 + pax_task_size -= PAGE_SIZE;
94125 +
94126 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
94127 goto out;
94128
94129 /* Check if the location we're moving into overlaps the
94130 * old location at all, and fail if it does.
94131 */
94132 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
94133 - goto out;
94134 -
94135 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
94136 + if (addr + old_len > new_addr && new_addr + new_len > addr)
94137 goto out;
94138
94139 ret = do_munmap(mm, new_addr, new_len);
94140 @@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94141 unsigned long ret = -EINVAL;
94142 unsigned long charged = 0;
94143 bool locked = false;
94144 + unsigned long pax_task_size = TASK_SIZE;
94145
94146 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
94147 return ret;
94148 @@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94149 if (!new_len)
94150 return ret;
94151
94152 +#ifdef CONFIG_PAX_SEGMEXEC
94153 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
94154 + pax_task_size = SEGMEXEC_TASK_SIZE;
94155 +#endif
94156 +
94157 + pax_task_size -= PAGE_SIZE;
94158 +
94159 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
94160 + old_len > pax_task_size || addr > pax_task_size-old_len)
94161 + return ret;
94162 +
94163 down_write(&current->mm->mmap_sem);
94164
94165 if (flags & MREMAP_FIXED) {
94166 @@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94167 new_addr = addr;
94168 }
94169 ret = addr;
94170 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
94171 goto out;
94172 }
94173 }
94174 @@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94175 goto out;
94176 }
94177
94178 + map_flags = vma->vm_flags;
94179 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
94180 + if (!(ret & ~PAGE_MASK)) {
94181 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
94182 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
94183 + }
94184 }
94185 out:
94186 if (ret & ~PAGE_MASK)
94187 diff --git a/mm/nommu.c b/mm/nommu.c
94188 index 8740213..f87e25b 100644
94189 --- a/mm/nommu.c
94190 +++ b/mm/nommu.c
94191 @@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
94192 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
94193 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94194 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94195 -int heap_stack_gap = 0;
94196
94197 atomic_long_t mmap_pages_allocated;
94198
94199 @@ -845,15 +844,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
94200 EXPORT_SYMBOL(find_vma);
94201
94202 /*
94203 - * find a VMA
94204 - * - we don't extend stack VMAs under NOMMU conditions
94205 - */
94206 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
94207 -{
94208 - return find_vma(mm, addr);
94209 -}
94210 -
94211 -/*
94212 * expand a stack to a given address
94213 * - not supported under NOMMU conditions
94214 */
94215 @@ -1564,6 +1554,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94216
94217 /* most fields are the same, copy all, and then fixup */
94218 *new = *vma;
94219 + INIT_LIST_HEAD(&new->anon_vma_chain);
94220 *region = *vma->vm_region;
94221 new->vm_region = region;
94222
94223 @@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
94224 }
94225 EXPORT_SYMBOL(generic_file_remap_pages);
94226
94227 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94228 - unsigned long addr, void *buf, int len, int write)
94229 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94230 + unsigned long addr, void *buf, size_t len, int write)
94231 {
94232 struct vm_area_struct *vma;
94233
94234 @@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94235 *
94236 * The caller must hold a reference on @mm.
94237 */
94238 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94239 - void *buf, int len, int write)
94240 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
94241 + void *buf, size_t len, int write)
94242 {
94243 return __access_remote_vm(NULL, mm, addr, buf, len, write);
94244 }
94245 @@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94246 * Access another process' address space.
94247 * - source/target buffer must be kernel space
94248 */
94249 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
94250 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
94251 {
94252 struct mm_struct *mm;
94253
94254 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
94255 index 7106cb1..0805f48 100644
94256 --- a/mm/page-writeback.c
94257 +++ b/mm/page-writeback.c
94258 @@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
94259 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
94260 * - the bdi dirty thresh drops quickly due to change of JBOD workload
94261 */
94262 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
94263 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
94264 unsigned long thresh,
94265 unsigned long bg_thresh,
94266 unsigned long dirty,
94267 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
94268 index 3bac76a..bf9f9ae 100644
94269 --- a/mm/page_alloc.c
94270 +++ b/mm/page_alloc.c
94271 @@ -61,6 +61,7 @@
94272 #include <linux/page-debug-flags.h>
94273 #include <linux/hugetlb.h>
94274 #include <linux/sched/rt.h>
94275 +#include <linux/random.h>
94276
94277 #include <asm/sections.h>
94278 #include <asm/tlbflush.h>
94279 @@ -354,7 +355,7 @@ out:
94280 * This usage means that zero-order pages may not be compound.
94281 */
94282
94283 -static void free_compound_page(struct page *page)
94284 +void free_compound_page(struct page *page)
94285 {
94286 __free_pages_ok(page, compound_order(page));
94287 }
94288 @@ -728,6 +729,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94289 int i;
94290 int bad = 0;
94291
94292 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94293 + unsigned long index = 1UL << order;
94294 +#endif
94295 +
94296 trace_mm_page_free(page, order);
94297 kmemcheck_free_shadow(page, order);
94298
94299 @@ -744,6 +749,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94300 debug_check_no_obj_freed(page_address(page),
94301 PAGE_SIZE << order);
94302 }
94303 +
94304 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94305 + for (; index; --index)
94306 + sanitize_highpage(page + index - 1);
94307 +#endif
94308 +
94309 arch_free_page(page, order);
94310 kernel_map_pages(page, 1 << order, 0);
94311
94312 @@ -766,6 +777,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
94313 local_irq_restore(flags);
94314 }
94315
94316 +#ifdef CONFIG_PAX_LATENT_ENTROPY
94317 +bool __meminitdata extra_latent_entropy;
94318 +
94319 +static int __init setup_pax_extra_latent_entropy(char *str)
94320 +{
94321 + extra_latent_entropy = true;
94322 + return 0;
94323 +}
94324 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
94325 +
94326 +volatile u64 latent_entropy __latent_entropy;
94327 +EXPORT_SYMBOL(latent_entropy);
94328 +#endif
94329 +
94330 void __init __free_pages_bootmem(struct page *page, unsigned int order)
94331 {
94332 unsigned int nr_pages = 1 << order;
94333 @@ -781,6 +806,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
94334 __ClearPageReserved(p);
94335 set_page_count(p, 0);
94336
94337 +#ifdef CONFIG_PAX_LATENT_ENTROPY
94338 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
94339 + u64 hash = 0;
94340 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
94341 + const u64 *data = lowmem_page_address(page);
94342 +
94343 + for (index = 0; index < end; index++)
94344 + hash ^= hash + data[index];
94345 + latent_entropy ^= hash;
94346 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
94347 + }
94348 +#endif
94349 +
94350 page_zone(page)->managed_pages += nr_pages;
94351 set_page_refcounted(page);
94352 __free_pages(page, order);
94353 @@ -897,8 +935,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
94354 arch_alloc_page(page, order);
94355 kernel_map_pages(page, 1 << order, 1);
94356
94357 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
94358 if (gfp_flags & __GFP_ZERO)
94359 prep_zero_page(page, order, gfp_flags);
94360 +#endif
94361
94362 if (order && (gfp_flags & __GFP_COMP))
94363 prep_compound_page(page, order);
94364 diff --git a/mm/page_io.c b/mm/page_io.c
94365 index 7c59ef6..1358905 100644
94366 --- a/mm/page_io.c
94367 +++ b/mm/page_io.c
94368 @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
94369 struct file *swap_file = sis->swap_file;
94370 struct address_space *mapping = swap_file->f_mapping;
94371 struct iovec iov = {
94372 - .iov_base = kmap(page),
94373 + .iov_base = (void __force_user *)kmap(page),
94374 .iov_len = PAGE_SIZE,
94375 };
94376
94377 diff --git a/mm/percpu.c b/mm/percpu.c
94378 index 036cfe0..980d0fa 100644
94379 --- a/mm/percpu.c
94380 +++ b/mm/percpu.c
94381 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
94382 static unsigned int pcpu_high_unit_cpu __read_mostly;
94383
94384 /* the address of the first chunk which starts with the kernel static area */
94385 -void *pcpu_base_addr __read_mostly;
94386 +void *pcpu_base_addr __read_only;
94387 EXPORT_SYMBOL_GPL(pcpu_base_addr);
94388
94389 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
94390 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
94391 index fd26d04..0cea1b0 100644
94392 --- a/mm/process_vm_access.c
94393 +++ b/mm/process_vm_access.c
94394 @@ -13,6 +13,7 @@
94395 #include <linux/uio.h>
94396 #include <linux/sched.h>
94397 #include <linux/highmem.h>
94398 +#include <linux/security.h>
94399 #include <linux/ptrace.h>
94400 #include <linux/slab.h>
94401 #include <linux/syscalls.h>
94402 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94403 size_t iov_l_curr_offset = 0;
94404 ssize_t iov_len;
94405
94406 + return -ENOSYS; // PaX: until properly audited
94407 +
94408 /*
94409 * Work out how many pages of struct pages we're going to need
94410 * when eventually calling get_user_pages
94411 */
94412 for (i = 0; i < riovcnt; i++) {
94413 iov_len = rvec[i].iov_len;
94414 - if (iov_len > 0) {
94415 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
94416 - + iov_len)
94417 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
94418 - / PAGE_SIZE + 1;
94419 - nr_pages = max(nr_pages, nr_pages_iov);
94420 - }
94421 + if (iov_len <= 0)
94422 + continue;
94423 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
94424 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
94425 + nr_pages = max(nr_pages, nr_pages_iov);
94426 }
94427
94428 if (nr_pages == 0)
94429 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94430 goto free_proc_pages;
94431 }
94432
94433 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
94434 + rc = -EPERM;
94435 + goto put_task_struct;
94436 + }
94437 +
94438 mm = mm_access(task, PTRACE_MODE_ATTACH);
94439 if (!mm || IS_ERR(mm)) {
94440 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
94441 diff --git a/mm/rmap.c b/mm/rmap.c
94442 index 8fc049f..1b21e12 100644
94443 --- a/mm/rmap.c
94444 +++ b/mm/rmap.c
94445 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94446 struct anon_vma *anon_vma = vma->anon_vma;
94447 struct anon_vma_chain *avc;
94448
94449 +#ifdef CONFIG_PAX_SEGMEXEC
94450 + struct anon_vma_chain *avc_m = NULL;
94451 +#endif
94452 +
94453 might_sleep();
94454 if (unlikely(!anon_vma)) {
94455 struct mm_struct *mm = vma->vm_mm;
94456 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94457 if (!avc)
94458 goto out_enomem;
94459
94460 +#ifdef CONFIG_PAX_SEGMEXEC
94461 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
94462 + if (!avc_m)
94463 + goto out_enomem_free_avc;
94464 +#endif
94465 +
94466 anon_vma = find_mergeable_anon_vma(vma);
94467 allocated = NULL;
94468 if (!anon_vma) {
94469 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94470 /* page_table_lock to protect against threads */
94471 spin_lock(&mm->page_table_lock);
94472 if (likely(!vma->anon_vma)) {
94473 +
94474 +#ifdef CONFIG_PAX_SEGMEXEC
94475 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
94476 +
94477 + if (vma_m) {
94478 + BUG_ON(vma_m->anon_vma);
94479 + vma_m->anon_vma = anon_vma;
94480 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
94481 + avc_m = NULL;
94482 + }
94483 +#endif
94484 +
94485 vma->anon_vma = anon_vma;
94486 anon_vma_chain_link(vma, avc, anon_vma);
94487 allocated = NULL;
94488 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94489
94490 if (unlikely(allocated))
94491 put_anon_vma(allocated);
94492 +
94493 +#ifdef CONFIG_PAX_SEGMEXEC
94494 + if (unlikely(avc_m))
94495 + anon_vma_chain_free(avc_m);
94496 +#endif
94497 +
94498 if (unlikely(avc))
94499 anon_vma_chain_free(avc);
94500 }
94501 return 0;
94502
94503 out_enomem_free_avc:
94504 +
94505 +#ifdef CONFIG_PAX_SEGMEXEC
94506 + if (avc_m)
94507 + anon_vma_chain_free(avc_m);
94508 +#endif
94509 +
94510 anon_vma_chain_free(avc);
94511 out_enomem:
94512 return -ENOMEM;
94513 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
94514 * Attach the anon_vmas from src to dst.
94515 * Returns 0 on success, -ENOMEM on failure.
94516 */
94517 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94518 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
94519 {
94520 struct anon_vma_chain *avc, *pavc;
94521 struct anon_vma *root = NULL;
94522 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94523 * the corresponding VMA in the parent process is attached to.
94524 * Returns 0 on success, non-zero on failure.
94525 */
94526 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
94527 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
94528 {
94529 struct anon_vma_chain *avc;
94530 struct anon_vma *anon_vma;
94531 @@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
94532 void __init anon_vma_init(void)
94533 {
94534 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
94535 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
94536 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
94537 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
94538 + anon_vma_ctor);
94539 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
94540 + SLAB_PANIC|SLAB_NO_SANITIZE);
94541 }
94542
94543 /*
94544 diff --git a/mm/shmem.c b/mm/shmem.c
94545 index 1f18c9d..3e03d33 100644
94546 --- a/mm/shmem.c
94547 +++ b/mm/shmem.c
94548 @@ -33,7 +33,7 @@
94549 #include <linux/swap.h>
94550 #include <linux/aio.h>
94551
94552 -static struct vfsmount *shm_mnt;
94553 +struct vfsmount *shm_mnt;
94554
94555 #ifdef CONFIG_SHMEM
94556 /*
94557 @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
94558 #define BOGO_DIRENT_SIZE 20
94559
94560 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
94561 -#define SHORT_SYMLINK_LEN 128
94562 +#define SHORT_SYMLINK_LEN 64
94563
94564 /*
94565 * shmem_fallocate and shmem_writepage communicate via inode->i_private
94566 @@ -2218,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
94567 static int shmem_xattr_validate(const char *name)
94568 {
94569 struct { const char *prefix; size_t len; } arr[] = {
94570 +
94571 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94572 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
94573 +#endif
94574 +
94575 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
94576 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
94577 };
94578 @@ -2273,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
94579 if (err)
94580 return err;
94581
94582 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94583 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
94584 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
94585 + return -EOPNOTSUPP;
94586 + if (size > 8)
94587 + return -EINVAL;
94588 + }
94589 +#endif
94590 +
94591 return simple_xattr_set(&info->xattrs, name, value, size, flags);
94592 }
94593
94594 @@ -2585,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
94595 int err = -ENOMEM;
94596
94597 /* Round up to L1_CACHE_BYTES to resist false sharing */
94598 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
94599 - L1_CACHE_BYTES), GFP_KERNEL);
94600 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
94601 if (!sbinfo)
94602 return -ENOMEM;
94603
94604 diff --git a/mm/slab.c b/mm/slab.c
94605 index b264214..83872cd 100644
94606 --- a/mm/slab.c
94607 +++ b/mm/slab.c
94608 @@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94609 if ((x)->max_freeable < i) \
94610 (x)->max_freeable = i; \
94611 } while (0)
94612 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
94613 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
94614 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
94615 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
94616 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
94617 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
94618 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
94619 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
94620 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
94621 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
94622 #else
94623 #define STATS_INC_ACTIVE(x) do { } while (0)
94624 #define STATS_DEC_ACTIVE(x) do { } while (0)
94625 @@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94626 #define STATS_INC_ALLOCMISS(x) do { } while (0)
94627 #define STATS_INC_FREEHIT(x) do { } while (0)
94628 #define STATS_INC_FREEMISS(x) do { } while (0)
94629 +#define STATS_INC_SANITIZED(x) do { } while (0)
94630 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
94631 #endif
94632
94633 #if DEBUG
94634 @@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
94635 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
94636 */
94637 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
94638 - const struct page *page, void *obj)
94639 + const struct page *page, const void *obj)
94640 {
94641 u32 offset = (obj - page->s_mem);
94642 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
94643 @@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
94644 */
94645
94646 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
94647 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
94648 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94649
94650 if (INDEX_AC != INDEX_NODE)
94651 kmalloc_caches[INDEX_NODE] =
94652 create_kmalloc_cache("kmalloc-node",
94653 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
94654 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94655
94656 slab_early_init = 0;
94657
94658 @@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
94659 struct array_cache *ac = cpu_cache_get(cachep);
94660
94661 check_irq_off();
94662 +
94663 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94664 + if (pax_sanitize_slab) {
94665 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
94666 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
94667 +
94668 + if (cachep->ctor)
94669 + cachep->ctor(objp);
94670 +
94671 + STATS_INC_SANITIZED(cachep);
94672 + } else
94673 + STATS_INC_NOT_SANITIZED(cachep);
94674 + }
94675 +#endif
94676 +
94677 kmemleak_free_recursive(objp, cachep->flags);
94678 objp = cache_free_debugcheck(cachep, objp, caller);
94679
94680 @@ -3656,6 +3675,7 @@ void kfree(const void *objp)
94681
94682 if (unlikely(ZERO_OR_NULL_PTR(objp)))
94683 return;
94684 + VM_BUG_ON(!virt_addr_valid(objp));
94685 local_irq_save(flags);
94686 kfree_debugcheck(objp);
94687 c = virt_to_cache(objp);
94688 @@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
94689 }
94690 /* cpu stats */
94691 {
94692 - unsigned long allochit = atomic_read(&cachep->allochit);
94693 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
94694 - unsigned long freehit = atomic_read(&cachep->freehit);
94695 - unsigned long freemiss = atomic_read(&cachep->freemiss);
94696 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
94697 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
94698 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
94699 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
94700
94701 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
94702 allochit, allocmiss, freehit, freemiss);
94703 }
94704 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94705 + {
94706 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
94707 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
94708 +
94709 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
94710 + }
94711 +#endif
94712 #endif
94713 }
94714
94715 @@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
94716 static int __init slab_proc_init(void)
94717 {
94718 #ifdef CONFIG_DEBUG_SLAB_LEAK
94719 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
94720 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
94721 #endif
94722 return 0;
94723 }
94724 module_init(slab_proc_init);
94725 #endif
94726
94727 +bool is_usercopy_object(const void *ptr)
94728 +{
94729 + struct page *page;
94730 + struct kmem_cache *cachep;
94731 +
94732 + if (ZERO_OR_NULL_PTR(ptr))
94733 + return false;
94734 +
94735 + if (!slab_is_available())
94736 + return false;
94737 +
94738 + if (!virt_addr_valid(ptr))
94739 + return false;
94740 +
94741 + page = virt_to_head_page(ptr);
94742 +
94743 + if (!PageSlab(page))
94744 + return false;
94745 +
94746 + cachep = page->slab_cache;
94747 + return cachep->flags & SLAB_USERCOPY;
94748 +}
94749 +
94750 +#ifdef CONFIG_PAX_USERCOPY
94751 +const char *check_heap_object(const void *ptr, unsigned long n)
94752 +{
94753 + struct page *page;
94754 + struct kmem_cache *cachep;
94755 + unsigned int objnr;
94756 + unsigned long offset;
94757 +
94758 + if (ZERO_OR_NULL_PTR(ptr))
94759 + return "<null>";
94760 +
94761 + if (!virt_addr_valid(ptr))
94762 + return NULL;
94763 +
94764 + page = virt_to_head_page(ptr);
94765 +
94766 + if (!PageSlab(page))
94767 + return NULL;
94768 +
94769 + cachep = page->slab_cache;
94770 + if (!(cachep->flags & SLAB_USERCOPY))
94771 + return cachep->name;
94772 +
94773 + objnr = obj_to_index(cachep, page, ptr);
94774 + BUG_ON(objnr >= cachep->num);
94775 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
94776 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
94777 + return NULL;
94778 +
94779 + return cachep->name;
94780 +}
94781 +#endif
94782 +
94783 /**
94784 * ksize - get the actual amount of memory allocated for a given object
94785 * @objp: Pointer to the object
94786 diff --git a/mm/slab.h b/mm/slab.h
94787 index 8184a7c..ab27737 100644
94788 --- a/mm/slab.h
94789 +++ b/mm/slab.h
94790 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
94791 /* The slab cache that manages slab cache information */
94792 extern struct kmem_cache *kmem_cache;
94793
94794 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94795 +#ifdef CONFIG_X86_64
94796 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
94797 +#else
94798 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
94799 +#endif
94800 +extern bool pax_sanitize_slab;
94801 +#endif
94802 +
94803 unsigned long calculate_alignment(unsigned long flags,
94804 unsigned long align, unsigned long size);
94805
94806 @@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94807
94808 /* Legal flag mask for kmem_cache_create(), for various configurations */
94809 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
94810 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
94811 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
94812 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
94813
94814 #if defined(CONFIG_DEBUG_SLAB)
94815 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
94816 @@ -257,6 +267,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
94817 return s;
94818
94819 page = virt_to_head_page(x);
94820 +
94821 + BUG_ON(!PageSlab(page));
94822 +
94823 cachep = page->slab_cache;
94824 if (slab_equal_or_root(cachep, s))
94825 return cachep;
94826 diff --git a/mm/slab_common.c b/mm/slab_common.c
94827 index 1ec3c61..2067c11 100644
94828 --- a/mm/slab_common.c
94829 +++ b/mm/slab_common.c
94830 @@ -23,11 +23,22 @@
94831
94832 #include "slab.h"
94833
94834 -enum slab_state slab_state;
94835 +enum slab_state slab_state __read_only;
94836 LIST_HEAD(slab_caches);
94837 DEFINE_MUTEX(slab_mutex);
94838 struct kmem_cache *kmem_cache;
94839
94840 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94841 +bool pax_sanitize_slab __read_only = true;
94842 +static int __init pax_sanitize_slab_setup(char *str)
94843 +{
94844 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
94845 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
94846 + return 1;
94847 +}
94848 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
94849 +#endif
94850 +
94851 #ifdef CONFIG_DEBUG_VM
94852 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
94853 size_t size)
94854 @@ -225,7 +236,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
94855 if (err)
94856 goto out_free_cache;
94857
94858 - s->refcount = 1;
94859 + atomic_set(&s->refcount, 1);
94860 list_add(&s->list, &slab_caches);
94861 memcg_register_cache(s);
94862
94863 @@ -278,8 +289,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
94864
94865 get_online_cpus();
94866 mutex_lock(&slab_mutex);
94867 - s->refcount--;
94868 - if (!s->refcount) {
94869 + if (atomic_dec_and_test(&s->refcount)) {
94870 list_del(&s->list);
94871
94872 if (!__kmem_cache_shutdown(s)) {
94873 @@ -326,7 +336,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
94874 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
94875 name, size, err);
94876
94877 - s->refcount = -1; /* Exempt from merging for now */
94878 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
94879 }
94880
94881 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
94882 @@ -339,7 +349,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
94883
94884 create_boot_cache(s, name, size, flags);
94885 list_add(&s->list, &slab_caches);
94886 - s->refcount = 1;
94887 + atomic_set(&s->refcount, 1);
94888 return s;
94889 }
94890
94891 @@ -351,6 +361,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
94892 EXPORT_SYMBOL(kmalloc_dma_caches);
94893 #endif
94894
94895 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94896 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
94897 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
94898 +#endif
94899 +
94900 /*
94901 * Conversion table for small slabs sizes / 8 to the index in the
94902 * kmalloc array. This is necessary for slabs < 192 since we have non power
94903 @@ -415,6 +430,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
94904 return kmalloc_dma_caches[index];
94905
94906 #endif
94907 +
94908 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94909 + if (unlikely((flags & GFP_USERCOPY)))
94910 + return kmalloc_usercopy_caches[index];
94911 +
94912 +#endif
94913 +
94914 return kmalloc_caches[index];
94915 }
94916
94917 @@ -471,7 +493,7 @@ void __init create_kmalloc_caches(unsigned long flags)
94918 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
94919 if (!kmalloc_caches[i]) {
94920 kmalloc_caches[i] = create_kmalloc_cache(NULL,
94921 - 1 << i, flags);
94922 + 1 << i, SLAB_USERCOPY | flags);
94923 }
94924
94925 /*
94926 @@ -480,10 +502,10 @@ void __init create_kmalloc_caches(unsigned long flags)
94927 * earlier power of two caches
94928 */
94929 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
94930 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
94931 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
94932
94933 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
94934 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
94935 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
94936 }
94937
94938 /* Kmalloc array is now usable */
94939 @@ -516,6 +538,23 @@ void __init create_kmalloc_caches(unsigned long flags)
94940 }
94941 }
94942 #endif
94943 +
94944 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94945 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
94946 + struct kmem_cache *s = kmalloc_caches[i];
94947 +
94948 + if (s) {
94949 + int size = kmalloc_size(i);
94950 + char *n = kasprintf(GFP_NOWAIT,
94951 + "usercopy-kmalloc-%d", size);
94952 +
94953 + BUG_ON(!n);
94954 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
94955 + size, SLAB_USERCOPY | flags);
94956 + }
94957 + }
94958 +#endif
94959 +
94960 }
94961 #endif /* !CONFIG_SLOB */
94962
94963 @@ -556,6 +595,9 @@ void print_slabinfo_header(struct seq_file *m)
94964 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
94965 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
94966 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
94967 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94968 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
94969 +#endif
94970 #endif
94971 seq_putc(m, '\n');
94972 }
94973 diff --git a/mm/slob.c b/mm/slob.c
94974 index 4bf8809..98a6914 100644
94975 --- a/mm/slob.c
94976 +++ b/mm/slob.c
94977 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
94978 /*
94979 * Return the size of a slob block.
94980 */
94981 -static slobidx_t slob_units(slob_t *s)
94982 +static slobidx_t slob_units(const slob_t *s)
94983 {
94984 if (s->units > 0)
94985 return s->units;
94986 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
94987 /*
94988 * Return the next free slob block pointer after this one.
94989 */
94990 -static slob_t *slob_next(slob_t *s)
94991 +static slob_t *slob_next(const slob_t *s)
94992 {
94993 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
94994 slobidx_t next;
94995 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
94996 /*
94997 * Returns true if s is the last free block in its page.
94998 */
94999 -static int slob_last(slob_t *s)
95000 +static int slob_last(const slob_t *s)
95001 {
95002 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
95003 }
95004
95005 -static void *slob_new_pages(gfp_t gfp, int order, int node)
95006 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
95007 {
95008 - void *page;
95009 + struct page *page;
95010
95011 #ifdef CONFIG_NUMA
95012 if (node != NUMA_NO_NODE)
95013 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
95014 if (!page)
95015 return NULL;
95016
95017 - return page_address(page);
95018 + __SetPageSlab(page);
95019 + return page;
95020 }
95021
95022 -static void slob_free_pages(void *b, int order)
95023 +static void slob_free_pages(struct page *sp, int order)
95024 {
95025 if (current->reclaim_state)
95026 current->reclaim_state->reclaimed_slab += 1 << order;
95027 - free_pages((unsigned long)b, order);
95028 + __ClearPageSlab(sp);
95029 + page_mapcount_reset(sp);
95030 + sp->private = 0;
95031 + __free_pages(sp, order);
95032 }
95033
95034 /*
95035 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
95036
95037 /* Not enough space: must allocate a new page */
95038 if (!b) {
95039 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95040 - if (!b)
95041 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95042 + if (!sp)
95043 return NULL;
95044 - sp = virt_to_page(b);
95045 - __SetPageSlab(sp);
95046 + b = page_address(sp);
95047
95048 spin_lock_irqsave(&slob_lock, flags);
95049 sp->units = SLOB_UNITS(PAGE_SIZE);
95050 sp->freelist = b;
95051 + sp->private = 0;
95052 INIT_LIST_HEAD(&sp->list);
95053 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
95054 set_slob_page_free(sp, slob_list);
95055 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
95056 if (slob_page_free(sp))
95057 clear_slob_page_free(sp);
95058 spin_unlock_irqrestore(&slob_lock, flags);
95059 - __ClearPageSlab(sp);
95060 - page_mapcount_reset(sp);
95061 - slob_free_pages(b, 0);
95062 + slob_free_pages(sp, 0);
95063 return;
95064 }
95065
95066 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95067 + if (pax_sanitize_slab)
95068 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
95069 +#endif
95070 +
95071 if (!slob_page_free(sp)) {
95072 /* This slob page is about to become partially free. Easy! */
95073 sp->units = units;
95074 @@ -424,11 +431,10 @@ out:
95075 */
95076
95077 static __always_inline void *
95078 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95079 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
95080 {
95081 - unsigned int *m;
95082 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95083 - void *ret;
95084 + slob_t *m;
95085 + void *ret = NULL;
95086
95087 gfp &= gfp_allowed_mask;
95088
95089 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95090
95091 if (!m)
95092 return NULL;
95093 - *m = size;
95094 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
95095 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
95096 + m[0].units = size;
95097 + m[1].units = align;
95098 ret = (void *)m + align;
95099
95100 trace_kmalloc_node(caller, ret,
95101 size, size + align, gfp, node);
95102 } else {
95103 unsigned int order = get_order(size);
95104 + struct page *page;
95105
95106 if (likely(order))
95107 gfp |= __GFP_COMP;
95108 - ret = slob_new_pages(gfp, order, node);
95109 + page = slob_new_pages(gfp, order, node);
95110 + if (page) {
95111 + ret = page_address(page);
95112 + page->private = size;
95113 + }
95114
95115 trace_kmalloc_node(caller, ret,
95116 size, PAGE_SIZE << order, gfp, node);
95117 }
95118
95119 - kmemleak_alloc(ret, size, 1, gfp);
95120 + return ret;
95121 +}
95122 +
95123 +static __always_inline void *
95124 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95125 +{
95126 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95127 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
95128 +
95129 + if (!ZERO_OR_NULL_PTR(ret))
95130 + kmemleak_alloc(ret, size, 1, gfp);
95131 return ret;
95132 }
95133
95134 @@ -493,34 +517,112 @@ void kfree(const void *block)
95135 return;
95136 kmemleak_free(block);
95137
95138 + VM_BUG_ON(!virt_addr_valid(block));
95139 sp = virt_to_page(block);
95140 - if (PageSlab(sp)) {
95141 + VM_BUG_ON(!PageSlab(sp));
95142 + if (!sp->private) {
95143 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95144 - unsigned int *m = (unsigned int *)(block - align);
95145 - slob_free(m, *m + align);
95146 - } else
95147 + slob_t *m = (slob_t *)(block - align);
95148 + slob_free(m, m[0].units + align);
95149 + } else {
95150 + __ClearPageSlab(sp);
95151 + page_mapcount_reset(sp);
95152 + sp->private = 0;
95153 __free_pages(sp, compound_order(sp));
95154 + }
95155 }
95156 EXPORT_SYMBOL(kfree);
95157
95158 +bool is_usercopy_object(const void *ptr)
95159 +{
95160 + if (!slab_is_available())
95161 + return false;
95162 +
95163 + // PAX: TODO
95164 +
95165 + return false;
95166 +}
95167 +
95168 +#ifdef CONFIG_PAX_USERCOPY
95169 +const char *check_heap_object(const void *ptr, unsigned long n)
95170 +{
95171 + struct page *page;
95172 + const slob_t *free;
95173 + const void *base;
95174 + unsigned long flags;
95175 +
95176 + if (ZERO_OR_NULL_PTR(ptr))
95177 + return "<null>";
95178 +
95179 + if (!virt_addr_valid(ptr))
95180 + return NULL;
95181 +
95182 + page = virt_to_head_page(ptr);
95183 + if (!PageSlab(page))
95184 + return NULL;
95185 +
95186 + if (page->private) {
95187 + base = page;
95188 + if (base <= ptr && n <= page->private - (ptr - base))
95189 + return NULL;
95190 + return "<slob>";
95191 + }
95192 +
95193 + /* some tricky double walking to find the chunk */
95194 + spin_lock_irqsave(&slob_lock, flags);
95195 + base = (void *)((unsigned long)ptr & PAGE_MASK);
95196 + free = page->freelist;
95197 +
95198 + while (!slob_last(free) && (void *)free <= ptr) {
95199 + base = free + slob_units(free);
95200 + free = slob_next(free);
95201 + }
95202 +
95203 + while (base < (void *)free) {
95204 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
95205 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
95206 + int offset;
95207 +
95208 + if (ptr < base + align)
95209 + break;
95210 +
95211 + offset = ptr - base - align;
95212 + if (offset >= m) {
95213 + base += size;
95214 + continue;
95215 + }
95216 +
95217 + if (n > m - offset)
95218 + break;
95219 +
95220 + spin_unlock_irqrestore(&slob_lock, flags);
95221 + return NULL;
95222 + }
95223 +
95224 + spin_unlock_irqrestore(&slob_lock, flags);
95225 + return "<slob>";
95226 +}
95227 +#endif
95228 +
95229 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
95230 size_t ksize(const void *block)
95231 {
95232 struct page *sp;
95233 int align;
95234 - unsigned int *m;
95235 + slob_t *m;
95236
95237 BUG_ON(!block);
95238 if (unlikely(block == ZERO_SIZE_PTR))
95239 return 0;
95240
95241 sp = virt_to_page(block);
95242 - if (unlikely(!PageSlab(sp)))
95243 - return PAGE_SIZE << compound_order(sp);
95244 + VM_BUG_ON(!PageSlab(sp));
95245 + if (sp->private)
95246 + return sp->private;
95247
95248 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95249 - m = (unsigned int *)(block - align);
95250 - return SLOB_UNITS(*m) * SLOB_UNIT;
95251 + m = (slob_t *)(block - align);
95252 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
95253 }
95254 EXPORT_SYMBOL(ksize);
95255
95256 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
95257
95258 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
95259 {
95260 - void *b;
95261 + void *b = NULL;
95262
95263 flags &= gfp_allowed_mask;
95264
95265 lockdep_trace_alloc(flags);
95266
95267 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95268 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
95269 +#else
95270 if (c->size < PAGE_SIZE) {
95271 b = slob_alloc(c->size, flags, c->align, node);
95272 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95273 SLOB_UNITS(c->size) * SLOB_UNIT,
95274 flags, node);
95275 } else {
95276 - b = slob_new_pages(flags, get_order(c->size), node);
95277 + struct page *sp;
95278 +
95279 + sp = slob_new_pages(flags, get_order(c->size), node);
95280 + if (sp) {
95281 + b = page_address(sp);
95282 + sp->private = c->size;
95283 + }
95284 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95285 PAGE_SIZE << get_order(c->size),
95286 flags, node);
95287 }
95288 +#endif
95289
95290 if (b && c->ctor)
95291 c->ctor(b);
95292 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
95293
95294 static void __kmem_cache_free(void *b, int size)
95295 {
95296 - if (size < PAGE_SIZE)
95297 + struct page *sp;
95298 +
95299 + sp = virt_to_page(b);
95300 + BUG_ON(!PageSlab(sp));
95301 + if (!sp->private)
95302 slob_free(b, size);
95303 else
95304 - slob_free_pages(b, get_order(size));
95305 + slob_free_pages(sp, get_order(size));
95306 }
95307
95308 static void kmem_rcu_free(struct rcu_head *head)
95309 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
95310
95311 void kmem_cache_free(struct kmem_cache *c, void *b)
95312 {
95313 + int size = c->size;
95314 +
95315 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95316 + if (size + c->align < PAGE_SIZE) {
95317 + size += c->align;
95318 + b -= c->align;
95319 + }
95320 +#endif
95321 +
95322 kmemleak_free_recursive(b, c->flags);
95323 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
95324 struct slob_rcu *slob_rcu;
95325 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
95326 - slob_rcu->size = c->size;
95327 + slob_rcu = b + (size - sizeof(struct slob_rcu));
95328 + slob_rcu->size = size;
95329 call_rcu(&slob_rcu->head, kmem_rcu_free);
95330 } else {
95331 - __kmem_cache_free(b, c->size);
95332 + __kmem_cache_free(b, size);
95333 }
95334
95335 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95336 + trace_kfree(_RET_IP_, b);
95337 +#else
95338 trace_kmem_cache_free(_RET_IP_, b);
95339 +#endif
95340 +
95341 }
95342 EXPORT_SYMBOL(kmem_cache_free);
95343
95344 diff --git a/mm/slub.c b/mm/slub.c
95345 index 25f14ad..ff4d0b7 100644
95346 --- a/mm/slub.c
95347 +++ b/mm/slub.c
95348 @@ -207,7 +207,7 @@ struct track {
95349
95350 enum track_item { TRACK_ALLOC, TRACK_FREE };
95351
95352 -#ifdef CONFIG_SYSFS
95353 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95354 static int sysfs_slab_add(struct kmem_cache *);
95355 static int sysfs_slab_alias(struct kmem_cache *, const char *);
95356 static void sysfs_slab_remove(struct kmem_cache *);
95357 @@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
95358 if (!t->addr)
95359 return;
95360
95361 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
95362 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
95363 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
95364 #ifdef CONFIG_STACKTRACE
95365 {
95366 @@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
95367
95368 slab_free_hook(s, x);
95369
95370 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95371 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
95372 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
95373 + if (s->ctor)
95374 + s->ctor(x);
95375 + }
95376 +#endif
95377 +
95378 redo:
95379 /*
95380 * Determine the currently cpus per cpu slab.
95381 @@ -2733,7 +2741,7 @@ static int slub_min_objects;
95382 * Merge control. If this is set then no merging of slab caches will occur.
95383 * (Could be removed. This was introduced to pacify the merge skeptics.)
95384 */
95385 -static int slub_nomerge;
95386 +static int slub_nomerge = 1;
95387
95388 /*
95389 * Calculate the order of allocation given an slab object size.
95390 @@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
95391 s->inuse = size;
95392
95393 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
95394 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95395 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
95396 +#endif
95397 s->ctor)) {
95398 /*
95399 * Relocate free pointer after the object if it is not
95400 @@ -3359,6 +3370,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
95401 EXPORT_SYMBOL(__kmalloc_node);
95402 #endif
95403
95404 +bool is_usercopy_object(const void *ptr)
95405 +{
95406 + struct page *page;
95407 + struct kmem_cache *s;
95408 +
95409 + if (ZERO_OR_NULL_PTR(ptr))
95410 + return false;
95411 +
95412 + if (!slab_is_available())
95413 + return false;
95414 +
95415 + if (!virt_addr_valid(ptr))
95416 + return false;
95417 +
95418 + page = virt_to_head_page(ptr);
95419 +
95420 + if (!PageSlab(page))
95421 + return false;
95422 +
95423 + s = page->slab_cache;
95424 + return s->flags & SLAB_USERCOPY;
95425 +}
95426 +
95427 +#ifdef CONFIG_PAX_USERCOPY
95428 +const char *check_heap_object(const void *ptr, unsigned long n)
95429 +{
95430 + struct page *page;
95431 + struct kmem_cache *s;
95432 + unsigned long offset;
95433 +
95434 + if (ZERO_OR_NULL_PTR(ptr))
95435 + return "<null>";
95436 +
95437 + if (!virt_addr_valid(ptr))
95438 + return NULL;
95439 +
95440 + page = virt_to_head_page(ptr);
95441 +
95442 + if (!PageSlab(page))
95443 + return NULL;
95444 +
95445 + s = page->slab_cache;
95446 + if (!(s->flags & SLAB_USERCOPY))
95447 + return s->name;
95448 +
95449 + offset = (ptr - page_address(page)) % s->size;
95450 + if (offset <= s->object_size && n <= s->object_size - offset)
95451 + return NULL;
95452 +
95453 + return s->name;
95454 +}
95455 +#endif
95456 +
95457 size_t ksize(const void *object)
95458 {
95459 struct page *page;
95460 @@ -3387,6 +3451,7 @@ void kfree(const void *x)
95461 if (unlikely(ZERO_OR_NULL_PTR(x)))
95462 return;
95463
95464 + VM_BUG_ON(!virt_addr_valid(x));
95465 page = virt_to_head_page(x);
95466 if (unlikely(!PageSlab(page))) {
95467 BUG_ON(!PageCompound(page));
95468 @@ -3692,7 +3757,7 @@ static int slab_unmergeable(struct kmem_cache *s)
95469 /*
95470 * We may have set a slab to be unmergeable during bootstrap.
95471 */
95472 - if (s->refcount < 0)
95473 + if (atomic_read(&s->refcount) < 0)
95474 return 1;
95475
95476 return 0;
95477 @@ -3750,7 +3815,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95478
95479 s = find_mergeable(memcg, size, align, flags, name, ctor);
95480 if (s) {
95481 - s->refcount++;
95482 + atomic_inc(&s->refcount);
95483 /*
95484 * Adjust the object sizes so that we clear
95485 * the complete object on kzalloc.
95486 @@ -3759,7 +3824,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95487 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
95488
95489 if (sysfs_slab_alias(s, name)) {
95490 - s->refcount--;
95491 + atomic_dec(&s->refcount);
95492 s = NULL;
95493 }
95494 }
95495 @@ -3879,7 +3944,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
95496 }
95497 #endif
95498
95499 -#ifdef CONFIG_SYSFS
95500 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95501 static int count_inuse(struct page *page)
95502 {
95503 return page->inuse;
95504 @@ -4268,12 +4333,12 @@ static void resiliency_test(void)
95505 validate_slab_cache(kmalloc_caches[9]);
95506 }
95507 #else
95508 -#ifdef CONFIG_SYSFS
95509 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95510 static void resiliency_test(void) {};
95511 #endif
95512 #endif
95513
95514 -#ifdef CONFIG_SYSFS
95515 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95516 enum slab_stat_type {
95517 SL_ALL, /* All slabs */
95518 SL_PARTIAL, /* Only partially allocated slabs */
95519 @@ -4519,7 +4584,7 @@ SLAB_ATTR_RO(ctor);
95520
95521 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
95522 {
95523 - return sprintf(buf, "%d\n", s->refcount - 1);
95524 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
95525 }
95526 SLAB_ATTR_RO(aliases);
95527
95528 @@ -4607,6 +4672,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
95529 SLAB_ATTR_RO(cache_dma);
95530 #endif
95531
95532 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95533 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
95534 +{
95535 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
95536 +}
95537 +SLAB_ATTR_RO(usercopy);
95538 +#endif
95539 +
95540 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
95541 {
95542 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
95543 @@ -4941,6 +5014,9 @@ static struct attribute *slab_attrs[] = {
95544 #ifdef CONFIG_ZONE_DMA
95545 &cache_dma_attr.attr,
95546 #endif
95547 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95548 + &usercopy_attr.attr,
95549 +#endif
95550 #ifdef CONFIG_NUMA
95551 &remote_node_defrag_ratio_attr.attr,
95552 #endif
95553 @@ -5173,6 +5249,7 @@ static char *create_unique_id(struct kmem_cache *s)
95554 return name;
95555 }
95556
95557 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95558 static int sysfs_slab_add(struct kmem_cache *s)
95559 {
95560 int err;
95561 @@ -5230,6 +5307,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
95562 kobject_del(&s->kobj);
95563 kobject_put(&s->kobj);
95564 }
95565 +#endif
95566
95567 /*
95568 * Need to buffer aliases during bootup until sysfs becomes
95569 @@ -5243,6 +5321,7 @@ struct saved_alias {
95570
95571 static struct saved_alias *alias_list;
95572
95573 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95574 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95575 {
95576 struct saved_alias *al;
95577 @@ -5265,6 +5344,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95578 alias_list = al;
95579 return 0;
95580 }
95581 +#endif
95582
95583 static int __init slab_sysfs_init(void)
95584 {
95585 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
95586 index 4cba9c2..b4f9fcc 100644
95587 --- a/mm/sparse-vmemmap.c
95588 +++ b/mm/sparse-vmemmap.c
95589 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
95590 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95591 if (!p)
95592 return NULL;
95593 - pud_populate(&init_mm, pud, p);
95594 + pud_populate_kernel(&init_mm, pud, p);
95595 }
95596 return pud;
95597 }
95598 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
95599 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95600 if (!p)
95601 return NULL;
95602 - pgd_populate(&init_mm, pgd, p);
95603 + pgd_populate_kernel(&init_mm, pgd, p);
95604 }
95605 return pgd;
95606 }
95607 diff --git a/mm/sparse.c b/mm/sparse.c
95608 index 63c3ea5..95c0858 100644
95609 --- a/mm/sparse.c
95610 +++ b/mm/sparse.c
95611 @@ -748,7 +748,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
95612
95613 for (i = 0; i < PAGES_PER_SECTION; i++) {
95614 if (PageHWPoison(&memmap[i])) {
95615 - atomic_long_sub(1, &num_poisoned_pages);
95616 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
95617 ClearPageHWPoison(&memmap[i]);
95618 }
95619 }
95620 diff --git a/mm/swap.c b/mm/swap.c
95621 index 0092097..33361ff 100644
95622 --- a/mm/swap.c
95623 +++ b/mm/swap.c
95624 @@ -31,6 +31,7 @@
95625 #include <linux/memcontrol.h>
95626 #include <linux/gfp.h>
95627 #include <linux/uio.h>
95628 +#include <linux/hugetlb.h>
95629
95630 #include "internal.h"
95631
95632 @@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
95633
95634 __page_cache_release(page);
95635 dtor = get_compound_page_dtor(page);
95636 + if (!PageHuge(page))
95637 + BUG_ON(dtor != free_compound_page);
95638 (*dtor)(page);
95639 }
95640
95641 diff --git a/mm/swapfile.c b/mm/swapfile.c
95642 index 4a7f7e6..22cddf5 100644
95643 --- a/mm/swapfile.c
95644 +++ b/mm/swapfile.c
95645 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
95646
95647 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
95648 /* Activity counter to indicate that a swapon or swapoff has occurred */
95649 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
95650 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
95651
95652 static inline unsigned char swap_count(unsigned char ent)
95653 {
95654 @@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
95655 spin_unlock(&swap_lock);
95656
95657 err = 0;
95658 - atomic_inc(&proc_poll_event);
95659 + atomic_inc_unchecked(&proc_poll_event);
95660 wake_up_interruptible(&proc_poll_wait);
95661
95662 out_dput:
95663 @@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
95664
95665 poll_wait(file, &proc_poll_wait, wait);
95666
95667 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
95668 - seq->poll_event = atomic_read(&proc_poll_event);
95669 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
95670 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95671 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
95672 }
95673
95674 @@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
95675 return ret;
95676
95677 seq = file->private_data;
95678 - seq->poll_event = atomic_read(&proc_poll_event);
95679 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95680 return 0;
95681 }
95682
95683 @@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
95684 (frontswap_map) ? "FS" : "");
95685
95686 mutex_unlock(&swapon_mutex);
95687 - atomic_inc(&proc_poll_event);
95688 + atomic_inc_unchecked(&proc_poll_event);
95689 wake_up_interruptible(&proc_poll_wait);
95690
95691 if (S_ISREG(inode->i_mode))
95692 diff --git a/mm/util.c b/mm/util.c
95693 index a24aa22..a0d41ae 100644
95694 --- a/mm/util.c
95695 +++ b/mm/util.c
95696 @@ -297,6 +297,12 @@ done:
95697 void arch_pick_mmap_layout(struct mm_struct *mm)
95698 {
95699 mm->mmap_base = TASK_UNMAPPED_BASE;
95700 +
95701 +#ifdef CONFIG_PAX_RANDMMAP
95702 + if (mm->pax_flags & MF_PAX_RANDMMAP)
95703 + mm->mmap_base += mm->delta_mmap;
95704 +#endif
95705 +
95706 mm->get_unmapped_area = arch_get_unmapped_area;
95707 }
95708 #endif
95709 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
95710 index 0fdf968..d6686e8 100644
95711 --- a/mm/vmalloc.c
95712 +++ b/mm/vmalloc.c
95713 @@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
95714
95715 pte = pte_offset_kernel(pmd, addr);
95716 do {
95717 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95718 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95719 +
95720 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95721 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
95722 + BUG_ON(!pte_exec(*pte));
95723 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
95724 + continue;
95725 + }
95726 +#endif
95727 +
95728 + {
95729 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95730 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95731 + }
95732 } while (pte++, addr += PAGE_SIZE, addr != end);
95733 }
95734
95735 @@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
95736 pte = pte_alloc_kernel(pmd, addr);
95737 if (!pte)
95738 return -ENOMEM;
95739 +
95740 + pax_open_kernel();
95741 do {
95742 struct page *page = pages[*nr];
95743
95744 - if (WARN_ON(!pte_none(*pte)))
95745 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95746 + if (pgprot_val(prot) & _PAGE_NX)
95747 +#endif
95748 +
95749 + if (!pte_none(*pte)) {
95750 + pax_close_kernel();
95751 + WARN_ON(1);
95752 return -EBUSY;
95753 - if (WARN_ON(!page))
95754 + }
95755 + if (!page) {
95756 + pax_close_kernel();
95757 + WARN_ON(1);
95758 return -ENOMEM;
95759 + }
95760 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
95761 (*nr)++;
95762 } while (pte++, addr += PAGE_SIZE, addr != end);
95763 + pax_close_kernel();
95764 return 0;
95765 }
95766
95767 @@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
95768 pmd_t *pmd;
95769 unsigned long next;
95770
95771 - pmd = pmd_alloc(&init_mm, pud, addr);
95772 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
95773 if (!pmd)
95774 return -ENOMEM;
95775 do {
95776 @@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
95777 pud_t *pud;
95778 unsigned long next;
95779
95780 - pud = pud_alloc(&init_mm, pgd, addr);
95781 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
95782 if (!pud)
95783 return -ENOMEM;
95784 do {
95785 @@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
95786 if (addr >= MODULES_VADDR && addr < MODULES_END)
95787 return 1;
95788 #endif
95789 +
95790 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95791 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
95792 + return 1;
95793 +#endif
95794 +
95795 return is_vmalloc_addr(x);
95796 }
95797
95798 @@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
95799
95800 if (!pgd_none(*pgd)) {
95801 pud_t *pud = pud_offset(pgd, addr);
95802 +#ifdef CONFIG_X86
95803 + if (!pud_large(*pud))
95804 +#endif
95805 if (!pud_none(*pud)) {
95806 pmd_t *pmd = pmd_offset(pud, addr);
95807 +#ifdef CONFIG_X86
95808 + if (!pmd_large(*pmd))
95809 +#endif
95810 if (!pmd_none(*pmd)) {
95811 pte_t *ptep, pte;
95812
95813 @@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
95814 struct vm_struct *area;
95815
95816 BUG_ON(in_interrupt());
95817 +
95818 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95819 + if (flags & VM_KERNEXEC) {
95820 + if (start != VMALLOC_START || end != VMALLOC_END)
95821 + return NULL;
95822 + start = (unsigned long)MODULES_EXEC_VADDR;
95823 + end = (unsigned long)MODULES_EXEC_END;
95824 + }
95825 +#endif
95826 +
95827 if (flags & VM_IOREMAP)
95828 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
95829
95830 @@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
95831 if (count > totalram_pages)
95832 return NULL;
95833
95834 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95835 + if (!(pgprot_val(prot) & _PAGE_NX))
95836 + flags |= VM_KERNEXEC;
95837 +#endif
95838 +
95839 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
95840 __builtin_return_address(0));
95841 if (!area)
95842 @@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
95843 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
95844 goto fail;
95845
95846 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95847 + if (!(pgprot_val(prot) & _PAGE_NX))
95848 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
95849 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
95850 + else
95851 +#endif
95852 +
95853 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
95854 start, end, node, gfp_mask, caller);
95855 if (!area)
95856 @@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
95857 * For tight control over page level allocator and protection flags
95858 * use __vmalloc() instead.
95859 */
95860 -
95861 void *vmalloc_exec(unsigned long size)
95862 {
95863 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
95864 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
95865 NUMA_NO_NODE, __builtin_return_address(0));
95866 }
95867
95868 @@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
95869 {
95870 struct vm_struct *area;
95871
95872 + BUG_ON(vma->vm_mirror);
95873 +
95874 size = PAGE_ALIGN(size);
95875
95876 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
95877 @@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
95878 v->addr, v->addr + v->size, v->size);
95879
95880 if (v->caller)
95881 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95882 + seq_printf(m, " %pK", v->caller);
95883 +#else
95884 seq_printf(m, " %pS", v->caller);
95885 +#endif
95886
95887 if (v->nr_pages)
95888 seq_printf(m, " pages=%d", v->nr_pages);
95889 diff --git a/mm/vmstat.c b/mm/vmstat.c
95890 index def5dd2..4ce55cec 100644
95891 --- a/mm/vmstat.c
95892 +++ b/mm/vmstat.c
95893 @@ -20,6 +20,7 @@
95894 #include <linux/writeback.h>
95895 #include <linux/compaction.h>
95896 #include <linux/mm_inline.h>
95897 +#include <linux/grsecurity.h>
95898
95899 #include "internal.h"
95900
95901 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
95902 *
95903 * vm_stat contains the global counters
95904 */
95905 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
95906 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
95907 EXPORT_SYMBOL(vm_stat);
95908
95909 #ifdef CONFIG_SMP
95910 @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
95911
95912 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
95913 if (diff[i])
95914 - atomic_long_add(diff[i], &vm_stat[i]);
95915 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
95916 }
95917
95918 /*
95919 @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
95920 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
95921 if (v) {
95922
95923 - atomic_long_add(v, &zone->vm_stat[i]);
95924 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95925 global_diff[i] += v;
95926 #ifdef CONFIG_NUMA
95927 /* 3 seconds idle till flush */
95928 @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
95929
95930 v = p->vm_stat_diff[i];
95931 p->vm_stat_diff[i] = 0;
95932 - atomic_long_add(v, &zone->vm_stat[i]);
95933 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95934 global_diff[i] += v;
95935 }
95936 }
95937 @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
95938 if (pset->vm_stat_diff[i]) {
95939 int v = pset->vm_stat_diff[i];
95940 pset->vm_stat_diff[i] = 0;
95941 - atomic_long_add(v, &zone->vm_stat[i]);
95942 - atomic_long_add(v, &vm_stat[i]);
95943 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95944 + atomic_long_add_unchecked(v, &vm_stat[i]);
95945 }
95946 }
95947 #endif
95948 @@ -1150,10 +1151,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
95949 stat_items_size += sizeof(struct vm_event_state);
95950 #endif
95951
95952 - v = kmalloc(stat_items_size, GFP_KERNEL);
95953 + v = kzalloc(stat_items_size, GFP_KERNEL);
95954 m->private = v;
95955 if (!v)
95956 return ERR_PTR(-ENOMEM);
95957 +
95958 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
95959 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
95960 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
95961 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
95962 + && !in_group_p(grsec_proc_gid)
95963 +#endif
95964 + )
95965 + return (unsigned long *)m->private + *pos;
95966 +#endif
95967 +#endif
95968 +
95969 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
95970 v[i] = global_page_state(i);
95971 v += NR_VM_ZONE_STAT_ITEMS;
95972 @@ -1302,10 +1315,16 @@ static int __init setup_vmstat(void)
95973 put_online_cpus();
95974 #endif
95975 #ifdef CONFIG_PROC_FS
95976 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
95977 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
95978 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
95979 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
95980 + {
95981 + mode_t gr_mode = S_IRUGO;
95982 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
95983 + gr_mode = S_IRUSR;
95984 +#endif
95985 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
95986 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
95987 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
95988 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
95989 + }
95990 #endif
95991 return 0;
95992 }
95993 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
95994 index 175273f..1c63e05 100644
95995 --- a/net/8021q/vlan.c
95996 +++ b/net/8021q/vlan.c
95997 @@ -474,7 +474,7 @@ out:
95998 return NOTIFY_DONE;
95999 }
96000
96001 -static struct notifier_block vlan_notifier_block __read_mostly = {
96002 +static struct notifier_block vlan_notifier_block = {
96003 .notifier_call = vlan_device_event,
96004 };
96005
96006 @@ -549,8 +549,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
96007 err = -EPERM;
96008 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
96009 break;
96010 - if ((args.u.name_type >= 0) &&
96011 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
96012 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
96013 struct vlan_net *vn;
96014
96015 vn = net_generic(net, vlan_net_id);
96016 diff --git a/net/9p/client.c b/net/9p/client.c
96017 index 9186550..e604a2f 100644
96018 --- a/net/9p/client.c
96019 +++ b/net/9p/client.c
96020 @@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
96021 len - inline_len);
96022 } else {
96023 err = copy_from_user(ename + inline_len,
96024 - uidata, len - inline_len);
96025 + (char __force_user *)uidata, len - inline_len);
96026 if (err) {
96027 err = -EFAULT;
96028 goto out_err;
96029 @@ -1560,7 +1560,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
96030 kernel_buf = 1;
96031 indata = data;
96032 } else
96033 - indata = (__force char *)udata;
96034 + indata = (__force_kernel char *)udata;
96035 /*
96036 * response header len is 11
96037 * PDU Header(7) + IO Size (4)
96038 @@ -1635,7 +1635,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
96039 kernel_buf = 1;
96040 odata = data;
96041 } else
96042 - odata = (char *)udata;
96043 + odata = (char __force_kernel *)udata;
96044 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
96045 P9_ZC_HDR_SZ, kernel_buf, "dqd",
96046 fid->fid, offset, rsize);
96047 diff --git a/net/9p/mod.c b/net/9p/mod.c
96048 index 6ab36ae..6f1841b 100644
96049 --- a/net/9p/mod.c
96050 +++ b/net/9p/mod.c
96051 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
96052 void v9fs_register_trans(struct p9_trans_module *m)
96053 {
96054 spin_lock(&v9fs_trans_lock);
96055 - list_add_tail(&m->list, &v9fs_trans_list);
96056 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
96057 spin_unlock(&v9fs_trans_lock);
96058 }
96059 EXPORT_SYMBOL(v9fs_register_trans);
96060 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
96061 void v9fs_unregister_trans(struct p9_trans_module *m)
96062 {
96063 spin_lock(&v9fs_trans_lock);
96064 - list_del_init(&m->list);
96065 + pax_list_del_init((struct list_head *)&m->list);
96066 spin_unlock(&v9fs_trans_lock);
96067 }
96068 EXPORT_SYMBOL(v9fs_unregister_trans);
96069 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
96070 index b7bd7f2..2498bf7 100644
96071 --- a/net/9p/trans_fd.c
96072 +++ b/net/9p/trans_fd.c
96073 @@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
96074 oldfs = get_fs();
96075 set_fs(get_ds());
96076 /* The cast to a user pointer is valid due to the set_fs() */
96077 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
96078 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
96079 set_fs(oldfs);
96080
96081 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
96082 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
96083 index 876fbe8..8bbea9f 100644
96084 --- a/net/atm/atm_misc.c
96085 +++ b/net/atm/atm_misc.c
96086 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
96087 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
96088 return 1;
96089 atm_return(vcc, truesize);
96090 - atomic_inc(&vcc->stats->rx_drop);
96091 + atomic_inc_unchecked(&vcc->stats->rx_drop);
96092 return 0;
96093 }
96094 EXPORT_SYMBOL(atm_charge);
96095 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
96096 }
96097 }
96098 atm_return(vcc, guess);
96099 - atomic_inc(&vcc->stats->rx_drop);
96100 + atomic_inc_unchecked(&vcc->stats->rx_drop);
96101 return NULL;
96102 }
96103 EXPORT_SYMBOL(atm_alloc_charge);
96104 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
96105
96106 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96107 {
96108 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96109 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96110 __SONET_ITEMS
96111 #undef __HANDLE_ITEM
96112 }
96113 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
96114
96115 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96116 {
96117 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96118 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
96119 __SONET_ITEMS
96120 #undef __HANDLE_ITEM
96121 }
96122 diff --git a/net/atm/lec.c b/net/atm/lec.c
96123 index 5a2f602..9396143 100644
96124 --- a/net/atm/lec.c
96125 +++ b/net/atm/lec.c
96126 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
96127 }
96128
96129 static struct lane2_ops lane2_ops = {
96130 - lane2_resolve, /* resolve, spec 3.1.3 */
96131 - lane2_associate_req, /* associate_req, spec 3.1.4 */
96132 - NULL /* associate indicator, spec 3.1.5 */
96133 + .resolve = lane2_resolve,
96134 + .associate_req = lane2_associate_req,
96135 + .associate_indicator = NULL
96136 };
96137
96138 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
96139 diff --git a/net/atm/lec.h b/net/atm/lec.h
96140 index 4149db1..f2ab682 100644
96141 --- a/net/atm/lec.h
96142 +++ b/net/atm/lec.h
96143 @@ -48,7 +48,7 @@ struct lane2_ops {
96144 const u8 *tlvs, u32 sizeoftlvs);
96145 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
96146 const u8 *tlvs, u32 sizeoftlvs);
96147 -};
96148 +} __no_const;
96149
96150 /*
96151 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
96152 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
96153 index d1b2d9a..d549f7f 100644
96154 --- a/net/atm/mpoa_caches.c
96155 +++ b/net/atm/mpoa_caches.c
96156 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
96157
96158
96159 static struct in_cache_ops ingress_ops = {
96160 - in_cache_add_entry, /* add_entry */
96161 - in_cache_get, /* get */
96162 - in_cache_get_with_mask, /* get_with_mask */
96163 - in_cache_get_by_vcc, /* get_by_vcc */
96164 - in_cache_put, /* put */
96165 - in_cache_remove_entry, /* remove_entry */
96166 - cache_hit, /* cache_hit */
96167 - clear_count_and_expired, /* clear_count */
96168 - check_resolving_entries, /* check_resolving */
96169 - refresh_entries, /* refresh */
96170 - in_destroy_cache /* destroy_cache */
96171 + .add_entry = in_cache_add_entry,
96172 + .get = in_cache_get,
96173 + .get_with_mask = in_cache_get_with_mask,
96174 + .get_by_vcc = in_cache_get_by_vcc,
96175 + .put = in_cache_put,
96176 + .remove_entry = in_cache_remove_entry,
96177 + .cache_hit = cache_hit,
96178 + .clear_count = clear_count_and_expired,
96179 + .check_resolving = check_resolving_entries,
96180 + .refresh = refresh_entries,
96181 + .destroy_cache = in_destroy_cache
96182 };
96183
96184 static struct eg_cache_ops egress_ops = {
96185 - eg_cache_add_entry, /* add_entry */
96186 - eg_cache_get_by_cache_id, /* get_by_cache_id */
96187 - eg_cache_get_by_tag, /* get_by_tag */
96188 - eg_cache_get_by_vcc, /* get_by_vcc */
96189 - eg_cache_get_by_src_ip, /* get_by_src_ip */
96190 - eg_cache_put, /* put */
96191 - eg_cache_remove_entry, /* remove_entry */
96192 - update_eg_cache_entry, /* update */
96193 - clear_expired, /* clear_expired */
96194 - eg_destroy_cache /* destroy_cache */
96195 + .add_entry = eg_cache_add_entry,
96196 + .get_by_cache_id = eg_cache_get_by_cache_id,
96197 + .get_by_tag = eg_cache_get_by_tag,
96198 + .get_by_vcc = eg_cache_get_by_vcc,
96199 + .get_by_src_ip = eg_cache_get_by_src_ip,
96200 + .put = eg_cache_put,
96201 + .remove_entry = eg_cache_remove_entry,
96202 + .update = update_eg_cache_entry,
96203 + .clear_expired = clear_expired,
96204 + .destroy_cache = eg_destroy_cache
96205 };
96206
96207
96208 diff --git a/net/atm/proc.c b/net/atm/proc.c
96209 index bbb6461..cf04016 100644
96210 --- a/net/atm/proc.c
96211 +++ b/net/atm/proc.c
96212 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
96213 const struct k_atm_aal_stats *stats)
96214 {
96215 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
96216 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
96217 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
96218 - atomic_read(&stats->rx_drop));
96219 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
96220 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
96221 + atomic_read_unchecked(&stats->rx_drop));
96222 }
96223
96224 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
96225 diff --git a/net/atm/resources.c b/net/atm/resources.c
96226 index 0447d5d..3cf4728 100644
96227 --- a/net/atm/resources.c
96228 +++ b/net/atm/resources.c
96229 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
96230 static void copy_aal_stats(struct k_atm_aal_stats *from,
96231 struct atm_aal_stats *to)
96232 {
96233 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96234 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96235 __AAL_STAT_ITEMS
96236 #undef __HANDLE_ITEM
96237 }
96238 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
96239 static void subtract_aal_stats(struct k_atm_aal_stats *from,
96240 struct atm_aal_stats *to)
96241 {
96242 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96243 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
96244 __AAL_STAT_ITEMS
96245 #undef __HANDLE_ITEM
96246 }
96247 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
96248 index 919a5ce..cc6b444 100644
96249 --- a/net/ax25/sysctl_net_ax25.c
96250 +++ b/net/ax25/sysctl_net_ax25.c
96251 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
96252 {
96253 char path[sizeof("net/ax25/") + IFNAMSIZ];
96254 int k;
96255 - struct ctl_table *table;
96256 + ctl_table_no_const *table;
96257
96258 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
96259 if (!table)
96260 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
96261 index 8323bce..a03130d 100644
96262 --- a/net/batman-adv/bat_iv_ogm.c
96263 +++ b/net/batman-adv/bat_iv_ogm.c
96264 @@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
96265
96266 /* randomize initial seqno to avoid collision */
96267 get_random_bytes(&random_seqno, sizeof(random_seqno));
96268 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96269 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96270
96271 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
96272 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
96273 @@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
96274 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
96275
96276 /* change sequence number to network order */
96277 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
96278 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
96279 batadv_ogm_packet->seqno = htonl(seqno);
96280 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
96281 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
96282
96283 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
96284
96285 @@ -1594,7 +1594,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
96286 return;
96287
96288 /* could be changed by schedule_own_packet() */
96289 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
96290 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
96291
96292 if (ogm_packet->flags & BATADV_DIRECTLINK)
96293 has_directlink_flag = true;
96294 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
96295 index 88df9b1..69cf7c0 100644
96296 --- a/net/batman-adv/fragmentation.c
96297 +++ b/net/batman-adv/fragmentation.c
96298 @@ -445,7 +445,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
96299 frag_header.packet_type = BATADV_UNICAST_FRAG;
96300 frag_header.version = BATADV_COMPAT_VERSION;
96301 frag_header.ttl = BATADV_TTL;
96302 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
96303 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
96304 frag_header.reserved = 0;
96305 frag_header.no = 0;
96306 frag_header.total_size = htons(skb->len);
96307 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
96308 index f82c267..0e56d32 100644
96309 --- a/net/batman-adv/soft-interface.c
96310 +++ b/net/batman-adv/soft-interface.c
96311 @@ -283,7 +283,7 @@ send:
96312 primary_if->net_dev->dev_addr, ETH_ALEN);
96313
96314 /* set broadcast sequence number */
96315 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
96316 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
96317 bcast_packet->seqno = htonl(seqno);
96318
96319 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
96320 @@ -707,7 +707,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96321 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
96322
96323 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
96324 - atomic_set(&bat_priv->bcast_seqno, 1);
96325 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
96326 atomic_set(&bat_priv->tt.vn, 0);
96327 atomic_set(&bat_priv->tt.local_changes, 0);
96328 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
96329 @@ -721,7 +721,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96330
96331 /* randomize initial seqno to avoid collision */
96332 get_random_bytes(&random_seqno, sizeof(random_seqno));
96333 - atomic_set(&bat_priv->frag_seqno, random_seqno);
96334 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
96335
96336 bat_priv->primary_if = NULL;
96337 bat_priv->num_ifaces = 0;
96338 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
96339 index 78370ab..1cb3614 100644
96340 --- a/net/batman-adv/types.h
96341 +++ b/net/batman-adv/types.h
96342 @@ -66,7 +66,7 @@ enum batadv_dhcp_recipient {
96343 struct batadv_hard_iface_bat_iv {
96344 unsigned char *ogm_buff;
96345 int ogm_buff_len;
96346 - atomic_t ogm_seqno;
96347 + atomic_unchecked_t ogm_seqno;
96348 };
96349
96350 /**
96351 @@ -714,7 +714,7 @@ struct batadv_priv {
96352 atomic_t bonding;
96353 atomic_t fragmentation;
96354 atomic_t packet_size_max;
96355 - atomic_t frag_seqno;
96356 + atomic_unchecked_t frag_seqno;
96357 #ifdef CONFIG_BATMAN_ADV_BLA
96358 atomic_t bridge_loop_avoidance;
96359 #endif
96360 @@ -730,7 +730,7 @@ struct batadv_priv {
96361 #endif
96362 uint32_t isolation_mark;
96363 uint32_t isolation_mark_mask;
96364 - atomic_t bcast_seqno;
96365 + atomic_unchecked_t bcast_seqno;
96366 atomic_t bcast_queue_left;
96367 atomic_t batman_queue_left;
96368 char num_ifaces;
96369 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
96370 index 7552f9e..074ce29 100644
96371 --- a/net/bluetooth/hci_sock.c
96372 +++ b/net/bluetooth/hci_sock.c
96373 @@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
96374 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
96375 }
96376
96377 - len = min_t(unsigned int, len, sizeof(uf));
96378 + len = min((size_t)len, sizeof(uf));
96379 if (copy_from_user(&uf, optval, len)) {
96380 err = -EFAULT;
96381 break;
96382 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
96383 index b0ad2c7..96f6a5e 100644
96384 --- a/net/bluetooth/l2cap_core.c
96385 +++ b/net/bluetooth/l2cap_core.c
96386 @@ -3740,8 +3740,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
96387 break;
96388
96389 case L2CAP_CONF_RFC:
96390 - if (olen == sizeof(rfc))
96391 - memcpy(&rfc, (void *)val, olen);
96392 + if (olen != sizeof(rfc))
96393 + break;
96394 +
96395 + memcpy(&rfc, (void *)val, olen);
96396
96397 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
96398 rfc.mode != chan->mode)
96399 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
96400 index d58f76b..b69600a 100644
96401 --- a/net/bluetooth/l2cap_sock.c
96402 +++ b/net/bluetooth/l2cap_sock.c
96403 @@ -625,7 +625,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96404 struct sock *sk = sock->sk;
96405 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
96406 struct l2cap_options opts;
96407 - int len, err = 0;
96408 + int err = 0;
96409 + size_t len = optlen;
96410 u32 opt;
96411
96412 BT_DBG("sk %p", sk);
96413 @@ -652,7 +653,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96414 opts.max_tx = chan->max_tx;
96415 opts.txwin_size = chan->tx_win;
96416
96417 - len = min_t(unsigned int, sizeof(opts), optlen);
96418 + len = min(sizeof(opts), len);
96419 if (copy_from_user((char *) &opts, optval, len)) {
96420 err = -EFAULT;
96421 break;
96422 @@ -734,7 +735,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96423 struct bt_security sec;
96424 struct bt_power pwr;
96425 struct l2cap_conn *conn;
96426 - int len, err = 0;
96427 + int err = 0;
96428 + size_t len = optlen;
96429 u32 opt;
96430
96431 BT_DBG("sk %p", sk);
96432 @@ -757,7 +759,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96433
96434 sec.level = BT_SECURITY_LOW;
96435
96436 - len = min_t(unsigned int, sizeof(sec), optlen);
96437 + len = min(sizeof(sec), len);
96438 if (copy_from_user((char *) &sec, optval, len)) {
96439 err = -EFAULT;
96440 break;
96441 @@ -857,7 +859,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96442
96443 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
96444
96445 - len = min_t(unsigned int, sizeof(pwr), optlen);
96446 + len = min(sizeof(pwr), len);
96447 if (copy_from_user((char *) &pwr, optval, len)) {
96448 err = -EFAULT;
96449 break;
96450 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
96451 index 3c2d3e4..884855a 100644
96452 --- a/net/bluetooth/rfcomm/sock.c
96453 +++ b/net/bluetooth/rfcomm/sock.c
96454 @@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96455 struct sock *sk = sock->sk;
96456 struct bt_security sec;
96457 int err = 0;
96458 - size_t len;
96459 + size_t len = optlen;
96460 u32 opt;
96461
96462 BT_DBG("sk %p", sk);
96463 @@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96464
96465 sec.level = BT_SECURITY_LOW;
96466
96467 - len = min_t(unsigned int, sizeof(sec), optlen);
96468 + len = min(sizeof(sec), len);
96469 if (copy_from_user((char *) &sec, optval, len)) {
96470 err = -EFAULT;
96471 break;
96472 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
96473 index f9c0980a..fcbbfeb 100644
96474 --- a/net/bluetooth/rfcomm/tty.c
96475 +++ b/net/bluetooth/rfcomm/tty.c
96476 @@ -717,7 +717,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
96477 BT_DBG("tty %p id %d", tty, tty->index);
96478
96479 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
96480 - dev->channel, dev->port.count);
96481 + dev->channel, atomic_read(&dev->port.count));
96482
96483 err = tty_port_open(&dev->port, tty, filp);
96484 if (err)
96485 @@ -740,7 +740,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
96486 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
96487
96488 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
96489 - dev->port.count);
96490 + atomic_read(&dev->port.count));
96491
96492 tty_port_close(&dev->port, tty, filp);
96493 }
96494 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
96495 index 0e474b1..fb7109c 100644
96496 --- a/net/bridge/netfilter/ebtables.c
96497 +++ b/net/bridge/netfilter/ebtables.c
96498 @@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96499 tmp.valid_hooks = t->table->valid_hooks;
96500 }
96501 mutex_unlock(&ebt_mutex);
96502 - if (copy_to_user(user, &tmp, *len) != 0) {
96503 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96504 BUGPRINT("c2u Didn't work\n");
96505 ret = -EFAULT;
96506 break;
96507 @@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96508 goto out;
96509 tmp.valid_hooks = t->valid_hooks;
96510
96511 - if (copy_to_user(user, &tmp, *len) != 0) {
96512 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96513 ret = -EFAULT;
96514 break;
96515 }
96516 @@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96517 tmp.entries_size = t->table->entries_size;
96518 tmp.valid_hooks = t->table->valid_hooks;
96519
96520 - if (copy_to_user(user, &tmp, *len) != 0) {
96521 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96522 ret = -EFAULT;
96523 break;
96524 }
96525 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
96526 index 0f45522..dab651f 100644
96527 --- a/net/caif/cfctrl.c
96528 +++ b/net/caif/cfctrl.c
96529 @@ -10,6 +10,7 @@
96530 #include <linux/spinlock.h>
96531 #include <linux/slab.h>
96532 #include <linux/pkt_sched.h>
96533 +#include <linux/sched.h>
96534 #include <net/caif/caif_layer.h>
96535 #include <net/caif/cfpkt.h>
96536 #include <net/caif/cfctrl.h>
96537 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
96538 memset(&dev_info, 0, sizeof(dev_info));
96539 dev_info.id = 0xff;
96540 cfsrvl_init(&this->serv, 0, &dev_info, false);
96541 - atomic_set(&this->req_seq_no, 1);
96542 - atomic_set(&this->rsp_seq_no, 1);
96543 + atomic_set_unchecked(&this->req_seq_no, 1);
96544 + atomic_set_unchecked(&this->rsp_seq_no, 1);
96545 this->serv.layer.receive = cfctrl_recv;
96546 sprintf(this->serv.layer.name, "ctrl");
96547 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
96548 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
96549 struct cfctrl_request_info *req)
96550 {
96551 spin_lock_bh(&ctrl->info_list_lock);
96552 - atomic_inc(&ctrl->req_seq_no);
96553 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
96554 + atomic_inc_unchecked(&ctrl->req_seq_no);
96555 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
96556 list_add_tail(&req->list, &ctrl->list);
96557 spin_unlock_bh(&ctrl->info_list_lock);
96558 }
96559 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
96560 if (p != first)
96561 pr_warn("Requests are not received in order\n");
96562
96563 - atomic_set(&ctrl->rsp_seq_no,
96564 + atomic_set_unchecked(&ctrl->rsp_seq_no,
96565 p->sequence_no);
96566 list_del(&p->list);
96567 goto out;
96568 diff --git a/net/can/af_can.c b/net/can/af_can.c
96569 index a27f8aa..67174a3 100644
96570 --- a/net/can/af_can.c
96571 +++ b/net/can/af_can.c
96572 @@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
96573 };
96574
96575 /* notifier block for netdevice event */
96576 -static struct notifier_block can_netdev_notifier __read_mostly = {
96577 +static struct notifier_block can_netdev_notifier = {
96578 .notifier_call = can_notifier,
96579 };
96580
96581 diff --git a/net/can/gw.c b/net/can/gw.c
96582 index ac31891..4799c17 100644
96583 --- a/net/can/gw.c
96584 +++ b/net/can/gw.c
96585 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
96586 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
96587
96588 static HLIST_HEAD(cgw_list);
96589 -static struct notifier_block notifier;
96590
96591 static struct kmem_cache *cgw_cache __read_mostly;
96592
96593 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
96594 return err;
96595 }
96596
96597 +static struct notifier_block notifier = {
96598 + .notifier_call = cgw_notifier
96599 +};
96600 +
96601 static __init int cgw_module_init(void)
96602 {
96603 /* sanitize given module parameter */
96604 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
96605 return -ENOMEM;
96606
96607 /* set notifier */
96608 - notifier.notifier_call = cgw_notifier;
96609 register_netdevice_notifier(&notifier);
96610
96611 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
96612 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
96613 index 30efc5c..cfa1bbc 100644
96614 --- a/net/ceph/messenger.c
96615 +++ b/net/ceph/messenger.c
96616 @@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
96617 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
96618
96619 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
96620 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
96621 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
96622
96623 static struct page *zero_page; /* used in certain error cases */
96624
96625 @@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
96626 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
96627 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
96628
96629 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96630 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96631 s = addr_str[i];
96632
96633 switch (ss->ss_family) {
96634 diff --git a/net/compat.c b/net/compat.c
96635 index f50161f..94fa415 100644
96636 --- a/net/compat.c
96637 +++ b/net/compat.c
96638 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
96639 return -EFAULT;
96640 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
96641 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
96642 - kmsg->msg_name = compat_ptr(tmp1);
96643 - kmsg->msg_iov = compat_ptr(tmp2);
96644 - kmsg->msg_control = compat_ptr(tmp3);
96645 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
96646 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
96647 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
96648 return 0;
96649 }
96650
96651 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96652
96653 if (kern_msg->msg_namelen) {
96654 if (mode == VERIFY_READ) {
96655 - int err = move_addr_to_kernel(kern_msg->msg_name,
96656 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
96657 kern_msg->msg_namelen,
96658 kern_address);
96659 if (err < 0)
96660 @@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96661 kern_msg->msg_name = NULL;
96662
96663 tot_len = iov_from_user_compat_to_kern(kern_iov,
96664 - (struct compat_iovec __user *)kern_msg->msg_iov,
96665 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
96666 kern_msg->msg_iovlen);
96667 if (tot_len >= 0)
96668 kern_msg->msg_iov = kern_iov;
96669 @@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96670
96671 #define CMSG_COMPAT_FIRSTHDR(msg) \
96672 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
96673 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
96674 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
96675 (struct compat_cmsghdr __user *)NULL)
96676
96677 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
96678 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
96679 (ucmlen) <= (unsigned long) \
96680 ((mhdr)->msg_controllen - \
96681 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
96682 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
96683
96684 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
96685 struct compat_cmsghdr __user *cmsg, int cmsg_len)
96686 {
96687 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
96688 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
96689 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
96690 msg->msg_controllen)
96691 return NULL;
96692 return (struct compat_cmsghdr __user *)ptr;
96693 @@ -222,7 +222,7 @@ Efault:
96694
96695 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
96696 {
96697 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96698 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96699 struct compat_cmsghdr cmhdr;
96700 struct compat_timeval ctv;
96701 struct compat_timespec cts[3];
96702 @@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
96703
96704 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
96705 {
96706 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96707 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96708 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
96709 int fdnum = scm->fp->count;
96710 struct file **fp = scm->fp->fp;
96711 @@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
96712 return -EFAULT;
96713 old_fs = get_fs();
96714 set_fs(KERNEL_DS);
96715 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
96716 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
96717 set_fs(old_fs);
96718
96719 return err;
96720 @@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
96721 len = sizeof(ktime);
96722 old_fs = get_fs();
96723 set_fs(KERNEL_DS);
96724 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
96725 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
96726 set_fs(old_fs);
96727
96728 if (!err) {
96729 @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96730 case MCAST_JOIN_GROUP:
96731 case MCAST_LEAVE_GROUP:
96732 {
96733 - struct compat_group_req __user *gr32 = (void *)optval;
96734 + struct compat_group_req __user *gr32 = (void __user *)optval;
96735 struct group_req __user *kgr =
96736 compat_alloc_user_space(sizeof(struct group_req));
96737 u32 interface;
96738 @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96739 case MCAST_BLOCK_SOURCE:
96740 case MCAST_UNBLOCK_SOURCE:
96741 {
96742 - struct compat_group_source_req __user *gsr32 = (void *)optval;
96743 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
96744 struct group_source_req __user *kgsr = compat_alloc_user_space(
96745 sizeof(struct group_source_req));
96746 u32 interface;
96747 @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96748 }
96749 case MCAST_MSFILTER:
96750 {
96751 - struct compat_group_filter __user *gf32 = (void *)optval;
96752 + struct compat_group_filter __user *gf32 = (void __user *)optval;
96753 struct group_filter __user *kgf;
96754 u32 interface, fmode, numsrc;
96755
96756 @@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
96757 char __user *optval, int __user *optlen,
96758 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
96759 {
96760 - struct compat_group_filter __user *gf32 = (void *)optval;
96761 + struct compat_group_filter __user *gf32 = (void __user *)optval;
96762 struct group_filter __user *kgf;
96763 int __user *koptlen;
96764 u32 interface, fmode, numsrc;
96765 @@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
96766
96767 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
96768 return -EINVAL;
96769 - if (copy_from_user(a, args, nas[call]))
96770 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
96771 return -EFAULT;
96772 a0 = a[0];
96773 a1 = a[1];
96774 diff --git a/net/core/datagram.c b/net/core/datagram.c
96775 index a16ed7b..eb44d17 100644
96776 --- a/net/core/datagram.c
96777 +++ b/net/core/datagram.c
96778 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
96779 }
96780
96781 kfree_skb(skb);
96782 - atomic_inc(&sk->sk_drops);
96783 + atomic_inc_unchecked(&sk->sk_drops);
96784 sk_mem_reclaim_partial(sk);
96785
96786 return err;
96787 diff --git a/net/core/dev.c b/net/core/dev.c
96788 index 45fa2f1..f3e28ec 100644
96789 --- a/net/core/dev.c
96790 +++ b/net/core/dev.c
96791 @@ -1688,14 +1688,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
96792 {
96793 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
96794 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
96795 - atomic_long_inc(&dev->rx_dropped);
96796 + atomic_long_inc_unchecked(&dev->rx_dropped);
96797 kfree_skb(skb);
96798 return NET_RX_DROP;
96799 }
96800 }
96801
96802 if (unlikely(!is_skb_forwardable(dev, skb))) {
96803 - atomic_long_inc(&dev->rx_dropped);
96804 + atomic_long_inc_unchecked(&dev->rx_dropped);
96805 kfree_skb(skb);
96806 return NET_RX_DROP;
96807 }
96808 @@ -2453,7 +2453,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
96809
96810 struct dev_gso_cb {
96811 void (*destructor)(struct sk_buff *skb);
96812 -};
96813 +} __no_const;
96814
96815 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
96816
96817 @@ -3227,7 +3227,7 @@ enqueue:
96818
96819 local_irq_restore(flags);
96820
96821 - atomic_long_inc(&skb->dev->rx_dropped);
96822 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
96823 kfree_skb(skb);
96824 return NET_RX_DROP;
96825 }
96826 @@ -3308,7 +3308,7 @@ int netif_rx_ni(struct sk_buff *skb)
96827 }
96828 EXPORT_SYMBOL(netif_rx_ni);
96829
96830 -static void net_tx_action(struct softirq_action *h)
96831 +static __latent_entropy void net_tx_action(void)
96832 {
96833 struct softnet_data *sd = &__get_cpu_var(softnet_data);
96834
96835 @@ -3645,7 +3645,7 @@ ncls:
96836 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
96837 } else {
96838 drop:
96839 - atomic_long_inc(&skb->dev->rx_dropped);
96840 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
96841 kfree_skb(skb);
96842 /* Jamal, now you will not able to escape explaining
96843 * me how you were going to use this. :-)
96844 @@ -4331,7 +4331,7 @@ void netif_napi_del(struct napi_struct *napi)
96845 }
96846 EXPORT_SYMBOL(netif_napi_del);
96847
96848 -static void net_rx_action(struct softirq_action *h)
96849 +static __latent_entropy void net_rx_action(void)
96850 {
96851 struct softnet_data *sd = &__get_cpu_var(softnet_data);
96852 unsigned long time_limit = jiffies + 2;
96853 @@ -6250,7 +6250,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
96854 } else {
96855 netdev_stats_to_stats64(storage, &dev->stats);
96856 }
96857 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
96858 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
96859 return storage;
96860 }
96861 EXPORT_SYMBOL(dev_get_stats);
96862 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
96863 index cf999e0..c59a975 100644
96864 --- a/net/core/dev_ioctl.c
96865 +++ b/net/core/dev_ioctl.c
96866 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
96867 if (no_module && capable(CAP_NET_ADMIN))
96868 no_module = request_module("netdev-%s", name);
96869 if (no_module && capable(CAP_SYS_MODULE)) {
96870 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
96871 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
96872 +#else
96873 if (!request_module("%s", name))
96874 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
96875 name);
96876 +#endif
96877 }
96878 }
96879 EXPORT_SYMBOL(dev_load);
96880 diff --git a/net/core/filter.c b/net/core/filter.c
96881 index ad30d62..21c0743 100644
96882 --- a/net/core/filter.c
96883 +++ b/net/core/filter.c
96884 @@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
96885 void *ptr;
96886 u32 A = 0; /* Accumulator */
96887 u32 X = 0; /* Index Register */
96888 - u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
96889 + u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
96890 u32 tmp;
96891 int k;
96892
96893 @@ -292,10 +292,10 @@ load_b:
96894 X = K;
96895 continue;
96896 case BPF_S_LD_MEM:
96897 - A = mem[K];
96898 + A = mem[K&15];
96899 continue;
96900 case BPF_S_LDX_MEM:
96901 - X = mem[K];
96902 + X = mem[K&15];
96903 continue;
96904 case BPF_S_MISC_TAX:
96905 X = A;
96906 @@ -308,10 +308,10 @@ load_b:
96907 case BPF_S_RET_A:
96908 return A;
96909 case BPF_S_ST:
96910 - mem[K] = A;
96911 + mem[K&15] = A;
96912 continue;
96913 case BPF_S_STX:
96914 - mem[K] = X;
96915 + mem[K&15] = X;
96916 continue;
96917 case BPF_S_ANC_PROTOCOL:
96918 A = ntohs(skb->protocol);
96919 @@ -355,6 +355,10 @@ load_b:
96920
96921 if (skb_is_nonlinear(skb))
96922 return 0;
96923 +
96924 + if (skb->len < sizeof(struct nlattr))
96925 + return 0;
96926 +
96927 if (A > skb->len - sizeof(struct nlattr))
96928 return 0;
96929
96930 @@ -371,11 +375,15 @@ load_b:
96931
96932 if (skb_is_nonlinear(skb))
96933 return 0;
96934 +
96935 + if (skb->len < sizeof(struct nlattr))
96936 + return 0;
96937 +
96938 if (A > skb->len - sizeof(struct nlattr))
96939 return 0;
96940
96941 nla = (struct nlattr *)&skb->data[A];
96942 - if (nla->nla_len > A - skb->len)
96943 + if (nla->nla_len > skb->len - A)
96944 return 0;
96945
96946 nla = nla_find_nested(nla, X);
96947 @@ -391,9 +399,10 @@ load_b:
96948 continue;
96949 #endif
96950 default:
96951 - WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
96952 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
96953 fentry->code, fentry->jt,
96954 fentry->jf, fentry->k);
96955 + BUG();
96956 return 0;
96957 }
96958 }
96959 @@ -416,7 +425,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
96960 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
96961 int pc, ret = 0;
96962
96963 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
96964 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
96965 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
96966 if (!masks)
96967 return -ENOMEM;
96968 @@ -679,7 +688,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
96969 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
96970 if (!fp)
96971 return -ENOMEM;
96972 - memcpy(fp->insns, fprog->filter, fsize);
96973 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
96974
96975 atomic_set(&fp->refcnt, 1);
96976 fp->len = fprog->len;
96977 diff --git a/net/core/flow.c b/net/core/flow.c
96978 index dfa602c..3103d88 100644
96979 --- a/net/core/flow.c
96980 +++ b/net/core/flow.c
96981 @@ -61,7 +61,7 @@ struct flow_cache {
96982 struct timer_list rnd_timer;
96983 };
96984
96985 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
96986 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
96987 EXPORT_SYMBOL(flow_cache_genid);
96988 static struct flow_cache flow_cache_global;
96989 static struct kmem_cache *flow_cachep __read_mostly;
96990 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
96991
96992 static int flow_entry_valid(struct flow_cache_entry *fle)
96993 {
96994 - if (atomic_read(&flow_cache_genid) != fle->genid)
96995 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
96996 return 0;
96997 if (fle->object && !fle->object->ops->check(fle->object))
96998 return 0;
96999 @@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
97000 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
97001 fcp->hash_count++;
97002 }
97003 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
97004 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
97005 flo = fle->object;
97006 if (!flo)
97007 goto ret_object;
97008 @@ -279,7 +279,7 @@ nocache:
97009 }
97010 flo = resolver(net, key, family, dir, flo, ctx);
97011 if (fle) {
97012 - fle->genid = atomic_read(&flow_cache_genid);
97013 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
97014 if (!IS_ERR(flo))
97015 fle->object = flo;
97016 else
97017 diff --git a/net/core/iovec.c b/net/core/iovec.c
97018 index b618694..192bbba 100644
97019 --- a/net/core/iovec.c
97020 +++ b/net/core/iovec.c
97021 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97022 if (m->msg_namelen) {
97023 if (mode == VERIFY_READ) {
97024 void __user *namep;
97025 - namep = (void __user __force *) m->msg_name;
97026 + namep = (void __force_user *) m->msg_name;
97027 err = move_addr_to_kernel(namep, m->msg_namelen,
97028 address);
97029 if (err < 0)
97030 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97031 }
97032
97033 size = m->msg_iovlen * sizeof(struct iovec);
97034 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
97035 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
97036 return -EFAULT;
97037
97038 m->msg_iov = iov;
97039 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
97040 index e161290..8149aea 100644
97041 --- a/net/core/neighbour.c
97042 +++ b/net/core/neighbour.c
97043 @@ -2824,7 +2824,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
97044 void __user *buffer, size_t *lenp, loff_t *ppos)
97045 {
97046 int size, ret;
97047 - struct ctl_table tmp = *ctl;
97048 + ctl_table_no_const tmp = *ctl;
97049
97050 tmp.extra1 = &zero;
97051 tmp.extra2 = &unres_qlen_max;
97052 @@ -2886,7 +2886,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
97053 void __user *buffer,
97054 size_t *lenp, loff_t *ppos)
97055 {
97056 - struct ctl_table tmp = *ctl;
97057 + ctl_table_no_const tmp = *ctl;
97058 int ret;
97059
97060 tmp.extra1 = &zero;
97061 @@ -3058,11 +3058,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
97062 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
97063 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
97064 } else {
97065 + struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
97066 dev_name_source = "default";
97067 - t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
97068 - t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
97069 - t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
97070 - t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
97071 + t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
97072 + t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
97073 + t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
97074 + t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
97075 }
97076
97077 if (handler) {
97078 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
97079 index 2bf8329..7960607 100644
97080 --- a/net/core/net-procfs.c
97081 +++ b/net/core/net-procfs.c
97082 @@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
97083 else
97084 seq_printf(seq, "%04x", ntohs(pt->type));
97085
97086 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97087 + seq_printf(seq, " %-8s %pf\n",
97088 + pt->dev ? pt->dev->name : "", NULL);
97089 +#else
97090 seq_printf(seq, " %-8s %pf\n",
97091 pt->dev ? pt->dev->name : "", pt->func);
97092 +#endif
97093 }
97094
97095 return 0;
97096 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
97097 index 81d3a9a..a0bd7a8 100644
97098 --- a/net/core/net_namespace.c
97099 +++ b/net/core/net_namespace.c
97100 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
97101 int error;
97102 LIST_HEAD(net_exit_list);
97103
97104 - list_add_tail(&ops->list, list);
97105 + pax_list_add_tail((struct list_head *)&ops->list, list);
97106 if (ops->init || (ops->id && ops->size)) {
97107 for_each_net(net) {
97108 error = ops_init(ops, net);
97109 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
97110
97111 out_undo:
97112 /* If I have an error cleanup all namespaces I initialized */
97113 - list_del(&ops->list);
97114 + pax_list_del((struct list_head *)&ops->list);
97115 ops_exit_list(ops, &net_exit_list);
97116 ops_free_list(ops, &net_exit_list);
97117 return error;
97118 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
97119 struct net *net;
97120 LIST_HEAD(net_exit_list);
97121
97122 - list_del(&ops->list);
97123 + pax_list_del((struct list_head *)&ops->list);
97124 for_each_net(net)
97125 list_add_tail(&net->exit_list, &net_exit_list);
97126 ops_exit_list(ops, &net_exit_list);
97127 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
97128 mutex_lock(&net_mutex);
97129 error = register_pernet_operations(&pernet_list, ops);
97130 if (!error && (first_device == &pernet_list))
97131 - first_device = &ops->list;
97132 + first_device = (struct list_head *)&ops->list;
97133 mutex_unlock(&net_mutex);
97134 return error;
97135 }
97136 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
97137 index df9e6b1..6e68e4e 100644
97138 --- a/net/core/netpoll.c
97139 +++ b/net/core/netpoll.c
97140 @@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97141 struct udphdr *udph;
97142 struct iphdr *iph;
97143 struct ethhdr *eth;
97144 - static atomic_t ip_ident;
97145 + static atomic_unchecked_t ip_ident;
97146 struct ipv6hdr *ip6h;
97147
97148 udp_len = len + sizeof(*udph);
97149 @@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97150 put_unaligned(0x45, (unsigned char *)iph);
97151 iph->tos = 0;
97152 put_unaligned(htons(ip_len), &(iph->tot_len));
97153 - iph->id = htons(atomic_inc_return(&ip_ident));
97154 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
97155 iph->frag_off = 0;
97156 iph->ttl = 64;
97157 iph->protocol = IPPROTO_UDP;
97158 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
97159 index 120eecc..cd1ec44 100644
97160 --- a/net/core/rtnetlink.c
97161 +++ b/net/core/rtnetlink.c
97162 @@ -58,7 +58,7 @@ struct rtnl_link {
97163 rtnl_doit_func doit;
97164 rtnl_dumpit_func dumpit;
97165 rtnl_calcit_func calcit;
97166 -};
97167 +} __no_const;
97168
97169 static DEFINE_MUTEX(rtnl_mutex);
97170
97171 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
97172 if (rtnl_link_ops_get(ops->kind))
97173 return -EEXIST;
97174
97175 - if (!ops->dellink)
97176 - ops->dellink = unregister_netdevice_queue;
97177 + if (!ops->dellink) {
97178 + pax_open_kernel();
97179 + *(void **)&ops->dellink = unregister_netdevice_queue;
97180 + pax_close_kernel();
97181 + }
97182
97183 - list_add_tail(&ops->list, &link_ops);
97184 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
97185 return 0;
97186 }
97187 EXPORT_SYMBOL_GPL(__rtnl_link_register);
97188 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
97189 for_each_net(net) {
97190 __rtnl_kill_links(net, ops);
97191 }
97192 - list_del(&ops->list);
97193 + pax_list_del((struct list_head *)&ops->list);
97194 }
97195 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
97196
97197 diff --git a/net/core/scm.c b/net/core/scm.c
97198 index b442e7e..6f5b5a2 100644
97199 --- a/net/core/scm.c
97200 +++ b/net/core/scm.c
97201 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
97202 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97203 {
97204 struct cmsghdr __user *cm
97205 - = (__force struct cmsghdr __user *)msg->msg_control;
97206 + = (struct cmsghdr __force_user *)msg->msg_control;
97207 struct cmsghdr cmhdr;
97208 int cmlen = CMSG_LEN(len);
97209 int err;
97210 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97211 err = -EFAULT;
97212 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
97213 goto out;
97214 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
97215 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
97216 goto out;
97217 cmlen = CMSG_SPACE(len);
97218 if (msg->msg_controllen < cmlen)
97219 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
97220 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97221 {
97222 struct cmsghdr __user *cm
97223 - = (__force struct cmsghdr __user*)msg->msg_control;
97224 + = (struct cmsghdr __force_user *)msg->msg_control;
97225
97226 int fdmax = 0;
97227 int fdnum = scm->fp->count;
97228 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97229 if (fdnum < fdmax)
97230 fdmax = fdnum;
97231
97232 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
97233 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
97234 i++, cmfptr++)
97235 {
97236 struct socket *sock;
97237 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
97238 index 90b96a1..cd18f16 100644
97239 --- a/net/core/skbuff.c
97240 +++ b/net/core/skbuff.c
97241 @@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
97242 __wsum skb_checksum(const struct sk_buff *skb, int offset,
97243 int len, __wsum csum)
97244 {
97245 - const struct skb_checksum_ops ops = {
97246 + static const struct skb_checksum_ops ops = {
97247 .update = csum_partial_ext,
97248 .combine = csum_block_add_ext,
97249 };
97250 @@ -3220,13 +3220,15 @@ void __init skb_init(void)
97251 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
97252 sizeof(struct sk_buff),
97253 0,
97254 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97255 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97256 + SLAB_NO_SANITIZE,
97257 NULL);
97258 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
97259 (2*sizeof(struct sk_buff)) +
97260 sizeof(atomic_t),
97261 0,
97262 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97263 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97264 + SLAB_NO_SANITIZE,
97265 NULL);
97266 }
97267
97268 diff --git a/net/core/sock.c b/net/core/sock.c
97269 index c0fc6bd..51d8326 100644
97270 --- a/net/core/sock.c
97271 +++ b/net/core/sock.c
97272 @@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97273 struct sk_buff_head *list = &sk->sk_receive_queue;
97274
97275 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
97276 - atomic_inc(&sk->sk_drops);
97277 + atomic_inc_unchecked(&sk->sk_drops);
97278 trace_sock_rcvqueue_full(sk, skb);
97279 return -ENOMEM;
97280 }
97281 @@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97282 return err;
97283
97284 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
97285 - atomic_inc(&sk->sk_drops);
97286 + atomic_inc_unchecked(&sk->sk_drops);
97287 return -ENOBUFS;
97288 }
97289
97290 @@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97291 skb_dst_force(skb);
97292
97293 spin_lock_irqsave(&list->lock, flags);
97294 - skb->dropcount = atomic_read(&sk->sk_drops);
97295 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
97296 __skb_queue_tail(list, skb);
97297 spin_unlock_irqrestore(&list->lock, flags);
97298
97299 @@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97300 skb->dev = NULL;
97301
97302 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
97303 - atomic_inc(&sk->sk_drops);
97304 + atomic_inc_unchecked(&sk->sk_drops);
97305 goto discard_and_relse;
97306 }
97307 if (nested)
97308 @@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97309 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
97310 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
97311 bh_unlock_sock(sk);
97312 - atomic_inc(&sk->sk_drops);
97313 + atomic_inc_unchecked(&sk->sk_drops);
97314 goto discard_and_relse;
97315 }
97316
97317 @@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97318 struct timeval tm;
97319 } v;
97320
97321 - int lv = sizeof(int);
97322 - int len;
97323 + unsigned int lv = sizeof(int);
97324 + unsigned int len;
97325
97326 if (get_user(len, optlen))
97327 return -EFAULT;
97328 - if (len < 0)
97329 + if (len > INT_MAX)
97330 return -EINVAL;
97331
97332 memset(&v, 0, sizeof(v));
97333 @@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97334
97335 case SO_PEERNAME:
97336 {
97337 - char address[128];
97338 + char address[_K_SS_MAXSIZE];
97339
97340 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
97341 return -ENOTCONN;
97342 - if (lv < len)
97343 + if (lv < len || sizeof address < len)
97344 return -EINVAL;
97345 if (copy_to_user(optval, address, len))
97346 return -EFAULT;
97347 @@ -1191,7 +1191,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97348
97349 if (len > lv)
97350 len = lv;
97351 - if (copy_to_user(optval, &v, len))
97352 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
97353 return -EFAULT;
97354 lenout:
97355 if (put_user(len, optlen))
97356 @@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
97357 */
97358 smp_wmb();
97359 atomic_set(&sk->sk_refcnt, 1);
97360 - atomic_set(&sk->sk_drops, 0);
97361 + atomic_set_unchecked(&sk->sk_drops, 0);
97362 }
97363 EXPORT_SYMBOL(sock_init_data);
97364
97365 @@ -2454,6 +2454,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
97366 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97367 int level, int type)
97368 {
97369 + struct sock_extended_err ee;
97370 struct sock_exterr_skb *serr;
97371 struct sk_buff *skb, *skb2;
97372 int copied, err;
97373 @@ -2475,7 +2476,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97374 sock_recv_timestamp(msg, sk, skb);
97375
97376 serr = SKB_EXT_ERR(skb);
97377 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
97378 + ee = serr->ee;
97379 + put_cmsg(msg, level, type, sizeof ee, &ee);
97380
97381 msg->msg_flags |= MSG_ERRQUEUE;
97382 err = copied;
97383 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
97384 index a0e9cf6..ef7f9ed 100644
97385 --- a/net/core/sock_diag.c
97386 +++ b/net/core/sock_diag.c
97387 @@ -9,26 +9,33 @@
97388 #include <linux/inet_diag.h>
97389 #include <linux/sock_diag.h>
97390
97391 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
97392 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
97393 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
97394 static DEFINE_MUTEX(sock_diag_table_mutex);
97395
97396 int sock_diag_check_cookie(void *sk, __u32 *cookie)
97397 {
97398 +#ifndef CONFIG_GRKERNSEC_HIDESYM
97399 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
97400 cookie[1] != INET_DIAG_NOCOOKIE) &&
97401 ((u32)(unsigned long)sk != cookie[0] ||
97402 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
97403 return -ESTALE;
97404 else
97405 +#endif
97406 return 0;
97407 }
97408 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
97409
97410 void sock_diag_save_cookie(void *sk, __u32 *cookie)
97411 {
97412 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97413 + cookie[0] = 0;
97414 + cookie[1] = 0;
97415 +#else
97416 cookie[0] = (u32)(unsigned long)sk;
97417 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
97418 +#endif
97419 }
97420 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
97421
97422 @@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
97423 mutex_lock(&sock_diag_table_mutex);
97424 if (sock_diag_handlers[hndl->family])
97425 err = -EBUSY;
97426 - else
97427 + else {
97428 + pax_open_kernel();
97429 sock_diag_handlers[hndl->family] = hndl;
97430 + pax_close_kernel();
97431 + }
97432 mutex_unlock(&sock_diag_table_mutex);
97433
97434 return err;
97435 @@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
97436
97437 mutex_lock(&sock_diag_table_mutex);
97438 BUG_ON(sock_diag_handlers[family] != hnld);
97439 + pax_open_kernel();
97440 sock_diag_handlers[family] = NULL;
97441 + pax_close_kernel();
97442 mutex_unlock(&sock_diag_table_mutex);
97443 }
97444 EXPORT_SYMBOL_GPL(sock_diag_unregister);
97445 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
97446 index cf9cd13..8b56af3 100644
97447 --- a/net/core/sysctl_net_core.c
97448 +++ b/net/core/sysctl_net_core.c
97449 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
97450 {
97451 unsigned int orig_size, size;
97452 int ret, i;
97453 - struct ctl_table tmp = {
97454 + ctl_table_no_const tmp = {
97455 .data = &size,
97456 .maxlen = sizeof(size),
97457 .mode = table->mode
97458 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
97459 void __user *buffer, size_t *lenp, loff_t *ppos)
97460 {
97461 char id[IFNAMSIZ];
97462 - struct ctl_table tbl = {
97463 + ctl_table_no_const tbl = {
97464 .data = id,
97465 .maxlen = IFNAMSIZ,
97466 };
97467 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
97468
97469 static __net_init int sysctl_core_net_init(struct net *net)
97470 {
97471 - struct ctl_table *tbl;
97472 + ctl_table_no_const *tbl = NULL;
97473
97474 net->core.sysctl_somaxconn = SOMAXCONN;
97475
97476 - tbl = netns_core_table;
97477 if (!net_eq(net, &init_net)) {
97478 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
97479 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
97480 if (tbl == NULL)
97481 goto err_dup;
97482
97483 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
97484 if (net->user_ns != &init_user_ns) {
97485 tbl[0].procname = NULL;
97486 }
97487 - }
97488 -
97489 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97490 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97491 + } else
97492 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
97493 if (net->core.sysctl_hdr == NULL)
97494 goto err_reg;
97495
97496 return 0;
97497
97498 err_reg:
97499 - if (tbl != netns_core_table)
97500 - kfree(tbl);
97501 + kfree(tbl);
97502 err_dup:
97503 return -ENOMEM;
97504 }
97505 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
97506 kfree(tbl);
97507 }
97508
97509 -static __net_initdata struct pernet_operations sysctl_core_ops = {
97510 +static __net_initconst struct pernet_operations sysctl_core_ops = {
97511 .init = sysctl_core_net_init,
97512 .exit = sysctl_core_net_exit,
97513 };
97514 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
97515 index 4c04848..f575934 100644
97516 --- a/net/decnet/af_decnet.c
97517 +++ b/net/decnet/af_decnet.c
97518 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
97519 .sysctl_rmem = sysctl_decnet_rmem,
97520 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
97521 .obj_size = sizeof(struct dn_sock),
97522 + .slab_flags = SLAB_USERCOPY,
97523 };
97524
97525 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
97526 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
97527 index a603823..a36ee0b 100644
97528 --- a/net/decnet/dn_dev.c
97529 +++ b/net/decnet/dn_dev.c
97530 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
97531 .extra1 = &min_t3,
97532 .extra2 = &max_t3
97533 },
97534 - {0}
97535 + { }
97536 },
97537 };
97538
97539 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
97540 index 5325b54..a0d4d69 100644
97541 --- a/net/decnet/sysctl_net_decnet.c
97542 +++ b/net/decnet/sysctl_net_decnet.c
97543 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
97544
97545 if (len > *lenp) len = *lenp;
97546
97547 - if (copy_to_user(buffer, addr, len))
97548 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
97549 return -EFAULT;
97550
97551 *lenp = len;
97552 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
97553
97554 if (len > *lenp) len = *lenp;
97555
97556 - if (copy_to_user(buffer, devname, len))
97557 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
97558 return -EFAULT;
97559
97560 *lenp = len;
97561 diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
97562 index 1846c1f..96d4a9f 100644
97563 --- a/net/ieee802154/dgram.c
97564 +++ b/net/ieee802154/dgram.c
97565 @@ -313,8 +313,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
97566 if (saddr) {
97567 saddr->family = AF_IEEE802154;
97568 saddr->addr = mac_cb(skb)->sa;
97569 + }
97570 + if (addr_len)
97571 *addr_len = sizeof(*saddr);
97572 - }
97573
97574 if (flags & MSG_TRUNC)
97575 copied = skb->len;
97576 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
97577 index 19ab78a..bf575c9 100644
97578 --- a/net/ipv4/af_inet.c
97579 +++ b/net/ipv4/af_inet.c
97580 @@ -1703,13 +1703,9 @@ static int __init inet_init(void)
97581
97582 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
97583
97584 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
97585 - if (!sysctl_local_reserved_ports)
97586 - goto out;
97587 -
97588 rc = proto_register(&tcp_prot, 1);
97589 if (rc)
97590 - goto out_free_reserved_ports;
97591 + goto out;
97592
97593 rc = proto_register(&udp_prot, 1);
97594 if (rc)
97595 @@ -1816,8 +1812,6 @@ out_unregister_udp_proto:
97596 proto_unregister(&udp_prot);
97597 out_unregister_tcp_proto:
97598 proto_unregister(&tcp_prot);
97599 -out_free_reserved_ports:
97600 - kfree(sysctl_local_reserved_ports);
97601 goto out;
97602 }
97603
97604 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
97605 index bdbf68b..deb4759 100644
97606 --- a/net/ipv4/devinet.c
97607 +++ b/net/ipv4/devinet.c
97608 @@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
97609 idx = 0;
97610 head = &net->dev_index_head[h];
97611 rcu_read_lock();
97612 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97613 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97614 net->dev_base_seq;
97615 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97616 if (idx < s_idx)
97617 @@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
97618 idx = 0;
97619 head = &net->dev_index_head[h];
97620 rcu_read_lock();
97621 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97622 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97623 net->dev_base_seq;
97624 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97625 if (idx < s_idx)
97626 @@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
97627 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
97628 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
97629
97630 -static struct devinet_sysctl_table {
97631 +static const struct devinet_sysctl_table {
97632 struct ctl_table_header *sysctl_header;
97633 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
97634 } devinet_sysctl = {
97635 @@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
97636 int err;
97637 struct ipv4_devconf *all, *dflt;
97638 #ifdef CONFIG_SYSCTL
97639 - struct ctl_table *tbl = ctl_forward_entry;
97640 + ctl_table_no_const *tbl = NULL;
97641 struct ctl_table_header *forw_hdr;
97642 #endif
97643
97644 @@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
97645 goto err_alloc_dflt;
97646
97647 #ifdef CONFIG_SYSCTL
97648 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
97649 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
97650 if (tbl == NULL)
97651 goto err_alloc_ctl;
97652
97653 @@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
97654 goto err_reg_dflt;
97655
97656 err = -ENOMEM;
97657 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97658 + if (!net_eq(net, &init_net))
97659 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97660 + else
97661 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
97662 if (forw_hdr == NULL)
97663 goto err_reg_ctl;
97664 net->ipv4.forw_hdr = forw_hdr;
97665 @@ -2272,8 +2275,7 @@ err_reg_ctl:
97666 err_reg_dflt:
97667 __devinet_sysctl_unregister(all);
97668 err_reg_all:
97669 - if (tbl != ctl_forward_entry)
97670 - kfree(tbl);
97671 + kfree(tbl);
97672 err_alloc_ctl:
97673 #endif
97674 if (dflt != &ipv4_devconf_dflt)
97675 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
97676 index c7539e2..b455e51 100644
97677 --- a/net/ipv4/fib_frontend.c
97678 +++ b/net/ipv4/fib_frontend.c
97679 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
97680 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97681 fib_sync_up(dev);
97682 #endif
97683 - atomic_inc(&net->ipv4.dev_addr_genid);
97684 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97685 rt_cache_flush(dev_net(dev));
97686 break;
97687 case NETDEV_DOWN:
97688 fib_del_ifaddr(ifa, NULL);
97689 - atomic_inc(&net->ipv4.dev_addr_genid);
97690 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97691 if (ifa->ifa_dev->ifa_list == NULL) {
97692 /* Last address was deleted from this interface.
97693 * Disable IP.
97694 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
97695 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97696 fib_sync_up(dev);
97697 #endif
97698 - atomic_inc(&net->ipv4.dev_addr_genid);
97699 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97700 rt_cache_flush(net);
97701 break;
97702 case NETDEV_DOWN:
97703 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
97704 index b53f0bf..3585b33 100644
97705 --- a/net/ipv4/fib_semantics.c
97706 +++ b/net/ipv4/fib_semantics.c
97707 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
97708 nh->nh_saddr = inet_select_addr(nh->nh_dev,
97709 nh->nh_gw,
97710 nh->nh_parent->fib_scope);
97711 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
97712 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
97713
97714 return nh->nh_saddr;
97715 }
97716 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
97717 index 0d1e2cb..4501a2c 100644
97718 --- a/net/ipv4/inet_connection_sock.c
97719 +++ b/net/ipv4/inet_connection_sock.c
97720 @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
97721 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
97722 #endif
97723
97724 -unsigned long *sysctl_local_reserved_ports;
97725 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
97726 EXPORT_SYMBOL(sysctl_local_reserved_ports);
97727
97728 void inet_get_local_port_range(struct net *net, int *low, int *high)
97729 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
97730 index 8b9cf27..0d8d592 100644
97731 --- a/net/ipv4/inet_hashtables.c
97732 +++ b/net/ipv4/inet_hashtables.c
97733 @@ -18,6 +18,7 @@
97734 #include <linux/sched.h>
97735 #include <linux/slab.h>
97736 #include <linux/wait.h>
97737 +#include <linux/security.h>
97738
97739 #include <net/inet_connection_sock.h>
97740 #include <net/inet_hashtables.h>
97741 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
97742 return inet_ehashfn(net, laddr, lport, faddr, fport);
97743 }
97744
97745 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
97746 +
97747 /*
97748 * Allocate and initialize a new local port bind bucket.
97749 * The bindhash mutex for snum's hash chain must be held here.
97750 @@ -554,6 +557,8 @@ ok:
97751 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
97752 spin_unlock(&head->lock);
97753
97754 + gr_update_task_in_ip_table(current, inet_sk(sk));
97755 +
97756 if (tw) {
97757 inet_twsk_deschedule(tw, death_row);
97758 while (twrefcnt) {
97759 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
97760 index 48f4244..f56d83a 100644
97761 --- a/net/ipv4/inetpeer.c
97762 +++ b/net/ipv4/inetpeer.c
97763 @@ -496,8 +496,8 @@ relookup:
97764 if (p) {
97765 p->daddr = *daddr;
97766 atomic_set(&p->refcnt, 1);
97767 - atomic_set(&p->rid, 0);
97768 - atomic_set(&p->ip_id_count,
97769 + atomic_set_unchecked(&p->rid, 0);
97770 + atomic_set_unchecked(&p->ip_id_count,
97771 (daddr->family == AF_INET) ?
97772 secure_ip_id(daddr->addr.a4) :
97773 secure_ipv6_id(daddr->addr.a6));
97774 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
97775 index c10a3ce..dd71f84 100644
97776 --- a/net/ipv4/ip_fragment.c
97777 +++ b/net/ipv4/ip_fragment.c
97778 @@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
97779 return 0;
97780
97781 start = qp->rid;
97782 - end = atomic_inc_return(&peer->rid);
97783 + end = atomic_inc_return_unchecked(&peer->rid);
97784 qp->rid = end;
97785
97786 rc = qp->q.fragments && (end - start) > max;
97787 @@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
97788
97789 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97790 {
97791 - struct ctl_table *table;
97792 + ctl_table_no_const *table = NULL;
97793 struct ctl_table_header *hdr;
97794
97795 - table = ip4_frags_ns_ctl_table;
97796 if (!net_eq(net, &init_net)) {
97797 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
97798 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
97799 if (table == NULL)
97800 goto err_alloc;
97801
97802 @@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97803 /* Don't export sysctls to unprivileged users */
97804 if (net->user_ns != &init_user_ns)
97805 table[0].procname = NULL;
97806 - }
97807 + hdr = register_net_sysctl(net, "net/ipv4", table);
97808 + } else
97809 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
97810
97811 - hdr = register_net_sysctl(net, "net/ipv4", table);
97812 if (hdr == NULL)
97813 goto err_reg;
97814
97815 @@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97816 return 0;
97817
97818 err_reg:
97819 - if (!net_eq(net, &init_net))
97820 - kfree(table);
97821 + kfree(table);
97822 err_alloc:
97823 return -ENOMEM;
97824 }
97825 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
97826 index ec4f762..4ce3645 100644
97827 --- a/net/ipv4/ip_gre.c
97828 +++ b/net/ipv4/ip_gre.c
97829 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
97830 module_param(log_ecn_error, bool, 0644);
97831 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
97832
97833 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
97834 +static struct rtnl_link_ops ipgre_link_ops;
97835 static int ipgre_tunnel_init(struct net_device *dev);
97836
97837 static int ipgre_net_id __read_mostly;
97838 @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
97839 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
97840 };
97841
97842 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
97843 +static struct rtnl_link_ops ipgre_link_ops = {
97844 .kind = "gre",
97845 .maxtype = IFLA_GRE_MAX,
97846 .policy = ipgre_policy,
97847 @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
97848 .fill_info = ipgre_fill_info,
97849 };
97850
97851 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
97852 +static struct rtnl_link_ops ipgre_tap_ops = {
97853 .kind = "gretap",
97854 .maxtype = IFLA_GRE_MAX,
97855 .policy = ipgre_policy,
97856 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
97857 index 580dd96..9fcef7e 100644
97858 --- a/net/ipv4/ip_sockglue.c
97859 +++ b/net/ipv4/ip_sockglue.c
97860 @@ -1171,7 +1171,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
97861 len = min_t(unsigned int, len, opt->optlen);
97862 if (put_user(len, optlen))
97863 return -EFAULT;
97864 - if (copy_to_user(optval, opt->__data, len))
97865 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
97866 + copy_to_user(optval, opt->__data, len))
97867 return -EFAULT;
97868 return 0;
97869 }
97870 @@ -1302,7 +1303,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
97871 if (sk->sk_type != SOCK_STREAM)
97872 return -ENOPROTOOPT;
97873
97874 - msg.msg_control = optval;
97875 + msg.msg_control = (void __force_kernel *)optval;
97876 msg.msg_controllen = len;
97877 msg.msg_flags = flags;
97878
97879 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
97880 index 48eafae..defff53 100644
97881 --- a/net/ipv4/ip_vti.c
97882 +++ b/net/ipv4/ip_vti.c
97883 @@ -44,7 +44,7 @@
97884 #include <net/net_namespace.h>
97885 #include <net/netns/generic.h>
97886
97887 -static struct rtnl_link_ops vti_link_ops __read_mostly;
97888 +static struct rtnl_link_ops vti_link_ops;
97889
97890 static int vti_net_id __read_mostly;
97891 static int vti_tunnel_init(struct net_device *dev);
97892 @@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
97893 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
97894 };
97895
97896 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
97897 +static struct rtnl_link_ops vti_link_ops = {
97898 .kind = "vti",
97899 .maxtype = IFLA_VTI_MAX,
97900 .policy = vti_policy,
97901 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
97902 index b3e86ea..18ce98c 100644
97903 --- a/net/ipv4/ipconfig.c
97904 +++ b/net/ipv4/ipconfig.c
97905 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
97906
97907 mm_segment_t oldfs = get_fs();
97908 set_fs(get_ds());
97909 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
97910 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
97911 set_fs(oldfs);
97912 return res;
97913 }
97914 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
97915
97916 mm_segment_t oldfs = get_fs();
97917 set_fs(get_ds());
97918 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
97919 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
97920 set_fs(oldfs);
97921 return res;
97922 }
97923 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
97924
97925 mm_segment_t oldfs = get_fs();
97926 set_fs(get_ds());
97927 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
97928 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
97929 set_fs(oldfs);
97930 return res;
97931 }
97932 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
97933 index 812b183..56cbe9c 100644
97934 --- a/net/ipv4/ipip.c
97935 +++ b/net/ipv4/ipip.c
97936 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
97937 static int ipip_net_id __read_mostly;
97938
97939 static int ipip_tunnel_init(struct net_device *dev);
97940 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
97941 +static struct rtnl_link_ops ipip_link_ops;
97942
97943 static int ipip_err(struct sk_buff *skb, u32 info)
97944 {
97945 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
97946 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
97947 };
97948
97949 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
97950 +static struct rtnl_link_ops ipip_link_ops = {
97951 .kind = "ipip",
97952 .maxtype = IFLA_IPTUN_MAX,
97953 .policy = ipip_policy,
97954 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
97955 index 59da7cd..e318de1 100644
97956 --- a/net/ipv4/netfilter/arp_tables.c
97957 +++ b/net/ipv4/netfilter/arp_tables.c
97958 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
97959 #endif
97960
97961 static int get_info(struct net *net, void __user *user,
97962 - const int *len, int compat)
97963 + int len, int compat)
97964 {
97965 char name[XT_TABLE_MAXNAMELEN];
97966 struct xt_table *t;
97967 int ret;
97968
97969 - if (*len != sizeof(struct arpt_getinfo)) {
97970 - duprintf("length %u != %Zu\n", *len,
97971 + if (len != sizeof(struct arpt_getinfo)) {
97972 + duprintf("length %u != %Zu\n", len,
97973 sizeof(struct arpt_getinfo));
97974 return -EINVAL;
97975 }
97976 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
97977 info.size = private->size;
97978 strcpy(info.name, name);
97979
97980 - if (copy_to_user(user, &info, *len) != 0)
97981 + if (copy_to_user(user, &info, len) != 0)
97982 ret = -EFAULT;
97983 else
97984 ret = 0;
97985 @@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
97986
97987 switch (cmd) {
97988 case ARPT_SO_GET_INFO:
97989 - ret = get_info(sock_net(sk), user, len, 1);
97990 + ret = get_info(sock_net(sk), user, *len, 1);
97991 break;
97992 case ARPT_SO_GET_ENTRIES:
97993 ret = compat_get_entries(sock_net(sk), user, len);
97994 @@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
97995
97996 switch (cmd) {
97997 case ARPT_SO_GET_INFO:
97998 - ret = get_info(sock_net(sk), user, len, 0);
97999 + ret = get_info(sock_net(sk), user, *len, 0);
98000 break;
98001
98002 case ARPT_SO_GET_ENTRIES:
98003 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
98004 index 718dfbd..cef4152 100644
98005 --- a/net/ipv4/netfilter/ip_tables.c
98006 +++ b/net/ipv4/netfilter/ip_tables.c
98007 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
98008 #endif
98009
98010 static int get_info(struct net *net, void __user *user,
98011 - const int *len, int compat)
98012 + int len, int compat)
98013 {
98014 char name[XT_TABLE_MAXNAMELEN];
98015 struct xt_table *t;
98016 int ret;
98017
98018 - if (*len != sizeof(struct ipt_getinfo)) {
98019 - duprintf("length %u != %zu\n", *len,
98020 + if (len != sizeof(struct ipt_getinfo)) {
98021 + duprintf("length %u != %zu\n", len,
98022 sizeof(struct ipt_getinfo));
98023 return -EINVAL;
98024 }
98025 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
98026 info.size = private->size;
98027 strcpy(info.name, name);
98028
98029 - if (copy_to_user(user, &info, *len) != 0)
98030 + if (copy_to_user(user, &info, len) != 0)
98031 ret = -EFAULT;
98032 else
98033 ret = 0;
98034 @@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98035
98036 switch (cmd) {
98037 case IPT_SO_GET_INFO:
98038 - ret = get_info(sock_net(sk), user, len, 1);
98039 + ret = get_info(sock_net(sk), user, *len, 1);
98040 break;
98041 case IPT_SO_GET_ENTRIES:
98042 ret = compat_get_entries(sock_net(sk), user, len);
98043 @@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98044
98045 switch (cmd) {
98046 case IPT_SO_GET_INFO:
98047 - ret = get_info(sock_net(sk), user, len, 0);
98048 + ret = get_info(sock_net(sk), user, *len, 0);
98049 break;
98050
98051 case IPT_SO_GET_ENTRIES:
98052 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
98053 index 2d11c09..3f153f8 100644
98054 --- a/net/ipv4/ping.c
98055 +++ b/net/ipv4/ping.c
98056 @@ -59,7 +59,7 @@ struct ping_table {
98057 };
98058
98059 static struct ping_table ping_table;
98060 -struct pingv6_ops pingv6_ops;
98061 +struct pingv6_ops *pingv6_ops;
98062 EXPORT_SYMBOL_GPL(pingv6_ops);
98063
98064 static u16 ping_port_rover;
98065 @@ -255,23 +255,28 @@ int ping_init_sock(struct sock *sk)
98066 struct group_info *group_info = get_current_groups();
98067 int i, j, count = group_info->ngroups;
98068 kgid_t low, high;
98069 + int ret = 0;
98070
98071 inet_get_ping_group_range_net(net, &low, &high);
98072 if (gid_lte(low, group) && gid_lte(group, high))
98073 - return 0;
98074 + goto out_release_group;
98075
98076 for (i = 0; i < group_info->nblocks; i++) {
98077 int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
98078 for (j = 0; j < cp_count; j++) {
98079 kgid_t gid = group_info->blocks[i][j];
98080 if (gid_lte(low, gid) && gid_lte(gid, high))
98081 - return 0;
98082 + goto out_release_group;
98083 }
98084
98085 count -= cp_count;
98086 }
98087
98088 - return -EACCES;
98089 + ret = -EACCES;
98090 +
98091 +out_release_group:
98092 + put_group_info(group_info);
98093 + return ret;
98094 }
98095 EXPORT_SYMBOL_GPL(ping_init_sock);
98096
98097 @@ -341,7 +346,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
98098 return -ENODEV;
98099 }
98100 }
98101 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
98102 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
98103 scoped);
98104 rcu_read_unlock();
98105
98106 @@ -549,7 +554,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98107 }
98108 #if IS_ENABLED(CONFIG_IPV6)
98109 } else if (skb->protocol == htons(ETH_P_IPV6)) {
98110 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
98111 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
98112 #endif
98113 }
98114
98115 @@ -567,7 +572,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98116 info, (u8 *)icmph);
98117 #if IS_ENABLED(CONFIG_IPV6)
98118 } else if (family == AF_INET6) {
98119 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
98120 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
98121 info, (u8 *)icmph);
98122 #endif
98123 }
98124 @@ -837,6 +842,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98125 {
98126 struct inet_sock *isk = inet_sk(sk);
98127 int family = sk->sk_family;
98128 + struct sockaddr_in *sin;
98129 + struct sockaddr_in6 *sin6;
98130 struct sk_buff *skb;
98131 int copied, err;
98132
98133 @@ -846,12 +853,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98134 if (flags & MSG_OOB)
98135 goto out;
98136
98137 + if (addr_len) {
98138 + if (family == AF_INET)
98139 + *addr_len = sizeof(*sin);
98140 + else if (family == AF_INET6 && addr_len)
98141 + *addr_len = sizeof(*sin6);
98142 + }
98143 +
98144 if (flags & MSG_ERRQUEUE) {
98145 if (family == AF_INET) {
98146 return ip_recv_error(sk, msg, len, addr_len);
98147 #if IS_ENABLED(CONFIG_IPV6)
98148 } else if (family == AF_INET6) {
98149 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
98150 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
98151 addr_len);
98152 #endif
98153 }
98154 @@ -883,7 +897,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98155 sin->sin_port = 0 /* skb->h.uh->source */;
98156 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98157 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98158 - *addr_len = sizeof(*sin);
98159 }
98160
98161 if (isk->cmsg_flags)
98162 @@ -905,14 +918,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98163 sin6->sin6_scope_id =
98164 ipv6_iface_scope_id(&sin6->sin6_addr,
98165 IP6CB(skb)->iif);
98166 - *addr_len = sizeof(*sin6);
98167 }
98168
98169 if (inet6_sk(sk)->rxopt.all)
98170 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
98171 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
98172 if (skb->protocol == htons(ETH_P_IPV6) &&
98173 inet6_sk(sk)->rxopt.all)
98174 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
98175 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
98176 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
98177 ip_cmsg_recv(msg, skb);
98178 #endif
98179 @@ -1104,7 +1116,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
98180 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98181 0, sock_i_ino(sp),
98182 atomic_read(&sp->sk_refcnt), sp,
98183 - atomic_read(&sp->sk_drops));
98184 + atomic_read_unchecked(&sp->sk_drops));
98185 }
98186
98187 static int ping_v4_seq_show(struct seq_file *seq, void *v)
98188 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
98189 index c04518f..824ebe5 100644
98190 --- a/net/ipv4/raw.c
98191 +++ b/net/ipv4/raw.c
98192 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
98193 int raw_rcv(struct sock *sk, struct sk_buff *skb)
98194 {
98195 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
98196 - atomic_inc(&sk->sk_drops);
98197 + atomic_inc_unchecked(&sk->sk_drops);
98198 kfree_skb(skb);
98199 return NET_RX_DROP;
98200 }
98201 @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98202 if (flags & MSG_OOB)
98203 goto out;
98204
98205 + if (addr_len)
98206 + *addr_len = sizeof(*sin);
98207 +
98208 if (flags & MSG_ERRQUEUE) {
98209 err = ip_recv_error(sk, msg, len, addr_len);
98210 goto out;
98211 @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98212 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98213 sin->sin_port = 0;
98214 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98215 - *addr_len = sizeof(*sin);
98216 }
98217 if (inet->cmsg_flags)
98218 ip_cmsg_recv(msg, skb);
98219 @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
98220
98221 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
98222 {
98223 + struct icmp_filter filter;
98224 +
98225 if (optlen > sizeof(struct icmp_filter))
98226 optlen = sizeof(struct icmp_filter);
98227 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
98228 + if (copy_from_user(&filter, optval, optlen))
98229 return -EFAULT;
98230 + raw_sk(sk)->filter = filter;
98231 return 0;
98232 }
98233
98234 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
98235 {
98236 int len, ret = -EFAULT;
98237 + struct icmp_filter filter;
98238
98239 if (get_user(len, optlen))
98240 goto out;
98241 @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
98242 if (len > sizeof(struct icmp_filter))
98243 len = sizeof(struct icmp_filter);
98244 ret = -EFAULT;
98245 - if (put_user(len, optlen) ||
98246 - copy_to_user(optval, &raw_sk(sk)->filter, len))
98247 + filter = raw_sk(sk)->filter;
98248 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
98249 goto out;
98250 ret = 0;
98251 out: return ret;
98252 @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
98253 0, 0L, 0,
98254 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
98255 0, sock_i_ino(sp),
98256 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
98257 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
98258 }
98259
98260 static int raw_seq_show(struct seq_file *seq, void *v)
98261 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
98262 index 4c011ec..5cdfedb 100644
98263 --- a/net/ipv4/route.c
98264 +++ b/net/ipv4/route.c
98265 @@ -2623,34 +2623,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
98266 .maxlen = sizeof(int),
98267 .mode = 0200,
98268 .proc_handler = ipv4_sysctl_rtcache_flush,
98269 + .extra1 = &init_net,
98270 },
98271 { },
98272 };
98273
98274 static __net_init int sysctl_route_net_init(struct net *net)
98275 {
98276 - struct ctl_table *tbl;
98277 + ctl_table_no_const *tbl = NULL;
98278
98279 - tbl = ipv4_route_flush_table;
98280 if (!net_eq(net, &init_net)) {
98281 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98282 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98283 if (tbl == NULL)
98284 goto err_dup;
98285
98286 /* Don't export sysctls to unprivileged users */
98287 if (net->user_ns != &init_user_ns)
98288 tbl[0].procname = NULL;
98289 - }
98290 - tbl[0].extra1 = net;
98291 + tbl[0].extra1 = net;
98292 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98293 + } else
98294 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
98295
98296 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98297 if (net->ipv4.route_hdr == NULL)
98298 goto err_reg;
98299 return 0;
98300
98301 err_reg:
98302 - if (tbl != ipv4_route_flush_table)
98303 - kfree(tbl);
98304 + kfree(tbl);
98305 err_dup:
98306 return -ENOMEM;
98307 }
98308 @@ -2673,8 +2673,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
98309
98310 static __net_init int rt_genid_init(struct net *net)
98311 {
98312 - atomic_set(&net->ipv4.rt_genid, 0);
98313 - atomic_set(&net->fnhe_genid, 0);
98314 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
98315 + atomic_set_unchecked(&net->fnhe_genid, 0);
98316 get_random_bytes(&net->ipv4.dev_addr_genid,
98317 sizeof(net->ipv4.dev_addr_genid));
98318 return 0;
98319 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
98320 index 44eba05..b36864b 100644
98321 --- a/net/ipv4/sysctl_net_ipv4.c
98322 +++ b/net/ipv4/sysctl_net_ipv4.c
98323 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
98324 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
98325 int ret;
98326 int range[2];
98327 - struct ctl_table tmp = {
98328 + ctl_table_no_const tmp = {
98329 .data = &range,
98330 .maxlen = sizeof(range),
98331 .mode = table->mode,
98332 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
98333 int ret;
98334 gid_t urange[2];
98335 kgid_t low, high;
98336 - struct ctl_table tmp = {
98337 + ctl_table_no_const tmp = {
98338 .data = &urange,
98339 .maxlen = sizeof(urange),
98340 .mode = table->mode,
98341 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
98342 void __user *buffer, size_t *lenp, loff_t *ppos)
98343 {
98344 char val[TCP_CA_NAME_MAX];
98345 - struct ctl_table tbl = {
98346 + ctl_table_no_const tbl = {
98347 .data = val,
98348 .maxlen = TCP_CA_NAME_MAX,
98349 };
98350 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
98351 void __user *buffer, size_t *lenp,
98352 loff_t *ppos)
98353 {
98354 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
98355 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
98356 int ret;
98357
98358 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98359 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
98360 void __user *buffer, size_t *lenp,
98361 loff_t *ppos)
98362 {
98363 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
98364 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
98365 int ret;
98366
98367 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98368 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
98369 void __user *buffer, size_t *lenp,
98370 loff_t *ppos)
98371 {
98372 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98373 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98374 struct tcp_fastopen_context *ctxt;
98375 int ret;
98376 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
98377 @@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
98378 },
98379 {
98380 .procname = "ip_local_reserved_ports",
98381 - .data = NULL, /* initialized in sysctl_ipv4_init */
98382 + .data = sysctl_local_reserved_ports,
98383 .maxlen = 65536,
98384 .mode = 0644,
98385 .proc_handler = proc_do_large_bitmap,
98386 @@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
98387
98388 static __net_init int ipv4_sysctl_init_net(struct net *net)
98389 {
98390 - struct ctl_table *table;
98391 + ctl_table_no_const *table = NULL;
98392
98393 - table = ipv4_net_table;
98394 if (!net_eq(net, &init_net)) {
98395 int i;
98396
98397 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
98398 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
98399 if (table == NULL)
98400 goto err_alloc;
98401
98402 @@ -872,15 +871,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
98403 net->ipv4.sysctl_local_ports.range[0] = 32768;
98404 net->ipv4.sysctl_local_ports.range[1] = 61000;
98405
98406 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98407 + if (!net_eq(net, &init_net))
98408 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98409 + else
98410 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
98411 if (net->ipv4.ipv4_hdr == NULL)
98412 goto err_reg;
98413
98414 return 0;
98415
98416 err_reg:
98417 - if (!net_eq(net, &init_net))
98418 - kfree(table);
98419 + kfree(table);
98420 err_alloc:
98421 return -ENOMEM;
98422 }
98423 @@ -902,16 +903,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
98424 static __init int sysctl_ipv4_init(void)
98425 {
98426 struct ctl_table_header *hdr;
98427 - struct ctl_table *i;
98428 -
98429 - for (i = ipv4_table; i->procname; i++) {
98430 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
98431 - i->data = sysctl_local_reserved_ports;
98432 - break;
98433 - }
98434 - }
98435 - if (!i->procname)
98436 - return -EINVAL;
98437
98438 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
98439 if (hdr == NULL)
98440 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
98441 index eeaac39..dc29942 100644
98442 --- a/net/ipv4/tcp_input.c
98443 +++ b/net/ipv4/tcp_input.c
98444 @@ -761,7 +761,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
98445 * without any lock. We want to make sure compiler wont store
98446 * intermediate values in this location.
98447 */
98448 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
98449 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
98450 sk->sk_max_pacing_rate);
98451 }
98452
98453 @@ -4485,7 +4485,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
98454 * simplifies code)
98455 */
98456 static void
98457 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98458 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98459 struct sk_buff *head, struct sk_buff *tail,
98460 u32 start, u32 end)
98461 {
98462 @@ -5562,6 +5562,7 @@ discard:
98463 tcp_paws_reject(&tp->rx_opt, 0))
98464 goto discard_and_undo;
98465
98466 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
98467 if (th->syn) {
98468 /* We see SYN without ACK. It is attempt of
98469 * simultaneous connect with crossed SYNs.
98470 @@ -5612,6 +5613,7 @@ discard:
98471 goto discard;
98472 #endif
98473 }
98474 +#endif
98475 /* "fifth, if neither of the SYN or RST bits is set then
98476 * drop the segment and return."
98477 */
98478 @@ -5658,7 +5660,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
98479 goto discard;
98480
98481 if (th->syn) {
98482 - if (th->fin)
98483 + if (th->fin || th->urg || th->psh)
98484 goto discard;
98485 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
98486 return 1;
98487 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
98488 index 1e4eac7..a66fa4a 100644
98489 --- a/net/ipv4/tcp_ipv4.c
98490 +++ b/net/ipv4/tcp_ipv4.c
98491 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
98492 EXPORT_SYMBOL(sysctl_tcp_low_latency);
98493
98494
98495 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98496 +extern int grsec_enable_blackhole;
98497 +#endif
98498 +
98499 #ifdef CONFIG_TCP_MD5SIG
98500 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
98501 __be32 daddr, __be32 saddr, const struct tcphdr *th);
98502 @@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
98503 return 0;
98504
98505 reset:
98506 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98507 + if (!grsec_enable_blackhole)
98508 +#endif
98509 tcp_v4_send_reset(rsk, skb);
98510 discard:
98511 kfree_skb(skb);
98512 @@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
98513 TCP_SKB_CB(skb)->sacked = 0;
98514
98515 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
98516 - if (!sk)
98517 + if (!sk) {
98518 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98519 + ret = 1;
98520 +#endif
98521 goto no_tcp_socket;
98522 -
98523 + }
98524 process:
98525 - if (sk->sk_state == TCP_TIME_WAIT)
98526 + if (sk->sk_state == TCP_TIME_WAIT) {
98527 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98528 + ret = 2;
98529 +#endif
98530 goto do_time_wait;
98531 + }
98532
98533 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
98534 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
98535 @@ -2033,6 +2047,10 @@ csum_error:
98536 bad_packet:
98537 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
98538 } else {
98539 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98540 + if (!grsec_enable_blackhole || (ret == 1 &&
98541 + (skb->dev->flags & IFF_LOOPBACK)))
98542 +#endif
98543 tcp_v4_send_reset(NULL, skb);
98544 }
98545
98546 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
98547 index 7a436c5..1b05c59 100644
98548 --- a/net/ipv4/tcp_minisocks.c
98549 +++ b/net/ipv4/tcp_minisocks.c
98550 @@ -27,6 +27,10 @@
98551 #include <net/inet_common.h>
98552 #include <net/xfrm.h>
98553
98554 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98555 +extern int grsec_enable_blackhole;
98556 +#endif
98557 +
98558 int sysctl_tcp_syncookies __read_mostly = 1;
98559 EXPORT_SYMBOL(sysctl_tcp_syncookies);
98560
98561 @@ -709,7 +713,10 @@ embryonic_reset:
98562 * avoid becoming vulnerable to outside attack aiming at
98563 * resetting legit local connections.
98564 */
98565 - req->rsk_ops->send_reset(sk, skb);
98566 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98567 + if (!grsec_enable_blackhole)
98568 +#endif
98569 + req->rsk_ops->send_reset(sk, skb);
98570 } else if (fastopen) { /* received a valid RST pkt */
98571 reqsk_fastopen_remove(sk, req, true);
98572 tcp_reset(sk);
98573 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
98574 index 1f2d376..01d18c4 100644
98575 --- a/net/ipv4/tcp_probe.c
98576 +++ b/net/ipv4/tcp_probe.c
98577 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
98578 if (cnt + width >= len)
98579 break;
98580
98581 - if (copy_to_user(buf + cnt, tbuf, width))
98582 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
98583 return -EFAULT;
98584 cnt += width;
98585 }
98586 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
98587 index 64f0354..a81b39d 100644
98588 --- a/net/ipv4/tcp_timer.c
98589 +++ b/net/ipv4/tcp_timer.c
98590 @@ -22,6 +22,10 @@
98591 #include <linux/gfp.h>
98592 #include <net/tcp.h>
98593
98594 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98595 +extern int grsec_lastack_retries;
98596 +#endif
98597 +
98598 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
98599 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
98600 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
98601 @@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
98602 }
98603 }
98604
98605 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98606 + if ((sk->sk_state == TCP_LAST_ACK) &&
98607 + (grsec_lastack_retries > 0) &&
98608 + (grsec_lastack_retries < retry_until))
98609 + retry_until = grsec_lastack_retries;
98610 +#endif
98611 +
98612 if (retransmits_timed_out(sk, retry_until,
98613 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
98614 /* Has it gone just too far? */
98615 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
98616 index 77bd16f..5f7174a 100644
98617 --- a/net/ipv4/udp.c
98618 +++ b/net/ipv4/udp.c
98619 @@ -87,6 +87,7 @@
98620 #include <linux/types.h>
98621 #include <linux/fcntl.h>
98622 #include <linux/module.h>
98623 +#include <linux/security.h>
98624 #include <linux/socket.h>
98625 #include <linux/sockios.h>
98626 #include <linux/igmp.h>
98627 @@ -113,6 +114,10 @@
98628 #include <net/busy_poll.h>
98629 #include "udp_impl.h"
98630
98631 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98632 +extern int grsec_enable_blackhole;
98633 +#endif
98634 +
98635 struct udp_table udp_table __read_mostly;
98636 EXPORT_SYMBOL(udp_table);
98637
98638 @@ -615,6 +620,9 @@ found:
98639 return s;
98640 }
98641
98642 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
98643 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
98644 +
98645 /*
98646 * This routine is called by the ICMP module when it gets some
98647 * sort of error condition. If err < 0 then the socket should
98648 @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98649 dport = usin->sin_port;
98650 if (dport == 0)
98651 return -EINVAL;
98652 +
98653 + err = gr_search_udp_sendmsg(sk, usin);
98654 + if (err)
98655 + return err;
98656 } else {
98657 if (sk->sk_state != TCP_ESTABLISHED)
98658 return -EDESTADDRREQ;
98659 +
98660 + err = gr_search_udp_sendmsg(sk, NULL);
98661 + if (err)
98662 + return err;
98663 +
98664 daddr = inet->inet_daddr;
98665 dport = inet->inet_dport;
98666 /* Open fast path for connected socket.
98667 @@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
98668 IS_UDPLITE(sk));
98669 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98670 IS_UDPLITE(sk));
98671 - atomic_inc(&sk->sk_drops);
98672 + atomic_inc_unchecked(&sk->sk_drops);
98673 __skb_unlink(skb, rcvq);
98674 __skb_queue_tail(&list_kill, skb);
98675 }
98676 @@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98677 int is_udplite = IS_UDPLITE(sk);
98678 bool slow;
98679
98680 + /*
98681 + * Check any passed addresses
98682 + */
98683 + if (addr_len)
98684 + *addr_len = sizeof(*sin);
98685 +
98686 if (flags & MSG_ERRQUEUE)
98687 return ip_recv_error(sk, msg, len, addr_len);
98688
98689 @@ -1243,6 +1266,10 @@ try_again:
98690 if (!skb)
98691 goto out;
98692
98693 + err = gr_search_udp_recvmsg(sk, skb);
98694 + if (err)
98695 + goto out_free;
98696 +
98697 ulen = skb->len - sizeof(struct udphdr);
98698 copied = len;
98699 if (copied > ulen)
98700 @@ -1276,7 +1303,7 @@ try_again:
98701 if (unlikely(err)) {
98702 trace_kfree_skb(skb, udp_recvmsg);
98703 if (!peeked) {
98704 - atomic_inc(&sk->sk_drops);
98705 + atomic_inc_unchecked(&sk->sk_drops);
98706 UDP_INC_STATS_USER(sock_net(sk),
98707 UDP_MIB_INERRORS, is_udplite);
98708 }
98709 @@ -1295,7 +1322,6 @@ try_again:
98710 sin->sin_port = udp_hdr(skb)->source;
98711 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98712 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98713 - *addr_len = sizeof(*sin);
98714 }
98715 if (inet->cmsg_flags)
98716 ip_cmsg_recv(msg, skb);
98717 @@ -1566,7 +1592,7 @@ csum_error:
98718 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
98719 drop:
98720 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
98721 - atomic_inc(&sk->sk_drops);
98722 + atomic_inc_unchecked(&sk->sk_drops);
98723 kfree_skb(skb);
98724 return -1;
98725 }
98726 @@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
98727 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
98728
98729 if (!skb1) {
98730 - atomic_inc(&sk->sk_drops);
98731 + atomic_inc_unchecked(&sk->sk_drops);
98732 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
98733 IS_UDPLITE(sk));
98734 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98735 @@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
98736 goto csum_error;
98737
98738 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
98739 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98740 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
98741 +#endif
98742 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
98743
98744 /*
98745 @@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
98746 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98747 0, sock_i_ino(sp),
98748 atomic_read(&sp->sk_refcnt), sp,
98749 - atomic_read(&sp->sk_drops));
98750 + atomic_read_unchecked(&sp->sk_drops));
98751 }
98752
98753 int udp4_seq_show(struct seq_file *seq, void *v)
98754 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
98755 index e1a6393..f634ce5 100644
98756 --- a/net/ipv4/xfrm4_policy.c
98757 +++ b/net/ipv4/xfrm4_policy.c
98758 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
98759 fl4->flowi4_tos = iph->tos;
98760 }
98761
98762 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
98763 +static int xfrm4_garbage_collect(struct dst_ops *ops)
98764 {
98765 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
98766
98767 - xfrm4_policy_afinfo.garbage_collect(net);
98768 + xfrm_garbage_collect_deferred(net);
98769 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
98770 }
98771
98772 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
98773
98774 static int __net_init xfrm4_net_init(struct net *net)
98775 {
98776 - struct ctl_table *table;
98777 + ctl_table_no_const *table = NULL;
98778 struct ctl_table_header *hdr;
98779
98780 - table = xfrm4_policy_table;
98781 if (!net_eq(net, &init_net)) {
98782 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
98783 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
98784 if (!table)
98785 goto err_alloc;
98786
98787 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
98788 - }
98789 -
98790 - hdr = register_net_sysctl(net, "net/ipv4", table);
98791 + hdr = register_net_sysctl(net, "net/ipv4", table);
98792 + } else
98793 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
98794 if (!hdr)
98795 goto err_reg;
98796
98797 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
98798 return 0;
98799
98800 err_reg:
98801 - if (!net_eq(net, &init_net))
98802 - kfree(table);
98803 + kfree(table);
98804 err_alloc:
98805 return -ENOMEM;
98806 }
98807 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
98808 index 6c7fa08..285086c 100644
98809 --- a/net/ipv6/addrconf.c
98810 +++ b/net/ipv6/addrconf.c
98811 @@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
98812 idx = 0;
98813 head = &net->dev_index_head[h];
98814 rcu_read_lock();
98815 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
98816 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
98817 net->dev_base_seq;
98818 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98819 if (idx < s_idx)
98820 @@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
98821 p.iph.ihl = 5;
98822 p.iph.protocol = IPPROTO_IPV6;
98823 p.iph.ttl = 64;
98824 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
98825 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
98826
98827 if (ops->ndo_do_ioctl) {
98828 mm_segment_t oldfs = get_fs();
98829 @@ -4146,7 +4146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
98830 s_ip_idx = ip_idx = cb->args[2];
98831
98832 rcu_read_lock();
98833 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
98834 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
98835 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
98836 idx = 0;
98837 head = &net->dev_index_head[h];
98838 @@ -4758,7 +4758,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
98839 dst_free(&ifp->rt->dst);
98840 break;
98841 }
98842 - atomic_inc(&net->ipv6.dev_addr_genid);
98843 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
98844 rt_genid_bump_ipv6(net);
98845 }
98846
98847 @@ -4779,7 +4779,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
98848 int *valp = ctl->data;
98849 int val = *valp;
98850 loff_t pos = *ppos;
98851 - struct ctl_table lctl;
98852 + ctl_table_no_const lctl;
98853 int ret;
98854
98855 /*
98856 @@ -4864,7 +4864,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
98857 int *valp = ctl->data;
98858 int val = *valp;
98859 loff_t pos = *ppos;
98860 - struct ctl_table lctl;
98861 + ctl_table_no_const lctl;
98862 int ret;
98863
98864 /*
98865 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
98866 index d935889..2f64330 100644
98867 --- a/net/ipv6/af_inet6.c
98868 +++ b/net/ipv6/af_inet6.c
98869 @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
98870 net->ipv6.sysctl.bindv6only = 0;
98871 net->ipv6.sysctl.icmpv6_time = 1*HZ;
98872 net->ipv6.sysctl.flowlabel_consistency = 1;
98873 - atomic_set(&net->ipv6.rt_genid, 0);
98874 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
98875
98876 err = ipv6_init_mibs(net);
98877 if (err)
98878 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
98879 index c3bf2d2..1f00573 100644
98880 --- a/net/ipv6/datagram.c
98881 +++ b/net/ipv6/datagram.c
98882 @@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
98883 0,
98884 sock_i_ino(sp),
98885 atomic_read(&sp->sk_refcnt), sp,
98886 - atomic_read(&sp->sk_drops));
98887 + atomic_read_unchecked(&sp->sk_drops));
98888 }
98889 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
98890 index 7b32652..0bc348b 100644
98891 --- a/net/ipv6/icmp.c
98892 +++ b/net/ipv6/icmp.c
98893 @@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
98894
98895 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
98896 {
98897 - struct ctl_table *table;
98898 + ctl_table_no_const *table;
98899
98900 table = kmemdup(ipv6_icmp_table_template,
98901 sizeof(ipv6_icmp_table_template),
98902 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
98903 index f3ffb43..1172ba7 100644
98904 --- a/net/ipv6/ip6_gre.c
98905 +++ b/net/ipv6/ip6_gre.c
98906 @@ -71,7 +71,7 @@ struct ip6gre_net {
98907 struct net_device *fb_tunnel_dev;
98908 };
98909
98910 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
98911 +static struct rtnl_link_ops ip6gre_link_ops;
98912 static int ip6gre_tunnel_init(struct net_device *dev);
98913 static void ip6gre_tunnel_setup(struct net_device *dev);
98914 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
98915 @@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
98916 }
98917
98918
98919 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
98920 +static struct inet6_protocol ip6gre_protocol = {
98921 .handler = ip6gre_rcv,
98922 .err_handler = ip6gre_err,
98923 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
98924 @@ -1634,7 +1634,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
98925 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
98926 };
98927
98928 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
98929 +static struct rtnl_link_ops ip6gre_link_ops = {
98930 .kind = "ip6gre",
98931 .maxtype = IFLA_GRE_MAX,
98932 .policy = ip6gre_policy,
98933 @@ -1647,7 +1647,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
98934 .fill_info = ip6gre_fill_info,
98935 };
98936
98937 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
98938 +static struct rtnl_link_ops ip6gre_tap_ops = {
98939 .kind = "ip6gretap",
98940 .maxtype = IFLA_GRE_MAX,
98941 .policy = ip6gre_policy,
98942 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
98943 index 5db8d31..4a72c26 100644
98944 --- a/net/ipv6/ip6_tunnel.c
98945 +++ b/net/ipv6/ip6_tunnel.c
98946 @@ -85,7 +85,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
98947
98948 static int ip6_tnl_dev_init(struct net_device *dev);
98949 static void ip6_tnl_dev_setup(struct net_device *dev);
98950 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
98951 +static struct rtnl_link_ops ip6_link_ops;
98952
98953 static int ip6_tnl_net_id __read_mostly;
98954 struct ip6_tnl_net {
98955 @@ -1714,7 +1714,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
98956 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
98957 };
98958
98959 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
98960 +static struct rtnl_link_ops ip6_link_ops = {
98961 .kind = "ip6tnl",
98962 .maxtype = IFLA_IPTUN_MAX,
98963 .policy = ip6_tnl_policy,
98964 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
98965 index 2d19272..3a46322 100644
98966 --- a/net/ipv6/ip6_vti.c
98967 +++ b/net/ipv6/ip6_vti.c
98968 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
98969
98970 static int vti6_dev_init(struct net_device *dev);
98971 static void vti6_dev_setup(struct net_device *dev);
98972 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
98973 +static struct rtnl_link_ops vti6_link_ops;
98974
98975 static int vti6_net_id __read_mostly;
98976 struct vti6_net {
98977 @@ -901,7 +901,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
98978 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
98979 };
98980
98981 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
98982 +static struct rtnl_link_ops vti6_link_ops = {
98983 .kind = "vti6",
98984 .maxtype = IFLA_VTI_MAX,
98985 .policy = vti6_policy,
98986 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
98987 index 0a00f44..bec42b2 100644
98988 --- a/net/ipv6/ipv6_sockglue.c
98989 +++ b/net/ipv6/ipv6_sockglue.c
98990 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
98991 if (sk->sk_type != SOCK_STREAM)
98992 return -ENOPROTOOPT;
98993
98994 - msg.msg_control = optval;
98995 + msg.msg_control = (void __force_kernel *)optval;
98996 msg.msg_controllen = len;
98997 msg.msg_flags = flags;
98998
98999 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
99000 index 710238f..0fd1816 100644
99001 --- a/net/ipv6/netfilter/ip6_tables.c
99002 +++ b/net/ipv6/netfilter/ip6_tables.c
99003 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
99004 #endif
99005
99006 static int get_info(struct net *net, void __user *user,
99007 - const int *len, int compat)
99008 + int len, int compat)
99009 {
99010 char name[XT_TABLE_MAXNAMELEN];
99011 struct xt_table *t;
99012 int ret;
99013
99014 - if (*len != sizeof(struct ip6t_getinfo)) {
99015 - duprintf("length %u != %zu\n", *len,
99016 + if (len != sizeof(struct ip6t_getinfo)) {
99017 + duprintf("length %u != %zu\n", len,
99018 sizeof(struct ip6t_getinfo));
99019 return -EINVAL;
99020 }
99021 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
99022 info.size = private->size;
99023 strcpy(info.name, name);
99024
99025 - if (copy_to_user(user, &info, *len) != 0)
99026 + if (copy_to_user(user, &info, len) != 0)
99027 ret = -EFAULT;
99028 else
99029 ret = 0;
99030 @@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99031
99032 switch (cmd) {
99033 case IP6T_SO_GET_INFO:
99034 - ret = get_info(sock_net(sk), user, len, 1);
99035 + ret = get_info(sock_net(sk), user, *len, 1);
99036 break;
99037 case IP6T_SO_GET_ENTRIES:
99038 ret = compat_get_entries(sock_net(sk), user, len);
99039 @@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99040
99041 switch (cmd) {
99042 case IP6T_SO_GET_INFO:
99043 - ret = get_info(sock_net(sk), user, len, 0);
99044 + ret = get_info(sock_net(sk), user, *len, 0);
99045 break;
99046
99047 case IP6T_SO_GET_ENTRIES:
99048 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
99049 index 767ab8d..c5ec70a 100644
99050 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
99051 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
99052 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
99053
99054 static int nf_ct_frag6_sysctl_register(struct net *net)
99055 {
99056 - struct ctl_table *table;
99057 + ctl_table_no_const *table = NULL;
99058 struct ctl_table_header *hdr;
99059
99060 - table = nf_ct_frag6_sysctl_table;
99061 if (!net_eq(net, &init_net)) {
99062 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
99063 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
99064 GFP_KERNEL);
99065 if (table == NULL)
99066 goto err_alloc;
99067 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99068 table[0].data = &net->nf_frag.frags.timeout;
99069 table[1].data = &net->nf_frag.frags.low_thresh;
99070 table[2].data = &net->nf_frag.frags.high_thresh;
99071 - }
99072 -
99073 - hdr = register_net_sysctl(net, "net/netfilter", table);
99074 + hdr = register_net_sysctl(net, "net/netfilter", table);
99075 + } else
99076 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
99077 if (hdr == NULL)
99078 goto err_reg;
99079
99080 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99081 return 0;
99082
99083 err_reg:
99084 - if (!net_eq(net, &init_net))
99085 - kfree(table);
99086 + kfree(table);
99087 err_alloc:
99088 return -ENOMEM;
99089 }
99090 diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
99091 index 827f795..7e28e82 100644
99092 --- a/net/ipv6/output_core.c
99093 +++ b/net/ipv6/output_core.c
99094 @@ -9,8 +9,8 @@
99095
99096 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99097 {
99098 - static atomic_t ipv6_fragmentation_id;
99099 - int old, new;
99100 + static atomic_unchecked_t ipv6_fragmentation_id;
99101 + int id;
99102
99103 #if IS_ENABLED(CONFIG_IPV6)
99104 if (rt && !(rt->dst.flags & DST_NOPEER)) {
99105 @@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99106 }
99107 }
99108 #endif
99109 - do {
99110 - old = atomic_read(&ipv6_fragmentation_id);
99111 - new = old + 1;
99112 - if (!new)
99113 - new = 1;
99114 - } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
99115 - fhdr->identification = htonl(new);
99116 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99117 + if (!id)
99118 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99119 + fhdr->identification = htonl(id);
99120 }
99121 EXPORT_SYMBOL(ipv6_select_ident);
99122
99123 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
99124 index bda7429..469b26b 100644
99125 --- a/net/ipv6/ping.c
99126 +++ b/net/ipv6/ping.c
99127 @@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
99128 };
99129 #endif
99130
99131 +static struct pingv6_ops real_pingv6_ops = {
99132 + .ipv6_recv_error = ipv6_recv_error,
99133 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
99134 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
99135 + .icmpv6_err_convert = icmpv6_err_convert,
99136 + .ipv6_icmp_error = ipv6_icmp_error,
99137 + .ipv6_chk_addr = ipv6_chk_addr,
99138 +};
99139 +
99140 +static struct pingv6_ops dummy_pingv6_ops = {
99141 + .ipv6_recv_error = dummy_ipv6_recv_error,
99142 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
99143 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
99144 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
99145 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
99146 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
99147 +};
99148 +
99149 int __init pingv6_init(void)
99150 {
99151 #ifdef CONFIG_PROC_FS
99152 @@ -253,13 +271,7 @@ int __init pingv6_init(void)
99153 if (ret)
99154 return ret;
99155 #endif
99156 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
99157 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
99158 - pingv6_ops.ip6_datagram_recv_specific_ctl =
99159 - ip6_datagram_recv_specific_ctl;
99160 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
99161 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
99162 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
99163 + pingv6_ops = &real_pingv6_ops;
99164 return inet6_register_protosw(&pingv6_protosw);
99165 }
99166
99167 @@ -268,14 +280,9 @@ int __init pingv6_init(void)
99168 */
99169 void pingv6_exit(void)
99170 {
99171 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
99172 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
99173 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
99174 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
99175 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
99176 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
99177 #ifdef CONFIG_PROC_FS
99178 unregister_pernet_subsys(&ping_v6_net_ops);
99179 #endif
99180 + pingv6_ops = &dummy_pingv6_ops;
99181 inet6_unregister_protosw(&pingv6_protosw);
99182 }
99183 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
99184 index 1f29996..46fe0c7 100644
99185 --- a/net/ipv6/raw.c
99186 +++ b/net/ipv6/raw.c
99187 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
99188 {
99189 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
99190 skb_checksum_complete(skb)) {
99191 - atomic_inc(&sk->sk_drops);
99192 + atomic_inc_unchecked(&sk->sk_drops);
99193 kfree_skb(skb);
99194 return NET_RX_DROP;
99195 }
99196 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99197 struct raw6_sock *rp = raw6_sk(sk);
99198
99199 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
99200 - atomic_inc(&sk->sk_drops);
99201 + atomic_inc_unchecked(&sk->sk_drops);
99202 kfree_skb(skb);
99203 return NET_RX_DROP;
99204 }
99205 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99206
99207 if (inet->hdrincl) {
99208 if (skb_checksum_complete(skb)) {
99209 - atomic_inc(&sk->sk_drops);
99210 + atomic_inc_unchecked(&sk->sk_drops);
99211 kfree_skb(skb);
99212 return NET_RX_DROP;
99213 }
99214 @@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99215 if (flags & MSG_OOB)
99216 return -EOPNOTSUPP;
99217
99218 + if (addr_len)
99219 + *addr_len=sizeof(*sin6);
99220 +
99221 if (flags & MSG_ERRQUEUE)
99222 return ipv6_recv_error(sk, msg, len, addr_len);
99223
99224 @@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99225 sin6->sin6_flowinfo = 0;
99226 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
99227 IP6CB(skb)->iif);
99228 - *addr_len = sizeof(*sin6);
99229 }
99230
99231 sock_recv_ts_and_drops(msg, sk, skb);
99232 @@ -610,7 +612,7 @@ out:
99233 return err;
99234 }
99235
99236 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
99237 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
99238 struct flowi6 *fl6, struct dst_entry **dstp,
99239 unsigned int flags)
99240 {
99241 @@ -922,12 +924,15 @@ do_confirm:
99242 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
99243 char __user *optval, int optlen)
99244 {
99245 + struct icmp6_filter filter;
99246 +
99247 switch (optname) {
99248 case ICMPV6_FILTER:
99249 if (optlen > sizeof(struct icmp6_filter))
99250 optlen = sizeof(struct icmp6_filter);
99251 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
99252 + if (copy_from_user(&filter, optval, optlen))
99253 return -EFAULT;
99254 + raw6_sk(sk)->filter = filter;
99255 return 0;
99256 default:
99257 return -ENOPROTOOPT;
99258 @@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99259 char __user *optval, int __user *optlen)
99260 {
99261 int len;
99262 + struct icmp6_filter filter;
99263
99264 switch (optname) {
99265 case ICMPV6_FILTER:
99266 @@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99267 len = sizeof(struct icmp6_filter);
99268 if (put_user(len, optlen))
99269 return -EFAULT;
99270 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
99271 + filter = raw6_sk(sk)->filter;
99272 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
99273 return -EFAULT;
99274 return 0;
99275 default:
99276 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
99277 index cc85a9b..526a133 100644
99278 --- a/net/ipv6/reassembly.c
99279 +++ b/net/ipv6/reassembly.c
99280 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
99281
99282 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99283 {
99284 - struct ctl_table *table;
99285 + ctl_table_no_const *table = NULL;
99286 struct ctl_table_header *hdr;
99287
99288 - table = ip6_frags_ns_ctl_table;
99289 if (!net_eq(net, &init_net)) {
99290 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99291 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99292 if (table == NULL)
99293 goto err_alloc;
99294
99295 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99296 /* Don't export sysctls to unprivileged users */
99297 if (net->user_ns != &init_user_ns)
99298 table[0].procname = NULL;
99299 - }
99300 + hdr = register_net_sysctl(net, "net/ipv6", table);
99301 + } else
99302 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
99303
99304 - hdr = register_net_sysctl(net, "net/ipv6", table);
99305 if (hdr == NULL)
99306 goto err_reg;
99307
99308 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99309 return 0;
99310
99311 err_reg:
99312 - if (!net_eq(net, &init_net))
99313 - kfree(table);
99314 + kfree(table);
99315 err_alloc:
99316 return -ENOMEM;
99317 }
99318 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
99319 index fba54a4..73e374e 100644
99320 --- a/net/ipv6/route.c
99321 +++ b/net/ipv6/route.c
99322 @@ -2972,7 +2972,7 @@ struct ctl_table ipv6_route_table_template[] = {
99323
99324 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
99325 {
99326 - struct ctl_table *table;
99327 + ctl_table_no_const *table;
99328
99329 table = kmemdup(ipv6_route_table_template,
99330 sizeof(ipv6_route_table_template),
99331 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
99332 index b4d74c8..b4f3fbe 100644
99333 --- a/net/ipv6/sit.c
99334 +++ b/net/ipv6/sit.c
99335 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
99336 static void ipip6_dev_free(struct net_device *dev);
99337 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
99338 __be32 *v4dst);
99339 -static struct rtnl_link_ops sit_link_ops __read_mostly;
99340 +static struct rtnl_link_ops sit_link_ops;
99341
99342 static int sit_net_id __read_mostly;
99343 struct sit_net {
99344 @@ -1683,7 +1683,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
99345 unregister_netdevice_queue(dev, head);
99346 }
99347
99348 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
99349 +static struct rtnl_link_ops sit_link_ops = {
99350 .kind = "sit",
99351 .maxtype = IFLA_IPTUN_MAX,
99352 .policy = ipip6_policy,
99353 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
99354 index 7f405a1..eabef92 100644
99355 --- a/net/ipv6/sysctl_net_ipv6.c
99356 +++ b/net/ipv6/sysctl_net_ipv6.c
99357 @@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
99358
99359 static int __net_init ipv6_sysctl_net_init(struct net *net)
99360 {
99361 - struct ctl_table *ipv6_table;
99362 + ctl_table_no_const *ipv6_table;
99363 struct ctl_table *ipv6_route_table;
99364 struct ctl_table *ipv6_icmp_table;
99365 int err;
99366 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
99367 index 889079b..a04512c 100644
99368 --- a/net/ipv6/tcp_ipv6.c
99369 +++ b/net/ipv6/tcp_ipv6.c
99370 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
99371 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
99372 }
99373
99374 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99375 +extern int grsec_enable_blackhole;
99376 +#endif
99377 +
99378 static void tcp_v6_hash(struct sock *sk)
99379 {
99380 if (sk->sk_state != TCP_CLOSE) {
99381 @@ -1412,6 +1416,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
99382 return 0;
99383
99384 reset:
99385 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99386 + if (!grsec_enable_blackhole)
99387 +#endif
99388 tcp_v6_send_reset(sk, skb);
99389 discard:
99390 if (opt_skb)
99391 @@ -1496,12 +1503,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
99392 TCP_SKB_CB(skb)->sacked = 0;
99393
99394 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99395 - if (!sk)
99396 + if (!sk) {
99397 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99398 + ret = 1;
99399 +#endif
99400 goto no_tcp_socket;
99401 + }
99402
99403 process:
99404 - if (sk->sk_state == TCP_TIME_WAIT)
99405 + if (sk->sk_state == TCP_TIME_WAIT) {
99406 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99407 + ret = 2;
99408 +#endif
99409 goto do_time_wait;
99410 + }
99411
99412 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
99413 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99414 @@ -1553,6 +1568,10 @@ csum_error:
99415 bad_packet:
99416 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99417 } else {
99418 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99419 + if (!grsec_enable_blackhole || (ret == 1 &&
99420 + (skb->dev->flags & IFF_LOOPBACK)))
99421 +#endif
99422 tcp_v6_send_reset(NULL, skb);
99423 }
99424
99425 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
99426 index 1e586d9..384a9c9 100644
99427 --- a/net/ipv6/udp.c
99428 +++ b/net/ipv6/udp.c
99429 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
99430 udp_ipv6_hash_secret + net_hash_mix(net));
99431 }
99432
99433 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99434 +extern int grsec_enable_blackhole;
99435 +#endif
99436 +
99437 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
99438 {
99439 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
99440 @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99441 int is_udp4;
99442 bool slow;
99443
99444 + if (addr_len)
99445 + *addr_len = sizeof(struct sockaddr_in6);
99446 +
99447 if (flags & MSG_ERRQUEUE)
99448 return ipv6_recv_error(sk, msg, len, addr_len);
99449
99450 @@ -435,7 +442,7 @@ try_again:
99451 if (unlikely(err)) {
99452 trace_kfree_skb(skb, udpv6_recvmsg);
99453 if (!peeked) {
99454 - atomic_inc(&sk->sk_drops);
99455 + atomic_inc_unchecked(&sk->sk_drops);
99456 if (is_udp4)
99457 UDP_INC_STATS_USER(sock_net(sk),
99458 UDP_MIB_INERRORS,
99459 @@ -475,7 +482,7 @@ try_again:
99460 ipv6_iface_scope_id(&sin6->sin6_addr,
99461 IP6CB(skb)->iif);
99462 }
99463 - *addr_len = sizeof(*sin6);
99464 +
99465 }
99466
99467 if (np->rxopt.all)
99468 @@ -690,7 +697,7 @@ csum_error:
99469 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
99470 drop:
99471 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
99472 - atomic_inc(&sk->sk_drops);
99473 + atomic_inc_unchecked(&sk->sk_drops);
99474 kfree_skb(skb);
99475 return -1;
99476 }
99477 @@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
99478 if (likely(skb1 == NULL))
99479 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
99480 if (!skb1) {
99481 - atomic_inc(&sk->sk_drops);
99482 + atomic_inc_unchecked(&sk->sk_drops);
99483 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
99484 IS_UDPLITE(sk));
99485 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99486 @@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
99487 goto csum_error;
99488
99489 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
99490 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99491 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
99492 +#endif
99493 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
99494
99495 kfree_skb(skb);
99496 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
99497 index 5f8e128..865d38e 100644
99498 --- a/net/ipv6/xfrm6_policy.c
99499 +++ b/net/ipv6/xfrm6_policy.c
99500 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
99501 }
99502 }
99503
99504 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
99505 +static int xfrm6_garbage_collect(struct dst_ops *ops)
99506 {
99507 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
99508
99509 - xfrm6_policy_afinfo.garbage_collect(net);
99510 + xfrm_garbage_collect_deferred(net);
99511 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
99512 }
99513
99514 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
99515
99516 static int __net_init xfrm6_net_init(struct net *net)
99517 {
99518 - struct ctl_table *table;
99519 + ctl_table_no_const *table = NULL;
99520 struct ctl_table_header *hdr;
99521
99522 - table = xfrm6_policy_table;
99523 if (!net_eq(net, &init_net)) {
99524 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99525 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99526 if (!table)
99527 goto err_alloc;
99528
99529 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
99530 - }
99531 + hdr = register_net_sysctl(net, "net/ipv6", table);
99532 + } else
99533 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
99534
99535 - hdr = register_net_sysctl(net, "net/ipv6", table);
99536 if (!hdr)
99537 goto err_reg;
99538
99539 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
99540 return 0;
99541
99542 err_reg:
99543 - if (!net_eq(net, &init_net))
99544 - kfree(table);
99545 + kfree(table);
99546 err_alloc:
99547 return -ENOMEM;
99548 }
99549 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
99550 index 2ba8b97..6d33010 100644
99551 --- a/net/irda/ircomm/ircomm_tty.c
99552 +++ b/net/irda/ircomm/ircomm_tty.c
99553 @@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99554 add_wait_queue(&port->open_wait, &wait);
99555
99556 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
99557 - __FILE__, __LINE__, tty->driver->name, port->count);
99558 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99559
99560 spin_lock_irqsave(&port->lock, flags);
99561 if (!tty_hung_up_p(filp))
99562 - port->count--;
99563 + atomic_dec(&port->count);
99564 port->blocked_open++;
99565 spin_unlock_irqrestore(&port->lock, flags);
99566
99567 @@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99568 }
99569
99570 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
99571 - __FILE__, __LINE__, tty->driver->name, port->count);
99572 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99573
99574 schedule();
99575 }
99576 @@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99577
99578 spin_lock_irqsave(&port->lock, flags);
99579 if (!tty_hung_up_p(filp))
99580 - port->count++;
99581 + atomic_inc(&port->count);
99582 port->blocked_open--;
99583 spin_unlock_irqrestore(&port->lock, flags);
99584
99585 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
99586 - __FILE__, __LINE__, tty->driver->name, port->count);
99587 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99588
99589 if (!retval)
99590 port->flags |= ASYNC_NORMAL_ACTIVE;
99591 @@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
99592
99593 /* ++ is not atomic, so this should be protected - Jean II */
99594 spin_lock_irqsave(&self->port.lock, flags);
99595 - self->port.count++;
99596 + atomic_inc(&self->port.count);
99597 spin_unlock_irqrestore(&self->port.lock, flags);
99598 tty_port_tty_set(&self->port, tty);
99599
99600 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
99601 - self->line, self->port.count);
99602 + self->line, atomic_read(&self->port.count));
99603
99604 /* Not really used by us, but lets do it anyway */
99605 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
99606 @@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
99607 tty_kref_put(port->tty);
99608 }
99609 port->tty = NULL;
99610 - port->count = 0;
99611 + atomic_set(&port->count, 0);
99612 spin_unlock_irqrestore(&port->lock, flags);
99613
99614 wake_up_interruptible(&port->open_wait);
99615 @@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
99616 seq_putc(m, '\n');
99617
99618 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
99619 - seq_printf(m, "Open count: %d\n", self->port.count);
99620 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
99621 seq_printf(m, "Max data size: %d\n", self->max_data_size);
99622 seq_printf(m, "Max header size: %d\n", self->max_header_size);
99623
99624 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
99625 index c4b7218..3e83259 100644
99626 --- a/net/iucv/af_iucv.c
99627 +++ b/net/iucv/af_iucv.c
99628 @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
99629
99630 write_lock_bh(&iucv_sk_list.lock);
99631
99632 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
99633 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99634 while (__iucv_get_sock_by_name(name)) {
99635 sprintf(name, "%08x",
99636 - atomic_inc_return(&iucv_sk_list.autobind_name));
99637 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99638 }
99639
99640 write_unlock_bh(&iucv_sk_list.lock);
99641 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
99642 index cd5b8ec..f205e6b 100644
99643 --- a/net/iucv/iucv.c
99644 +++ b/net/iucv/iucv.c
99645 @@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
99646 return NOTIFY_OK;
99647 }
99648
99649 -static struct notifier_block __refdata iucv_cpu_notifier = {
99650 +static struct notifier_block iucv_cpu_notifier = {
99651 .notifier_call = iucv_cpu_notify,
99652 };
99653
99654 diff --git a/net/key/af_key.c b/net/key/af_key.c
99655 index 7932697..a13d158 100644
99656 --- a/net/key/af_key.c
99657 +++ b/net/key/af_key.c
99658 @@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
99659 static u32 get_acqseq(void)
99660 {
99661 u32 res;
99662 - static atomic_t acqseq;
99663 + static atomic_unchecked_t acqseq;
99664
99665 do {
99666 - res = atomic_inc_return(&acqseq);
99667 + res = atomic_inc_return_unchecked(&acqseq);
99668 } while (!res);
99669 return res;
99670 }
99671 diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
99672 index 0b44d85..1a7f88b 100644
99673 --- a/net/l2tp/l2tp_ip.c
99674 +++ b/net/l2tp/l2tp_ip.c
99675 @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99676 if (flags & MSG_OOB)
99677 goto out;
99678
99679 + if (addr_len)
99680 + *addr_len = sizeof(*sin);
99681 +
99682 skb = skb_recv_datagram(sk, flags, noblock, &err);
99683 if (!skb)
99684 goto out;
99685 @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99686 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99687 sin->sin_port = 0;
99688 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99689 - *addr_len = sizeof(*sin);
99690 }
99691 if (inet->cmsg_flags)
99692 ip_cmsg_recv(msg, skb);
99693 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
99694 index 453e974..b3a43a5 100644
99695 --- a/net/mac80211/cfg.c
99696 +++ b/net/mac80211/cfg.c
99697 @@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
99698 ret = ieee80211_vif_use_channel(sdata, chandef,
99699 IEEE80211_CHANCTX_EXCLUSIVE);
99700 }
99701 - } else if (local->open_count == local->monitors) {
99702 + } else if (local_read(&local->open_count) == local->monitors) {
99703 local->_oper_chandef = *chandef;
99704 ieee80211_hw_config(local, 0);
99705 }
99706 @@ -3356,7 +3356,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
99707 else
99708 local->probe_req_reg--;
99709
99710 - if (!local->open_count)
99711 + if (!local_read(&local->open_count))
99712 break;
99713
99714 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
99715 @@ -3819,8 +3819,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
99716 if (chanctx_conf) {
99717 *chandef = chanctx_conf->def;
99718 ret = 0;
99719 - } else if (local->open_count > 0 &&
99720 - local->open_count == local->monitors &&
99721 + } else if (local_read(&local->open_count) > 0 &&
99722 + local_read(&local->open_count) == local->monitors &&
99723 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
99724 if (local->use_chanctx)
99725 *chandef = local->monitor_chandef;
99726 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
99727 index 5e44e317..3d404a6 100644
99728 --- a/net/mac80211/ieee80211_i.h
99729 +++ b/net/mac80211/ieee80211_i.h
99730 @@ -28,6 +28,7 @@
99731 #include <net/ieee80211_radiotap.h>
99732 #include <net/cfg80211.h>
99733 #include <net/mac80211.h>
99734 +#include <asm/local.h>
99735 #include "key.h"
99736 #include "sta_info.h"
99737 #include "debug.h"
99738 @@ -994,7 +995,7 @@ struct ieee80211_local {
99739 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
99740 spinlock_t queue_stop_reason_lock;
99741
99742 - int open_count;
99743 + local_t open_count;
99744 int monitors, cooked_mntrs;
99745 /* number of interfaces with corresponding FIF_ flags */
99746 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
99747 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
99748 index ce1c443..6cd39e1 100644
99749 --- a/net/mac80211/iface.c
99750 +++ b/net/mac80211/iface.c
99751 @@ -529,7 +529,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99752 break;
99753 }
99754
99755 - if (local->open_count == 0) {
99756 + if (local_read(&local->open_count) == 0) {
99757 res = drv_start(local);
99758 if (res)
99759 goto err_del_bss;
99760 @@ -576,7 +576,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99761 res = drv_add_interface(local, sdata);
99762 if (res)
99763 goto err_stop;
99764 - } else if (local->monitors == 0 && local->open_count == 0) {
99765 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
99766 res = ieee80211_add_virtual_monitor(local);
99767 if (res)
99768 goto err_stop;
99769 @@ -685,7 +685,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99770 atomic_inc(&local->iff_promiscs);
99771
99772 if (coming_up)
99773 - local->open_count++;
99774 + local_inc(&local->open_count);
99775
99776 if (hw_reconf_flags)
99777 ieee80211_hw_config(local, hw_reconf_flags);
99778 @@ -723,7 +723,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99779 err_del_interface:
99780 drv_remove_interface(local, sdata);
99781 err_stop:
99782 - if (!local->open_count)
99783 + if (!local_read(&local->open_count))
99784 drv_stop(local);
99785 err_del_bss:
99786 sdata->bss = NULL;
99787 @@ -874,7 +874,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99788 }
99789
99790 if (going_down)
99791 - local->open_count--;
99792 + local_dec(&local->open_count);
99793
99794 switch (sdata->vif.type) {
99795 case NL80211_IFTYPE_AP_VLAN:
99796 @@ -933,7 +933,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99797 }
99798 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
99799
99800 - if (local->open_count == 0)
99801 + if (local_read(&local->open_count) == 0)
99802 ieee80211_clear_tx_pending(local);
99803
99804 /*
99805 @@ -973,7 +973,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99806
99807 ieee80211_recalc_ps(local, -1);
99808
99809 - if (local->open_count == 0) {
99810 + if (local_read(&local->open_count) == 0) {
99811 ieee80211_stop_device(local);
99812
99813 /* no reconfiguring after stop! */
99814 @@ -984,7 +984,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99815 ieee80211_configure_filter(local);
99816 ieee80211_hw_config(local, hw_reconf_flags);
99817
99818 - if (local->monitors == local->open_count)
99819 + if (local->monitors == local_read(&local->open_count))
99820 ieee80211_add_virtual_monitor(local);
99821 }
99822
99823 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
99824 index d767cfb..b4cd07d 100644
99825 --- a/net/mac80211/main.c
99826 +++ b/net/mac80211/main.c
99827 @@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
99828 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
99829 IEEE80211_CONF_CHANGE_POWER);
99830
99831 - if (changed && local->open_count) {
99832 + if (changed && local_read(&local->open_count)) {
99833 ret = drv_config(local, changed);
99834 /*
99835 * Goal:
99836 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
99837 index af64fb8..366e371 100644
99838 --- a/net/mac80211/pm.c
99839 +++ b/net/mac80211/pm.c
99840 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99841 struct ieee80211_sub_if_data *sdata;
99842 struct sta_info *sta;
99843
99844 - if (!local->open_count)
99845 + if (!local_read(&local->open_count))
99846 goto suspend;
99847
99848 ieee80211_scan_cancel(local);
99849 @@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99850 cancel_work_sync(&local->dynamic_ps_enable_work);
99851 del_timer_sync(&local->dynamic_ps_timer);
99852
99853 - local->wowlan = wowlan && local->open_count;
99854 + local->wowlan = wowlan && local_read(&local->open_count);
99855 if (local->wowlan) {
99856 int err = drv_suspend(local, wowlan);
99857 if (err < 0) {
99858 @@ -115,7 +115,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99859 WARN_ON(!list_empty(&local->chanctx_list));
99860
99861 /* stop hardware - this must stop RX */
99862 - if (local->open_count)
99863 + if (local_read(&local->open_count))
99864 ieee80211_stop_device(local);
99865
99866 suspend:
99867 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
99868 index 22b223f..ab70070 100644
99869 --- a/net/mac80211/rate.c
99870 +++ b/net/mac80211/rate.c
99871 @@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
99872
99873 ASSERT_RTNL();
99874
99875 - if (local->open_count)
99876 + if (local_read(&local->open_count))
99877 return -EBUSY;
99878
99879 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
99880 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
99881 index 6ff1346..936ca9a 100644
99882 --- a/net/mac80211/rc80211_pid_debugfs.c
99883 +++ b/net/mac80211/rc80211_pid_debugfs.c
99884 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
99885
99886 spin_unlock_irqrestore(&events->lock, status);
99887
99888 - if (copy_to_user(buf, pb, p))
99889 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
99890 return -EFAULT;
99891
99892 return p;
99893 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
99894 index b8700d4..89086d5 100644
99895 --- a/net/mac80211/util.c
99896 +++ b/net/mac80211/util.c
99897 @@ -1483,7 +1483,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
99898 }
99899 #endif
99900 /* everything else happens only if HW was up & running */
99901 - if (!local->open_count)
99902 + if (!local_read(&local->open_count))
99903 goto wake_up;
99904
99905 /*
99906 @@ -1708,7 +1708,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
99907 local->in_reconfig = false;
99908 barrier();
99909
99910 - if (local->monitors == local->open_count && local->monitors > 0)
99911 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
99912 ieee80211_add_virtual_monitor(local);
99913
99914 /*
99915 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
99916 index e9410d1..77b6378 100644
99917 --- a/net/netfilter/Kconfig
99918 +++ b/net/netfilter/Kconfig
99919 @@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
99920
99921 To compile it as a module, choose M here. If unsure, say N.
99922
99923 +config NETFILTER_XT_MATCH_GRADM
99924 + tristate '"gradm" match support'
99925 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
99926 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
99927 + ---help---
99928 + The gradm match allows to match on grsecurity RBAC being enabled.
99929 + It is useful when iptables rules are applied early on bootup to
99930 + prevent connections to the machine (except from a trusted host)
99931 + while the RBAC system is disabled.
99932 +
99933 config NETFILTER_XT_MATCH_HASHLIMIT
99934 tristate '"hashlimit" match support'
99935 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
99936 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
99937 index bffdad7..f9317d1 100644
99938 --- a/net/netfilter/Makefile
99939 +++ b/net/netfilter/Makefile
99940 @@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
99941 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
99942 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
99943 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
99944 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
99945 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
99946 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
99947 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
99948 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
99949 index de770ec..3fc49d2 100644
99950 --- a/net/netfilter/ipset/ip_set_core.c
99951 +++ b/net/netfilter/ipset/ip_set_core.c
99952 @@ -1922,7 +1922,7 @@ done:
99953 return ret;
99954 }
99955
99956 -static struct nf_sockopt_ops so_set __read_mostly = {
99957 +static struct nf_sockopt_ops so_set = {
99958 .pf = PF_INET,
99959 .get_optmin = SO_IP_SET,
99960 .get_optmax = SO_IP_SET + 1,
99961 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
99962 index a8eb0a8..86f2de4 100644
99963 --- a/net/netfilter/ipvs/ip_vs_conn.c
99964 +++ b/net/netfilter/ipvs/ip_vs_conn.c
99965 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
99966 /* Increase the refcnt counter of the dest */
99967 ip_vs_dest_hold(dest);
99968
99969 - conn_flags = atomic_read(&dest->conn_flags);
99970 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
99971 if (cp->protocol != IPPROTO_UDP)
99972 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
99973 flags = cp->flags;
99974 @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
99975
99976 cp->control = NULL;
99977 atomic_set(&cp->n_control, 0);
99978 - atomic_set(&cp->in_pkts, 0);
99979 + atomic_set_unchecked(&cp->in_pkts, 0);
99980
99981 cp->packet_xmit = NULL;
99982 cp->app = NULL;
99983 @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
99984
99985 /* Don't drop the entry if its number of incoming packets is not
99986 located in [0, 8] */
99987 - i = atomic_read(&cp->in_pkts);
99988 + i = atomic_read_unchecked(&cp->in_pkts);
99989 if (i > 8 || i < 0) return 0;
99990
99991 if (!todrop_rate[i]) return 0;
99992 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
99993 index 4f26ee4..6a9d7c3 100644
99994 --- a/net/netfilter/ipvs/ip_vs_core.c
99995 +++ b/net/netfilter/ipvs/ip_vs_core.c
99996 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
99997 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
99998 /* do not touch skb anymore */
99999
100000 - atomic_inc(&cp->in_pkts);
100001 + atomic_inc_unchecked(&cp->in_pkts);
100002 ip_vs_conn_put(cp);
100003 return ret;
100004 }
100005 @@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
100006 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
100007 pkts = sysctl_sync_threshold(ipvs);
100008 else
100009 - pkts = atomic_add_return(1, &cp->in_pkts);
100010 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100011
100012 if (ipvs->sync_state & IP_VS_STATE_MASTER)
100013 ip_vs_sync_conn(net, cp, pkts);
100014 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
100015 index 35be035..50f8834 100644
100016 --- a/net/netfilter/ipvs/ip_vs_ctl.c
100017 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
100018 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
100019 */
100020 ip_vs_rs_hash(ipvs, dest);
100021 }
100022 - atomic_set(&dest->conn_flags, conn_flags);
100023 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
100024
100025 /* bind the service */
100026 old_svc = rcu_dereference_protected(dest->svc, 1);
100027 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
100028 * align with netns init in ip_vs_control_net_init()
100029 */
100030
100031 -static struct ctl_table vs_vars[] = {
100032 +static ctl_table_no_const vs_vars[] __read_only = {
100033 {
100034 .procname = "amemthresh",
100035 .maxlen = sizeof(int),
100036 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100037 " %-7s %-6d %-10d %-10d\n",
100038 &dest->addr.in6,
100039 ntohs(dest->port),
100040 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100041 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100042 atomic_read(&dest->weight),
100043 atomic_read(&dest->activeconns),
100044 atomic_read(&dest->inactconns));
100045 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100046 "%-7s %-6d %-10d %-10d\n",
100047 ntohl(dest->addr.ip),
100048 ntohs(dest->port),
100049 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100050 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100051 atomic_read(&dest->weight),
100052 atomic_read(&dest->activeconns),
100053 atomic_read(&dest->inactconns));
100054 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
100055
100056 entry.addr = dest->addr.ip;
100057 entry.port = dest->port;
100058 - entry.conn_flags = atomic_read(&dest->conn_flags);
100059 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
100060 entry.weight = atomic_read(&dest->weight);
100061 entry.u_threshold = dest->u_threshold;
100062 entry.l_threshold = dest->l_threshold;
100063 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
100064 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
100065 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
100066 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
100067 - (atomic_read(&dest->conn_flags) &
100068 + (atomic_read_unchecked(&dest->conn_flags) &
100069 IP_VS_CONN_F_FWD_MASK)) ||
100070 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
100071 atomic_read(&dest->weight)) ||
100072 @@ -3580,7 +3580,7 @@ out:
100073 }
100074
100075
100076 -static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
100077 +static const struct genl_ops ip_vs_genl_ops[] = {
100078 {
100079 .cmd = IPVS_CMD_NEW_SERVICE,
100080 .flags = GENL_ADMIN_PERM,
100081 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
100082 {
100083 int idx;
100084 struct netns_ipvs *ipvs = net_ipvs(net);
100085 - struct ctl_table *tbl;
100086 + ctl_table_no_const *tbl;
100087
100088 atomic_set(&ipvs->dropentry, 0);
100089 spin_lock_init(&ipvs->dropentry_lock);
100090 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
100091 index ca056a3..9cf01ef 100644
100092 --- a/net/netfilter/ipvs/ip_vs_lblc.c
100093 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
100094 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
100095 * IPVS LBLC sysctl table
100096 */
100097 #ifdef CONFIG_SYSCTL
100098 -static struct ctl_table vs_vars_table[] = {
100099 +static ctl_table_no_const vs_vars_table[] __read_only = {
100100 {
100101 .procname = "lblc_expiration",
100102 .data = NULL,
100103 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
100104 index 3f21a2f..a112e85 100644
100105 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
100106 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
100107 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
100108 * IPVS LBLCR sysctl table
100109 */
100110
100111 -static struct ctl_table vs_vars_table[] = {
100112 +static ctl_table_no_const vs_vars_table[] __read_only = {
100113 {
100114 .procname = "lblcr_expiration",
100115 .data = NULL,
100116 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
100117 index db80126..ef7110e 100644
100118 --- a/net/netfilter/ipvs/ip_vs_sync.c
100119 +++ b/net/netfilter/ipvs/ip_vs_sync.c
100120 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
100121 cp = cp->control;
100122 if (cp) {
100123 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100124 - pkts = atomic_add_return(1, &cp->in_pkts);
100125 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100126 else
100127 pkts = sysctl_sync_threshold(ipvs);
100128 ip_vs_sync_conn(net, cp->control, pkts);
100129 @@ -771,7 +771,7 @@ control:
100130 if (!cp)
100131 return;
100132 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100133 - pkts = atomic_add_return(1, &cp->in_pkts);
100134 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100135 else
100136 pkts = sysctl_sync_threshold(ipvs);
100137 goto sloop;
100138 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
100139
100140 if (opt)
100141 memcpy(&cp->in_seq, opt, sizeof(*opt));
100142 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100143 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100144 cp->state = state;
100145 cp->old_state = cp->state;
100146 /*
100147 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
100148 index c47444e..b0961c6 100644
100149 --- a/net/netfilter/ipvs/ip_vs_xmit.c
100150 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
100151 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
100152 else
100153 rc = NF_ACCEPT;
100154 /* do not touch skb anymore */
100155 - atomic_inc(&cp->in_pkts);
100156 + atomic_inc_unchecked(&cp->in_pkts);
100157 goto out;
100158 }
100159
100160 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
100161 else
100162 rc = NF_ACCEPT;
100163 /* do not touch skb anymore */
100164 - atomic_inc(&cp->in_pkts);
100165 + atomic_inc_unchecked(&cp->in_pkts);
100166 goto out;
100167 }
100168
100169 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
100170 index a4b5e2a..13b1de3 100644
100171 --- a/net/netfilter/nf_conntrack_acct.c
100172 +++ b/net/netfilter/nf_conntrack_acct.c
100173 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
100174 #ifdef CONFIG_SYSCTL
100175 static int nf_conntrack_acct_init_sysctl(struct net *net)
100176 {
100177 - struct ctl_table *table;
100178 + ctl_table_no_const *table;
100179
100180 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
100181 GFP_KERNEL);
100182 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
100183 index 356bef5..99932cb 100644
100184 --- a/net/netfilter/nf_conntrack_core.c
100185 +++ b/net/netfilter/nf_conntrack_core.c
100186 @@ -1627,6 +1627,10 @@ void nf_conntrack_init_end(void)
100187 #define DYING_NULLS_VAL ((1<<30)+1)
100188 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
100189
100190 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100191 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
100192 +#endif
100193 +
100194 int nf_conntrack_init_net(struct net *net)
100195 {
100196 int ret;
100197 @@ -1641,7 +1645,11 @@ int nf_conntrack_init_net(struct net *net)
100198 goto err_stat;
100199 }
100200
100201 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100202 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
100203 +#else
100204 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
100205 +#endif
100206 if (!net->ct.slabname) {
100207 ret = -ENOMEM;
100208 goto err_slabname;
100209 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
100210 index 1df1761..ce8b88a 100644
100211 --- a/net/netfilter/nf_conntrack_ecache.c
100212 +++ b/net/netfilter/nf_conntrack_ecache.c
100213 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
100214 #ifdef CONFIG_SYSCTL
100215 static int nf_conntrack_event_init_sysctl(struct net *net)
100216 {
100217 - struct ctl_table *table;
100218 + ctl_table_no_const *table;
100219
100220 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
100221 GFP_KERNEL);
100222 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
100223 index 974a2a4..52cc6ff 100644
100224 --- a/net/netfilter/nf_conntrack_helper.c
100225 +++ b/net/netfilter/nf_conntrack_helper.c
100226 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
100227
100228 static int nf_conntrack_helper_init_sysctl(struct net *net)
100229 {
100230 - struct ctl_table *table;
100231 + ctl_table_no_const *table;
100232
100233 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
100234 GFP_KERNEL);
100235 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
100236 index b65d586..beec902 100644
100237 --- a/net/netfilter/nf_conntrack_proto.c
100238 +++ b/net/netfilter/nf_conntrack_proto.c
100239 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
100240
100241 static void
100242 nf_ct_unregister_sysctl(struct ctl_table_header **header,
100243 - struct ctl_table **table,
100244 + ctl_table_no_const **table,
100245 unsigned int users)
100246 {
100247 if (users > 0)
100248 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
100249 index f641751..d3c5b51 100644
100250 --- a/net/netfilter/nf_conntrack_standalone.c
100251 +++ b/net/netfilter/nf_conntrack_standalone.c
100252 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
100253
100254 static int nf_conntrack_standalone_init_sysctl(struct net *net)
100255 {
100256 - struct ctl_table *table;
100257 + ctl_table_no_const *table;
100258
100259 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
100260 GFP_KERNEL);
100261 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
100262 index 7a394df..bd91a8a 100644
100263 --- a/net/netfilter/nf_conntrack_timestamp.c
100264 +++ b/net/netfilter/nf_conntrack_timestamp.c
100265 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
100266 #ifdef CONFIG_SYSCTL
100267 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
100268 {
100269 - struct ctl_table *table;
100270 + ctl_table_no_const *table;
100271
100272 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
100273 GFP_KERNEL);
100274 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
100275 index 85296d4..8becdec 100644
100276 --- a/net/netfilter/nf_log.c
100277 +++ b/net/netfilter/nf_log.c
100278 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
100279
100280 #ifdef CONFIG_SYSCTL
100281 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
100282 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
100283 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
100284
100285 static int nf_log_proc_dostring(struct ctl_table *table, int write,
100286 void __user *buffer, size_t *lenp, loff_t *ppos)
100287 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
100288 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
100289 mutex_unlock(&nf_log_mutex);
100290 } else {
100291 + ctl_table_no_const nf_log_table = *table;
100292 +
100293 mutex_lock(&nf_log_mutex);
100294 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
100295 lockdep_is_held(&nf_log_mutex));
100296 if (!logger)
100297 - table->data = "NONE";
100298 + nf_log_table.data = "NONE";
100299 else
100300 - table->data = logger->name;
100301 - r = proc_dostring(table, write, buffer, lenp, ppos);
100302 + nf_log_table.data = logger->name;
100303 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
100304 mutex_unlock(&nf_log_mutex);
100305 }
100306
100307 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
100308 index f042ae5..30ea486 100644
100309 --- a/net/netfilter/nf_sockopt.c
100310 +++ b/net/netfilter/nf_sockopt.c
100311 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
100312 }
100313 }
100314
100315 - list_add(&reg->list, &nf_sockopts);
100316 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
100317 out:
100318 mutex_unlock(&nf_sockopt_mutex);
100319 return ret;
100320 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
100321 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
100322 {
100323 mutex_lock(&nf_sockopt_mutex);
100324 - list_del(&reg->list);
100325 + pax_list_del((struct list_head *)&reg->list);
100326 mutex_unlock(&nf_sockopt_mutex);
100327 }
100328 EXPORT_SYMBOL(nf_unregister_sockopt);
100329 diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
100330 index adce01e..8d52d50 100644
100331 --- a/net/netfilter/nf_tables_api.c
100332 +++ b/net/netfilter/nf_tables_api.c
100333 @@ -152,8 +152,8 @@ nf_tables_chain_type_lookup(const struct nft_af_info *afi,
100334 #ifdef CONFIG_MODULES
100335 if (autoload) {
100336 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
100337 - request_module("nft-chain-%u-%*.s", afi->family,
100338 - nla_len(nla)-1, (const char *)nla_data(nla));
100339 + request_module("nft-chain-%u-%.*s", afi->family,
100340 + nla_len(nla), (const char *)nla_data(nla));
100341 nfnl_lock(NFNL_SUBSYS_NFTABLES);
100342 type = __nf_tables_chain_type_lookup(afi->family, nla);
100343 if (type != NULL)
100344 @@ -1934,7 +1934,8 @@ static const struct nft_set_ops *nft_select_set_ops(const struct nlattr * const
100345
100346 static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
100347 [NFTA_SET_TABLE] = { .type = NLA_STRING },
100348 - [NFTA_SET_NAME] = { .type = NLA_STRING },
100349 + [NFTA_SET_NAME] = { .type = NLA_STRING,
100350 + .len = IFNAMSIZ - 1 },
100351 [NFTA_SET_FLAGS] = { .type = NLA_U32 },
100352 [NFTA_SET_KEY_TYPE] = { .type = NLA_U32 },
100353 [NFTA_SET_KEY_LEN] = { .type = NLA_U32 },
100354 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
100355 index a155d19..726b0f2 100644
100356 --- a/net/netfilter/nfnetlink_log.c
100357 +++ b/net/netfilter/nfnetlink_log.c
100358 @@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
100359 struct nfnl_log_net {
100360 spinlock_t instances_lock;
100361 struct hlist_head instance_table[INSTANCE_BUCKETS];
100362 - atomic_t global_seq;
100363 + atomic_unchecked_t global_seq;
100364 };
100365
100366 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
100367 @@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
100368 /* global sequence number */
100369 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
100370 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
100371 - htonl(atomic_inc_return(&log->global_seq))))
100372 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
100373 goto nla_put_failure;
100374
100375 if (data_len) {
100376 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
100377 index 82cb823..5685dd5 100644
100378 --- a/net/netfilter/nft_compat.c
100379 +++ b/net/netfilter/nft_compat.c
100380 @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
100381 /* We want to reuse existing compat_to_user */
100382 old_fs = get_fs();
100383 set_fs(KERNEL_DS);
100384 - t->compat_to_user(out, in);
100385 + t->compat_to_user((void __force_user *)out, in);
100386 set_fs(old_fs);
100387 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
100388 kfree(out);
100389 @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
100390 /* We want to reuse existing compat_to_user */
100391 old_fs = get_fs();
100392 set_fs(KERNEL_DS);
100393 - m->compat_to_user(out, in);
100394 + m->compat_to_user((void __force_user *)out, in);
100395 set_fs(old_fs);
100396 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
100397 kfree(out);
100398 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
100399 new file mode 100644
100400 index 0000000..c566332
100401 --- /dev/null
100402 +++ b/net/netfilter/xt_gradm.c
100403 @@ -0,0 +1,51 @@
100404 +/*
100405 + * gradm match for netfilter
100406 + * Copyright © Zbigniew Krzystolik, 2010
100407 + *
100408 + * This program is free software; you can redistribute it and/or modify
100409 + * it under the terms of the GNU General Public License; either version
100410 + * 2 or 3 as published by the Free Software Foundation.
100411 + */
100412 +#include <linux/module.h>
100413 +#include <linux/moduleparam.h>
100414 +#include <linux/skbuff.h>
100415 +#include <linux/netfilter/x_tables.h>
100416 +#include <linux/grsecurity.h>
100417 +#include <linux/netfilter/xt_gradm.h>
100418 +
100419 +static bool
100420 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
100421 +{
100422 + const struct xt_gradm_mtinfo *info = par->matchinfo;
100423 + bool retval = false;
100424 + if (gr_acl_is_enabled())
100425 + retval = true;
100426 + return retval ^ info->invflags;
100427 +}
100428 +
100429 +static struct xt_match gradm_mt_reg __read_mostly = {
100430 + .name = "gradm",
100431 + .revision = 0,
100432 + .family = NFPROTO_UNSPEC,
100433 + .match = gradm_mt,
100434 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
100435 + .me = THIS_MODULE,
100436 +};
100437 +
100438 +static int __init gradm_mt_init(void)
100439 +{
100440 + return xt_register_match(&gradm_mt_reg);
100441 +}
100442 +
100443 +static void __exit gradm_mt_exit(void)
100444 +{
100445 + xt_unregister_match(&gradm_mt_reg);
100446 +}
100447 +
100448 +module_init(gradm_mt_init);
100449 +module_exit(gradm_mt_exit);
100450 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
100451 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
100452 +MODULE_LICENSE("GPL");
100453 +MODULE_ALIAS("ipt_gradm");
100454 +MODULE_ALIAS("ip6t_gradm");
100455 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
100456 index 11de55e..f25e448 100644
100457 --- a/net/netfilter/xt_statistic.c
100458 +++ b/net/netfilter/xt_statistic.c
100459 @@ -19,7 +19,7 @@
100460 #include <linux/module.h>
100461
100462 struct xt_statistic_priv {
100463 - atomic_t count;
100464 + atomic_unchecked_t count;
100465 } ____cacheline_aligned_in_smp;
100466
100467 MODULE_LICENSE("GPL");
100468 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
100469 break;
100470 case XT_STATISTIC_MODE_NTH:
100471 do {
100472 - oval = atomic_read(&info->master->count);
100473 + oval = atomic_read_unchecked(&info->master->count);
100474 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
100475 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
100476 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
100477 if (nval == 0)
100478 ret = !ret;
100479 break;
100480 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
100481 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
100482 if (info->master == NULL)
100483 return -ENOMEM;
100484 - atomic_set(&info->master->count, info->u.nth.count);
100485 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
100486
100487 return 0;
100488 }
100489 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
100490 index 04748ab6..ca8f86f 100644
100491 --- a/net/netlink/af_netlink.c
100492 +++ b/net/netlink/af_netlink.c
100493 @@ -257,7 +257,7 @@ static void netlink_overrun(struct sock *sk)
100494 sk->sk_error_report(sk);
100495 }
100496 }
100497 - atomic_inc(&sk->sk_drops);
100498 + atomic_inc_unchecked(&sk->sk_drops);
100499 }
100500
100501 static void netlink_rcv_wake(struct sock *sk)
100502 @@ -2933,7 +2933,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
100503 sk_wmem_alloc_get(s),
100504 nlk->cb_running,
100505 atomic_read(&s->sk_refcnt),
100506 - atomic_read(&s->sk_drops),
100507 + atomic_read_unchecked(&s->sk_drops),
100508 sock_i_ino(s)
100509 );
100510
100511 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
100512 index b74aa07..d41926e 100644
100513 --- a/net/netrom/af_netrom.c
100514 +++ b/net/netrom/af_netrom.c
100515 @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
100516 *uaddr_len = sizeof(struct full_sockaddr_ax25);
100517 } else {
100518 sax->fsa_ax25.sax25_family = AF_NETROM;
100519 - sax->fsa_ax25.sax25_ndigis = 0;
100520 sax->fsa_ax25.sax25_call = nr->source_addr;
100521 *uaddr_len = sizeof(struct sockaddr_ax25);
100522 }
100523 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
100524 index 48a6a93..0b0496e 100644
100525 --- a/net/packet/af_packet.c
100526 +++ b/net/packet/af_packet.c
100527 @@ -1845,7 +1845,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
100528
100529 spin_lock(&sk->sk_receive_queue.lock);
100530 po->stats.stats1.tp_packets++;
100531 - skb->dropcount = atomic_read(&sk->sk_drops);
100532 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
100533 __skb_queue_tail(&sk->sk_receive_queue, skb);
100534 spin_unlock(&sk->sk_receive_queue.lock);
100535 sk->sk_data_ready(sk, skb->len);
100536 @@ -1854,7 +1854,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
100537 drop_n_acct:
100538 spin_lock(&sk->sk_receive_queue.lock);
100539 po->stats.stats1.tp_drops++;
100540 - atomic_inc(&sk->sk_drops);
100541 + atomic_inc_unchecked(&sk->sk_drops);
100542 spin_unlock(&sk->sk_receive_queue.lock);
100543
100544 drop_n_restore:
100545 @@ -3449,7 +3449,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
100546 case PACKET_HDRLEN:
100547 if (len > sizeof(int))
100548 len = sizeof(int);
100549 - if (copy_from_user(&val, optval, len))
100550 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
100551 return -EFAULT;
100552 switch (val) {
100553 case TPACKET_V1:
100554 @@ -3495,7 +3495,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
100555 len = lv;
100556 if (put_user(len, optlen))
100557 return -EFAULT;
100558 - if (copy_to_user(optval, data, len))
100559 + if (len > sizeof(st) || copy_to_user(optval, data, len))
100560 return -EFAULT;
100561 return 0;
100562 }
100563 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
100564 index e774117..900b8b7 100644
100565 --- a/net/phonet/pep.c
100566 +++ b/net/phonet/pep.c
100567 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
100568
100569 case PNS_PEP_CTRL_REQ:
100570 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
100571 - atomic_inc(&sk->sk_drops);
100572 + atomic_inc_unchecked(&sk->sk_drops);
100573 break;
100574 }
100575 __skb_pull(skb, 4);
100576 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
100577 }
100578
100579 if (pn->rx_credits == 0) {
100580 - atomic_inc(&sk->sk_drops);
100581 + atomic_inc_unchecked(&sk->sk_drops);
100582 err = -ENOBUFS;
100583 break;
100584 }
100585 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
100586 }
100587
100588 if (pn->rx_credits == 0) {
100589 - atomic_inc(&sk->sk_drops);
100590 + atomic_inc_unchecked(&sk->sk_drops);
100591 err = NET_RX_DROP;
100592 break;
100593 }
100594 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
100595 index 008214a..bb68240 100644
100596 --- a/net/phonet/socket.c
100597 +++ b/net/phonet/socket.c
100598 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
100599 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
100600 sock_i_ino(sk),
100601 atomic_read(&sk->sk_refcnt), sk,
100602 - atomic_read(&sk->sk_drops));
100603 + atomic_read_unchecked(&sk->sk_drops));
100604 }
100605 seq_pad(seq, '\n');
100606 return 0;
100607 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
100608 index c02a8c4..3c5b600 100644
100609 --- a/net/phonet/sysctl.c
100610 +++ b/net/phonet/sysctl.c
100611 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
100612 {
100613 int ret;
100614 int range[2] = {local_port_range[0], local_port_range[1]};
100615 - struct ctl_table tmp = {
100616 + ctl_table_no_const tmp = {
100617 .data = &range,
100618 .maxlen = sizeof(range),
100619 .mode = table->mode,
100620 diff --git a/net/rds/cong.c b/net/rds/cong.c
100621 index e5b65ac..f3b6fb7 100644
100622 --- a/net/rds/cong.c
100623 +++ b/net/rds/cong.c
100624 @@ -78,7 +78,7 @@
100625 * finds that the saved generation number is smaller than the global generation
100626 * number, it wakes up the process.
100627 */
100628 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
100629 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
100630
100631 /*
100632 * Congestion monitoring
100633 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
100634 rdsdebug("waking map %p for %pI4\n",
100635 map, &map->m_addr);
100636 rds_stats_inc(s_cong_update_received);
100637 - atomic_inc(&rds_cong_generation);
100638 + atomic_inc_unchecked(&rds_cong_generation);
100639 if (waitqueue_active(&map->m_waitq))
100640 wake_up(&map->m_waitq);
100641 if (waitqueue_active(&rds_poll_waitq))
100642 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
100643
100644 int rds_cong_updated_since(unsigned long *recent)
100645 {
100646 - unsigned long gen = atomic_read(&rds_cong_generation);
100647 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
100648
100649 if (likely(*recent == gen))
100650 return 0;
100651 diff --git a/net/rds/ib.h b/net/rds/ib.h
100652 index 7280ab8..e04f4ea 100644
100653 --- a/net/rds/ib.h
100654 +++ b/net/rds/ib.h
100655 @@ -128,7 +128,7 @@ struct rds_ib_connection {
100656 /* sending acks */
100657 unsigned long i_ack_flags;
100658 #ifdef KERNEL_HAS_ATOMIC64
100659 - atomic64_t i_ack_next; /* next ACK to send */
100660 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
100661 #else
100662 spinlock_t i_ack_lock; /* protect i_ack_next */
100663 u64 i_ack_next; /* next ACK to send */
100664 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
100665 index 31b74f5..dc1fbfa 100644
100666 --- a/net/rds/ib_cm.c
100667 +++ b/net/rds/ib_cm.c
100668 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
100669 /* Clear the ACK state */
100670 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
100671 #ifdef KERNEL_HAS_ATOMIC64
100672 - atomic64_set(&ic->i_ack_next, 0);
100673 + atomic64_set_unchecked(&ic->i_ack_next, 0);
100674 #else
100675 ic->i_ack_next = 0;
100676 #endif
100677 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
100678 index b7ebe23..b6352f6 100644
100679 --- a/net/rds/ib_recv.c
100680 +++ b/net/rds/ib_recv.c
100681 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
100682 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
100683 int ack_required)
100684 {
100685 - atomic64_set(&ic->i_ack_next, seq);
100686 + atomic64_set_unchecked(&ic->i_ack_next, seq);
100687 if (ack_required) {
100688 smp_mb__before_clear_bit();
100689 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100690 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
100691 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100692 smp_mb__after_clear_bit();
100693
100694 - return atomic64_read(&ic->i_ack_next);
100695 + return atomic64_read_unchecked(&ic->i_ack_next);
100696 }
100697 #endif
100698
100699 diff --git a/net/rds/iw.h b/net/rds/iw.h
100700 index 04ce3b1..48119a6 100644
100701 --- a/net/rds/iw.h
100702 +++ b/net/rds/iw.h
100703 @@ -134,7 +134,7 @@ struct rds_iw_connection {
100704 /* sending acks */
100705 unsigned long i_ack_flags;
100706 #ifdef KERNEL_HAS_ATOMIC64
100707 - atomic64_t i_ack_next; /* next ACK to send */
100708 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
100709 #else
100710 spinlock_t i_ack_lock; /* protect i_ack_next */
100711 u64 i_ack_next; /* next ACK to send */
100712 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
100713 index a91e1db..cf3053f 100644
100714 --- a/net/rds/iw_cm.c
100715 +++ b/net/rds/iw_cm.c
100716 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
100717 /* Clear the ACK state */
100718 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
100719 #ifdef KERNEL_HAS_ATOMIC64
100720 - atomic64_set(&ic->i_ack_next, 0);
100721 + atomic64_set_unchecked(&ic->i_ack_next, 0);
100722 #else
100723 ic->i_ack_next = 0;
100724 #endif
100725 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
100726 index 4503335..db566b4 100644
100727 --- a/net/rds/iw_recv.c
100728 +++ b/net/rds/iw_recv.c
100729 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
100730 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
100731 int ack_required)
100732 {
100733 - atomic64_set(&ic->i_ack_next, seq);
100734 + atomic64_set_unchecked(&ic->i_ack_next, seq);
100735 if (ack_required) {
100736 smp_mb__before_clear_bit();
100737 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100738 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
100739 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100740 smp_mb__after_clear_bit();
100741
100742 - return atomic64_read(&ic->i_ack_next);
100743 + return atomic64_read_unchecked(&ic->i_ack_next);
100744 }
100745 #endif
100746
100747 diff --git a/net/rds/rds.h b/net/rds/rds.h
100748 index 48f8ffc..0ef3eec 100644
100749 --- a/net/rds/rds.h
100750 +++ b/net/rds/rds.h
100751 @@ -449,7 +449,7 @@ struct rds_transport {
100752 void (*sync_mr)(void *trans_private, int direction);
100753 void (*free_mr)(void *trans_private, int invalidate);
100754 void (*flush_mrs)(void);
100755 -};
100756 +} __do_const;
100757
100758 struct rds_sock {
100759 struct sock rs_sk;
100760 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
100761 index edac9ef..16bcb98 100644
100762 --- a/net/rds/tcp.c
100763 +++ b/net/rds/tcp.c
100764 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
100765 int val = 1;
100766
100767 set_fs(KERNEL_DS);
100768 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
100769 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
100770 sizeof(val));
100771 set_fs(oldfs);
100772 }
100773 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
100774 index 81cf5a4..b5826ff 100644
100775 --- a/net/rds/tcp_send.c
100776 +++ b/net/rds/tcp_send.c
100777 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
100778
100779 oldfs = get_fs();
100780 set_fs(KERNEL_DS);
100781 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
100782 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
100783 sizeof(val));
100784 set_fs(oldfs);
100785 }
100786 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
100787 index e61aa60..f07cc89 100644
100788 --- a/net/rxrpc/af_rxrpc.c
100789 +++ b/net/rxrpc/af_rxrpc.c
100790 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
100791 __be32 rxrpc_epoch;
100792
100793 /* current debugging ID */
100794 -atomic_t rxrpc_debug_id;
100795 +atomic_unchecked_t rxrpc_debug_id;
100796
100797 /* count of skbs currently in use */
100798 atomic_t rxrpc_n_skbs;
100799 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
100800 index cd97a0c..0041649 100644
100801 --- a/net/rxrpc/ar-ack.c
100802 +++ b/net/rxrpc/ar-ack.c
100803 @@ -182,7 +182,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
100804
100805 _enter("{%d,%d,%d,%d},",
100806 call->acks_hard, call->acks_unacked,
100807 - atomic_read(&call->sequence),
100808 + atomic_read_unchecked(&call->sequence),
100809 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
100810
100811 stop = 0;
100812 @@ -206,7 +206,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
100813
100814 /* each Tx packet has a new serial number */
100815 sp->hdr.serial =
100816 - htonl(atomic_inc_return(&call->conn->serial));
100817 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
100818
100819 hdr = (struct rxrpc_header *) txb->head;
100820 hdr->serial = sp->hdr.serial;
100821 @@ -410,7 +410,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
100822 */
100823 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
100824 {
100825 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
100826 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
100827 }
100828
100829 /*
100830 @@ -636,7 +636,7 @@ process_further:
100831
100832 latest = ntohl(sp->hdr.serial);
100833 hard = ntohl(ack.firstPacket);
100834 - tx = atomic_read(&call->sequence);
100835 + tx = atomic_read_unchecked(&call->sequence);
100836
100837 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
100838 latest,
100839 @@ -1168,7 +1168,7 @@ void rxrpc_process_call(struct work_struct *work)
100840 goto maybe_reschedule;
100841
100842 send_ACK_with_skew:
100843 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
100844 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
100845 ntohl(ack.serial));
100846 send_ACK:
100847 mtu = call->conn->trans->peer->if_mtu;
100848 @@ -1180,7 +1180,7 @@ send_ACK:
100849 ackinfo.rxMTU = htonl(5692);
100850 ackinfo.jumbo_max = htonl(4);
100851
100852 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
100853 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
100854 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
100855 ntohl(hdr.serial),
100856 ntohs(ack.maxSkew),
100857 @@ -1198,7 +1198,7 @@ send_ACK:
100858 send_message:
100859 _debug("send message");
100860
100861 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
100862 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
100863 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
100864 send_message_2:
100865
100866 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
100867 index a3bbb36..3341fb9 100644
100868 --- a/net/rxrpc/ar-call.c
100869 +++ b/net/rxrpc/ar-call.c
100870 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
100871 spin_lock_init(&call->lock);
100872 rwlock_init(&call->state_lock);
100873 atomic_set(&call->usage, 1);
100874 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
100875 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
100876 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
100877
100878 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
100879 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
100880 index 7bf5b5b..4a3bf2c 100644
100881 --- a/net/rxrpc/ar-connection.c
100882 +++ b/net/rxrpc/ar-connection.c
100883 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
100884 rwlock_init(&conn->lock);
100885 spin_lock_init(&conn->state_lock);
100886 atomic_set(&conn->usage, 1);
100887 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
100888 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
100889 conn->avail_calls = RXRPC_MAXCALLS;
100890 conn->size_align = 4;
100891 conn->header_size = sizeof(struct rxrpc_header);
100892 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
100893 index e7ed43a..6afa140 100644
100894 --- a/net/rxrpc/ar-connevent.c
100895 +++ b/net/rxrpc/ar-connevent.c
100896 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
100897
100898 len = iov[0].iov_len + iov[1].iov_len;
100899
100900 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
100901 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
100902 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
100903
100904 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
100905 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
100906 index 529572f..c758ca7 100644
100907 --- a/net/rxrpc/ar-input.c
100908 +++ b/net/rxrpc/ar-input.c
100909 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
100910 /* track the latest serial number on this connection for ACK packet
100911 * information */
100912 serial = ntohl(sp->hdr.serial);
100913 - hi_serial = atomic_read(&call->conn->hi_serial);
100914 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
100915 while (serial > hi_serial)
100916 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
100917 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
100918 serial);
100919
100920 /* request ACK generation for any ACK or DATA packet that requests
100921 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
100922 index 5f43675..ca07817 100644
100923 --- a/net/rxrpc/ar-internal.h
100924 +++ b/net/rxrpc/ar-internal.h
100925 @@ -272,8 +272,8 @@ struct rxrpc_connection {
100926 int error; /* error code for local abort */
100927 int debug_id; /* debug ID for printks */
100928 unsigned int call_counter; /* call ID counter */
100929 - atomic_t serial; /* packet serial number counter */
100930 - atomic_t hi_serial; /* highest serial number received */
100931 + atomic_unchecked_t serial; /* packet serial number counter */
100932 + atomic_unchecked_t hi_serial; /* highest serial number received */
100933 u8 avail_calls; /* number of calls available */
100934 u8 size_align; /* data size alignment (for security) */
100935 u8 header_size; /* rxrpc + security header size */
100936 @@ -346,7 +346,7 @@ struct rxrpc_call {
100937 spinlock_t lock;
100938 rwlock_t state_lock; /* lock for state transition */
100939 atomic_t usage;
100940 - atomic_t sequence; /* Tx data packet sequence counter */
100941 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
100942 u32 abort_code; /* local/remote abort code */
100943 enum { /* current state of call */
100944 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
100945 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
100946 */
100947 extern atomic_t rxrpc_n_skbs;
100948 extern __be32 rxrpc_epoch;
100949 -extern atomic_t rxrpc_debug_id;
100950 +extern atomic_unchecked_t rxrpc_debug_id;
100951 extern struct workqueue_struct *rxrpc_workqueue;
100952
100953 /*
100954 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
100955 index 87f7135..74d3703 100644
100956 --- a/net/rxrpc/ar-local.c
100957 +++ b/net/rxrpc/ar-local.c
100958 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
100959 spin_lock_init(&local->lock);
100960 rwlock_init(&local->services_lock);
100961 atomic_set(&local->usage, 1);
100962 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
100963 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
100964 memcpy(&local->srx, srx, sizeof(*srx));
100965 }
100966
100967 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
100968 index d0e8f1c..a3a1686 100644
100969 --- a/net/rxrpc/ar-output.c
100970 +++ b/net/rxrpc/ar-output.c
100971 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
100972 sp->hdr.cid = call->cid;
100973 sp->hdr.callNumber = call->call_id;
100974 sp->hdr.seq =
100975 - htonl(atomic_inc_return(&call->sequence));
100976 + htonl(atomic_inc_return_unchecked(&call->sequence));
100977 sp->hdr.serial =
100978 - htonl(atomic_inc_return(&conn->serial));
100979 + htonl(atomic_inc_return_unchecked(&conn->serial));
100980 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
100981 sp->hdr.userStatus = 0;
100982 sp->hdr.securityIndex = conn->security_ix;
100983 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
100984 index bebaa43..2644591 100644
100985 --- a/net/rxrpc/ar-peer.c
100986 +++ b/net/rxrpc/ar-peer.c
100987 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
100988 INIT_LIST_HEAD(&peer->error_targets);
100989 spin_lock_init(&peer->lock);
100990 atomic_set(&peer->usage, 1);
100991 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
100992 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
100993 memcpy(&peer->srx, srx, sizeof(*srx));
100994
100995 rxrpc_assess_MTU_size(peer);
100996 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
100997 index 38047f7..9f48511 100644
100998 --- a/net/rxrpc/ar-proc.c
100999 +++ b/net/rxrpc/ar-proc.c
101000 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
101001 atomic_read(&conn->usage),
101002 rxrpc_conn_states[conn->state],
101003 key_serial(conn->key),
101004 - atomic_read(&conn->serial),
101005 - atomic_read(&conn->hi_serial));
101006 + atomic_read_unchecked(&conn->serial),
101007 + atomic_read_unchecked(&conn->hi_serial));
101008
101009 return 0;
101010 }
101011 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
101012 index 92df566..87ec1bf 100644
101013 --- a/net/rxrpc/ar-transport.c
101014 +++ b/net/rxrpc/ar-transport.c
101015 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
101016 spin_lock_init(&trans->client_lock);
101017 rwlock_init(&trans->conn_lock);
101018 atomic_set(&trans->usage, 1);
101019 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
101020 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
101021
101022 if (peer->srx.transport.family == AF_INET) {
101023 switch (peer->srx.transport_type) {
101024 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
101025 index f226709..0e735a8 100644
101026 --- a/net/rxrpc/rxkad.c
101027 +++ b/net/rxrpc/rxkad.c
101028 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
101029
101030 len = iov[0].iov_len + iov[1].iov_len;
101031
101032 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
101033 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
101034 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
101035
101036 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
101037 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
101038
101039 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
101040
101041 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
101042 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
101043 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
101044
101045 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
101046 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
101047 index 2b1738e..a9d0fc9 100644
101048 --- a/net/sctp/ipv6.c
101049 +++ b/net/sctp/ipv6.c
101050 @@ -966,7 +966,7 @@ static const struct inet6_protocol sctpv6_protocol = {
101051 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
101052 };
101053
101054 -static struct sctp_af sctp_af_inet6 = {
101055 +static struct sctp_af sctp_af_inet6 __read_only = {
101056 .sa_family = AF_INET6,
101057 .sctp_xmit = sctp_v6_xmit,
101058 .setsockopt = ipv6_setsockopt,
101059 @@ -998,7 +998,7 @@ static struct sctp_af sctp_af_inet6 = {
101060 #endif
101061 };
101062
101063 -static struct sctp_pf sctp_pf_inet6 = {
101064 +static struct sctp_pf sctp_pf_inet6 __read_only = {
101065 .event_msgname = sctp_inet6_event_msgname,
101066 .skb_msgname = sctp_inet6_skb_msgname,
101067 .af_supported = sctp_inet6_af_supported,
101068 @@ -1023,7 +1023,7 @@ void sctp_v6_pf_init(void)
101069
101070 void sctp_v6_pf_exit(void)
101071 {
101072 - list_del(&sctp_af_inet6.list);
101073 + pax_list_del(&sctp_af_inet6.list);
101074 }
101075
101076 /* Initialize IPv6 support and register with socket layer. */
101077 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
101078 index 4e1d0fc..068fef7 100644
101079 --- a/net/sctp/protocol.c
101080 +++ b/net/sctp/protocol.c
101081 @@ -831,8 +831,10 @@ int sctp_register_af(struct sctp_af *af)
101082 return 0;
101083 }
101084
101085 + pax_open_kernel();
101086 INIT_LIST_HEAD(&af->list);
101087 - list_add_tail(&af->list, &sctp_address_families);
101088 + pax_close_kernel();
101089 + pax_list_add_tail(&af->list, &sctp_address_families);
101090 return 1;
101091 }
101092
101093 @@ -962,7 +964,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
101094
101095 static struct sctp_af sctp_af_inet;
101096
101097 -static struct sctp_pf sctp_pf_inet = {
101098 +static struct sctp_pf sctp_pf_inet __read_only = {
101099 .event_msgname = sctp_inet_event_msgname,
101100 .skb_msgname = sctp_inet_skb_msgname,
101101 .af_supported = sctp_inet_af_supported,
101102 @@ -1034,7 +1036,7 @@ static const struct net_protocol sctp_protocol = {
101103 };
101104
101105 /* IPv4 address related functions. */
101106 -static struct sctp_af sctp_af_inet = {
101107 +static struct sctp_af sctp_af_inet __read_only = {
101108 .sa_family = AF_INET,
101109 .sctp_xmit = sctp_v4_xmit,
101110 .setsockopt = ip_setsockopt,
101111 @@ -1119,7 +1121,7 @@ static void sctp_v4_pf_init(void)
101112
101113 static void sctp_v4_pf_exit(void)
101114 {
101115 - list_del(&sctp_af_inet.list);
101116 + pax_list_del(&sctp_af_inet.list);
101117 }
101118
101119 static int sctp_v4_protosw_init(void)
101120 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
101121 index 5d6883f..394a102 100644
101122 --- a/net/sctp/sm_sideeffect.c
101123 +++ b/net/sctp/sm_sideeffect.c
101124 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
101125 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
101126 }
101127
101128 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
101129 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
101130 NULL,
101131 sctp_generate_t1_cookie_event,
101132 sctp_generate_t1_init_event,
101133 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
101134 index 981aaf8..5bc016d 100644
101135 --- a/net/sctp/socket.c
101136 +++ b/net/sctp/socket.c
101137 @@ -2169,11 +2169,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
101138 {
101139 struct sctp_association *asoc;
101140 struct sctp_ulpevent *event;
101141 + struct sctp_event_subscribe subscribe;
101142
101143 if (optlen > sizeof(struct sctp_event_subscribe))
101144 return -EINVAL;
101145 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
101146 + if (copy_from_user(&subscribe, optval, optlen))
101147 return -EFAULT;
101148 + sctp_sk(sk)->subscribe = subscribe;
101149
101150 /*
101151 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
101152 @@ -4255,13 +4257,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
101153 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
101154 int __user *optlen)
101155 {
101156 + struct sctp_event_subscribe subscribe;
101157 +
101158 if (len <= 0)
101159 return -EINVAL;
101160 if (len > sizeof(struct sctp_event_subscribe))
101161 len = sizeof(struct sctp_event_subscribe);
101162 if (put_user(len, optlen))
101163 return -EFAULT;
101164 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
101165 + subscribe = sctp_sk(sk)->subscribe;
101166 + if (copy_to_user(optval, &subscribe, len))
101167 return -EFAULT;
101168 return 0;
101169 }
101170 @@ -4279,6 +4284,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
101171 */
101172 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
101173 {
101174 + __u32 autoclose;
101175 +
101176 /* Applicable to UDP-style socket only */
101177 if (sctp_style(sk, TCP))
101178 return -EOPNOTSUPP;
101179 @@ -4287,7 +4294,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
101180 len = sizeof(int);
101181 if (put_user(len, optlen))
101182 return -EFAULT;
101183 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
101184 + autoclose = sctp_sk(sk)->autoclose;
101185 + if (copy_to_user(optval, &autoclose, sizeof(int)))
101186 return -EFAULT;
101187 return 0;
101188 }
101189 @@ -4662,12 +4670,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
101190 */
101191 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
101192 {
101193 + struct sctp_initmsg initmsg;
101194 +
101195 if (len < sizeof(struct sctp_initmsg))
101196 return -EINVAL;
101197 len = sizeof(struct sctp_initmsg);
101198 if (put_user(len, optlen))
101199 return -EFAULT;
101200 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
101201 + initmsg = sctp_sk(sk)->initmsg;
101202 + if (copy_to_user(optval, &initmsg, len))
101203 return -EFAULT;
101204 return 0;
101205 }
101206 @@ -4708,6 +4719,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
101207 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
101208 if (space_left < addrlen)
101209 return -ENOMEM;
101210 + if (addrlen > sizeof(temp) || addrlen < 0)
101211 + return -EFAULT;
101212 if (copy_to_user(to, &temp, addrlen))
101213 return -EFAULT;
101214 to += addrlen;
101215 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
101216 index 35c8923..536614e 100644
101217 --- a/net/sctp/sysctl.c
101218 +++ b/net/sctp/sysctl.c
101219 @@ -305,7 +305,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
101220 {
101221 struct net *net = current->nsproxy->net_ns;
101222 char tmp[8];
101223 - struct ctl_table tbl;
101224 + ctl_table_no_const tbl;
101225 int ret;
101226 int changed = 0;
101227 char *none = "none";
101228 @@ -352,7 +352,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
101229 {
101230 struct net *net = current->nsproxy->net_ns;
101231 int new_value;
101232 - struct ctl_table tbl;
101233 + ctl_table_no_const tbl;
101234 unsigned int min = *(unsigned int *) ctl->extra1;
101235 unsigned int max = *(unsigned int *) ctl->extra2;
101236 int ret;
101237 @@ -379,7 +379,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
101238 {
101239 struct net *net = current->nsproxy->net_ns;
101240 int new_value;
101241 - struct ctl_table tbl;
101242 + ctl_table_no_const tbl;
101243 unsigned int min = *(unsigned int *) ctl->extra1;
101244 unsigned int max = *(unsigned int *) ctl->extra2;
101245 int ret;
101246 @@ -402,7 +402,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
101247
101248 int sctp_sysctl_net_register(struct net *net)
101249 {
101250 - struct ctl_table *table = sctp_net_table;
101251 + ctl_table_no_const *table = NULL;
101252
101253 if (!net_eq(net, &init_net)) {
101254 int i;
101255 @@ -415,7 +415,10 @@ int sctp_sysctl_net_register(struct net *net)
101256 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
101257 }
101258
101259 - net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
101260 + if (!net_eq(net, &init_net))
101261 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
101262 + else
101263 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", sctp_net_table);
101264 return 0;
101265 }
101266
101267 diff --git a/net/socket.c b/net/socket.c
101268 index a19ae19..89554dc 100644
101269 --- a/net/socket.c
101270 +++ b/net/socket.c
101271 @@ -88,6 +88,7 @@
101272 #include <linux/magic.h>
101273 #include <linux/slab.h>
101274 #include <linux/xattr.h>
101275 +#include <linux/in.h>
101276
101277 #include <asm/uaccess.h>
101278 #include <asm/unistd.h>
101279 @@ -111,6 +112,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
101280 unsigned int sysctl_net_busy_poll __read_mostly;
101281 #endif
101282
101283 +#include <linux/grsock.h>
101284 +
101285 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
101286 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
101287 unsigned long nr_segs, loff_t pos);
101288 @@ -162,7 +165,7 @@ static const struct file_operations socket_file_ops = {
101289 */
101290
101291 static DEFINE_SPINLOCK(net_family_lock);
101292 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
101293 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
101294
101295 /*
101296 * Statistics counters of the socket lists
101297 @@ -328,7 +331,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
101298 &sockfs_dentry_operations, SOCKFS_MAGIC);
101299 }
101300
101301 -static struct vfsmount *sock_mnt __read_mostly;
101302 +struct vfsmount *sock_mnt __read_mostly;
101303
101304 static struct file_system_type sock_fs_type = {
101305 .name = "sockfs",
101306 @@ -1256,6 +1259,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
101307 return -EAFNOSUPPORT;
101308 if (type < 0 || type >= SOCK_MAX)
101309 return -EINVAL;
101310 + if (protocol < 0)
101311 + return -EINVAL;
101312
101313 /* Compatibility.
101314
101315 @@ -1276,6 +1281,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
101316 if (err)
101317 return err;
101318
101319 + if(!kern && !gr_search_socket(family, type, protocol)) {
101320 + if (rcu_access_pointer(net_families[family]) == NULL)
101321 + return -EAFNOSUPPORT;
101322 + else
101323 + return -EACCES;
101324 + }
101325 +
101326 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
101327 + if (rcu_access_pointer(net_families[family]) == NULL)
101328 + return -EAFNOSUPPORT;
101329 + else
101330 + return -EACCES;
101331 + }
101332 +
101333 /*
101334 * Allocate the socket and allow the family to set things up. if
101335 * the protocol is 0, the family is instructed to select an appropriate
101336 @@ -1527,6 +1546,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
101337 if (sock) {
101338 err = move_addr_to_kernel(umyaddr, addrlen, &address);
101339 if (err >= 0) {
101340 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
101341 + err = -EACCES;
101342 + goto error;
101343 + }
101344 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
101345 + if (err)
101346 + goto error;
101347 +
101348 err = security_socket_bind(sock,
101349 (struct sockaddr *)&address,
101350 addrlen);
101351 @@ -1535,6 +1562,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
101352 (struct sockaddr *)
101353 &address, addrlen);
101354 }
101355 +error:
101356 fput_light(sock->file, fput_needed);
101357 }
101358 return err;
101359 @@ -1558,10 +1586,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
101360 if ((unsigned int)backlog > somaxconn)
101361 backlog = somaxconn;
101362
101363 + if (gr_handle_sock_server_other(sock->sk)) {
101364 + err = -EPERM;
101365 + goto error;
101366 + }
101367 +
101368 + err = gr_search_listen(sock);
101369 + if (err)
101370 + goto error;
101371 +
101372 err = security_socket_listen(sock, backlog);
101373 if (!err)
101374 err = sock->ops->listen(sock, backlog);
101375
101376 +error:
101377 fput_light(sock->file, fput_needed);
101378 }
101379 return err;
101380 @@ -1605,6 +1643,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
101381 newsock->type = sock->type;
101382 newsock->ops = sock->ops;
101383
101384 + if (gr_handle_sock_server_other(sock->sk)) {
101385 + err = -EPERM;
101386 + sock_release(newsock);
101387 + goto out_put;
101388 + }
101389 +
101390 + err = gr_search_accept(sock);
101391 + if (err) {
101392 + sock_release(newsock);
101393 + goto out_put;
101394 + }
101395 +
101396 /*
101397 * We don't need try_module_get here, as the listening socket (sock)
101398 * has the protocol module (sock->ops->owner) held.
101399 @@ -1650,6 +1700,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
101400 fd_install(newfd, newfile);
101401 err = newfd;
101402
101403 + gr_attach_curr_ip(newsock->sk);
101404 +
101405 out_put:
101406 fput_light(sock->file, fput_needed);
101407 out:
101408 @@ -1682,6 +1734,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
101409 int, addrlen)
101410 {
101411 struct socket *sock;
101412 + struct sockaddr *sck;
101413 struct sockaddr_storage address;
101414 int err, fput_needed;
101415
101416 @@ -1692,6 +1745,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
101417 if (err < 0)
101418 goto out_put;
101419
101420 + sck = (struct sockaddr *)&address;
101421 +
101422 + if (gr_handle_sock_client(sck)) {
101423 + err = -EACCES;
101424 + goto out_put;
101425 + }
101426 +
101427 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
101428 + if (err)
101429 + goto out_put;
101430 +
101431 err =
101432 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
101433 if (err)
101434 @@ -1773,6 +1837,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
101435 * the protocol.
101436 */
101437
101438 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
101439 +
101440 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
101441 unsigned int, flags, struct sockaddr __user *, addr,
101442 int, addr_len)
101443 @@ -1839,7 +1905,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
101444 struct socket *sock;
101445 struct iovec iov;
101446 struct msghdr msg;
101447 - struct sockaddr_storage address;
101448 + struct sockaddr_storage address = { };
101449 int err, err2;
101450 int fput_needed;
101451
101452 @@ -2065,7 +2131,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
101453 * checking falls down on this.
101454 */
101455 if (copy_from_user(ctl_buf,
101456 - (void __user __force *)msg_sys->msg_control,
101457 + (void __force_user *)msg_sys->msg_control,
101458 ctl_len))
101459 goto out_freectl;
101460 msg_sys->msg_control = ctl_buf;
101461 @@ -2216,7 +2282,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
101462 int err, total_len, len;
101463
101464 /* kernel mode address */
101465 - struct sockaddr_storage addr;
101466 + struct sockaddr_storage addr = { };
101467
101468 /* user mode address pointers */
101469 struct sockaddr __user *uaddr;
101470 @@ -2245,7 +2311,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
101471 /* Save the user-mode address (verify_iovec will change the
101472 * kernel msghdr to use the kernel address space)
101473 */
101474 - uaddr = (__force void __user *)msg_sys->msg_name;
101475 + uaddr = (void __force_user *)msg_sys->msg_name;
101476 uaddr_len = COMPAT_NAMELEN(msg);
101477 if (MSG_CMSG_COMPAT & flags)
101478 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
101479 @@ -2889,7 +2955,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
101480 ifr = compat_alloc_user_space(buf_size);
101481 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
101482
101483 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
101484 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
101485 return -EFAULT;
101486
101487 if (put_user(convert_in ? rxnfc : compat_ptr(data),
101488 @@ -3000,7 +3066,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
101489 old_fs = get_fs();
101490 set_fs(KERNEL_DS);
101491 err = dev_ioctl(net, cmd,
101492 - (struct ifreq __user __force *) &kifr);
101493 + (struct ifreq __force_user *) &kifr);
101494 set_fs(old_fs);
101495
101496 return err;
101497 @@ -3093,7 +3159,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
101498
101499 old_fs = get_fs();
101500 set_fs(KERNEL_DS);
101501 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
101502 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
101503 set_fs(old_fs);
101504
101505 if (cmd == SIOCGIFMAP && !err) {
101506 @@ -3177,7 +3243,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
101507 ret |= get_user(rtdev, &(ur4->rt_dev));
101508 if (rtdev) {
101509 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
101510 - r4.rt_dev = (char __user __force *)devname;
101511 + r4.rt_dev = (char __force_user *)devname;
101512 devname[15] = 0;
101513 } else
101514 r4.rt_dev = NULL;
101515 @@ -3404,8 +3470,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
101516 int __user *uoptlen;
101517 int err;
101518
101519 - uoptval = (char __user __force *) optval;
101520 - uoptlen = (int __user __force *) optlen;
101521 + uoptval = (char __force_user *) optval;
101522 + uoptlen = (int __force_user *) optlen;
101523
101524 set_fs(KERNEL_DS);
101525 if (level == SOL_SOCKET)
101526 @@ -3425,7 +3491,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
101527 char __user *uoptval;
101528 int err;
101529
101530 - uoptval = (char __user __force *) optval;
101531 + uoptval = (char __force_user *) optval;
101532
101533 set_fs(KERNEL_DS);
101534 if (level == SOL_SOCKET)
101535 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
101536 index 0f73f45..a96aa52 100644
101537 --- a/net/sunrpc/auth_gss/svcauth_gss.c
101538 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
101539 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
101540 uint64_t *handle)
101541 {
101542 struct rsc rsci, *rscp = NULL;
101543 - static atomic64_t ctxhctr;
101544 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
101545 long long ctxh;
101546 struct gss_api_mech *gm = NULL;
101547 time_t expiry;
101548 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
101549 status = -ENOMEM;
101550 /* the handle needs to be just a unique id,
101551 * use a static counter */
101552 - ctxh = atomic64_inc_return(&ctxhctr);
101553 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
101554
101555 /* make a copy for the caller */
101556 *handle = ctxh;
101557 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
101558 index 0edada9..9247ea0 100644
101559 --- a/net/sunrpc/clnt.c
101560 +++ b/net/sunrpc/clnt.c
101561 @@ -1415,7 +1415,9 @@ call_start(struct rpc_task *task)
101562 (RPC_IS_ASYNC(task) ? "async" : "sync"));
101563
101564 /* Increment call count */
101565 - task->tk_msg.rpc_proc->p_count++;
101566 + pax_open_kernel();
101567 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
101568 + pax_close_kernel();
101569 clnt->cl_stats->rpccnt++;
101570 task->tk_action = call_reserve;
101571 }
101572 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
101573 index ff3cc4b..7612a9e 100644
101574 --- a/net/sunrpc/sched.c
101575 +++ b/net/sunrpc/sched.c
101576 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
101577 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
101578 static void rpc_task_set_debuginfo(struct rpc_task *task)
101579 {
101580 - static atomic_t rpc_pid;
101581 + static atomic_unchecked_t rpc_pid;
101582
101583 - task->tk_pid = atomic_inc_return(&rpc_pid);
101584 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
101585 }
101586 #else
101587 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
101588 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
101589 index 5de6801..b4e330d 100644
101590 --- a/net/sunrpc/svc.c
101591 +++ b/net/sunrpc/svc.c
101592 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
101593 svc_putnl(resv, RPC_SUCCESS);
101594
101595 /* Bump per-procedure stats counter */
101596 - procp->pc_count++;
101597 + pax_open_kernel();
101598 + (*(unsigned int *)&procp->pc_count)++;
101599 + pax_close_kernel();
101600
101601 /* Initialize storage for argp and resp */
101602 memset(rqstp->rq_argp, 0, procp->pc_argsize);
101603 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
101604 index 621ca7b..59421dd 100644
101605 --- a/net/sunrpc/svcauth_unix.c
101606 +++ b/net/sunrpc/svcauth_unix.c
101607 @@ -414,7 +414,7 @@ struct unix_gid {
101608 struct group_info *gi;
101609 };
101610
101611 -static int unix_gid_hash(kuid_t uid)
101612 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
101613 {
101614 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
101615 }
101616 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
101617 (*bpp)[-1] = '\n';
101618 }
101619
101620 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
101621 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
101622
101623 static int unix_gid_parse(struct cache_detail *cd,
101624 char *mesg, int mlen)
101625 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
101626 index c1b6270..05089c1 100644
101627 --- a/net/sunrpc/xprtrdma/svc_rdma.c
101628 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
101629 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
101630 static unsigned int min_max_inline = 4096;
101631 static unsigned int max_max_inline = 65536;
101632
101633 -atomic_t rdma_stat_recv;
101634 -atomic_t rdma_stat_read;
101635 -atomic_t rdma_stat_write;
101636 -atomic_t rdma_stat_sq_starve;
101637 -atomic_t rdma_stat_rq_starve;
101638 -atomic_t rdma_stat_rq_poll;
101639 -atomic_t rdma_stat_rq_prod;
101640 -atomic_t rdma_stat_sq_poll;
101641 -atomic_t rdma_stat_sq_prod;
101642 +atomic_unchecked_t rdma_stat_recv;
101643 +atomic_unchecked_t rdma_stat_read;
101644 +atomic_unchecked_t rdma_stat_write;
101645 +atomic_unchecked_t rdma_stat_sq_starve;
101646 +atomic_unchecked_t rdma_stat_rq_starve;
101647 +atomic_unchecked_t rdma_stat_rq_poll;
101648 +atomic_unchecked_t rdma_stat_rq_prod;
101649 +atomic_unchecked_t rdma_stat_sq_poll;
101650 +atomic_unchecked_t rdma_stat_sq_prod;
101651
101652 /* Temporary NFS request map and context caches */
101653 struct kmem_cache *svc_rdma_map_cachep;
101654 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
101655 len -= *ppos;
101656 if (len > *lenp)
101657 len = *lenp;
101658 - if (len && copy_to_user(buffer, str_buf, len))
101659 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
101660 return -EFAULT;
101661 *lenp = len;
101662 *ppos += len;
101663 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
101664 {
101665 .procname = "rdma_stat_read",
101666 .data = &rdma_stat_read,
101667 - .maxlen = sizeof(atomic_t),
101668 + .maxlen = sizeof(atomic_unchecked_t),
101669 .mode = 0644,
101670 .proc_handler = read_reset_stat,
101671 },
101672 {
101673 .procname = "rdma_stat_recv",
101674 .data = &rdma_stat_recv,
101675 - .maxlen = sizeof(atomic_t),
101676 + .maxlen = sizeof(atomic_unchecked_t),
101677 .mode = 0644,
101678 .proc_handler = read_reset_stat,
101679 },
101680 {
101681 .procname = "rdma_stat_write",
101682 .data = &rdma_stat_write,
101683 - .maxlen = sizeof(atomic_t),
101684 + .maxlen = sizeof(atomic_unchecked_t),
101685 .mode = 0644,
101686 .proc_handler = read_reset_stat,
101687 },
101688 {
101689 .procname = "rdma_stat_sq_starve",
101690 .data = &rdma_stat_sq_starve,
101691 - .maxlen = sizeof(atomic_t),
101692 + .maxlen = sizeof(atomic_unchecked_t),
101693 .mode = 0644,
101694 .proc_handler = read_reset_stat,
101695 },
101696 {
101697 .procname = "rdma_stat_rq_starve",
101698 .data = &rdma_stat_rq_starve,
101699 - .maxlen = sizeof(atomic_t),
101700 + .maxlen = sizeof(atomic_unchecked_t),
101701 .mode = 0644,
101702 .proc_handler = read_reset_stat,
101703 },
101704 {
101705 .procname = "rdma_stat_rq_poll",
101706 .data = &rdma_stat_rq_poll,
101707 - .maxlen = sizeof(atomic_t),
101708 + .maxlen = sizeof(atomic_unchecked_t),
101709 .mode = 0644,
101710 .proc_handler = read_reset_stat,
101711 },
101712 {
101713 .procname = "rdma_stat_rq_prod",
101714 .data = &rdma_stat_rq_prod,
101715 - .maxlen = sizeof(atomic_t),
101716 + .maxlen = sizeof(atomic_unchecked_t),
101717 .mode = 0644,
101718 .proc_handler = read_reset_stat,
101719 },
101720 {
101721 .procname = "rdma_stat_sq_poll",
101722 .data = &rdma_stat_sq_poll,
101723 - .maxlen = sizeof(atomic_t),
101724 + .maxlen = sizeof(atomic_unchecked_t),
101725 .mode = 0644,
101726 .proc_handler = read_reset_stat,
101727 },
101728 {
101729 .procname = "rdma_stat_sq_prod",
101730 .data = &rdma_stat_sq_prod,
101731 - .maxlen = sizeof(atomic_t),
101732 + .maxlen = sizeof(atomic_unchecked_t),
101733 .mode = 0644,
101734 .proc_handler = read_reset_stat,
101735 },
101736 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
101737 index 0ce7552..d074459 100644
101738 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
101739 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
101740 @@ -501,7 +501,7 @@ next_sge:
101741 svc_rdma_put_context(ctxt, 0);
101742 goto out;
101743 }
101744 - atomic_inc(&rdma_stat_read);
101745 + atomic_inc_unchecked(&rdma_stat_read);
101746
101747 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
101748 chl_map->ch[ch_no].count -= read_wr.num_sge;
101749 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
101750 dto_q);
101751 list_del_init(&ctxt->dto_q);
101752 } else {
101753 - atomic_inc(&rdma_stat_rq_starve);
101754 + atomic_inc_unchecked(&rdma_stat_rq_starve);
101755 clear_bit(XPT_DATA, &xprt->xpt_flags);
101756 ctxt = NULL;
101757 }
101758 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
101759 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
101760 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
101761 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
101762 - atomic_inc(&rdma_stat_recv);
101763 + atomic_inc_unchecked(&rdma_stat_recv);
101764
101765 /* Build up the XDR from the receive buffers. */
101766 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
101767 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
101768 index c1d124d..acfc59e 100644
101769 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
101770 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
101771 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
101772 write_wr.wr.rdma.remote_addr = to;
101773
101774 /* Post It */
101775 - atomic_inc(&rdma_stat_write);
101776 + atomic_inc_unchecked(&rdma_stat_write);
101777 if (svc_rdma_send(xprt, &write_wr))
101778 goto err;
101779 return 0;
101780 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
101781 index 62e4f9b..dd3f2d7 100644
101782 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
101783 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
101784 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
101785 return;
101786
101787 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
101788 - atomic_inc(&rdma_stat_rq_poll);
101789 + atomic_inc_unchecked(&rdma_stat_rq_poll);
101790
101791 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
101792 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
101793 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
101794 }
101795
101796 if (ctxt)
101797 - atomic_inc(&rdma_stat_rq_prod);
101798 + atomic_inc_unchecked(&rdma_stat_rq_prod);
101799
101800 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
101801 /*
101802 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
101803 return;
101804
101805 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
101806 - atomic_inc(&rdma_stat_sq_poll);
101807 + atomic_inc_unchecked(&rdma_stat_sq_poll);
101808 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
101809 if (wc.status != IB_WC_SUCCESS)
101810 /* Close the transport */
101811 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
101812 }
101813
101814 if (ctxt)
101815 - atomic_inc(&rdma_stat_sq_prod);
101816 + atomic_inc_unchecked(&rdma_stat_sq_prod);
101817 }
101818
101819 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
101820 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
101821 spin_lock_bh(&xprt->sc_lock);
101822 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
101823 spin_unlock_bh(&xprt->sc_lock);
101824 - atomic_inc(&rdma_stat_sq_starve);
101825 + atomic_inc_unchecked(&rdma_stat_sq_starve);
101826
101827 /* See if we can opportunistically reap SQ WR to make room */
101828 sq_cq_reap(xprt);
101829 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
101830 index e7000be..e3b0ba7 100644
101831 --- a/net/sysctl_net.c
101832 +++ b/net/sysctl_net.c
101833 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
101834 kgid_t root_gid = make_kgid(net->user_ns, 0);
101835
101836 /* Allow network administrator to have same access as root. */
101837 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
101838 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
101839 uid_eq(root_uid, current_euid())) {
101840 int mode = (table->mode >> 6) & 7;
101841 return (mode << 6) | (mode << 3) | mode;
101842 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
101843 index 6424372..afd36e9 100644
101844 --- a/net/tipc/subscr.c
101845 +++ b/net/tipc/subscr.c
101846 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
101847 struct tipc_subscriber *subscriber = sub->subscriber;
101848 struct kvec msg_sect;
101849
101850 - msg_sect.iov_base = (void *)&sub->evt;
101851 + msg_sect.iov_base = &sub->evt;
101852 msg_sect.iov_len = sizeof(struct tipc_event);
101853 sub->evt.event = htohl(event, sub->swap);
101854 sub->evt.found_lower = htohl(found_lower, sub->swap);
101855 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
101856 index 94404f1..5782191 100644
101857 --- a/net/unix/af_unix.c
101858 +++ b/net/unix/af_unix.c
101859 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
101860 err = -ECONNREFUSED;
101861 if (!S_ISSOCK(inode->i_mode))
101862 goto put_fail;
101863 +
101864 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
101865 + err = -EACCES;
101866 + goto put_fail;
101867 + }
101868 +
101869 u = unix_find_socket_byinode(inode);
101870 if (!u)
101871 goto put_fail;
101872 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
101873 if (u) {
101874 struct dentry *dentry;
101875 dentry = unix_sk(u)->path.dentry;
101876 +
101877 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
101878 + err = -EPERM;
101879 + sock_put(u);
101880 + goto fail;
101881 + }
101882 +
101883 if (dentry)
101884 touch_atime(&unix_sk(u)->path);
101885 } else
101886 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
101887 */
101888 err = security_path_mknod(&path, dentry, mode, 0);
101889 if (!err) {
101890 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
101891 + err = -EACCES;
101892 + goto out;
101893 + }
101894 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
101895 if (!err) {
101896 res->mnt = mntget(path.mnt);
101897 res->dentry = dget(dentry);
101898 + gr_handle_create(dentry, path.mnt);
101899 }
101900 }
101901 +out:
101902 done_path_create(&path, dentry);
101903 return err;
101904 }
101905 @@ -2344,9 +2363,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
101906 seq_puts(seq, "Num RefCount Protocol Flags Type St "
101907 "Inode Path\n");
101908 else {
101909 - struct sock *s = v;
101910 + struct sock *s = v, *peer;
101911 struct unix_sock *u = unix_sk(s);
101912 unix_state_lock(s);
101913 + peer = unix_peer(s);
101914 + unix_state_unlock(s);
101915 +
101916 + unix_state_double_lock(s, peer);
101917
101918 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
101919 s,
101920 @@ -2373,8 +2396,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
101921 }
101922 for ( ; i < len; i++)
101923 seq_putc(seq, u->addr->name->sun_path[i]);
101924 - }
101925 - unix_state_unlock(s);
101926 + } else if (peer)
101927 + seq_printf(seq, " P%lu", sock_i_ino(peer));
101928 +
101929 + unix_state_double_unlock(s, peer);
101930 seq_putc(seq, '\n');
101931 }
101932
101933 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
101934 index b3d5150..ff3a837 100644
101935 --- a/net/unix/sysctl_net_unix.c
101936 +++ b/net/unix/sysctl_net_unix.c
101937 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
101938
101939 int __net_init unix_sysctl_register(struct net *net)
101940 {
101941 - struct ctl_table *table;
101942 + ctl_table_no_const *table;
101943
101944 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
101945 if (table == NULL)
101946 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
101947 index 9a73074..aecba9a 100644
101948 --- a/net/vmw_vsock/vmci_transport_notify.c
101949 +++ b/net/vmw_vsock/vmci_transport_notify.c
101950 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
101951
101952 /* Socket control packet based operations. */
101953 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
101954 - vmci_transport_notify_pkt_socket_init,
101955 - vmci_transport_notify_pkt_socket_destruct,
101956 - vmci_transport_notify_pkt_poll_in,
101957 - vmci_transport_notify_pkt_poll_out,
101958 - vmci_transport_notify_pkt_handle_pkt,
101959 - vmci_transport_notify_pkt_recv_init,
101960 - vmci_transport_notify_pkt_recv_pre_block,
101961 - vmci_transport_notify_pkt_recv_pre_dequeue,
101962 - vmci_transport_notify_pkt_recv_post_dequeue,
101963 - vmci_transport_notify_pkt_send_init,
101964 - vmci_transport_notify_pkt_send_pre_block,
101965 - vmci_transport_notify_pkt_send_pre_enqueue,
101966 - vmci_transport_notify_pkt_send_post_enqueue,
101967 - vmci_transport_notify_pkt_process_request,
101968 - vmci_transport_notify_pkt_process_negotiate,
101969 + .socket_init = vmci_transport_notify_pkt_socket_init,
101970 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
101971 + .poll_in = vmci_transport_notify_pkt_poll_in,
101972 + .poll_out = vmci_transport_notify_pkt_poll_out,
101973 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
101974 + .recv_init = vmci_transport_notify_pkt_recv_init,
101975 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
101976 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
101977 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
101978 + .send_init = vmci_transport_notify_pkt_send_init,
101979 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
101980 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
101981 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
101982 + .process_request = vmci_transport_notify_pkt_process_request,
101983 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
101984 };
101985 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
101986 index 622bd7a..b92086c 100644
101987 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
101988 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
101989 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
101990
101991 /* Socket always on control packet based operations. */
101992 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
101993 - vmci_transport_notify_pkt_socket_init,
101994 - vmci_transport_notify_pkt_socket_destruct,
101995 - vmci_transport_notify_pkt_poll_in,
101996 - vmci_transport_notify_pkt_poll_out,
101997 - vmci_transport_notify_pkt_handle_pkt,
101998 - vmci_transport_notify_pkt_recv_init,
101999 - vmci_transport_notify_pkt_recv_pre_block,
102000 - vmci_transport_notify_pkt_recv_pre_dequeue,
102001 - vmci_transport_notify_pkt_recv_post_dequeue,
102002 - vmci_transport_notify_pkt_send_init,
102003 - vmci_transport_notify_pkt_send_pre_block,
102004 - vmci_transport_notify_pkt_send_pre_enqueue,
102005 - vmci_transport_notify_pkt_send_post_enqueue,
102006 - vmci_transport_notify_pkt_process_request,
102007 - vmci_transport_notify_pkt_process_negotiate,
102008 + .socket_init = vmci_transport_notify_pkt_socket_init,
102009 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
102010 + .poll_in = vmci_transport_notify_pkt_poll_in,
102011 + .poll_out = vmci_transport_notify_pkt_poll_out,
102012 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
102013 + .recv_init = vmci_transport_notify_pkt_recv_init,
102014 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
102015 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
102016 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
102017 + .send_init = vmci_transport_notify_pkt_send_init,
102018 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
102019 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
102020 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
102021 + .process_request = vmci_transport_notify_pkt_process_request,
102022 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
102023 };
102024 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
102025 index c8717c1..08539f5 100644
102026 --- a/net/wireless/wext-core.c
102027 +++ b/net/wireless/wext-core.c
102028 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
102029 */
102030
102031 /* Support for very large requests */
102032 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
102033 - (user_length > descr->max_tokens)) {
102034 + if (user_length > descr->max_tokens) {
102035 /* Allow userspace to GET more than max so
102036 * we can support any size GET requests.
102037 * There is still a limit : -ENOMEM.
102038 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
102039 }
102040 }
102041
102042 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
102043 - /*
102044 - * If this is a GET, but not NOMAX, it means that the extra
102045 - * data is not bounded by userspace, but by max_tokens. Thus
102046 - * set the length to max_tokens. This matches the extra data
102047 - * allocation.
102048 - * The driver should fill it with the number of tokens it
102049 - * provided, and it may check iwp->length rather than having
102050 - * knowledge of max_tokens. If the driver doesn't change the
102051 - * iwp->length, this ioctl just copies back max_token tokens
102052 - * filled with zeroes. Hopefully the driver isn't claiming
102053 - * them to be valid data.
102054 - */
102055 - iwp->length = descr->max_tokens;
102056 - }
102057 -
102058 err = handler(dev, info, (union iwreq_data *) iwp, extra);
102059
102060 iwp->length += essid_compat;
102061 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
102062 index 4323952..a06dfe1 100644
102063 --- a/net/x25/sysctl_net_x25.c
102064 +++ b/net/x25/sysctl_net_x25.c
102065 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
102066 .mode = 0644,
102067 .proc_handler = proc_dointvec,
102068 },
102069 - { 0, },
102070 + { },
102071 };
102072
102073 void __init x25_register_sysctl(void)
102074 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
102075 index 1d5c7bf..f762f1f 100644
102076 --- a/net/xfrm/xfrm_policy.c
102077 +++ b/net/xfrm/xfrm_policy.c
102078 @@ -327,7 +327,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
102079 {
102080 policy->walk.dead = 1;
102081
102082 - atomic_inc(&policy->genid);
102083 + atomic_inc_unchecked(&policy->genid);
102084
102085 if (del_timer(&policy->polq.hold_timer))
102086 xfrm_pol_put(policy);
102087 @@ -661,7 +661,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
102088 hlist_add_head(&policy->bydst, chain);
102089 xfrm_pol_hold(policy);
102090 net->xfrm.policy_count[dir]++;
102091 - atomic_inc(&flow_cache_genid);
102092 + atomic_inc_unchecked(&flow_cache_genid);
102093
102094 /* After previous checking, family can either be AF_INET or AF_INET6 */
102095 if (policy->family == AF_INET)
102096 @@ -1761,7 +1761,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
102097
102098 xdst->num_pols = num_pols;
102099 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
102100 - xdst->policy_genid = atomic_read(&pols[0]->genid);
102101 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
102102
102103 return xdst;
102104 }
102105 @@ -2572,11 +2572,12 @@ void xfrm_garbage_collect(struct net *net)
102106 }
102107 EXPORT_SYMBOL(xfrm_garbage_collect);
102108
102109 -static void xfrm_garbage_collect_deferred(struct net *net)
102110 +void xfrm_garbage_collect_deferred(struct net *net)
102111 {
102112 flow_cache_flush_deferred();
102113 __xfrm_garbage_collect(net);
102114 }
102115 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
102116
102117 static void xfrm_init_pmtu(struct dst_entry *dst)
102118 {
102119 @@ -2626,7 +2627,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
102120 if (xdst->xfrm_genid != dst->xfrm->genid)
102121 return 0;
102122 if (xdst->num_pols > 0 &&
102123 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
102124 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
102125 return 0;
102126
102127 mtu = dst_mtu(dst->child);
102128 @@ -2714,8 +2715,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
102129 dst_ops->link_failure = xfrm_link_failure;
102130 if (likely(dst_ops->neigh_lookup == NULL))
102131 dst_ops->neigh_lookup = xfrm_neigh_lookup;
102132 - if (likely(afinfo->garbage_collect == NULL))
102133 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
102134 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
102135 }
102136 spin_unlock(&xfrm_policy_afinfo_lock);
102137 @@ -2769,7 +2768,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
102138 dst_ops->check = NULL;
102139 dst_ops->negative_advice = NULL;
102140 dst_ops->link_failure = NULL;
102141 - afinfo->garbage_collect = NULL;
102142 }
102143 return err;
102144 }
102145 @@ -3159,7 +3157,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
102146 sizeof(pol->xfrm_vec[i].saddr));
102147 pol->xfrm_vec[i].encap_family = mp->new_family;
102148 /* flush bundles */
102149 - atomic_inc(&pol->genid);
102150 + atomic_inc_unchecked(&pol->genid);
102151 }
102152 }
102153
102154 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
102155 index 40f1b3e..e33fdfa 100644
102156 --- a/net/xfrm/xfrm_state.c
102157 +++ b/net/xfrm/xfrm_state.c
102158 @@ -172,12 +172,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
102159
102160 if (unlikely(afinfo == NULL))
102161 return -EAFNOSUPPORT;
102162 - typemap = afinfo->type_map;
102163 + typemap = (const struct xfrm_type **)afinfo->type_map;
102164 spin_lock_bh(&xfrm_type_lock);
102165
102166 - if (likely(typemap[type->proto] == NULL))
102167 + if (likely(typemap[type->proto] == NULL)) {
102168 + pax_open_kernel();
102169 typemap[type->proto] = type;
102170 - else
102171 + pax_close_kernel();
102172 + } else
102173 err = -EEXIST;
102174 spin_unlock_bh(&xfrm_type_lock);
102175 xfrm_state_put_afinfo(afinfo);
102176 @@ -193,13 +195,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
102177
102178 if (unlikely(afinfo == NULL))
102179 return -EAFNOSUPPORT;
102180 - typemap = afinfo->type_map;
102181 + typemap = (const struct xfrm_type **)afinfo->type_map;
102182 spin_lock_bh(&xfrm_type_lock);
102183
102184 if (unlikely(typemap[type->proto] != type))
102185 err = -ENOENT;
102186 - else
102187 + else {
102188 + pax_open_kernel();
102189 typemap[type->proto] = NULL;
102190 + pax_close_kernel();
102191 + }
102192 spin_unlock_bh(&xfrm_type_lock);
102193 xfrm_state_put_afinfo(afinfo);
102194 return err;
102195 @@ -209,7 +214,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
102196 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
102197 {
102198 struct xfrm_state_afinfo *afinfo;
102199 - const struct xfrm_type **typemap;
102200 const struct xfrm_type *type;
102201 int modload_attempted = 0;
102202
102203 @@ -217,9 +221,8 @@ retry:
102204 afinfo = xfrm_state_get_afinfo(family);
102205 if (unlikely(afinfo == NULL))
102206 return NULL;
102207 - typemap = afinfo->type_map;
102208
102209 - type = typemap[proto];
102210 + type = afinfo->type_map[proto];
102211 if (unlikely(type && !try_module_get(type->owner)))
102212 type = NULL;
102213 if (!type && !modload_attempted) {
102214 @@ -253,7 +256,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
102215 return -EAFNOSUPPORT;
102216
102217 err = -EEXIST;
102218 - modemap = afinfo->mode_map;
102219 + modemap = (struct xfrm_mode **)afinfo->mode_map;
102220 spin_lock_bh(&xfrm_mode_lock);
102221 if (modemap[mode->encap])
102222 goto out;
102223 @@ -262,8 +265,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
102224 if (!try_module_get(afinfo->owner))
102225 goto out;
102226
102227 - mode->afinfo = afinfo;
102228 + pax_open_kernel();
102229 + *(const void **)&mode->afinfo = afinfo;
102230 modemap[mode->encap] = mode;
102231 + pax_close_kernel();
102232 err = 0;
102233
102234 out:
102235 @@ -287,10 +292,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
102236 return -EAFNOSUPPORT;
102237
102238 err = -ENOENT;
102239 - modemap = afinfo->mode_map;
102240 + modemap = (struct xfrm_mode **)afinfo->mode_map;
102241 spin_lock_bh(&xfrm_mode_lock);
102242 if (likely(modemap[mode->encap] == mode)) {
102243 + pax_open_kernel();
102244 modemap[mode->encap] = NULL;
102245 + pax_close_kernel();
102246 module_put(mode->afinfo->owner);
102247 err = 0;
102248 }
102249 @@ -1512,10 +1519,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
102250 u32 xfrm_get_acqseq(void)
102251 {
102252 u32 res;
102253 - static atomic_t acqseq;
102254 + static atomic_unchecked_t acqseq;
102255
102256 do {
102257 - res = atomic_inc_return(&acqseq);
102258 + res = atomic_inc_return_unchecked(&acqseq);
102259 } while (!res);
102260
102261 return res;
102262 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
102263 index 05a6e3d..6716ec9 100644
102264 --- a/net/xfrm/xfrm_sysctl.c
102265 +++ b/net/xfrm/xfrm_sysctl.c
102266 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
102267
102268 int __net_init xfrm_sysctl_init(struct net *net)
102269 {
102270 - struct ctl_table *table;
102271 + ctl_table_no_const *table;
102272
102273 __xfrm_sysctl_init(net);
102274
102275 diff --git a/scripts/Makefile b/scripts/Makefile
102276 index 01e7adb..6176d5d 100644
102277 --- a/scripts/Makefile
102278 +++ b/scripts/Makefile
102279 @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
102280
102281 # Let clean descend into subdirs
102282 subdir- += basic kconfig package selinux
102283 +
102284 +clean-files := randstruct.seed
102285 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
102286 index d5d859c..781cbcb 100644
102287 --- a/scripts/Makefile.build
102288 +++ b/scripts/Makefile.build
102289 @@ -111,7 +111,7 @@ endif
102290 endif
102291
102292 # Do not include host rules unless needed
102293 -ifneq ($(hostprogs-y)$(hostprogs-m),)
102294 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
102295 include scripts/Makefile.host
102296 endif
102297
102298 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
102299 index 686cb0d..9d653bf 100644
102300 --- a/scripts/Makefile.clean
102301 +++ b/scripts/Makefile.clean
102302 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
102303 __clean-files := $(extra-y) $(always) \
102304 $(targets) $(clean-files) \
102305 $(host-progs) \
102306 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
102307 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
102308 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
102309
102310 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
102311
102312 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
102313 index 1ac414f..38575f7 100644
102314 --- a/scripts/Makefile.host
102315 +++ b/scripts/Makefile.host
102316 @@ -31,6 +31,8 @@
102317 # Note: Shared libraries consisting of C++ files are not supported
102318
102319 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
102320 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
102321 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
102322
102323 # C code
102324 # Executables compiled from a single .c file
102325 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
102326 # Shared libaries (only .c supported)
102327 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
102328 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
102329 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
102330 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
102331 # Remove .so files from "xxx-objs"
102332 host-cobjs := $(filter-out %.so,$(host-cobjs))
102333 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
102334
102335 -#Object (.o) files used by the shared libaries
102336 +# Object (.o) files used by the shared libaries
102337 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
102338 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
102339
102340 # output directory for programs/.o files
102341 # hostprogs-y := tools/build may have been specified. Retrieve directory
102342 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
102343 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
102344 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
102345 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
102346 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
102347 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
102348 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
102349 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
102350
102351 obj-dirs += $(host-objdirs)
102352 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
102353 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
102354 $(call if_changed_dep,host-cshobjs)
102355
102356 +# Compile .c file, create position independent .o file
102357 +# host-cxxshobjs -> .o
102358 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
102359 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
102360 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
102361 + $(call if_changed_dep,host-cxxshobjs)
102362 +
102363 # Link a shared library, based on position independent .o files
102364 # *.o -> .so shared library (host-cshlib)
102365 quiet_cmd_host-cshlib = HOSTLLD -shared $@
102366 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
102367 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
102368 $(call if_changed,host-cshlib)
102369
102370 +# Link a shared library, based on position independent .o files
102371 +# *.o -> .so shared library (host-cxxshlib)
102372 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
102373 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
102374 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
102375 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
102376 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
102377 + $(call if_changed,host-cxxshlib)
102378 +
102379 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
102380 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
102381 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
102382
102383 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
102384 index 078fe1d..fbdb363 100644
102385 --- a/scripts/basic/fixdep.c
102386 +++ b/scripts/basic/fixdep.c
102387 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
102388 /*
102389 * Lookup a value in the configuration string.
102390 */
102391 -static int is_defined_config(const char *name, int len, unsigned int hash)
102392 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
102393 {
102394 struct item *aux;
102395
102396 @@ -211,10 +211,10 @@ static void clear_config(void)
102397 /*
102398 * Record the use of a CONFIG_* word.
102399 */
102400 -static void use_config(const char *m, int slen)
102401 +static void use_config(const char *m, unsigned int slen)
102402 {
102403 unsigned int hash = strhash(m, slen);
102404 - int c, i;
102405 + unsigned int c, i;
102406
102407 if (is_defined_config(m, slen, hash))
102408 return;
102409 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
102410
102411 static void parse_config_file(const char *map, size_t len)
102412 {
102413 - const int *end = (const int *) (map + len);
102414 + const unsigned int *end = (const unsigned int *) (map + len);
102415 /* start at +1, so that p can never be < map */
102416 - const int *m = (const int *) map + 1;
102417 + const unsigned int *m = (const unsigned int *) map + 1;
102418 const char *p, *q;
102419
102420 for (; m < end; m++) {
102421 @@ -435,7 +435,7 @@ static void print_deps(void)
102422 static void traps(void)
102423 {
102424 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
102425 - int *p = (int *)test;
102426 + unsigned int *p = (unsigned int *)test;
102427
102428 if (*p != INT_CONF) {
102429 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
102430 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
102431 new file mode 100644
102432 index 0000000..edcbc3a
102433 --- /dev/null
102434 +++ b/scripts/gcc-plugin.sh
102435 @@ -0,0 +1,16 @@
102436 +#!/bin/bash
102437 +srctree=$(dirname "$0")
102438 +gccplugins_dir=$($3 -print-file-name=plugin)
102439 +plugincc=$($1 -E -shared - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
102440 +#include "gcc-common.h"
102441 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
102442 +#warning $2
102443 +#else
102444 +#warning $1
102445 +#endif
102446 +EOF
102447 +)
102448 +if [ $? -eq 0 ]
102449 +then
102450 + ( [[ "$plugincc" =~ "$1" ]] && echo "$1" ) || ( [[ "$plugincc" =~ "$2" ]] && echo "$2" )
102451 +fi
102452 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
102453 index 5de5660..d3deb89 100644
102454 --- a/scripts/headers_install.sh
102455 +++ b/scripts/headers_install.sh
102456 @@ -32,6 +32,7 @@ do
102457 FILE="$(basename "$i")"
102458 sed -r \
102459 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
102460 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
102461 -e 's/__attribute_const__([ \t]|$)/\1/g' \
102462 -e 's@^#include <linux/compiler.h>@@' \
102463 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
102464 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
102465 index 2dcb377..a82c500 100644
102466 --- a/scripts/link-vmlinux.sh
102467 +++ b/scripts/link-vmlinux.sh
102468 @@ -162,7 +162,7 @@ else
102469 fi;
102470
102471 # final build of init/
102472 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
102473 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
102474
102475 kallsymso=""
102476 kallsyms_vmlinux=""
102477 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
102478 index 25e5cb0..6e85821 100644
102479 --- a/scripts/mod/file2alias.c
102480 +++ b/scripts/mod/file2alias.c
102481 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
102482 unsigned long size, unsigned long id_size,
102483 void *symval)
102484 {
102485 - int i;
102486 + unsigned int i;
102487
102488 if (size % id_size || size < id_size) {
102489 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
102490 @@ -170,7 +170,7 @@ static void device_id_check(const char *modname, const char *device_id,
102491 /* USB is special because the bcdDevice can be matched against a numeric range */
102492 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
102493 static void do_usb_entry(void *symval,
102494 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
102495 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
102496 unsigned char range_lo, unsigned char range_hi,
102497 unsigned char max, struct module *mod)
102498 {
102499 @@ -280,7 +280,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
102500 {
102501 unsigned int devlo, devhi;
102502 unsigned char chi, clo, max;
102503 - int ndigits;
102504 + unsigned int ndigits;
102505
102506 DEF_FIELD(symval, usb_device_id, match_flags);
102507 DEF_FIELD(symval, usb_device_id, idVendor);
102508 @@ -533,7 +533,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
102509 for (i = 0; i < count; i++) {
102510 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
102511 char acpi_id[sizeof(*id)];
102512 - int j;
102513 + unsigned int j;
102514
102515 buf_printf(&mod->dev_table_buf,
102516 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
102517 @@ -562,7 +562,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
102518
102519 for (j = 0; j < PNP_MAX_DEVICES; j++) {
102520 const char *id = (char *)(*devs)[j].id;
102521 - int i2, j2;
102522 + unsigned int i2, j2;
102523 int dup = 0;
102524
102525 if (!id[0])
102526 @@ -588,7 +588,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
102527 /* add an individual alias for every device entry */
102528 if (!dup) {
102529 char acpi_id[PNP_ID_LEN];
102530 - int k;
102531 + unsigned int k;
102532
102533 buf_printf(&mod->dev_table_buf,
102534 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
102535 @@ -940,7 +940,7 @@ static void dmi_ascii_filter(char *d, const char *s)
102536 static int do_dmi_entry(const char *filename, void *symval,
102537 char *alias)
102538 {
102539 - int i, j;
102540 + unsigned int i, j;
102541 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
102542 sprintf(alias, "dmi*");
102543
102544 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
102545 index 99a45fd..4b995a3 100644
102546 --- a/scripts/mod/modpost.c
102547 +++ b/scripts/mod/modpost.c
102548 @@ -945,6 +945,7 @@ enum mismatch {
102549 ANY_INIT_TO_ANY_EXIT,
102550 ANY_EXIT_TO_ANY_INIT,
102551 EXPORT_TO_INIT_EXIT,
102552 + DATA_TO_TEXT
102553 };
102554
102555 struct sectioncheck {
102556 @@ -1031,6 +1032,12 @@ const struct sectioncheck sectioncheck[] = {
102557 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
102558 .mismatch = EXPORT_TO_INIT_EXIT,
102559 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
102560 +},
102561 +/* Do not reference code from writable data */
102562 +{
102563 + .fromsec = { DATA_SECTIONS, NULL },
102564 + .tosec = { TEXT_SECTIONS, NULL },
102565 + .mismatch = DATA_TO_TEXT
102566 }
102567 };
102568
102569 @@ -1151,10 +1158,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
102570 continue;
102571 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
102572 continue;
102573 - if (sym->st_value == addr)
102574 - return sym;
102575 /* Find a symbol nearby - addr are maybe negative */
102576 d = sym->st_value - addr;
102577 + if (d == 0)
102578 + return sym;
102579 if (d < 0)
102580 d = addr - sym->st_value;
102581 if (d < distance) {
102582 @@ -1432,6 +1439,14 @@ static void report_sec_mismatch(const char *modname,
102583 tosym, prl_to, prl_to, tosym);
102584 free(prl_to);
102585 break;
102586 + case DATA_TO_TEXT:
102587 +#if 0
102588 + fprintf(stderr,
102589 + "The %s %s:%s references\n"
102590 + "the %s %s:%s%s\n",
102591 + from, fromsec, fromsym, to, tosec, tosym, to_p);
102592 +#endif
102593 + break;
102594 }
102595 fprintf(stderr, "\n");
102596 }
102597 @@ -1679,7 +1694,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
102598 static void check_sec_ref(struct module *mod, const char *modname,
102599 struct elf_info *elf)
102600 {
102601 - int i;
102602 + unsigned int i;
102603 Elf_Shdr *sechdrs = elf->sechdrs;
102604
102605 /* Walk through all sections */
102606 @@ -1798,7 +1813,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
102607 va_end(ap);
102608 }
102609
102610 -void buf_write(struct buffer *buf, const char *s, int len)
102611 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
102612 {
102613 if (buf->size - buf->pos < len) {
102614 buf->size += len + SZ;
102615 @@ -2017,7 +2032,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
102616 if (fstat(fileno(file), &st) < 0)
102617 goto close_write;
102618
102619 - if (st.st_size != b->pos)
102620 + if (st.st_size != (off_t)b->pos)
102621 goto close_write;
102622
102623 tmp = NOFAIL(malloc(b->pos));
102624 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
102625 index 51207e4..f7d603d 100644
102626 --- a/scripts/mod/modpost.h
102627 +++ b/scripts/mod/modpost.h
102628 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
102629
102630 struct buffer {
102631 char *p;
102632 - int pos;
102633 - int size;
102634 + unsigned int pos;
102635 + unsigned int size;
102636 };
102637
102638 void __attribute__((format(printf, 2, 3)))
102639 buf_printf(struct buffer *buf, const char *fmt, ...);
102640
102641 void
102642 -buf_write(struct buffer *buf, const char *s, int len);
102643 +buf_write(struct buffer *buf, const char *s, unsigned int len);
102644
102645 struct module {
102646 struct module *next;
102647 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
102648 index deb2994..af4f63e 100644
102649 --- a/scripts/mod/sumversion.c
102650 +++ b/scripts/mod/sumversion.c
102651 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
102652 goto out;
102653 }
102654
102655 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
102656 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
102657 warn("writing sum in %s failed: %s\n",
102658 filename, strerror(errno));
102659 goto out;
102660 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
102661 index 0865b3e..7235dd4 100644
102662 --- a/scripts/module-common.lds
102663 +++ b/scripts/module-common.lds
102664 @@ -6,6 +6,10 @@
102665 SECTIONS {
102666 /DISCARD/ : { *(.discard) }
102667
102668 + .rodata : {
102669 + *(.rodata) *(.rodata.*)
102670 + *(.data..read_only)
102671 + }
102672 __ksymtab : { *(SORT(___ksymtab+*)) }
102673 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
102674 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
102675 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
102676 index f46e4dd..090e168 100644
102677 --- a/scripts/package/builddeb
102678 +++ b/scripts/package/builddeb
102679 @@ -291,6 +291,7 @@ fi
102680 (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
102681 (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
102682 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
102683 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
102684 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
102685 mkdir -p "$destdir"
102686 (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
102687 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
102688 index 68bb4ef..2f419e1 100644
102689 --- a/scripts/pnmtologo.c
102690 +++ b/scripts/pnmtologo.c
102691 @@ -244,14 +244,14 @@ static void write_header(void)
102692 fprintf(out, " * Linux logo %s\n", logoname);
102693 fputs(" */\n\n", out);
102694 fputs("#include <linux/linux_logo.h>\n\n", out);
102695 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
102696 + fprintf(out, "static unsigned char %s_data[] = {\n",
102697 logoname);
102698 }
102699
102700 static void write_footer(void)
102701 {
102702 fputs("\n};\n\n", out);
102703 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
102704 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
102705 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
102706 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
102707 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
102708 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
102709 fputs("\n};\n\n", out);
102710
102711 /* write logo clut */
102712 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
102713 + fprintf(out, "static unsigned char %s_clut[] = {\n",
102714 logoname);
102715 write_hex_cnt = 0;
102716 for (i = 0; i < logo_clutsize; i++) {
102717 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
102718 index 8fac3fd..32ff38d 100644
102719 --- a/scripts/sortextable.h
102720 +++ b/scripts/sortextable.h
102721 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
102722 const char *secstrtab;
102723 const char *strtab;
102724 char *extab_image;
102725 - int extab_index = 0;
102726 - int i;
102727 - int idx;
102728 + unsigned int extab_index = 0;
102729 + unsigned int i;
102730 + unsigned int idx;
102731 unsigned int num_sections;
102732 unsigned int secindex_strings;
102733
102734 diff --git a/security/Kconfig b/security/Kconfig
102735 index beb86b5..1ea5a01 100644
102736 --- a/security/Kconfig
102737 +++ b/security/Kconfig
102738 @@ -4,6 +4,960 @@
102739
102740 menu "Security options"
102741
102742 +menu "Grsecurity"
102743 +
102744 + config ARCH_TRACK_EXEC_LIMIT
102745 + bool
102746 +
102747 + config PAX_KERNEXEC_PLUGIN
102748 + bool
102749 +
102750 + config PAX_PER_CPU_PGD
102751 + bool
102752 +
102753 + config TASK_SIZE_MAX_SHIFT
102754 + int
102755 + depends on X86_64
102756 + default 47 if !PAX_PER_CPU_PGD
102757 + default 42 if PAX_PER_CPU_PGD
102758 +
102759 + config PAX_ENABLE_PAE
102760 + bool
102761 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
102762 +
102763 + config PAX_USERCOPY_SLABS
102764 + bool
102765 +
102766 +config GRKERNSEC
102767 + bool "Grsecurity"
102768 + select CRYPTO
102769 + select CRYPTO_SHA256
102770 + select PROC_FS
102771 + select STOP_MACHINE
102772 + select TTY
102773 + select DEBUG_KERNEL
102774 + select DEBUG_LIST
102775 + help
102776 + If you say Y here, you will be able to configure many features
102777 + that will enhance the security of your system. It is highly
102778 + recommended that you say Y here and read through the help
102779 + for each option so that you fully understand the features and
102780 + can evaluate their usefulness for your machine.
102781 +
102782 +choice
102783 + prompt "Configuration Method"
102784 + depends on GRKERNSEC
102785 + default GRKERNSEC_CONFIG_CUSTOM
102786 + help
102787 +
102788 +config GRKERNSEC_CONFIG_AUTO
102789 + bool "Automatic"
102790 + help
102791 + If you choose this configuration method, you'll be able to answer a small
102792 + number of simple questions about how you plan to use this kernel.
102793 + The settings of grsecurity and PaX will be automatically configured for
102794 + the highest commonly-used settings within the provided constraints.
102795 +
102796 + If you require additional configuration, custom changes can still be made
102797 + from the "custom configuration" menu.
102798 +
102799 +config GRKERNSEC_CONFIG_CUSTOM
102800 + bool "Custom"
102801 + help
102802 + If you choose this configuration method, you'll be able to configure all
102803 + grsecurity and PaX settings manually. Via this method, no options are
102804 + automatically enabled.
102805 +
102806 +endchoice
102807 +
102808 +choice
102809 + prompt "Usage Type"
102810 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
102811 + default GRKERNSEC_CONFIG_SERVER
102812 + help
102813 +
102814 +config GRKERNSEC_CONFIG_SERVER
102815 + bool "Server"
102816 + help
102817 + Choose this option if you plan to use this kernel on a server.
102818 +
102819 +config GRKERNSEC_CONFIG_DESKTOP
102820 + bool "Desktop"
102821 + help
102822 + Choose this option if you plan to use this kernel on a desktop.
102823 +
102824 +endchoice
102825 +
102826 +choice
102827 + prompt "Virtualization Type"
102828 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
102829 + default GRKERNSEC_CONFIG_VIRT_NONE
102830 + help
102831 +
102832 +config GRKERNSEC_CONFIG_VIRT_NONE
102833 + bool "None"
102834 + help
102835 + Choose this option if this kernel will be run on bare metal.
102836 +
102837 +config GRKERNSEC_CONFIG_VIRT_GUEST
102838 + bool "Guest"
102839 + help
102840 + Choose this option if this kernel will be run as a VM guest.
102841 +
102842 +config GRKERNSEC_CONFIG_VIRT_HOST
102843 + bool "Host"
102844 + help
102845 + Choose this option if this kernel will be run as a VM host.
102846 +
102847 +endchoice
102848 +
102849 +choice
102850 + prompt "Virtualization Hardware"
102851 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
102852 + help
102853 +
102854 +config GRKERNSEC_CONFIG_VIRT_EPT
102855 + bool "EPT/RVI Processor Support"
102856 + depends on X86
102857 + help
102858 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
102859 + hardware virtualization. This allows for additional kernel hardening protections
102860 + to operate without additional performance impact.
102861 +
102862 + To see if your Intel processor supports EPT, see:
102863 + http://ark.intel.com/Products/VirtualizationTechnology
102864 + (Most Core i3/5/7 support EPT)
102865 +
102866 + To see if your AMD processor supports RVI, see:
102867 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
102868 +
102869 +config GRKERNSEC_CONFIG_VIRT_SOFT
102870 + bool "First-gen/No Hardware Virtualization"
102871 + help
102872 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
102873 + support hardware virtualization or doesn't support the EPT/RVI extensions.
102874 +
102875 +endchoice
102876 +
102877 +choice
102878 + prompt "Virtualization Software"
102879 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
102880 + help
102881 +
102882 +config GRKERNSEC_CONFIG_VIRT_XEN
102883 + bool "Xen"
102884 + help
102885 + Choose this option if this kernel is running as a Xen guest or host.
102886 +
102887 +config GRKERNSEC_CONFIG_VIRT_VMWARE
102888 + bool "VMWare"
102889 + help
102890 + Choose this option if this kernel is running as a VMWare guest or host.
102891 +
102892 +config GRKERNSEC_CONFIG_VIRT_KVM
102893 + bool "KVM"
102894 + help
102895 + Choose this option if this kernel is running as a KVM guest or host.
102896 +
102897 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
102898 + bool "VirtualBox"
102899 + help
102900 + Choose this option if this kernel is running as a VirtualBox guest or host.
102901 +
102902 +endchoice
102903 +
102904 +choice
102905 + prompt "Required Priorities"
102906 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
102907 + default GRKERNSEC_CONFIG_PRIORITY_PERF
102908 + help
102909 +
102910 +config GRKERNSEC_CONFIG_PRIORITY_PERF
102911 + bool "Performance"
102912 + help
102913 + Choose this option if performance is of highest priority for this deployment
102914 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
102915 + clearing of structures intended for userland, and freed memory sanitizing will
102916 + be disabled.
102917 +
102918 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
102919 + bool "Security"
102920 + help
102921 + Choose this option if security is of highest priority for this deployment of
102922 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
102923 + for userland, and freed memory sanitizing will be enabled for this kernel.
102924 + In a worst-case scenario, these features can introduce a 20% performance hit
102925 + (UDEREF on x64 contributing half of this hit).
102926 +
102927 +endchoice
102928 +
102929 +menu "Default Special Groups"
102930 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
102931 +
102932 +config GRKERNSEC_PROC_GID
102933 + int "GID exempted from /proc restrictions"
102934 + default 1001
102935 + help
102936 + Setting this GID determines which group will be exempted from
102937 + grsecurity's /proc restrictions, allowing users of the specified
102938 + group to view network statistics and the existence of other users'
102939 + processes on the system. This GID may also be chosen at boot time
102940 + via "grsec_proc_gid=" on the kernel commandline.
102941 +
102942 +config GRKERNSEC_TPE_UNTRUSTED_GID
102943 + int "GID for TPE-untrusted users"
102944 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
102945 + default 1005
102946 + help
102947 + Setting this GID determines which group untrusted users should
102948 + be added to. These users will be placed under grsecurity's Trusted Path
102949 + Execution mechanism, preventing them from executing their own binaries.
102950 + The users will only be able to execute binaries in directories owned and
102951 + writable only by the root user. If the sysctl option is enabled, a sysctl
102952 + option with name "tpe_gid" is created.
102953 +
102954 +config GRKERNSEC_TPE_TRUSTED_GID
102955 + int "GID for TPE-trusted users"
102956 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
102957 + default 1005
102958 + help
102959 + Setting this GID determines what group TPE restrictions will be
102960 + *disabled* for. If the sysctl option is enabled, a sysctl option
102961 + with name "tpe_gid" is created.
102962 +
102963 +config GRKERNSEC_SYMLINKOWN_GID
102964 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
102965 + depends on GRKERNSEC_CONFIG_SERVER
102966 + default 1006
102967 + help
102968 + Setting this GID determines what group kernel-enforced
102969 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
102970 + is enabled, a sysctl option with name "symlinkown_gid" is created.
102971 +
102972 +
102973 +endmenu
102974 +
102975 +menu "Customize Configuration"
102976 +depends on GRKERNSEC
102977 +
102978 +menu "PaX"
102979 +
102980 +config PAX
102981 + bool "Enable various PaX features"
102982 + default y if GRKERNSEC_CONFIG_AUTO
102983 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
102984 + help
102985 + This allows you to enable various PaX features. PaX adds
102986 + intrusion prevention mechanisms to the kernel that reduce
102987 + the risks posed by exploitable memory corruption bugs.
102988 +
102989 +menu "PaX Control"
102990 + depends on PAX
102991 +
102992 +config PAX_SOFTMODE
102993 + bool 'Support soft mode'
102994 + help
102995 + Enabling this option will allow you to run PaX in soft mode, that
102996 + is, PaX features will not be enforced by default, only on executables
102997 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
102998 + support as they are the only way to mark executables for soft mode use.
102999 +
103000 + Soft mode can be activated by using the "pax_softmode=1" kernel command
103001 + line option on boot. Furthermore you can control various PaX features
103002 + at runtime via the entries in /proc/sys/kernel/pax.
103003 +
103004 +config PAX_EI_PAX
103005 + bool 'Use legacy ELF header marking'
103006 + default y if GRKERNSEC_CONFIG_AUTO
103007 + help
103008 + Enabling this option will allow you to control PaX features on
103009 + a per executable basis via the 'chpax' utility available at
103010 + http://pax.grsecurity.net/. The control flags will be read from
103011 + an otherwise reserved part of the ELF header. This marking has
103012 + numerous drawbacks (no support for soft-mode, toolchain does not
103013 + know about the non-standard use of the ELF header) therefore it
103014 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
103015 + support.
103016 +
103017 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
103018 + support as well, they will override the legacy EI_PAX marks.
103019 +
103020 + If you enable none of the marking options then all applications
103021 + will run with PaX enabled on them by default.
103022 +
103023 +config PAX_PT_PAX_FLAGS
103024 + bool 'Use ELF program header marking'
103025 + default y if GRKERNSEC_CONFIG_AUTO
103026 + help
103027 + Enabling this option will allow you to control PaX features on
103028 + a per executable basis via the 'paxctl' utility available at
103029 + http://pax.grsecurity.net/. The control flags will be read from
103030 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
103031 + has the benefits of supporting both soft mode and being fully
103032 + integrated into the toolchain (the binutils patch is available
103033 + from http://pax.grsecurity.net).
103034 +
103035 + Note that if you enable the legacy EI_PAX marking support as well,
103036 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
103037 +
103038 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
103039 + must make sure that the marks are the same if a binary has both marks.
103040 +
103041 + If you enable none of the marking options then all applications
103042 + will run with PaX enabled on them by default.
103043 +
103044 +config PAX_XATTR_PAX_FLAGS
103045 + bool 'Use filesystem extended attributes marking'
103046 + default y if GRKERNSEC_CONFIG_AUTO
103047 + select CIFS_XATTR if CIFS
103048 + select EXT2_FS_XATTR if EXT2_FS
103049 + select EXT3_FS_XATTR if EXT3_FS
103050 + select JFFS2_FS_XATTR if JFFS2_FS
103051 + select REISERFS_FS_XATTR if REISERFS_FS
103052 + select SQUASHFS_XATTR if SQUASHFS
103053 + select TMPFS_XATTR if TMPFS
103054 + select UBIFS_FS_XATTR if UBIFS_FS
103055 + help
103056 + Enabling this option will allow you to control PaX features on
103057 + a per executable basis via the 'setfattr' utility. The control
103058 + flags will be read from the user.pax.flags extended attribute of
103059 + the file. This marking has the benefit of supporting binary-only
103060 + applications that self-check themselves (e.g., skype) and would
103061 + not tolerate chpax/paxctl changes. The main drawback is that
103062 + extended attributes are not supported by some filesystems (e.g.,
103063 + isofs, udf, vfat) so copying files through such filesystems will
103064 + lose the extended attributes and these PaX markings.
103065 +
103066 + Note that if you enable the legacy EI_PAX marking support as well,
103067 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
103068 +
103069 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
103070 + must make sure that the marks are the same if a binary has both marks.
103071 +
103072 + If you enable none of the marking options then all applications
103073 + will run with PaX enabled on them by default.
103074 +
103075 +choice
103076 + prompt 'MAC system integration'
103077 + default PAX_HAVE_ACL_FLAGS
103078 + help
103079 + Mandatory Access Control systems have the option of controlling
103080 + PaX flags on a per executable basis, choose the method supported
103081 + by your particular system.
103082 +
103083 + - "none": if your MAC system does not interact with PaX,
103084 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
103085 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
103086 +
103087 + NOTE: this option is for developers/integrators only.
103088 +
103089 + config PAX_NO_ACL_FLAGS
103090 + bool 'none'
103091 +
103092 + config PAX_HAVE_ACL_FLAGS
103093 + bool 'direct'
103094 +
103095 + config PAX_HOOK_ACL_FLAGS
103096 + bool 'hook'
103097 +endchoice
103098 +
103099 +endmenu
103100 +
103101 +menu "Non-executable pages"
103102 + depends on PAX
103103 +
103104 +config PAX_NOEXEC
103105 + bool "Enforce non-executable pages"
103106 + default y if GRKERNSEC_CONFIG_AUTO
103107 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
103108 + help
103109 + By design some architectures do not allow for protecting memory
103110 + pages against execution or even if they do, Linux does not make
103111 + use of this feature. In practice this means that if a page is
103112 + readable (such as the stack or heap) it is also executable.
103113 +
103114 + There is a well known exploit technique that makes use of this
103115 + fact and a common programming mistake where an attacker can
103116 + introduce code of his choice somewhere in the attacked program's
103117 + memory (typically the stack or the heap) and then execute it.
103118 +
103119 + If the attacked program was running with different (typically
103120 + higher) privileges than that of the attacker, then he can elevate
103121 + his own privilege level (e.g. get a root shell, write to files for
103122 + which he does not have write access to, etc).
103123 +
103124 + Enabling this option will let you choose from various features
103125 + that prevent the injection and execution of 'foreign' code in
103126 + a program.
103127 +
103128 + This will also break programs that rely on the old behaviour and
103129 + expect that dynamically allocated memory via the malloc() family
103130 + of functions is executable (which it is not). Notable examples
103131 + are the XFree86 4.x server, the java runtime and wine.
103132 +
103133 +config PAX_PAGEEXEC
103134 + bool "Paging based non-executable pages"
103135 + default y if GRKERNSEC_CONFIG_AUTO
103136 + 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)
103137 + select ARCH_TRACK_EXEC_LIMIT if X86_32
103138 + help
103139 + This implementation is based on the paging feature of the CPU.
103140 + On i386 without hardware non-executable bit support there is a
103141 + variable but usually low performance impact, however on Intel's
103142 + P4 core based CPUs it is very high so you should not enable this
103143 + for kernels meant to be used on such CPUs.
103144 +
103145 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
103146 + with hardware non-executable bit support there is no performance
103147 + impact, on ppc the impact is negligible.
103148 +
103149 + Note that several architectures require various emulations due to
103150 + badly designed userland ABIs, this will cause a performance impact
103151 + but will disappear as soon as userland is fixed. For example, ppc
103152 + userland MUST have been built with secure-plt by a recent toolchain.
103153 +
103154 +config PAX_SEGMEXEC
103155 + bool "Segmentation based non-executable pages"
103156 + default y if GRKERNSEC_CONFIG_AUTO
103157 + depends on PAX_NOEXEC && X86_32
103158 + help
103159 + This implementation is based on the segmentation feature of the
103160 + CPU and has a very small performance impact, however applications
103161 + will be limited to a 1.5 GB address space instead of the normal
103162 + 3 GB.
103163 +
103164 +config PAX_EMUTRAMP
103165 + bool "Emulate trampolines"
103166 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
103167 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
103168 + help
103169 + There are some programs and libraries that for one reason or
103170 + another attempt to execute special small code snippets from
103171 + non-executable memory pages. Most notable examples are the
103172 + signal handler return code generated by the kernel itself and
103173 + the GCC trampolines.
103174 +
103175 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
103176 + such programs will no longer work under your kernel.
103177 +
103178 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
103179 + utilities to enable trampoline emulation for the affected programs
103180 + yet still have the protection provided by the non-executable pages.
103181 +
103182 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
103183 + your system will not even boot.
103184 +
103185 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
103186 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
103187 + for the affected files.
103188 +
103189 + NOTE: enabling this feature *may* open up a loophole in the
103190 + protection provided by non-executable pages that an attacker
103191 + could abuse. Therefore the best solution is to not have any
103192 + files on your system that would require this option. This can
103193 + be achieved by not using libc5 (which relies on the kernel
103194 + signal handler return code) and not using or rewriting programs
103195 + that make use of the nested function implementation of GCC.
103196 + Skilled users can just fix GCC itself so that it implements
103197 + nested function calls in a way that does not interfere with PaX.
103198 +
103199 +config PAX_EMUSIGRT
103200 + bool "Automatically emulate sigreturn trampolines"
103201 + depends on PAX_EMUTRAMP && PARISC
103202 + default y
103203 + help
103204 + Enabling this option will have the kernel automatically detect
103205 + and emulate signal return trampolines executing on the stack
103206 + that would otherwise lead to task termination.
103207 +
103208 + This solution is intended as a temporary one for users with
103209 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
103210 + Modula-3 runtime, etc) or executables linked to such, basically
103211 + everything that does not specify its own SA_RESTORER function in
103212 + normal executable memory like glibc 2.1+ does.
103213 +
103214 + On parisc you MUST enable this option, otherwise your system will
103215 + not even boot.
103216 +
103217 + NOTE: this feature cannot be disabled on a per executable basis
103218 + and since it *does* open up a loophole in the protection provided
103219 + by non-executable pages, the best solution is to not have any
103220 + files on your system that would require this option.
103221 +
103222 +config PAX_MPROTECT
103223 + bool "Restrict mprotect()"
103224 + default y if GRKERNSEC_CONFIG_AUTO
103225 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
103226 + help
103227 + Enabling this option will prevent programs from
103228 + - changing the executable status of memory pages that were
103229 + not originally created as executable,
103230 + - making read-only executable pages writable again,
103231 + - creating executable pages from anonymous memory,
103232 + - making read-only-after-relocations (RELRO) data pages writable again.
103233 +
103234 + You should say Y here to complete the protection provided by
103235 + the enforcement of non-executable pages.
103236 +
103237 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
103238 + this feature on a per file basis.
103239 +
103240 +config PAX_MPROTECT_COMPAT
103241 + bool "Use legacy/compat protection demoting (read help)"
103242 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
103243 + depends on PAX_MPROTECT
103244 + help
103245 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
103246 + by sending the proper error code to the application. For some broken
103247 + userland, this can cause problems with Python or other applications. The
103248 + current implementation however allows for applications like clamav to
103249 + detect if JIT compilation/execution is allowed and to fall back gracefully
103250 + to an interpreter-based mode if it does not. While we encourage everyone
103251 + to use the current implementation as-is and push upstream to fix broken
103252 + userland (note that the RWX logging option can assist with this), in some
103253 + environments this may not be possible. Having to disable MPROTECT
103254 + completely on certain binaries reduces the security benefit of PaX,
103255 + so this option is provided for those environments to revert to the old
103256 + behavior.
103257 +
103258 +config PAX_ELFRELOCS
103259 + bool "Allow ELF text relocations (read help)"
103260 + depends on PAX_MPROTECT
103261 + default n
103262 + help
103263 + Non-executable pages and mprotect() restrictions are effective
103264 + in preventing the introduction of new executable code into an
103265 + attacked task's address space. There remain only two venues
103266 + for this kind of attack: if the attacker can execute already
103267 + existing code in the attacked task then he can either have it
103268 + create and mmap() a file containing his code or have it mmap()
103269 + an already existing ELF library that does not have position
103270 + independent code in it and use mprotect() on it to make it
103271 + writable and copy his code there. While protecting against
103272 + the former approach is beyond PaX, the latter can be prevented
103273 + by having only PIC ELF libraries on one's system (which do not
103274 + need to relocate their code). If you are sure this is your case,
103275 + as is the case with all modern Linux distributions, then leave
103276 + this option disabled. You should say 'n' here.
103277 +
103278 +config PAX_ETEXECRELOCS
103279 + bool "Allow ELF ET_EXEC text relocations"
103280 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
103281 + select PAX_ELFRELOCS
103282 + default y
103283 + help
103284 + On some architectures there are incorrectly created applications
103285 + that require text relocations and would not work without enabling
103286 + this option. If you are an alpha, ia64 or parisc user, you should
103287 + enable this option and disable it once you have made sure that
103288 + none of your applications need it.
103289 +
103290 +config PAX_EMUPLT
103291 + bool "Automatically emulate ELF PLT"
103292 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
103293 + default y
103294 + help
103295 + Enabling this option will have the kernel automatically detect
103296 + and emulate the Procedure Linkage Table entries in ELF files.
103297 + On some architectures such entries are in writable memory, and
103298 + become non-executable leading to task termination. Therefore
103299 + it is mandatory that you enable this option on alpha, parisc,
103300 + sparc and sparc64, otherwise your system would not even boot.
103301 +
103302 + NOTE: this feature *does* open up a loophole in the protection
103303 + provided by the non-executable pages, therefore the proper
103304 + solution is to modify the toolchain to produce a PLT that does
103305 + not need to be writable.
103306 +
103307 +config PAX_DLRESOLVE
103308 + bool 'Emulate old glibc resolver stub'
103309 + depends on PAX_EMUPLT && SPARC
103310 + default n
103311 + help
103312 + This option is needed if userland has an old glibc (before 2.4)
103313 + that puts a 'save' instruction into the runtime generated resolver
103314 + stub that needs special emulation.
103315 +
103316 +config PAX_KERNEXEC
103317 + bool "Enforce non-executable kernel pages"
103318 + default y if GRKERNSEC_CONFIG_AUTO && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_GUEST) || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_KVM))
103319 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
103320 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
103321 + select PAX_KERNEXEC_PLUGIN if X86_64
103322 + help
103323 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
103324 + that is, enabling this option will make it harder to inject
103325 + and execute 'foreign' code in kernel memory itself.
103326 +
103327 +choice
103328 + prompt "Return Address Instrumentation Method"
103329 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
103330 + depends on PAX_KERNEXEC_PLUGIN
103331 + help
103332 + Select the method used to instrument function pointer dereferences.
103333 + Note that binary modules cannot be instrumented by this approach.
103334 +
103335 + Note that the implementation requires a gcc with plugin support,
103336 + i.e., gcc 4.5 or newer. You may need to install the supporting
103337 + headers explicitly in addition to the normal gcc package.
103338 +
103339 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
103340 + bool "bts"
103341 + help
103342 + This method is compatible with binary only modules but has
103343 + a higher runtime overhead.
103344 +
103345 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
103346 + bool "or"
103347 + depends on !PARAVIRT
103348 + help
103349 + This method is incompatible with binary only modules but has
103350 + a lower runtime overhead.
103351 +endchoice
103352 +
103353 +config PAX_KERNEXEC_PLUGIN_METHOD
103354 + string
103355 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
103356 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
103357 + default ""
103358 +
103359 +config PAX_KERNEXEC_MODULE_TEXT
103360 + int "Minimum amount of memory reserved for module code"
103361 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
103362 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
103363 + depends on PAX_KERNEXEC && X86_32
103364 + help
103365 + Due to implementation details the kernel must reserve a fixed
103366 + amount of memory for runtime allocated code (such as modules)
103367 + at compile time that cannot be changed at runtime. Here you
103368 + can specify the minimum amount in MB that will be reserved.
103369 + Due to the same implementation details this size will always
103370 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
103371 + the actually available memory for runtime allocated code will
103372 + usually be more than this minimum.
103373 +
103374 + The default 4 MB should be enough for most users but if you have
103375 + an excessive number of modules (e.g., most distribution configs
103376 + compile many drivers as modules) or use huge modules such as
103377 + nvidia's kernel driver, you will need to adjust this amount.
103378 + A good rule of thumb is to look at your currently loaded kernel
103379 + modules and add up their sizes.
103380 +
103381 +endmenu
103382 +
103383 +menu "Address Space Layout Randomization"
103384 + depends on PAX
103385 +
103386 +config PAX_ASLR
103387 + bool "Address Space Layout Randomization"
103388 + default y if GRKERNSEC_CONFIG_AUTO
103389 + help
103390 + Many if not most exploit techniques rely on the knowledge of
103391 + certain addresses in the attacked program. The following options
103392 + will allow the kernel to apply a certain amount of randomization
103393 + to specific parts of the program thereby forcing an attacker to
103394 + guess them in most cases. Any failed guess will most likely crash
103395 + the attacked program which allows the kernel to detect such attempts
103396 + and react on them. PaX itself provides no reaction mechanisms,
103397 + instead it is strongly encouraged that you make use of Nergal's
103398 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
103399 + (http://www.grsecurity.net/) built-in crash detection features or
103400 + develop one yourself.
103401 +
103402 + By saying Y here you can choose to randomize the following areas:
103403 + - top of the task's kernel stack
103404 + - top of the task's userland stack
103405 + - base address for mmap() requests that do not specify one
103406 + (this includes all libraries)
103407 + - base address of the main executable
103408 +
103409 + It is strongly recommended to say Y here as address space layout
103410 + randomization has negligible impact on performance yet it provides
103411 + a very effective protection.
103412 +
103413 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
103414 + this feature on a per file basis.
103415 +
103416 +config PAX_RANDKSTACK
103417 + bool "Randomize kernel stack base"
103418 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
103419 + depends on X86_TSC && X86
103420 + help
103421 + By saying Y here the kernel will randomize every task's kernel
103422 + stack on every system call. This will not only force an attacker
103423 + to guess it but also prevent him from making use of possible
103424 + leaked information about it.
103425 +
103426 + Since the kernel stack is a rather scarce resource, randomization
103427 + may cause unexpected stack overflows, therefore you should very
103428 + carefully test your system. Note that once enabled in the kernel
103429 + configuration, this feature cannot be disabled on a per file basis.
103430 +
103431 +config PAX_RANDUSTACK
103432 + bool "Randomize user stack base"
103433 + default y if GRKERNSEC_CONFIG_AUTO
103434 + depends on PAX_ASLR
103435 + help
103436 + By saying Y here the kernel will randomize every task's userland
103437 + stack. The randomization is done in two steps where the second
103438 + one may apply a big amount of shift to the top of the stack and
103439 + cause problems for programs that want to use lots of memory (more
103440 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
103441 + For this reason the second step can be controlled by 'chpax' or
103442 + 'paxctl' on a per file basis.
103443 +
103444 +config PAX_RANDMMAP
103445 + bool "Randomize mmap() base"
103446 + default y if GRKERNSEC_CONFIG_AUTO
103447 + depends on PAX_ASLR
103448 + help
103449 + By saying Y here the kernel will use a randomized base address for
103450 + mmap() requests that do not specify one themselves. As a result
103451 + all dynamically loaded libraries will appear at random addresses
103452 + and therefore be harder to exploit by a technique where an attacker
103453 + attempts to execute library code for his purposes (e.g. spawn a
103454 + shell from an exploited program that is running at an elevated
103455 + privilege level).
103456 +
103457 + Furthermore, if a program is relinked as a dynamic ELF file, its
103458 + base address will be randomized as well, completing the full
103459 + randomization of the address space layout. Attacking such programs
103460 + becomes a guess game. You can find an example of doing this at
103461 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
103462 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
103463 +
103464 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
103465 + feature on a per file basis.
103466 +
103467 +endmenu
103468 +
103469 +menu "Miscellaneous hardening features"
103470 +
103471 +config PAX_MEMORY_SANITIZE
103472 + bool "Sanitize all freed memory"
103473 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103474 + help
103475 + By saying Y here the kernel will erase memory pages and slab objects
103476 + as soon as they are freed. This in turn reduces the lifetime of data
103477 + stored in them, making it less likely that sensitive information such
103478 + as passwords, cryptographic secrets, etc stay in memory for too long.
103479 +
103480 + This is especially useful for programs whose runtime is short, long
103481 + lived processes and the kernel itself benefit from this as long as
103482 + they ensure timely freeing of memory that may hold sensitive
103483 + information.
103484 +
103485 + A nice side effect of the sanitization of slab objects is the
103486 + reduction of possible info leaks caused by padding bytes within the
103487 + leaky structures. Use-after-free bugs for structures containing
103488 + pointers can also be detected as dereferencing the sanitized pointer
103489 + will generate an access violation.
103490 +
103491 + The tradeoff is performance impact, on a single CPU system kernel
103492 + compilation sees a 3% slowdown, other systems and workloads may vary
103493 + and you are advised to test this feature on your expected workload
103494 + before deploying it.
103495 +
103496 + To reduce the performance penalty by sanitizing pages only, albeit
103497 + limiting the effectiveness of this feature at the same time, slab
103498 + sanitization can be disabled with the kernel commandline parameter
103499 + "pax_sanitize_slab=0".
103500 +
103501 + Note that this feature does not protect data stored in live pages,
103502 + e.g., process memory swapped to disk may stay there for a long time.
103503 +
103504 +config PAX_MEMORY_STACKLEAK
103505 + bool "Sanitize kernel stack"
103506 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103507 + depends on X86
103508 + help
103509 + By saying Y here the kernel will erase the kernel stack before it
103510 + returns from a system call. This in turn reduces the information
103511 + that a kernel stack leak bug can reveal.
103512 +
103513 + Note that such a bug can still leak information that was put on
103514 + the stack by the current system call (the one eventually triggering
103515 + the bug) but traces of earlier system calls on the kernel stack
103516 + cannot leak anymore.
103517 +
103518 + The tradeoff is performance impact: on a single CPU system kernel
103519 + compilation sees a 1% slowdown, other systems and workloads may vary
103520 + and you are advised to test this feature on your expected workload
103521 + before deploying it.
103522 +
103523 + Note that the full feature requires a gcc with plugin support,
103524 + i.e., gcc 4.5 or newer. You may need to install the supporting
103525 + headers explicitly in addition to the normal gcc package. Using
103526 + older gcc versions means that functions with large enough stack
103527 + frames may leave uninitialized memory behind that may be exposed
103528 + to a later syscall leaking the stack.
103529 +
103530 +config PAX_MEMORY_STRUCTLEAK
103531 + bool "Forcibly initialize local variables copied to userland"
103532 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103533 + help
103534 + By saying Y here the kernel will zero initialize some local
103535 + variables that are going to be copied to userland. This in
103536 + turn prevents unintended information leakage from the kernel
103537 + stack should later code forget to explicitly set all parts of
103538 + the copied variable.
103539 +
103540 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
103541 + at a much smaller coverage.
103542 +
103543 + Note that the implementation requires a gcc with plugin support,
103544 + i.e., gcc 4.5 or newer. You may need to install the supporting
103545 + headers explicitly in addition to the normal gcc package.
103546 +
103547 +config PAX_MEMORY_UDEREF
103548 + bool "Prevent invalid userland pointer dereference"
103549 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
103550 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
103551 + select PAX_PER_CPU_PGD if X86_64
103552 + help
103553 + By saying Y here the kernel will be prevented from dereferencing
103554 + userland pointers in contexts where the kernel expects only kernel
103555 + pointers. This is both a useful runtime debugging feature and a
103556 + security measure that prevents exploiting a class of kernel bugs.
103557 +
103558 + The tradeoff is that some virtualization solutions may experience
103559 + a huge slowdown and therefore you should not enable this feature
103560 + for kernels meant to run in such environments. Whether a given VM
103561 + solution is affected or not is best determined by simply trying it
103562 + out, the performance impact will be obvious right on boot as this
103563 + mechanism engages from very early on. A good rule of thumb is that
103564 + VMs running on CPUs without hardware virtualization support (i.e.,
103565 + the majority of IA-32 CPUs) will likely experience the slowdown.
103566 +
103567 + On X86_64 the kernel will make use of PCID support when available
103568 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
103569 + or performance impact. Pass pax_weakuderef on the kernel command
103570 + line to choose the latter.
103571 +
103572 +config PAX_REFCOUNT
103573 + bool "Prevent various kernel object reference counter overflows"
103574 + default y if GRKERNSEC_CONFIG_AUTO
103575 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
103576 + help
103577 + By saying Y here the kernel will detect and prevent overflowing
103578 + various (but not all) kinds of object reference counters. Such
103579 + overflows can normally occur due to bugs only and are often, if
103580 + not always, exploitable.
103581 +
103582 + The tradeoff is that data structures protected by an overflowed
103583 + refcount will never be freed and therefore will leak memory. Note
103584 + that this leak also happens even without this protection but in
103585 + that case the overflow can eventually trigger the freeing of the
103586 + data structure while it is still being used elsewhere, resulting
103587 + in the exploitable situation that this feature prevents.
103588 +
103589 + Since this has a negligible performance impact, you should enable
103590 + this feature.
103591 +
103592 +config PAX_CONSTIFY_PLUGIN
103593 + bool "Automatically constify eligible structures"
103594 + default y
103595 + depends on !UML && PAX_KERNEXEC
103596 + help
103597 + By saying Y here the compiler will automatically constify a class
103598 + of types that contain only function pointers. This reduces the
103599 + kernel's attack surface and also produces a better memory layout.
103600 +
103601 + Note that the implementation requires a gcc with plugin support,
103602 + i.e., gcc 4.5 or newer. You may need to install the supporting
103603 + headers explicitly in addition to the normal gcc package.
103604 +
103605 + Note that if some code really has to modify constified variables
103606 + then the source code will have to be patched to allow it. Examples
103607 + can be found in PaX itself (the no_const attribute) and for some
103608 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
103609 +
103610 +config PAX_USERCOPY
103611 + bool "Harden heap object copies between kernel and userland"
103612 + default y if GRKERNSEC_CONFIG_AUTO
103613 + depends on ARM || IA64 || PPC || SPARC || X86
103614 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
103615 + select PAX_USERCOPY_SLABS
103616 + help
103617 + By saying Y here the kernel will enforce the size of heap objects
103618 + when they are copied in either direction between the kernel and
103619 + userland, even if only a part of the heap object is copied.
103620 +
103621 + Specifically, this checking prevents information leaking from the
103622 + kernel heap during kernel to userland copies (if the kernel heap
103623 + object is otherwise fully initialized) and prevents kernel heap
103624 + overflows during userland to kernel copies.
103625 +
103626 + Note that the current implementation provides the strictest bounds
103627 + checks for the SLUB allocator.
103628 +
103629 + Enabling this option also enables per-slab cache protection against
103630 + data in a given cache being copied into/out of via userland
103631 + accessors. Though the whitelist of regions will be reduced over
103632 + time, it notably protects important data structures like task structs.
103633 +
103634 + If frame pointers are enabled on x86, this option will also restrict
103635 + copies into and out of the kernel stack to local variables within a
103636 + single frame.
103637 +
103638 + Since this has a negligible performance impact, you should enable
103639 + this feature.
103640 +
103641 +config PAX_USERCOPY_DEBUG
103642 + bool
103643 + depends on X86 && PAX_USERCOPY
103644 + default n
103645 +
103646 +config PAX_SIZE_OVERFLOW
103647 + bool "Prevent various integer overflows in function size parameters"
103648 + default y if GRKERNSEC_CONFIG_AUTO
103649 + depends on X86
103650 + help
103651 + By saying Y here the kernel recomputes expressions of function
103652 + arguments marked by a size_overflow attribute with double integer
103653 + precision (DImode/TImode for 32/64 bit integer types).
103654 +
103655 + The recomputed argument is checked against TYPE_MAX and an event
103656 + is logged on overflow and the triggering process is killed.
103657 +
103658 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
103659 +
103660 + Note that the implementation requires a gcc with plugin support,
103661 + i.e., gcc 4.5 or newer. You may need to install the supporting
103662 + headers explicitly in addition to the normal gcc package.
103663 +
103664 +config PAX_LATENT_ENTROPY
103665 + bool "Generate some entropy during boot and runtime"
103666 + default y if GRKERNSEC_CONFIG_AUTO
103667 + help
103668 + By saying Y here the kernel will instrument some kernel code to
103669 + extract some entropy from both original and artificially created
103670 + program state. This will help especially embedded systems where
103671 + there is little 'natural' source of entropy normally. The cost
103672 + is some slowdown of the boot process and fork and irq processing.
103673 +
103674 + When pax_extra_latent_entropy is passed on the kernel command line,
103675 + entropy will be extracted from up to the first 4GB of RAM while the
103676 + runtime memory allocator is being initialized. This costs even more
103677 + slowdown of the boot process.
103678 +
103679 + Note that the implementation requires a gcc with plugin support,
103680 + i.e., gcc 4.5 or newer. You may need to install the supporting
103681 + headers explicitly in addition to the normal gcc package.
103682 +
103683 + Note that entropy extracted this way is not cryptographically
103684 + secure!
103685 +
103686 +endmenu
103687 +
103688 +endmenu
103689 +
103690 +source grsecurity/Kconfig
103691 +
103692 +endmenu
103693 +
103694 +endmenu
103695 +
103696 source security/keys/Kconfig
103697
103698 config SECURITY_DMESG_RESTRICT
103699 @@ -103,7 +1057,7 @@ config INTEL_TXT
103700 config LSM_MMAP_MIN_ADDR
103701 int "Low address space for LSM to protect from user allocation"
103702 depends on SECURITY && SECURITY_SELINUX
103703 - default 32768 if ARM || (ARM64 && COMPAT)
103704 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
103705 default 65536
103706 help
103707 This is the portion of low virtual memory which should be protected
103708 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
103709 index fdaa50c..2761dcb 100644
103710 --- a/security/apparmor/file.c
103711 +++ b/security/apparmor/file.c
103712 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
103713 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
103714 struct path *new_dir, struct dentry *new_dentry)
103715 {
103716 - struct path link = { new_dir->mnt, new_dentry };
103717 - struct path target = { new_dir->mnt, old_dentry };
103718 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
103719 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
103720 struct path_cond cond = {
103721 old_dentry->d_inode->i_uid,
103722 old_dentry->d_inode->i_mode
103723 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
103724 index 4257b7e..2d0732d 100644
103725 --- a/security/apparmor/lsm.c
103726 +++ b/security/apparmor/lsm.c
103727 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
103728 struct dentry *dentry, u32 mask,
103729 struct path_cond *cond)
103730 {
103731 - struct path path = { dir->mnt, dentry };
103732 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
103733
103734 return common_perm(op, &path, mask, cond);
103735 }
103736 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
103737 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
103738 struct dentry *dentry, u32 mask)
103739 {
103740 - struct path path = { mnt, dentry };
103741 + struct path path = { .mnt = mnt, .dentry = dentry };
103742 struct path_cond cond = { dentry->d_inode->i_uid,
103743 dentry->d_inode->i_mode
103744 };
103745 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
103746
103747 profile = aa_current_profile();
103748 if (!unconfined(profile)) {
103749 - struct path old_path = { old_dir->mnt, old_dentry };
103750 - struct path new_path = { new_dir->mnt, new_dentry };
103751 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
103752 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
103753 struct path_cond cond = { old_dentry->d_inode->i_uid,
103754 old_dentry->d_inode->i_mode
103755 };
103756 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
103757 return error;
103758 }
103759
103760 -static struct security_operations apparmor_ops = {
103761 +static struct security_operations apparmor_ops __read_only = {
103762 .name = "apparmor",
103763
103764 .ptrace_access_check = apparmor_ptrace_access_check,
103765 diff --git a/security/commoncap.c b/security/commoncap.c
103766 index b9d613e..f68305c 100644
103767 --- a/security/commoncap.c
103768 +++ b/security/commoncap.c
103769 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
103770 return 0;
103771 }
103772
103773 +/* returns:
103774 + 1 for suid privilege
103775 + 2 for sgid privilege
103776 + 3 for fscap privilege
103777 +*/
103778 +int is_privileged_binary(const struct dentry *dentry)
103779 +{
103780 + struct cpu_vfs_cap_data capdata;
103781 + struct inode *inode = dentry->d_inode;
103782 +
103783 + if (!inode || S_ISDIR(inode->i_mode))
103784 + return 0;
103785 +
103786 + if (inode->i_mode & S_ISUID)
103787 + return 1;
103788 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
103789 + return 2;
103790 +
103791 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
103792 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
103793 + return 3;
103794 + }
103795 +
103796 + return 0;
103797 +}
103798 +
103799 /*
103800 * Attempt to get the on-exec apply capability sets for an executable file from
103801 * its xattrs and, if present, apply them to the proposed credentials being
103802 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
103803 const struct cred *cred = current_cred();
103804 kuid_t root_uid = make_kuid(cred->user_ns, 0);
103805
103806 + if (gr_acl_enable_at_secure())
103807 + return 1;
103808 +
103809 if (!uid_eq(cred->uid, root_uid)) {
103810 if (bprm->cap_effective)
103811 return 1;
103812 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
103813 index 0356e1d..72332ab 100644
103814 --- a/security/integrity/ima/ima.h
103815 +++ b/security/integrity/ima/ima.h
103816 @@ -118,8 +118,8 @@ int ima_init_template(void);
103817 extern spinlock_t ima_queue_lock;
103818
103819 struct ima_h_table {
103820 - atomic_long_t len; /* number of stored measurements in the list */
103821 - atomic_long_t violations;
103822 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
103823 + atomic_long_unchecked_t violations;
103824 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
103825 };
103826 extern struct ima_h_table ima_htable;
103827 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
103828 index c38bbce..f45133d 100644
103829 --- a/security/integrity/ima/ima_api.c
103830 +++ b/security/integrity/ima/ima_api.c
103831 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
103832 int result;
103833
103834 /* can overflow, only indicator */
103835 - atomic_long_inc(&ima_htable.violations);
103836 + atomic_long_inc_unchecked(&ima_htable.violations);
103837
103838 result = ima_alloc_init_template(NULL, file, filename,
103839 NULL, 0, &entry);
103840 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
103841 index db01125..61f6597 100644
103842 --- a/security/integrity/ima/ima_fs.c
103843 +++ b/security/integrity/ima/ima_fs.c
103844 @@ -28,12 +28,12 @@
103845 static int valid_policy = 1;
103846 #define TMPBUFLEN 12
103847 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
103848 - loff_t *ppos, atomic_long_t *val)
103849 + loff_t *ppos, atomic_long_unchecked_t *val)
103850 {
103851 char tmpbuf[TMPBUFLEN];
103852 ssize_t len;
103853
103854 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
103855 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
103856 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
103857 }
103858
103859 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
103860 index d85e997..6992813 100644
103861 --- a/security/integrity/ima/ima_queue.c
103862 +++ b/security/integrity/ima/ima_queue.c
103863 @@ -80,7 +80,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
103864 INIT_LIST_HEAD(&qe->later);
103865 list_add_tail_rcu(&qe->later, &ima_measurements);
103866
103867 - atomic_long_inc(&ima_htable.len);
103868 + atomic_long_inc_unchecked(&ima_htable.len);
103869 key = ima_hash_key(entry->digest);
103870 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
103871 return 0;
103872 diff --git a/security/keys/compat.c b/security/keys/compat.c
103873 index bbd32c7..c60c927 100644
103874 --- a/security/keys/compat.c
103875 +++ b/security/keys/compat.c
103876 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
103877 if (ret == 0)
103878 goto no_payload_free;
103879
103880 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
103881 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
103882 err:
103883 if (iov != iovstack)
103884 kfree(iov);
103885 diff --git a/security/keys/internal.h b/security/keys/internal.h
103886 index 80b2aac..bb7ee65 100644
103887 --- a/security/keys/internal.h
103888 +++ b/security/keys/internal.h
103889 @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
103890 extern long keyctl_invalidate_key(key_serial_t);
103891
103892 extern long keyctl_instantiate_key_common(key_serial_t,
103893 - const struct iovec *,
103894 + const struct iovec __user *,
103895 unsigned, size_t, key_serial_t);
103896 #ifdef CONFIG_PERSISTENT_KEYRINGS
103897 extern long keyctl_get_persistent(uid_t, key_serial_t);
103898 diff --git a/security/keys/key.c b/security/keys/key.c
103899 index 6e21c11..9ed67ca 100644
103900 --- a/security/keys/key.c
103901 +++ b/security/keys/key.c
103902 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
103903
103904 atomic_set(&key->usage, 1);
103905 init_rwsem(&key->sem);
103906 - lockdep_set_class(&key->sem, &type->lock_class);
103907 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
103908 key->index_key.type = type;
103909 key->user = user;
103910 key->quotalen = quotalen;
103911 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
103912 struct key_type *p;
103913 int ret;
103914
103915 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
103916 + pax_open_kernel();
103917 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
103918 + pax_close_kernel();
103919
103920 ret = -EEXIST;
103921 down_write(&key_types_sem);
103922 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
103923 }
103924
103925 /* store the type */
103926 - list_add(&ktype->link, &key_types_list);
103927 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
103928
103929 pr_notice("Key type %s registered\n", ktype->name);
103930 ret = 0;
103931 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
103932 void unregister_key_type(struct key_type *ktype)
103933 {
103934 down_write(&key_types_sem);
103935 - list_del_init(&ktype->link);
103936 + pax_list_del_init((struct list_head *)&ktype->link);
103937 downgrade_write(&key_types_sem);
103938 key_gc_keytype(ktype);
103939 pr_notice("Key type %s unregistered\n", ktype->name);
103940 @@ -1088,10 +1090,10 @@ void __init key_init(void)
103941 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
103942
103943 /* add the special key types */
103944 - list_add_tail(&key_type_keyring.link, &key_types_list);
103945 - list_add_tail(&key_type_dead.link, &key_types_list);
103946 - list_add_tail(&key_type_user.link, &key_types_list);
103947 - list_add_tail(&key_type_logon.link, &key_types_list);
103948 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
103949 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
103950 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
103951 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
103952
103953 /* record the root user tracking */
103954 rb_link_node(&root_key_user.node,
103955 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
103956 index cee72ce..e46074a 100644
103957 --- a/security/keys/keyctl.c
103958 +++ b/security/keys/keyctl.c
103959 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
103960 /*
103961 * Copy the iovec data from userspace
103962 */
103963 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
103964 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
103965 unsigned ioc)
103966 {
103967 for (; ioc > 0; ioc--) {
103968 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
103969 * If successful, 0 will be returned.
103970 */
103971 long keyctl_instantiate_key_common(key_serial_t id,
103972 - const struct iovec *payload_iov,
103973 + const struct iovec __user *payload_iov,
103974 unsigned ioc,
103975 size_t plen,
103976 key_serial_t ringid)
103977 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
103978 [0].iov_len = plen
103979 };
103980
103981 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
103982 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
103983 }
103984
103985 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
103986 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
103987 if (ret == 0)
103988 goto no_payload_free;
103989
103990 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
103991 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
103992 err:
103993 if (iov != iovstack)
103994 kfree(iov);
103995 diff --git a/security/min_addr.c b/security/min_addr.c
103996 index f728728..6457a0c 100644
103997 --- a/security/min_addr.c
103998 +++ b/security/min_addr.c
103999 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
104000 */
104001 static void update_mmap_min_addr(void)
104002 {
104003 +#ifndef SPARC
104004 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
104005 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
104006 mmap_min_addr = dac_mmap_min_addr;
104007 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
104008 #else
104009 mmap_min_addr = dac_mmap_min_addr;
104010 #endif
104011 +#endif
104012 }
104013
104014 /*
104015 diff --git a/security/security.c b/security/security.c
104016 index 919cad9..2127be1 100644
104017 --- a/security/security.c
104018 +++ b/security/security.c
104019 @@ -33,8 +33,8 @@
104020 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
104021 CONFIG_DEFAULT_SECURITY;
104022
104023 -static struct security_operations *security_ops;
104024 -static struct security_operations default_security_ops = {
104025 +struct security_operations *security_ops __read_only;
104026 +struct security_operations default_security_ops __read_only = {
104027 .name = "default",
104028 };
104029
104030 @@ -73,11 +73,6 @@ int __init security_init(void)
104031 return 0;
104032 }
104033
104034 -void reset_security_ops(void)
104035 -{
104036 - security_ops = &default_security_ops;
104037 -}
104038 -
104039 /* Save user chosen LSM */
104040 static int __init choose_lsm(char *str)
104041 {
104042 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
104043 index fc3e662..7844c60 100644
104044 --- a/security/selinux/avc.c
104045 +++ b/security/selinux/avc.c
104046 @@ -59,7 +59,7 @@ struct avc_node {
104047 struct avc_cache {
104048 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
104049 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
104050 - atomic_t lru_hint; /* LRU hint for reclaim scan */
104051 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
104052 atomic_t active_nodes;
104053 u32 latest_notif; /* latest revocation notification */
104054 };
104055 @@ -167,7 +167,7 @@ void __init avc_init(void)
104056 spin_lock_init(&avc_cache.slots_lock[i]);
104057 }
104058 atomic_set(&avc_cache.active_nodes, 0);
104059 - atomic_set(&avc_cache.lru_hint, 0);
104060 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
104061
104062 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
104063 0, SLAB_PANIC, NULL);
104064 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
104065 spinlock_t *lock;
104066
104067 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
104068 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
104069 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
104070 head = &avc_cache.slots[hvalue];
104071 lock = &avc_cache.slots_lock[hvalue];
104072
104073 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
104074 index e294b86..eda45c55 100644
104075 --- a/security/selinux/hooks.c
104076 +++ b/security/selinux/hooks.c
104077 @@ -95,8 +95,6 @@
104078 #include "audit.h"
104079 #include "avc_ss.h"
104080
104081 -extern struct security_operations *security_ops;
104082 -
104083 /* SECMARK reference count */
104084 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
104085
104086 @@ -5759,7 +5757,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
104087
104088 #endif
104089
104090 -static struct security_operations selinux_ops = {
104091 +static struct security_operations selinux_ops __read_only = {
104092 .name = "selinux",
104093
104094 .ptrace_access_check = selinux_ptrace_access_check,
104095 @@ -6112,6 +6110,9 @@ static void selinux_nf_ip_exit(void)
104096 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
104097 static int selinux_disabled;
104098
104099 +extern struct security_operations *security_ops;
104100 +extern struct security_operations default_security_ops;
104101 +
104102 int selinux_disable(void)
104103 {
104104 if (ss_initialized) {
104105 @@ -6129,7 +6130,9 @@ int selinux_disable(void)
104106 selinux_disabled = 1;
104107 selinux_enabled = 0;
104108
104109 - reset_security_ops();
104110 + pax_open_kernel();
104111 + security_ops = &default_security_ops;
104112 + pax_close_kernel();
104113
104114 /* Try to destroy the avc node cache */
104115 avc_disable();
104116 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
104117 index 9f05847..7933395 100644
104118 --- a/security/selinux/include/xfrm.h
104119 +++ b/security/selinux/include/xfrm.h
104120 @@ -46,7 +46,7 @@ static inline void selinux_xfrm_notify_policyload(void)
104121 {
104122 struct net *net;
104123
104124 - atomic_inc(&flow_cache_genid);
104125 + atomic_inc_unchecked(&flow_cache_genid);
104126 rtnl_lock();
104127 for_each_net(net)
104128 rt_genid_bump_all(net);
104129 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
104130 index 14f52be..7352368 100644
104131 --- a/security/smack/smack_lsm.c
104132 +++ b/security/smack/smack_lsm.c
104133 @@ -3726,7 +3726,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
104134 return 0;
104135 }
104136
104137 -struct security_operations smack_ops = {
104138 +struct security_operations smack_ops __read_only = {
104139 .name = "smack",
104140
104141 .ptrace_access_check = smack_ptrace_access_check,
104142 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
104143 index 4003907..13a2b55 100644
104144 --- a/security/tomoyo/file.c
104145 +++ b/security/tomoyo/file.c
104146 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
104147 {
104148 struct tomoyo_request_info r;
104149 struct tomoyo_obj_info obj = {
104150 - .path1 = *path,
104151 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104152 };
104153 int error = -ENOMEM;
104154 struct tomoyo_path_info buf;
104155 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
104156 struct tomoyo_path_info buf;
104157 struct tomoyo_request_info r;
104158 struct tomoyo_obj_info obj = {
104159 - .path1 = *path,
104160 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104161 };
104162 int idx;
104163
104164 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
104165 {
104166 struct tomoyo_request_info r;
104167 struct tomoyo_obj_info obj = {
104168 - .path1 = *path,
104169 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104170 };
104171 int error;
104172 struct tomoyo_path_info buf;
104173 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
104174 {
104175 struct tomoyo_request_info r;
104176 struct tomoyo_obj_info obj = {
104177 - .path1 = *path,
104178 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104179 };
104180 int error = -ENOMEM;
104181 struct tomoyo_path_info buf;
104182 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
104183 struct tomoyo_path_info buf2;
104184 struct tomoyo_request_info r;
104185 struct tomoyo_obj_info obj = {
104186 - .path1 = *path1,
104187 - .path2 = *path2,
104188 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
104189 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
104190 };
104191 int idx;
104192
104193 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
104194 index 390c646..f2f8db3 100644
104195 --- a/security/tomoyo/mount.c
104196 +++ b/security/tomoyo/mount.c
104197 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
104198 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
104199 need_dev = -1; /* dev_name is a directory */
104200 } else {
104201 + if (!capable(CAP_SYS_ADMIN)) {
104202 + error = -EPERM;
104203 + goto out;
104204 + }
104205 fstype = get_fs_type(type);
104206 if (!fstype) {
104207 error = -ENODEV;
104208 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
104209 index f0b756e..8aa497b 100644
104210 --- a/security/tomoyo/tomoyo.c
104211 +++ b/security/tomoyo/tomoyo.c
104212 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
104213 */
104214 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
104215 {
104216 - struct path path = { mnt, dentry };
104217 + struct path path = { .mnt = mnt, .dentry = dentry };
104218 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
104219 }
104220
104221 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
104222 */
104223 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
104224 {
104225 - struct path path = { parent->mnt, dentry };
104226 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104227 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
104228 }
104229
104230 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
104231 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
104232 umode_t mode)
104233 {
104234 - struct path path = { parent->mnt, dentry };
104235 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104236 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
104237 mode & S_IALLUGO);
104238 }
104239 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
104240 */
104241 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
104242 {
104243 - struct path path = { parent->mnt, dentry };
104244 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104245 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
104246 }
104247
104248 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
104249 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
104250 const char *old_name)
104251 {
104252 - struct path path = { parent->mnt, dentry };
104253 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104254 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
104255 }
104256
104257 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
104258 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
104259 umode_t mode, unsigned int dev)
104260 {
104261 - struct path path = { parent->mnt, dentry };
104262 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104263 int type = TOMOYO_TYPE_CREATE;
104264 const unsigned int perm = mode & S_IALLUGO;
104265
104266 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
104267 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
104268 struct dentry *new_dentry)
104269 {
104270 - struct path path1 = { new_dir->mnt, old_dentry };
104271 - struct path path2 = { new_dir->mnt, new_dentry };
104272 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
104273 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
104274 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
104275 }
104276
104277 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
104278 struct path *new_parent,
104279 struct dentry *new_dentry)
104280 {
104281 - struct path path1 = { old_parent->mnt, old_dentry };
104282 - struct path path2 = { new_parent->mnt, new_dentry };
104283 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
104284 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
104285 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
104286 }
104287
104288 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
104289 */
104290 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
104291 {
104292 - struct path path = { mnt, mnt->mnt_root };
104293 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
104294 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
104295 }
104296
104297 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
104298 * tomoyo_security_ops is a "struct security_operations" which is used for
104299 * registering TOMOYO.
104300 */
104301 -static struct security_operations tomoyo_security_ops = {
104302 +static struct security_operations tomoyo_security_ops __read_only = {
104303 .name = "tomoyo",
104304 .cred_alloc_blank = tomoyo_cred_alloc_blank,
104305 .cred_prepare = tomoyo_cred_prepare,
104306 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
104307 index 20ef514..4182bed 100644
104308 --- a/security/yama/Kconfig
104309 +++ b/security/yama/Kconfig
104310 @@ -1,6 +1,6 @@
104311 config SECURITY_YAMA
104312 bool "Yama support"
104313 - depends on SECURITY
104314 + depends on SECURITY && !GRKERNSEC
104315 select SECURITYFS
104316 select SECURITY_PATH
104317 default n
104318 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
104319 index 13c88fbc..f8c115e 100644
104320 --- a/security/yama/yama_lsm.c
104321 +++ b/security/yama/yama_lsm.c
104322 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
104323 }
104324
104325 #ifndef CONFIG_SECURITY_YAMA_STACKED
104326 -static struct security_operations yama_ops = {
104327 +static struct security_operations yama_ops __read_only = {
104328 .name = "yama",
104329
104330 .ptrace_access_check = yama_ptrace_access_check,
104331 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
104332 #endif
104333
104334 #ifdef CONFIG_SYSCTL
104335 +static int zero __read_only;
104336 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
104337 +
104338 static int yama_dointvec_minmax(struct ctl_table *table, int write,
104339 void __user *buffer, size_t *lenp, loff_t *ppos)
104340 {
104341 - int rc;
104342 + ctl_table_no_const yama_table;
104343
104344 if (write && !capable(CAP_SYS_PTRACE))
104345 return -EPERM;
104346
104347 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
104348 - if (rc)
104349 - return rc;
104350 -
104351 + yama_table = *table;
104352 /* Lock the max value if it ever gets set. */
104353 - if (write && *(int *)table->data == *(int *)table->extra2)
104354 - table->extra1 = table->extra2;
104355 -
104356 - return rc;
104357 + if (ptrace_scope == max_scope)
104358 + yama_table.extra1 = &max_scope;
104359 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
104360 }
104361
104362 -static int zero;
104363 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
104364 -
104365 struct ctl_path yama_sysctl_path[] = {
104366 { .procname = "kernel", },
104367 { .procname = "yama", },
104368 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
104369 index 4cedc69..e59d8a3 100644
104370 --- a/sound/aoa/codecs/onyx.c
104371 +++ b/sound/aoa/codecs/onyx.c
104372 @@ -54,7 +54,7 @@ struct onyx {
104373 spdif_locked:1,
104374 analog_locked:1,
104375 original_mute:2;
104376 - int open_count;
104377 + local_t open_count;
104378 struct codec_info *codec_info;
104379
104380 /* mutex serializes concurrent access to the device
104381 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
104382 struct onyx *onyx = cii->codec_data;
104383
104384 mutex_lock(&onyx->mutex);
104385 - onyx->open_count++;
104386 + local_inc(&onyx->open_count);
104387 mutex_unlock(&onyx->mutex);
104388
104389 return 0;
104390 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
104391 struct onyx *onyx = cii->codec_data;
104392
104393 mutex_lock(&onyx->mutex);
104394 - onyx->open_count--;
104395 - if (!onyx->open_count)
104396 + if (local_dec_and_test(&onyx->open_count))
104397 onyx->spdif_locked = onyx->analog_locked = 0;
104398 mutex_unlock(&onyx->mutex);
104399
104400 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
104401 index ffd2025..df062c9 100644
104402 --- a/sound/aoa/codecs/onyx.h
104403 +++ b/sound/aoa/codecs/onyx.h
104404 @@ -11,6 +11,7 @@
104405 #include <linux/i2c.h>
104406 #include <asm/pmac_low_i2c.h>
104407 #include <asm/prom.h>
104408 +#include <asm/local.h>
104409
104410 /* PCM3052 register definitions */
104411
104412 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
104413 index 4c1cc51..16040040 100644
104414 --- a/sound/core/oss/pcm_oss.c
104415 +++ b/sound/core/oss/pcm_oss.c
104416 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
104417 if (in_kernel) {
104418 mm_segment_t fs;
104419 fs = snd_enter_user();
104420 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
104421 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
104422 snd_leave_user(fs);
104423 } else {
104424 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
104425 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
104426 }
104427 if (ret != -EPIPE && ret != -ESTRPIPE)
104428 break;
104429 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
104430 if (in_kernel) {
104431 mm_segment_t fs;
104432 fs = snd_enter_user();
104433 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
104434 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
104435 snd_leave_user(fs);
104436 } else {
104437 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
104438 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
104439 }
104440 if (ret == -EPIPE) {
104441 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
104442 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
104443 struct snd_pcm_plugin_channel *channels;
104444 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
104445 if (!in_kernel) {
104446 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
104447 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
104448 return -EFAULT;
104449 buf = runtime->oss.buffer;
104450 }
104451 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
104452 }
104453 } else {
104454 tmp = snd_pcm_oss_write2(substream,
104455 - (const char __force *)buf,
104456 + (const char __force_kernel *)buf,
104457 runtime->oss.period_bytes, 0);
104458 if (tmp <= 0)
104459 goto err;
104460 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
104461 struct snd_pcm_runtime *runtime = substream->runtime;
104462 snd_pcm_sframes_t frames, frames1;
104463 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
104464 - char __user *final_dst = (char __force __user *)buf;
104465 + char __user *final_dst = (char __force_user *)buf;
104466 if (runtime->oss.plugin_first) {
104467 struct snd_pcm_plugin_channel *channels;
104468 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
104469 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
104470 xfer += tmp;
104471 runtime->oss.buffer_used -= tmp;
104472 } else {
104473 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
104474 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
104475 runtime->oss.period_bytes, 0);
104476 if (tmp <= 0)
104477 goto err;
104478 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
104479 size1);
104480 size1 /= runtime->channels; /* frames */
104481 fs = snd_enter_user();
104482 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
104483 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
104484 snd_leave_user(fs);
104485 }
104486 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
104487 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
104488 index af49721..e85058e 100644
104489 --- a/sound/core/pcm_compat.c
104490 +++ b/sound/core/pcm_compat.c
104491 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
104492 int err;
104493
104494 fs = snd_enter_user();
104495 - err = snd_pcm_delay(substream, &delay);
104496 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
104497 snd_leave_user(fs);
104498 if (err < 0)
104499 return err;
104500 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
104501 index 01a5e05..c6bb425 100644
104502 --- a/sound/core/pcm_native.c
104503 +++ b/sound/core/pcm_native.c
104504 @@ -2811,11 +2811,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
104505 switch (substream->stream) {
104506 case SNDRV_PCM_STREAM_PLAYBACK:
104507 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
104508 - (void __user *)arg);
104509 + (void __force_user *)arg);
104510 break;
104511 case SNDRV_PCM_STREAM_CAPTURE:
104512 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
104513 - (void __user *)arg);
104514 + (void __force_user *)arg);
104515 break;
104516 default:
104517 result = -EINVAL;
104518 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
104519 index 8d4d5e8..fdd0826 100644
104520 --- a/sound/core/seq/oss/seq_oss.c
104521 +++ b/sound/core/seq/oss/seq_oss.c
104522 @@ -75,8 +75,8 @@ static int __init alsa_seq_oss_init(void)
104523 {
104524 int rc;
104525 static struct snd_seq_dev_ops ops = {
104526 - snd_seq_oss_synth_register,
104527 - snd_seq_oss_synth_unregister,
104528 + .init_device = snd_seq_oss_synth_register,
104529 + .free_device = snd_seq_oss_synth_unregister,
104530 };
104531
104532 snd_seq_autoload_lock();
104533 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
104534 index 040c60e..989a19a 100644
104535 --- a/sound/core/seq/seq_device.c
104536 +++ b/sound/core/seq/seq_device.c
104537 @@ -64,7 +64,7 @@ struct ops_list {
104538 int argsize; /* argument size */
104539
104540 /* operators */
104541 - struct snd_seq_dev_ops ops;
104542 + struct snd_seq_dev_ops *ops;
104543
104544 /* registered devices */
104545 struct list_head dev_list; /* list of devices */
104546 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
104547
104548 mutex_lock(&ops->reg_mutex);
104549 /* copy driver operators */
104550 - ops->ops = *entry;
104551 + ops->ops = entry;
104552 ops->driver |= DRIVER_LOADED;
104553 ops->argsize = argsize;
104554
104555 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
104556 dev->name, ops->id, ops->argsize, dev->argsize);
104557 return -EINVAL;
104558 }
104559 - if (ops->ops.init_device(dev) >= 0) {
104560 + if (ops->ops->init_device(dev) >= 0) {
104561 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
104562 ops->num_init_devices++;
104563 } else {
104564 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
104565 dev->name, ops->id, ops->argsize, dev->argsize);
104566 return -EINVAL;
104567 }
104568 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
104569 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
104570 dev->status = SNDRV_SEQ_DEVICE_FREE;
104571 dev->driver_data = NULL;
104572 ops->num_init_devices--;
104573 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
104574 index 64069db..3c6d392 100644
104575 --- a/sound/core/seq/seq_midi.c
104576 +++ b/sound/core/seq/seq_midi.c
104577 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
104578 static int __init alsa_seq_midi_init(void)
104579 {
104580 static struct snd_seq_dev_ops ops = {
104581 - snd_seq_midisynth_register_port,
104582 - snd_seq_midisynth_unregister_port,
104583 + .init_device = snd_seq_midisynth_register_port,
104584 + .free_device = snd_seq_midisynth_unregister_port,
104585 };
104586 memset(&synths, 0, sizeof(synths));
104587 snd_seq_autoload_lock();
104588 diff --git a/sound/core/sound.c b/sound/core/sound.c
104589 index 437c25e..cd040ab 100644
104590 --- a/sound/core/sound.c
104591 +++ b/sound/core/sound.c
104592 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
104593 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
104594 default: return;
104595 }
104596 - request_module(str);
104597 + request_module("%s", str);
104598 }
104599
104600 #endif /* modular kernel */
104601 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
104602 index 4e0dd22..7a1f32c 100644
104603 --- a/sound/drivers/mts64.c
104604 +++ b/sound/drivers/mts64.c
104605 @@ -29,6 +29,7 @@
104606 #include <sound/initval.h>
104607 #include <sound/rawmidi.h>
104608 #include <sound/control.h>
104609 +#include <asm/local.h>
104610
104611 #define CARD_NAME "Miditerminal 4140"
104612 #define DRIVER_NAME "MTS64"
104613 @@ -67,7 +68,7 @@ struct mts64 {
104614 struct pardevice *pardev;
104615 int pardev_claimed;
104616
104617 - int open_count;
104618 + local_t open_count;
104619 int current_midi_output_port;
104620 int current_midi_input_port;
104621 u8 mode[MTS64_NUM_INPUT_PORTS];
104622 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
104623 {
104624 struct mts64 *mts = substream->rmidi->private_data;
104625
104626 - if (mts->open_count == 0) {
104627 + if (local_read(&mts->open_count) == 0) {
104628 /* We don't need a spinlock here, because this is just called
104629 if the device has not been opened before.
104630 So there aren't any IRQs from the device */
104631 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
104632
104633 msleep(50);
104634 }
104635 - ++(mts->open_count);
104636 + local_inc(&mts->open_count);
104637
104638 return 0;
104639 }
104640 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
104641 struct mts64 *mts = substream->rmidi->private_data;
104642 unsigned long flags;
104643
104644 - --(mts->open_count);
104645 - if (mts->open_count == 0) {
104646 + if (local_dec_return(&mts->open_count) == 0) {
104647 /* We need the spinlock_irqsave here because we can still
104648 have IRQs at this point */
104649 spin_lock_irqsave(&mts->lock, flags);
104650 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
104651
104652 msleep(500);
104653
104654 - } else if (mts->open_count < 0)
104655 - mts->open_count = 0;
104656 + } else if (local_read(&mts->open_count) < 0)
104657 + local_set(&mts->open_count, 0);
104658
104659 return 0;
104660 }
104661 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
104662 index 6839953..7a0f4b9 100644
104663 --- a/sound/drivers/opl3/opl3_seq.c
104664 +++ b/sound/drivers/opl3/opl3_seq.c
104665 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
104666 {
104667 static struct snd_seq_dev_ops ops =
104668 {
104669 - snd_opl3_seq_new_device,
104670 - snd_opl3_seq_delete_device
104671 + .init_device = snd_opl3_seq_new_device,
104672 + .free_device = snd_opl3_seq_delete_device
104673 };
104674
104675 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
104676 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
104677 index b953fb4..1999c01 100644
104678 --- a/sound/drivers/opl4/opl4_lib.c
104679 +++ b/sound/drivers/opl4/opl4_lib.c
104680 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
104681 MODULE_DESCRIPTION("OPL4 driver");
104682 MODULE_LICENSE("GPL");
104683
104684 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
104685 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
104686 {
104687 int timeout = 10;
104688 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
104689 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
104690 index 9919769..d7de36c 100644
104691 --- a/sound/drivers/opl4/opl4_seq.c
104692 +++ b/sound/drivers/opl4/opl4_seq.c
104693 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
104694 static int __init alsa_opl4_synth_init(void)
104695 {
104696 static struct snd_seq_dev_ops ops = {
104697 - snd_opl4_seq_new_device,
104698 - snd_opl4_seq_delete_device
104699 + .init_device = snd_opl4_seq_new_device,
104700 + .free_device = snd_opl4_seq_delete_device
104701 };
104702
104703 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
104704 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
104705 index 991018d..8984740 100644
104706 --- a/sound/drivers/portman2x4.c
104707 +++ b/sound/drivers/portman2x4.c
104708 @@ -48,6 +48,7 @@
104709 #include <sound/initval.h>
104710 #include <sound/rawmidi.h>
104711 #include <sound/control.h>
104712 +#include <asm/local.h>
104713
104714 #define CARD_NAME "Portman 2x4"
104715 #define DRIVER_NAME "portman"
104716 @@ -85,7 +86,7 @@ struct portman {
104717 struct pardevice *pardev;
104718 int pardev_claimed;
104719
104720 - int open_count;
104721 + local_t open_count;
104722 int mode[PORTMAN_NUM_INPUT_PORTS];
104723 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
104724 };
104725 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
104726 index 9048777..2d8b1fc 100644
104727 --- a/sound/firewire/amdtp.c
104728 +++ b/sound/firewire/amdtp.c
104729 @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
104730 ptr = s->pcm_buffer_pointer + data_blocks;
104731 if (ptr >= pcm->runtime->buffer_size)
104732 ptr -= pcm->runtime->buffer_size;
104733 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
104734 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
104735
104736 s->pcm_period_pointer += data_blocks;
104737 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
104738 @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
104739 */
104740 void amdtp_out_stream_update(struct amdtp_out_stream *s)
104741 {
104742 - ACCESS_ONCE(s->source_node_id_field) =
104743 + ACCESS_ONCE_RW(s->source_node_id_field) =
104744 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
104745 }
104746 EXPORT_SYMBOL(amdtp_out_stream_update);
104747 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
104748 index 2746ecd..c35dedd 100644
104749 --- a/sound/firewire/amdtp.h
104750 +++ b/sound/firewire/amdtp.h
104751 @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
104752 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
104753 struct snd_pcm_substream *pcm)
104754 {
104755 - ACCESS_ONCE(s->pcm) = pcm;
104756 + ACCESS_ONCE_RW(s->pcm) = pcm;
104757 }
104758
104759 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
104760 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
104761 index fd42e6b..c041971 100644
104762 --- a/sound/firewire/isight.c
104763 +++ b/sound/firewire/isight.c
104764 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
104765 ptr += count;
104766 if (ptr >= runtime->buffer_size)
104767 ptr -= runtime->buffer_size;
104768 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
104769 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
104770
104771 isight->period_counter += count;
104772 if (isight->period_counter >= runtime->period_size) {
104773 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
104774 if (err < 0)
104775 return err;
104776
104777 - ACCESS_ONCE(isight->pcm_active) = true;
104778 + ACCESS_ONCE_RW(isight->pcm_active) = true;
104779
104780 return 0;
104781 }
104782 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
104783 {
104784 struct isight *isight = substream->private_data;
104785
104786 - ACCESS_ONCE(isight->pcm_active) = false;
104787 + ACCESS_ONCE_RW(isight->pcm_active) = false;
104788
104789 mutex_lock(&isight->mutex);
104790 isight_stop_streaming(isight);
104791 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
104792
104793 switch (cmd) {
104794 case SNDRV_PCM_TRIGGER_START:
104795 - ACCESS_ONCE(isight->pcm_running) = true;
104796 + ACCESS_ONCE_RW(isight->pcm_running) = true;
104797 break;
104798 case SNDRV_PCM_TRIGGER_STOP:
104799 - ACCESS_ONCE(isight->pcm_running) = false;
104800 + ACCESS_ONCE_RW(isight->pcm_running) = false;
104801 break;
104802 default:
104803 return -EINVAL;
104804 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
104805 index 858023c..83b3d3c 100644
104806 --- a/sound/firewire/scs1x.c
104807 +++ b/sound/firewire/scs1x.c
104808 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
104809 {
104810 struct scs *scs = stream->rmidi->private_data;
104811
104812 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
104813 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
104814 if (up) {
104815 scs->output_idle = false;
104816 tasklet_schedule(&scs->tasklet);
104817 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
104818 {
104819 struct scs *scs = stream->rmidi->private_data;
104820
104821 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
104822 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
104823 }
104824
104825 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
104826 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
104827
104828 snd_card_disconnect(scs->card);
104829
104830 - ACCESS_ONCE(scs->output) = NULL;
104831 - ACCESS_ONCE(scs->input) = NULL;
104832 + ACCESS_ONCE_RW(scs->output) = NULL;
104833 + ACCESS_ONCE_RW(scs->input) = NULL;
104834
104835 wait_event(scs->idle_wait, scs->output_idle);
104836
104837 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
104838 index 4e3fcfb..ab45a9d 100644
104839 --- a/sound/isa/sb/emu8000_synth.c
104840 +++ b/sound/isa/sb/emu8000_synth.c
104841 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
104842 {
104843
104844 static struct snd_seq_dev_ops ops = {
104845 - snd_emu8000_new_device,
104846 - snd_emu8000_delete_device,
104847 + .init_device = snd_emu8000_new_device,
104848 + .free_device = snd_emu8000_delete_device,
104849 };
104850 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
104851 sizeof(struct snd_emu8000*));
104852 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
104853 index 048439a..3be9f6f 100644
104854 --- a/sound/oss/sb_audio.c
104855 +++ b/sound/oss/sb_audio.c
104856 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
104857 buf16 = (signed short *)(localbuf + localoffs);
104858 while (c)
104859 {
104860 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
104861 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
104862 if (copy_from_user(lbuf8,
104863 userbuf+useroffs + p,
104864 locallen))
104865 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
104866 index f851fd0..92576fb 100644
104867 --- a/sound/oss/swarm_cs4297a.c
104868 +++ b/sound/oss/swarm_cs4297a.c
104869 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
104870 {
104871 struct cs4297a_state *s;
104872 u32 pwr, id;
104873 - mm_segment_t fs;
104874 int rval;
104875 #ifndef CONFIG_BCM_CS4297A_CSWARM
104876 u64 cfg;
104877 @@ -2713,22 +2712,23 @@ static int __init cs4297a_init(void)
104878 if (!rval) {
104879 char *sb1250_duart_present;
104880
104881 +#if 0
104882 + mm_segment_t fs;
104883 fs = get_fs();
104884 set_fs(KERNEL_DS);
104885 -#if 0
104886 val = SOUND_MASK_LINE;
104887 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
104888 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
104889 val = initvol[i].vol;
104890 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
104891 }
104892 + set_fs(fs);
104893 // cs4297a_write_ac97(s, 0x18, 0x0808);
104894 #else
104895 // cs4297a_write_ac97(s, 0x5e, 0x180);
104896 cs4297a_write_ac97(s, 0x02, 0x0808);
104897 cs4297a_write_ac97(s, 0x18, 0x0808);
104898 #endif
104899 - set_fs(fs);
104900
104901 list_add(&s->list, &cs4297a_devs);
104902
104903 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
104904 index 4c41c90..37f3631 100644
104905 --- a/sound/pci/emu10k1/emu10k1_synth.c
104906 +++ b/sound/pci/emu10k1/emu10k1_synth.c
104907 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
104908 {
104909
104910 static struct snd_seq_dev_ops ops = {
104911 - snd_emu10k1_synth_new_device,
104912 - snd_emu10k1_synth_delete_device,
104913 + .init_device = snd_emu10k1_synth_new_device,
104914 + .free_device = snd_emu10k1_synth_delete_device,
104915 };
104916 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
104917 sizeof(struct snd_emu10k1_synth_arg));
104918 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
104919 index dafcf82..dd9356f 100644
104920 --- a/sound/pci/hda/hda_codec.c
104921 +++ b/sound/pci/hda/hda_codec.c
104922 @@ -983,14 +983,10 @@ find_codec_preset(struct hda_codec *codec)
104923 mutex_unlock(&preset_mutex);
104924
104925 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
104926 - char name[32];
104927 if (!mod_requested)
104928 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
104929 - codec->vendor_id);
104930 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
104931 else
104932 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
104933 - (codec->vendor_id >> 16) & 0xffff);
104934 - request_module(name);
104935 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
104936 mod_requested++;
104937 goto again;
104938 }
104939 @@ -2739,7 +2735,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
104940 /* FIXME: set_fs() hack for obtaining user-space TLV data */
104941 mm_segment_t fs = get_fs();
104942 set_fs(get_ds());
104943 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
104944 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
104945 tlv = _tlv;
104946 set_fs(fs);
104947 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
104948 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
104949 index 4631a23..001ae57 100644
104950 --- a/sound/pci/ymfpci/ymfpci.h
104951 +++ b/sound/pci/ymfpci/ymfpci.h
104952 @@ -358,7 +358,7 @@ struct snd_ymfpci {
104953 spinlock_t reg_lock;
104954 spinlock_t voice_lock;
104955 wait_queue_head_t interrupt_sleep;
104956 - atomic_t interrupt_sleep_count;
104957 + atomic_unchecked_t interrupt_sleep_count;
104958 struct snd_info_entry *proc_entry;
104959 const struct firmware *dsp_microcode;
104960 const struct firmware *controller_microcode;
104961 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
104962 index d591c15..8cb8f94 100644
104963 --- a/sound/pci/ymfpci/ymfpci_main.c
104964 +++ b/sound/pci/ymfpci/ymfpci_main.c
104965 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
104966 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
104967 break;
104968 }
104969 - if (atomic_read(&chip->interrupt_sleep_count)) {
104970 - atomic_set(&chip->interrupt_sleep_count, 0);
104971 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
104972 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
104973 wake_up(&chip->interrupt_sleep);
104974 }
104975 __end:
104976 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
104977 continue;
104978 init_waitqueue_entry(&wait, current);
104979 add_wait_queue(&chip->interrupt_sleep, &wait);
104980 - atomic_inc(&chip->interrupt_sleep_count);
104981 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
104982 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
104983 remove_wait_queue(&chip->interrupt_sleep, &wait);
104984 }
104985 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
104986 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
104987 spin_unlock(&chip->reg_lock);
104988
104989 - if (atomic_read(&chip->interrupt_sleep_count)) {
104990 - atomic_set(&chip->interrupt_sleep_count, 0);
104991 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
104992 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
104993 wake_up(&chip->interrupt_sleep);
104994 }
104995 }
104996 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
104997 spin_lock_init(&chip->reg_lock);
104998 spin_lock_init(&chip->voice_lock);
104999 init_waitqueue_head(&chip->interrupt_sleep);
105000 - atomic_set(&chip->interrupt_sleep_count, 0);
105001 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
105002 chip->card = card;
105003 chip->pci = pci;
105004 chip->irq = -1;
105005 diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
105006 index 5428a1f..474f651 100644
105007 --- a/sound/soc/fsl/fsl_ssi.c
105008 +++ b/sound/soc/fsl/fsl_ssi.c
105009 @@ -1255,7 +1255,6 @@ static int fsl_ssi_probe(struct platform_device *pdev)
105010 {
105011 struct fsl_ssi_private *ssi_private;
105012 int ret = 0;
105013 - struct device_attribute *dev_attr = NULL;
105014 struct device_node *np = pdev->dev.of_node;
105015 const struct of_device_id *of_id;
105016 enum fsl_ssi_type hw_type;
105017 @@ -1481,7 +1480,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
105018 &ssi_private->cpu_dai_drv, 1);
105019 if (ret) {
105020 dev_err(&pdev->dev, "failed to register DAI: %d\n", ret);
105021 - goto error_dev;
105022 + goto error_clk;
105023 }
105024
105025 ret = fsl_ssi_debugfs_create(ssi_private, &pdev->dev);
105026 @@ -1562,9 +1561,6 @@ error_pcm:
105027 error_dbgfs:
105028 snd_soc_unregister_component(&pdev->dev);
105029
105030 -error_dev:
105031 - device_remove_file(&pdev->dev, dev_attr);
105032 -
105033 error_clk:
105034 if (ssi_private->ssi_on_imx) {
105035 if (!IS_ERR(ssi_private->baudclk))
105036 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
105037 index fe1df50..09d3be6 100644
105038 --- a/sound/soc/soc-core.c
105039 +++ b/sound/soc/soc-core.c
105040 @@ -2254,8 +2254,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
105041 if (ret)
105042 return ret;
105043
105044 - ops->warm_reset = snd_soc_ac97_warm_reset;
105045 - ops->reset = snd_soc_ac97_reset;
105046 + pax_open_kernel();
105047 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
105048 + *(void **)&ops->reset = snd_soc_ac97_reset;
105049 + pax_close_kernel();
105050
105051 snd_ac97_rst_cfg = cfg;
105052 return 0;
105053 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
105054 index 7778b8e..3d619fc 100644
105055 --- a/sound/synth/emux/emux_seq.c
105056 +++ b/sound/synth/emux/emux_seq.c
105057 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
105058 * MIDI emulation operators
105059 */
105060 static struct snd_midi_op emux_ops = {
105061 - snd_emux_note_on,
105062 - snd_emux_note_off,
105063 - snd_emux_key_press,
105064 - snd_emux_terminate_note,
105065 - snd_emux_control,
105066 - snd_emux_nrpn,
105067 - snd_emux_sysex,
105068 + .note_on = snd_emux_note_on,
105069 + .note_off = snd_emux_note_off,
105070 + .key_press = snd_emux_key_press,
105071 + .note_terminate = snd_emux_terminate_note,
105072 + .control = snd_emux_control,
105073 + .nrpn = snd_emux_nrpn,
105074 + .sysex = snd_emux_sysex,
105075 };
105076
105077
105078 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
105079 new file mode 100644
105080 index 0000000..4c2c45c
105081 --- /dev/null
105082 +++ b/tools/gcc/.gitignore
105083 @@ -0,0 +1,2 @@
105084 +randomize_layout_seed.h
105085 +size_overflow_hash.h
105086 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
105087 new file mode 100644
105088 index 0000000..5ca9688
105089 --- /dev/null
105090 +++ b/tools/gcc/Makefile
105091 @@ -0,0 +1,62 @@
105092 +#CC := gcc
105093 +#PLUGIN_SOURCE_FILES := pax_plugin.c
105094 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
105095 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
105096 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
105097 +
105098 +ifeq ($(PLUGINCC),$(HOSTCC))
105099 +HOSTLIBS := hostlibs
105100 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu99 -ggdb
105101 +else
105102 +HOSTLIBS := hostcxxlibs
105103 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing
105104 +endif
105105 +
105106 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
105107 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
105108 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
105109 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
105110 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
105111 +$(HOSTLIBS)-y += colorize_plugin.so
105112 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
105113 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
105114 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
105115 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
105116 +
105117 +always := $($(HOSTLIBS)-y)
105118 +
105119 +constify_plugin-objs := constify_plugin.o
105120 +stackleak_plugin-objs := stackleak_plugin.o
105121 +kallocstat_plugin-objs := kallocstat_plugin.o
105122 +kernexec_plugin-objs := kernexec_plugin.o
105123 +checker_plugin-objs := checker_plugin.o
105124 +colorize_plugin-objs := colorize_plugin.o
105125 +size_overflow_plugin-objs := size_overflow_plugin.o
105126 +latent_entropy_plugin-objs := latent_entropy_plugin.o
105127 +structleak_plugin-objs := structleak_plugin.o
105128 +randomize_layout_plugin-objs := randomize_layout_plugin.o
105129 +
105130 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
105131 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
105132 +
105133 +quiet_cmd_build_size_overflow_hash = GENHASH $@
105134 + cmd_build_size_overflow_hash = \
105135 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
105136 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
105137 + $(call if_changed,build_size_overflow_hash)
105138 +
105139 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
105140 + cmd_build_size_overflow_hash_aux = \
105141 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
105142 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
105143 + $(call if_changed,build_size_overflow_hash_aux)
105144 +
105145 +targets += size_overflow_hash.h size_overflow_hash_aux.h
105146 +
105147 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
105148 + cmd_create_randomize_layout_seed = \
105149 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
105150 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
105151 + $(call if_changed,create_randomize_layout_seed)
105152 +
105153 +targets += size_overflow_hash.h randomize_layout_seed.h randomize_layout_hash.h
105154 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
105155 new file mode 100644
105156 index 0000000..5452feea
105157 --- /dev/null
105158 +++ b/tools/gcc/checker_plugin.c
105159 @@ -0,0 +1,150 @@
105160 +/*
105161 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
105162 + * Licensed under the GPL v2
105163 + *
105164 + * Note: the choice of the license means that the compilation process is
105165 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105166 + * but for the kernel it doesn't matter since it doesn't link against
105167 + * any of the gcc libraries
105168 + *
105169 + * gcc plugin to implement various sparse (source code checker) features
105170 + *
105171 + * TODO:
105172 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
105173 + *
105174 + * BUGS:
105175 + * - none known
105176 + */
105177 +
105178 +#include "gcc-common.h"
105179 +
105180 +extern void c_register_addr_space (const char *str, addr_space_t as);
105181 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
105182 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
105183 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
105184 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
105185 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
105186 +
105187 +int plugin_is_GPL_compatible;
105188 +
105189 +static struct plugin_info checker_plugin_info = {
105190 + .version = "201304082245",
105191 + .help = NULL,
105192 +};
105193 +
105194 +#define ADDR_SPACE_KERNEL 0
105195 +#define ADDR_SPACE_FORCE_KERNEL 1
105196 +#define ADDR_SPACE_USER 2
105197 +#define ADDR_SPACE_FORCE_USER 3
105198 +#define ADDR_SPACE_IOMEM 0
105199 +#define ADDR_SPACE_FORCE_IOMEM 0
105200 +#define ADDR_SPACE_PERCPU 0
105201 +#define ADDR_SPACE_FORCE_PERCPU 0
105202 +#define ADDR_SPACE_RCU 0
105203 +#define ADDR_SPACE_FORCE_RCU 0
105204 +
105205 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
105206 +{
105207 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
105208 +}
105209 +
105210 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
105211 +{
105212 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
105213 +}
105214 +
105215 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
105216 +{
105217 + return default_addr_space_valid_pointer_mode(mode, as);
105218 +}
105219 +
105220 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
105221 +{
105222 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
105223 +}
105224 +
105225 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
105226 +{
105227 + return default_addr_space_legitimize_address(x, oldx, mode, as);
105228 +}
105229 +
105230 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
105231 +{
105232 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
105233 + return true;
105234 +
105235 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
105236 + return true;
105237 +
105238 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
105239 + return true;
105240 +
105241 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
105242 + return true;
105243 +
105244 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
105245 + return true;
105246 +
105247 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
105248 + return true;
105249 +
105250 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
105251 + return true;
105252 +
105253 + return subset == superset;
105254 +}
105255 +
105256 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
105257 +{
105258 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
105259 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
105260 +
105261 + return op;
105262 +}
105263 +
105264 +static void register_checker_address_spaces(void *event_data, void *data)
105265 +{
105266 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
105267 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
105268 + c_register_addr_space("__user", ADDR_SPACE_USER);
105269 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
105270 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
105271 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
105272 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
105273 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
105274 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
105275 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
105276 +
105277 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
105278 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
105279 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
105280 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
105281 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
105282 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
105283 + targetm.addr_space.convert = checker_addr_space_convert;
105284 +}
105285 +
105286 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105287 +{
105288 + const char * const plugin_name = plugin_info->base_name;
105289 + const int argc = plugin_info->argc;
105290 + const struct plugin_argument * const argv = plugin_info->argv;
105291 + int i;
105292 +
105293 + if (!plugin_default_version_check(version, &gcc_version)) {
105294 + error(G_("incompatible gcc/plugin versions"));
105295 + return 1;
105296 + }
105297 +
105298 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
105299 +
105300 + for (i = 0; i < argc; ++i)
105301 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105302 +
105303 + if (TARGET_64BIT == 0)
105304 + return 0;
105305 +
105306 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
105307 +
105308 + return 0;
105309 +}
105310 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
105311 new file mode 100644
105312 index 0000000..06dcfda
105313 --- /dev/null
105314 +++ b/tools/gcc/colorize_plugin.c
105315 @@ -0,0 +1,169 @@
105316 +/*
105317 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
105318 + * Licensed under the GPL v2
105319 + *
105320 + * Note: the choice of the license means that the compilation process is
105321 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105322 + * but for the kernel it doesn't matter since it doesn't link against
105323 + * any of the gcc libraries
105324 + *
105325 + * gcc plugin to colorize diagnostic output
105326 + *
105327 + */
105328 +
105329 +#include "gcc-common.h"
105330 +
105331 +int plugin_is_GPL_compatible;
105332 +
105333 +static struct plugin_info colorize_plugin_info = {
105334 + .version = "201401260140",
105335 + .help = NULL,
105336 +};
105337 +
105338 +#define GREEN "\033[32m\033[2m"
105339 +#define LIGHTGREEN "\033[32m\033[1m"
105340 +#define YELLOW "\033[33m\033[2m"
105341 +#define LIGHTYELLOW "\033[33m\033[1m"
105342 +#define RED "\033[31m\033[2m"
105343 +#define LIGHTRED "\033[31m\033[1m"
105344 +#define BLUE "\033[34m\033[2m"
105345 +#define LIGHTBLUE "\033[34m\033[1m"
105346 +#define BRIGHT "\033[m\033[1m"
105347 +#define NORMAL "\033[m"
105348 +
105349 +static diagnostic_starter_fn old_starter;
105350 +static diagnostic_finalizer_fn old_finalizer;
105351 +
105352 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
105353 +{
105354 + const char *color;
105355 + char *newprefix;
105356 +
105357 + switch (diagnostic->kind) {
105358 + case DK_NOTE:
105359 + color = LIGHTBLUE;
105360 + break;
105361 +
105362 + case DK_PEDWARN:
105363 + case DK_WARNING:
105364 + color = LIGHTYELLOW;
105365 + break;
105366 +
105367 + case DK_ERROR:
105368 + case DK_FATAL:
105369 + case DK_ICE:
105370 + case DK_PERMERROR:
105371 + case DK_SORRY:
105372 + color = LIGHTRED;
105373 + break;
105374 +
105375 + default:
105376 + color = NORMAL;
105377 + }
105378 +
105379 + old_starter(context, diagnostic);
105380 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
105381 + return;
105382 + pp_destroy_prefix(context->printer);
105383 + pp_set_prefix(context->printer, newprefix);
105384 +}
105385 +
105386 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
105387 +{
105388 + old_finalizer(context, diagnostic);
105389 +}
105390 +
105391 +static void colorize_arm(void)
105392 +{
105393 + old_starter = diagnostic_starter(global_dc);
105394 + old_finalizer = diagnostic_finalizer(global_dc);
105395 +
105396 + diagnostic_starter(global_dc) = start_colorize;
105397 + diagnostic_finalizer(global_dc) = finalize_colorize;
105398 +}
105399 +
105400 +static unsigned int execute_colorize_rearm(void)
105401 +{
105402 + if (diagnostic_starter(global_dc) == start_colorize)
105403 + return 0;
105404 +
105405 + colorize_arm();
105406 + return 0;
105407 +}
105408 +
105409 +#if BUILDING_GCC_VERSION >= 4009
105410 +static const struct pass_data colorize_rearm_pass_data = {
105411 +#else
105412 +struct simple_ipa_opt_pass colorize_rearm_pass = {
105413 + .pass = {
105414 +#endif
105415 + .type = SIMPLE_IPA_PASS,
105416 + .name = "colorize_rearm",
105417 +#if BUILDING_GCC_VERSION >= 4008
105418 + .optinfo_flags = OPTGROUP_NONE,
105419 +#endif
105420 +#if BUILDING_GCC_VERSION >= 4009
105421 + .has_gate = false,
105422 + .has_execute = true,
105423 +#else
105424 + .gate = NULL,
105425 + .execute = execute_colorize_rearm,
105426 + .sub = NULL,
105427 + .next = NULL,
105428 + .static_pass_number = 0,
105429 +#endif
105430 + .tv_id = TV_NONE,
105431 + .properties_required = 0,
105432 + .properties_provided = 0,
105433 + .properties_destroyed = 0,
105434 + .todo_flags_start = 0,
105435 + .todo_flags_finish = 0
105436 +#if BUILDING_GCC_VERSION < 4009
105437 + }
105438 +#endif
105439 +};
105440 +
105441 +#if BUILDING_GCC_VERSION >= 4009
105442 +namespace {
105443 +class colorize_rearm_pass : public simple_ipa_opt_pass {
105444 +public:
105445 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
105446 + unsigned int execute() { return execute_colorize_rearm(); }
105447 +};
105448 +}
105449 +#endif
105450 +
105451 +static struct opt_pass *make_colorize_rearm_pass(void)
105452 +{
105453 +#if BUILDING_GCC_VERSION >= 4009
105454 + return new colorize_rearm_pass();
105455 +#else
105456 + return &colorize_rearm_pass.pass;
105457 +#endif
105458 +}
105459 +
105460 +static void colorize_start_unit(void *gcc_data, void *user_data)
105461 +{
105462 + colorize_arm();
105463 +}
105464 +
105465 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105466 +{
105467 + const char * const plugin_name = plugin_info->base_name;
105468 + struct register_pass_info colorize_rearm_pass_info;
105469 +
105470 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
105471 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
105472 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
105473 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105474 +
105475 + if (!plugin_default_version_check(version, &gcc_version)) {
105476 + error(G_("incompatible gcc/plugin versions"));
105477 + return 1;
105478 + }
105479 +
105480 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
105481 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
105482 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
105483 + return 0;
105484 +}
105485 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
105486 new file mode 100644
105487 index 0000000..4f67ac1
105488 --- /dev/null
105489 +++ b/tools/gcc/constify_plugin.c
105490 @@ -0,0 +1,552 @@
105491 +/*
105492 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
105493 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
105494 + * Licensed under the GPL v2, or (at your option) v3
105495 + *
105496 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
105497 + *
105498 + * Homepage:
105499 + * http://www.grsecurity.net/~ephox/const_plugin/
105500 + *
105501 + * Usage:
105502 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
105503 + * $ gcc -fplugin=constify_plugin.so test.c -O2
105504 + */
105505 +
105506 +#include "gcc-common.h"
105507 +
105508 +// unused C type flag in all versions 4.5-4.9
105509 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
105510 +
105511 +int plugin_is_GPL_compatible;
105512 +
105513 +static struct plugin_info const_plugin_info = {
105514 + .version = "201401270210",
105515 + .help = "no-constify\tturn off constification\n",
105516 +};
105517 +
105518 +typedef struct {
105519 + bool has_fptr_field;
105520 + bool has_writable_field;
105521 + bool has_do_const_field;
105522 + bool has_no_const_field;
105523 +} constify_info;
105524 +
105525 +static const_tree get_field_type(const_tree field)
105526 +{
105527 + return strip_array_types(TREE_TYPE(field));
105528 +}
105529 +
105530 +static bool is_fptr(const_tree field)
105531 +{
105532 + const_tree ptr = get_field_type(field);
105533 +
105534 + if (TREE_CODE(ptr) != POINTER_TYPE)
105535 + return false;
105536 +
105537 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
105538 +}
105539 +
105540 +/*
105541 + * determine whether the given structure type meets the requirements for automatic constification,
105542 + * including the constification attributes on nested structure types
105543 + */
105544 +static void constifiable(const_tree node, constify_info *cinfo)
105545 +{
105546 + const_tree field;
105547 +
105548 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
105549 +
105550 + // e.g., pointer to structure fields while still constructing the structure type
105551 + if (TYPE_FIELDS(node) == NULL_TREE)
105552 + return;
105553 +
105554 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
105555 + const_tree type = get_field_type(field);
105556 + enum tree_code code = TREE_CODE(type);
105557 +
105558 + if (node == type)
105559 + continue;
105560 +
105561 + if (is_fptr(field))
105562 + cinfo->has_fptr_field = true;
105563 + else if (!TREE_READONLY(field))
105564 + cinfo->has_writable_field = true;
105565 +
105566 + if (code == RECORD_TYPE || code == UNION_TYPE) {
105567 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
105568 + cinfo->has_do_const_field = true;
105569 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
105570 + cinfo->has_no_const_field = true;
105571 + else
105572 + constifiable(type, cinfo);
105573 + }
105574 + }
105575 +}
105576 +
105577 +static bool constified(const_tree node)
105578 +{
105579 + constify_info cinfo = {
105580 + .has_fptr_field = false,
105581 + .has_writable_field = false,
105582 + .has_do_const_field = false,
105583 + .has_no_const_field = false
105584 + };
105585 +
105586 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
105587 +
105588 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
105589 +// gcc_assert(!TYPE_READONLY(node));
105590 + return false;
105591 + }
105592 +
105593 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
105594 + gcc_assert(TYPE_READONLY(node));
105595 + return true;
105596 + }
105597 +
105598 + constifiable(node, &cinfo);
105599 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
105600 + return false;
105601 +
105602 + return TYPE_READONLY(node);
105603 +}
105604 +
105605 +static void deconstify_tree(tree node);
105606 +
105607 +static void deconstify_type(tree type)
105608 +{
105609 + tree field;
105610 +
105611 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
105612 +
105613 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
105614 + const_tree fieldtype = get_field_type(field);
105615 +
105616 + // special case handling of simple ptr-to-same-array-type members
105617 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
105618 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
105619 +
105620 + if (TREE_TYPE(TREE_TYPE(field)) == type)
105621 + continue;
105622 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
105623 + continue;
105624 + if (!constified(ptrtype))
105625 + continue;
105626 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
105627 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
105628 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
105629 + }
105630 + continue;
105631 + }
105632 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
105633 + continue;
105634 + if (!constified(fieldtype))
105635 + continue;
105636 +
105637 + deconstify_tree(field);
105638 + TREE_READONLY(field) = 0;
105639 + }
105640 + TYPE_READONLY(type) = 0;
105641 + C_TYPE_FIELDS_READONLY(type) = 0;
105642 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105643 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
105644 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
105645 + }
105646 +}
105647 +
105648 +static void deconstify_tree(tree node)
105649 +{
105650 + tree old_type, new_type, field;
105651 +
105652 + old_type = TREE_TYPE(node);
105653 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
105654 + node = TREE_TYPE(node) = copy_node(old_type);
105655 + old_type = TREE_TYPE(old_type);
105656 + }
105657 +
105658 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
105659 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
105660 +
105661 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
105662 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
105663 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
105664 + DECL_FIELD_CONTEXT(field) = new_type;
105665 +
105666 + deconstify_type(new_type);
105667 +
105668 + TREE_TYPE(node) = new_type;
105669 +}
105670 +
105671 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
105672 +{
105673 + tree type;
105674 + constify_info cinfo = {
105675 + .has_fptr_field = false,
105676 + .has_writable_field = false,
105677 + .has_do_const_field = false,
105678 + .has_no_const_field = false
105679 + };
105680 +
105681 + *no_add_attrs = true;
105682 + if (TREE_CODE(*node) == FUNCTION_DECL) {
105683 + error("%qE attribute does not apply to functions (%qF)", name, *node);
105684 + return NULL_TREE;
105685 + }
105686 +
105687 + if (TREE_CODE(*node) == PARM_DECL) {
105688 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
105689 + return NULL_TREE;
105690 + }
105691 +
105692 + if (TREE_CODE(*node) == VAR_DECL) {
105693 + error("%qE attribute does not apply to variables (%qD)", name, *node);
105694 + return NULL_TREE;
105695 + }
105696 +
105697 + if (TYPE_P(*node)) {
105698 + type = *node;
105699 + } else {
105700 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
105701 + type = TREE_TYPE(*node);
105702 + }
105703 +
105704 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
105705 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
105706 + return NULL_TREE;
105707 + }
105708 +
105709 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
105710 + error("%qE attribute is already applied to the type %qT", name, type);
105711 + return NULL_TREE;
105712 + }
105713 +
105714 + if (TYPE_P(*node)) {
105715 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
105716 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
105717 + else
105718 + *no_add_attrs = false;
105719 + return NULL_TREE;
105720 + }
105721 +
105722 + constifiable(type, &cinfo);
105723 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105724 + deconstify_tree(*node);
105725 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
105726 + return NULL_TREE;
105727 + }
105728 +
105729 + error("%qE attribute used on type %qT that is not constified", name, type);
105730 + return NULL_TREE;
105731 +}
105732 +
105733 +static void constify_type(tree type)
105734 +{
105735 + TYPE_READONLY(type) = 1;
105736 + C_TYPE_FIELDS_READONLY(type) = 1;
105737 + TYPE_CONSTIFY_VISITED(type) = 1;
105738 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
105739 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
105740 +}
105741 +
105742 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
105743 +{
105744 + *no_add_attrs = true;
105745 + if (!TYPE_P(*node)) {
105746 + error("%qE attribute applies to types only (%qD)", name, *node);
105747 + return NULL_TREE;
105748 + }
105749 +
105750 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
105751 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
105752 + return NULL_TREE;
105753 + }
105754 +
105755 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
105756 + error("%qE attribute used on %qT is already applied to the type", name, *node);
105757 + return NULL_TREE;
105758 + }
105759 +
105760 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
105761 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
105762 + return NULL_TREE;
105763 + }
105764 +
105765 + *no_add_attrs = false;
105766 + return NULL_TREE;
105767 +}
105768 +
105769 +static struct attribute_spec no_const_attr = {
105770 + .name = "no_const",
105771 + .min_length = 0,
105772 + .max_length = 0,
105773 + .decl_required = false,
105774 + .type_required = false,
105775 + .function_type_required = false,
105776 + .handler = handle_no_const_attribute,
105777 +#if BUILDING_GCC_VERSION >= 4007
105778 + .affects_type_identity = true
105779 +#endif
105780 +};
105781 +
105782 +static struct attribute_spec do_const_attr = {
105783 + .name = "do_const",
105784 + .min_length = 0,
105785 + .max_length = 0,
105786 + .decl_required = false,
105787 + .type_required = false,
105788 + .function_type_required = false,
105789 + .handler = handle_do_const_attribute,
105790 +#if BUILDING_GCC_VERSION >= 4007
105791 + .affects_type_identity = true
105792 +#endif
105793 +};
105794 +
105795 +static void register_attributes(void *event_data, void *data)
105796 +{
105797 + register_attribute(&no_const_attr);
105798 + register_attribute(&do_const_attr);
105799 +}
105800 +
105801 +static void finish_type(void *event_data, void *data)
105802 +{
105803 + tree type = (tree)event_data;
105804 + constify_info cinfo = {
105805 + .has_fptr_field = false,
105806 + .has_writable_field = false,
105807 + .has_do_const_field = false,
105808 + .has_no_const_field = false
105809 + };
105810 +
105811 + if (type == NULL_TREE || type == error_mark_node)
105812 + return;
105813 +
105814 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
105815 + return;
105816 +
105817 + constifiable(type, &cinfo);
105818 +
105819 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
105820 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
105821 + deconstify_type(type);
105822 + TYPE_CONSTIFY_VISITED(type) = 1;
105823 + } else
105824 + error("'no_const' attribute used on type %qT that is not constified", type);
105825 + return;
105826 + }
105827 +
105828 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105829 + if (!cinfo.has_writable_field) {
105830 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
105831 + return;
105832 + }
105833 + constify_type(type);
105834 + return;
105835 + }
105836 +
105837 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
105838 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105839 + error("'do_const' attribute used on type %qT that is constified", type);
105840 + return;
105841 + }
105842 + constify_type(type);
105843 + return;
105844 + }
105845 +
105846 + deconstify_type(type);
105847 + TYPE_CONSTIFY_VISITED(type) = 1;
105848 +}
105849 +
105850 +static void check_global_variables(void *event_data, void *data)
105851 +{
105852 + struct varpool_node *node;
105853 +
105854 + FOR_EACH_VARIABLE(node) {
105855 + tree var = NODE_DECL(node);
105856 + tree type = TREE_TYPE(var);
105857 +
105858 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
105859 + continue;
105860 +
105861 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
105862 + continue;
105863 +
105864 + if (!TYPE_CONSTIFY_VISITED(type))
105865 + continue;
105866 +
105867 + if (DECL_EXTERNAL(var))
105868 + continue;
105869 +
105870 + if (DECL_INITIAL(var))
105871 + continue;
105872 +
105873 + // this works around a gcc bug/feature where uninitialized globals
105874 + // are moved into the .bss section regardless of any constification
105875 + DECL_INITIAL(var) = build_constructor(type, NULL);
105876 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
105877 + }
105878 +}
105879 +
105880 +static unsigned int check_local_variables(void)
105881 +{
105882 + unsigned int ret = 0;
105883 + tree var;
105884 +
105885 + unsigned int i;
105886 +
105887 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
105888 + tree type = TREE_TYPE(var);
105889 +
105890 + gcc_assert(DECL_P(var));
105891 + if (is_global_var(var))
105892 + continue;
105893 +
105894 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
105895 + continue;
105896 +
105897 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
105898 + continue;
105899 +
105900 + if (!TYPE_CONSTIFY_VISITED(type))
105901 + continue;
105902 +
105903 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
105904 + ret = 1;
105905 + }
105906 + return ret;
105907 +}
105908 +
105909 +#if BUILDING_GCC_VERSION >= 4009
105910 +static const struct pass_data check_local_variables_pass_data = {
105911 +#else
105912 +static struct gimple_opt_pass check_local_variables_pass = {
105913 + .pass = {
105914 +#endif
105915 + .type = GIMPLE_PASS,
105916 + .name = "check_local_variables",
105917 +#if BUILDING_GCC_VERSION >= 4008
105918 + .optinfo_flags = OPTGROUP_NONE,
105919 +#endif
105920 +#if BUILDING_GCC_VERSION >= 4009
105921 + .has_gate = false,
105922 + .has_execute = true,
105923 +#else
105924 + .gate = NULL,
105925 + .execute = check_local_variables,
105926 + .sub = NULL,
105927 + .next = NULL,
105928 + .static_pass_number = 0,
105929 +#endif
105930 + .tv_id = TV_NONE,
105931 + .properties_required = 0,
105932 + .properties_provided = 0,
105933 + .properties_destroyed = 0,
105934 + .todo_flags_start = 0,
105935 + .todo_flags_finish = 0
105936 +#if BUILDING_GCC_VERSION < 4009
105937 + }
105938 +#endif
105939 +};
105940 +
105941 +#if BUILDING_GCC_VERSION >= 4009
105942 +namespace {
105943 +class check_local_variables_pass : public gimple_opt_pass {
105944 +public:
105945 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
105946 + unsigned int execute() { return check_local_variables(); }
105947 +};
105948 +}
105949 +#endif
105950 +
105951 +static struct opt_pass *make_check_local_variables_pass(void)
105952 +{
105953 +#if BUILDING_GCC_VERSION >= 4009
105954 + return new check_local_variables_pass();
105955 +#else
105956 + return &check_local_variables_pass.pass;
105957 +#endif
105958 +}
105959 +
105960 +static struct {
105961 + const char *name;
105962 + const char *asm_op;
105963 +} sections[] = {
105964 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
105965 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
105966 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
105967 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
105968 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
105969 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
105970 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
105971 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
105972 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
105973 +};
105974 +
105975 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
105976 +
105977 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
105978 +{
105979 + size_t i;
105980 +
105981 + for (i = 0; i < ARRAY_SIZE(sections); i++)
105982 + if (!strcmp(sections[i].name, name))
105983 + return 0;
105984 + return old_section_type_flags(decl, name, reloc);
105985 +}
105986 +
105987 +static void constify_start_unit(void *gcc_data, void *user_data)
105988 +{
105989 +// size_t i;
105990 +
105991 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
105992 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
105993 +// sections[i].section = get_section(sections[i].name, 0, NULL);
105994 +
105995 + old_section_type_flags = targetm.section_type_flags;
105996 + targetm.section_type_flags = constify_section_type_flags;
105997 +}
105998 +
105999 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106000 +{
106001 + const char * const plugin_name = plugin_info->base_name;
106002 + const int argc = plugin_info->argc;
106003 + const struct plugin_argument * const argv = plugin_info->argv;
106004 + int i;
106005 + bool constify = true;
106006 +
106007 + struct register_pass_info check_local_variables_pass_info;
106008 +
106009 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
106010 + check_local_variables_pass_info.reference_pass_name = "ssa";
106011 + check_local_variables_pass_info.ref_pass_instance_number = 1;
106012 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
106013 +
106014 + if (!plugin_default_version_check(version, &gcc_version)) {
106015 + error(G_("incompatible gcc/plugin versions"));
106016 + return 1;
106017 + }
106018 +
106019 + for (i = 0; i < argc; ++i) {
106020 + if (!(strcmp(argv[i].key, "no-constify"))) {
106021 + constify = false;
106022 + continue;
106023 + }
106024 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
106025 + }
106026 +
106027 + if (strcmp(lang_hooks.name, "GNU C")) {
106028 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
106029 + constify = false;
106030 + }
106031 +
106032 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
106033 + if (constify) {
106034 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
106035 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
106036 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
106037 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
106038 + }
106039 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
106040 +
106041 + return 0;
106042 +}
106043 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
106044 new file mode 100644
106045 index 0000000..8af3693
106046 --- /dev/null
106047 +++ b/tools/gcc/gcc-common.h
106048 @@ -0,0 +1,287 @@
106049 +#ifndef GCC_COMMON_H_INCLUDED
106050 +#define GCC_COMMON_H_INCLUDED
106051 +
106052 +#include "plugin.h"
106053 +#include "bversion.h"
106054 +#include "plugin-version.h"
106055 +#include "config.h"
106056 +#include "system.h"
106057 +#include "coretypes.h"
106058 +#include "tm.h"
106059 +#include "line-map.h"
106060 +#include "input.h"
106061 +#include "tree.h"
106062 +
106063 +#include "tree-inline.h"
106064 +#include "version.h"
106065 +#include "rtl.h"
106066 +#include "tm_p.h"
106067 +#include "flags.h"
106068 +//#include "insn-attr.h"
106069 +//#include "insn-config.h"
106070 +//#include "insn-flags.h"
106071 +#include "hard-reg-set.h"
106072 +//#include "recog.h"
106073 +#include "output.h"
106074 +#include "except.h"
106075 +#include "function.h"
106076 +#include "toplev.h"
106077 +//#include "expr.h"
106078 +#include "basic-block.h"
106079 +#include "intl.h"
106080 +#include "ggc.h"
106081 +//#include "regs.h"
106082 +#include "timevar.h"
106083 +
106084 +#include "params.h"
106085 +#include "pointer-set.h"
106086 +#include "emit-rtl.h"
106087 +//#include "reload.h"
106088 +//#include "ira.h"
106089 +//#include "dwarf2asm.h"
106090 +#include "debug.h"
106091 +#include "target.h"
106092 +#include "langhooks.h"
106093 +#include "cfgloop.h"
106094 +//#include "hosthooks.h"
106095 +#include "cgraph.h"
106096 +#include "opts.h"
106097 +//#include "coverage.h"
106098 +//#include "value-prof.h"
106099 +
106100 +#if BUILDING_GCC_VERSION >= 4007
106101 +#include "tree-pretty-print.h"
106102 +#include "gimple-pretty-print.h"
106103 +#include "c-tree.h"
106104 +//#include "alloc-pool.h"
106105 +#endif
106106 +
106107 +#if BUILDING_GCC_VERSION <= 4008
106108 +#include "tree-flow.h"
106109 +#else
106110 +#include "tree-cfgcleanup.h"
106111 +#endif
106112 +
106113 +#include "diagnostic.h"
106114 +//#include "tree-diagnostic.h"
106115 +#include "tree-dump.h"
106116 +#include "tree-pass.h"
106117 +//#include "df.h"
106118 +#include "predict.h"
106119 +//#include "lto-streamer.h"
106120 +#include "ipa-utils.h"
106121 +
106122 +#if BUILDING_GCC_VERSION >= 4009
106123 +#include "varasm.h"
106124 +#include "stor-layout.h"
106125 +#include "internal-fn.h"
106126 +#include "gimple-expr.h"
106127 +//#include "diagnostic-color.h"
106128 +#include "context.h"
106129 +#include "tree-ssa-alias.h"
106130 +#include "stringpool.h"
106131 +#include "tree-ssanames.h"
106132 +#include "print-tree.h"
106133 +#include "tree-eh.h"
106134 +#endif
106135 +
106136 +#include "gimple.h"
106137 +
106138 +#if BUILDING_GCC_VERSION >= 4009
106139 +#include "tree-ssa-operands.h"
106140 +#include "tree-phinodes.h"
106141 +#include "tree-cfg.h"
106142 +#include "gimple-iterator.h"
106143 +#include "gimple-ssa.h"
106144 +#include "ssa-iterators.h"
106145 +#endif
106146 +
106147 +//#include "expr.h" where are you...
106148 +extern rtx emit_move_insn(rtx x, rtx y);
106149 +
106150 +// missing from basic_block.h...
106151 +extern void debug_dominance_info(enum cdi_direction dir);
106152 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
106153 +
106154 +#define __unused __attribute__((__unused__))
106155 +
106156 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
106157 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
106158 +
106159 +#if BUILDING_GCC_VERSION == 4005
106160 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
106161 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
106162 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
106163 +#define TODO_rebuild_cgraph_edges 0
106164 +
106165 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
106166 +{
106167 + tree fndecl;
106168 +
106169 + if (!is_gimple_call(stmt))
106170 + return false;
106171 + fndecl = gimple_call_fndecl(stmt);
106172 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
106173 + return false;
106174 +// print_node(stderr, "pax", fndecl, 4);
106175 + return DECL_FUNCTION_CODE(fndecl) == code;
106176 +}
106177 +
106178 +static inline bool is_simple_builtin(tree decl)
106179 +{
106180 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
106181 + return false;
106182 +
106183 + switch (DECL_FUNCTION_CODE(decl)) {
106184 + /* Builtins that expand to constants. */
106185 + case BUILT_IN_CONSTANT_P:
106186 + case BUILT_IN_EXPECT:
106187 + case BUILT_IN_OBJECT_SIZE:
106188 + case BUILT_IN_UNREACHABLE:
106189 + /* Simple register moves or loads from stack. */
106190 + case BUILT_IN_RETURN_ADDRESS:
106191 + case BUILT_IN_EXTRACT_RETURN_ADDR:
106192 + case BUILT_IN_FROB_RETURN_ADDR:
106193 + case BUILT_IN_RETURN:
106194 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
106195 + case BUILT_IN_FRAME_ADDRESS:
106196 + case BUILT_IN_VA_END:
106197 + case BUILT_IN_STACK_SAVE:
106198 + case BUILT_IN_STACK_RESTORE:
106199 + /* Exception state returns or moves registers around. */
106200 + case BUILT_IN_EH_FILTER:
106201 + case BUILT_IN_EH_POINTER:
106202 + case BUILT_IN_EH_COPY_VALUES:
106203 + return true;
106204 +
106205 + default:
106206 + return false;
106207 + }
106208 +}
106209 +#endif
106210 +
106211 +#if BUILDING_GCC_VERSION <= 4006
106212 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
106213 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
106214 +
106215 +// should come from c-tree.h if only it were installed for gcc 4.5...
106216 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
106217 +
106218 +#define get_random_seed(noinit) ({ \
106219 + unsigned HOST_WIDE_INT seed; \
106220 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
106221 + seed * seed; })
106222 +
106223 +static inline bool gimple_clobber_p(gimple s)
106224 +{
106225 + return false;
106226 +}
106227 +
106228 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
106229 +{
106230 + return implicit_built_in_decls[fncode];
106231 +}
106232 +
106233 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
106234 +{
106235 + struct cgraph_node *node = cgraph_get_node(decl);
106236 +
106237 + return node ? node : cgraph_node(decl);
106238 +}
106239 +
106240 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
106241 +{
106242 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
106243 +}
106244 +
106245 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
106246 +{
106247 + struct cgraph_node *node;
106248 +
106249 + for (node = cgraph_nodes; node; node = node->next)
106250 + if (cgraph_function_with_gimple_body_p(node))
106251 + return node;
106252 + return NULL;
106253 +}
106254 +
106255 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
106256 +{
106257 + for (node = node->next; node; node = node->next)
106258 + if (cgraph_function_with_gimple_body_p(node))
106259 + return node;
106260 + return NULL;
106261 +}
106262 +
106263 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
106264 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
106265 + (node) = cgraph_next_function_with_gimple_body(node))
106266 +#endif
106267 +
106268 +#if BUILDING_GCC_VERSION == 4006
106269 +extern void debug_gimple_stmt(gimple);
106270 +extern void debug_gimple_seq(gimple_seq);
106271 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
106272 +extern void print_gimple_stmt(FILE *, gimple, int, int);
106273 +extern void print_gimple_expr(FILE *, gimple, int, int);
106274 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
106275 +#endif
106276 +
106277 +#if BUILDING_GCC_VERSION <= 4007
106278 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
106279 +#define PROP_loops 0
106280 +
106281 +static inline int bb_loop_depth(const_basic_block bb)
106282 +{
106283 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
106284 +}
106285 +
106286 +static inline bool gimple_store_p(gimple gs)
106287 +{
106288 + tree lhs = gimple_get_lhs(gs);
106289 + return lhs && !is_gimple_reg(lhs);
106290 +}
106291 +#endif
106292 +
106293 +#if BUILDING_GCC_VERSION >= 4007
106294 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
106295 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
106296 +#endif
106297 +
106298 +#if BUILDING_GCC_VERSION <= 4008
106299 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
106300 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
106301 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
106302 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
106303 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
106304 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
106305 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
106306 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
106307 +
106308 +static inline const char *get_tree_code_name(enum tree_code code)
106309 +{
106310 + gcc_assert(code < MAX_TREE_CODES);
106311 + return tree_code_name[code];
106312 +}
106313 +
106314 +#define ipa_remove_stmt_references(cnode, stmt)
106315 +#endif
106316 +
106317 +#if BUILDING_GCC_VERSION == 4008
106318 +#define NODE_DECL(node) node->symbol.decl
106319 +#else
106320 +#define NODE_DECL(node) node->decl
106321 +#endif
106322 +
106323 +#if BUILDING_GCC_VERSION >= 4008
106324 +#define add_referenced_var(var)
106325 +#define mark_sym_for_renaming(var)
106326 +#define varpool_mark_needed_node(node)
106327 +#define TODO_dump_func 0
106328 +#define TODO_dump_cgraph 0
106329 +#endif
106330 +
106331 +#if BUILDING_GCC_VERSION >= 4009
106332 +#define TODO_ggc_collect 0
106333 +#endif
106334 +
106335 +#endif
106336 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
106337 new file mode 100644
106338 index 0000000..7514850
106339 --- /dev/null
106340 +++ b/tools/gcc/gen-random-seed.sh
106341 @@ -0,0 +1,8 @@
106342 +#!/bin/sh
106343 +
106344 +if [ ! -f "$1" ]; then
106345 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
106346 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
106347 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
106348 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
106349 +fi
106350 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
106351 new file mode 100644
106352 index 0000000..791ca76
106353 --- /dev/null
106354 +++ b/tools/gcc/generate_size_overflow_hash.sh
106355 @@ -0,0 +1,97 @@
106356 +#!/bin/bash
106357 +
106358 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
106359 +
106360 +header1="size_overflow_hash.h"
106361 +database="size_overflow_hash.data"
106362 +n=65536
106363 +hashtable_name="size_overflow_hash"
106364 +
106365 +usage() {
106366 +cat <<EOF
106367 +usage: $0 options
106368 +OPTIONS:
106369 + -h|--help help
106370 + -o header file
106371 + -d database file
106372 + -n hash array size
106373 + -s name of the hash table
106374 +EOF
106375 + return 0
106376 +}
106377 +
106378 +while true
106379 +do
106380 + case "$1" in
106381 + -h|--help) usage && exit 0;;
106382 + -n) n=$2; shift 2;;
106383 + -o) header1="$2"; shift 2;;
106384 + -d) database="$2"; shift 2;;
106385 + -s) hashtable_name="$2"; shift 2;;
106386 + --) shift 1; break ;;
106387 + *) break ;;
106388 + esac
106389 +done
106390 +
106391 +create_defines() {
106392 + for i in `seq 0 31`
106393 + do
106394 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
106395 + done
106396 + echo >> "$header1"
106397 +}
106398 +
106399 +create_structs() {
106400 + rm -f "$header1"
106401 +
106402 + create_defines
106403 +
106404 + cat "$database" | while read data
106405 + do
106406 + data_array=($data)
106407 + struct_hash_name="${data_array[0]}"
106408 + funcn="${data_array[1]}"
106409 + params="${data_array[2]}"
106410 + next="${data_array[4]}"
106411 +
106412 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
106413 +
106414 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
106415 + echo -en "\t.param\t= " >> "$header1"
106416 + line=
106417 + for param_num in ${params//-/ };
106418 + do
106419 + line="${line}PARAM"$param_num"|"
106420 + done
106421 +
106422 + echo -e "${line%?},\n};\n" >> "$header1"
106423 + done
106424 +}
106425 +
106426 +create_headers() {
106427 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
106428 +}
106429 +
106430 +create_array_elements() {
106431 + index=0
106432 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
106433 + do
106434 + data_array=($data)
106435 + i="${data_array[3]}"
106436 + hash="${data_array[0]}"
106437 + while [[ $index -lt $i ]]
106438 + do
106439 + echo -e "\t["$index"]\t= NULL," >> "$header1"
106440 + index=$(($index + 1))
106441 + done
106442 + index=$(($index + 1))
106443 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
106444 + done
106445 + echo '};' >> $header1
106446 +}
106447 +
106448 +create_structs
106449 +create_headers
106450 +create_array_elements
106451 +
106452 +exit 0
106453 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
106454 new file mode 100644
106455 index 0000000..b559327
106456 --- /dev/null
106457 +++ b/tools/gcc/kallocstat_plugin.c
106458 @@ -0,0 +1,182 @@
106459 +/*
106460 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
106461 + * Licensed under the GPL v2
106462 + *
106463 + * Note: the choice of the license means that the compilation process is
106464 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106465 + * but for the kernel it doesn't matter since it doesn't link against
106466 + * any of the gcc libraries
106467 + *
106468 + * gcc plugin to find the distribution of k*alloc sizes
106469 + *
106470 + * TODO:
106471 + *
106472 + * BUGS:
106473 + * - none known
106474 + */
106475 +
106476 +#include "gcc-common.h"
106477 +
106478 +int plugin_is_GPL_compatible;
106479 +
106480 +static struct plugin_info kallocstat_plugin_info = {
106481 + .version = "201401260140",
106482 + .help = NULL
106483 +};
106484 +
106485 +static const char * const kalloc_functions[] = {
106486 + "__kmalloc",
106487 + "kmalloc",
106488 + "kmalloc_large",
106489 + "kmalloc_node",
106490 + "kmalloc_order",
106491 + "kmalloc_order_trace",
106492 + "kmalloc_slab",
106493 + "kzalloc",
106494 + "kzalloc_node",
106495 +};
106496 +
106497 +static bool is_kalloc(const char *fnname)
106498 +{
106499 + size_t i;
106500 +
106501 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
106502 + if (!strcmp(fnname, kalloc_functions[i]))
106503 + return true;
106504 + return false;
106505 +}
106506 +
106507 +static unsigned int execute_kallocstat(void)
106508 +{
106509 + basic_block bb;
106510 +
106511 + // 1. loop through BBs and GIMPLE statements
106512 + FOR_EACH_BB_FN(bb, cfun) {
106513 + gimple_stmt_iterator gsi;
106514 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106515 + // gimple match:
106516 + tree fndecl, size;
106517 + gimple stmt;
106518 + const char *fnname;
106519 +
106520 + // is it a call
106521 + stmt = gsi_stmt(gsi);
106522 + if (!is_gimple_call(stmt))
106523 + continue;
106524 + fndecl = gimple_call_fndecl(stmt);
106525 + if (fndecl == NULL_TREE)
106526 + continue;
106527 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
106528 + continue;
106529 +
106530 + // is it a call to k*alloc
106531 + fnname = DECL_NAME_POINTER(fndecl);
106532 + if (!is_kalloc(fnname))
106533 + continue;
106534 +
106535 + // is the size arg const or the result of a simple const assignment
106536 + size = gimple_call_arg(stmt, 0);
106537 + while (true) {
106538 + expanded_location xloc;
106539 + size_t size_val;
106540 +
106541 + if (TREE_CONSTANT(size)) {
106542 + xloc = expand_location(gimple_location(stmt));
106543 + if (!xloc.file)
106544 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
106545 + size_val = TREE_INT_CST_LOW(size);
106546 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
106547 + break;
106548 + }
106549 +
106550 + if (TREE_CODE(size) != SSA_NAME)
106551 + break;
106552 + stmt = SSA_NAME_DEF_STMT(size);
106553 +//debug_gimple_stmt(stmt);
106554 +//debug_tree(size);
106555 + if (!stmt || !is_gimple_assign(stmt))
106556 + break;
106557 + if (gimple_num_ops(stmt) != 2)
106558 + break;
106559 + size = gimple_assign_rhs1(stmt);
106560 + }
106561 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
106562 +//debug_tree(gimple_call_fn(call_stmt));
106563 +//print_node(stderr, "pax", fndecl, 4);
106564 + }
106565 + }
106566 +
106567 + return 0;
106568 +}
106569 +
106570 +#if BUILDING_GCC_VERSION >= 4009
106571 +static const struct pass_data kallocstat_pass_data = {
106572 +#else
106573 +static struct gimple_opt_pass kallocstat_pass = {
106574 + .pass = {
106575 +#endif
106576 + .type = GIMPLE_PASS,
106577 + .name = "kallocstat",
106578 +#if BUILDING_GCC_VERSION >= 4008
106579 + .optinfo_flags = OPTGROUP_NONE,
106580 +#endif
106581 +#if BUILDING_GCC_VERSION >= 4009
106582 + .has_gate = false,
106583 + .has_execute = true,
106584 +#else
106585 + .gate = NULL,
106586 + .execute = execute_kallocstat,
106587 + .sub = NULL,
106588 + .next = NULL,
106589 + .static_pass_number = 0,
106590 +#endif
106591 + .tv_id = TV_NONE,
106592 + .properties_required = 0,
106593 + .properties_provided = 0,
106594 + .properties_destroyed = 0,
106595 + .todo_flags_start = 0,
106596 + .todo_flags_finish = 0
106597 +#if BUILDING_GCC_VERSION < 4009
106598 + }
106599 +#endif
106600 +};
106601 +
106602 +#if BUILDING_GCC_VERSION >= 4009
106603 +namespace {
106604 +class kallocstat_pass : public gimple_opt_pass {
106605 +public:
106606 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
106607 + unsigned int execute() { return execute_kallocstat(); }
106608 +};
106609 +}
106610 +#endif
106611 +
106612 +static struct opt_pass *make_kallocstat_pass(void)
106613 +{
106614 +#if BUILDING_GCC_VERSION >= 4009
106615 + return new kallocstat_pass();
106616 +#else
106617 + return &kallocstat_pass.pass;
106618 +#endif
106619 +}
106620 +
106621 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106622 +{
106623 + const char * const plugin_name = plugin_info->base_name;
106624 + struct register_pass_info kallocstat_pass_info;
106625 +
106626 + kallocstat_pass_info.pass = make_kallocstat_pass();
106627 + kallocstat_pass_info.reference_pass_name = "ssa";
106628 + kallocstat_pass_info.ref_pass_instance_number = 1;
106629 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
106630 +
106631 + if (!plugin_default_version_check(version, &gcc_version)) {
106632 + error(G_("incompatible gcc/plugin versions"));
106633 + return 1;
106634 + }
106635 +
106636 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
106637 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
106638 +
106639 + return 0;
106640 +}
106641 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
106642 new file mode 100644
106643 index 0000000..dd73713
106644 --- /dev/null
106645 +++ b/tools/gcc/kernexec_plugin.c
106646 @@ -0,0 +1,519 @@
106647 +/*
106648 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
106649 + * Licensed under the GPL v2
106650 + *
106651 + * Note: the choice of the license means that the compilation process is
106652 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106653 + * but for the kernel it doesn't matter since it doesn't link against
106654 + * any of the gcc libraries
106655 + *
106656 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
106657 + *
106658 + * TODO:
106659 + *
106660 + * BUGS:
106661 + * - none known
106662 + */
106663 +
106664 +#include "gcc-common.h"
106665 +
106666 +int plugin_is_GPL_compatible;
106667 +
106668 +static struct plugin_info kernexec_plugin_info = {
106669 + .version = "201401260140",
106670 + .help = "method=[bts|or]\tinstrumentation method\n"
106671 +};
106672 +
106673 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
106674 +static void (*kernexec_instrument_retaddr)(rtx);
106675 +
106676 +/*
106677 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
106678 + */
106679 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
106680 +{
106681 + gimple asm_movabs_stmt;
106682 +
106683 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
106684 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
106685 + gimple_asm_set_volatile(asm_movabs_stmt, true);
106686 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
106687 + update_stmt(asm_movabs_stmt);
106688 +}
106689 +
106690 +/*
106691 + * find all asm() stmts that clobber r12 and add a reload of r12
106692 + */
106693 +static unsigned int execute_kernexec_reload(void)
106694 +{
106695 + basic_block bb;
106696 +
106697 + // 1. loop through BBs and GIMPLE statements
106698 + FOR_EACH_BB_FN(bb, cfun) {
106699 + gimple_stmt_iterator gsi;
106700 +
106701 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106702 + // gimple match: __asm__ ("" : : : "r12");
106703 + gimple asm_stmt;
106704 + size_t nclobbers;
106705 +
106706 + // is it an asm ...
106707 + asm_stmt = gsi_stmt(gsi);
106708 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
106709 + continue;
106710 +
106711 + // ... clobbering r12
106712 + nclobbers = gimple_asm_nclobbers(asm_stmt);
106713 + while (nclobbers--) {
106714 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
106715 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
106716 + continue;
106717 + kernexec_reload_fptr_mask(&gsi);
106718 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
106719 + break;
106720 + }
106721 + }
106722 + }
106723 +
106724 + return 0;
106725 +}
106726 +
106727 +/*
106728 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
106729 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
106730 + */
106731 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
106732 +{
106733 + gimple assign_intptr, assign_new_fptr, call_stmt;
106734 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
106735 +
106736 + call_stmt = gsi_stmt(*gsi);
106737 + old_fptr = gimple_call_fn(call_stmt);
106738 +
106739 + // create temporary unsigned long variable used for bitops and cast fptr to it
106740 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
106741 + add_referenced_var(intptr);
106742 + intptr = make_ssa_name(intptr, NULL);
106743 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
106744 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
106745 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
106746 + update_stmt(assign_intptr);
106747 +
106748 + // apply logical or to temporary unsigned long and bitmask
106749 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
106750 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
106751 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
106752 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
106753 + assign_intptr = gimple_build_assign(intptr, orptr);
106754 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
106755 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
106756 + update_stmt(assign_intptr);
106757 +
106758 + // cast temporary unsigned long back to a temporary fptr variable
106759 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
106760 + add_referenced_var(new_fptr);
106761 + new_fptr = make_ssa_name(new_fptr, NULL);
106762 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
106763 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
106764 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
106765 + update_stmt(assign_new_fptr);
106766 +
106767 + // replace call stmt fn with the new fptr
106768 + gimple_call_set_fn(call_stmt, new_fptr);
106769 + update_stmt(call_stmt);
106770 +}
106771 +
106772 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
106773 +{
106774 + gimple asm_or_stmt, call_stmt;
106775 + tree old_fptr, new_fptr, input, output;
106776 +#if BUILDING_GCC_VERSION <= 4007
106777 + VEC(tree, gc) *inputs = NULL;
106778 + VEC(tree, gc) *outputs = NULL;
106779 +#else
106780 + vec<tree, va_gc> *inputs = NULL;
106781 + vec<tree, va_gc> *outputs = NULL;
106782 +#endif
106783 +
106784 + call_stmt = gsi_stmt(*gsi);
106785 + old_fptr = gimple_call_fn(call_stmt);
106786 +
106787 + // create temporary fptr variable
106788 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
106789 + add_referenced_var(new_fptr);
106790 + new_fptr = make_ssa_name(new_fptr, NULL);
106791 +
106792 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
106793 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
106794 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
106795 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
106796 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
106797 +#if BUILDING_GCC_VERSION <= 4007
106798 + VEC_safe_push(tree, gc, inputs, input);
106799 + VEC_safe_push(tree, gc, outputs, output);
106800 +#else
106801 + vec_safe_push(inputs, input);
106802 + vec_safe_push(outputs, output);
106803 +#endif
106804 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
106805 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
106806 + gimple_asm_set_volatile(asm_or_stmt, true);
106807 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
106808 + update_stmt(asm_or_stmt);
106809 +
106810 + // replace call stmt fn with the new fptr
106811 + gimple_call_set_fn(call_stmt, new_fptr);
106812 + update_stmt(call_stmt);
106813 +}
106814 +
106815 +/*
106816 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
106817 + */
106818 +static unsigned int execute_kernexec_fptr(void)
106819 +{
106820 + basic_block bb;
106821 +
106822 + // 1. loop through BBs and GIMPLE statements
106823 + FOR_EACH_BB_FN(bb, cfun) {
106824 + gimple_stmt_iterator gsi;
106825 +
106826 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106827 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
106828 + tree fn;
106829 + gimple call_stmt;
106830 +
106831 + // is it a call ...
106832 + call_stmt = gsi_stmt(gsi);
106833 + if (!is_gimple_call(call_stmt))
106834 + continue;
106835 + fn = gimple_call_fn(call_stmt);
106836 + if (TREE_CODE(fn) == ADDR_EXPR)
106837 + continue;
106838 + if (TREE_CODE(fn) != SSA_NAME)
106839 + gcc_unreachable();
106840 +
106841 + // ... through a function pointer
106842 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
106843 + fn = SSA_NAME_VAR(fn);
106844 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
106845 + debug_tree(fn);
106846 + gcc_unreachable();
106847 + }
106848 + }
106849 + fn = TREE_TYPE(fn);
106850 + if (TREE_CODE(fn) != POINTER_TYPE)
106851 + continue;
106852 + fn = TREE_TYPE(fn);
106853 + if (TREE_CODE(fn) != FUNCTION_TYPE)
106854 + continue;
106855 +
106856 + kernexec_instrument_fptr(&gsi);
106857 +
106858 +//debug_tree(gimple_call_fn(call_stmt));
106859 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
106860 + }
106861 + }
106862 +
106863 + return 0;
106864 +}
106865 +
106866 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
106867 +static void kernexec_instrument_retaddr_bts(rtx insn)
106868 +{
106869 + rtx btsq;
106870 + rtvec argvec, constraintvec, labelvec;
106871 + int line;
106872 +
106873 + // create asm volatile("btsq $63,(%%rsp)":::)
106874 + argvec = rtvec_alloc(0);
106875 + constraintvec = rtvec_alloc(0);
106876 + labelvec = rtvec_alloc(0);
106877 + line = expand_location(RTL_LOCATION(insn)).line;
106878 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
106879 + MEM_VOLATILE_P(btsq) = 1;
106880 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
106881 + emit_insn_before(btsq, insn);
106882 +}
106883 +
106884 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
106885 +static void kernexec_instrument_retaddr_or(rtx insn)
106886 +{
106887 + rtx orq;
106888 + rtvec argvec, constraintvec, labelvec;
106889 + int line;
106890 +
106891 + // create asm volatile("orq %%r12,(%%rsp)":::)
106892 + argvec = rtvec_alloc(0);
106893 + constraintvec = rtvec_alloc(0);
106894 + labelvec = rtvec_alloc(0);
106895 + line = expand_location(RTL_LOCATION(insn)).line;
106896 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
106897 + MEM_VOLATILE_P(orq) = 1;
106898 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
106899 + emit_insn_before(orq, insn);
106900 +}
106901 +
106902 +/*
106903 + * find all asm level function returns and forcibly set the highest bit of the return address
106904 + */
106905 +static unsigned int execute_kernexec_retaddr(void)
106906 +{
106907 + rtx insn;
106908 +
106909 +// if (stack_realign_drap)
106910 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
106911 +
106912 + // 1. find function returns
106913 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
106914 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
106915 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
106916 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
106917 + rtx body;
106918 +
106919 + // is it a retn
106920 + if (!JUMP_P(insn))
106921 + continue;
106922 + body = PATTERN(insn);
106923 + if (GET_CODE(body) == PARALLEL)
106924 + body = XVECEXP(body, 0, 0);
106925 + if (!ANY_RETURN_P(body))
106926 + continue;
106927 + kernexec_instrument_retaddr(insn);
106928 + }
106929 +
106930 +// print_simple_rtl(stderr, get_insns());
106931 +// print_rtl(stderr, get_insns());
106932 +
106933 + return 0;
106934 +}
106935 +
106936 +static bool kernexec_cmodel_check(void)
106937 +{
106938 + tree section;
106939 +
106940 + if (ix86_cmodel != CM_KERNEL)
106941 + return false;
106942 +
106943 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
106944 + if (!section || !TREE_VALUE(section))
106945 + return true;
106946 +
106947 + section = TREE_VALUE(TREE_VALUE(section));
106948 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
106949 + return true;
106950 +
106951 + return false;
106952 +}
106953 +
106954 +#if BUILDING_GCC_VERSION >= 4009
106955 +static const struct pass_data kernexec_reload_pass_data = {
106956 +#else
106957 +static struct gimple_opt_pass kernexec_reload_pass = {
106958 + .pass = {
106959 +#endif
106960 + .type = GIMPLE_PASS,
106961 + .name = "kernexec_reload",
106962 +#if BUILDING_GCC_VERSION >= 4008
106963 + .optinfo_flags = OPTGROUP_NONE,
106964 +#endif
106965 +#if BUILDING_GCC_VERSION >= 4009
106966 + .has_gate = true,
106967 + .has_execute = true,
106968 +#else
106969 + .gate = kernexec_cmodel_check,
106970 + .execute = execute_kernexec_reload,
106971 + .sub = NULL,
106972 + .next = NULL,
106973 + .static_pass_number = 0,
106974 +#endif
106975 + .tv_id = TV_NONE,
106976 + .properties_required = 0,
106977 + .properties_provided = 0,
106978 + .properties_destroyed = 0,
106979 + .todo_flags_start = 0,
106980 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
106981 +#if BUILDING_GCC_VERSION < 4009
106982 + }
106983 +#endif
106984 +};
106985 +
106986 +#if BUILDING_GCC_VERSION >= 4009
106987 +static const struct pass_data kernexec_fptr_pass_data = {
106988 +#else
106989 +static struct gimple_opt_pass kernexec_fptr_pass = {
106990 + .pass = {
106991 +#endif
106992 + .type = GIMPLE_PASS,
106993 + .name = "kernexec_fptr",
106994 +#if BUILDING_GCC_VERSION >= 4008
106995 + .optinfo_flags = OPTGROUP_NONE,
106996 +#endif
106997 +#if BUILDING_GCC_VERSION >= 4009
106998 + .has_gate = true,
106999 + .has_execute = true,
107000 +#else
107001 + .gate = kernexec_cmodel_check,
107002 + .execute = execute_kernexec_fptr,
107003 + .sub = NULL,
107004 + .next = NULL,
107005 + .static_pass_number = 0,
107006 +#endif
107007 + .tv_id = TV_NONE,
107008 + .properties_required = 0,
107009 + .properties_provided = 0,
107010 + .properties_destroyed = 0,
107011 + .todo_flags_start = 0,
107012 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
107013 +#if BUILDING_GCC_VERSION < 4009
107014 + }
107015 +#endif
107016 +};
107017 +
107018 +#if BUILDING_GCC_VERSION >= 4009
107019 +static const struct pass_data kernexec_retaddr_pass_data = {
107020 +#else
107021 +static struct rtl_opt_pass kernexec_retaddr_pass = {
107022 + .pass = {
107023 +#endif
107024 + .type = RTL_PASS,
107025 + .name = "kernexec_retaddr",
107026 +#if BUILDING_GCC_VERSION >= 4008
107027 + .optinfo_flags = OPTGROUP_NONE,
107028 +#endif
107029 +#if BUILDING_GCC_VERSION >= 4009
107030 + .has_gate = true,
107031 + .has_execute = true,
107032 +#else
107033 + .gate = kernexec_cmodel_check,
107034 + .execute = execute_kernexec_retaddr,
107035 + .sub = NULL,
107036 + .next = NULL,
107037 + .static_pass_number = 0,
107038 +#endif
107039 + .tv_id = TV_NONE,
107040 + .properties_required = 0,
107041 + .properties_provided = 0,
107042 + .properties_destroyed = 0,
107043 + .todo_flags_start = 0,
107044 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
107045 +#if BUILDING_GCC_VERSION < 4009
107046 + }
107047 +#endif
107048 +};
107049 +
107050 +#if BUILDING_GCC_VERSION >= 4009
107051 +namespace {
107052 +class kernexec_reload_pass : public gimple_opt_pass {
107053 +public:
107054 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
107055 + bool gate() { return kernexec_cmodel_check(); }
107056 + unsigned int execute() { return execute_kernexec_reload(); }
107057 +};
107058 +
107059 +class kernexec_fptr_pass : public gimple_opt_pass {
107060 +public:
107061 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
107062 + bool gate() { return kernexec_cmodel_check(); }
107063 + unsigned int execute() { return execute_kernexec_fptr(); }
107064 +};
107065 +
107066 +class kernexec_retaddr_pass : public rtl_opt_pass {
107067 +public:
107068 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
107069 + bool gate() { return kernexec_cmodel_check(); }
107070 + unsigned int execute() { return execute_kernexec_retaddr(); }
107071 +};
107072 +}
107073 +#endif
107074 +
107075 +static struct opt_pass *make_kernexec_reload_pass(void)
107076 +{
107077 +#if BUILDING_GCC_VERSION >= 4009
107078 + return new kernexec_reload_pass();
107079 +#else
107080 + return &kernexec_reload_pass.pass;
107081 +#endif
107082 +}
107083 +
107084 +static struct opt_pass *make_kernexec_fptr_pass(void)
107085 +{
107086 +#if BUILDING_GCC_VERSION >= 4009
107087 + return new kernexec_fptr_pass();
107088 +#else
107089 + return &kernexec_fptr_pass.pass;
107090 +#endif
107091 +}
107092 +
107093 +static struct opt_pass *make_kernexec_retaddr_pass(void)
107094 +{
107095 +#if BUILDING_GCC_VERSION >= 4009
107096 + return new kernexec_retaddr_pass();
107097 +#else
107098 + return &kernexec_retaddr_pass.pass;
107099 +#endif
107100 +}
107101 +
107102 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107103 +{
107104 + const char * const plugin_name = plugin_info->base_name;
107105 + const int argc = plugin_info->argc;
107106 + const struct plugin_argument * const argv = plugin_info->argv;
107107 + int i;
107108 + struct register_pass_info kernexec_reload_pass_info;
107109 + struct register_pass_info kernexec_fptr_pass_info;
107110 + struct register_pass_info kernexec_retaddr_pass_info;
107111 +
107112 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
107113 + kernexec_reload_pass_info.reference_pass_name = "ssa";
107114 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
107115 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107116 +
107117 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
107118 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
107119 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
107120 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107121 +
107122 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
107123 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
107124 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
107125 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107126 +
107127 + if (!plugin_default_version_check(version, &gcc_version)) {
107128 + error(G_("incompatible gcc/plugin versions"));
107129 + return 1;
107130 + }
107131 +
107132 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
107133 +
107134 + if (TARGET_64BIT == 0)
107135 + return 0;
107136 +
107137 + for (i = 0; i < argc; ++i) {
107138 + if (!strcmp(argv[i].key, "method")) {
107139 + if (!argv[i].value) {
107140 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107141 + continue;
107142 + }
107143 + if (!strcmp(argv[i].value, "bts")) {
107144 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
107145 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
107146 + } else if (!strcmp(argv[i].value, "or")) {
107147 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
107148 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
107149 + fix_register("r12", 1, 1);
107150 + } else
107151 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
107152 + continue;
107153 + }
107154 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107155 + }
107156 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
107157 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
107158 +
107159 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
107160 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
107161 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
107162 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
107163 +
107164 + return 0;
107165 +}
107166 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
107167 new file mode 100644
107168 index 0000000..319229d
107169 --- /dev/null
107170 +++ b/tools/gcc/latent_entropy_plugin.c
107171 @@ -0,0 +1,457 @@
107172 +/*
107173 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
107174 + * Licensed under the GPL v2
107175 + *
107176 + * Note: the choice of the license means that the compilation process is
107177 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
107178 + * but for the kernel it doesn't matter since it doesn't link against
107179 + * any of the gcc libraries
107180 + *
107181 + * gcc plugin to help generate a little bit of entropy from program state,
107182 + * used throughout the uptime of the kernel
107183 + *
107184 + * TODO:
107185 + * - add ipa pass to identify not explicitly marked candidate functions
107186 + * - mix in more program state (function arguments/return values, loop variables, etc)
107187 + * - more instrumentation control via attribute parameters
107188 + *
107189 + * BUGS:
107190 + * - LTO needs -flto-partition=none for now
107191 + */
107192 +
107193 +#include "gcc-common.h"
107194 +
107195 +int plugin_is_GPL_compatible;
107196 +
107197 +static tree latent_entropy_decl;
107198 +
107199 +static struct plugin_info latent_entropy_plugin_info = {
107200 + .version = "201403280150",
107201 + .help = NULL
107202 +};
107203 +
107204 +static unsigned HOST_WIDE_INT seed;
107205 +static unsigned HOST_WIDE_INT get_random_const(void)
107206 +{
107207 + unsigned int i;
107208 + unsigned HOST_WIDE_INT ret = 0;
107209 +
107210 + for (i = 0; i < 8 * sizeof ret; i++) {
107211 + ret = (ret << 1) | (seed & 1);
107212 + seed >>= 1;
107213 + if (ret & 1)
107214 + seed ^= 0xD800000000000000ULL;
107215 + }
107216 +
107217 + return ret;
107218 +}
107219 +
107220 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107221 +{
107222 + tree type;
107223 + unsigned long long mask;
107224 +#if BUILDING_GCC_VERSION <= 4007
107225 + VEC(constructor_elt, gc) *vals;
107226 +#else
107227 + vec<constructor_elt, va_gc> *vals;
107228 +#endif
107229 +
107230 + switch (TREE_CODE(*node)) {
107231 + default:
107232 + *no_add_attrs = true;
107233 + error("%qE attribute only applies to functions and variables", name);
107234 + break;
107235 +
107236 + case VAR_DECL:
107237 + if (DECL_INITIAL(*node)) {
107238 + *no_add_attrs = true;
107239 + error("variable %qD with %qE attribute must not be initialized", *node, name);
107240 + break;
107241 + }
107242 +
107243 + if (!TREE_STATIC(*node)) {
107244 + *no_add_attrs = true;
107245 + error("variable %qD with %qE attribute must not be local", *node, name);
107246 + break;
107247 + }
107248 +
107249 + type = TREE_TYPE(*node);
107250 + switch (TREE_CODE(type)) {
107251 + default:
107252 + *no_add_attrs = true;
107253 + error("variable %qD with %qE attribute must be an integer or a fixed length integer array type or a fixed sized structure with integer fields", *node, name);
107254 + break;
107255 +
107256 + case RECORD_TYPE: {
107257 + tree field;
107258 + unsigned int nelt = 0;
107259 +
107260 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
107261 + tree fieldtype;
107262 +
107263 + fieldtype = TREE_TYPE(field);
107264 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
107265 + *no_add_attrs = true;
107266 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
107267 + break;
107268 + }
107269 + }
107270 +
107271 + if (field)
107272 + break;
107273 +
107274 +#if BUILDING_GCC_VERSION <= 4007
107275 + vals = VEC_alloc(constructor_elt, gc, nelt);
107276 +#else
107277 + vec_alloc(vals, nelt);
107278 +#endif
107279 +
107280 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
107281 + tree fieldtype;
107282 +
107283 + fieldtype = TREE_TYPE(field);
107284 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
107285 + mask = 2 * (mask - 1) + 1;
107286 +
107287 + if (TYPE_UNSIGNED(fieldtype))
107288 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
107289 + else
107290 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
107291 + }
107292 +
107293 + DECL_INITIAL(*node) = build_constructor(type, vals);
107294 +//debug_tree(DECL_INITIAL(*node));
107295 + break;
107296 + }
107297 +
107298 + case INTEGER_TYPE:
107299 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
107300 + mask = 2 * (mask - 1) + 1;
107301 +
107302 + if (TYPE_UNSIGNED(type))
107303 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
107304 + else
107305 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
107306 + break;
107307 +
107308 + case ARRAY_TYPE: {
107309 + tree elt_type, array_size, elt_size;
107310 + unsigned int i, nelt;
107311 +
107312 + elt_type = TREE_TYPE(type);
107313 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
107314 + array_size = TYPE_SIZE_UNIT(type);
107315 +
107316 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
107317 + *no_add_attrs = true;
107318 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
107319 + break;
107320 + }
107321 +
107322 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
107323 +#if BUILDING_GCC_VERSION <= 4007
107324 + vals = VEC_alloc(constructor_elt, gc, nelt);
107325 +#else
107326 + vec_alloc(vals, nelt);
107327 +#endif
107328 +
107329 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
107330 + mask = 2 * (mask - 1) + 1;
107331 +
107332 + for (i = 0; i < nelt; i++)
107333 + if (TYPE_UNSIGNED(elt_type))
107334 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
107335 + else
107336 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
107337 +
107338 + DECL_INITIAL(*node) = build_constructor(type, vals);
107339 +//debug_tree(DECL_INITIAL(*node));
107340 + break;
107341 + }
107342 + }
107343 + break;
107344 +
107345 + case FUNCTION_DECL:
107346 + break;
107347 + }
107348 +
107349 + return NULL_TREE;
107350 +}
107351 +
107352 +static struct attribute_spec latent_entropy_attr = {
107353 + .name = "latent_entropy",
107354 + .min_length = 0,
107355 + .max_length = 0,
107356 + .decl_required = true,
107357 + .type_required = false,
107358 + .function_type_required = false,
107359 + .handler = handle_latent_entropy_attribute,
107360 +#if BUILDING_GCC_VERSION >= 4007
107361 + .affects_type_identity = false
107362 +#endif
107363 +};
107364 +
107365 +static void register_attributes(void *event_data, void *data)
107366 +{
107367 + register_attribute(&latent_entropy_attr);
107368 +}
107369 +
107370 +static bool gate_latent_entropy(void)
107371 +{
107372 + // don't bother with noreturn functions for now
107373 + if (TREE_THIS_VOLATILE(current_function_decl))
107374 + return false;
107375 +
107376 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
107377 +}
107378 +
107379 +static enum tree_code get_op(tree *rhs)
107380 +{
107381 + static enum tree_code op;
107382 + unsigned HOST_WIDE_INT random_const;
107383 +
107384 + random_const = get_random_const();
107385 +
107386 + switch (op) {
107387 + case BIT_XOR_EXPR:
107388 + op = PLUS_EXPR;
107389 + break;
107390 +
107391 + case PLUS_EXPR:
107392 + if (rhs) {
107393 + op = LROTATE_EXPR;
107394 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
107395 + break;
107396 + }
107397 +
107398 + case LROTATE_EXPR:
107399 + default:
107400 + op = BIT_XOR_EXPR;
107401 + break;
107402 + }
107403 + if (rhs)
107404 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
107405 + return op;
107406 +}
107407 +
107408 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
107409 +{
107410 + gimple_stmt_iterator gsi;
107411 + gimple assign;
107412 + tree addxorrol, rhs;
107413 + enum tree_code op;
107414 +
107415 + op = get_op(&rhs);
107416 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
107417 + assign = gimple_build_assign(local_entropy, addxorrol);
107418 + gsi = gsi_after_labels(bb);
107419 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
107420 + update_stmt(assign);
107421 +//debug_bb(bb);
107422 +}
107423 +
107424 +static void perturb_latent_entropy(basic_block bb, tree rhs)
107425 +{
107426 + gimple_stmt_iterator gsi;
107427 + gimple assign;
107428 + tree addxorrol, temp;
107429 +
107430 + // 1. create temporary copy of latent_entropy
107431 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
107432 + add_referenced_var(temp);
107433 +
107434 + // 2. read...
107435 + temp = make_ssa_name(temp, NULL);
107436 + assign = gimple_build_assign(temp, latent_entropy_decl);
107437 + SSA_NAME_DEF_STMT(temp) = assign;
107438 + add_referenced_var(latent_entropy_decl);
107439 + gsi = gsi_after_labels(bb);
107440 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107441 + update_stmt(assign);
107442 +
107443 + // 3. ...modify...
107444 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
107445 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
107446 + assign = gimple_build_assign(temp, addxorrol);
107447 + SSA_NAME_DEF_STMT(temp) = assign;
107448 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107449 + update_stmt(assign);
107450 +
107451 + // 4. ...write latent_entropy
107452 + assign = gimple_build_assign(latent_entropy_decl, temp);
107453 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107454 + update_stmt(assign);
107455 +}
107456 +
107457 +static unsigned int execute_latent_entropy(void)
107458 +{
107459 + basic_block bb;
107460 + gimple assign;
107461 + gimple_stmt_iterator gsi;
107462 + tree local_entropy;
107463 +
107464 + if (!latent_entropy_decl) {
107465 + struct varpool_node *node;
107466 +
107467 + FOR_EACH_VARIABLE(node) {
107468 + tree var = NODE_DECL(node);
107469 +
107470 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
107471 + continue;
107472 + latent_entropy_decl = var;
107473 +// debug_tree(var);
107474 + break;
107475 + }
107476 + if (!latent_entropy_decl) {
107477 +// debug_tree(current_function_decl);
107478 + return 0;
107479 + }
107480 + }
107481 +
107482 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
107483 +
107484 + // 1. create local entropy variable
107485 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
107486 + add_referenced_var(local_entropy);
107487 + mark_sym_for_renaming(local_entropy);
107488 +
107489 + // 2. initialize local entropy variable
107490 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
107491 + if (dom_info_available_p(CDI_DOMINATORS))
107492 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
107493 + gsi = gsi_start_bb(bb);
107494 +
107495 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
107496 +// gimple_set_location(assign, loc);
107497 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107498 + update_stmt(assign);
107499 +//debug_bb(bb);
107500 + gcc_assert(single_succ_p(bb));
107501 + bb = single_succ(bb);
107502 +
107503 + // 3. instrument each BB with an operation on the local entropy variable
107504 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
107505 + perturb_local_entropy(bb, local_entropy);
107506 +//debug_bb(bb);
107507 + bb = bb->next_bb;
107508 + };
107509 +
107510 + // 4. mix local entropy into the global entropy variable
107511 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
107512 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
107513 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
107514 + return 0;
107515 +}
107516 +
107517 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
107518 +{
107519 + tree latent_entropy_type;
107520 +
107521 + seed = get_random_seed(false);
107522 +
107523 + if (in_lto_p)
107524 + return;
107525 +
107526 + // extern volatile u64 latent_entropy
107527 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
107528 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
107529 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
107530 +
107531 + TREE_STATIC(latent_entropy_decl) = 1;
107532 + TREE_PUBLIC(latent_entropy_decl) = 1;
107533 + TREE_USED(latent_entropy_decl) = 1;
107534 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
107535 + DECL_EXTERNAL(latent_entropy_decl) = 1;
107536 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
107537 + lang_hooks.decls.pushdecl(latent_entropy_decl);
107538 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
107539 +// varpool_finalize_decl(latent_entropy_decl);
107540 +// varpool_mark_needed_node(latent_entropy_decl);
107541 +}
107542 +
107543 +#if BUILDING_GCC_VERSION >= 4009
107544 +static const struct pass_data latent_entropy_pass_data = {
107545 +#else
107546 +static struct gimple_opt_pass latent_entropy_pass = {
107547 + .pass = {
107548 +#endif
107549 + .type = GIMPLE_PASS,
107550 + .name = "latent_entropy",
107551 +#if BUILDING_GCC_VERSION >= 4008
107552 + .optinfo_flags = OPTGROUP_NONE,
107553 +#endif
107554 +#if BUILDING_GCC_VERSION >= 4009
107555 + .has_gate = true,
107556 + .has_execute = true,
107557 +#else
107558 + .gate = gate_latent_entropy,
107559 + .execute = execute_latent_entropy,
107560 + .sub = NULL,
107561 + .next = NULL,
107562 + .static_pass_number = 0,
107563 +#endif
107564 + .tv_id = TV_NONE,
107565 + .properties_required = PROP_gimple_leh | PROP_cfg,
107566 + .properties_provided = 0,
107567 + .properties_destroyed = 0,
107568 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
107569 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
107570 +#if BUILDING_GCC_VERSION < 4009
107571 + }
107572 +#endif
107573 +};
107574 +
107575 +#if BUILDING_GCC_VERSION >= 4009
107576 +namespace {
107577 +class latent_entropy_pass : public gimple_opt_pass {
107578 +public:
107579 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
107580 + bool gate() { return gate_latent_entropy(); }
107581 + unsigned int execute() { return execute_latent_entropy(); }
107582 +};
107583 +}
107584 +#endif
107585 +
107586 +static struct opt_pass *make_latent_entropy_pass(void)
107587 +{
107588 +#if BUILDING_GCC_VERSION >= 4009
107589 + return new latent_entropy_pass();
107590 +#else
107591 + return &latent_entropy_pass.pass;
107592 +#endif
107593 +}
107594 +
107595 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107596 +{
107597 + const char * const plugin_name = plugin_info->base_name;
107598 + struct register_pass_info latent_entropy_pass_info;
107599 +
107600 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
107601 + latent_entropy_pass_info.reference_pass_name = "optimized";
107602 + latent_entropy_pass_info.ref_pass_instance_number = 1;
107603 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
107604 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
107605 + {
107606 + .base = &latent_entropy_decl,
107607 + .nelt = 1,
107608 + .stride = sizeof(latent_entropy_decl),
107609 + .cb = &gt_ggc_mx_tree_node,
107610 + .pchw = &gt_pch_nx_tree_node
107611 + },
107612 + LAST_GGC_ROOT_TAB
107613 + };
107614 +
107615 + if (!plugin_default_version_check(version, &gcc_version)) {
107616 + error(G_("incompatible gcc/plugin versions"));
107617 + return 1;
107618 + }
107619 +
107620 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
107621 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
107622 + if (!in_lto_p)
107623 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
107624 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
107625 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
107626 +
107627 + return 0;
107628 +}
107629 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
107630 new file mode 100644
107631 index 0000000..8dafb22
107632 --- /dev/null
107633 +++ b/tools/gcc/randomize_layout_plugin.c
107634 @@ -0,0 +1,910 @@
107635 +/*
107636 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
107637 + * and PaX Team <pageexec@freemail.hu>
107638 + * Licensed under the GPL v2
107639 + *
107640 + * Usage:
107641 + * $ # for 4.5/4.6/C based 4.7
107642 + * $ 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
107643 + * $ # for C++ based 4.7/4.8+
107644 + * $ 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
107645 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
107646 + */
107647 +
107648 +#include "gcc-common.h"
107649 +#include "randomize_layout_seed.h"
107650 +
107651 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
107652 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
107653 +#endif
107654 +
107655 +#define ORIG_TYPE_NAME(node) \
107656 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
107657 +
107658 +int plugin_is_GPL_compatible;
107659 +
107660 +static int performance_mode;
107661 +
107662 +static struct plugin_info randomize_layout_plugin_info = {
107663 + .version = "201402201816",
107664 + .help = "disable\t\t\tdo not activate plugin\n"
107665 + "performance-mode\tenable cacheline-aware layout randomization\n"
107666 +};
107667 +
107668 +/* from old Linux dcache.h */
107669 +static inline unsigned long
107670 +partial_name_hash(unsigned long c, unsigned long prevhash)
107671 +{
107672 + return (prevhash + (c << 4) + (c >> 4)) * 11;
107673 +}
107674 +static inline unsigned int
107675 +name_hash(const unsigned char *name)
107676 +{
107677 + unsigned long hash = 0;
107678 + unsigned int len = strlen((const char *)name);
107679 + while (len--)
107680 + hash = partial_name_hash(*name++, hash);
107681 + return (unsigned int)hash;
107682 +}
107683 +
107684 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107685 +{
107686 + tree type;
107687 +
107688 + *no_add_attrs = true;
107689 + if (TREE_CODE(*node) == FUNCTION_DECL) {
107690 + error("%qE attribute does not apply to functions (%qF)", name, *node);
107691 + return NULL_TREE;
107692 + }
107693 +
107694 + if (TREE_CODE(*node) == PARM_DECL) {
107695 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
107696 + return NULL_TREE;
107697 + }
107698 +
107699 + if (TREE_CODE(*node) == VAR_DECL) {
107700 + error("%qE attribute does not apply to variables (%qD)", name, *node);
107701 + return NULL_TREE;
107702 + }
107703 +
107704 + if (TYPE_P(*node)) {
107705 + type = *node;
107706 + } else {
107707 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
107708 + type = TREE_TYPE(*node);
107709 + }
107710 +
107711 + if (TREE_CODE(type) != RECORD_TYPE) {
107712 + error("%qE attribute used on %qT applies to struct types only", name, type);
107713 + return NULL_TREE;
107714 + }
107715 +
107716 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
107717 + error("%qE attribute is already applied to the type %qT", name, type);
107718 + return NULL_TREE;
107719 + }
107720 +
107721 + *no_add_attrs = false;
107722 +
107723 + return NULL_TREE;
107724 +}
107725 +
107726 +/* set on complete types that we don't need to inspect further at all */
107727 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107728 +{
107729 + *no_add_attrs = false;
107730 + return NULL_TREE;
107731 +}
107732 +
107733 +/*
107734 + * set on types that we've performed a shuffle on, to prevent re-shuffling
107735 + * this does not preclude us from inspecting its fields for potential shuffles
107736 + */
107737 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107738 +{
107739 + *no_add_attrs = false;
107740 + return NULL_TREE;
107741 +}
107742 +
107743 +/*
107744 + * 64bit variant of Bob Jenkins' public domain PRNG
107745 + * 256 bits of internal state
107746 + */
107747 +
107748 +typedef unsigned long long u64;
107749 +
107750 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
107751 +
107752 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
107753 +static u64 ranval(ranctx *x) {
107754 + u64 e = x->a - rot(x->b, 7);
107755 + x->a = x->b ^ rot(x->c, 13);
107756 + x->b = x->c + rot(x->d, 37);
107757 + x->c = x->d + e;
107758 + x->d = e + x->a;
107759 + return x->d;
107760 +}
107761 +
107762 +static void raninit(ranctx *x, u64 *seed) {
107763 + int i;
107764 +
107765 + x->a = seed[0];
107766 + x->b = seed[1];
107767 + x->c = seed[2];
107768 + x->d = seed[3];
107769 +
107770 + for (i=0; i < 30; ++i)
107771 + (void)ranval(x);
107772 +}
107773 +
107774 +static u64 shuffle_seed[4];
107775 +
107776 +struct partition_group {
107777 + tree tree_start;
107778 + unsigned long start;
107779 + unsigned long length;
107780 +};
107781 +
107782 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
107783 +{
107784 + unsigned long i;
107785 + unsigned long accum_size = 0;
107786 + unsigned long accum_length = 0;
107787 + unsigned long group_idx = 0;
107788 +
107789 + gcc_assert(length < INT_MAX);
107790 +
107791 + memset(size_groups, 0, sizeof(struct partition_group) * length);
107792 +
107793 + for (i = 0; i < length; i++) {
107794 + if (size_groups[group_idx].tree_start == NULL_TREE) {
107795 + size_groups[group_idx].tree_start = fields[i];
107796 + size_groups[group_idx].start = i;
107797 + accum_length = 0;
107798 + accum_size = 0;
107799 + }
107800 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
107801 + accum_length++;
107802 + if (accum_size >= 64) {
107803 + size_groups[group_idx].length = accum_length;
107804 + accum_length = 0;
107805 + group_idx++;
107806 + }
107807 + }
107808 +
107809 + if (size_groups[group_idx].tree_start != NULL_TREE &&
107810 + !size_groups[group_idx].length) {
107811 + size_groups[group_idx].length = accum_length;
107812 + group_idx++;
107813 + }
107814 +
107815 + *num_groups = group_idx;
107816 +}
107817 +
107818 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
107819 +{
107820 + unsigned long i, x;
107821 + struct partition_group size_group[length];
107822 + unsigned long num_groups = 0;
107823 + unsigned long randnum;
107824 +
107825 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
107826 + for (i = num_groups - 1; i > 0; i--) {
107827 + struct partition_group tmp;
107828 + randnum = ranval(prng_state) % (i + 1);
107829 + tmp = size_group[i];
107830 + size_group[i] = size_group[randnum];
107831 + size_group[randnum] = tmp;
107832 + }
107833 +
107834 + for (x = 0; x < num_groups; x++) {
107835 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
107836 + tree tmp;
107837 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
107838 + continue;
107839 + randnum = ranval(prng_state) % (i + 1);
107840 + // we could handle this case differently if desired
107841 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
107842 + continue;
107843 + tmp = newtree[i];
107844 + newtree[i] = newtree[randnum];
107845 + newtree[randnum] = tmp;
107846 + }
107847 + }
107848 +}
107849 +
107850 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
107851 +{
107852 + unsigned long i, randnum;
107853 +
107854 + for (i = length - 1; i > 0; i--) {
107855 + tree tmp;
107856 + randnum = ranval(prng_state) % (i + 1);
107857 + tmp = newtree[i];
107858 + newtree[i] = newtree[randnum];
107859 + newtree[randnum] = tmp;
107860 + }
107861 +}
107862 +
107863 +/* modern in-place Fisher-Yates shuffle */
107864 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
107865 +{
107866 + unsigned long i;
107867 + u64 seed[4];
107868 + ranctx prng_state;
107869 + const unsigned char *structname;
107870 +
107871 + if (length == 0)
107872 + return;
107873 +
107874 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
107875 +
107876 + structname = ORIG_TYPE_NAME(type);
107877 +
107878 +#ifdef __DEBUG_PLUGIN
107879 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
107880 +#ifdef __DEBUG_VERBOSE
107881 + debug_tree((tree)type);
107882 +#endif
107883 +#endif
107884 +
107885 + for (i = 0; i < 4; i++) {
107886 + seed[i] = shuffle_seed[i];
107887 + seed[i] ^= name_hash(structname);
107888 + }
107889 +
107890 + raninit(&prng_state, (u64 *)&seed);
107891 +
107892 + if (performance_mode)
107893 + performance_shuffle(newtree, length, &prng_state);
107894 + else
107895 + full_shuffle(newtree, length, &prng_state);
107896 +}
107897 +
107898 +static bool is_flexible_array(const_tree field)
107899 +{
107900 + const_tree fieldtype;
107901 + const_tree typesize;
107902 + const_tree elemtype;
107903 + const_tree elemsize;
107904 +
107905 + fieldtype = TREE_TYPE(field);
107906 + typesize = TYPE_SIZE(fieldtype);
107907 +
107908 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
107909 + return false;
107910 +
107911 + elemtype = TREE_TYPE(fieldtype);
107912 + elemsize = TYPE_SIZE(elemtype);
107913 +
107914 + /* size of type is represented in bits */
107915 +
107916 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
107917 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
107918 + return true;
107919 +
107920 + if (typesize != NULL_TREE &&
107921 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
107922 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
107923 + return true;
107924 +
107925 + return false;
107926 +}
107927 +
107928 +static int relayout_struct(tree type)
107929 +{
107930 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
107931 + unsigned long shuffle_length = num_fields;
107932 + tree field;
107933 + tree newtree[num_fields];
107934 + unsigned long i;
107935 + tree list;
107936 + tree variant;
107937 + expanded_location xloc;
107938 +
107939 + if (TYPE_FIELDS(type) == NULL_TREE)
107940 + return 0;
107941 +
107942 + if (num_fields < 2)
107943 + return 0;
107944 +
107945 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
107946 +
107947 + gcc_assert(num_fields < INT_MAX);
107948 +
107949 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
107950 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
107951 + return 0;
107952 +
107953 + /* throw out any structs in uapi */
107954 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
107955 +
107956 + if (strstr(xloc.file, "/uapi/"))
107957 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
107958 +
107959 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
107960 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
107961 + newtree[i] = field;
107962 + }
107963 +
107964 + /*
107965 + * enforce that we don't randomize the layout of the last
107966 + * element of a struct if it's a 0 or 1-length array
107967 + * or a proper flexible array
107968 + */
107969 + if (is_flexible_array(newtree[num_fields - 1]))
107970 + shuffle_length--;
107971 +
107972 + shuffle(type, (tree *)newtree, shuffle_length);
107973 +
107974 + /*
107975 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
107976 + * as gcc provides no other way to detect such code
107977 + */
107978 + list = make_node(FIELD_DECL);
107979 + TREE_CHAIN(list) = newtree[0];
107980 + TREE_TYPE(list) = void_type_node;
107981 + DECL_SIZE(list) = bitsize_zero_node;
107982 + DECL_NONADDRESSABLE_P(list) = 1;
107983 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
107984 + DECL_SIZE_UNIT(list) = size_zero_node;
107985 + DECL_FIELD_OFFSET(list) = size_zero_node;
107986 + // to satisfy the constify plugin
107987 + TREE_READONLY(list) = 1;
107988 +
107989 + for (i = 0; i < num_fields - 1; i++)
107990 + TREE_CHAIN(newtree[i]) = newtree[i+1];
107991 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
107992 +
107993 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
107994 + TYPE_FIELDS(variant) = list;
107995 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
107996 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
107997 + // force a re-layout
107998 + TYPE_SIZE(variant) = NULL_TREE;
107999 + layout_type(variant);
108000 + }
108001 +
108002 + return 1;
108003 +}
108004 +
108005 +/* from constify plugin */
108006 +static const_tree get_field_type(const_tree field)
108007 +{
108008 + return strip_array_types(TREE_TYPE(field));
108009 +}
108010 +
108011 +/* from constify plugin */
108012 +static bool is_fptr(const_tree fieldtype)
108013 +{
108014 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
108015 + return false;
108016 +
108017 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
108018 +}
108019 +
108020 +/* derived from constify plugin */
108021 +static int is_pure_ops_struct(const_tree node)
108022 +{
108023 + const_tree field;
108024 +
108025 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
108026 +
108027 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
108028 + const_tree fieldtype = get_field_type(field);
108029 + enum tree_code code = TREE_CODE(fieldtype);
108030 +
108031 + if (node == fieldtype)
108032 + continue;
108033 +
108034 + if (!is_fptr(fieldtype))
108035 + return 0;
108036 +
108037 + if (code != RECORD_TYPE && code != UNION_TYPE)
108038 + continue;
108039 +
108040 + if (!is_pure_ops_struct(fieldtype))
108041 + return 0;
108042 + }
108043 +
108044 + return 1;
108045 +}
108046 +
108047 +static void randomize_type(tree type)
108048 +{
108049 + tree variant;
108050 +
108051 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
108052 +
108053 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
108054 + return;
108055 +
108056 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
108057 + relayout_struct(type);
108058 +
108059 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
108060 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
108061 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
108062 + }
108063 +#ifdef __DEBUG_PLUGIN
108064 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
108065 +#ifdef __DEBUG_VERBOSE
108066 + debug_tree(type);
108067 +#endif
108068 +#endif
108069 +}
108070 +
108071 +static void randomize_layout_finish_decl(void *event_data, void *data)
108072 +{
108073 + tree decl = (tree)event_data;
108074 + tree type;
108075 +
108076 + if (decl == NULL_TREE || decl == error_mark_node)
108077 + return;
108078 +
108079 + type = TREE_TYPE(decl);
108080 +
108081 + if (TREE_CODE(decl) != VAR_DECL)
108082 + return;
108083 +
108084 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
108085 + return;
108086 +
108087 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
108088 + return;
108089 +
108090 + relayout_decl(decl);
108091 +}
108092 +
108093 +static void finish_type(void *event_data, void *data)
108094 +{
108095 + tree type = (tree)event_data;
108096 +
108097 + if (type == NULL_TREE || type == error_mark_node)
108098 + return;
108099 +
108100 + if (TREE_CODE(type) != RECORD_TYPE)
108101 + return;
108102 +
108103 + if (TYPE_FIELDS(type) == NULL_TREE)
108104 + return;
108105 +
108106 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
108107 + return;
108108 +
108109 +#ifdef __DEBUG_PLUGIN
108110 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
108111 +#endif
108112 +#ifdef __DEBUG_VERBOSE
108113 + debug_tree(type);
108114 +#endif
108115 + randomize_type(type);
108116 +
108117 + return;
108118 +}
108119 +
108120 +static struct attribute_spec randomize_layout_attr = {
108121 + .name = "randomize_layout",
108122 + // related to args
108123 + .min_length = 0,
108124 + .max_length = 0,
108125 + .decl_required = false,
108126 + // need type declaration
108127 + .type_required = true,
108128 + .function_type_required = false,
108129 + .handler = handle_randomize_layout_attr,
108130 +#if BUILDING_GCC_VERSION >= 4007
108131 + .affects_type_identity = true
108132 +#endif
108133 +};
108134 +
108135 +static struct attribute_spec no_randomize_layout_attr = {
108136 + .name = "no_randomize_layout",
108137 + // related to args
108138 + .min_length = 0,
108139 + .max_length = 0,
108140 + .decl_required = false,
108141 + // need type declaration
108142 + .type_required = true,
108143 + .function_type_required = false,
108144 + .handler = handle_randomize_layout_attr,
108145 +#if BUILDING_GCC_VERSION >= 4007
108146 + .affects_type_identity = true
108147 +#endif
108148 +};
108149 +
108150 +static struct attribute_spec randomize_considered_attr = {
108151 + .name = "randomize_considered",
108152 + // related to args
108153 + .min_length = 0,
108154 + .max_length = 0,
108155 + .decl_required = false,
108156 + // need type declaration
108157 + .type_required = true,
108158 + .function_type_required = false,
108159 + .handler = handle_randomize_considered_attr,
108160 +#if BUILDING_GCC_VERSION >= 4007
108161 + .affects_type_identity = false
108162 +#endif
108163 +};
108164 +
108165 +static struct attribute_spec randomize_performed_attr = {
108166 + .name = "randomize_performed",
108167 + // related to args
108168 + .min_length = 0,
108169 + .max_length = 0,
108170 + .decl_required = false,
108171 + // need type declaration
108172 + .type_required = true,
108173 + .function_type_required = false,
108174 + .handler = handle_randomize_performed_attr,
108175 +#if BUILDING_GCC_VERSION >= 4007
108176 + .affects_type_identity = false
108177 +#endif
108178 +};
108179 +
108180 +static void register_attributes(void *event_data, void *data)
108181 +{
108182 + register_attribute(&randomize_layout_attr);
108183 + register_attribute(&no_randomize_layout_attr);
108184 + register_attribute(&randomize_considered_attr);
108185 + register_attribute(&randomize_performed_attr);
108186 +}
108187 +
108188 +static void check_bad_casts_in_constructor(tree var, tree init)
108189 +{
108190 + unsigned HOST_WIDE_INT idx;
108191 + tree field, val;
108192 + tree field_type, val_type;
108193 +
108194 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
108195 + if (TREE_CODE(val) == CONSTRUCTOR) {
108196 + check_bad_casts_in_constructor(var, val);
108197 + continue;
108198 + }
108199 +
108200 + /* pipacs' plugin creates franken-arrays that differ from those produced by
108201 + normal code which all have valid 'field' trees. work around this */
108202 + if (field == NULL_TREE)
108203 + continue;
108204 + field_type = TREE_TYPE(field);
108205 + val_type = TREE_TYPE(val);
108206 +
108207 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
108208 + continue;
108209 +
108210 + if (field_type == val_type)
108211 + continue;
108212 +
108213 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
108214 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
108215 +
108216 + if (field_type == void_type_node)
108217 + continue;
108218 + if (field_type == val_type)
108219 + continue;
108220 + if (TREE_CODE(val_type) != RECORD_TYPE)
108221 + continue;
108222 +
108223 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
108224 + continue;
108225 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
108226 + }
108227 +}
108228 +
108229 +/* derived from the constify plugin */
108230 +static void check_global_variables(void *event_data, void *data)
108231 +{
108232 + struct varpool_node *node;
108233 + tree init;
108234 +
108235 + FOR_EACH_VARIABLE(node) {
108236 + tree var = NODE_DECL(node);
108237 + init = DECL_INITIAL(var);
108238 + if (init == NULL_TREE)
108239 + continue;
108240 +
108241 + if (TREE_CODE(init) != CONSTRUCTOR)
108242 + continue;
108243 +
108244 + check_bad_casts_in_constructor(var, init);
108245 + }
108246 +}
108247 +
108248 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
108249 +{
108250 + basic_block dom;
108251 + gimple dom_stmt;
108252 + gimple call_stmt;
108253 + const_tree dom_lhs;
108254 + const_tree poss_is_err_cond;
108255 + const_tree poss_is_err_func;
108256 + const_tree is_err_arg;
108257 +
108258 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
108259 + if (!dom)
108260 + return false;
108261 +
108262 + dom_stmt = last_stmt(dom);
108263 + if (!dom_stmt)
108264 + return false;
108265 +
108266 + if (gimple_code(dom_stmt) != GIMPLE_COND)
108267 + return false;
108268 +
108269 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
108270 + return false;
108271 +
108272 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
108273 + return false;
108274 +
108275 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
108276 +
108277 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
108278 + return false;
108279 +
108280 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
108281 +
108282 + if (gimple_code(call_stmt) != GIMPLE_CALL)
108283 + return false;
108284 +
108285 + dom_lhs = gimple_get_lhs(call_stmt);
108286 + poss_is_err_func = gimple_call_fndecl(call_stmt);
108287 + if (!poss_is_err_func)
108288 + return false;
108289 + if (dom_lhs != poss_is_err_cond)
108290 + return false;
108291 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
108292 + return false;
108293 +
108294 + is_err_arg = gimple_call_arg(call_stmt, 0);
108295 + if (!is_err_arg)
108296 + return false;
108297 +
108298 + if (is_err_arg != rhs)
108299 + return false;
108300 +
108301 + return true;
108302 +}
108303 +
108304 +static void handle_local_var_initializers(void)
108305 +{
108306 + tree var;
108307 + unsigned int i;
108308 +
108309 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
108310 + tree init = DECL_INITIAL(var);
108311 + if (!init)
108312 + continue;
108313 + if (TREE_CODE(init) != CONSTRUCTOR)
108314 + continue;
108315 + check_bad_casts_in_constructor(var, init);
108316 + }
108317 +}
108318 +
108319 +/*
108320 + * iterate over all statements to find "bad" casts:
108321 + * those where the address of the start of a structure is cast
108322 + * to a pointer of a structure of a different type, or a
108323 + * structure pointer type is cast to a different structure pointer type
108324 + */
108325 +static unsigned int find_bad_casts(void)
108326 +{
108327 + basic_block bb;
108328 +
108329 + handle_local_var_initializers();
108330 +
108331 + FOR_ALL_BB_FN(bb, cfun) {
108332 + gimple_stmt_iterator gsi;
108333 +
108334 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108335 + gimple stmt;
108336 + const_tree lhs;
108337 + const_tree lhs_type;
108338 + const_tree rhs1;
108339 + const_tree rhs_type;
108340 + const_tree ptr_lhs_type;
108341 + const_tree ptr_rhs_type;
108342 + const_tree op0;
108343 + const_tree op0_type;
108344 + enum tree_code rhs_code;
108345 +
108346 + stmt = gsi_stmt(gsi);
108347 +
108348 +#ifdef __DEBUG_PLUGIN
108349 +#ifdef __DEBUG_VERBOSE
108350 + debug_gimple_stmt(stmt);
108351 + debug_tree(gimple_get_lhs(stmt));
108352 +#endif
108353 +#endif
108354 +
108355 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
108356 + continue;
108357 +
108358 +#ifdef __DEBUG_PLUGIN
108359 +#ifdef __DEBUG_VERBOSE
108360 + debug_tree(gimple_assign_rhs1(stmt));
108361 +#endif
108362 +#endif
108363 +
108364 + rhs_code = gimple_assign_rhs_code(stmt);
108365 +
108366 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
108367 + continue;
108368 +
108369 + lhs = gimple_get_lhs(stmt);
108370 + lhs_type = TREE_TYPE(lhs);
108371 + rhs1 = gimple_assign_rhs1(stmt);
108372 + rhs_type = TREE_TYPE(rhs1);
108373 +
108374 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
108375 + TREE_CODE(lhs_type) != POINTER_TYPE)
108376 + continue;
108377 +
108378 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
108379 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
108380 +
108381 + if (ptr_rhs_type == void_type_node)
108382 + continue;
108383 +
108384 + if (ptr_lhs_type == void_type_node)
108385 + continue;
108386 +
108387 + if (dominated_by_is_err(rhs1, bb))
108388 + continue;
108389 +
108390 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
108391 +#ifndef __DEBUG_PLUGIN
108392 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
108393 +#endif
108394 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
108395 + continue;
108396 + }
108397 +
108398 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
108399 + continue;
108400 +
108401 + if (rhs_code == ADDR_EXPR) {
108402 + op0 = TREE_OPERAND(rhs1, 0);
108403 +
108404 + if (op0 == NULL_TREE)
108405 + continue;
108406 +
108407 + if (TREE_CODE(op0) != VAR_DECL)
108408 + continue;
108409 +
108410 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
108411 + if (op0_type == ptr_lhs_type)
108412 + continue;
108413 +
108414 +#ifndef __DEBUG_PLUGIN
108415 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
108416 +#endif
108417 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
108418 + } else {
108419 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
108420 + /* skip bogus type casts introduced by container_of */
108421 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
108422 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
108423 + continue;
108424 +#ifndef __DEBUG_PLUGIN
108425 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
108426 +#endif
108427 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
108428 + }
108429 +
108430 + }
108431 + }
108432 + return 0;
108433 +}
108434 +
108435 +#if BUILDING_GCC_VERSION >= 4009
108436 +static const struct pass_data randomize_layout_bad_cast_data = {
108437 +#else
108438 +static struct gimple_opt_pass randomize_layout_bad_cast = {
108439 + .pass = {
108440 +#endif
108441 + .type = GIMPLE_PASS,
108442 + .name = "randomize_layout_bad_cast",
108443 +#if BUILDING_GCC_VERSION >= 4008
108444 + .optinfo_flags = OPTGROUP_NONE,
108445 +#endif
108446 +#if BUILDING_GCC_VERSION >= 4009
108447 + .has_gate = false,
108448 + .has_execute = true,
108449 +#else
108450 + .gate = NULL,
108451 + .execute = find_bad_casts,
108452 + .sub = NULL,
108453 + .next = NULL,
108454 + .static_pass_number = 0,
108455 +#endif
108456 + .tv_id = TV_NONE,
108457 + .properties_required = PROP_cfg,
108458 + .properties_provided = 0,
108459 + .properties_destroyed = 0,
108460 + .todo_flags_start = 0,
108461 + .todo_flags_finish = TODO_dump_func
108462 +#if BUILDING_GCC_VERSION < 4009
108463 + }
108464 +#endif
108465 +};
108466 +
108467 +#if BUILDING_GCC_VERSION >= 4009
108468 +namespace {
108469 +class randomize_layout_bad_cast : public gimple_opt_pass {
108470 +public:
108471 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
108472 + unsigned int execute() { return find_bad_casts(); }
108473 +};
108474 +}
108475 +#endif
108476 +
108477 +static struct opt_pass *make_randomize_layout_bad_cast(void)
108478 +{
108479 +#if BUILDING_GCC_VERSION >= 4009
108480 + return new randomize_layout_bad_cast();
108481 +#else
108482 + return &randomize_layout_bad_cast.pass;
108483 +#endif
108484 +}
108485 +
108486 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108487 +{
108488 + int i;
108489 + const char * const plugin_name = plugin_info->base_name;
108490 + const int argc = plugin_info->argc;
108491 + const struct plugin_argument * const argv = plugin_info->argv;
108492 + bool enable = true;
108493 + int obtained_seed = 0;
108494 + struct register_pass_info randomize_layout_bad_cast_info;
108495 +
108496 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
108497 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
108498 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
108499 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
108500 +
108501 + if (!plugin_default_version_check(version, &gcc_version)) {
108502 + error(G_("incompatible gcc/plugin versions"));
108503 + return 1;
108504 + }
108505 +
108506 + if (strcmp(lang_hooks.name, "GNU C")) {
108507 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
108508 + enable = false;
108509 + }
108510 +
108511 + for (i = 0; i < argc; ++i) {
108512 + if (!strcmp(argv[i].key, "disable")) {
108513 + enable = false;
108514 + continue;
108515 + }
108516 + if (!strcmp(argv[i].key, "performance-mode")) {
108517 + performance_mode = 1;
108518 + continue;
108519 + }
108520 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
108521 + }
108522 +
108523 + if (strlen(randstruct_seed) != 64) {
108524 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
108525 + return 1;
108526 + }
108527 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
108528 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
108529 + if (obtained_seed != 4) {
108530 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
108531 + return 1;
108532 + }
108533 +
108534 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
108535 + if (enable) {
108536 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
108537 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
108538 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
108539 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
108540 + }
108541 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
108542 +
108543 + return 0;
108544 +}
108545 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
108546 new file mode 100644
108547 index 0000000..ebbd9a3
108548 --- /dev/null
108549 +++ b/tools/gcc/size_overflow_hash.data
108550 @@ -0,0 +1,5933 @@
108551 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
108552 +ocfs2_get_refcount_tree_3 ocfs2_get_refcount_tree 0 3 NULL
108553 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
108554 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
108555 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
108556 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
108557 +padzero_55 padzero 1 55 &sel_read_policyvers_55
108558 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
108559 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
108560 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
108561 +load_msg_95 load_msg 2 95 NULL
108562 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
108563 +init_q_132 init_q 4 132 NULL
108564 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
108565 +gfs2_glock_get_147 gfs2_glock_get 0 147 NULL
108566 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
108567 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
108568 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
108569 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
108570 +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
108571 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
108572 +xfs_bmap_btalloc_192 xfs_bmap_btalloc 0 192 NULL
108573 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
108574 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
108575 +br_port_info_size_268 br_port_info_size 0 268 NULL
108576 +generic_file_direct_write_291 generic_file_direct_write 0 291 NULL
108577 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
108578 +xfs_zero_last_block_298 xfs_zero_last_block 0 298 NULL
108579 +SYSC_connect_304 SYSC_connect 3 304 NULL
108580 +syslog_print_307 syslog_print 2 307 NULL
108581 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
108582 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
108583 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
108584 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
108585 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
108586 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
108587 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
108588 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
108589 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
108590 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
108591 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
108592 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
108593 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
108594 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
108595 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
108596 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
108597 +ocfs2_refcounted_xattr_delete_need_584 ocfs2_refcounted_xattr_delete_need 0 584 NULL
108598 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
108599 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
108600 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
108601 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
108602 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
108603 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
108604 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
108605 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
108606 +unlink_queued_645 unlink_queued 4 645 NULL
108607 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
108608 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
108609 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
108610 +xfs_bmap_eof_728 xfs_bmap_eof 0 728 NULL
108611 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
108612 +dvb_video_write_754 dvb_video_write 3 754 NULL
108613 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
108614 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
108615 +if_writecmd_815 if_writecmd 2 815 NULL
108616 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
108617 +error_state_read_859 error_state_read 6 859 NULL
108618 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
108619 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
108620 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
108621 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
108622 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
108623 +mnt_want_write_975 mnt_want_write 0 975 NULL
108624 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
108625 +memcmp_990 memcmp 0 990 NULL
108626 +readreg_1017 readreg 0-1 1017 NULL
108627 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
108628 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
108629 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
108630 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
108631 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
108632 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
108633 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
108634 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
108635 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
108636 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
108637 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
108638 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
108639 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
108640 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
108641 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
108642 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
108643 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
108644 +fsync_buffers_list_1219 fsync_buffers_list 0 1219 NULL
108645 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
108646 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
108647 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
108648 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
108649 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
108650 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
108651 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
108652 +tcf_hash_create_1305 tcf_hash_create 4 1305 NULL
108653 +ffs_1322 ffs 0 1322 NULL
108654 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
108655 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
108656 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
108657 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
108658 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
108659 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
108660 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
108661 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
108662 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
108663 +file_read_actor_1401 file_read_actor 4-0 1401 NULL
108664 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
108665 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
108666 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
108667 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
108668 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
108669 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
108670 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
108671 +fpregs_set_1497 fpregs_set 4 1497 NULL
108672 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
108673 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
108674 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
108675 +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
108676 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
108677 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
108678 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
108679 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
108680 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
108681 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
108682 +rmap_add_1677 rmap_add 3 1677 NULL
108683 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
108684 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
108685 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
108686 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
108687 +internal_create_group_1733 internal_create_group 0 1733 NULL
108688 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
108689 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
108690 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
108691 +cosa_write_1774 cosa_write 3 1774 NULL
108692 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
108693 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
108694 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
108695 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
108696 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
108697 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
108698 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
108699 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
108700 +bdev_erase_1933 bdev_erase 3 1933 NULL
108701 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
108702 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
108703 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
108704 +update_qd_1955 update_qd 0 1955 NULL
108705 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
108706 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
108707 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
108708 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
108709 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
108710 +xfs_mru_cache_insert_2013 xfs_mru_cache_insert 0 2013 NULL
108711 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
108712 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
108713 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
108714 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
108715 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
108716 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
108717 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
108718 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
108719 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
108720 +audit_expand_2098 audit_expand 0 2098 NULL
108721 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
108722 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
108723 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
108724 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
108725 +enable_read_2117 enable_read 3 2117 NULL
108726 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
108727 +xfs_recover_inode_owner_change_2132 xfs_recover_inode_owner_change 0 2132 NULL
108728 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
108729 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
108730 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
108731 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
108732 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
108733 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
108734 +xfs_inobt_update_2206 xfs_inobt_update 0 2206 NULL
108735 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
108736 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
108737 +__ocfs2_journal_access_2241 __ocfs2_journal_access 0 2241 NULL
108738 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
108739 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
108740 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
108741 +do_update_counters_2259 do_update_counters 4 2259 NULL
108742 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
108743 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
108744 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
108745 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
108746 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
108747 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
108748 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
108749 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
108750 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
108751 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
108752 +ntfs_file_aio_write_nolock_2360 ntfs_file_aio_write_nolock 0 2360 NULL
108753 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
108754 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5-0 2368 NULL nohasharray
108755 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
108756 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
108757 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
108758 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
108759 +raid1_size_2419 raid1_size 0-2 2419 NULL
108760 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
108761 +wiphy_new_2482 wiphy_new 2 2482 NULL
108762 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
108763 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
108764 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
108765 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
108766 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
108767 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
108768 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
108769 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
108770 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
108771 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
108772 +slot_bytes_2609 slot_bytes 0 2609 NULL
108773 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
108774 +switch_status_2629 switch_status 5 2629 NULL
108775 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
108776 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
108777 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
108778 +oti6858_write_2692 oti6858_write 4 2692 NULL
108779 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
108780 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
108781 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
108782 +gfs2_glock_nq_num_2747 gfs2_glock_nq_num 0 2747 NULL
108783 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
108784 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
108785 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
108786 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
108787 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
108788 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
108789 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
108790 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
108791 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
108792 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
108793 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
108794 +nla_padlen_2883 nla_padlen 1 2883 NULL
108795 +cmm_write_2896 cmm_write 3 2896 NULL
108796 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
108797 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
108798 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
108799 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
108800 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
108801 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
108802 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
108803 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
108804 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
108805 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
108806 +_xfs_filestream_pick_ag_3007 _xfs_filestream_pick_ag 0 3007 NULL
108807 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
108808 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
108809 +depth_write_3021 depth_write 3 3021 NULL
108810 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
108811 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
108812 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
108813 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
108814 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
108815 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
108816 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
108817 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
108818 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
108819 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
108820 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
108821 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
108822 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
108823 +rb_alloc_3102 rb_alloc 1 3102 NULL
108824 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
108825 +print_time_3132 print_time 0 3132 NULL
108826 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
108827 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
108828 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
108829 +gfs2_rindex_update_3165 gfs2_rindex_update 0 3165 NULL
108830 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
108831 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 NULL
108832 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
108833 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
108834 +alloc_context_3194 alloc_context 1 3194 NULL
108835 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
108836 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
108837 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
108838 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
108839 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
108840 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
108841 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
108842 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
108843 +key_key_read_3241 key_key_read 3 3241 NULL
108844 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
108845 +__set_extent_bit_3305 __set_extent_bit 0 3305 NULL
108846 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
108847 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
108848 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
108849 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
108850 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
108851 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
108852 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
108853 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
108854 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
108855 +scnprintf_3360 scnprintf 0-2 3360 NULL
108856 +ReadByteAmd7930_3365 ReadByteAmd7930 0 3365 NULL
108857 +sr_read_3366 sr_read 3 3366 NULL
108858 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
108859 +send_stream_3397 send_stream 4 3397 NULL
108860 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
108861 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
108862 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
108863 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
108864 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
108865 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
108866 +softsynth_write_3455 softsynth_write 3 3455 NULL
108867 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
108868 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
108869 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
108870 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
108871 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
108872 +SyS_readv_3539 SyS_readv 3 3539 NULL
108873 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
108874 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
108875 +evtchn_read_3569 evtchn_read 3 3569 NULL
108876 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
108877 +vc_resize_3585 vc_resize 3-2 3585 NULL
108878 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
108879 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
108880 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
108881 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
108882 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
108883 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
108884 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
108885 +xfs_attr3_leaf_list_int_3661 xfs_attr3_leaf_list_int 0 3661 NULL
108886 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
108887 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
108888 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
108889 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
108890 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
108891 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
108892 +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
108893 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
108894 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
108895 +get_fd_set_3866 get_fd_set 1 3866 NULL
108896 +apei_res_sub_3873 apei_res_sub 0 3873 NULL
108897 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
108898 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
108899 +nvram_write_3894 nvram_write 3 3894 NULL
108900 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
108901 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
108902 +vcs_write_3910 vcs_write 3 3910 NULL
108903 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
108904 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
108905 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
108906 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
108907 +do_add_counters_3992 do_add_counters 3 3992 NULL
108908 +xfs_bmbt_lookup_eq_3997 xfs_bmbt_lookup_eq 0 3997 NULL
108909 +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
108910 +userspace_status_4004 userspace_status 4 4004 NULL
108911 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
108912 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
108913 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
108914 +blk_end_request_4024 blk_end_request 3 4024 NULL
108915 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
108916 +xfs_free_ag_extent_4036 xfs_free_ag_extent 0 4036 NULL
108917 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
108918 +read_file_queues_4078 read_file_queues 3 4078 NULL
108919 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
108920 +tm6000_read_4151 tm6000_read 3 4151 NULL
108921 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
108922 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
108923 +get_alua_req_4166 get_alua_req 3 4166 NULL
108924 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
108925 +read_file_bool_4180 read_file_bool 3 4180 NULL
108926 +ocfs2_find_cpos_for_right_leaf_4194 ocfs2_find_cpos_for_right_leaf 0 4194 NULL
108927 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
108928 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
108929 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
108930 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
108931 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
108932 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
108933 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
108934 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
108935 +count_strings_4315 count_strings 0 4315 NULL
108936 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
108937 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
108938 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
108939 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
108940 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
108941 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
108942 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
108943 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
108944 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
108945 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
108946 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
108947 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
108948 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
108949 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
108950 +set_link_security_4502 set_link_security 4 4502 NULL
108951 +xfs_btree_kill_root_4526 xfs_btree_kill_root 0 4526 NULL
108952 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
108953 +tty_register_device_4544 tty_register_device 2 4544 NULL
108954 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
108955 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
108956 +bch_alloc_4593 bch_alloc 1 4593 NULL
108957 +ocfs2_refcount_lock_4595 ocfs2_refcount_lock 0 4595 NULL
108958 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
108959 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
108960 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
108961 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
108962 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
108963 +kone_receive_4690 kone_receive 4 4690 NULL
108964 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
108965 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
108966 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
108967 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
108968 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 NULL nohasharray
108969 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 &bitmap_startwrite_4736
108970 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
108971 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
108972 +create_subvol_4791 create_subvol 4 4791 NULL
108973 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
108974 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
108975 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
108976 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
108977 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
108978 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
108979 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
108980 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
108981 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
108982 +ocfs2_should_refresh_lock_res_4958 ocfs2_should_refresh_lock_res 0 4958 NULL
108983 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
108984 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
108985 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
108986 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
108987 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
108988 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
108989 +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
108990 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
108991 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
108992 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
108993 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
108994 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
108995 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
108996 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
108997 +sound_write_5102 sound_write 3 5102 NULL
108998 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
108999 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
109000 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
109001 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
109002 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
109003 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
109004 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
109005 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
109006 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
109007 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
109008 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
109009 +cq_free_res_5355 cq_free_res 5 5355 NULL
109010 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
109011 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
109012 +xfs_free_extent_5411 xfs_free_extent 0 5411 NULL
109013 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
109014 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
109015 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
109016 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
109017 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
109018 +tty_write_5494 tty_write 3 5494 NULL
109019 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
109020 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
109021 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
109022 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
109023 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
109024 +le_readq_5557 le_readq 0 5557 NULL
109025 +inw_5558 inw 0 5558 NULL
109026 +gfs2_extent_map_5561 gfs2_extent_map 0 5561 NULL
109027 +bioset_create_5580 bioset_create 1 5580 NULL
109028 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
109029 +__remove_suid_5618 __remove_suid 0 5618 NULL
109030 +gfs2_unstuffer_page_5620 gfs2_unstuffer_page 0 5620 NULL
109031 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
109032 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
109033 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
109034 +get_arg_5694 get_arg 3 5694 NULL
109035 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
109036 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
109037 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
109038 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
109039 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
109040 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
109041 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
109042 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
109043 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
109044 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
109045 +setup_req_5848 setup_req 3 5848 NULL
109046 +ria_page_count_5849 ria_page_count 0 5849 NULL
109047 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
109048 +config_buf_5862 config_buf 0 5862 NULL
109049 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
109050 +port_show_regs_5904 port_show_regs 3 5904 NULL
109051 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
109052 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
109053 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
109054 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
109055 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
109056 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
109057 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
109058 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
109059 +alloc_msg_6072 alloc_msg 1 6072 NULL
109060 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
109061 +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
109062 +__mnt_want_write_6091 __mnt_want_write 0 6091 NULL
109063 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL
109064 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
109065 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
109066 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
109067 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
109068 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
109069 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
109070 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
109071 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
109072 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
109073 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
109074 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
109075 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
109076 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
109077 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
109078 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
109079 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
109080 +serial_port_in_6291 serial_port_in 0 6291 NULL
109081 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
109082 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
109083 +SyS_mincore_6329 SyS_mincore 2-1 6329 &hfa384x_inw_6329
109084 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
109085 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
109086 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
109087 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
109088 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
109089 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
109090 +xfs_bmap_extents_to_btree_6387 xfs_bmap_extents_to_btree 0 6387 NULL
109091 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
109092 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
109093 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
109094 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
109095 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
109096 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
109097 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
109098 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
109099 +mei_read_6507 mei_read 3 6507 NULL
109100 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
109101 +wdm_read_6549 wdm_read 3 6549 NULL
109102 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
109103 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
109104 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
109105 +xfs_iozero_6573 xfs_iozero 0 6573 NULL
109106 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
109107 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
109108 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
109109 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
109110 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
109111 +mpeg_read_6708 mpeg_read 3 6708 NULL
109112 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
109113 +video_proc_write_6724 video_proc_write 3 6724 NULL
109114 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
109115 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
109116 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
109117 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
109118 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
109119 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
109120 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
109121 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
109122 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
109123 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
109124 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
109125 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
109126 +xfs_rtany_summary_6851 xfs_rtany_summary 0 6851 NULL
109127 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
109128 +dio_complete_6879 dio_complete 0-2-3 6879 NULL
109129 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
109130 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
109131 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
109132 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
109133 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
109134 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
109135 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
109136 +lops_scan_elements_6916 lops_scan_elements 0 6916 NULL
109137 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
109138 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
109139 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
109140 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
109141 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
109142 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL nohasharray
109143 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 &rsa_extract_mpi_6973
109144 +request_key_async_6990 request_key_async 4 6990 NULL
109145 +tpl_write_6998 tpl_write 3 6998 NULL
109146 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
109147 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
109148 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
109149 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
109150 +wimax_msg_7030 wimax_msg 4 7030 NULL
109151 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
109152 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
109153 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
109154 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
109155 +event_enable_read_7074 event_enable_read 3 7074 NULL
109156 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
109157 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
109158 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
109159 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
109160 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
109161 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
109162 +f_midi_start_ep_7270 f_midi_start_ep 0 7270 NULL
109163 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
109164 +get_string_7302 get_string 0 7302 NULL
109165 +security_inode_need_killpriv_7322 security_inode_need_killpriv 0 7322 NULL
109166 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
109167 +mgmt_control_7349 mgmt_control 3 7349 NULL
109168 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
109169 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
109170 +xfs_btree_delete_7384 xfs_btree_delete 0 7384 NULL
109171 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
109172 +hweight_long_7388 hweight_long 1-0 7388 NULL
109173 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
109174 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
109175 +readb_7401 readb 0 7401 NULL
109176 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
109177 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
109178 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
109179 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
109180 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
109181 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
109182 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
109183 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
109184 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
109185 +iwl_mvm_power_dbgfs_read_7502 iwl_mvm_power_dbgfs_read 0 7502 NULL
109186 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
109187 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
109188 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
109189 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
109190 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
109191 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
109192 +ocfs2_lock_create_7612 ocfs2_lock_create 0 7612 NULL
109193 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
109194 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
109195 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
109196 +xfs_bmap_btalloc_nullfb_7654 xfs_bmap_btalloc_nullfb 0 7654 NULL
109197 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
109198 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
109199 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
109200 +dev_write_7708 dev_write 3 7708 NULL
109201 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
109202 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
109203 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
109204 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
109205 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
109206 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
109207 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
109208 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
109209 +xfs_alloc_find_best_extent_7837 xfs_alloc_find_best_extent 0 7837 NULL
109210 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
109211 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
109212 +config_desc_7878 config_desc 0 7878 NULL
109213 +gfs2_permission_7884 gfs2_permission 0 7884 NULL
109214 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
109215 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
109216 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
109217 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
109218 +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
109219 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
109220 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
109221 +vcs_read_8017 vcs_read 3 8017 NULL
109222 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
109223 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
109224 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
109225 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
109226 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
109227 +venus_lookup_8121 venus_lookup 4 8121 NULL
109228 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
109229 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
109230 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
109231 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
109232 +__ocfs2_lock_refcount_tree_8207 __ocfs2_lock_refcount_tree 0 8207 NULL
109233 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
109234 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
109235 +play_iframe_8219 play_iframe 3 8219 NULL
109236 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
109237 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
109238 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
109239 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
109240 +init_cdev_8274 init_cdev 1 8274 NULL
109241 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
109242 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
109243 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
109244 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
109245 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
109246 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
109247 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
109248 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
109249 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
109250 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
109251 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
109252 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
109253 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
109254 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
109255 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
109256 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
109257 +dev_config_8506 dev_config 3 8506 NULL
109258 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
109259 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
109260 +user_on_off_8552 user_on_off 2 8552 NULL
109261 +profile_remove_8556 profile_remove 3 8556 NULL
109262 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
109263 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
109264 +tower_write_8580 tower_write 3 8580 NULL
109265 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
109266 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
109267 +xfs_qm_dqattach_locked_8625 xfs_qm_dqattach_locked 0 8625 NULL
109268 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
109269 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
109270 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
109271 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
109272 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
109273 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
109274 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
109275 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
109276 +arcfb_write_8702 arcfb_write 3 8702 NULL
109277 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
109278 +init_header_8703 init_header 0 8703 &i_size_read_8703
109279 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
109280 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
109281 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
109282 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
109283 +__create_irqs_8733 __create_irqs 2 8733 NULL
109284 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
109285 +compound_order_8750 compound_order 0 8750 NULL
109286 +ocfs2_find_path_8754 ocfs2_find_path 0 8754 NULL
109287 +yurex_write_8761 yurex_write 3 8761 NULL
109288 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
109289 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
109290 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
109291 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
109292 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
109293 +gfs2_glock_nq_8808 gfs2_glock_nq 0 8808 NULL
109294 +ntfs_commit_pages_after_write_8809 ntfs_commit_pages_after_write 0 8809 NULL
109295 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
109296 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
109297 +extent_read_full_page_8826 extent_read_full_page 0 8826 NULL
109298 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
109299 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
109300 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
109301 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
109302 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
109303 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
109304 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
109305 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
109306 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
109307 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
109308 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
109309 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
109310 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
109311 +write_file_ani_8918 write_file_ani 3 8918 NULL
109312 +layout_commit_8926 layout_commit 3 8926 NULL
109313 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
109314 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
109315 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
109316 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
109317 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
109318 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
109319 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
109320 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
109321 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
109322 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
109323 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
109324 +xfs_inobt_get_rec_9023 xfs_inobt_get_rec 0 9023 NULL
109325 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
109326 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
109327 +nla_put_9042 nla_put 3 9042 NULL
109328 +ffs_func_revmap_intf_9043 ffs_func_revmap_intf 0 9043 NULL
109329 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
109330 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
109331 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
109332 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
109333 +create_queues_9088 create_queues 2-3 9088 NULL
109334 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
109335 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
109336 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
109337 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 &caif_stream_sendmsg_9110 nohasharray
109338 +jhead_scan_9110 jhead_scan 0 9110 &gfn_to_rmap_9110
109339 +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
109340 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
109341 +apei_resources_merge_9149 apei_resources_merge 0 9149 NULL
109342 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
109343 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
109344 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
109345 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
109346 +xfs_btree_rshift_9187 xfs_btree_rshift 0 9187 NULL
109347 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
109348 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
109349 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
109350 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
109351 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
109352 +xfs_error_trap_9239 xfs_error_trap 0-1 9239 NULL
109353 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
109354 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
109355 +flakey_status_9274 flakey_status 5 9274 NULL
109356 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
109357 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
109358 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
109359 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
109360 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
109361 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
109362 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
109363 +get_request_type_9393 get_request_type 0 9393 NULL nohasharray
109364 +mlx4_bitmap_init_9393 mlx4_bitmap_init 5-2 9393 &get_request_type_9393
109365 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
109366 +read_9397 read 3 9397 NULL
109367 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
109368 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
109369 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
109370 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
109371 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
109372 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL nohasharray
109373 +get_registers_9470 get_registers 4 9470 &agp_generic_alloc_user_9470
109374 +crypt_status_9492 crypt_status 5 9492 NULL
109375 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
109376 +lp_write_9511 lp_write 3 9511 NULL
109377 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
109378 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
109379 +read_file_dma_9530 read_file_dma 3 9530 NULL
109380 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
109381 +xfs_ialloc_read_agi_9545 xfs_ialloc_read_agi 0 9545 NULL
109382 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
109383 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
109384 +fw_node_create_9559 fw_node_create 2 9559 NULL
109385 +kobj_map_9566 kobj_map 2-3 9566 NULL
109386 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
109387 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
109388 +xfs_qm_dqattach_one_9612 xfs_qm_dqattach_one 0 9612 NULL
109389 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
109390 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
109391 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
109392 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
109393 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
109394 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
109395 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
109396 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
109397 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
109398 +dns_query_9676 dns_query 3 9676 NULL
109399 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
109400 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
109401 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
109402 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
109403 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
109404 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
109405 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
109406 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
109407 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
109408 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
109409 +shmem_replace_page_9740 shmem_replace_page 0 9740 NULL
109410 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
109411 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 NULL
109412 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
109413 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
109414 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
109415 +parse_uac2_sample_rate_range_9801 parse_uac2_sample_rate_range 0 9801 NULL
109416 +tpm_data_in_9802 tpm_data_in 0 9802 NULL
109417 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
109418 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
109419 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
109420 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
109421 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
109422 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
109423 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
109424 +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
109425 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 5-3 9895 NULL
109426 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
109427 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
109428 +read_file_misc_9948 read_file_misc 3 9948 NULL
109429 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
109430 +xfs_buf_geterror_9959 xfs_buf_geterror 0 9959 NULL
109431 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
109432 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
109433 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
109434 +gameport_read_9983 gameport_read 0 9983 NULL
109435 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
109436 +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
109437 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
109438 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
109439 +xfs_attr_rmtval_get_10092 xfs_attr_rmtval_get 0 10092 NULL
109440 +xfs_btree_check_lptr_10104 xfs_btree_check_lptr 0 10104 NULL
109441 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
109442 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
109443 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
109444 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
109445 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
109446 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
109447 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
109448 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
109449 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
109450 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
109451 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
109452 +xfs_attr_rmtval_copyout_10222 xfs_attr_rmtval_copyout 0 10222 NULL nohasharray
109453 +xfs_btree_read_buf_block_10222 xfs_btree_read_buf_block 0 10222 &xfs_attr_rmtval_copyout_10222
109454 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
109455 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
109456 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
109457 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
109458 +read_emulate_10310 read_emulate 2-4 10310 NULL
109459 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
109460 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
109461 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
109462 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
109463 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
109464 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
109465 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
109466 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
109467 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
109468 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
109469 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
109470 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
109471 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
109472 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
109473 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
109474 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
109475 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
109476 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
109477 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
109478 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
109479 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
109480 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
109481 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
109482 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
109483 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
109484 +otp_read_10594 otp_read 2-4-5 10594 NULL
109485 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
109486 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
109487 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
109488 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
109489 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
109490 +parport_write_10669 parport_write 0 10669 NULL
109491 +edge_write_10692 edge_write 4 10692 NULL
109492 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
109493 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
109494 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
109495 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
109496 +spi_sync_10731 spi_sync 0 10731 NULL
109497 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
109498 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
109499 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
109500 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
109501 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
109502 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
109503 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
109504 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
109505 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
109506 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
109507 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
109508 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
109509 +get_scq_10897 get_scq 2 10897 NULL
109510 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
109511 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
109512 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
109513 +kobject_add_10919 kobject_add 0 10919 NULL
109514 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
109515 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
109516 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
109517 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
109518 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
109519 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
109520 +gfs2_dir_read_11017 gfs2_dir_read 0 11017 NULL
109521 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
109522 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
109523 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
109524 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
109525 +count_argc_11083 count_argc 0 11083 NULL
109526 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
109527 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
109528 +page_offset_11120 page_offset 0 11120 NULL
109529 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL nohasharray
109530 +cea_db_payload_len_11124 cea_db_payload_len 0 11124 &tracing_buffers_read_11124
109531 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 4-3 11172 NULL
109532 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
109533 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
109534 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
109535 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
109536 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
109537 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
109538 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
109539 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
109540 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
109541 +shmem_radix_tree_replace_11325 shmem_radix_tree_replace 0 11325 NULL
109542 +construct_key_11329 construct_key 3 11329 NULL nohasharray
109543 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
109544 +next_segment_11330 next_segment 0-2-1 11330 NULL
109545 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
109546 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
109547 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
109548 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
109549 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
109550 +nft_value_dump_11381 nft_value_dump 3 11381 NULL
109551 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
109552 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
109553 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
109554 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
109555 +str_to_user_11411 str_to_user 2 11411 NULL
109556 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
109557 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
109558 +xfs_btree_lookup_11417 xfs_btree_lookup 0 11417 NULL nohasharray
109559 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 &xfs_btree_lookup_11417
109560 +trace_options_read_11419 trace_options_read 3 11419 NULL
109561 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
109562 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
109563 +bttv_read_11432 bttv_read 3 11432 NULL
109564 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
109565 +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
109566 +pci_set_power_state_11479 pci_set_power_state 0 11479 NULL nohasharray
109567 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 &pci_set_power_state_11479
109568 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4-0 11492 NULL
109569 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
109570 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
109571 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
109572 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
109573 +xfs_rtcheck_alloc_range_11553 xfs_rtcheck_alloc_range 0 11553 NULL
109574 +radix_tree_extend_11555 radix_tree_extend 0 11555 NULL
109575 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
109576 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
109577 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
109578 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
109579 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
109580 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
109581 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
109582 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
109583 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
109584 +nla_total_size_11658 nla_total_size 1-0 11658 NULL
109585 +slab_ksize_11664 slab_ksize 0 11664 NULL
109586 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
109587 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
109588 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
109589 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
109590 +split_11691 split 2 11691 NULL
109591 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
109592 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
109593 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
109594 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
109595 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
109596 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
109597 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
109598 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
109599 +xfs_ialloc_11819 xfs_ialloc 0 11819 NULL
109600 +umc_device_register_11824 umc_device_register 0 11824 NULL
109601 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
109602 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
109603 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
109604 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
109605 +xfs_file_aio_write_checks_11851 xfs_file_aio_write_checks 0 11851 NULL
109606 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
109607 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
109608 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
109609 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
109610 +ti_write_11916 ti_write 4 11916 NULL
109611 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
109612 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
109613 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
109614 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
109615 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
109616 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
109617 +i40e_pci_sriov_configure_12011 i40e_pci_sriov_configure 2 12011 NULL
109618 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
109619 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
109620 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
109621 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
109622 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
109623 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
109624 +gfs2_find_jhead_12117 gfs2_find_jhead 0 12117 NULL
109625 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
109626 +set_powered_12129 set_powered 4 12129 NULL
109627 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
109628 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
109629 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
109630 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
109631 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
109632 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
109633 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
109634 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
109635 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
109636 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
109637 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
109638 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
109639 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
109640 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
109641 +xfs_attr3_leaf_read_12222 xfs_attr3_leaf_read 0 12222 NULL
109642 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
109643 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
109644 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
109645 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
109646 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
109647 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
109648 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
109649 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
109650 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
109651 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
109652 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
109653 +xfs_bmap_last_extent_12335 xfs_bmap_last_extent 0 12335 NULL
109654 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
109655 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
109656 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
109657 +populate_dir_12391 populate_dir 0 12391 NULL nohasharray
109658 +write_file_dump_12391 write_file_dump 3 12391 &populate_dir_12391
109659 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
109660 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
109661 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
109662 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
109663 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
109664 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
109665 +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
109666 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
109667 +write_inode_now_12565 write_inode_now 0 12565 NULL
109668 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
109669 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
109670 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
109671 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
109672 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
109673 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
109674 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
109675 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
109676 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
109677 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
109678 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
109679 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
109680 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
109681 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
109682 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
109683 +ivtv_write_12721 ivtv_write 3 12721 NULL
109684 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
109685 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
109686 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
109687 +listxattr_12769 listxattr 3 12769 NULL
109688 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
109689 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
109690 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
109691 +readq_12825 readq 0 12825 NULL
109692 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
109693 +gfs2_log_reserve_12835 gfs2_log_reserve 0 12835 NULL
109694 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
109695 +spidev_sync_12842 spidev_sync 0 12842 NULL
109696 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
109697 +xfs_rtallocate_extent_exact_12865 xfs_rtallocate_extent_exact 0 12865 NULL
109698 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
109699 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
109700 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
109701 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
109702 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
109703 +bm_status_write_12964 bm_status_write 3 12964 NULL
109704 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
109705 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
109706 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
109707 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
109708 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
109709 +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
109710 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
109711 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
109712 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
109713 +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
109714 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
109715 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
109716 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
109717 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
109718 +blk_update_request_13146 blk_update_request 3 13146 NULL
109719 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
109720 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
109721 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
109722 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
109723 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
109724 +comedi_read_13199 comedi_read 3 13199 NULL
109725 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
109726 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
109727 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
109728 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
109729 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
109730 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
109731 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
109732 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
109733 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
109734 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
109735 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
109736 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
109737 +sd_major_13294 sd_major 0-1 13294 NULL
109738 +module_param_sysfs_setup_13296 module_param_sysfs_setup 0 13296 NULL
109739 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
109740 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
109741 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
109742 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
109743 +xfs_btree_delrec_13364 xfs_btree_delrec 0 13364 NULL
109744 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
109745 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
109746 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
109747 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
109748 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
109749 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
109750 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
109751 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 8-9-7 13443 NULL
109752 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
109753 +data_read_13494 data_read 3 13494 NULL
109754 +ioat_chansts_32_13506 ioat_chansts_32 0 13506 NULL
109755 +core_status_13515 core_status 4 13515 NULL
109756 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
109757 +bm_init_13529 bm_init 2 13529 NULL
109758 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
109759 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
109760 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
109761 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
109762 +cache_write_13589 cache_write 3 13589 NULL
109763 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
109764 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
109765 +__ntfs_grab_cache_pages_13617 __ntfs_grab_cache_pages 0 13617 NULL
109766 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
109767 +packet_snd_13634 packet_snd 3 13634 NULL
109768 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
109769 +cache_downcall_13666 cache_downcall 3 13666 NULL
109770 +usb_get_string_13693 usb_get_string 0 13693 NULL
109771 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
109772 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
109773 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
109774 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
109775 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
109776 +random_read_13815 random_read 3 13815 NULL
109777 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
109778 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
109779 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
109780 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
109781 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
109782 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
109783 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
109784 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
109785 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
109786 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
109787 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
109788 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
109789 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
109790 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
109791 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL nohasharray
109792 +pagecache_write_end_13950 pagecache_write_end 0 13950 &lpfc_idiag_queacc_read_13950
109793 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
109794 +ocfs2_refresh_slot_info_13957 ocfs2_refresh_slot_info 0 13957 NULL
109795 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
109796 +qcam_read_13977 qcam_read 3 13977 NULL
109797 +dsp_read_13980 dsp_read 2 13980 NULL
109798 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
109799 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
109800 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
109801 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
109802 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
109803 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
109804 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
109805 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
109806 +xfs_bmap_alloc_14044 xfs_bmap_alloc 0 14044 NULL
109807 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
109808 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
109809 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
109810 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
109811 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
109812 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
109813 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
109814 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
109815 +em_canid_change_14150 em_canid_change 3 14150 NULL
109816 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
109817 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
109818 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
109819 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
109820 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
109821 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
109822 +alloc_async_14208 alloc_async 1 14208 NULL
109823 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
109824 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
109825 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
109826 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
109827 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
109828 +rr_status_14293 rr_status 5 14293 NULL
109829 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
109830 +update_rgrp_lvb_14303 update_rgrp_lvb 0 14303 NULL
109831 +xfs_qm_qino_alloc_14309 xfs_qm_qino_alloc 0 14309 NULL
109832 +oo_objects_14319 oo_objects 0 14319 NULL
109833 +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
109834 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
109835 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
109836 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
109837 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
109838 +lowpan_read_14369 lowpan_read 3 14369 NULL
109839 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
109840 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
109841 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
109842 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
109843 +block_size_14443 block_size 0 14443 NULL
109844 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
109845 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
109846 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
109847 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
109848 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
109849 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
109850 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
109851 +split_state_14491 split_state 0 14491 NULL
109852 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
109853 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
109854 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 &ep0_write_14536
109855 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
109856 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
109857 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
109858 +stuffed_readpage_14581 stuffed_readpage 0 14581 NULL
109859 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
109860 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
109861 +dbJoin_14644 dbJoin 0 14644 NULL
109862 +profile_replace_14652 profile_replace 3 14652 NULL
109863 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
109864 +add_to_page_cache_locked_14668 add_to_page_cache_locked 0 14668 NULL
109865 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
109866 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
109867 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
109868 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
109869 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
109870 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
109871 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
109872 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
109873 +vfd_write_14717 vfd_write 3 14717 NULL
109874 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
109875 +raid1_resize_14740 raid1_resize 2 14740 NULL
109876 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
109877 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
109878 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
109879 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
109880 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
109881 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
109882 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
109883 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
109884 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
109885 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
109886 +xfs_btree_kill_iroot_14824 xfs_btree_kill_iroot 0 14824 NULL
109887 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
109888 +lcd_write_14857 lcd_write 3 14857 NULL
109889 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
109890 +xfs_bmapi_convert_unwritten_14886 xfs_bmapi_convert_unwritten 0 14886 NULL
109891 +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
109892 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
109893 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
109894 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
109895 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
109896 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
109897 +queue_cnt_14951 queue_cnt 0 14951 NULL
109898 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
109899 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
109900 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
109901 +setkey_14987 setkey 3 14987 NULL nohasharray
109902 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
109903 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
109904 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
109905 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
109906 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
109907 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
109908 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
109909 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
109910 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
109911 +xfs_btree_insrec_15090 xfs_btree_insrec 0 15090 NULL
109912 +btrfs_readpage_15094 btrfs_readpage 0 15094 NULL
109913 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
109914 +start_port_15124 start_port 0 15124 NULL
109915 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
109916 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
109917 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
109918 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
109919 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
109920 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
109921 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
109922 +simple_strtol_15273 simple_strtol 0 15273 NULL
109923 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
109924 +ocfs2_read_refcount_block_15305 ocfs2_read_refcount_block 0 15305 NULL
109925 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
109926 +ioread16_15342 ioread16 0 15342 NULL
109927 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
109928 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
109929 +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
109930 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
109931 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
109932 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
109933 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
109934 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
109935 +get_modalias_15406 get_modalias 2 15406 NULL
109936 +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
109937 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
109938 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
109939 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
109940 +memweight_15450 memweight 2 15450 NULL
109941 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
109942 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
109943 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
109944 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
109945 +persistent_status_15574 persistent_status 4 15574 NULL
109946 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
109947 +vme_user_write_15587 vme_user_write 3 15587 NULL
109948 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
109949 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
109950 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
109951 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &tomoyo_scan_bprm_15642 nohasharray
109952 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &sk_memory_allocated_add_15642
109953 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
109954 +fs_path_add_15648 fs_path_add 3 15648 NULL
109955 +__do_readpage_15652 __do_readpage 0 15652 NULL
109956 +xsd_read_15653 xsd_read 3 15653 NULL
109957 +unix_bind_15668 unix_bind 3 15668 NULL
109958 +dm_read_15674 dm_read 3 15674 NULL nohasharray
109959 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
109960 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
109961 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
109962 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
109963 +nameseq_list_15817 nameseq_list 3-0 15817 NULL nohasharray
109964 +gnttab_expand_15817 gnttab_expand 1 15817 &nameseq_list_15817
109965 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
109966 +table_size_15851 table_size 0-1-2 15851 NULL
109967 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
109968 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
109969 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
109970 +native_read_msr_15905 native_read_msr 0 15905 NULL
109971 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
109972 +power_read_15939 power_read 3 15939 NULL
109973 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
109974 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
109975 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
109976 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
109977 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
109978 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
109979 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
109980 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
109981 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
109982 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
109983 +gfs2_jdesc_check_16122 gfs2_jdesc_check 0 16122 NULL
109984 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
109985 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
109986 +fsm_init_16134 fsm_init 2 16134 NULL
109987 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
109988 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
109989 +mapping_level_16188 mapping_level 2-0 16188 NULL
109990 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
109991 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
109992 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
109993 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
109994 +create_table_16213 create_table 2 16213 NULL
109995 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
109996 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
109997 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
109998 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
109999 +btrfs_dev_extent_chunk_offset_16247 btrfs_dev_extent_chunk_offset 0 16247 NULL nohasharray
110000 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 &btrfs_dev_extent_chunk_offset_16247
110001 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
110002 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
110003 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
110004 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
110005 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
110006 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
110007 +account_16283 account 0-4-2 16283 NULL nohasharray
110008 +mirror_status_16283 mirror_status 5 16283 &account_16283
110009 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
110010 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
110011 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
110012 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
110013 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
110014 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
110015 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
110016 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
110017 +xfs_inobt_lookup_16367 xfs_inobt_lookup 0 16367 NULL
110018 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
110019 +gfs2_dinode_in_16378 gfs2_dinode_in 0 16378 NULL
110020 +xfs_btree_check_block_16419 xfs_btree_check_block 0 16419 NULL
110021 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
110022 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
110023 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
110024 +cmdline_store_16442 cmdline_store 4 16442 NULL
110025 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
110026 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
110027 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
110028 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
110029 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
110030 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
110031 +raid10_resize_16537 raid10_resize 2 16537 NULL
110032 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
110033 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
110034 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
110035 +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
110036 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
110037 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
110038 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
110039 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
110040 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
110041 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
110042 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
110043 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
110044 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
110045 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
110046 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
110047 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
110048 +xfs_dialloc_ag_16868 xfs_dialloc_ag 0 16868 NULL
110049 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL nohasharray
110050 +xfs_iget_16872 xfs_iget 0 16872 &alloc_idx_lebs_16872
110051 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
110052 +st_write_16874 st_write 3 16874 NULL
110053 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
110054 +transport_init_session_tags_16878 transport_init_session_tags 1-2 16878 NULL
110055 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 NULL nohasharray
110056 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 &snd_gf1_mem_proc_dump_16926
110057 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
110058 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
110059 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
110060 +ocfs2_read_quota_phys_block_16990 ocfs2_read_quota_phys_block 0 16990 NULL
110061 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
110062 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
110063 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
110064 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
110065 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
110066 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
110067 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
110068 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
110069 +entry_length_17093 entry_length 0 17093 NULL
110070 +ocfs2_get_refcount_cpos_end_17113 ocfs2_get_refcount_cpos_end 0 17113 NULL
110071 +write_mem_17114 write_mem 3 17114 NULL
110072 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
110073 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
110074 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
110075 +sep_read_17161 sep_read 3 17161 NULL
110076 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
110077 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
110078 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
110079 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
110080 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189 nohasharray
110081 +ocfs2_flock_handle_signal_17189 ocfs2_flock_handle_signal 0 17189 &iwl_dbgfs_txfifo_flush_write_17189
110082 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
110083 +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
110084 +sync_request_17208 sync_request 2 17208 NULL
110085 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
110086 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
110087 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
110088 +alloc_ep_17269 alloc_ep 1 17269 NULL
110089 +pg_read_17276 pg_read 3 17276 NULL
110090 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
110091 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
110092 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
110093 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
110094 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
110095 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
110096 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
110097 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
110098 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
110099 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
110100 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
110101 +compat_sys_ppoll_17430 compat_sys_ppoll 2 17430 NULL
110102 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
110103 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
110104 +xfs_btree_lshift_17448 xfs_btree_lshift 0 17448 NULL
110105 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
110106 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
110107 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
110108 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
110109 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
110110 +qp_free_res_17541 qp_free_res 5 17541 NULL
110111 +__copy_to_user_17551 __copy_to_user 3-0 17551 NULL
110112 +copy_from_user_17559 copy_from_user 0-3 17559 NULL
110113 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
110114 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
110115 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
110116 +osst_execute_17607 osst_execute 7-6 17607 NULL
110117 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
110118 +dma_map_page_17628 dma_map_page 0 17628 NULL
110119 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
110120 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
110121 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
110122 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
110123 +filemap_fdatawait_17688 filemap_fdatawait 0 17688 NULL
110124 +venus_rename_17707 venus_rename 4-5 17707 NULL nohasharray
110125 +__einj_error_trigger_17707 __einj_error_trigger 0 17707 &venus_rename_17707
110126 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
110127 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
110128 +dgap_do_fep_load_17765 dgap_do_fep_load 3 17765 NULL
110129 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
110130 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
110131 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
110132 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
110133 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
110134 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
110135 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
110136 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
110137 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
110138 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
110139 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
110140 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
110141 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
110142 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
110143 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
110144 +xfs_rtallocate_extent_near_17916 xfs_rtallocate_extent_near 0 17916 NULL
110145 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
110146 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
110147 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
110148 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
110149 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
110150 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
110151 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
110152 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
110153 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
110154 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
110155 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
110156 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
110157 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
110158 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
110159 +fpregs_get_18066 fpregs_get 4 18066 NULL
110160 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
110161 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
110162 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
110163 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
110164 +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
110165 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
110166 +svc_getnl_18120 svc_getnl 0 18120 NULL
110167 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
110168 +xfs_zero_eof_18134 xfs_zero_eof 0 18134 NULL
110169 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
110170 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
110171 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
110172 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
110173 +read_rindex_entry_18213 read_rindex_entry 0 18213 NULL
110174 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
110175 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
110176 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
110177 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
110178 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
110179 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
110180 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
110181 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
110182 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
110183 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
110184 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
110185 +um_idi_write_18293 um_idi_write 3 18293 NULL
110186 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
110187 +vga_r_18310 vga_r 0 18310 NULL
110188 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
110189 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
110190 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
110191 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
110192 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
110193 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
110194 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
110195 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
110196 +ep_io_18367 ep_io 0 18367 NULL
110197 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
110198 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
110199 +ci_role_write_18388 ci_role_write 3 18388 NULL
110200 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
110201 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
110202 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
110203 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
110204 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
110205 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
110206 +flash_dev_cache_miss_18454 flash_dev_cache_miss 4 18454 NULL
110207 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
110208 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
110209 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
110210 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
110211 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
110212 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
110213 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
110214 +__block_write_begin_18511 __block_write_begin 0 18511 NULL
110215 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
110216 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
110217 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
110218 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
110219 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
110220 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
110221 +debug_output_18575 debug_output 3 18575 NULL
110222 +xfs_btree_read_bufl_18597 xfs_btree_read_bufl 0 18597 NULL
110223 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL
110224 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
110225 +nvc0_ram_create__18624 nvc0_ram_create_ 4 18624 NULL
110226 +from_buffer_18625 from_buffer 3 18625 NULL
110227 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
110228 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
110229 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
110230 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
110231 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
110232 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
110233 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
110234 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
110235 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
110236 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
110237 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
110238 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
110239 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
110240 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
110241 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
110242 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
110243 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
110244 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
110245 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
110246 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
110247 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
110248 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
110249 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
110250 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
110251 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
110252 +clean_journal_18955 clean_journal 0 18955 NULL
110253 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
110254 +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
110255 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
110256 +huge_page_size_19008 huge_page_size 0 19008 NULL
110257 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
110258 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
110259 +revalidate_19043 revalidate 2 19043 NULL
110260 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
110261 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
110262 +get_log_header_19063 get_log_header 0 19063 NULL
110263 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
110264 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
110265 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
110266 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
110267 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
110268 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
110269 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
110270 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
110271 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
110272 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
110273 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
110274 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
110275 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
110276 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
110277 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
110278 +ucma_query_19260 ucma_query 4 19260 NULL
110279 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
110280 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
110281 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
110282 +qc_capture_19298 qc_capture 3 19298 NULL
110283 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
110284 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
110285 +debug_read_19322 debug_read 3 19322 NULL
110286 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
110287 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
110288 +closure_sub_19359 closure_sub 2 19359 NULL
110289 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
110290 +read_zero_19366 read_zero 3 19366 NULL
110291 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
110292 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
110293 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
110294 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
110295 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
110296 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
110297 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
110298 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
110299 +sky2_read16_19475 sky2_read16 0 19475 NULL
110300 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
110301 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
110302 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
110303 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
110304 +apei_exec_pre_map_gars_19529 apei_exec_pre_map_gars 0 19529 NULL nohasharray
110305 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 &apei_exec_pre_map_gars_19529
110306 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
110307 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
110308 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
110309 +nfsd_read_19568 nfsd_read 5 19568 NULL
110310 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
110311 +mnt_want_write_file_19579 mnt_want_write_file 0 19579 NULL
110312 +bm_status_read_19583 bm_status_read 3 19583 NULL
110313 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
110314 +fallocate_chunk_19610 fallocate_chunk 0 19610 NULL
110315 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
110316 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
110317 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
110318 +ocfs2_control_get_this_node_19721 ocfs2_control_get_this_node 0 19721 NULL
110319 +read_reg_19723 read_reg 0 19723 NULL
110320 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
110321 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
110322 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
110323 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
110324 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
110325 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
110326 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
110327 +readhscx_19769 readhscx 0 19769 NULL
110328 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
110329 +xfs_bmap_add_extent_hole_real_19828 xfs_bmap_add_extent_hole_real 0 19828 NULL
110330 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
110331 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
110332 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
110333 +__nla_put_19857 __nla_put 3 19857 NULL
110334 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
110335 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
110336 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
110337 +mangle_name_19923 mangle_name 0 19923 NULL
110338 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
110339 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
110340 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
110341 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
110342 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
110343 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
110344 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
110345 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
110346 +event_trigger_write_20009 event_trigger_write 3 20009 NULL nohasharray
110347 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 &event_trigger_write_20009
110348 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
110349 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
110350 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
110351 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
110352 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 4 20067 NULL
110353 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
110354 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
110355 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
110356 +team_options_register_20091 team_options_register 3 20091 NULL
110357 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
110358 +xfs_qm_dqget_20103 xfs_qm_dqget 0 20103 NULL
110359 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
110360 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
110361 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
110362 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
110363 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
110364 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
110365 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
110366 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
110367 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
110368 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
110369 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
110370 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
110371 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
110372 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
110373 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
110374 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
110375 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
110376 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL nohasharray
110377 +read_7220_creg32_20394 read_7220_creg32 0 20394 &snd_nm256_readl_20394
110378 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL nohasharray
110379 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 &__kfifo_from_user_20399
110380 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
110381 +read_buf_20469 read_buf 2 20469 NULL
110382 +bio_trim_20472 bio_trim 2 20472 NULL
110383 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
110384 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
110385 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
110386 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
110387 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
110388 +venus_create_20555 venus_create 4 20555 NULL
110389 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
110390 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
110391 +xfs_bmap_isaeof_20570 xfs_bmap_isaeof 0 20570 NULL
110392 +ocfs2_cluster_lock_20588 ocfs2_cluster_lock 0 20588 NULL
110393 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
110394 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
110395 +lirc_write_20604 lirc_write 3 20604 NULL
110396 +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
110397 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
110398 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
110399 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
110400 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
110401 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
110402 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
110403 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL nohasharray
110404 +btrfs_qgroup_reserve_20676 btrfs_qgroup_reserve 0 20676 &snd_hdsp_playback_copy_20676
110405 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
110406 +cpumask_size_20683 cpumask_size 0 20683 NULL
110407 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
110408 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
110409 +__maestro_read_20700 __maestro_read 0 20700 NULL
110410 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
110411 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
110412 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
110413 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
110414 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
110415 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
110416 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
110417 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL nohasharray
110418 +mnt_clone_write_20763 mnt_clone_write 0 20763 &brcmf_p2p_escan_20763
110419 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
110420 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
110421 +lowpan_write_20800 lowpan_write 3 20800 NULL
110422 +strndup_user_20819 strndup_user 2 20819 NULL nohasharray
110423 +do_glock_20819 do_glock 0 20819 &strndup_user_20819
110424 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
110425 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
110426 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
110427 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
110428 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
110429 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
110430 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
110431 +srq_free_res_20868 srq_free_res 5 20868 NULL
110432 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
110433 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
110434 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
110435 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
110436 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
110437 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
110438 +htable_bits_20933 htable_bits 0 20933 NULL
110439 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
110440 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
110441 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
110442 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
110443 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
110444 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
110445 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
110446 +btrfs_dirty_pages_21019 btrfs_dirty_pages 0 21019 NULL
110447 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
110448 +xfs_btree_new_root_21028 xfs_btree_new_root 0 21028 NULL
110449 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
110450 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
110451 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
110452 +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
110453 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
110454 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
110455 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
110456 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
110457 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
110458 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
110459 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
110460 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
110461 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
110462 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
110463 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
110464 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
110465 +input_ff_create_21240 input_ff_create 2 21240 NULL
110466 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
110467 +use_debug_keys_read_21251 use_debug_keys_read 3 21251 NULL
110468 +fru_length_21257 fru_length 0 21257 NULL
110469 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
110470 +xfs_alloc_ag_vextent_size_21276 xfs_alloc_ag_vextent_size 0 21276 NULL
110471 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
110472 +add_res_range_21310 add_res_range 4 21310 NULL
110473 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
110474 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
110475 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
110476 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
110477 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
110478 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
110479 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
110480 +insert_ptr_21386 insert_ptr 6 21386 NULL
110481 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
110482 +__clone_and_map_simple_bio_21404 __clone_and_map_simple_bio 4 21404 NULL
110483 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
110484 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
110485 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
110486 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
110487 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
110488 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
110489 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
110490 +ReadISAR_21453 ReadISAR 0 21453 NULL
110491 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
110492 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
110493 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
110494 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
110495 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
110496 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
110497 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
110498 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
110499 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
110500 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
110501 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
110502 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
110503 +gfs2_glock_nq_init_21624 gfs2_glock_nq_init 0 21624 NULL
110504 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
110505 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
110506 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
110507 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
110508 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
110509 +xfs_btree_insert_21712 xfs_btree_insert 0 21712 NULL
110510 +update_time_21719 update_time 0 21719 NULL
110511 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
110512 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
110513 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
110514 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
110515 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
110516 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
110517 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
110518 +__ocfs2_cluster_lock_21812 __ocfs2_cluster_lock 0 21812 NULL
110519 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
110520 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
110521 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
110522 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
110523 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
110524 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
110525 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
110526 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
110527 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
110528 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
110529 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
110530 +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
110531 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
110532 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
110533 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
110534 +lookup_metapath_22039 lookup_metapath 0 22039 NULL
110535 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
110536 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
110537 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
110538 +mem_rw_22085 mem_rw 3 22085 NULL
110539 +xfs_bmapi_reserve_delalloc_22086 xfs_bmapi_reserve_delalloc 0 22086 NULL
110540 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
110541 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
110542 +shmem_add_to_page_cache_22121 shmem_add_to_page_cache 0 22121 NULL
110543 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
110544 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
110545 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
110546 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
110547 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
110548 +mem_write_22232 mem_write 3 22232 NULL
110549 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
110550 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
110551 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
110552 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
110553 +add_res_tree_22263 add_res_tree 7 22263 NULL
110554 +__btrfs_direct_write_22273 __btrfs_direct_write 4-0 22273 NULL
110555 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
110556 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
110557 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
110558 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
110559 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
110560 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
110561 +atomic_read_22342 atomic_read 0 22342 NULL
110562 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
110563 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
110564 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
110565 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
110566 +zoran_write_22404 zoran_write 3 22404 NULL
110567 +queue_reply_22416 queue_reply 3 22416 NULL
110568 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
110569 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
110570 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
110571 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
110572 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
110573 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
110574 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
110575 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
110576 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
110577 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
110578 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
110579 +snapshot_read_22601 snapshot_read 3 22601 NULL
110580 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
110581 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
110582 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
110583 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
110584 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
110585 +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
110586 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
110587 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
110588 +reg_umr_22686 reg_umr 5 22686 NULL
110589 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
110590 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
110591 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
110592 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
110593 +__writeback_single_inode_22739 __writeback_single_inode 0 22739 NULL
110594 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
110595 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
110596 +print_frame_22769 print_frame 0 22769 NULL
110597 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
110598 +__break_lease_22777 __break_lease 0 22777 NULL
110599 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
110600 +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
110601 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
110602 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
110603 +create_attr_set_22861 create_attr_set 1 22861 NULL
110604 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
110605 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
110606 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
110607 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
110608 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
110609 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
110610 +__set_xattr_22923 __set_xattr 0 22923 NULL
110611 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
110612 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
110613 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
110614 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
110615 +vme_get_size_22964 vme_get_size 0 22964 NULL
110616 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
110617 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
110618 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
110619 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
110620 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
110621 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
110622 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 0 23029 NULL
110623 +st_status_23032 st_status 5 23032 NULL
110624 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
110625 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
110626 +security_inode_killpriv_23060 security_inode_killpriv 0 23060 NULL
110627 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
110628 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
110629 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
110630 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
110631 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
110632 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
110633 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
110634 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
110635 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
110636 +xfs_dir_ialloc_23100 xfs_dir_ialloc 0 23100 NULL
110637 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
110638 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
110639 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
110640 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 NULL nohasharray
110641 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 &nl80211_send_rx_auth_23111
110642 +__clear_user_23118 __clear_user 0-2 23118 NULL
110643 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
110644 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
110645 +read_file_ani_23161 read_file_ani 3 23161 NULL
110646 +usblp_write_23178 usblp_write 3 23178 NULL
110647 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
110648 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
110649 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
110650 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
110651 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
110652 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
110653 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
110654 +__gfn_to_rmap_23240 __gfn_to_rmap 2-1 23240 NULL
110655 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
110656 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
110657 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
110658 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
110659 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
110660 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
110661 +page_readlink_23346 page_readlink 3 23346 NULL
110662 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
110663 +get_dst_timing_23358 get_dst_timing 0 23358 NULL nohasharray
110664 +write_inode_23358 write_inode 0 23358 &get_dst_timing_23358
110665 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
110666 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
110667 +vga_mm_r_23419 vga_mm_r 0 23419 NULL
110668 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
110669 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
110670 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
110671 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
110672 +sync_mapping_buffers_23485 sync_mapping_buffers 0 23485 &linear_conf_23485
110673 +event_filter_read_23494 event_filter_read 3 23494 NULL
110674 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
110675 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
110676 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
110677 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
110678 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
110679 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
110680 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
110681 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
110682 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
110683 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
110684 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
110685 +xfs_qm_dqread_23613 xfs_qm_dqread 0 23613 NULL
110686 +ocfs2_journal_access_23616 ocfs2_journal_access 0 23616 NULL
110687 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
110688 +sInW_23663 sInW 0 23663 NULL
110689 +SyS_connect_23669 SyS_connect 3 23669 NULL
110690 +cx18_read_23699 cx18_read 3 23699 NULL
110691 +at_get_23708 at_get 0 23708 NULL
110692 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
110693 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
110694 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
110695 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
110696 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
110697 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
110698 +map_write_23795 map_write 3 23795 NULL
110699 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
110700 +ocfs2_replace_cow_23803 ocfs2_replace_cow 0 23803 NULL
110701 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
110702 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
110703 +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 0-4-3 23829 NULL
110704 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
110705 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
110706 +p54_init_common_23850 p54_init_common 1 23850 NULL
110707 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
110708 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
110709 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
110710 +writeback_single_inode_23881 writeback_single_inode 0 23881 NULL nohasharray
110711 +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 &writeback_single_inode_23881
110712 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
110713 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
110714 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
110715 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
110716 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 NULL nohasharray
110717 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 &mpihelp_mul_karatsuba_case_23918
110718 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
110719 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
110720 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
110721 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
110722 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
110723 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
110724 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
110725 +give_pages_24021 give_pages 3 24021 NULL
110726 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
110727 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
110728 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
110729 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
110730 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
110731 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
110732 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
110733 +lov_brw_24122 lov_brw 4 24122 NULL
110734 +mpu401_read_24126 mpu401_read 3-0 24126 NULL
110735 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
110736 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL nohasharray
110737 +xfs_btree_increment_24139 xfs_btree_increment 0 24139 &irnet_ctrl_write_24139
110738 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
110739 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
110740 +adu_read_24177 adu_read 3 24177 NULL
110741 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
110742 +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
110743 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
110744 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
110745 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
110746 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
110747 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
110748 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
110749 +xfs_bmap_rtalloc_24237 xfs_bmap_rtalloc 0 24237 NULL
110750 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
110751 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
110752 +thin_status_24278 thin_status 5 24278 NULL
110753 +msg_size_24288 msg_size 0 24288 NULL
110754 +gserial_connect_24302 gserial_connect 0 24302 NULL
110755 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
110756 +reserve_metadata_bytes_24313 reserve_metadata_bytes 0 24313 NULL
110757 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
110758 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
110759 +prepare_pages_24349 prepare_pages 0 24349 NULL
110760 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
110761 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
110762 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
110763 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
110764 +igetword_24373 igetword 0 24373 NULL nohasharray
110765 +break_deleg_24373 break_deleg 0 24373 &igetword_24373
110766 +max_io_len_24384 max_io_len 0-1 24384 NULL
110767 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
110768 +xfs_bmapi_read_24392 xfs_bmapi_read 0 24392 NULL
110769 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
110770 +getxattr_24398 getxattr 4 24398 NULL nohasharray
110771 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
110772 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
110773 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
110774 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
110775 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
110776 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
110777 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
110778 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
110779 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
110780 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
110781 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
110782 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
110783 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
110784 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
110785 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
110786 +pd_video_read_24510 pd_video_read 3 24510 NULL
110787 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
110788 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
110789 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
110790 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
110791 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
110792 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
110793 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
110794 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
110795 +SyS_poll_24620 SyS_poll 2 24620 NULL
110796 +context_alloc_24645 context_alloc 3 24645 NULL
110797 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
110798 +xfs_log_commit_cil_24653 xfs_log_commit_cil 0 24653 NULL
110799 +btrfs_check_data_free_space_24692 btrfs_check_data_free_space 0 24692 NULL
110800 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
110801 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
110802 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
110803 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
110804 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
110805 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
110806 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
110807 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
110808 +cache_read_24790 cache_read 3 24790 NULL
110809 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
110810 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
110811 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
110812 +net2272_read_24825 net2272_read 0 24825 NULL
110813 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
110814 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
110815 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
110816 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
110817 +queues_read_24877 queues_read 3 24877 NULL
110818 +__vxge_hw_vp_initialize_24885 __vxge_hw_vp_initialize 2 24885 NULL
110819 +xfs_qm_dqattach_24898 xfs_qm_dqattach 0 24898 NULL
110820 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
110821 +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 NULL nohasharray
110822 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 &__btrfs_free_extent_24927
110823 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
110824 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
110825 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
110826 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
110827 +slot_get_24999 slot_get 0 24999 NULL
110828 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
110829 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
110830 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
110831 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
110832 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
110833 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
110834 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
110835 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
110836 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
110837 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
110838 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
110839 +gfs2_quota_check_25130 gfs2_quota_check 0 25130 NULL
110840 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
110841 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
110842 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
110843 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
110844 +stripe_status_25259 stripe_status 5 25259 NULL
110845 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
110846 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
110847 +vfs_writev_25278 vfs_writev 3 25278 NULL
110848 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
110849 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
110850 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
110851 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
110852 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
110853 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
110854 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
110855 +xfs_ialloc_pagi_init_25411 xfs_ialloc_pagi_init 0 25411 NULL
110856 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
110857 +xfs_qm_dqtobp_25448 xfs_qm_dqtobp 0 25448 NULL
110858 +generic_file_buffered_write_25464 generic_file_buffered_write 4-0-7 25464 NULL
110859 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
110860 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
110861 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
110862 +xfs_alloc_fix_freelist_25514 xfs_alloc_fix_freelist 0 25514 NULL
110863 +sb_permission_25523 sb_permission 0 25523 NULL
110864 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
110865 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
110866 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
110867 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
110868 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
110869 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
110870 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
110871 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
110872 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
110873 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
110874 +__direct_map_25647 __direct_map 5-6 25647 NULL
110875 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
110876 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
110877 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
110878 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
110879 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
110880 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
110881 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
110882 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
110883 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
110884 +sg_read_25799 sg_read 3 25799 NULL
110885 +xfs_alloc_ag_vextent_exact_25810 xfs_alloc_ag_vextent_exact 0 25810 NULL
110886 +system_enable_read_25815 system_enable_read 3 25815 NULL
110887 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
110888 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
110889 +parport_read_25855 parport_read 0 25855 NULL
110890 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
110891 +key_attr_size_25865 key_attr_size 0 25865 NULL
110892 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
110893 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
110894 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
110895 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
110896 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
110897 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
110898 +rcname_read_25919 rcname_read 3 25919 NULL
110899 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
110900 +key_flags_read_25931 key_flags_read 3 25931 NULL
110901 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
110902 +flush_25957 flush 2 25957 NULL
110903 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
110904 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
110905 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
110906 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
110907 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
110908 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
110909 +btrfs_wait_ordered_range_26086 btrfs_wait_ordered_range 0 26086 NULL
110910 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
110911 +read_sb_page_26119 read_sb_page 5 26119 NULL
110912 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
110913 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
110914 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
110915 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
110916 +disk_devt_26180 disk_devt 0 26180 NULL
110917 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
110918 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
110919 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
110920 +mce_write_26201 mce_write 3 26201 NULL
110921 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
110922 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
110923 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
110924 +simple_setattr_26234 simple_setattr 0 26234 NULL
110925 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
110926 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
110927 +apei_resources_request_26279 apei_resources_request 0 26279 NULL
110928 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
110929 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
110930 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
110931 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
110932 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
110933 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
110934 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
110935 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
110936 +ntty_write_26404 ntty_write 3 26404 NULL
110937 +firmware_store_26408 firmware_store 4 26408 NULL
110938 +pagemap_read_26441 pagemap_read 3 26441 NULL
110939 +tower_read_26461 tower_read 3 26461 NULL nohasharray
110940 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
110941 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
110942 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
110943 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
110944 +read_vmcore_26501 read_vmcore 3 26501 NULL
110945 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
110946 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
110947 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
110948 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
110949 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
110950 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
110951 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
110952 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
110953 +xfs_rtcheck_range_26614 xfs_rtcheck_range 0 26614 NULL
110954 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
110955 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
110956 +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
110957 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
110958 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
110959 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
110960 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
110961 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
110962 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
110963 +bos_desc_26752 bos_desc 0 26752 NULL
110964 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
110965 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
110966 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
110967 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
110968 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
110969 +smk_write_load_26829 smk_write_load 3 26829 NULL
110970 +xfs_alloc_pagf_init_26834 xfs_alloc_pagf_init 0 26834 NULL
110971 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
110972 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
110973 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
110974 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
110975 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
110976 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
110977 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
110978 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
110979 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
110980 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
110981 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
110982 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
110983 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
110984 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
110985 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
110986 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
110987 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
110988 +xfs_filestream_associate_27030 xfs_filestream_associate 0 27030 NULL
110989 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
110990 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
110991 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
110992 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
110993 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
110994 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
110995 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
110996 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
110997 +get_kernel_page_27133 get_kernel_page 0 27133 NULL
110998 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
110999 +pms_capture_27142 pms_capture 4 27142 NULL
111000 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
111001 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
111002 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
111003 +__sg_alloc_table_27198 __sg_alloc_table 0 27198 NULL
111004 +write_kmem_27225 write_kmem 3 27225 NULL
111005 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
111006 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
111007 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
111008 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
111009 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
111010 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
111011 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
111012 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
111013 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
111014 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
111015 +seq_read_27411 seq_read 3 27411 NULL
111016 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
111017 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
111018 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 0 27422 NULL
111019 +cypress_write_27423 cypress_write 4 27423 NULL
111020 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
111021 +xfs_btree_lookup_get_block_27448 xfs_btree_lookup_get_block 0 27448 NULL
111022 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
111023 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
111024 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
111025 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
111026 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
111027 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
111028 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
111029 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
111030 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
111031 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
111032 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
111033 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
111034 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
111035 +read_flush_procfs_27642 read_flush_procfs 3 27642 &nl80211_send_connect_result_27642 nohasharray
111036 +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &read_flush_procfs_27642 nohasharray
111037 +xfs_alloc_vextent_27642 xfs_alloc_vextent 0 27642 &ocfs2_direct_IO_27642
111038 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
111039 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
111040 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
111041 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
111042 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
111043 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
111044 +evm_write_key_27715 evm_write_key 3 27715 NULL
111045 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
111046 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
111047 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
111048 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
111049 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
111050 +SyS_readv_27804 SyS_readv 3 27804 NULL
111051 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
111052 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
111053 +init_header_complete_27833 init_header_complete 0 27833 NULL
111054 +read_profile_27859 read_profile 3 27859 NULL
111055 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
111056 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
111057 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
111058 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL nohasharray
111059 +bio_next_split_27961 bio_next_split 2 27961 &tracing_clock_write_27961
111060 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
111061 +device_register_27972 device_register 0 27972 NULL nohasharray
111062 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 &device_register_27972
111063 +xfs_alloc_fixup_trees_27975 xfs_alloc_fixup_trees 0 27975 NULL
111064 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL nohasharray
111065 +__kernfs_setattr_27977 __kernfs_setattr 0 27977 &pci_enable_device_flags_27977
111066 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
111067 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
111068 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
111069 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
111070 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
111071 +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
111072 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
111073 +pool_status_28055 pool_status 5 28055 NULL
111074 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
111075 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
111076 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
111077 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
111078 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
111079 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
111080 +memblock_virt_alloc_from_nopanic_28146 memblock_virt_alloc_from_nopanic 1 28146 NULL
111081 +video_read_28148 video_read 3 28148 NULL
111082 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
111083 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
111084 +vread_28173 vread 0-3 28173 NULL
111085 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
111086 +counter_free_res_28187 counter_free_res 5 28187 NULL
111087 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
111088 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
111089 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
111090 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
111091 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
111092 +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
111093 +usemap_size_28281 usemap_size 0 28281 NULL
111094 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
111095 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
111096 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
111097 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
111098 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
111099 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
111100 +generic_write_checks_28329 generic_write_checks 0 28329 NULL
111101 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
111102 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
111103 +snapshot_write_28351 snapshot_write 3 28351 NULL
111104 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
111105 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
111106 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
111107 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
111108 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
111109 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
111110 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
111111 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
111112 +xfs_rtfind_back_28450 xfs_rtfind_back 0 28450 NULL
111113 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
111114 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
111115 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
111116 +__filemap_fdatawrite_28485 __filemap_fdatawrite 0 28485 NULL
111117 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
111118 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
111119 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
111120 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
111121 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &mptctl_getiocinfo_28545 nohasharray
111122 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545
111123 +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
111124 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
111125 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
111126 +gfs2_meta_indirect_buffer_28573 gfs2_meta_indirect_buffer 0 28573 NULL
111127 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
111128 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
111129 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
111130 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
111131 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
111132 +xfs_bmap_finish_28644 xfs_bmap_finish 0 28644 NULL
111133 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
111134 +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
111135 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
111136 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
111137 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
111138 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
111139 +spi_execute_28736 spi_execute 5 28736 NULL
111140 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
111141 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
111142 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
111143 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
111144 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
111145 +sel_write_member_28800 sel_write_member 3 28800 NULL
111146 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
111147 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
111148 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
111149 +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
111150 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
111151 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
111152 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
111153 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
111154 +push_rx_28939 push_rx 3 28939 NULL
111155 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
111156 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
111157 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
111158 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
111159 +xfs_alloc_update_28982 xfs_alloc_update 0 28982 NULL
111160 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
111161 +bin_uuid_28999 bin_uuid 3 28999 NULL
111162 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
111163 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
111164 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
111165 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
111166 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
111167 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
111168 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
111169 +xfs_alloc_ag_vextent_small_29084 xfs_alloc_ag_vextent_small 0 29084 NULL
111170 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
111171 +i915_error_object_create_sized_29091 i915_error_object_create_sized 3 29091 NULL
111172 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
111173 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
111174 +snprintf_29125 snprintf 0 29125 NULL
111175 +iov_shorten_29130 iov_shorten 0 29130 NULL
111176 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
111177 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
111178 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
111179 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
111180 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
111181 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
111182 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
111183 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
111184 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
111185 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
111186 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
111187 +xfs_bmap_btree_to_extents_29297 xfs_bmap_btree_to_extents 0 29297 NULL
111188 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
111189 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
111190 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
111191 +xfs_bmbt_change_owner_29325 xfs_bmbt_change_owner 0 29325 NULL
111192 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
111193 +tun_put_user_29337 tun_put_user 5 29337 NULL
111194 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
111195 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
111196 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
111197 +mempool_create_29437 mempool_create 1 29437 NULL
111198 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
111199 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
111200 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
111201 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
111202 +do_register_entry_29478 do_register_entry 4 29478 NULL
111203 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
111204 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
111205 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
111206 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
111207 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
111208 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
111209 +add_to_page_cache_lru_29534 add_to_page_cache_lru 0 29534 NULL
111210 +ftrace_write_29551 ftrace_write 3 29551 NULL
111211 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
111212 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
111213 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
111214 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
111215 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
111216 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
111217 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
111218 +slots_per_page_29601 slots_per_page 0 29601 NULL
111219 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
111220 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
111221 +gfs2_alloc_blocks_29630 gfs2_alloc_blocks 0 29630 NULL
111222 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
111223 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
111224 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
111225 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
111226 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
111227 +probes_write_29711 probes_write 3 29711 NULL
111228 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
111229 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
111230 +std_nic_write_29752 std_nic_write 3 29752 NULL
111231 +dbAlloc_29794 dbAlloc 0 29794 NULL
111232 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
111233 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
111234 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
111235 +count_partial_29850 count_partial 0 29850 NULL
111236 +xfs_rtfind_forw_29866 xfs_rtfind_forw 0 29866 NULL
111237 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
111238 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
111239 +scsi_end_request_29876 scsi_end_request 3 29876 NULL
111240 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
111241 +xfs_alloc_read_agf_29893 xfs_alloc_read_agf 0 29893 NULL
111242 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
111243 +write_file_queue_29922 write_file_queue 3 29922 NULL
111244 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
111245 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
111246 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
111247 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
111248 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
111249 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
111250 +drp_wmove_30043 drp_wmove 4 30043 NULL
111251 +mem_cgroup_charge_common_30047 mem_cgroup_charge_common 0 30047 NULL
111252 +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
111253 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
111254 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
111255 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
111256 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
111257 +xfs_iget_cache_miss_30115 xfs_iget_cache_miss 0 30115 NULL
111258 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
111259 +recv_stream_30138 recv_stream 4 30138 NULL
111260 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
111261 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
111262 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
111263 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
111264 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
111265 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
111266 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
111267 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
111268 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
111269 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
111270 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
111271 +shmem_unuse_inode_30263 shmem_unuse_inode 0 30263 NULL
111272 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
111273 +try_break_deleg_30271 try_break_deleg 0 30271 NULL nohasharray
111274 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 &try_break_deleg_30271
111275 +compat_readv_30273 compat_readv 3 30273 NULL
111276 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
111277 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
111278 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
111279 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
111280 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
111281 +i8254_read_30330 i8254_read 0 30330 NULL
111282 +resource_from_user_30341 resource_from_user 3 30341 NULL
111283 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
111284 +gfs2_trans_begin_30359 gfs2_trans_begin 0 30359 NULL
111285 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
111286 +pagecache_write_begin_30364 pagecache_write_begin 0 30364 NULL
111287 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
111288 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
111289 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
111290 +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
111291 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
111292 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
111293 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
111294 +enable_write_30456 enable_write 3 30456 NULL
111295 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
111296 +urandom_read_30462 urandom_read 3 30462 NULL
111297 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
111298 +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
111299 +adu_write_30487 adu_write 3 30487 NULL
111300 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
111301 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
111302 +__send_duplicate_bios_30498 __send_duplicate_bios 4 30498 NULL
111303 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
111304 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
111305 +set_config_30526 set_config 0 30526 NULL nohasharray
111306 +debug_debug2_read_30526 debug_debug2_read 3 30526 &set_config_30526
111307 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
111308 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
111309 +set_le_30581 set_le 4 30581 NULL
111310 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
111311 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
111312 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
111313 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
111314 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
111315 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
111316 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
111317 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
111318 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
111319 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL nohasharray
111320 +xfs_bmap_add_extent_unwritten_real_30701 xfs_bmap_add_extent_unwritten_real 0 30701 &dccp_setsockopt_ccid_30701
111321 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
111322 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
111323 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
111324 +snapshot_status_30744 snapshot_status 5 30744 NULL
111325 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
111326 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
111327 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
111328 +xlog_grant_head_wait_30829 xlog_grant_head_wait 0 30829 NULL
111329 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
111330 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
111331 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
111332 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
111333 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
111334 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
111335 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
111336 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
111337 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
111338 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
111339 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
111340 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
111341 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
111342 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
111343 +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
111344 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
111345 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
111346 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
111347 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
111348 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
111349 +depth_read_31112 depth_read 3 31112 NULL
111350 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
111351 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
111352 +size_inside_page_31141 size_inside_page 0 31141 NULL
111353 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
111354 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
111355 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
111356 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
111357 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
111358 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
111359 +__read_reg_31216 __read_reg 0 31216 NULL
111360 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
111361 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
111362 +cyy_readb_31240 cyy_readb 0 31240 NULL
111363 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
111364 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
111365 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
111366 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
111367 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
111368 +command_file_write_31318 command_file_write 3 31318 NULL
111369 +radix_tree_insert_31336 radix_tree_insert 0 31336 NULL
111370 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
111371 +outlen_write_31358 outlen_write 3 31358 NULL
111372 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
111373 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
111374 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
111375 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
111376 +inb_31388 inb 0 31388 NULL
111377 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
111378 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
111379 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
111380 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
111381 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
111382 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
111383 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
111384 +alg_setkey_31485 alg_setkey 3 31485 NULL
111385 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
111386 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
111387 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
111388 +hidraw_write_31536 hidraw_write 3 31536 NULL
111389 +usbvision_read_31555 usbvision_read 3 31555 NULL
111390 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
111391 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
111392 +osst_write_31581 osst_write 3 31581 NULL
111393 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
111394 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
111395 +mtd_get_user_prot_info_31616 mtd_get_user_prot_info 0 31616 NULL
111396 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL nohasharray
111397 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 &arvo_sysfs_read_31617
111398 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
111399 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
111400 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
111401 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
111402 +__lgread_31668 __lgread 4 31668 NULL
111403 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
111404 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
111405 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
111406 +gfs2_dir_check_31711 gfs2_dir_check 0 31711 NULL
111407 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
111408 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 NULL nohasharray
111409 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 &utf16s_to_utf8s_31735
111410 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
111411 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
111412 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
111413 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
111414 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
111415 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
111416 +osync_buffers_list_31789 osync_buffers_list 0 31789 NULL
111417 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
111418 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
111419 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
111420 +data_write_31805 data_write 3 31805 NULL
111421 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
111422 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
111423 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
111424 +clone_bio_31854 clone_bio 4-3 31854 NULL
111425 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
111426 +foreach_descriptor_31873 foreach_descriptor 0 31873 NULL
111427 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
111428 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
111429 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
111430 +xattr_permission_31907 xattr_permission 0 31907 NULL
111431 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
111432 +new_dir_31919 new_dir 3 31919 NULL
111433 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
111434 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
111435 +read_mem_31942 read_mem 3 31942 NULL nohasharray
111436 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
111437 +vb2_write_31948 vb2_write 3 31948 NULL
111438 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
111439 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
111440 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
111441 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
111442 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
111443 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
111444 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
111445 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
111446 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
111447 +calc_hmac_32010 calc_hmac 3 32010 NULL
111448 +aead_len_32021 aead_len 0 32021 NULL
111449 +stk_read_32038 stk_read 3 32038 NULL
111450 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
111451 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
111452 +xfs_buf_iowait_32068 xfs_buf_iowait 0 32068 NULL
111453 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
111454 +bio_alloc_32095 bio_alloc 2 32095 NULL
111455 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
111456 +disk_status_32120 disk_status 4 32120 NULL
111457 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
111458 +venus_link_32165 venus_link 5 32165 NULL
111459 +do_writepages_32173 do_writepages 0 32173 NULL
111460 +del_ptr_32197 del_ptr 4 32197 NULL
111461 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
111462 +__mem_cgroup_try_charge_swapin_32204 __mem_cgroup_try_charge_swapin 0 32204 NULL
111463 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
111464 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
111465 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
111466 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
111467 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
111468 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
111469 +SyS_select_32319 SyS_select 1 32319 NULL
111470 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
111471 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
111472 +xfs_bmap_extsize_align_32338 xfs_bmap_extsize_align 0 32338 NULL
111473 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
111474 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
111475 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
111476 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 NULL nohasharray
111477 +sel_read_initcon_32362 sel_read_initcon 3 32362 &ReadHDLCPCI_32362
111478 +ocfs2_cancel_convert_32392 ocfs2_cancel_convert 0 32392 NULL
111479 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
111480 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
111481 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
111482 +xfs_alloc_put_freelist_32437 xfs_alloc_put_freelist 0 32437 NULL
111483 +cache_status_32462 cache_status 5 32462 NULL
111484 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
111485 +dgap_usertoboard_32490 dgap_usertoboard 4 32490 NULL
111486 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
111487 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
111488 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
111489 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
111490 +disconnect_32521 disconnect 4 32521 NULL
111491 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
111492 +ocfs2_refresh_qinfo_32524 ocfs2_refresh_qinfo 0 32524 NULL
111493 +ilo_read_32531 ilo_read 3 32531 NULL
111494 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
111495 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
111496 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
111497 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
111498 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
111499 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
111500 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
111501 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
111502 +xfs_bmap_last_offset_32614 xfs_bmap_last_offset 0 32614 NULL
111503 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
111504 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
111505 +kvmalloc_32646 kvmalloc 1 32646 NULL
111506 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
111507 +generic_readlink_32654 generic_readlink 3 32654 NULL
111508 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
111509 +apei_res_add_32674 apei_res_add 0 32674 NULL
111510 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
111511 +xfs_filestream_new_ag_32711 xfs_filestream_new_ag 0 32711 NULL
111512 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
111513 +xfs_bmbt_update_32713 xfs_bmbt_update 0 32713 NULL
111514 +i40e_pci_sriov_enable_32742 i40e_pci_sriov_enable 2 32742 NULL
111515 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
111516 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
111517 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
111518 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
111519 +xfs_trans_read_buf_32795 xfs_trans_read_buf 0 32795 NULL
111520 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
111521 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
111522 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
111523 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
111524 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
111525 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
111526 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
111527 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
111528 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
111529 +xfs_log_reserve_32959 xfs_log_reserve 0 32959 NULL
111530 +compat_filldir_32999 compat_filldir 3 32999 NULL
111531 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
111532 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
111533 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
111534 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
111535 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
111536 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
111537 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
111538 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
111539 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
111540 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
111541 +alloc_tio_33077 alloc_tio 3 33077 NULL
111542 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
111543 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
111544 +notify_change_33143 notify_change 0 33143 NULL
111545 +SyS_poll_33152 SyS_poll 2 33152 NULL
111546 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
111547 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
111548 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
111549 +pp_read_33210 pp_read 3 33210 NULL
111550 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
111551 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
111552 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
111553 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
111554 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
111555 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
111556 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
111557 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
111558 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
111559 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
111560 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
111561 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
111562 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
111563 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
111564 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
111565 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
111566 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
111567 +filemap_fdatawrite_33415 filemap_fdatawrite 0 33415 NULL
111568 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
111569 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
111570 +message_stats_list_33440 message_stats_list 5 33440 NULL
111571 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
111572 +create_entry_33479 create_entry 2 33479 NULL
111573 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
111574 +res_counter_read_33499 res_counter_read 4 33499 NULL
111575 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
111576 +fb_read_33506 fb_read 3 33506 NULL
111577 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
111578 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
111579 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
111580 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
111581 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
111582 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
111583 +count_subheaders_33591 count_subheaders 0 33591 NULL
111584 +scsi_execute_33596 scsi_execute 5 33596 NULL
111585 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
111586 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
111587 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
111588 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
111589 +xfs_btree_check_sblock_33618 xfs_btree_check_sblock 0 33618 NULL
111590 +stride_page_count_33641 stride_page_count 2 33641 NULL
111591 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
111592 +inw_p_33668 inw_p 0 33668 NULL
111593 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
111594 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
111595 +submit_one_bio_33683 submit_one_bio 0 33683 NULL
111596 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
111597 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
111598 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
111599 +ext4_wb_update_i_disksize_33717 ext4_wb_update_i_disksize 2 33717 NULL
111600 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
111601 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
111602 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
111603 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
111604 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
111605 +hashtab_create_33769 hashtab_create 3 33769 NULL
111606 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
111607 +filter_write_33819 filter_write 3 33819 NULL
111608 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
111609 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
111610 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
111611 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
111612 +get_user_pages_33908 get_user_pages 0 33908 NULL
111613 +sg_nents_33909 sg_nents 0 33909 NULL
111614 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
111615 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
111616 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
111617 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
111618 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
111619 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
111620 +btrfs_delalloc_reserve_metadata_33963 btrfs_delalloc_reserve_metadata 0 33963 NULL
111621 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
111622 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
111623 +ppp_write_34034 ppp_write 3 34034 NULL
111624 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
111625 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
111626 +xfs_dialloc_34078 xfs_dialloc 0 34078 NULL
111627 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
111628 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
111629 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
111630 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
111631 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
111632 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
111633 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
111634 +ocfs2_xattr_list_entry_34165 ocfs2_xattr_list_entry 0 34165 NULL
111635 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
111636 +xfs_bmapi_write_34208 xfs_bmapi_write 0 34208 NULL
111637 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
111638 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
111639 +ocfs2_dlm_lock_34265 ocfs2_dlm_lock 0 34265 NULL
111640 +device_private_init_34279 device_private_init 0 34279 NULL
111641 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
111642 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
111643 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
111644 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
111645 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
111646 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
111647 +ea_read_34378 ea_read 0 34378 NULL
111648 +fuse_send_read_34379 fuse_send_read 4 34379 NULL
111649 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
111650 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
111651 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
111652 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
111653 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
111654 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
111655 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
111656 +__extent_read_full_page_34437 __extent_read_full_page 0 34437 NULL
111657 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
111658 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
111659 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
111660 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
111661 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
111662 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
111663 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
111664 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
111665 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
111666 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
111667 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
111668 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
111669 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
111670 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
111671 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
111672 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
111673 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
111674 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
111675 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
111676 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
111677 +apei_get_nvs_resources_34616 apei_get_nvs_resources 0 34616 NULL
111678 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
111679 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
111680 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
111681 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
111682 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
111683 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
111684 +port_print_34704 port_print 3 34704 NULL
111685 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
111686 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
111687 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
111688 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
111689 +bootmode_store_34762 bootmode_store 4 34762 NULL
111690 +device_add_34766 device_add 0 34766 NULL
111691 +xfs_iget_cache_hit_34767 xfs_iget_cache_hit 0 34767 NULL
111692 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
111693 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
111694 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
111695 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
111696 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
111697 +file_page_index_34820 file_page_index 0-2 34820 NULL
111698 +bio_segments_34832 bio_segments 0 34832 NULL
111699 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
111700 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
111701 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
111702 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
111703 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
111704 +msg_print_text_34889 msg_print_text 0 34889 NULL
111705 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
111706 +gfs2_glock_wait_34913 gfs2_glock_wait 0 34913 NULL
111707 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
111708 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
111709 +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
111710 +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
111711 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
111712 +i2c_transfer_34958 i2c_transfer 0 34958 NULL
111713 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
111714 +print_message_35000 print_message 0 35000 NULL
111715 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
111716 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
111717 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
111718 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
111719 +xfs_rtallocate_extent_35052 xfs_rtallocate_extent 0 35052 NULL
111720 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
111721 +ntfs_attr_extend_initialized_35084 ntfs_attr_extend_initialized 0 35084 NULL
111722 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
111723 +capi_write_35104 capi_write 3 35104 NULL nohasharray
111724 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
111725 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
111726 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
111727 +message_stats_print_35158 message_stats_print 6 35158 NULL
111728 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
111729 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
111730 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
111731 +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
111732 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
111733 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
111734 +set_fd_set_35249 set_fd_set 1 35249 NULL
111735 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
111736 +jbd2_journal_get_write_access_35263 jbd2_journal_get_write_access 0 35263 NULL
111737 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
111738 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
111739 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
111740 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
111741 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
111742 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3-0 35311 NULL nohasharray
111743 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
111744 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
111745 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
111746 +xfs_btree_check_lblock_35333 xfs_btree_check_lblock 0 35333 NULL
111747 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
111748 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
111749 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
111750 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
111751 +read_kmem_35372 read_kmem 3 35372 NULL
111752 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
111753 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
111754 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
111755 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
111756 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
111757 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
111758 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
111759 +async_setkey_35521 async_setkey 3 35521 NULL
111760 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
111761 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
111762 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
111763 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
111764 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
111765 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
111766 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
111767 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
111768 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
111769 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
111770 +kernel_readv_35617 kernel_readv 3 35617 NULL
111771 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
111772 +pci_request_regions_35635 pci_request_regions 0 35635 NULL
111773 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
111774 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
111775 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
111776 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
111777 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
111778 +md_super_write_35703 md_super_write 4 35703 NULL
111779 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
111780 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
111781 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
111782 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
111783 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
111784 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
111785 +fls64_35862 fls64 0 35862 NULL
111786 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
111787 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
111788 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
111789 +SyS_set_mempolicy_35909 SyS_set_mempolicy 3 35909 NULL
111790 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
111791 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
111792 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
111793 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
111794 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
111795 +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
111796 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL nohasharray
111797 +generic_ocp_read_35974 generic_ocp_read 3 35974 &ceph_buffer_new_35974
111798 +acl_alloc_35979 acl_alloc 1 35979 NULL
111799 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
111800 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
111801 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
111802 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
111803 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
111804 +account_shadowed_36048 account_shadowed 2 36048 NULL
111805 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
111806 +write_emulate_36065 write_emulate 2-4 36065 NULL
111807 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
111808 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
111809 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
111810 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
111811 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
111812 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
111813 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
111814 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
111815 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
111816 +twl_set_36154 twl_set 2 36154 NULL
111817 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
111818 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
111819 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
111820 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
111821 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
111822 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
111823 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
111824 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
111825 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
111826 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
111827 +scrub_stripe_36248 scrub_stripe 5-4 36248 NULL
111828 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
111829 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL nohasharray
111830 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 &usb_buffer_alloc_36276
111831 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
111832 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
111833 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
111834 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
111835 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
111836 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
111837 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
111838 +lc_create_36332 lc_create 4 36332 NULL
111839 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
111840 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
111841 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
111842 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
111843 +to_sector_36361 to_sector 0-1 36361 NULL
111844 +tunables_read_36385 tunables_read 3 36385 NULL
111845 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
111846 +sierra_write_36402 sierra_write 4 36402 NULL
111847 +qdsb_get_36409 qdsb_get 0 36409 NULL
111848 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
111849 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
111850 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
111851 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
111852 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
111853 +lock_and_cleanup_extent_if_need_36480 lock_and_cleanup_extent_if_need 0 36480 NULL
111854 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
111855 +ip6_append_data_36490 ip6_append_data 4 36490 NULL nohasharray
111856 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
111857 +cmd_loop_36491 cmd_loop 0 36491 NULL
111858 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
111859 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
111860 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
111861 +get_param_l_36518 get_param_l 0 36518 NULL
111862 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
111863 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
111864 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
111865 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
111866 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
111867 +__erst_read_36579 __erst_read 0 36579 NULL
111868 +put_cmsg_36589 put_cmsg 4 36589 NULL
111869 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
111870 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
111871 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
111872 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
111873 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
111874 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
111875 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
111876 +xillybus_read_36678 xillybus_read 3 36678 NULL
111877 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
111878 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
111879 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
111880 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
111881 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
111882 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
111883 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
111884 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
111885 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
111886 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
111887 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
111888 +cm_write_36858 cm_write 3 36858 NULL
111889 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
111890 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
111891 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
111892 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
111893 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
111894 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
111895 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
111896 +crypto_blkcipher_ivsize_36944 crypto_blkcipher_ivsize 0 36944 NULL
111897 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
111898 +xfs_btree_check_sptr_36984 xfs_btree_check_sptr 0 36984 NULL
111899 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
111900 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
111901 +setxattr_37006 setxattr 4 37006 NULL
111902 +ocfs2_dlm_unlock_37037 ocfs2_dlm_unlock 0 37037 NULL
111903 +command_file_read_37038 command_file_read 3 37038 NULL
111904 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
111905 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL nohasharray
111906 +qp_broker_create_37053 qp_broker_create 6-5 37053 &ieee80211_if_read_drop_unencrypted_37053
111907 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
111908 +parse_command_37079 parse_command 2 37079 NULL
111909 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
111910 +tun_get_user_37094 tun_get_user 5 37094 NULL
111911 +xlog_grant_head_check_37116 xlog_grant_head_check 0 37116 NULL
111912 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
111913 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
111914 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
111915 +msg_word_37164 msg_word 0 37164 NULL
111916 +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
111917 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
111918 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
111919 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
111920 +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 0-4 37212 &crypto_shash_descsize_37212
111921 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
111922 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
111923 +__do_replace_37227 __do_replace 5 37227 NULL
111924 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
111925 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
111926 +xfs_reclaim_inode_37257 xfs_reclaim_inode 0 37257 NULL
111927 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
111928 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
111929 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
111930 +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
111931 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
111932 +send_msg_37323 send_msg 4 37323 NULL
111933 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
111934 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
111935 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
111936 +xfs_iomap_write_allocate_37336 xfs_iomap_write_allocate 0 37336 NULL
111937 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
111938 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
111939 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
111940 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
111941 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
111942 +fru_alloc_37442 fru_alloc 1 37442 NULL
111943 +tcp_established_options_37450 tcp_established_options 0 37450 NULL nohasharray
111944 +tipc_send2port_37450 tipc_send2port 4 37450 &tcp_established_options_37450
111945 +xfs_btree_dec_cursor_37452 xfs_btree_dec_cursor 0 37452 NULL
111946 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
111947 +get_est_timing_37484 get_est_timing 0 37484 NULL
111948 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
111949 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
111950 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
111951 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
111952 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
111953 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
111954 +hdr_size_37536 hdr_size 0 37536 NULL
111955 +extent_map_end_37550 extent_map_end 0 37550 NULL
111956 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
111957 +fat_cont_expand_37552 fat_cont_expand 0 37552 NULL
111958 +ioat_chansts_37558 ioat_chansts 0 37558 NULL
111959 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
111960 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
111961 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
111962 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
111963 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
111964 +may_delete_37656 may_delete 0 37656 NULL
111965 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
111966 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
111967 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
111968 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
111969 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
111970 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
111971 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
111972 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
111973 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
111974 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
111975 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
111976 +xfs_read_agf_37749 xfs_read_agf 0 37749 NULL
111977 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
111978 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
111979 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
111980 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
111981 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
111982 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
111983 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
111984 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
111985 +jbd2_journal_get_undo_access_37837 jbd2_journal_get_undo_access 0 37837 NULL
111986 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
111987 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
111988 +set_registers_37883 set_registers 4 37883 NULL
111989 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
111990 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL nohasharray
111991 +_rtw_malloc_37928 _rtw_malloc 1 37928 &pkt_alloc_packet_data_37928
111992 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
111993 +write_file_bool_37957 write_file_bool 3 37957 NULL
111994 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
111995 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
111996 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
111997 +vfs_readv_38011 vfs_readv 3 38011 NULL
111998 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
111999 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
112000 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
112001 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
112002 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
112003 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
112004 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
112005 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
112006 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL nohasharray
112007 +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 &xfs_buf_readahead_map_38081
112008 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
112009 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
112010 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
112011 +ep0_read_38095 ep0_read 3 38095 NULL
112012 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 NULL nohasharray
112013 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 &sk_wmem_schedule_38096
112014 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
112015 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
112016 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
112017 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 0-4-3 38153 NULL
112018 +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
112019 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
112020 +cdev_add_38176 cdev_add 2-3 38176 NULL
112021 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
112022 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
112023 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL nohasharray
112024 +xfs_rtallocate_range_38223 xfs_rtallocate_range 0 38223 &osd_req_list_partition_collections_38223
112025 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
112026 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
112027 +xfs_qm_dqrepair_38262 xfs_qm_dqrepair 0 38262 NULL
112028 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
112029 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268
112030 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
112031 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
112032 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
112033 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
112034 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
112035 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
112036 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
112037 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
112038 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
112039 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
112040 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
112041 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
112042 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
112043 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
112044 +dev_names_read_38509 dev_names_read 3 38509 NULL
112045 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
112046 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
112047 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
112048 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
112049 +kuc_len_38557 kuc_len 0-1 38557 NULL
112050 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
112051 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
112052 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
112053 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
112054 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
112055 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
112056 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
112057 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
112058 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
112059 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
112060 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
112061 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
112062 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
112063 +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
112064 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
112065 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
112066 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
112067 +udf_readpages_38761 udf_readpages 4 38761 NULL
112068 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
112069 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
112070 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
112071 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
112072 +err_decode_38804 err_decode 2 38804 NULL
112073 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
112074 +direct_entry_38836 direct_entry 3 38836 NULL
112075 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
112076 +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
112077 +interfaces_38859 interfaces 2 38859 NULL
112078 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
112079 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
112080 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
112081 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
112082 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
112083 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
112084 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
112085 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
112086 +get_nodes_39012 get_nodes 3 39012 NULL
112087 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
112088 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
112089 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
112090 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
112091 +ReadHFC_39104 ReadHFC 0 39104 NULL
112092 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
112093 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
112094 +ea_foreach_39133 ea_foreach 0 39133 NULL
112095 +generic_permission_39150 generic_permission 0 39150 NULL
112096 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
112097 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
112098 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
112099 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
112100 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
112101 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
112102 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
112103 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
112104 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 NULL nohasharray
112105 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 &pwr_cont_miss_bcns_spread_read_39250
112106 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
112107 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
112108 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
112109 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
112110 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
112111 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
112112 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
112113 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
112114 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
112115 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
112116 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
112117 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
112118 +__send_to_port_39386 __send_to_port 3 39386 NULL
112119 +xfs_btree_dup_cursor_39394 xfs_btree_dup_cursor 0 39394 NULL
112120 +gfs2_internal_read_39413 gfs2_internal_read 0 39413 NULL
112121 +user_power_read_39414 user_power_read 3 39414 NULL
112122 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
112123 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
112124 +apei_resources_add_39470 apei_resources_add 0 39470 NULL
112125 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
112126 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
112127 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
112128 +int_proc_write_39542 int_proc_write 3 39542 NULL
112129 +pp_write_39554 pp_write 3 39554 NULL
112130 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
112131 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
112132 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
112133 +ext_depth_39607 ext_depth 0 39607 NULL
112134 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
112135 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
112136 +sdio_readb_39618 sdio_readb 0 39618 NULL
112137 +prepare_uptodate_page_39622 prepare_uptodate_page 0 39622 NULL
112138 +set_dev_class_39645 set_dev_class 4 39645 NULL
112139 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
112140 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
112141 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
112142 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
112143 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
112144 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
112145 +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
112146 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
112147 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
112148 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
112149 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
112150 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
112151 +pkt_add_39897 pkt_add 3 39897 NULL
112152 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
112153 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
112154 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
112155 +__mnt_want_write_file_39917 __mnt_want_write_file 0 39917 NULL
112156 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
112157 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
112158 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
112159 +__spi_async_39932 __spi_async 0 39932 NULL
112160 +__get_order_39935 __get_order 0 39935 NULL
112161 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
112162 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
112163 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
112164 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
112165 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
112166 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
112167 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
112168 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
112169 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
112170 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
112171 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
112172 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
112173 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
112174 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
112175 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
112176 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
112177 +xfs_rtbuf_get_40107 xfs_rtbuf_get 0 40107 NULL
112178 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
112179 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
112180 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
112181 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
112182 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
112183 +pt_write_40159 pt_write 3 40159 NULL
112184 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
112185 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
112186 +allocate_probes_40204 allocate_probes 1 40204 NULL
112187 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
112188 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
112189 +osst_read_40237 osst_read 3 40237 NULL
112190 +lpage_info_slot_40243 lpage_info_slot 3-1 40243 NULL
112191 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4 40248 NULL
112192 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
112193 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
112194 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
112195 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
112196 +SyS_bind_40303 SyS_bind 3 40303 NULL
112197 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
112198 +mmio_read_40348 mmio_read 4 40348 NULL
112199 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
112200 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
112201 +get_chars_40373 get_chars 3 40373 NULL
112202 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
112203 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
112204 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
112205 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
112206 +SyS_writev_40467 SyS_writev 3 40467 NULL
112207 +SyS_select_40473 SyS_select 1 40473 NULL
112208 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
112209 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
112210 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
112211 +xfs_iread_extents_40510 xfs_iread_extents 0 40510 NULL
112212 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
112213 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
112214 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
112215 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
112216 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
112217 +b1_get_byte_40597 b1_get_byte 0 40597 NULL
112218 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
112219 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
112220 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
112221 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
112222 +fops_read_40672 fops_read 3 40672 NULL
112223 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
112224 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
112225 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
112226 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
112227 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
112228 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
112229 +set_extent_bit_40719 set_extent_bit 0 40719 NULL
112230 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
112231 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
112232 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
112233 +card_send_command_40757 card_send_command 3 40757 NULL
112234 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
112235 +pg_write_40766 pg_write 3 40766 NULL
112236 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
112237 +show_list_40775 show_list 3-0 40775 NULL
112238 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
112239 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
112240 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
112241 +add_action_40811 add_action 4 40811 NULL
112242 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
112243 +SyS_mbind_40828 SyS_mbind 5 40828 NULL
112244 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
112245 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
112246 +read_file_queue_40895 read_file_queue 3 40895 NULL
112247 +waiters_read_40902 waiters_read 3 40902 NULL
112248 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
112249 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
112250 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
112251 +snd_vx_create_40948 snd_vx_create 4 40948 NULL nohasharray
112252 +sg_alloc_table_40948 sg_alloc_table 0 40948 &snd_vx_create_40948
112253 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
112254 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
112255 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
112256 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
112257 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
112258 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
112259 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
112260 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
112261 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
112262 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
112263 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
112264 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
112265 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
112266 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
112267 +dma_attach_41094 dma_attach 5-6 41094 NULL
112268 +provide_user_output_41105 provide_user_output 3 41105 NULL
112269 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
112270 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
112271 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
112272 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
112273 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
112274 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
112275 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
112276 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
112277 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
112278 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
112279 +erst_read_41260 erst_read 0 41260 NULL
112280 +alloc_context_41283 alloc_context 1 41283 NULL
112281 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
112282 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
112283 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
112284 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
112285 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
112286 +kmp_init_41373 kmp_init 2 41373 NULL
112287 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
112288 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
112289 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
112290 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
112291 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
112292 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
112293 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4-0 41442 NULL
112294 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
112295 +se_io_cb_41461 se_io_cb 3 41461 NULL
112296 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
112297 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
112298 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
112299 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
112300 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
112301 +SyS_get_mempolicy_41495 SyS_get_mempolicy 3 41495 NULL
112302 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
112303 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
112304 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
112305 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
112306 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
112307 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
112308 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
112309 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
112310 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
112311 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
112312 +vga_io_r_41609 vga_io_r 0 41609 NULL
112313 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
112314 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
112315 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
112316 +a2mp_send_41615 a2mp_send 4 41615 NULL
112317 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
112318 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
112319 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
112320 +get_std_timing_41654 get_std_timing 0 41654 NULL
112321 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
112322 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
112323 +apei_exec_for_each_entry_41717 apei_exec_for_each_entry 0 41717 NULL
112324 +fillonedir_41746 fillonedir 3 41746 NULL
112325 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
112326 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
112327 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
112328 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
112329 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
112330 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
112331 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
112332 +xfs_rtget_summary_41864 xfs_rtget_summary 0 41864 NULL
112333 +pci_map_single_41869 pci_map_single 0 41869 NULL
112334 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
112335 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
112336 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
112337 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
112338 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
112339 +read_gssp_41947 read_gssp 3 41947 NULL
112340 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
112341 +portnames_read_41958 portnames_read 3 41958 NULL
112342 +dst_mtu_41969 dst_mtu 0 41969 NULL
112343 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
112344 +xfs_qm_dqalloc_41985 xfs_qm_dqalloc 0 41985 NULL
112345 +pool_allocate_42012 pool_allocate 3 42012 NULL
112346 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
112347 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
112348 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
112349 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
112350 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
112351 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
112352 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
112353 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
112354 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
112355 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
112356 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
112357 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
112358 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
112359 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
112360 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
112361 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
112362 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
112363 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
112364 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
112365 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
112366 +xfs_rtfree_range_42244 xfs_rtfree_range 0 42244 NULL
112367 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
112368 +find_last_bit_42260 find_last_bit 0 42260 NULL
112369 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
112370 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
112371 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
112372 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
112373 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
112374 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
112375 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
112376 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
112377 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
112378 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
112379 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
112380 +tipc_send_42374 tipc_send 3 42374 NULL
112381 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
112382 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
112383 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
112384 +krng_get_random_42420 krng_get_random 3 42420 NULL
112385 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
112386 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
112387 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
112388 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
112389 +kuc_free_42455 kuc_free 2 42455 NULL
112390 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
112391 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
112392 +bypass_write_42498 bypass_write 3 42498 NULL
112393 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
112394 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
112395 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
112396 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
112397 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
112398 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
112399 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
112400 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
112401 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
112402 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
112403 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
112404 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
112405 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
112406 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
112407 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
112408 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
112409 +vb2_read_42703 vb2_read 3 42703 NULL
112410 +read_status_42722 read_status 0 42722 NULL
112411 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
112412 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
112413 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
112414 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
112415 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
112416 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
112417 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
112418 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
112419 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
112420 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
112421 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
112422 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
112423 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
112424 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
112425 +set_arg_42824 set_arg 3 42824 NULL
112426 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
112427 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
112428 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
112429 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
112430 +hd_end_request_42904 hd_end_request 2 42904 NULL
112431 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
112432 +xfs_bmapi_allocate_42938 xfs_bmapi_allocate 0 42938 NULL
112433 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
112434 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
112435 +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
112436 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
112437 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
112438 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
112439 +xfs_da_read_buf_43008 xfs_da_read_buf 0 43008 NULL
112440 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
112441 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
112442 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
112443 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
112444 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
112445 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
112446 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
112447 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
112448 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
112449 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
112450 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
112451 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
112452 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
112453 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
112454 +uio_write_43202 uio_write 3 43202 NULL
112455 +iso_callback_43208 iso_callback 3 43208 NULL
112456 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
112457 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
112458 +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
112459 +inode_init_always_43225 inode_init_always 0 43225 NULL
112460 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
112461 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
112462 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
112463 +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
112464 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 NULL nohasharray
112465 +evtchn_write_43278 evtchn_write 3 43278 &parport_pc_ecp_write_block_pio_43278
112466 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
112467 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
112468 +mmu_set_spte_43327 mmu_set_spte 6-7 43327 NULL
112469 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
112470 +xfs_log_regrant_43350 xfs_log_regrant 0 43350 NULL
112471 +gfs2_rgrp_bh_get_43375 gfs2_rgrp_bh_get 0 43375 NULL
112472 +xfs_btree_new_iroot_43392 xfs_btree_new_iroot 0 43392 NULL
112473 +xenfb_write_43412 xenfb_write 3 43412 NULL
112474 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
112475 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
112476 +cifs_writev_43437 cifs_writev 4 43437 NULL
112477 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
112478 +usb_string_43443 usb_string 0 43443 NULL nohasharray
112479 +usemap_size_43443 usemap_size 0-2-1 43443 &usb_string_43443
112480 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
112481 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
112482 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
112483 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
112484 +do_readlink_43518 do_readlink 2 43518 NULL
112485 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
112486 +read_events_43534 read_events 3 43534 NULL
112487 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
112488 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
112489 +request_resource_43548 request_resource 0 43548 NULL
112490 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
112491 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
112492 +proc_read_43614 proc_read 3 43614 NULL
112493 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
112494 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
112495 +random_write_43656 random_write 3 43656 NULL
112496 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
112497 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
112498 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
112499 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
112500 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
112501 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
112502 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
112503 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
112504 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
112505 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
112506 +xfs_alloc_lookup_eq_43775 xfs_alloc_lookup_eq 0 43775 NULL
112507 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
112508 +byte_pos_43787 byte_pos 0-2 43787 &ocfs2_xattr_get_value_outside_43787
112509 +xfs_trans_reserve_quota_bydquots_43797 xfs_trans_reserve_quota_bydquots 0 43797 NULL
112510 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
112511 +_xfs_filestream_update_ag_43824 _xfs_filestream_update_ag 0 43824 NULL
112512 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
112513 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
112514 +read_flush_43851 read_flush 3 43851 NULL
112515 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
112516 +SendString_43928 SendString 3 43928 NULL
112517 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
112518 +xfs_trans_dqresv_43960 xfs_trans_dqresv 0 43960 NULL
112519 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
112520 +nla_reserve_43984 nla_reserve 3 43984 NULL
112521 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
112522 +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
112523 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &scsi_command_size_43992 nohasharray
112524 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &kvm_read_guest_virt_43992
112525 +ulist_add_43994 ulist_add 0 43994 NULL
112526 +emit_flags_44006 emit_flags 4-3 44006 NULL
112527 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
112528 +fru_strlen_44046 fru_strlen 0 44046 NULL
112529 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
112530 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
112531 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL nohasharray
112532 +__vxge_hw_vpath_tim_configure_44093 __vxge_hw_vpath_tim_configure 2 44093 &pci_msix_vec_count_44093
112533 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
112534 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
112535 +file_remove_suid_44122 file_remove_suid 0 44122 NULL nohasharray
112536 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 &file_remove_suid_44122
112537 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
112538 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
112539 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
112540 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
112541 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
112542 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
112543 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
112544 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
112545 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
112546 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
112547 +apei_resources_sub_44252 apei_resources_sub 0 44252 NULL
112548 +device_create_file_44285 device_create_file 0 44285 NULL
112549 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
112550 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
112551 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
112552 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
112553 +rs_init_44327 rs_init 1 44327 NULL
112554 +radix_tree_maybe_preload_44346 radix_tree_maybe_preload 0 44346 NULL
112555 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
112556 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
112557 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
112558 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
112559 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
112560 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
112561 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
112562 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
112563 +xfs_mod_incore_sb_44439 xfs_mod_incore_sb 0 44439 NULL
112564 +write_file_debug_44476 write_file_debug 3 44476 NULL
112565 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
112566 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
112567 +bio_advance_44496 bio_advance 2 44496 NULL
112568 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
112569 +ac_register_board_44504 ac_register_board 3 44504 NULL
112570 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
112571 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
112572 +spidev_write_44510 spidev_write 3 44510 NULL
112573 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
112574 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
112575 +comm_write_44537 comm_write 3 44537 NULL
112576 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
112577 +btrfs_set_extent_delalloc_44587 btrfs_set_extent_delalloc 0 44587 NULL
112578 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
112579 +xfs_bmapi_delay_44630 xfs_bmapi_delay 0 44630 NULL
112580 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
112581 +mpi_resize_44674 mpi_resize 2 44674 NULL
112582 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
112583 +ts_read_44687 ts_read 3 44687 NULL
112584 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
112585 +xfer_to_user_44713 xfer_to_user 3 44713 NULL nohasharray
112586 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 &xfer_to_user_44713
112587 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
112588 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
112589 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
112590 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
112591 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
112592 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
112593 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
112594 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
112595 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
112596 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
112597 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
112598 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
112599 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
112600 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
112601 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
112602 +sisusb_write_44834 sisusb_write 3 44834 NULL
112603 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
112604 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
112605 +copydesc_user_44855 copydesc_user 3 44855 NULL
112606 +set_advertising_44870 set_advertising 4 44870 NULL
112607 +init_rs_44873 init_rs 1 44873 NULL
112608 +skb_availroom_44883 skb_availroom 0 44883 NULL
112609 +ocfs2_wait_for_mask_44893 ocfs2_wait_for_mask 0 44893 NULL
112610 +do_tty_write_44896 do_tty_write 5 44896 NULL
112611 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
112612 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
112613 +bytepos_delta_45017 bytepos_delta 0-2 45017 NULL
112614 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
112615 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
112616 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
112617 +sel_write_user_45060 sel_write_user 3 45060 NULL
112618 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
112619 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
112620 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
112621 +usbdev_read_45114 usbdev_read 3 45114 NULL
112622 +send_to_tty_45141 send_to_tty 3 45141 NULL
112623 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
112624 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
112625 +device_write_45156 device_write 3 45156 NULL nohasharray
112626 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3 45156 &device_write_45156
112627 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
112628 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
112629 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
112630 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
112631 +__radix_tree_preload_45197 __radix_tree_preload 0 45197 NULL
112632 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
112633 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
112634 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
112635 +event_enable_write_45238 event_enable_write 3 45238 NULL
112636 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
112637 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
112638 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
112639 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
112640 +xfs_alert_fsblock_zero_45304 xfs_alert_fsblock_zero 0 45304 NULL
112641 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
112642 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
112643 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
112644 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
112645 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
112646 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
112647 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
112648 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
112649 +__node_remap_45458 __node_remap 4 45458 NULL
112650 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
112651 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
112652 +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
112653 +xfs_btree_block_change_owner_45476 xfs_btree_block_change_owner 0 45476 NULL
112654 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
112655 +i40e_alloc_vfs_45511 i40e_alloc_vfs 2 45511 NULL
112656 +copy_macs_45534 copy_macs 4 45534 NULL
112657 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
112658 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
112659 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
112660 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
112661 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
112662 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
112663 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
112664 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
112665 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
112666 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
112667 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
112668 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
112669 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL nohasharray
112670 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 &unix_dgram_sendmsg_45699
112671 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
112672 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
112673 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
112674 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
112675 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
112676 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
112677 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
112678 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
112679 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
112680 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
112681 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
112682 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
112683 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
112684 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
112685 +insert_state_45848 insert_state 0 45848 NULL
112686 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
112687 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
112688 +isdn_write_45863 isdn_write 3 45863 NULL
112689 +tpm_config_in_45880 tpm_config_in 0 45880 NULL
112690 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
112691 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
112692 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
112693 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
112694 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
112695 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
112696 +alloc_mr_45935 alloc_mr 1 45935 NULL
112697 +copy_to_45969 copy_to 3 45969 NULL
112698 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
112699 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
112700 +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
112701 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
112702 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
112703 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
112704 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
112705 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
112706 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
112707 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
112708 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
112709 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL nohasharray
112710 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 &il3945_ucode_general_stats_read_46111
112711 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
112712 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
112713 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
112714 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
112715 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
112716 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
112717 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
112718 +fq_resize_46195 fq_resize 2 46195 NULL
112719 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
112720 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
112721 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
112722 +dsp_write_46218 dsp_write 2 46218 NULL
112723 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
112724 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
112725 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
112726 +ReadReg_46277 ReadReg 0 46277 NULL
112727 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
112728 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
112729 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
112730 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
112731 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
112732 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
112733 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
112734 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
112735 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
112736 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
112737 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
112738 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
112739 +filldir64_46469 filldir64 3 46469 NULL
112740 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
112741 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
112742 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
112743 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
112744 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
112745 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
112746 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
112747 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
112748 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
112749 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
112750 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
112751 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
112752 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
112753 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
112754 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
112755 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
112756 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
112757 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
112758 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
112759 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
112760 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
112761 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
112762 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
112763 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
112764 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
112765 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
112766 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
112767 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
112768 +readreg_46845 readreg 0 46845 NULL
112769 +spi_async_46857 spi_async 0 46857 NULL
112770 +SyS_move_pages_46863 SyS_move_pages 2 46863 NULL nohasharray
112771 +vsnprintf_46863 vsnprintf 0 46863 &SyS_move_pages_46863
112772 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
112773 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
112774 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
112775 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
112776 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
112777 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
112778 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
112779 +fb_write_46924 fb_write 3 46924 NULL
112780 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
112781 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL nohasharray
112782 +ntfs_truncate_46953 ntfs_truncate 0 46953 &qla4xxx_post_aen_work_46953
112783 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
112784 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
112785 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
112786 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
112787 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
112788 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
112789 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
112790 +fs_path_len_47060 fs_path_len 0 47060 NULL
112791 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
112792 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
112793 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
112794 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
112795 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
112796 +mousedev_read_47123 mousedev_read 3 47123 NULL
112797 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
112798 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
112799 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
112800 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
112801 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
112802 +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
112803 +xfs_btree_get_buf_block_47197 xfs_btree_get_buf_block 0 47197 NULL
112804 +options_write_47243 options_write 3 47243 NULL
112805 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
112806 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
112807 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
112808 +vsnprintf_47291 vsnprintf 0 47291 NULL
112809 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
112810 +xfs_trans_reserve_quota_nblks_47313 xfs_trans_reserve_quota_nblks 0 47313 NULL
112811 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
112812 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
112813 +gfs2_replay_read_block_47357 gfs2_replay_read_block 0 47357 NULL
112814 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
112815 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
112816 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
112817 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
112818 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL nohasharray
112819 +nv_rd32_47390 nv_rd32 0 47390 &trace_options_core_read_47390
112820 +nametbl_list_47391 nametbl_list 2 47391 NULL
112821 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
112822 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
112823 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
112824 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
112825 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
112826 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
112827 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
112828 +newpart_47485 newpart 6-4 47485 NULL
112829 +core_sys_select_47494 core_sys_select 1 47494 NULL
112830 +unlink_simple_47506 unlink_simple 3 47506 NULL
112831 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
112832 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
112833 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
112834 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
112835 +einj_check_trigger_header_47534 einj_check_trigger_header 0 47534 NULL
112836 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
112837 +read_ldt_47570 read_ldt 2 47570 NULL
112838 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
112839 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
112840 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
112841 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
112842 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
112843 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
112844 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
112845 +get_size_47644 get_size 1-2 47644 NULL
112846 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
112847 +save_microcode_47717 save_microcode 3 47717 NULL
112848 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
112849 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
112850 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
112851 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
112852 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
112853 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
112854 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
112855 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
112856 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
112857 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
112858 +lov_packmd_47810 lov_packmd 0 47810 NULL
112859 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
112860 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
112861 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
112862 +vhci_read_47878 vhci_read 3 47878 NULL
112863 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
112864 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
112865 +comedi_write_47926 comedi_write 3 47926 NULL
112866 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
112867 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
112868 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
112869 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
112870 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
112871 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
112872 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
112873 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
112874 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
112875 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
112876 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
112877 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
112878 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
112879 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
112880 +disc_write_48070 disc_write 3 48070 NULL
112881 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
112882 +xfs_read_agi_48100 xfs_read_agi 0 48100 NULL
112883 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
112884 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
112885 +set_discoverable_48141 set_discoverable 4 48141 NULL
112886 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
112887 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
112888 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
112889 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
112890 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
112891 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
112892 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
112893 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
112894 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
112895 +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
112896 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
112897 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
112898 +read_file_recv_48232 read_file_recv 3 48232 NULL
112899 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
112900 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
112901 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
112902 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
112903 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
112904 +trace_options_write_48275 trace_options_write 3 48275 NULL
112905 +send_set_info_48288 send_set_info 7 48288 NULL
112906 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
112907 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
112908 +hash_setkey_48310 hash_setkey 3 48310 NULL
112909 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
112910 +skb_add_data_48363 skb_add_data 3 48363 NULL
112911 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
112912 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
112913 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
112914 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
112915 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
112916 +print_filtered_48442 print_filtered 2-0 48442 NULL
112917 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
112918 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
112919 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
112920 +send_control_msg_48498 send_control_msg 6 48498 NULL
112921 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
112922 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
112923 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
112924 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
112925 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
112926 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
112927 +llog_data_len_48607 llog_data_len 1 48607 NULL
112928 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
112929 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
112930 +mtd_read_48655 mtd_read 0 48655 NULL
112931 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
112932 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
112933 +security_inode_setattr_48689 security_inode_setattr 0 48689 NULL
112934 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
112935 +altera_drscan_48698 altera_drscan 2 48698 NULL
112936 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
112937 +recv_msg_48709 recv_msg 4 48709 NULL
112938 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
112939 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
112940 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
112941 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
112942 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
112943 +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
112944 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
112945 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
112946 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
112947 +azx_get_position_48841 azx_get_position 0 48841 NULL
112948 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
112949 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
112950 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
112951 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
112952 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
112953 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
112954 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
112955 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
112956 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
112957 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
112958 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
112959 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
112960 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
112961 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
112962 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
112963 +xfs_trans_commit_48982 xfs_trans_commit 0 48982 NULL
112964 +gfs2_dir_add_48987 gfs2_dir_add 0 48987 NULL
112965 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
112966 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
112967 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
112968 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
112969 +transient_status_49027 transient_status 4 49027 NULL
112970 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
112971 +iwl_mvm_power_legacy_dbgfs_read_49038 iwl_mvm_power_legacy_dbgfs_read 4 49038 NULL
112972 +scsi_register_49094 scsi_register 2 49094 NULL
112973 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
112974 +gfs2_diradd_alloc_required_49105 gfs2_diradd_alloc_required 0 49105 NULL
112975 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
112976 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
112977 +pt_read_49136 pt_read 3 49136 NULL
112978 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
112979 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
112980 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
112981 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
112982 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
112983 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
112984 +print_queue_49191 print_queue 4-0 49191 NULL
112985 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
112986 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
112987 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
112988 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
112989 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
112990 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
112991 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
112992 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
112993 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
112994 +uio_read_49300 uio_read 3 49300 NULL
112995 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
112996 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
112997 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
112998 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
112999 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
113000 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
113001 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
113002 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
113003 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
113004 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
113005 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
113006 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
113007 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
113008 +xfs_iformat_local_49472 xfs_iformat_local 4-0 49472 NULL
113009 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
113010 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
113011 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
113012 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
113013 +smk_write_access_49561 smk_write_access 3 49561 NULL
113014 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
113015 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
113016 +readfifo_49583 readfifo 1 49583 NULL
113017 +gfs2_quota_lock_49587 gfs2_quota_lock 0 49587 NULL
113018 +evm_inode_setattr_49594 evm_inode_setattr 0 49594 NULL
113019 +tap_write_49595 tap_write 3 49595 NULL
113020 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
113021 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
113022 +heap_init_49617 heap_init 2 49617 NULL
113023 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
113024 +port_fops_read_49626 port_fops_read 3 49626 NULL
113025 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
113026 +xfs_ialloc_get_rec_49648 xfs_ialloc_get_rec 0 49648 NULL
113027 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 4-3 49683 NULL
113028 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
113029 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
113030 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
113031 +write_pool_49718 write_pool 3 49718 NULL
113032 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
113033 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
113034 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
113035 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
113036 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
113037 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
113038 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
113039 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
113040 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
113041 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
113042 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
113043 +add_uuid_49831 add_uuid 4 49831 NULL
113044 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
113045 +twl4030_write_49846 twl4030_write 2 49846 NULL
113046 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
113047 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
113048 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
113049 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
113050 +osc_brw_49896 osc_brw 4 49896 NULL
113051 +config_ep_by_speed_49939 config_ep_by_speed 0 49939 NULL
113052 +xfs_ialloc_ag_alloc_49960 xfs_ialloc_ag_alloc 0 49960 NULL
113053 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
113054 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
113055 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
113056 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
113057 +xfs_ialloc_inode_init_50015 xfs_ialloc_inode_init 0 50015 NULL
113058 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
113059 +isdn_read_50021 isdn_read 3 50021 NULL
113060 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
113061 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
113062 +ioread8_50049 ioread8 0 50049 NULL
113063 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
113064 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
113065 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
113066 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
113067 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
113068 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
113069 +read_file_slot_50111 read_file_slot 3 50111 NULL
113070 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
113071 +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
113072 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
113073 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
113074 +xfs_bwrite_50154 xfs_bwrite 0 50154 NULL
113075 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
113076 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
113077 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
113078 +odev_update_50169 odev_update 2 50169 NULL
113079 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
113080 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
113081 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
113082 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
113083 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
113084 +mthca_buddy_init_50206 mthca_buddy_init 2 50206 NULL
113085 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
113086 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
113087 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
113088 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
113089 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
113090 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
113091 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
113092 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
113093 +do_launder_page_50329 do_launder_page 0 50329 NULL
113094 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
113095 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
113096 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
113097 +tpm_read_50344 tpm_read 3 50344 NULL
113098 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
113099 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
113100 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
113101 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
113102 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
113103 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
113104 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
113105 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
113106 +xfs_alloc_update_counters_50441 xfs_alloc_update_counters 0 50441 NULL
113107 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
113108 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
113109 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
113110 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
113111 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
113112 +xfs_iformat_extents_50486 xfs_iformat_extents 0 50486 NULL
113113 +gfs2_block_map_50492 gfs2_block_map 0 50492 NULL
113114 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
113115 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
113116 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
113117 +bh_get_50543 bh_get 0 50543 NULL
113118 +gfs2_meta_inode_buffer_50544 gfs2_meta_inode_buffer 0 50544 NULL
113119 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
113120 +fat_readpages_50582 fat_readpages 4 50582 NULL
113121 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
113122 +xillybus_write_50605 xillybus_write 3 50605 NULL
113123 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
113124 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
113125 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
113126 +gfs2_unstuff_dinode_50644 gfs2_unstuff_dinode 0 50644 NULL
113127 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
113128 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
113129 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
113130 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
113131 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
113132 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
113133 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
113134 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
113135 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
113136 +bio_alloc_map_data_50782 bio_alloc_map_data 2 50782 NULL
113137 +tpm_write_50798 tpm_write 3 50798 NULL
113138 +tun_do_read_50800 tun_do_read 4 50800 NULL
113139 +write_flush_50803 write_flush 3 50803 NULL
113140 +dvb_play_50814 dvb_play 3 50814 NULL
113141 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
113142 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
113143 +SetArea_50835 SetArea 4 50835 NULL
113144 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
113145 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
113146 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
113147 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
113148 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
113149 +xfs_alloc_get_freelist_50906 xfs_alloc_get_freelist 0 50906 NULL
113150 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
113151 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
113152 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
113153 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
113154 +show_device_status_50947 show_device_status 0 50947 NULL
113155 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
113156 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
113157 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
113158 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
113159 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
113160 +timeout_write_50991 timeout_write 3 50991 NULL
113161 +proc_write_51003 proc_write 3 51003 NULL
113162 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
113163 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
113164 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
113165 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
113166 +dump_midi_51040 dump_midi 3 51040 NULL
113167 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
113168 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
113169 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
113170 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
113171 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
113172 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
113173 +ti_recv_51110 ti_recv 3 51110 NULL
113174 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
113175 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
113176 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
113177 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
113178 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
113179 +drm_property_create_51239 drm_property_create 4 51239 NULL
113180 +__mxt_read_reg_51249 __mxt_read_reg 0 51249 NULL
113181 +st_read_51251 st_read 3 51251 NULL
113182 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
113183 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
113184 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
113185 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
113186 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
113187 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
113188 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
113189 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
113190 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
113191 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
113192 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
113193 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
113194 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
113195 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
113196 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
113197 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
113198 +xfs_mod_incore_sb_unlocked_51439 xfs_mod_incore_sb_unlocked 0 51439 NULL
113199 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
113200 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
113201 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
113202 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
113203 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
113204 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
113205 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
113206 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
113207 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
113208 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
113209 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
113210 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
113211 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
113212 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
113213 +xfs_iformat_btree_51651 xfs_iformat_btree 0 51651 NULL
113214 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
113215 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
113216 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
113217 +sel_write_access_51704 sel_write_access 3 51704 NULL
113218 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
113219 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
113220 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
113221 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
113222 +cm4040_read_51732 cm4040_read 3 51732 NULL
113223 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
113224 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
113225 +if_write_51756 if_write 3 51756 NULL
113226 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
113227 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
113228 +ioread32_51847 ioread32 0 51847 NULL nohasharray
113229 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
113230 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
113231 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
113232 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
113233 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
113234 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
113235 +user_read_51881 user_read 3 51881 NULL
113236 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
113237 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
113238 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
113239 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
113240 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
113241 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
113242 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
113243 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
113244 +__blkdev_get_51972 __blkdev_get 0 51972 NULL
113245 +get_zone_51981 get_zone 0-1 51981 NULL
113246 +cifs_strict_writev_51984 cifs_strict_writev 4 51984 NULL
113247 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
113248 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
113249 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
113250 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
113251 +rdmalt_52022 rdmalt 0 52022 NULL
113252 +override_release_52032 override_release 2 52032 NULL
113253 +end_port_52042 end_port 0 52042 NULL
113254 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
113255 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
113256 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
113257 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
113258 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
113259 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
113260 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
113261 +ulist_add_merge_52096 ulist_add_merge 0 52096 NULL
113262 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
113263 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
113264 +retry_count_read_52129 retry_count_read 3 52129 NULL
113265 +xfs_btree_change_owner_52137 xfs_btree_change_owner 0 52137 NULL
113266 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
113267 +sub_alloc_52140 sub_alloc 0 52140 NULL
113268 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
113269 +htable_size_52148 htable_size 0-1 52148 NULL
113270 +gfs2_rs_alloc_52152 gfs2_rs_alloc 0 52152 NULL
113271 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
113272 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
113273 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
113274 +print_prefix_52176 print_prefix 0 52176 NULL
113275 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
113276 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
113277 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
113278 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL nohasharray
113279 +xfs_iomap_eof_align_last_fsb_52243 xfs_iomap_eof_align_last_fsb 0 52243 &fuse_request_alloc_52243
113280 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
113281 +shrink_slab_52261 shrink_slab 2 52261 NULL
113282 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
113283 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
113284 +read_file_reset_52310 read_file_reset 3 52310 NULL
113285 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
113286 +hwflags_read_52318 hwflags_read 3 52318 NULL
113287 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
113288 +hur_len_52339 hur_len 0 52339 NULL
113289 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL nohasharray
113290 +cap_inode_killpriv_52362 cap_inode_killpriv 0 52362 &bytes_to_frames_52362
113291 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
113292 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
113293 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
113294 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
113295 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
113296 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
113297 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
113298 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
113299 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
113300 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
113301 +delay_status_52431 delay_status 5 52431 NULL
113302 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
113303 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
113304 +acpi_nvs_for_each_region_52448 acpi_nvs_for_each_region 0 52448 NULL
113305 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
113306 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
113307 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
113308 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
113309 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
113310 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
113311 +xfs_alloc_get_rec_52502 xfs_alloc_get_rec 0 52502 NULL
113312 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
113313 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
113314 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
113315 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
113316 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
113317 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
113318 +ntfs_prepare_pages_for_non_resident_write_52556 ntfs_prepare_pages_for_non_resident_write 0 52556 NULL
113319 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
113320 +kernfs_setattr_52583 kernfs_setattr 0 52583 NULL
113321 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
113322 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
113323 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
113324 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
113325 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
113326 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
113327 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
113328 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
113329 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
113330 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
113331 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
113332 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
113333 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
113334 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
113335 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
113336 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
113337 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
113338 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
113339 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
113340 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
113341 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
113342 +twlreg_write_52880 twlreg_write 3 52880 NULL
113343 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
113344 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
113345 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
113346 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
113347 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
113348 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
113349 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
113350 +send_packet_52960 send_packet 4 52960 NULL
113351 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
113352 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
113353 +num_node_state_52989 num_node_state 0 52989 NULL
113354 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
113355 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
113356 +xfs_rtfree_extent_53024 xfs_rtfree_extent 0 53024 NULL
113357 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
113358 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
113359 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
113360 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
113361 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
113362 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
113363 +verity_status_53120 verity_status 5 53120 NULL
113364 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
113365 +inode_newsize_ok_53140 inode_newsize_ok 0 53140 NULL nohasharray
113366 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 &inode_newsize_ok_53140
113367 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
113368 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
113369 +find_good_lh_53183 find_good_lh 0 53183 NULL
113370 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
113371 +xfs_btree_updkey_53195 xfs_btree_updkey 0 53195 NULL
113372 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
113373 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
113374 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5-0 53258 NULL
113375 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
113376 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
113377 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
113378 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
113379 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
113380 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
113381 +read_6120_creg32_53363 read_6120_creg32 0 53363 NULL
113382 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
113383 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
113384 +xfs_imap_53389 xfs_imap 0 53389 NULL
113385 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
113386 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
113387 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
113388 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
113389 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
113390 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
113391 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
113392 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
113393 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
113394 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
113395 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
113396 +check_acl_53512 check_acl 0 53512 NULL
113397 +ll_xattr_cache_update_53515 ll_xattr_cache_update 4 53515 NULL
113398 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
113399 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
113400 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
113401 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
113402 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
113403 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
113404 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
113405 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
113406 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
113407 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
113408 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
113409 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
113410 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
113411 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
113412 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
113413 +wdm_write_53735 wdm_write 3 53735 NULL
113414 +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 NULL nohasharray
113415 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 &amdtp_out_stream_get_max_payload_53755
113416 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
113417 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
113418 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
113419 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
113420 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
113421 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
113422 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
113423 +setup_data_read_53822 setup_data_read 3 53822 NULL
113424 +pms_read_53873 pms_read 3 53873 NULL
113425 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
113426 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
113427 +posix_acl_chmod_53904 posix_acl_chmod 0 53904 NULL
113428 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
113429 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
113430 +ocfs2_make_clusters_writable_53938 ocfs2_make_clusters_writable 0 53938 NULL
113431 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
113432 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
113433 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
113434 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
113435 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
113436 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
113437 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
113438 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
113439 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
113440 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
113441 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
113442 +_malloc_54077 _malloc 1 54077 NULL
113443 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
113444 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
113445 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2-0 54103 &altera_set_ir_pre_54103
113446 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
113447 +strn_len_54122 strn_len 0 54122 NULL
113448 +isku_receive_54130 isku_receive 4 54130 NULL
113449 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
113450 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
113451 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
113452 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
113453 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
113454 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
113455 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
113456 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
113457 +reada_add_block_54247 reada_add_block 2 54247 NULL
113458 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
113459 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
113460 +audio_write_54261 audio_write 4 54261 NULL nohasharray
113461 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
113462 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
113463 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
113464 +tipc_multicast_54285 tipc_multicast 4 54285 NULL
113465 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
113466 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
113467 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
113468 +sprintf_54306 sprintf 0 54306 NULL
113469 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
113470 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
113471 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
113472 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
113473 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
113474 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
113475 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
113476 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
113477 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
113478 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 3-0 54387 NULL
113479 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
113480 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
113481 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
113482 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
113483 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
113484 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
113485 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
113486 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
113487 +viacam_read_54526 viacam_read 3 54526 NULL
113488 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
113489 +setsockopt_54539 setsockopt 5 54539 NULL
113490 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
113491 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
113492 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
113493 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
113494 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
113495 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
113496 +port_fops_write_54627 port_fops_write 3 54627 NULL
113497 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
113498 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
113499 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
113500 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
113501 +bus_add_device_54665 bus_add_device 0 54665 NULL
113502 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
113503 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
113504 +evm_read_key_54674 evm_read_key 3 54674 NULL
113505 +tipc_link_send_sections_fast_54689 tipc_link_send_sections_fast 3 54689 NULL
113506 +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
113507 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
113508 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
113509 +kzalloc_54740 kzalloc 1 54740 NULL
113510 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
113511 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
113512 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
113513 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
113514 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
113515 +xfs_rtallocate_extent_block_54791 xfs_rtallocate_extent_block 0 54791 NULL
113516 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
113517 +nfsd_write_54809 nfsd_write 6 54809 NULL
113518 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
113519 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
113520 +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
113521 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
113522 +generic_perform_write_54832 generic_perform_write 3-0 54832 NULL
113523 +write_rio_54837 write_rio 3 54837 NULL
113524 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
113525 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
113526 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
113527 +printer_read_54851 printer_read 3 54851 NULL
113528 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
113529 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
113530 +xfs_alloc_read_agfl_54879 xfs_alloc_read_agfl 0 54879 NULL
113531 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
113532 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
113533 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
113534 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
113535 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
113536 +add_port_54941 add_port 2 54941 NULL
113537 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 3-0 54949 NULL
113538 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
113539 +c4_add_card_54968 c4_add_card 3 54968 NULL
113540 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
113541 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
113542 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
113543 +dgap_do_bios_load_55025 dgap_do_bios_load 3 55025 NULL
113544 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
113545 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
113546 +read_dma_55086 read_dma 3 55086 NULL
113547 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
113548 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
113549 +filldir_55137 filldir 3 55137 NULL
113550 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
113551 +xfs_check_agi_freecount_55149 xfs_check_agi_freecount 0 55149 NULL nohasharray
113552 +npages_to_npools_55149 npages_to_npools 0-1 55149 &xfs_check_agi_freecount_55149
113553 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
113554 +xfs_icsb_modify_counters_55156 xfs_icsb_modify_counters 0 55156 NULL
113555 +gfs2_ri_update_55185 gfs2_ri_update 0 55185 NULL
113556 +mtd_get_fact_prot_info_55186 mtd_get_fact_prot_info 0 55186 NULL
113557 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
113558 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
113559 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
113560 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
113561 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
113562 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
113563 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
113564 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
113565 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
113566 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
113567 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
113568 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
113569 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
113570 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
113571 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
113572 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL
113573 +__vxge_hw_vpath_initialize_55328 __vxge_hw_vpath_initialize 2 55328 NULL
113574 +vme_user_read_55338 vme_user_read 3 55338 NULL
113575 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
113576 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
113577 +tipc_send2name_55373 tipc_send2name 5 55373 NULL
113578 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
113579 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
113580 +sysfs_chmod_file_55408 sysfs_chmod_file 0 55408 NULL
113581 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
113582 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
113583 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
113584 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
113585 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
113586 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
113587 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
113588 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
113589 +xfs_btree_split_55515 xfs_btree_split 0 55515 NULL
113590 +ea_get_55522 ea_get 3-0 55522 NULL
113591 +buffer_size_55534 buffer_size 0 55534 NULL
113592 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
113593 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
113594 +dgap_do_config_load_55548 dgap_do_config_load 2 55548 NULL
113595 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
113596 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
113597 +add_partition_55588 add_partition 2 55588 NULL
113598 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
113599 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
113600 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
113601 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
113602 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
113603 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL nohasharray
113604 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 &pktgen_if_write_55628
113605 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
113606 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
113607 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
113608 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
113609 +get_info_55681 get_info 3 55681 NULL
113610 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
113611 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
113612 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
113613 +ocfs2_lock_refcount_tree_55719 ocfs2_lock_refcount_tree 0 55719 NULL
113614 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
113615 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
113616 +set_local_name_55757 set_local_name 4 55757 NULL
113617 +strlen_55778 strlen 0 55778 NULL
113618 +set_spte_55783 set_spte 4-5 55783 NULL
113619 +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
113620 +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
113621 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
113622 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
113623 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
113624 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
113625 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
113626 +hsc_write_55875 hsc_write 3 55875 NULL
113627 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
113628 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
113629 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
113630 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
113631 +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
113632 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
113633 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
113634 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
113635 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
113636 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
113637 +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
113638 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
113639 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
113640 +usb_ocp_write_56047 usb_ocp_write 4 56047 NULL
113641 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
113642 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
113643 +add_sysfs_param_56108 add_sysfs_param 0 56108 NULL
113644 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
113645 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
113646 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
113647 +__i2c_transfer_56162 __i2c_transfer 0 56162 NULL
113648 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
113649 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
113650 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
113651 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
113652 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
113653 +fd_copyin_56247 fd_copyin 3 56247 NULL
113654 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
113655 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
113656 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
113657 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
113658 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
113659 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
113660 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
113661 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
113662 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
113663 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
113664 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
113665 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
113666 +qd_get_56365 qd_get 0 56365 NULL
113667 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
113668 +dev_read_56369 dev_read 3 56369 NULL
113669 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
113670 +write_gssp_56404 write_gssp 3 56404 NULL
113671 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
113672 +do_get_write_access_56410 do_get_write_access 0 56410 NULL
113673 +store_msg_56417 store_msg 3 56417 NULL
113674 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
113675 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
113676 +fl_create_56435 fl_create 5 56435 NULL
113677 +gnttab_map_56439 gnttab_map 2 56439 NULL
113678 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
113679 +set_connectable_56458 set_connectable 4 56458 NULL
113680 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
113681 +putused_user_56467 putused_user 3 56467 NULL
113682 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
113683 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
113684 +calc_linear_pos_56472 calc_linear_pos 0-3 56472 NULL
113685 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
113686 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
113687 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
113688 +init_map_ip_56508 init_map_ip 5 56508 NULL
113689 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3-0-2 56512 NULL
113690 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
113691 +ip_options_get_56538 ip_options_get 4 56538 NULL
113692 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
113693 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
113694 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
113695 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
113696 +event_filter_write_56609 event_filter_write 3 56609 NULL
113697 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
113698 +edac_device_create_block_56619 edac_device_create_block 0 56619 NULL
113699 +gather_array_56641 gather_array 3 56641 NULL
113700 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
113701 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
113702 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
113703 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
113704 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
113705 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
113706 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
113707 +xfs_btree_decrement_56718 xfs_btree_decrement 0 56718 NULL
113708 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
113709 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
113710 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
113711 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
113712 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
113713 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
113714 +do_syslog_56807 do_syslog 3 56807 NULL
113715 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
113716 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
113717 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
113718 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
113719 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
113720 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
113721 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL
113722 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
113723 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
113724 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
113725 +xfs_alloc_ag_vextent_56943 xfs_alloc_ag_vextent 0 56943 NULL
113726 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
113727 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
113728 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
113729 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
113730 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
113731 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
113732 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
113733 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
113734 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
113735 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
113736 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
113737 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
113738 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
113739 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
113740 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
113741 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
113742 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
113743 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 NULL nohasharray
113744 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136 nohasharray
113745 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 &nl80211_send_deauth_57136
113746 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
113747 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
113748 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
113749 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
113750 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
113751 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
113752 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
113753 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
113754 +flush_space_57241 flush_space 0 57241 NULL
113755 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
113756 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
113757 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
113758 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
113759 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
113760 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
113761 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
113762 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
113763 +xfs_iread_57313 xfs_iread 0 57313 NULL nohasharray
113764 +write_file_regval_57313 write_file_regval 3 57313 &xfs_iread_57313
113765 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
113766 +usblp_read_57342 usblp_read 3 57342 NULL
113767 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
113768 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
113769 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
113770 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
113771 +read_file_blob_57406 read_file_blob 3 57406 NULL
113772 +enclosure_register_57412 enclosure_register 3 57412 NULL
113773 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
113774 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
113775 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
113776 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
113777 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
113778 +tipc_port_reject_sections_57478 tipc_port_reject_sections 4 57478 NULL
113779 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
113780 +skb_headlen_57501 skb_headlen 0 57501 NULL
113781 +copy_in_user_57502 copy_in_user 3 57502 NULL
113782 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL nohasharray
113783 +gfs2_quota_hold_57505 gfs2_quota_hold 0 57505 &ckhdid_printf_57505
113784 +init_tag_map_57515 init_tag_map 3 57515 NULL
113785 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL nohasharray
113786 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 &il_dbgfs_force_reset_read_57517
113787 +cmm_read_57520 cmm_read 3 57520 NULL
113788 +inode_permission_57531 inode_permission 0 57531 NULL
113789 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
113790 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
113791 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
113792 +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
113793 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
113794 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
113795 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
113796 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
113797 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
113798 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
113799 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
113800 +mem_read_57631 mem_read 3 57631 NULL
113801 +xfs_alloc_ag_vextent_near_57653 xfs_alloc_ag_vextent_near 0 57653 NULL
113802 +r3964_write_57662 r3964_write 4 57662 NULL
113803 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
113804 +__lgwrite_57669 __lgwrite 4 57669 NULL
113805 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
113806 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
113807 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
113808 +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
113809 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL nohasharray
113810 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 &pppol2tp_recvmsg_57742
113811 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
113812 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
113813 +apei_exec_collect_resources_57788 apei_exec_collect_resources 0 57788 NULL
113814 +ld2_57794 ld2 0 57794 NULL
113815 +ivtv_read_57796 ivtv_read 3 57796 NULL
113816 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
113817 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
113818 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
113819 +xfs_rtpick_extent_57843 xfs_rtpick_extent 0 57843 NULL nohasharray
113820 +flash_read_57843 flash_read 3 57843 &xfs_rtpick_extent_57843
113821 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
113822 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
113823 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
113824 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
113825 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
113826 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
113827 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
113828 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
113829 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
113830 +xfs_inode_item_format_convert_57937 xfs_inode_item_format_convert 0 57937 NULL
113831 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
113832 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
113833 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
113834 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
113835 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
113836 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
113837 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
113838 +mce_async_out_58056 mce_async_out 3 58056 NULL
113839 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
113840 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
113841 +cm4040_write_58079 cm4040_write 3 58079 NULL
113842 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
113843 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
113844 +rd_build_prot_space_58137 rd_build_prot_space 2 58137 NULL
113845 +xfs_bmap_add_extent_delay_real_58151 xfs_bmap_add_extent_delay_real 0 58151 NULL
113846 +xfs_btree_update_58167 xfs_btree_update 0 58167 NULL
113847 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
113848 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
113849 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
113850 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
113851 +read_file_debug_58256 read_file_debug 3 58256 NULL
113852 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
113853 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
113854 +profile_load_58267 profile_load 3 58267 NULL
113855 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
113856 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
113857 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
113858 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
113859 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
113860 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
113861 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
113862 +SyS_migrate_pages_58348 SyS_migrate_pages 2 58348 NULL
113863 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
113864 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
113865 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
113866 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
113867 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
113868 +xfs_btree_get_rec_58410 xfs_btree_get_rec 0 58410 NULL
113869 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
113870 +capabilities_read_58457 capabilities_read 3 58457 NULL
113871 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
113872 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
113873 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
113874 +nv_rd08_58472 nv_rd08 0 58472 NULL
113875 +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
113876 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
113877 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
113878 +btrfs_cont_expand_58498 btrfs_cont_expand 0-2-3 58498 NULL
113879 +gfs2_dir_get_new_buffer_58509 gfs2_dir_get_new_buffer 0 58509 NULL
113880 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
113881 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
113882 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
113883 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
113884 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
113885 +xip_file_read_58592 xip_file_read 3 58592 NULL
113886 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
113887 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
113888 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
113889 +filemap_fdatawrite_range_58630 filemap_fdatawrite_range 0 58630 NULL
113890 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
113891 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
113892 +find_zero_58685 find_zero 0-1 58685 NULL
113893 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
113894 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
113895 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
113896 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
113897 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
113898 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
113899 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
113900 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
113901 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
113902 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
113903 +ep_read_58813 ep_read 3 58813 NULL
113904 +command_write_58841 command_write 3 58841 NULL
113905 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
113906 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
113907 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
113908 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
113909 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
113910 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
113911 +xfs_bmap_read_extents_58936 xfs_bmap_read_extents 0 58936 NULL
113912 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
113913 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
113914 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
113915 +__mem_cgroup_try_charge_58976 __mem_cgroup_try_charge 0 58976 NULL
113916 +init_list_set_59005 init_list_set 3 59005 NULL
113917 +ep_write_59008 ep_write 3 59008 NULL
113918 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
113919 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
113920 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
113921 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
113922 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
113923 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
113924 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
113925 +scsi_io_completion_59122 scsi_io_completion 2 59122 NULL nohasharray
113926 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 &scsi_io_completion_59122
113927 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
113928 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 NULL nohasharray
113929 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 &print_devstats_dot11RTSSuccessCount_59145
113930 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
113931 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
113932 +ksize_59176 ksize 0 59176 NULL
113933 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
113934 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
113935 +xfs_ialloc_next_rec_59193 xfs_ialloc_next_rec 0 59193 NULL
113936 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
113937 +dt3155_read_59226 dt3155_read 3 59226 NULL
113938 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
113939 +nla_len_59258 nla_len 0 59258 NULL
113940 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
113941 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
113942 +xfs_iformat_fork_59312 xfs_iformat_fork 0 59312 NULL
113943 +fd_copyout_59323 fd_copyout 3 59323 NULL
113944 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
113945 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
113946 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL nohasharray
113947 +xfs_alloc_lookup_le_59346 xfs_alloc_lookup_le 0 59346 &xfs_attrmulti_attr_set_59346
113948 +__map_request_59350 __map_request 0 59350 NULL
113949 +gfs2_quota_lock_check_59353 gfs2_quota_lock_check 0 59353 NULL
113950 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
113951 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
113952 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
113953 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
113954 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
113955 +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
113956 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
113957 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
113958 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
113959 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
113960 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
113961 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
113962 +tunables_write_59563 tunables_write 3 59563 NULL
113963 +bio_split_59564 bio_split 2 59564 NULL
113964 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
113965 +write_pbl_59583 write_pbl 4 59583 NULL
113966 +memdup_user_59590 memdup_user 2 59590 NULL
113967 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
113968 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
113969 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
113970 +mtrr_write_59622 mtrr_write 3 59622 NULL
113971 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
113972 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
113973 +file_update_time_59647 file_update_time 0 59647 NULL
113974 +hidraw_read_59650 hidraw_read 3 59650 NULL
113975 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
113976 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
113977 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
113978 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
113979 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
113980 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
113981 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
113982 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
113983 +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
113984 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
113985 +strnlen_59746 strnlen 0 59746 NULL
113986 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
113987 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL nohasharray
113988 +cap_inode_need_killpriv_59766 cap_inode_need_killpriv 0 59766 &long_retry_limit_read_59766
113989 +venus_remove_59781 venus_remove 4 59781 NULL
113990 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
113991 +ipw_write_59807 ipw_write 3 59807 NULL
113992 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
113993 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
113994 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
113995 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
113996 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
113997 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
113998 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
113999 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
114000 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
114001 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
114002 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
114003 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
114004 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
114005 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
114006 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
114007 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
114008 +copy_items_60009 copy_items 7 60009 NULL
114009 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
114010 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
114011 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
114012 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
114013 +xfs_imap_to_bp_60034 xfs_imap_to_bp 0 60034 NULL
114014 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
114015 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
114016 +vcs_size_60050 vcs_size 0 60050 NULL
114017 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
114018 +compat_writev_60063 compat_writev 3 60063 NULL
114019 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
114020 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
114021 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
114022 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
114023 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
114024 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
114025 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
114026 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
114027 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
114028 +init_state_60165 init_state 2 60165 NULL
114029 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
114030 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
114031 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
114032 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
114033 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
114034 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
114035 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
114036 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
114037 +printer_write_60276 printer_write 3 60276 NULL
114038 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
114039 +getDataLength_60301 getDataLength 0 60301 NULL
114040 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
114041 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
114042 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
114043 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
114044 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
114045 +driver_names_read_60399 driver_names_read 3 60399 NULL
114046 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
114047 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
114048 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
114049 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
114050 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
114051 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
114052 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
114053 +xfs_btree_make_block_unfull_60511 xfs_btree_make_block_unfull 0 60511 NULL
114054 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
114055 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
114056 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
114057 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
114058 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
114059 +inode_change_ok_60614 inode_change_ok 0 60614 NULL
114060 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
114061 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
114062 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
114063 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
114064 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
114065 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
114066 +vga_rcrt_60731 vga_rcrt 0 60731 NULL
114067 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
114068 +raid_status_60755 raid_status 5 60755 NULL
114069 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
114070 +opticon_write_60775 opticon_write 4 60775 NULL
114071 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
114072 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
114073 +gfs2_bmap_alloc_60822 gfs2_bmap_alloc 0 60822 NULL
114074 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
114075 +__clone_and_map_data_bio_60861 __clone_and_map_data_bio 4-3 60861 NULL
114076 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
114077 +generic_writepages_60871 generic_writepages 0 60871 NULL
114078 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
114079 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
114080 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
114081 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
114082 +scrub_chunk_60926 scrub_chunk 5 60926 NULL
114083 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
114084 +xfs_rtallocate_extent_size_60939 xfs_rtallocate_extent_size 0 60939 NULL
114085 +pti_char_write_60960 pti_char_write 3 60960 NULL
114086 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
114087 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
114088 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
114089 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
114090 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
114091 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
114092 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
114093 +symtab_init_61050 symtab_init 2 61050 NULL
114094 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
114095 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
114096 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
114097 +xfs_dabuf_map_61093 xfs_dabuf_map 0 61093 NULL
114098 +get_derived_key_61100 get_derived_key 4 61100 NULL
114099 +mem_cgroup_cache_charge_61101 mem_cgroup_cache_charge 0 61101 NULL
114100 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
114101 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
114102 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
114103 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
114104 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
114105 +pair_device_61175 pair_device 4 61175 NULL nohasharray
114106 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
114107 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
114108 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
114109 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
114110 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
114111 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
114112 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
114113 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270
114114 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
114115 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
114116 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
114117 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
114118 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
114119 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
114120 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
114121 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
114122 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
114123 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
114124 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
114125 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
114126 +system_enable_write_61396 system_enable_write 3 61396 NULL
114127 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
114128 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
114129 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
114130 +ocfs2_get_refcount_rec_61514 ocfs2_get_refcount_rec 0 61514 NULL
114131 +erst_errno_61526 erst_errno 0 61526 NULL
114132 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
114133 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
114134 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
114135 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
114136 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
114137 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
114138 +seq_open_private_61589 seq_open_private 3 61589 NULL
114139 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
114140 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
114141 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
114142 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
114143 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
114144 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
114145 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
114146 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
114147 +resize_stripes_61650 resize_stripes 2 61650 NULL
114148 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
114149 +insert_one_name_61668 insert_one_name 7 61668 NULL
114150 +lock_loop_61681 lock_loop 1 61681 NULL
114151 +filter_read_61692 filter_read 3 61692 NULL
114152 +iov_length_61716 iov_length 0 61716 NULL
114153 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
114154 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
114155 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
114156 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
114157 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
114158 +gfs2_meta_wait_61773 gfs2_meta_wait 0 61773 NULL
114159 +xfs_file_dio_aio_write_61801 xfs_file_dio_aio_write 0 61801 NULL
114160 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
114161 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
114162 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
114163 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
114164 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
114165 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
114166 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
114167 +get_fw_name_61874 get_fw_name 3 61874 NULL
114168 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
114169 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
114170 +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
114171 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
114172 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
114173 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
114174 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
114175 +edac_device_create_instance_61940 edac_device_create_instance 0 61940 NULL
114176 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
114177 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
114178 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
114179 +fix_read_error_61965 fix_read_error 4 61965 NULL
114180 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
114181 +cow_file_range_61979 cow_file_range 3 61979 NULL
114182 +set_extent_delalloc_61982 set_extent_delalloc 0 61982 NULL
114183 +dequeue_event_62000 dequeue_event 3 62000 NULL
114184 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
114185 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
114186 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
114187 +SYSC_select_62024 SYSC_select 1 62024 NULL
114188 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
114189 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
114190 +do_pselect_62061 do_pselect 1 62061 NULL
114191 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
114192 +_xfs_log_force_lsn_62083 _xfs_log_force_lsn 0 62083 NULL
114193 +fat_setattr_62084 fat_setattr 0 62084 NULL
114194 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
114195 +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
114196 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
114197 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
114198 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
114199 +kobject_add_varg_62133 kobject_add_varg 0 62133 NULL nohasharray
114200 +qib_diag_write_62133 qib_diag_write 3 62133 &kobject_add_varg_62133
114201 +device_add_attrs_62135 device_add_attrs 0 62135 NULL nohasharray
114202 +ql_status_62135 ql_status 5 62135 &device_add_attrs_62135
114203 +video_usercopy_62151 video_usercopy 2 62151 NULL
114204 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
114205 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
114206 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
114207 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
114208 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
114209 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
114210 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
114211 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
114212 +subtract_dirty_62242 subtract_dirty 2-3 62242 NULL
114213 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
114214 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
114215 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
114216 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
114217 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
114218 +subseq_list_62332 subseq_list 3-0 62332 NULL
114219 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
114220 +flash_write_62354 flash_write 3 62354 NULL
114221 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
114222 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
114223 +altera_irscan_62396 altera_irscan 2 62396 NULL
114224 +set_ssp_62411 set_ssp 4 62411 NULL
114225 +udf_expand_file_adinicb_62470 udf_expand_file_adinicb 0 62470 NULL
114226 +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
114227 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
114228 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
114229 +debugfs_read_62535 debugfs_read 3 62535 NULL
114230 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
114231 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
114232 +link_send_sections_long_62557 link_send_sections_long 3 62557 NULL
114233 +compute_bitstructs_62570 compute_bitstructs 0 62570 NULL
114234 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
114235 +get_subdir_62581 get_subdir 3 62581 NULL
114236 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
114237 +tipc_port_recv_sections_62609 tipc_port_recv_sections 3 62609 NULL
114238 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
114239 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
114240 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
114241 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
114242 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
114243 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
114244 +rdm_62719 rdm 0 62719 NULL
114245 +add_to_page_cache_62724 add_to_page_cache 0 62724 NULL
114246 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
114247 +key_replays_read_62746 key_replays_read 3 62746 NULL
114248 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
114249 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
114250 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
114251 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
114252 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
114253 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
114254 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
114255 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
114256 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
114257 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
114258 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
114259 +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
114260 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
114261 +xfs_rtmodify_range_62877 xfs_rtmodify_range 0 62877 NULL
114262 +aoechr_write_62883 aoechr_write 3 62883 NULL
114263 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
114264 +ocfs2_validate_gd_parent_62905 ocfs2_validate_gd_parent 0 62905 NULL
114265 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
114266 +getdqbuf_62908 getdqbuf 1 62908 NULL
114267 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
114268 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
114269 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL nohasharray
114270 +xfs_trans_reserve_63026 xfs_trans_reserve 0 63026 &kstrtoull_from_user_63026
114271 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
114272 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
114273 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
114274 +unlink1_63059 unlink1 3 63059 NULL
114275 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
114276 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
114277 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
114278 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
114279 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
114280 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
114281 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
114282 +vme_master_read_63221 vme_master_read 0 63221 NULL
114283 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
114284 +ptp_read_63251 ptp_read 4 63251 NULL
114285 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
114286 +raid5_resize_63306 raid5_resize 2 63306 NULL
114287 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
114288 +proc_info_read_63344 proc_info_read 3 63344 NULL
114289 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
114290 +idmouse_read_63374 idmouse_read 3 63374 NULL
114291 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
114292 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
114293 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
114294 +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
114295 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
114296 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
114297 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
114298 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
114299 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
114300 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
114301 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
114302 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL nohasharray
114303 +generic_cont_expand_simple_63534 generic_cont_expand_simple 0 63534 &ubi_more_leb_change_data_63534
114304 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
114305 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
114306 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
114307 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
114308 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
114309 +write_debug_level_63613 write_debug_level 3 63613 NULL
114310 +__spi_validate_63618 __spi_validate 0 63618 NULL
114311 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
114312 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
114313 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
114314 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
114315 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
114316 +vbi_read_63673 vbi_read 3 63673 NULL
114317 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
114318 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
114319 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
114320 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
114321 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
114322 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
114323 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
114324 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
114325 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
114326 +sel_write_load_63830 sel_write_load 3 63830 NULL
114327 +ll_readlink_63836 ll_readlink 3 63836 NULL
114328 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
114329 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
114330 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
114331 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
114332 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
114333 +__team_options_register_63941 __team_options_register 3 63941 NULL
114334 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
114335 +xfs_iflush_63956 xfs_iflush 0 63956 NULL
114336 +set_bredr_63975 set_bredr 4 63975 NULL
114337 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
114338 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
114339 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
114340 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
114341 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
114342 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
114343 +__generic_file_aio_write_64049 __generic_file_aio_write 0 64049 NULL
114344 +get_u8_64076 get_u8 0 64076 NULL
114345 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
114346 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
114347 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
114348 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
114349 +gfs2_inplace_reserve_64096 gfs2_inplace_reserve 0 64096 NULL nohasharray
114350 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 &gfs2_inplace_reserve_64096
114351 +to_bytes_64103 to_bytes 0-1 64103 NULL
114352 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
114353 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
114354 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
114355 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
114356 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
114357 +init_bch_64130 init_bch 1-2 64130 NULL
114358 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
114359 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
114360 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
114361 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
114362 +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
114363 +read_pulse_64227 read_pulse 0-3 64227 NULL
114364 +ea_len_64229 ea_len 0 64229 NULL
114365 +xfs_rtmodify_summary_64265 xfs_rtmodify_summary 0 64265 NULL
114366 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
114367 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
114368 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
114369 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3-0 64288 NULL nohasharray
114370 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
114371 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
114372 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
114373 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
114374 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
114375 +ts_write_64336 ts_write 3 64336 NULL
114376 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
114377 +bnx2x_vfop_mcast_cmd_64354 bnx2x_vfop_mcast_cmd 5 64354 NULL
114378 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
114379 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
114380 +reg_create_64372 reg_create 5 64372 NULL
114381 +ilo_write_64378 ilo_write 3 64378 NULL
114382 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
114383 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
114384 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
114385 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
114386 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
114387 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
114388 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
114389 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
114390 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
114391 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
114392 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
114393 +single_open_size_64483 single_open_size 4 64483 NULL
114394 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL nohasharray
114395 +xfs_inode_ag_walk_64493 xfs_inode_ag_walk 0 64493 &p54_parse_rssical_64493
114396 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
114397 +remove_uuid_64505 remove_uuid 4 64505 NULL
114398 +crypto_blkcipher_alignmask_64520 crypto_blkcipher_alignmask 0 64520 NULL
114399 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
114400 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
114401 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
114402 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
114403 +SyS_bind_64544 SyS_bind 3 64544 NULL
114404 +rbd_obj_read_sync_64554 rbd_obj_read_sync 4-3 64554 NULL
114405 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
114406 +__spi_sync_64561 __spi_sync 0 64561 NULL nohasharray
114407 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 &__spi_sync_64561
114408 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
114409 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
114410 +do_erase_64574 do_erase 4 64574 NULL
114411 +fanotify_write_64623 fanotify_write 3 64623 NULL
114412 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
114413 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
114414 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
114415 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
114416 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
114417 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
114418 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
114419 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
114420 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
114421 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
114422 +AscGetChipVersion_64737 AscGetChipVersion 0 64737 NULL
114423 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
114424 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
114425 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
114426 +message_for_md_64777 message_for_md 5 64777 NULL
114427 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
114428 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
114429 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
114430 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
114431 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
114432 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
114433 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
114434 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
114435 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
114436 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
114437 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
114438 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
114439 +xfs_imap_lookup_64906 xfs_imap_lookup 0 64906 NULL
114440 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
114441 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
114442 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
114443 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
114444 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
114445 +insert_dent_65034 insert_dent 7 65034 NULL
114446 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
114447 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
114448 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
114449 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
114450 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
114451 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
114452 +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
114453 +__xfs_bmapi_allocate_65142 __xfs_bmapi_allocate 0 65142 NULL
114454 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
114455 +print_endpoint_stat_65232 print_endpoint_stat 3-4-0 65232 NULL
114456 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
114457 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
114458 +xfs_btree_check_ptr_65281 xfs_btree_check_ptr 0 65281 NULL
114459 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
114460 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
114461 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
114462 +get_var_len_65304 get_var_len 0 65304 NULL
114463 +unpack_array_65318 unpack_array 0 65318 NULL
114464 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
114465 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
114466 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
114467 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
114468 +SyS_writev_65372 SyS_writev 3 65372 NULL
114469 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
114470 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
114471 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
114472 +usb_ep_enable_65405 usb_ep_enable 0 65405 NULL
114473 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
114474 +device_add_groups_65423 device_add_groups 0 65423 NULL
114475 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
114476 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
114477 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
114478 +clear_user_65470 clear_user 2 65470 NULL
114479 +xfs_alloc_lookup_ge_65481 xfs_alloc_lookup_ge 0 65481 NULL
114480 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
114481 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
114482 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
114483 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
114484 diff --git a/tools/gcc/size_overflow_hash_aux.data b/tools/gcc/size_overflow_hash_aux.data
114485 new file mode 100644
114486 index 0000000..560cd7b
114487 --- /dev/null
114488 +++ b/tools/gcc/size_overflow_hash_aux.data
114489 @@ -0,0 +1,92 @@
114490 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
114491 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
114492 +mappedread_2627 mappedread 2 2627 NULL
114493 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
114494 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
114495 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
114496 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
114497 +dmu_write_6048 dmu_write 4-3 6048 NULL
114498 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
114499 +update_pages_6225 update_pages 2-3 6225 NULL
114500 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
114501 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
114502 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
114503 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
114504 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
114505 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
114506 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
114507 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
114508 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
114509 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
114510 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
114511 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
114512 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
114513 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
114514 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
114515 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
114516 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
114517 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
114518 +uiocopy_18680 uiocopy 2 18680 NULL
114519 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
114520 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
114521 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
114522 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
114523 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
114524 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
114525 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
114526 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
114527 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
114528 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
114529 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
114530 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
114531 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
114532 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
114533 +splat_write_30943 splat_write 3 30943 NULL
114534 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
114535 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
114536 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
114537 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
114538 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
114539 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
114540 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
114541 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
114542 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
114543 +copyinstr_36980 copyinstr 3 36980 NULL
114544 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
114545 +splat_read_38116 splat_read 3 38116 NULL
114546 +sa_setup_38756 sa_setup 4 38756 NULL
114547 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
114548 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
114549 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
114550 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
114551 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
114552 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
114553 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
114554 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
114555 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
114556 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
114557 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
114558 +kcopy_write_43683 kcopy_write 3 43683 NULL
114559 +uiomove_44355 uiomove 2 44355 NULL
114560 +dmu_read_44418 dmu_read 4-3 44418 NULL
114561 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
114562 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
114563 +copyin_45945 copyin 3 45945 NULL
114564 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
114565 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
114566 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
114567 +spa_history_write_49650 spa_history_write 3 49650 NULL
114568 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
114569 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
114570 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
114571 +copyout_51409 copyout 3 51409 NULL
114572 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
114573 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
114574 +get_nvlist_56685 get_nvlist 2 56685 NULL
114575 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
114576 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
114577 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
114578 +zpios_write_61823 zpios_write 3 61823 NULL
114579 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
114580 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
114581 +zpios_read_64734 zpios_read 3 64734 NULL
114582 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
114583 new file mode 100644
114584 index 0000000..ed21b21
114585 --- /dev/null
114586 +++ b/tools/gcc/size_overflow_plugin.c
114587 @@ -0,0 +1,4166 @@
114588 +/*
114589 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114590 + * Licensed under the GPL v2, or (at your option) v3
114591 + *
114592 + * Homepage:
114593 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114594 + *
114595 + * Documentation:
114596 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114597 + *
114598 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114599 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114600 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114601 + *
114602 + * Usage:
114603 + * $ # for 4.5/4.6/C based 4.7
114604 + * $ gcc -I`gcc -print-file-name=plugin`/include -I`gcc -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -std=gnu99 -ggdb -o size_overflow_plugin.so size_overflow_plugin.c
114605 + * $ # for C++ based 4.7/4.8+
114606 + * $ g++ -I`g++ -print-file-name=plugin`/include -I`g++ -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -std=gnu++98 -fno-rtti -ggdb -o size_overflow_plugin.so size_overflow_plugin.c
114607 + *
114608 + * $ gcc -fplugin=./size_overflow_plugin.so test.c -O2
114609 + */
114610 +
114611 +#include "gcc-common.h"
114612 +
114613 +int plugin_is_GPL_compatible;
114614 +
114615 +static struct plugin_info size_overflow_plugin_info = {
114616 + .version = "20140407",
114617 + .help = "no-size-overflow\tturn off size overflow checking\n",
114618 +};
114619 +
114620 +#define BEFORE_STMT true
114621 +#define AFTER_STMT false
114622 +#define CREATE_NEW_VAR NULL_TREE
114623 +#define CODES_LIMIT 32
114624 +#define MAX_PARAM 31
114625 +#define VEC_LEN 128
114626 +#define RET_CHECK NULL_TREE
114627 +#define CANNOT_FIND_ARG 32
114628 +#define WRONG_NODE 32
114629 +#define NOT_INTENTIONAL_ASM NULL
114630 +#define MIN_CHECK true
114631 +#define MAX_CHECK false
114632 +
114633 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
114634 +#define YES_ASM_STR "# size_overflow MARK_YES "
114635 +#define OK_ASM_STR "# size_overflow "
114636 +
114637 +struct size_overflow_hash {
114638 + const struct size_overflow_hash * const next;
114639 + const char * const name;
114640 + const unsigned int param;
114641 +};
114642 +
114643 +#include "size_overflow_hash.h"
114644 +#include "size_overflow_hash_aux.h"
114645 +
114646 +enum mark {
114647 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
114648 +};
114649 +
114650 +static unsigned int call_count;
114651 +
114652 +enum stmt_flags {
114653 + MY_STMT, NO_CAST_CHECK, VISITED_STMT, NO_FLAGS
114654 +};
114655 +
114656 +struct visited {
114657 + struct visited *next;
114658 + const_tree fndecl;
114659 + unsigned int num;
114660 +};
114661 +
114662 +struct next_cgraph_node {
114663 + struct next_cgraph_node *next;
114664 + struct cgraph_node *current_function;
114665 + tree callee_fndecl;
114666 + unsigned int num;
114667 +};
114668 +
114669 +struct interesting_node {
114670 + struct interesting_node *next;
114671 + gimple first_stmt;
114672 + const_tree fndecl;
114673 + tree node;
114674 +#if BUILDING_GCC_VERSION <= 4007
114675 + VEC(tree, gc) *last_nodes;
114676 +#else
114677 + vec<tree, va_gc> *last_nodes;
114678 +#endif
114679 + unsigned int num;
114680 + enum mark intentional_attr_decl;
114681 + enum mark intentional_attr_cur_fndecl;
114682 + gimple intentional_mark_from_gimple;
114683 +};
114684 +
114685 +static tree report_size_overflow_decl;
114686 +
114687 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs);
114688 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
114689 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
114690 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
114691 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
114692 +
114693 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
114694 +static tree get_size_overflow_type(gimple stmt, const_tree node);
114695 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
114696 +
114697 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
114698 +{
114699 + unsigned int arg_count;
114700 + enum tree_code code = TREE_CODE(*node);
114701 +
114702 + switch (code) {
114703 + case FUNCTION_DECL:
114704 + arg_count = type_num_arguments(TREE_TYPE(*node));
114705 + break;
114706 + case FUNCTION_TYPE:
114707 + case METHOD_TYPE:
114708 + arg_count = type_num_arguments(*node);
114709 + break;
114710 + default:
114711 + *no_add_attrs = true;
114712 + error("%s: %qE attribute only applies to functions", __func__, name);
114713 + return NULL_TREE;
114714 + }
114715 +
114716 + for (; args; args = TREE_CHAIN(args)) {
114717 + tree position = TREE_VALUE(args);
114718 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
114719 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
114720 + *no_add_attrs = true;
114721 + }
114722 + }
114723 + return NULL_TREE;
114724 +}
114725 +
114726 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
114727 +{
114728 + unsigned int arg_count;
114729 + enum tree_code code = TREE_CODE(*node);
114730 +
114731 + switch (code) {
114732 + case FUNCTION_DECL:
114733 + arg_count = type_num_arguments(TREE_TYPE(*node));
114734 + break;
114735 + case FUNCTION_TYPE:
114736 + case METHOD_TYPE:
114737 + arg_count = type_num_arguments(*node);
114738 + break;
114739 + case FIELD_DECL:
114740 + return NULL_TREE;
114741 + default:
114742 + *no_add_attrs = true;
114743 + error("%qE attribute only applies to functions", name);
114744 + return NULL_TREE;
114745 + }
114746 +
114747 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
114748 + return NULL_TREE;
114749 +
114750 + for (; args; args = TREE_CHAIN(args)) {
114751 + tree position = TREE_VALUE(args);
114752 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
114753 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
114754 + *no_add_attrs = true;
114755 + }
114756 + }
114757 + return NULL_TREE;
114758 +}
114759 +
114760 +static struct attribute_spec size_overflow_attr = {
114761 + .name = "size_overflow",
114762 + .min_length = 1,
114763 + .max_length = -1,
114764 + .decl_required = true,
114765 + .type_required = false,
114766 + .function_type_required = false,
114767 + .handler = handle_size_overflow_attribute,
114768 +#if BUILDING_GCC_VERSION >= 4007
114769 + .affects_type_identity = false
114770 +#endif
114771 +};
114772 +
114773 +static struct attribute_spec intentional_overflow_attr = {
114774 + .name = "intentional_overflow",
114775 + .min_length = 1,
114776 + .max_length = -1,
114777 + .decl_required = true,
114778 + .type_required = false,
114779 + .function_type_required = false,
114780 + .handler = handle_intentional_overflow_attribute,
114781 +#if BUILDING_GCC_VERSION >= 4007
114782 + .affects_type_identity = false
114783 +#endif
114784 +};
114785 +
114786 +static void register_attributes(void __unused *event_data, void __unused *data)
114787 +{
114788 + register_attribute(&size_overflow_attr);
114789 + register_attribute(&intentional_overflow_attr);
114790 +}
114791 +
114792 +static enum stmt_flags get_stmt_flag(gimple stmt)
114793 +{
114794 + bool bit_1, bit_2;
114795 +
114796 + bit_1 = gimple_plf(stmt, GF_PLF_1);
114797 + bit_2 = gimple_plf(stmt, GF_PLF_2);
114798 +
114799 + if (!bit_1 && !bit_2)
114800 + return NO_FLAGS;
114801 + if (bit_1 && bit_2)
114802 + return MY_STMT;
114803 + if (!bit_1 && bit_2)
114804 + return VISITED_STMT;
114805 + return NO_CAST_CHECK;
114806 +}
114807 +
114808 +static void set_stmt_flag(gimple stmt, enum stmt_flags new_flag)
114809 +{
114810 + bool bit_1, bit_2;
114811 +
114812 + switch (new_flag) {
114813 + case NO_FLAGS:
114814 + bit_1 = bit_2 = false;
114815 + break;
114816 + case MY_STMT:
114817 + bit_1 = bit_2 = true;
114818 + break;
114819 + case VISITED_STMT:
114820 + bit_1 = false;
114821 + bit_2 = true;
114822 + break;
114823 + case NO_CAST_CHECK:
114824 + bit_1 = true;
114825 + bit_2 = false;
114826 + break;
114827 + default:
114828 + gcc_unreachable();
114829 + }
114830 +
114831 + gimple_set_plf(stmt, GF_PLF_1, bit_1);
114832 + gimple_set_plf(stmt, GF_PLF_2, bit_2);
114833 +}
114834 +
114835 +static bool is_bool(const_tree node)
114836 +{
114837 + const_tree type;
114838 +
114839 + if (node == NULL_TREE)
114840 + return false;
114841 +
114842 + type = TREE_TYPE(node);
114843 + if (!INTEGRAL_TYPE_P(type))
114844 + return false;
114845 + if (TREE_CODE(type) == BOOLEAN_TYPE)
114846 + return true;
114847 + if (TYPE_PRECISION(type) == 1)
114848 + return true;
114849 + return false;
114850 +}
114851 +
114852 +static bool skip_types(const_tree var)
114853 +{
114854 + tree type;
114855 + enum tree_code code;
114856 +
114857 + if (is_gimple_constant(var))
114858 + return true;
114859 +
114860 + switch (TREE_CODE(var)) {
114861 + case ADDR_EXPR:
114862 +#if BUILDING_GCC_VERSION >= 4006
114863 + case MEM_REF:
114864 +#endif
114865 + case ARRAY_REF:
114866 + case BIT_FIELD_REF:
114867 + case INDIRECT_REF:
114868 + case TARGET_MEM_REF:
114869 + case COMPONENT_REF:
114870 + case VAR_DECL:
114871 + case VIEW_CONVERT_EXPR:
114872 + return true;
114873 + default:
114874 + break;
114875 + }
114876 +
114877 + code = TREE_CODE(var);
114878 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
114879 +
114880 + type = TREE_TYPE(var);
114881 + switch (TREE_CODE(type)) {
114882 + case INTEGER_TYPE:
114883 + case ENUMERAL_TYPE:
114884 + return false;
114885 + case BOOLEAN_TYPE:
114886 + return is_bool(var);
114887 + default:
114888 + return true;
114889 + }
114890 +}
114891 +
114892 +static inline gimple get_def_stmt(const_tree node)
114893 +{
114894 + gcc_assert(node != NULL_TREE);
114895 +
114896 + if (skip_types(node))
114897 + return NULL;
114898 +
114899 + if (TREE_CODE(node) != SSA_NAME)
114900 + return NULL;
114901 + return SSA_NAME_DEF_STMT(node);
114902 +}
114903 +
114904 +static unsigned char get_tree_code(const_tree type)
114905 +{
114906 + switch (TREE_CODE(type)) {
114907 + case ARRAY_TYPE:
114908 + return 0;
114909 + case BOOLEAN_TYPE:
114910 + return 1;
114911 + case ENUMERAL_TYPE:
114912 + return 2;
114913 + case FUNCTION_TYPE:
114914 + return 3;
114915 + case INTEGER_TYPE:
114916 + return 4;
114917 + case POINTER_TYPE:
114918 + return 5;
114919 + case RECORD_TYPE:
114920 + return 6;
114921 + case UNION_TYPE:
114922 + return 7;
114923 + case VOID_TYPE:
114924 + return 8;
114925 + case REAL_TYPE:
114926 + return 9;
114927 + case VECTOR_TYPE:
114928 + return 10;
114929 + case REFERENCE_TYPE:
114930 + return 11;
114931 + case OFFSET_TYPE:
114932 + return 12;
114933 + case COMPLEX_TYPE:
114934 + return 13;
114935 + default:
114936 + debug_tree((tree)type);
114937 + gcc_unreachable();
114938 + }
114939 +}
114940 +
114941 +struct function_hash {
114942 + size_t tree_codes_len;
114943 + unsigned char tree_codes[CODES_LIMIT];
114944 + const_tree fndecl;
114945 + unsigned int hash;
114946 +};
114947 +
114948 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
114949 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
114950 +{
114951 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
114952 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
114953 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
114954 +
114955 + unsigned int m = 0x57559429;
114956 + unsigned int n = 0x5052acdb;
114957 + const unsigned int *key4 = (const unsigned int *)key;
114958 + unsigned int h = len;
114959 + unsigned int k = len + seed + n;
114960 + unsigned long long p;
114961 +
114962 + while (len >= 8) {
114963 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
114964 + len -= 8;
114965 + }
114966 + if (len >= 4) {
114967 + cwmixb(key4[0]) key4 += 1;
114968 + len -= 4;
114969 + }
114970 + if (len)
114971 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
114972 + cwmixb(h ^ (k + n));
114973 + return k ^ h;
114974 +
114975 +#undef cwfold
114976 +#undef cwmixa
114977 +#undef cwmixb
114978 +}
114979 +
114980 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
114981 +{
114982 + unsigned int fn, codes, seed = 0;
114983 +
114984 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
114985 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
114986 +
114987 + fn_hash_data->hash = fn ^ codes;
114988 +}
114989 +
114990 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
114991 +{
114992 + gcc_assert(type != NULL_TREE);
114993 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
114994 +
114995 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
114996 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
114997 + fn_hash_data->tree_codes_len++;
114998 + type = TREE_TYPE(type);
114999 + }
115000 +}
115001 +
115002 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
115003 +{
115004 + const_tree result;
115005 +
115006 + gcc_assert(node != NULL_TREE);
115007 +
115008 + if (DECL_P(node)) {
115009 + result = DECL_RESULT(node);
115010 + if (result != NULL_TREE)
115011 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
115012 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
115013 + }
115014 +
115015 + gcc_assert(TYPE_P(node));
115016 +
115017 + if (TREE_CODE(node) == FUNCTION_TYPE)
115018 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
115019 +
115020 + return set_node_codes(node, fn_hash_data);
115021 +}
115022 +
115023 +static void set_function_codes(struct function_hash *fn_hash_data)
115024 +{
115025 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
115026 + enum tree_code code = TREE_CODE(type);
115027 +
115028 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
115029 +
115030 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
115031 +
115032 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
115033 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
115034 +}
115035 +
115036 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
115037 +{
115038 + while (entry) {
115039 + if (!strcmp(entry->name, func_name))
115040 + return entry;
115041 + entry = entry->next;
115042 + }
115043 + return NULL;
115044 +}
115045 +
115046 +static const struct size_overflow_hash *get_function_hash(const_tree fndecl)
115047 +{
115048 + const struct size_overflow_hash *entry;
115049 + struct function_hash fn_hash_data;
115050 + const char *func_name;
115051 +
115052 + // skip builtins __builtin_constant_p
115053 + if (DECL_BUILT_IN(fndecl))
115054 + return NULL;
115055 +
115056 + fn_hash_data.fndecl = fndecl;
115057 + fn_hash_data.tree_codes_len = 0;
115058 +
115059 + set_function_codes(&fn_hash_data);
115060 + gcc_assert(fn_hash_data.tree_codes_len != 0);
115061 +
115062 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
115063 + set_hash(func_name, &fn_hash_data);
115064 +
115065 + entry = size_overflow_hash[fn_hash_data.hash];
115066 + entry = get_proper_hash_chain(entry, func_name);
115067 + if (entry)
115068 + return entry;
115069 + entry = size_overflow_hash_aux[fn_hash_data.hash];
115070 + return get_proper_hash_chain(entry, func_name);
115071 +}
115072 +
115073 +static void print_missing_msg(const_tree func, unsigned int argnum)
115074 +{
115075 + location_t loc;
115076 + const char *curfunc;
115077 + struct function_hash fn_hash_data;
115078 +
115079 + fn_hash_data.fndecl = DECL_ORIGIN(func);
115080 + fn_hash_data.tree_codes_len = 0;
115081 +
115082 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
115083 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
115084 +
115085 + set_function_codes(&fn_hash_data);
115086 + set_hash(curfunc, &fn_hash_data);
115087 +
115088 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
115089 +}
115090 +
115091 +static unsigned int find_arg_number_tree(const_tree arg, const_tree func)
115092 +{
115093 + tree var;
115094 + unsigned int argnum = 1;
115095 +
115096 + if (TREE_CODE(arg) == SSA_NAME)
115097 + arg = SSA_NAME_VAR(arg);
115098 +
115099 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
115100 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
115101 + continue;
115102 + if (!skip_types(var))
115103 + return argnum;
115104 + }
115105 +
115106 + return CANNOT_FIND_ARG;
115107 +}
115108 +
115109 +static tree create_new_var(tree type)
115110 +{
115111 + tree new_var = create_tmp_var(type, "cicus");
115112 +
115113 + add_referenced_var(new_var);
115114 + return new_var;
115115 +}
115116 +
115117 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
115118 +{
115119 + gimple assign;
115120 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115121 + tree type = TREE_TYPE(rhs1);
115122 + tree lhs = create_new_var(type);
115123 +
115124 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
115125 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
115126 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
115127 +
115128 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
115129 + update_stmt(assign);
115130 + set_stmt_flag(assign, MY_STMT);
115131 + return assign;
115132 +}
115133 +
115134 +static tree cast_a_tree(tree type, tree var)
115135 +{
115136 + gcc_assert(type != NULL_TREE);
115137 + gcc_assert(var != NULL_TREE);
115138 + gcc_assert(fold_convertible_p(type, var));
115139 +
115140 + return fold_convert(type, var);
115141 +}
115142 +
115143 +static tree get_lhs(const_gimple stmt)
115144 +{
115145 + switch (gimple_code(stmt)) {
115146 + case GIMPLE_ASSIGN:
115147 + case GIMPLE_CALL:
115148 + return gimple_get_lhs(stmt);
115149 + case GIMPLE_PHI:
115150 + return gimple_phi_result(stmt);
115151 + default:
115152 + return NULL_TREE;
115153 + }
115154 +}
115155 +
115156 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
115157 +{
115158 + const_gimple def_stmt = get_def_stmt(rhs);
115159 +
115160 + if (force)
115161 + return false;
115162 +
115163 + if (is_gimple_constant(rhs))
115164 + return false;
115165 +
115166 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
115167 + return false;
115168 +
115169 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
115170 + return false;
115171 +
115172 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
115173 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
115174 + return false;
115175 +
115176 + return true;
115177 +}
115178 +
115179 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
115180 +{
115181 + gimple assign, def_stmt;
115182 +
115183 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
115184 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
115185 + gcc_unreachable();
115186 +
115187 + def_stmt = get_def_stmt(rhs);
115188 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && get_stmt_flag(def_stmt) == MY_STMT)
115189 + return def_stmt;
115190 +
115191 + if (lhs == CREATE_NEW_VAR)
115192 + lhs = create_new_var(dst_type);
115193 +
115194 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
115195 +
115196 + if (!gsi_end_p(*gsi)) {
115197 + location_t loc = gimple_location(gsi_stmt(*gsi));
115198 + gimple_set_location(assign, loc);
115199 + }
115200 +
115201 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
115202 +
115203 + if (before)
115204 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
115205 + else
115206 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
115207 + update_stmt(assign);
115208 + return assign;
115209 +}
115210 +
115211 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
115212 +{
115213 + gimple_stmt_iterator gsi;
115214 + tree lhs;
115215 + gimple new_stmt;
115216 +
115217 + if (rhs == NULL_TREE)
115218 + return NULL_TREE;
115219 +
115220 + gsi = gsi_for_stmt(stmt);
115221 + new_stmt = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
115222 + set_stmt_flag(new_stmt, MY_STMT);
115223 +
115224 + lhs = get_lhs(new_stmt);
115225 + gcc_assert(lhs != NULL_TREE);
115226 + return lhs;
115227 +}
115228 +
115229 +static tree cast_to_TI_type(gimple stmt, tree node)
115230 +{
115231 + gimple_stmt_iterator gsi;
115232 + gimple cast_stmt;
115233 + tree type = TREE_TYPE(node);
115234 +
115235 + if (types_compatible_p(type, intTI_type_node))
115236 + return node;
115237 +
115238 + gsi = gsi_for_stmt(stmt);
115239 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
115240 + set_stmt_flag(cast_stmt, MY_STMT);
115241 + return gimple_assign_lhs(cast_stmt);
115242 +}
115243 +
115244 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
115245 +{
115246 + tree lhs, new_lhs;
115247 + gimple_stmt_iterator gsi;
115248 +
115249 + if (rhs1 == NULL_TREE) {
115250 + debug_gimple_stmt(oldstmt);
115251 + error("%s: rhs1 is NULL_TREE", __func__);
115252 + gcc_unreachable();
115253 + }
115254 +
115255 + switch (gimple_code(oldstmt)) {
115256 + case GIMPLE_ASM:
115257 + lhs = rhs1;
115258 + break;
115259 + case GIMPLE_CALL:
115260 + case GIMPLE_ASSIGN:
115261 + lhs = gimple_get_lhs(oldstmt);
115262 + break;
115263 + default:
115264 + debug_gimple_stmt(oldstmt);
115265 + gcc_unreachable();
115266 + }
115267 +
115268 + gsi = gsi_for_stmt(oldstmt);
115269 + pointer_set_insert(visited, oldstmt);
115270 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
115271 + basic_block next_bb, cur_bb;
115272 + const_edge e;
115273 +
115274 + gcc_assert(before == false);
115275 + gcc_assert(stmt_can_throw_internal(oldstmt));
115276 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
115277 + gcc_assert(!gsi_end_p(gsi));
115278 +
115279 + cur_bb = gimple_bb(oldstmt);
115280 + next_bb = cur_bb->next_bb;
115281 + e = find_edge(cur_bb, next_bb);
115282 + gcc_assert(e != NULL);
115283 + gcc_assert(e->flags & EDGE_FALLTHRU);
115284 +
115285 + gsi = gsi_after_labels(next_bb);
115286 + gcc_assert(!gsi_end_p(gsi));
115287 +
115288 + before = true;
115289 + oldstmt = gsi_stmt(gsi);
115290 + }
115291 +
115292 + new_lhs = cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
115293 + return new_lhs;
115294 +}
115295 +
115296 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
115297 +{
115298 + gimple stmt;
115299 + gimple_stmt_iterator gsi;
115300 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
115301 +
115302 + if (get_stmt_flag(oldstmt) == MY_STMT)
115303 + return lhs;
115304 +
115305 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
115306 + rhs1 = gimple_assign_rhs1(oldstmt);
115307 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
115308 + }
115309 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
115310 + rhs2 = gimple_assign_rhs2(oldstmt);
115311 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
115312 + }
115313 +
115314 + stmt = gimple_copy(oldstmt);
115315 + gimple_set_location(stmt, gimple_location(oldstmt));
115316 + set_stmt_flag(stmt, MY_STMT);
115317 +
115318 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
115319 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
115320 +
115321 + size_overflow_type = get_size_overflow_type(oldstmt, node);
115322 +
115323 + new_var = create_new_var(size_overflow_type);
115324 + new_var = make_ssa_name(new_var, stmt);
115325 + gimple_assign_set_lhs(stmt, new_var);
115326 +
115327 + if (rhs1 != NULL_TREE)
115328 + gimple_assign_set_rhs1(stmt, rhs1);
115329 +
115330 + if (rhs2 != NULL_TREE)
115331 + gimple_assign_set_rhs2(stmt, rhs2);
115332 +#if BUILDING_GCC_VERSION >= 4006
115333 + if (rhs3 != NULL_TREE)
115334 + gimple_assign_set_rhs3(stmt, rhs3);
115335 +#endif
115336 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
115337 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
115338 +
115339 + gsi = gsi_for_stmt(oldstmt);
115340 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
115341 + update_stmt(stmt);
115342 + pointer_set_insert(visited, oldstmt);
115343 + return gimple_assign_lhs(stmt);
115344 +}
115345 +
115346 +static tree cast_parm_decl(tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
115347 +{
115348 + gimple assign;
115349 + gimple_stmt_iterator gsi;
115350 + basic_block first_bb;
115351 +
115352 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
115353 +
115354 + if (bb->index == 0) {
115355 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
115356 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115357 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
115358 + bb = first_bb;
115359 + }
115360 +
115361 + gsi = gsi_after_labels(bb);
115362 + assign = build_cast_stmt(size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
115363 + set_stmt_flag(assign, MY_STMT);
115364 +
115365 + return gimple_assign_lhs(assign);
115366 +}
115367 +
115368 +static tree use_phi_ssa_name(tree ssa_name_var, tree new_arg)
115369 +{
115370 + gimple_stmt_iterator gsi;
115371 + gimple assign, def_stmt = get_def_stmt(new_arg);
115372 +
115373 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
115374 + gsi = gsi_after_labels(gimple_bb(def_stmt));
115375 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
115376 + } else {
115377 + gsi = gsi_for_stmt(def_stmt);
115378 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
115379 + }
115380 +
115381 + set_stmt_flag(assign, MY_STMT);
115382 + return gimple_assign_lhs(assign);
115383 +}
115384 +
115385 +static tree cast_visited_phi_arg(tree ssa_name_var, tree arg, tree size_overflow_type)
115386 +{
115387 + basic_block bb;
115388 + gimple_stmt_iterator gsi;
115389 + const_gimple def_stmt;
115390 + gimple assign;
115391 +
115392 + def_stmt = get_def_stmt(arg);
115393 + bb = gimple_bb(def_stmt);
115394 + gcc_assert(bb->index != 0);
115395 + gsi = gsi_after_labels(bb);
115396 +
115397 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
115398 + set_stmt_flag(assign, MY_STMT);
115399 + return gimple_assign_lhs(assign);
115400 +}
115401 +
115402 +static tree create_new_phi_arg(tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
115403 +{
115404 + tree size_overflow_type;
115405 + tree arg;
115406 + const_gimple def_stmt;
115407 +
115408 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
115409 + return new_arg;
115410 +
115411 + arg = gimple_phi_arg_def(oldstmt, i);
115412 + def_stmt = get_def_stmt(arg);
115413 + gcc_assert(def_stmt != NULL);
115414 + size_overflow_type = get_size_overflow_type(oldstmt, arg);
115415 +
115416 + switch (gimple_code(def_stmt)) {
115417 + case GIMPLE_PHI:
115418 + return cast_visited_phi_arg(ssa_name_var, arg, size_overflow_type);
115419 + case GIMPLE_NOP: {
115420 + basic_block bb;
115421 +
115422 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
115423 + return cast_parm_decl(ssa_name_var, arg, size_overflow_type, bb);
115424 + }
115425 + case GIMPLE_ASM: {
115426 + gimple_stmt_iterator gsi;
115427 + gimple assign, stmt = get_def_stmt(arg);
115428 +
115429 + gsi = gsi_for_stmt(stmt);
115430 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
115431 + set_stmt_flag(assign, MY_STMT);
115432 + return gimple_assign_lhs(assign);
115433 + }
115434 + default:
115435 + gcc_assert(new_arg != NULL_TREE);
115436 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
115437 + return use_phi_ssa_name(ssa_name_var, new_arg);
115438 + }
115439 +}
115440 +
115441 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
115442 +{
115443 + basic_block bb;
115444 + gimple phi;
115445 + gimple_seq seq;
115446 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
115447 +
115448 + bb = gsi_bb(gsi);
115449 +
115450 + if (result == NULL_TREE) {
115451 + tree old_result = gimple_phi_result(oldstmt);
115452 + tree size_overflow_type = get_size_overflow_type(oldstmt, old_result);
115453 +
115454 + result = create_new_var(size_overflow_type);
115455 + }
115456 +
115457 + phi = create_phi_node(result, bb);
115458 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
115459 + seq = phi_nodes(bb);
115460 + gsi = gsi_last(seq);
115461 + gsi_remove(&gsi, false);
115462 +
115463 + gsi = gsi_for_stmt(oldstmt);
115464 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
115465 + gimple_set_bb(phi, bb);
115466 + set_stmt_flag(phi, MY_STMT);
115467 + return phi;
115468 +}
115469 +
115470 +#if BUILDING_GCC_VERSION <= 4007
115471 +static tree create_new_phi_node(VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
115472 +#else
115473 +static tree create_new_phi_node(vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
115474 +#endif
115475 +{
115476 + gimple new_phi;
115477 + unsigned int i;
115478 + tree arg, result;
115479 + location_t loc = gimple_location(oldstmt);
115480 +
115481 +#if BUILDING_GCC_VERSION <= 4007
115482 + gcc_assert(!VEC_empty(tree, *args));
115483 +#else
115484 + gcc_assert(!args->is_empty());
115485 +#endif
115486 +
115487 + new_phi = overflow_create_phi_node(oldstmt, ssa_name_var);
115488 + result = gimple_phi_result(new_phi);
115489 + ssa_name_var = SSA_NAME_VAR(result);
115490 +
115491 +#if BUILDING_GCC_VERSION <= 4007
115492 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
115493 +#else
115494 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
115495 +#endif
115496 + arg = create_new_phi_arg(ssa_name_var, arg, oldstmt, i);
115497 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
115498 + }
115499 +
115500 +#if BUILDING_GCC_VERSION <= 4007
115501 + VEC_free(tree, heap, *args);
115502 +#else
115503 + vec_free(args);
115504 +#endif
115505 + update_stmt(new_phi);
115506 + return result;
115507 +}
115508 +
115509 +static tree handle_phi(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree orig_result)
115510 +{
115511 + tree ssa_name_var = NULL_TREE;
115512 +#if BUILDING_GCC_VERSION <= 4007
115513 + VEC(tree, heap) *args = NULL;
115514 +#else
115515 + vec<tree, va_heap, vl_embed> *args = NULL;
115516 +#endif
115517 + gimple oldstmt = get_def_stmt(orig_result);
115518 + unsigned int i, len = gimple_phi_num_args(oldstmt);
115519 +
115520 + pointer_set_insert(visited, oldstmt);
115521 + for (i = 0; i < len; i++) {
115522 + tree arg, new_arg;
115523 +
115524 + arg = gimple_phi_arg_def(oldstmt, i);
115525 + new_arg = expand(visited, caller_node, arg);
115526 +
115527 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
115528 + ssa_name_var = SSA_NAME_VAR(new_arg);
115529 +
115530 + if (is_gimple_constant(arg)) {
115531 + tree size_overflow_type = get_size_overflow_type(oldstmt, arg);
115532 +
115533 + new_arg = cast_a_tree(size_overflow_type, arg);
115534 + }
115535 +
115536 +#if BUILDING_GCC_VERSION <= 4007
115537 + VEC_safe_push(tree, heap, args, new_arg);
115538 +#else
115539 + vec_safe_push(args, new_arg);
115540 +#endif
115541 + }
115542 +
115543 +#if BUILDING_GCC_VERSION <= 4007
115544 + return create_new_phi_node(&args, ssa_name_var, oldstmt);
115545 +#else
115546 + return create_new_phi_node(args, ssa_name_var, oldstmt);
115547 +#endif
115548 +}
115549 +
115550 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
115551 +{
115552 + gimple assign;
115553 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115554 + tree origtype = TREE_TYPE(orig_rhs);
115555 +
115556 + gcc_assert(is_gimple_assign(stmt));
115557 +
115558 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
115559 + set_stmt_flag(assign, MY_STMT);
115560 + return gimple_assign_lhs(assign);
115561 +}
115562 +
115563 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
115564 +{
115565 + const_tree rhs1, lhs, rhs1_type, lhs_type;
115566 + enum machine_mode lhs_mode, rhs_mode;
115567 + gimple def_stmt = get_def_stmt(no_const_rhs);
115568 +
115569 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115570 + return false;
115571 +
115572 + rhs1 = gimple_assign_rhs1(def_stmt);
115573 + lhs = gimple_assign_lhs(def_stmt);
115574 + rhs1_type = TREE_TYPE(rhs1);
115575 + lhs_type = TREE_TYPE(lhs);
115576 + rhs_mode = TYPE_MODE(rhs1_type);
115577 + lhs_mode = TYPE_MODE(lhs_type);
115578 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
115579 + return false;
115580 +
115581 + return true;
115582 +}
115583 +
115584 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
115585 +{
115586 + tree rhs1 = gimple_assign_rhs1(stmt);
115587 + tree lhs = gimple_assign_lhs(stmt);
115588 + const_tree rhs1_type = TREE_TYPE(rhs1);
115589 + const_tree lhs_type = TREE_TYPE(lhs);
115590 +
115591 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
115592 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115593 +
115594 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
115595 +}
115596 +
115597 +static bool no_uses(tree node)
115598 +{
115599 + imm_use_iterator imm_iter;
115600 + use_operand_p use_p;
115601 +
115602 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
115603 + const_gimple use_stmt = USE_STMT(use_p);
115604 +
115605 + if (use_stmt == NULL)
115606 + return true;
115607 + if (is_gimple_debug(use_stmt))
115608 + continue;
115609 + return false;
115610 + }
115611 + return true;
115612 +}
115613 +
115614 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
115615 +static bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
115616 +{
115617 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
115618 + gimple def_stmt = get_def_stmt(lhs);
115619 +
115620 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115621 + return false;
115622 +
115623 + rhs1 = gimple_assign_rhs1(def_stmt);
115624 + rhs_type = TREE_TYPE(rhs1);
115625 + lhs_type = TREE_TYPE(lhs);
115626 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
115627 + return false;
115628 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
115629 + return false;
115630 +
115631 + def_stmt = get_def_stmt(rhs1);
115632 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
115633 + return false;
115634 +
115635 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
115636 + return false;
115637 +
115638 + rhs1 = gimple_assign_rhs1(def_stmt);
115639 + rhs2 = gimple_assign_rhs2(def_stmt);
115640 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
115641 + return false;
115642 +
115643 + if (is_gimple_constant(rhs2))
115644 + not_const_rhs = rhs1;
115645 + else
115646 + not_const_rhs = rhs2;
115647 +
115648 + return no_uses(not_const_rhs);
115649 +}
115650 +
115651 +static bool skip_lhs_cast_check(const_gimple stmt)
115652 +{
115653 + const_tree rhs = gimple_assign_rhs1(stmt);
115654 + const_gimple def_stmt = get_def_stmt(rhs);
115655 +
115656 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
115657 + if (gimple_code(def_stmt) == GIMPLE_ASM)
115658 + return true;
115659 +
115660 + if (is_const_plus_unsigned_signed_truncation(rhs))
115661 + return true;
115662 +
115663 + return false;
115664 +}
115665 +
115666 +static tree create_cast_overflow_check(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
115667 +{
115668 + bool cast_lhs, cast_rhs;
115669 + tree lhs = gimple_assign_lhs(stmt);
115670 + tree rhs = gimple_assign_rhs1(stmt);
115671 + const_tree lhs_type = TREE_TYPE(lhs);
115672 + const_tree rhs_type = TREE_TYPE(rhs);
115673 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
115674 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
115675 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
115676 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
115677 +
115678 + static bool check_lhs[3][4] = {
115679 + // ss su us uu
115680 + { false, true, true, false }, // lhs > rhs
115681 + { false, false, false, false }, // lhs = rhs
115682 + { true, true, true, true }, // lhs < rhs
115683 + };
115684 +
115685 + static bool check_rhs[3][4] = {
115686 + // ss su us uu
115687 + { true, false, true, true }, // lhs > rhs
115688 + { true, false, true, true }, // lhs = rhs
115689 + { true, false, true, true }, // lhs < rhs
115690 + };
115691 +
115692 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
115693 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
115694 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115695 +
115696 + if (lhs_size > rhs_size) {
115697 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115698 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115699 + } else if (lhs_size == rhs_size) {
115700 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115701 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115702 + } else {
115703 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115704 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115705 + }
115706 +
115707 + if (!cast_lhs && !cast_rhs)
115708 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115709 +
115710 + if (cast_lhs && !skip_lhs_cast_check(stmt))
115711 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
115712 +
115713 + if (cast_rhs)
115714 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
115715 +
115716 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115717 +}
115718 +
115719 +static tree handle_unary_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
115720 +{
115721 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
115722 +
115723 + if (get_stmt_flag(stmt) == MY_STMT)
115724 + return lhs;
115725 +
115726 + rhs1 = gimple_assign_rhs1(stmt);
115727 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
115728 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115729 +
115730 + new_rhs1 = expand(visited, caller_node, rhs1);
115731 +
115732 + if (new_rhs1 == NULL_TREE)
115733 + return create_cast_assign(visited, stmt);
115734 +
115735 + if (get_stmt_flag(stmt) == NO_CAST_CHECK)
115736 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115737 +
115738 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
115739 + tree size_overflow_type = get_size_overflow_type(stmt, rhs1);
115740 +
115741 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
115742 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
115743 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115744 + }
115745 +
115746 + if (!gimple_assign_cast_p(stmt))
115747 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115748 +
115749 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
115750 +}
115751 +
115752 +static tree handle_unary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
115753 +{
115754 + tree rhs1, lhs = gimple_assign_lhs(stmt);
115755 + gimple def_stmt = get_def_stmt(lhs);
115756 +
115757 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
115758 + rhs1 = gimple_assign_rhs1(def_stmt);
115759 +
115760 + if (is_gimple_constant(rhs1))
115761 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115762 +
115763 + switch (TREE_CODE(rhs1)) {
115764 + case SSA_NAME:
115765 + return handle_unary_rhs(visited, caller_node, def_stmt);
115766 + case ARRAY_REF:
115767 + case BIT_FIELD_REF:
115768 + case ADDR_EXPR:
115769 + case COMPONENT_REF:
115770 + case INDIRECT_REF:
115771 +#if BUILDING_GCC_VERSION >= 4006
115772 + case MEM_REF:
115773 +#endif
115774 + case TARGET_MEM_REF:
115775 + case VIEW_CONVERT_EXPR:
115776 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115777 + case PARM_DECL:
115778 + case VAR_DECL:
115779 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115780 +
115781 + default:
115782 + debug_gimple_stmt(def_stmt);
115783 + debug_tree(rhs1);
115784 + gcc_unreachable();
115785 + }
115786 +}
115787 +
115788 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
115789 +{
115790 + gimple cond_stmt;
115791 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
115792 +
115793 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
115794 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
115795 + update_stmt(cond_stmt);
115796 +}
115797 +
115798 +static tree create_string_param(tree string)
115799 +{
115800 + tree i_type, a_type;
115801 + const int length = TREE_STRING_LENGTH(string);
115802 +
115803 + gcc_assert(length > 0);
115804 +
115805 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
115806 + a_type = build_array_type(char_type_node, i_type);
115807 +
115808 + TREE_TYPE(string) = a_type;
115809 + TREE_CONSTANT(string) = 1;
115810 + TREE_READONLY(string) = 1;
115811 +
115812 + return build1(ADDR_EXPR, ptr_type_node, string);
115813 +}
115814 +
115815 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
115816 +{
115817 + gimple func_stmt;
115818 + const_gimple def_stmt;
115819 + const_tree loc_line;
115820 + tree loc_file, ssa_name, current_func;
115821 + expanded_location xloc;
115822 + char *ssa_name_buf;
115823 + int len;
115824 + struct cgraph_edge *edge;
115825 + struct cgraph_node *callee_node;
115826 + int frequency;
115827 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
115828 +
115829 + def_stmt = get_def_stmt(arg);
115830 + xloc = expand_location(gimple_location(def_stmt));
115831 +
115832 + if (!gimple_has_location(def_stmt)) {
115833 + xloc = expand_location(gimple_location(stmt));
115834 + if (!gimple_has_location(stmt))
115835 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
115836 + }
115837 +
115838 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
115839 +
115840 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
115841 + loc_file = create_string_param(loc_file);
115842 +
115843 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
115844 + current_func = create_string_param(current_func);
115845 +
115846 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
115847 + call_count++;
115848 + 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);
115849 + gcc_assert(len > 0);
115850 + ssa_name = build_string(len + 1, ssa_name_buf);
115851 + free(ssa_name_buf);
115852 + ssa_name = create_string_param(ssa_name);
115853 +
115854 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
115855 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
115856 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
115857 +
115858 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
115859 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
115860 +
115861 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
115862 + gcc_assert(edge != NULL);
115863 +}
115864 +
115865 +static void __unused print_the_code_insertions(const_gimple stmt)
115866 +{
115867 + location_t loc = gimple_location(stmt);
115868 +
115869 + inform(loc, "Integer size_overflow check applied here.");
115870 +}
115871 +
115872 +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)
115873 +{
115874 + basic_block cond_bb, join_bb, bb_true;
115875 + edge e;
115876 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115877 +
115878 + cond_bb = gimple_bb(stmt);
115879 + if (before)
115880 + gsi_prev(&gsi);
115881 + if (gsi_end_p(gsi))
115882 + e = split_block_after_labels(cond_bb);
115883 + else
115884 + e = split_block(cond_bb, gsi_stmt(gsi));
115885 + cond_bb = e->src;
115886 + join_bb = e->dest;
115887 + e->flags = EDGE_FALSE_VALUE;
115888 + e->probability = REG_BR_PROB_BASE;
115889 +
115890 + bb_true = create_empty_bb(cond_bb);
115891 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
115892 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
115893 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
115894 +
115895 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115896 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
115897 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
115898 +
115899 + if (current_loops != NULL) {
115900 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
115901 + add_bb_to_loop(bb_true, cond_bb->loop_father);
115902 + }
115903 +
115904 + insert_cond(cond_bb, arg, cond_code, type_value);
115905 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
115906 +
115907 +// print_the_code_insertions(stmt);
115908 +}
115909 +
115910 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
115911 +{
115912 + const_tree rhs_type = TREE_TYPE(rhs);
115913 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
115914 +
115915 + gcc_assert(rhs_type != NULL_TREE);
115916 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
115917 + return;
115918 +
115919 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
115920 +
115921 + if (is_const_plus_unsigned_signed_truncation(rhs))
115922 + return;
115923 +
115924 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
115925 + // typemax (-1) < typemin (0)
115926 + if (TREE_OVERFLOW(type_max))
115927 + return;
115928 +
115929 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
115930 +
115931 + cast_rhs_type = TREE_TYPE(cast_rhs);
115932 + type_max_type = TREE_TYPE(type_max);
115933 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
115934 +
115935 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
115936 +
115937 + // special case: get_size_overflow_type(), 32, u64->s
115938 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
115939 + return;
115940 +
115941 + type_min_type = TREE_TYPE(type_min);
115942 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
115943 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
115944 +}
115945 +
115946 +static bool is_lt_signed_type_max(const_tree rhs)
115947 +{
115948 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
115949 +
115950 + if (!TYPE_UNSIGNED(type))
115951 + return true;
115952 +
115953 + switch (TYPE_MODE(type)) {
115954 + case QImode:
115955 + new_type = intQI_type_node;
115956 + break;
115957 + case HImode:
115958 + new_type = intHI_type_node;
115959 + break;
115960 + case SImode:
115961 + new_type = intSI_type_node;
115962 + break;
115963 + case DImode:
115964 + new_type = intDI_type_node;
115965 + break;
115966 + default:
115967 + debug_tree((tree)type);
115968 + gcc_unreachable();
115969 + }
115970 +
115971 + type_max = TYPE_MAX_VALUE(new_type);
115972 + if (!tree_int_cst_lt(type_max, rhs))
115973 + return true;
115974 +
115975 + return false;
115976 +}
115977 +
115978 +static bool is_gt_zero(const_tree rhs)
115979 +{
115980 + const_tree type = TREE_TYPE(rhs);
115981 +
115982 + if (TYPE_UNSIGNED(type))
115983 + return true;
115984 +
115985 + if (!tree_int_cst_lt(rhs, integer_zero_node))
115986 + return true;
115987 +
115988 + return false;
115989 +}
115990 +
115991 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
115992 +{
115993 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
115994 + return false;
115995 + if (!is_gimple_constant(rhs))
115996 + return false;
115997 +
115998 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
115999 +// if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
116000 +// return false;
116001 +
116002 + return true;
116003 +}
116004 +
116005 +static tree get_def_stmt_rhs(const_tree var)
116006 +{
116007 + tree rhs1, def_stmt_rhs1;
116008 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
116009 +
116010 + def_stmt = get_def_stmt(var);
116011 + if (!gimple_assign_cast_p(def_stmt))
116012 + return NULL_TREE;
116013 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && get_stmt_flag(def_stmt) == MY_STMT && gimple_assign_cast_p(def_stmt));
116014 +
116015 + rhs1 = gimple_assign_rhs1(def_stmt);
116016 + rhs1_def_stmt = get_def_stmt(rhs1);
116017 + if (!gimple_assign_cast_p(rhs1_def_stmt))
116018 + return rhs1;
116019 +
116020 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
116021 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
116022 +
116023 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
116024 + case GIMPLE_CALL:
116025 + case GIMPLE_NOP:
116026 + case GIMPLE_ASM:
116027 + case GIMPLE_PHI:
116028 + return def_stmt_rhs1;
116029 + case GIMPLE_ASSIGN:
116030 + return rhs1;
116031 + default:
116032 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
116033 + gcc_unreachable();
116034 + }
116035 +}
116036 +
116037 +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)
116038 +{
116039 + tree new_rhs, orig_rhs;
116040 + void (*gimple_assign_set_rhs)(gimple, tree);
116041 + tree rhs1 = gimple_assign_rhs1(stmt);
116042 + tree rhs2 = gimple_assign_rhs2(stmt);
116043 + tree lhs = gimple_assign_lhs(stmt);
116044 +
116045 + if (!check_overflow)
116046 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116047 +
116048 + if (change_rhs == NULL_TREE)
116049 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116050 +
116051 + if (new_rhs2 == NULL_TREE) {
116052 + orig_rhs = rhs1;
116053 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
116054 + } else {
116055 + orig_rhs = rhs2;
116056 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
116057 + }
116058 +
116059 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
116060 +
116061 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
116062 + gimple_assign_set_rhs(stmt, new_rhs);
116063 + update_stmt(stmt);
116064 +
116065 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116066 +}
116067 +
116068 +static bool is_subtraction_special(const_gimple stmt)
116069 +{
116070 + gimple rhs1_def_stmt, rhs2_def_stmt;
116071 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
116072 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
116073 + const_tree rhs1 = gimple_assign_rhs1(stmt);
116074 + const_tree rhs2 = gimple_assign_rhs2(stmt);
116075 +
116076 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
116077 + return false;
116078 +
116079 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
116080 +
116081 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
116082 + return false;
116083 +
116084 + rhs1_def_stmt = get_def_stmt(rhs1);
116085 + rhs2_def_stmt = get_def_stmt(rhs2);
116086 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
116087 + return false;
116088 +
116089 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
116090 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
116091 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
116092 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
116093 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
116094 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
116095 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
116096 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
116097 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
116098 + return false;
116099 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
116100 + return false;
116101 +
116102 + set_stmt_flag(rhs1_def_stmt, NO_CAST_CHECK);
116103 + set_stmt_flag(rhs2_def_stmt, NO_CAST_CHECK);
116104 + return true;
116105 +}
116106 +
116107 +static tree handle_integer_truncation(struct pointer_set_t *visited, struct cgraph_node *caller_node, const_tree lhs)
116108 +{
116109 + tree new_rhs1, new_rhs2;
116110 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
116111 + gimple assign, stmt = get_def_stmt(lhs);
116112 + tree rhs1 = gimple_assign_rhs1(stmt);
116113 + tree rhs2 = gimple_assign_rhs2(stmt);
116114 +
116115 + if (!is_subtraction_special(stmt))
116116 + return NULL_TREE;
116117 +
116118 + new_rhs1 = expand(visited, caller_node, rhs1);
116119 + new_rhs2 = expand(visited, caller_node, rhs2);
116120 +
116121 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
116122 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
116123 +
116124 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
116125 + return NULL_TREE;
116126 +
116127 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
116128 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
116129 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
116130 + }
116131 +
116132 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
116133 + new_lhs = gimple_assign_lhs(assign);
116134 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
116135 +
116136 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
116137 +}
116138 +
116139 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
116140 +{
116141 + const_gimple def_stmt;
116142 +
116143 + if (TREE_CODE(rhs) != SSA_NAME)
116144 + return false;
116145 +
116146 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
116147 + return false;
116148 +
116149 + def_stmt = get_def_stmt(rhs);
116150 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
116151 + return false;
116152 +
116153 + return true;
116154 +}
116155 +
116156 +static tree handle_binary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
116157 +{
116158 + tree rhs1, rhs2, new_lhs;
116159 + gimple def_stmt = get_def_stmt(lhs);
116160 + tree new_rhs1 = NULL_TREE;
116161 + tree new_rhs2 = NULL_TREE;
116162 +
116163 + rhs1 = gimple_assign_rhs1(def_stmt);
116164 + rhs2 = gimple_assign_rhs2(def_stmt);
116165 +
116166 + /* no DImode/TImode division in the 32/64 bit kernel */
116167 + switch (gimple_assign_rhs_code(def_stmt)) {
116168 + case RDIV_EXPR:
116169 + case TRUNC_DIV_EXPR:
116170 + case CEIL_DIV_EXPR:
116171 + case FLOOR_DIV_EXPR:
116172 + case ROUND_DIV_EXPR:
116173 + case TRUNC_MOD_EXPR:
116174 + case CEIL_MOD_EXPR:
116175 + case FLOOR_MOD_EXPR:
116176 + case ROUND_MOD_EXPR:
116177 + case EXACT_DIV_EXPR:
116178 + case POINTER_PLUS_EXPR:
116179 + case BIT_AND_EXPR:
116180 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116181 + default:
116182 + break;
116183 + }
116184 +
116185 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
116186 + if (new_lhs != NULL_TREE)
116187 + return new_lhs;
116188 +
116189 + if (TREE_CODE(rhs1) == SSA_NAME)
116190 + new_rhs1 = expand(visited, caller_node, rhs1);
116191 + if (TREE_CODE(rhs2) == SSA_NAME)
116192 + new_rhs2 = expand(visited, caller_node, rhs2);
116193 +
116194 + if (is_a_neg_overflow(def_stmt, rhs2))
116195 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
116196 + if (is_a_neg_overflow(def_stmt, rhs1))
116197 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
116198 +
116199 +
116200 + if (is_a_constant_overflow(def_stmt, rhs2))
116201 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
116202 + if (is_a_constant_overflow(def_stmt, rhs1))
116203 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
116204 +
116205 + // the const is between 0 and (signed) MAX
116206 + if (is_gimple_constant(rhs1))
116207 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
116208 + if (is_gimple_constant(rhs2))
116209 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
116210 +
116211 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
116212 +}
116213 +
116214 +#if BUILDING_GCC_VERSION >= 4006
116215 +static tree get_new_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
116216 +{
116217 + if (is_gimple_constant(rhs))
116218 + return cast_a_tree(size_overflow_type, rhs);
116219 + if (TREE_CODE(rhs) != SSA_NAME)
116220 + return NULL_TREE;
116221 + return expand(visited, caller_node, rhs);
116222 +}
116223 +
116224 +static tree handle_ternary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
116225 +{
116226 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
116227 + gimple def_stmt = get_def_stmt(lhs);
116228 +
116229 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
116230 +
116231 + rhs1 = gimple_assign_rhs1(def_stmt);
116232 + rhs2 = gimple_assign_rhs2(def_stmt);
116233 + rhs3 = gimple_assign_rhs3(def_stmt);
116234 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
116235 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
116236 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
116237 +
116238 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
116239 +}
116240 +#endif
116241 +
116242 +static tree get_size_overflow_type(gimple stmt, const_tree node)
116243 +{
116244 + const_tree type;
116245 + tree new_type;
116246 +
116247 + gcc_assert(node != NULL_TREE);
116248 +
116249 + type = TREE_TYPE(node);
116250 +
116251 + if (get_stmt_flag(stmt) == MY_STMT)
116252 + return TREE_TYPE(node);
116253 +
116254 + switch (TYPE_MODE(type)) {
116255 + case QImode:
116256 + new_type = intHI_type_node;
116257 + break;
116258 + case HImode:
116259 + new_type = intSI_type_node;
116260 + break;
116261 + case SImode:
116262 + new_type = intDI_type_node;
116263 + break;
116264 + case DImode:
116265 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
116266 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
116267 + else
116268 + new_type = intTI_type_node;
116269 + break;
116270 + case TImode:
116271 + gcc_assert(!TYPE_UNSIGNED(type));
116272 + new_type = intTI_type_node;
116273 + break;
116274 + default:
116275 + debug_tree((tree)node);
116276 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
116277 + gcc_unreachable();
116278 + }
116279 +
116280 + if (TYPE_QUALS(type) != 0)
116281 + return build_qualified_type(new_type, TYPE_QUALS(type));
116282 + return new_type;
116283 +}
116284 +
116285 +static tree expand_visited(gimple def_stmt)
116286 +{
116287 + const_gimple next_stmt;
116288 + gimple_stmt_iterator gsi;
116289 + enum gimple_code code = gimple_code(def_stmt);
116290 +
116291 + if (code == GIMPLE_ASM)
116292 + return NULL_TREE;
116293 +
116294 + gsi = gsi_for_stmt(def_stmt);
116295 + gsi_next(&gsi);
116296 +
116297 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
116298 + return NULL_TREE;
116299 + gcc_assert(!gsi_end_p(gsi));
116300 + next_stmt = gsi_stmt(gsi);
116301 +
116302 + if (gimple_code(def_stmt) == GIMPLE_PHI && get_stmt_flag((gimple)next_stmt) != MY_STMT)
116303 + return NULL_TREE;
116304 + gcc_assert(get_stmt_flag((gimple)next_stmt) == MY_STMT);
116305 +
116306 + return get_lhs(next_stmt);
116307 +}
116308 +
116309 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
116310 +{
116311 + gimple def_stmt;
116312 +
116313 + def_stmt = get_def_stmt(lhs);
116314 +
116315 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
116316 + return NULL_TREE;
116317 +
116318 + if (get_stmt_flag(def_stmt) == MY_STMT)
116319 + return lhs;
116320 +
116321 + if (pointer_set_contains(visited, def_stmt))
116322 + return expand_visited(def_stmt);
116323 +
116324 + switch (gimple_code(def_stmt)) {
116325 + case GIMPLE_PHI:
116326 + return handle_phi(visited, caller_node, lhs);
116327 + case GIMPLE_CALL:
116328 + case GIMPLE_ASM:
116329 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116330 + case GIMPLE_ASSIGN:
116331 + switch (gimple_num_ops(def_stmt)) {
116332 + case 2:
116333 + return handle_unary_ops(visited, caller_node, def_stmt);
116334 + case 3:
116335 + return handle_binary_ops(visited, caller_node, lhs);
116336 +#if BUILDING_GCC_VERSION >= 4006
116337 + case 4:
116338 + return handle_ternary_ops(visited, caller_node, lhs);
116339 +#endif
116340 + }
116341 + default:
116342 + debug_gimple_stmt(def_stmt);
116343 + error("%s: unknown gimple code", __func__);
116344 + gcc_unreachable();
116345 + }
116346 +}
116347 +
116348 +static tree cast_to_orig_type(gimple stmt, const_tree orig_node, tree new_node)
116349 +{
116350 + const_gimple assign;
116351 + tree orig_type = TREE_TYPE(orig_node);
116352 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116353 +
116354 + assign = build_cast_stmt(orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116355 + return gimple_assign_lhs(assign);
116356 +}
116357 +
116358 +static void change_orig_node(struct interesting_node *cur_node, tree new_node)
116359 +{
116360 + void (*set_rhs)(gimple, tree);
116361 + gimple stmt = cur_node->first_stmt;
116362 + const_tree orig_node = cur_node->node;
116363 +
116364 + switch (gimple_code(stmt)) {
116365 + case GIMPLE_RETURN:
116366 + gimple_return_set_retval(stmt, cast_to_orig_type(stmt, orig_node, new_node));
116367 + break;
116368 + case GIMPLE_CALL:
116369 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(stmt, orig_node, new_node));
116370 + break;
116371 + case GIMPLE_ASSIGN:
116372 + switch (cur_node->num) {
116373 + case 1:
116374 + set_rhs = &gimple_assign_set_rhs1;
116375 + break;
116376 + case 2:
116377 + set_rhs = &gimple_assign_set_rhs2;
116378 + break;
116379 +#if BUILDING_GCC_VERSION >= 4006
116380 + case 3:
116381 + set_rhs = &gimple_assign_set_rhs3;
116382 + break;
116383 +#endif
116384 + default:
116385 + gcc_unreachable();
116386 + }
116387 +
116388 + set_rhs(stmt, cast_to_orig_type(stmt, orig_node, new_node));
116389 + break;
116390 + default:
116391 + debug_gimple_stmt(stmt);
116392 + gcc_unreachable();
116393 + }
116394 +
116395 + update_stmt(stmt);
116396 +}
116397 +
116398 +static unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
116399 +{
116400 + const struct size_overflow_hash *hash;
116401 + unsigned int new_argnum;
116402 + tree arg;
116403 + const_tree origarg;
116404 +
116405 + if (argnum == 0)
116406 + return argnum;
116407 +
116408 + hash = get_function_hash(fndecl);
116409 + if (hash && hash->param & (1U << argnum))
116410 + return argnum;
116411 +
116412 + if (DECL_EXTERNAL(fndecl))
116413 + return argnum;
116414 +
116415 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
116416 + argnum--;
116417 + while (origarg && argnum) {
116418 + origarg = TREE_CHAIN(origarg);
116419 + argnum--;
116420 + }
116421 + gcc_assert(argnum == 0);
116422 + gcc_assert(origarg != NULL_TREE);
116423 +
116424 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
116425 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
116426 + return new_argnum;
116427 +
116428 + return CANNOT_FIND_ARG;
116429 +}
116430 +
116431 +// Don't want to duplicate entries in next_cgraph_node
116432 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
116433 +{
116434 + const_tree new_callee_fndecl;
116435 + struct next_cgraph_node *cur_node;
116436 +
116437 + if (fndecl == RET_CHECK)
116438 + new_callee_fndecl = NODE_DECL(node);
116439 + else
116440 + new_callee_fndecl = fndecl;
116441 +
116442 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
116443 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
116444 + continue;
116445 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
116446 + continue;
116447 + if (num == cur_node->num)
116448 + return true;
116449 + }
116450 + return false;
116451 +}
116452 +
116453 +/* Add a next_cgraph_node into the list for handle_function().
116454 + * handle_function() iterates over all the next cgraph nodes and
116455 + * starts the overflow check insertion process.
116456 + */
116457 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
116458 +{
116459 + struct next_cgraph_node *new_node;
116460 +
116461 + if (is_in_next_cgraph_node(head, node, fndecl, num))
116462 + return head;
116463 +
116464 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
116465 + new_node->current_function = node;
116466 + new_node->next = NULL;
116467 + new_node->num = num;
116468 + if (fndecl == RET_CHECK)
116469 + new_node->callee_fndecl = NODE_DECL(node);
116470 + else
116471 + new_node->callee_fndecl = fndecl;
116472 +
116473 + if (!head)
116474 + return new_node;
116475 +
116476 + new_node->next = head;
116477 + return new_node;
116478 +}
116479 +
116480 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
116481 +{
116482 + struct cgraph_edge *e;
116483 +
116484 + if (num == 0)
116485 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
116486 +
116487 + for (e = node->callers; e; e = e->next_caller) {
116488 + tree fndecl = gimple_call_fndecl(e->call_stmt);
116489 +
116490 + gcc_assert(fndecl != NULL_TREE);
116491 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
116492 + }
116493 +
116494 + return head;
116495 +}
116496 +
116497 +static bool is_a_return_check(const_tree node)
116498 +{
116499 + if (TREE_CODE(node) == FUNCTION_DECL)
116500 + return true;
116501 +
116502 + gcc_assert(TREE_CODE(node) == PARM_DECL);
116503 + return false;
116504 +}
116505 +
116506 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
116507 +{
116508 + const struct size_overflow_hash *hash;
116509 +
116510 + hash = get_function_hash(fndecl);
116511 + if (hash && (hash->param & (1U << num)))
116512 + return true;
116513 + return false;
116514 +}
116515 +
116516 +struct missing_functions {
116517 + struct missing_functions *next;
116518 + const_tree node;
116519 + tree fndecl;
116520 +};
116521 +
116522 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
116523 +{
116524 + struct missing_functions *new_function;
116525 +
116526 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
116527 + new_function->node = node;
116528 + new_function->next = NULL;
116529 +
116530 + if (TREE_CODE(node) == FUNCTION_DECL)
116531 + new_function->fndecl = node;
116532 + else
116533 + new_function->fndecl = current_function_decl;
116534 + gcc_assert(new_function->fndecl);
116535 +
116536 + if (!missing_fn_head)
116537 + return new_function;
116538 +
116539 + new_function->next = missing_fn_head;
116540 + return new_function;
116541 +}
116542 +
116543 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
116544 + * If the function is missing everywhere then print the missing message into stderr.
116545 + */
116546 +static bool is_missing_function(const_tree orig_fndecl, unsigned int num)
116547 +{
116548 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
116549 +#if BUILDING_GCC_VERSION >= 4008
116550 + case BUILT_IN_BSWAP16:
116551 +#endif
116552 + case BUILT_IN_BSWAP32:
116553 + case BUILT_IN_BSWAP64:
116554 + case BUILT_IN_EXPECT:
116555 + case BUILT_IN_MEMCMP:
116556 + return false;
116557 + default:
116558 + break;
116559 + }
116560 +
116561 + // skip test.c
116562 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
116563 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
116564 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
116565 + }
116566 +
116567 + if (is_in_hash_table(orig_fndecl, num))
116568 + return false;
116569 +
116570 + print_missing_msg(orig_fndecl, num);
116571 + return true;
116572 +}
116573 +
116574 +// Get the argnum of a function decl, if node is a return then the argnum is 0
116575 +static unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
116576 +{
116577 + if (is_a_return_check(node))
116578 + return 0;
116579 + else
116580 + return find_arg_number_tree(node, orig_fndecl);
116581 +}
116582 +
116583 +/* If the function is missing from the hash table and it is a static function
116584 + * then create a next_cgraph_node from it for handle_function()
116585 + */
116586 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
116587 +{
116588 + unsigned int num;
116589 + const_tree orig_fndecl;
116590 + struct cgraph_node *next_node = NULL;
116591 +
116592 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
116593 +
116594 + num = get_function_num(missing_fn_head->node, orig_fndecl);
116595 + if (num == CANNOT_FIND_ARG)
116596 + return cnodes;
116597 +
116598 + if (!is_missing_function(orig_fndecl, num))
116599 + return cnodes;
116600 +
116601 + next_node = cgraph_get_node(missing_fn_head->fndecl);
116602 + if (next_node && next_node->local.local)
116603 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
116604 + return cnodes;
116605 +}
116606 +
116607 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
116608 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
116609 + */
116610 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
116611 +{
116612 + unsigned int i;
116613 + tree node;
116614 + struct missing_functions *cur, *missing_fn_head = NULL;
116615 +
116616 +#if BUILDING_GCC_VERSION <= 4007
116617 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
116618 +#else
116619 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
116620 +#endif
116621 + switch (TREE_CODE(node)) {
116622 + case PARM_DECL:
116623 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
116624 + break;
116625 + case FUNCTION_DECL:
116626 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
116627 + break;
116628 + default:
116629 + break;
116630 + }
116631 + }
116632 +
116633 + while (missing_fn_head) {
116634 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
116635 +
116636 + cur = missing_fn_head->next;
116637 + free(missing_fn_head);
116638 + missing_fn_head = cur;
116639 + }
116640 +
116641 + return cnodes;
116642 +}
116643 +
116644 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
116645 +{
116646 + gimple phi = get_def_stmt(result);
116647 + unsigned int i, n = gimple_phi_num_args(phi);
116648 +
116649 + pointer_set_insert(visited, phi);
116650 + for (i = 0; i < n; i++) {
116651 + const_tree arg = gimple_phi_arg_def(phi, i);
116652 +
116653 + set_conditions(visited, interesting_conditions, arg);
116654 + }
116655 +}
116656 +
116657 +enum conditions {
116658 + FROM_CONST, NOT_UNARY, CAST
116659 +};
116660 +
116661 +// Search for constants, cast assignments and binary/ternary assignments
116662 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
116663 +{
116664 + gimple def_stmt = get_def_stmt(lhs);
116665 +
116666 + if (is_gimple_constant(lhs)) {
116667 + interesting_conditions[FROM_CONST] = true;
116668 + return;
116669 + }
116670 +
116671 + if (!def_stmt)
116672 + return;
116673 +
116674 + if (pointer_set_contains(visited, def_stmt))
116675 + return;
116676 +
116677 + switch (gimple_code(def_stmt)) {
116678 + case GIMPLE_NOP:
116679 + case GIMPLE_CALL:
116680 + case GIMPLE_ASM:
116681 + return;
116682 + case GIMPLE_PHI:
116683 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
116684 + case GIMPLE_ASSIGN:
116685 + if (gimple_num_ops(def_stmt) == 2) {
116686 + const_tree rhs = gimple_assign_rhs1(def_stmt);
116687 +
116688 + if (gimple_assign_cast_p(def_stmt))
116689 + interesting_conditions[CAST] = true;
116690 +
116691 + return set_conditions(visited, interesting_conditions, rhs);
116692 + } else {
116693 + interesting_conditions[NOT_UNARY] = true;
116694 + return;
116695 + }
116696 + default:
116697 + debug_gimple_stmt(def_stmt);
116698 + gcc_unreachable();
116699 + }
116700 +}
116701 +
116702 +// determine whether duplication will be necessary or not.
116703 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
116704 +{
116705 + struct pointer_set_t *visited;
116706 +
116707 + if (gimple_assign_cast_p(cur_node->first_stmt))
116708 + interesting_conditions[CAST] = true;
116709 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
116710 + interesting_conditions[NOT_UNARY] = true;
116711 +
116712 + visited = pointer_set_create();
116713 + set_conditions(visited, interesting_conditions, cur_node->node);
116714 + pointer_set_destroy(visited);
116715 +}
116716 +
116717 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
116718 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
116719 +{
116720 + gimple assign;
116721 + gimple_stmt_iterator gsi;
116722 +
116723 + // already removed
116724 + if (gimple_bb(asm_stmt) == NULL)
116725 + return;
116726 + gsi = gsi_for_stmt(asm_stmt);
116727 +
116728 + assign = gimple_build_assign(lhs, rhs);
116729 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
116730 + SSA_NAME_DEF_STMT(lhs) = assign;
116731 +
116732 + gsi_remove(&gsi, true);
116733 +}
116734 +
116735 +// Get the field decl of a component ref for intentional_overflow checking
116736 +static const_tree search_field_decl(const_tree comp_ref)
116737 +{
116738 + const_tree field = NULL_TREE;
116739 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
116740 +
116741 + for (i = 0; i < len; i++) {
116742 + field = TREE_OPERAND(comp_ref, i);
116743 + if (TREE_CODE(field) == FIELD_DECL)
116744 + break;
116745 + }
116746 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
116747 + return field;
116748 +}
116749 +
116750 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
116751 + * stmt is a return otherwise it is the callee function.
116752 + */
116753 +static const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
116754 +{
116755 + const_tree fndecl;
116756 +
116757 + if (argnum == 0)
116758 + fndecl = current_function_decl;
116759 + else
116760 + fndecl = gimple_call_fndecl(stmt);
116761 +
116762 + if (fndecl == NULL_TREE)
116763 + return NULL_TREE;
116764 +
116765 + return DECL_ORIGIN(fndecl);
116766 +}
116767 +
116768 +/* Get the param of the intentional_overflow attribute.
116769 + * * 0: MARK_NOT_INTENTIONAL
116770 + * * 1..MAX_PARAM: MARK_YES
116771 + * * -1: MARK_TURN_OFF
116772 + */
116773 +static tree get_attribute_param(const_tree decl)
116774 +{
116775 + const_tree attr;
116776 +
116777 + if (decl == NULL_TREE)
116778 + return NULL_TREE;
116779 +
116780 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
116781 + if (!attr || !TREE_VALUE(attr))
116782 + return NULL_TREE;
116783 +
116784 + return TREE_VALUE(attr);
116785 +}
116786 +
116787 +// MARK_TURN_OFF
116788 +static bool is_turn_off_intentional_attr(const_tree decl)
116789 +{
116790 + const_tree param_head;
116791 +
116792 + param_head = get_attribute_param(decl);
116793 + if (param_head == NULL_TREE)
116794 + return false;
116795 +
116796 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
116797 + return true;
116798 + return false;
116799 +}
116800 +
116801 +// MARK_NOT_INTENTIONAL
116802 +static bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
116803 +{
116804 + const_tree param_head;
116805 +
116806 + if (argnum == 0)
116807 + return false;
116808 +
116809 + param_head = get_attribute_param(decl);
116810 + if (param_head == NULL_TREE)
116811 + return false;
116812 +
116813 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
116814 + return true;
116815 + return false;
116816 +}
116817 +
116818 +// MARK_YES
116819 +static bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
116820 +{
116821 + tree param, param_head;
116822 +
116823 + if (argnum == 0)
116824 + return false;
116825 +
116826 + param_head = get_attribute_param(decl);
116827 + for (param = param_head; param; param = TREE_CHAIN(param))
116828 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
116829 + return true;
116830 + return false;
116831 +}
116832 +
116833 +static const char *get_asm_string(const_gimple stmt)
116834 +{
116835 + if (!stmt)
116836 + return NULL;
116837 + if (gimple_code(stmt) != GIMPLE_ASM)
116838 + return NULL;
116839 +
116840 + return gimple_asm_string(stmt);
116841 +}
116842 +
116843 +static bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
116844 +{
116845 + const char *str;
116846 +
116847 + str = get_asm_string(stmt);
116848 + if (!str)
116849 + return false;
116850 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
116851 +}
116852 +
116853 +static bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
116854 +{
116855 + const char *str;
116856 +
116857 + str = get_asm_string(stmt);
116858 + if (!str)
116859 + return false;
116860 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
116861 +}
116862 +
116863 +static bool is_size_overflow_asm(const_gimple stmt)
116864 +{
116865 + const char *str;
116866 +
116867 + str = get_asm_string(stmt);
116868 + if (!str)
116869 + return false;
116870 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
116871 +}
116872 +
116873 +static void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
116874 +{
116875 + location_t loc;
116876 +
116877 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
116878 + return;
116879 +
116880 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
116881 + return;
116882 +
116883 + loc = DECL_SOURCE_LOCATION(decl);
116884 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
116885 +}
116886 +
116887 +/* Get the type of the intentional_overflow attribute of a node
116888 + * * MARK_TURN_OFF
116889 + * * MARK_YES
116890 + * * MARK_NO
116891 + * * MARK_NOT_INTENTIONAL
116892 + */
116893 +static enum mark get_intentional_attr_type(const_tree node)
116894 +{
116895 + const_tree cur_decl;
116896 +
116897 + if (node == NULL_TREE)
116898 + return MARK_NO;
116899 +
116900 + switch (TREE_CODE(node)) {
116901 + case COMPONENT_REF:
116902 + cur_decl = search_field_decl(node);
116903 + if (is_turn_off_intentional_attr(cur_decl))
116904 + return MARK_TURN_OFF;
116905 + if (is_end_intentional_intentional_attr(cur_decl, 1))
116906 + return MARK_YES;
116907 + break;
116908 + case PARM_DECL: {
116909 + unsigned int argnum;
116910 +
116911 + cur_decl = DECL_ORIGIN(current_function_decl);
116912 + argnum = find_arg_number_tree(node, cur_decl);
116913 + if (argnum == CANNOT_FIND_ARG)
116914 + return MARK_NO;
116915 + if (is_yes_intentional_attr(cur_decl, argnum))
116916 + return MARK_YES;
116917 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
116918 + return MARK_NOT_INTENTIONAL;
116919 + break;
116920 + }
116921 + case FUNCTION_DECL:
116922 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
116923 + return MARK_TURN_OFF;
116924 + break;
116925 + default:
116926 + break;
116927 + }
116928 + return MARK_NO;
116929 +}
116930 +
116931 +// Search for the intentional_overflow attribute on the last nodes
116932 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
116933 +{
116934 + unsigned int i;
116935 + tree last_node;
116936 + enum mark mark = MARK_NO;
116937 +
116938 +#if BUILDING_GCC_VERSION <= 4007
116939 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
116940 +#else
116941 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
116942 +#endif
116943 + mark = get_intentional_attr_type(last_node);
116944 + if (mark != MARK_NO)
116945 + break;
116946 + }
116947 + return mark;
116948 +}
116949 +
116950 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
116951 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
116952 + */
116953 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
116954 +{
116955 + if (!cur_node->intentional_mark_from_gimple)
116956 + return false;
116957 +
116958 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
116959 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
116960 + else
116961 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116962 +
116963 + // skip param decls
116964 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
116965 + return true;
116966 + return true;
116967 +}
116968 +
116969 +/* Search intentional_overflow attribute on caller and on callee too.
116970 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
116971 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
116972 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
116973 +*/
116974 +static void check_intentional_attribute_ipa(struct interesting_node *cur_node)
116975 +{
116976 + const_tree fndecl;
116977 +
116978 + if (is_intentional_attribute_from_gimple(cur_node))
116979 + return;
116980 +
116981 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
116982 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116983 + return;
116984 + }
116985 +
116986 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
116987 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
116988 + return;
116989 + }
116990 +
116991 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
116992 + return;
116993 +
116994 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
116995 + if (is_turn_off_intentional_attr(fndecl)) {
116996 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
116997 + return;
116998 + }
116999 +
117000 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
117001 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
117002 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
117003 + cur_node->intentional_attr_decl = MARK_YES;
117004 +
117005 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
117006 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
117007 +}
117008 +
117009 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
117010 +static bool skip_asm(const_tree arg)
117011 +{
117012 + gimple def_stmt = get_def_stmt(arg);
117013 +
117014 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
117015 + return false;
117016 +
117017 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
117018 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
117019 +}
117020 +
117021 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
117022 +{
117023 + gimple phi = get_def_stmt(result);
117024 + unsigned int i, n = gimple_phi_num_args(phi);
117025 +
117026 + pointer_set_insert(visited, phi);
117027 + for (i = 0; i < n; i++) {
117028 + tree arg = gimple_phi_arg_def(phi, i);
117029 +
117030 + walk_use_def(visited, cur_node, arg);
117031 + }
117032 +}
117033 +
117034 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
117035 +{
117036 + gimple def_stmt = get_def_stmt(lhs);
117037 + tree rhs1, rhs2;
117038 +
117039 + rhs1 = gimple_assign_rhs1(def_stmt);
117040 + rhs2 = gimple_assign_rhs2(def_stmt);
117041 +
117042 + walk_use_def(visited, cur_node, rhs1);
117043 + walk_use_def(visited, cur_node, rhs2);
117044 +}
117045 +
117046 +static void insert_last_node(struct interesting_node *cur_node, tree node)
117047 +{
117048 + unsigned int i;
117049 + tree element;
117050 + enum tree_code code;
117051 +
117052 + gcc_assert(node != NULL_TREE);
117053 +
117054 + if (is_gimple_constant(node))
117055 + return;
117056 +
117057 + code = TREE_CODE(node);
117058 + if (code == VAR_DECL) {
117059 + node = DECL_ORIGIN(node);
117060 + code = TREE_CODE(node);
117061 + }
117062 +
117063 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
117064 + return;
117065 +
117066 +#if BUILDING_GCC_VERSION <= 4007
117067 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
117068 +#else
117069 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
117070 +#endif
117071 + if (operand_equal_p(node, element, 0))
117072 + return;
117073 + }
117074 +
117075 +#if BUILDING_GCC_VERSION <= 4007
117076 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
117077 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
117078 +#else
117079 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
117080 + vec_safe_push(cur_node->last_nodes, node);
117081 +#endif
117082 +}
117083 +
117084 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
117085 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
117086 +{
117087 + if (!is_size_overflow_asm(stmt))
117088 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
117089 +}
117090 +
117091 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
117092 + * and component refs (for checking the intentional_overflow attribute).
117093 + */
117094 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
117095 +{
117096 + const_gimple def_stmt;
117097 +
117098 + if (TREE_CODE(lhs) != SSA_NAME) {
117099 + insert_last_node(cur_node, lhs);
117100 + return;
117101 + }
117102 +
117103 + def_stmt = get_def_stmt(lhs);
117104 + if (!def_stmt)
117105 + return;
117106 +
117107 + if (pointer_set_insert(visited, def_stmt))
117108 + return;
117109 +
117110 + switch (gimple_code(def_stmt)) {
117111 + case GIMPLE_NOP:
117112 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
117113 + case GIMPLE_ASM:
117114 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
117115 + case GIMPLE_CALL: {
117116 + tree fndecl = gimple_call_fndecl(def_stmt);
117117 +
117118 + if (fndecl == NULL_TREE)
117119 + return;
117120 + insert_last_node(cur_node, fndecl);
117121 + return;
117122 + }
117123 + case GIMPLE_PHI:
117124 + return walk_use_def_phi(visited, cur_node, lhs);
117125 + case GIMPLE_ASSIGN:
117126 + switch (gimple_num_ops(def_stmt)) {
117127 + case 2:
117128 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
117129 + case 3:
117130 + return walk_use_def_binary(visited, cur_node, lhs);
117131 + }
117132 + default:
117133 + debug_gimple_stmt((gimple)def_stmt);
117134 + error("%s: unknown gimple code", __func__);
117135 + gcc_unreachable();
117136 + }
117137 +}
117138 +
117139 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
117140 +static void set_last_nodes(struct interesting_node *cur_node)
117141 +{
117142 + struct pointer_set_t *visited;
117143 +
117144 + visited = pointer_set_create();
117145 + walk_use_def(visited, cur_node, cur_node->node);
117146 + pointer_set_destroy(visited);
117147 +}
117148 +
117149 +enum precond {
117150 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
117151 +};
117152 +
117153 +/* 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.
117154 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
117155 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
117156 + * 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.
117157 + */
117158 +static enum precond check_preconditions(struct interesting_node *cur_node)
117159 +{
117160 + bool interesting_conditions[3] = {false, false, false};
117161 +
117162 + set_last_nodes(cur_node);
117163 +
117164 + check_intentional_attribute_ipa(cur_node);
117165 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
117166 + return NO_ATTRIBUTE_SEARCH;
117167 +
117168 + search_interesting_conditions(cur_node, interesting_conditions);
117169 +
117170 + // error code
117171 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
117172 + return NO_ATTRIBUTE_SEARCH;
117173 +
117174 + // unnecessary overflow check
117175 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
117176 + return NO_CHECK_INSERT;
117177 +
117178 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
117179 + return NO_CHECK_INSERT;
117180 +
117181 + return NONE;
117182 +}
117183 +
117184 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
117185 + * 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
117186 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
117187 + */
117188 +static struct next_cgraph_node *handle_interesting_stmt(struct next_cgraph_node *cnodes, struct interesting_node *cur_node, struct cgraph_node *caller_node)
117189 +{
117190 + enum precond ret;
117191 + struct pointer_set_t *visited;
117192 + tree new_node, orig_node = cur_node->node;
117193 +
117194 + ret = check_preconditions(cur_node);
117195 + if (ret == NO_ATTRIBUTE_SEARCH)
117196 + return cnodes;
117197 +
117198 + cnodes = search_overflow_attribute(cnodes, cur_node);
117199 +
117200 + if (ret == NO_CHECK_INSERT)
117201 + return cnodes;
117202 +
117203 + visited = pointer_set_create();
117204 + new_node = expand(visited, caller_node, orig_node);
117205 + pointer_set_destroy(visited);
117206 +
117207 + if (new_node == NULL_TREE)
117208 + return cnodes;
117209 +
117210 + change_orig_node(cur_node, new_node);
117211 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
117212 +
117213 + return cnodes;
117214 +}
117215 +
117216 +// Check visited interesting nodes.
117217 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
117218 +{
117219 + struct interesting_node *cur;
117220 +
117221 + for (cur = head; cur; cur = cur->next) {
117222 + if (!operand_equal_p(node, cur->node, 0))
117223 + continue;
117224 + if (num != cur->num)
117225 + continue;
117226 + if (first_stmt == cur->first_stmt)
117227 + return true;
117228 + }
117229 + return false;
117230 +}
117231 +
117232 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
117233 + 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
117234 + 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
117235 + the intentional_overflow attribute check. They are collected by set_last_nodes().
117236 + num: arg count of a call stmt or 0 when it is a ret
117237 + node: the recursion starts from here, it is a call arg or a return value
117238 + 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.
117239 + intentional_attr_decl: intentional_overflow attribute of the callee function
117240 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
117241 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
117242 + */
117243 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
117244 +{
117245 + struct interesting_node *new_node;
117246 + tree fndecl;
117247 + enum gimple_code code;
117248 +
117249 + gcc_assert(node != NULL_TREE);
117250 + code = gimple_code(first_stmt);
117251 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
117252 +
117253 + if (num == CANNOT_FIND_ARG)
117254 + return head;
117255 +
117256 + if (skip_types(node))
117257 + return head;
117258 +
117259 + if (skip_asm(node))
117260 + return head;
117261 +
117262 + if (is_gimple_call(first_stmt))
117263 + fndecl = gimple_call_fndecl(first_stmt);
117264 + else
117265 + fndecl = current_function_decl;
117266 +
117267 + if (fndecl == NULL_TREE)
117268 + return head;
117269 +
117270 + if (is_in_interesting_node(head, first_stmt, node, num))
117271 + return head;
117272 +
117273 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
117274 +
117275 + new_node->next = NULL;
117276 + new_node->first_stmt = first_stmt;
117277 +#if BUILDING_GCC_VERSION <= 4007
117278 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
117279 +#else
117280 + vec_alloc(new_node->last_nodes, VEC_LEN);
117281 +#endif
117282 + new_node->num = num;
117283 + new_node->node = node;
117284 + new_node->fndecl = fndecl;
117285 + new_node->intentional_attr_decl = MARK_NO;
117286 + new_node->intentional_attr_cur_fndecl = MARK_NO;
117287 + new_node->intentional_mark_from_gimple = asm_stmt;
117288 +
117289 + if (!head)
117290 + return new_node;
117291 +
117292 + new_node->next = head;
117293 + return new_node;
117294 +}
117295 +
117296 +/* 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).
117297 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
117298 + */
117299 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
117300 +{
117301 + struct next_cgraph_node *cur_node;
117302 + tree ret = gimple_return_retval(stmt);
117303 +
117304 + if (ret == NULL_TREE)
117305 + return head;
117306 +
117307 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
117308 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
117309 + continue;
117310 + if (cur_node->num == 0)
117311 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
117312 + }
117313 +
117314 + return head;
117315 +}
117316 +
117317 +/* 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).
117318 + * If the call stmt is in the next cgraph node list then it's an interesting call.
117319 + */
117320 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
117321 +{
117322 + unsigned int argnum;
117323 + tree arg;
117324 + const_tree fndecl;
117325 + struct next_cgraph_node *cur_node;
117326 +
117327 + fndecl = gimple_call_fndecl(stmt);
117328 + if (fndecl == NULL_TREE)
117329 + return head;
117330 +
117331 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
117332 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
117333 + continue;
117334 + argnum = get_correct_arg_count(cur_node->num, fndecl);
117335 + gcc_assert(argnum != CANNOT_FIND_ARG);
117336 + if (argnum == 0)
117337 + continue;
117338 +
117339 + arg = gimple_call_arg(stmt, argnum - 1);
117340 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
117341 + }
117342 +
117343 + return head;
117344 +}
117345 +
117346 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
117347 +{
117348 + if (!operand_equal_p(orig_node, node, 0))
117349 + return WRONG_NODE;
117350 + if (skip_types(node))
117351 + return WRONG_NODE;
117352 + return ret_count;
117353 +}
117354 +
117355 +// Get the index of the rhs node in an assignment
117356 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
117357 +{
117358 + const_tree rhs1, rhs2;
117359 + unsigned int ret;
117360 +
117361 + gcc_assert(stmt);
117362 + gcc_assert(is_gimple_assign(stmt));
117363 +
117364 + rhs1 = gimple_assign_rhs1(stmt);
117365 + gcc_assert(rhs1 != NULL_TREE);
117366 +
117367 + switch (gimple_num_ops(stmt)) {
117368 + case 2:
117369 + return check_ops(node, rhs1, 1);
117370 + case 3:
117371 + ret = check_ops(node, rhs1, 1);
117372 + if (ret != WRONG_NODE)
117373 + return ret;
117374 +
117375 + rhs2 = gimple_assign_rhs2(stmt);
117376 + gcc_assert(rhs2 != NULL_TREE);
117377 + return check_ops(node, rhs2, 2);
117378 + default:
117379 + gcc_unreachable();
117380 + }
117381 +}
117382 +
117383 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
117384 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
117385 +{
117386 + unsigned int i;
117387 +
117388 + if (gimple_call_fndecl(stmt) == NULL_TREE)
117389 + return CANNOT_FIND_ARG;
117390 +
117391 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
117392 + tree node;
117393 +
117394 + node = gimple_call_arg(stmt, i);
117395 + if (!operand_equal_p(arg, node, 0))
117396 + continue;
117397 + if (!skip_types(node))
117398 + return i + 1;
117399 + }
117400 +
117401 + return CANNOT_FIND_ARG;
117402 +}
117403 +
117404 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
117405 + * any of return, call or assignment stmts (because of inlining).
117406 + */
117407 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
117408 +{
117409 + use_operand_p use_p;
117410 + imm_use_iterator imm_iter;
117411 + unsigned int argnum;
117412 +
117413 + gcc_assert(TREE_CODE(node) == SSA_NAME);
117414 +
117415 + if (pointer_set_insert(visited, node))
117416 + return head;
117417 +
117418 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
117419 + gimple stmt = USE_STMT(use_p);
117420 +
117421 + if (stmt == NULL)
117422 + return head;
117423 + if (is_gimple_debug(stmt))
117424 + continue;
117425 +
117426 + switch (gimple_code(stmt)) {
117427 + case GIMPLE_CALL:
117428 + argnum = find_arg_number_gimple(node, stmt);
117429 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
117430 + break;
117431 + case GIMPLE_RETURN:
117432 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
117433 + break;
117434 + case GIMPLE_ASSIGN:
117435 + argnum = get_assign_ops_count(stmt, node);
117436 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
117437 + break;
117438 + case GIMPLE_PHI: {
117439 + tree result = gimple_phi_result(stmt);
117440 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
117441 + break;
117442 + }
117443 + case GIMPLE_ASM:
117444 + if (gimple_asm_noutputs(stmt) != 0)
117445 + break;
117446 + if (!is_size_overflow_asm(stmt))
117447 + break;
117448 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
117449 + break;
117450 + case GIMPLE_COND:
117451 + case GIMPLE_SWITCH:
117452 + break;
117453 + default:
117454 + debug_gimple_stmt(stmt);
117455 + gcc_unreachable();
117456 + break;
117457 + }
117458 + }
117459 + return head;
117460 +}
117461 +
117462 +static void remove_size_overflow_asm(gimple stmt)
117463 +{
117464 + gimple_stmt_iterator gsi;
117465 + tree input, output;
117466 +
117467 + if (!is_size_overflow_asm(stmt))
117468 + return;
117469 +
117470 + if (gimple_asm_noutputs(stmt) == 0) {
117471 + gsi = gsi_for_stmt(stmt);
117472 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
117473 + gsi_remove(&gsi, true);
117474 + return;
117475 + }
117476 +
117477 + input = gimple_asm_input_op(stmt, 0);
117478 + output = gimple_asm_output_op(stmt, 0);
117479 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
117480 +}
117481 +
117482 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
117483 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
117484 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
117485 + */
117486 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
117487 +{
117488 + const_tree output;
117489 + struct pointer_set_t *visited;
117490 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
117491 +
117492 + if (!is_size_overflow_asm(stmt))
117493 + return head;
117494 +
117495 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
117496 + intentional_asm = stmt;
117497 +
117498 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
117499 +
117500 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
117501 + return head;
117502 +
117503 + if (gimple_asm_noutputs(stmt) == 0) {
117504 + const_tree input;
117505 +
117506 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
117507 + return head;
117508 +
117509 + input = gimple_asm_input_op(stmt, 0);
117510 + remove_size_overflow_asm(stmt);
117511 + if (is_gimple_constant(TREE_VALUE(input)))
117512 + return head;
117513 + visited = pointer_set_create();
117514 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
117515 + pointer_set_destroy(visited);
117516 + return head;
117517 + }
117518 +
117519 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
117520 + remove_size_overflow_asm(stmt);
117521 +
117522 + visited = pointer_set_create();
117523 + output = gimple_asm_output_op(stmt, 0);
117524 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
117525 + pointer_set_destroy(visited);
117526 + return head;
117527 +}
117528 +
117529 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
117530 + * or a call stmt or a return stmt and store them in the interesting_node list
117531 + */
117532 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
117533 +{
117534 + basic_block bb;
117535 + struct interesting_node *head = NULL;
117536 +
117537 + FOR_ALL_BB_FN(bb, cfun) {
117538 + gimple_stmt_iterator gsi;
117539 +
117540 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
117541 + enum gimple_code code;
117542 + gimple stmt = gsi_stmt(gsi);
117543 +
117544 + code = gimple_code(stmt);
117545 +
117546 + if (code == GIMPLE_ASM)
117547 + head = handle_stmt_by_size_overflow_asm(stmt, head);
117548 +
117549 + if (!next_node)
117550 + continue;
117551 + if (code == GIMPLE_CALL)
117552 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
117553 + if (code == GIMPLE_RETURN)
117554 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
117555 + }
117556 + }
117557 + return head;
117558 +}
117559 +
117560 +static void set_current_function_decl(tree fndecl)
117561 +{
117562 + gcc_assert(fndecl != NULL_TREE);
117563 +
117564 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
117565 + calculate_dominance_info(CDI_DOMINATORS);
117566 + current_function_decl = fndecl;
117567 +}
117568 +
117569 +static void unset_current_function_decl(void)
117570 +{
117571 + free_dominance_info(CDI_DOMINATORS);
117572 + pop_cfun();
117573 + current_function_decl = NULL_TREE;
117574 +}
117575 +
117576 +static void free_interesting_node(struct interesting_node *head)
117577 +{
117578 + struct interesting_node *cur;
117579 +
117580 + while (head) {
117581 + cur = head->next;
117582 +#if BUILDING_GCC_VERSION <= 4007
117583 + VEC_free(tree, gc, head->last_nodes);
117584 +#else
117585 + vec_free(head->last_nodes);
117586 +#endif
117587 + free(head);
117588 + head = cur;
117589 + }
117590 +}
117591 +
117592 +static struct visited *insert_visited_function(struct visited *head, struct interesting_node *cur_node)
117593 +{
117594 + struct visited *new_visited;
117595 +
117596 + new_visited = (struct visited *)xmalloc(sizeof(*new_visited));
117597 + new_visited->fndecl = cur_node->fndecl;
117598 + new_visited->num = cur_node->num;
117599 + new_visited->next = NULL;
117600 +
117601 + if (!head)
117602 + return new_visited;
117603 +
117604 + new_visited->next = head;
117605 + return new_visited;
117606 +}
117607 +
117608 +/* 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
117609 + * it is a visited function.
117610 + */
117611 +static bool is_visited_function(struct visited *head, struct interesting_node *cur_node)
117612 +{
117613 + struct visited *cur;
117614 +
117615 + if (!head)
117616 + return false;
117617 +
117618 + if (get_stmt_flag(cur_node->first_stmt) != VISITED_STMT)
117619 + return false;
117620 +
117621 + for (cur = head; cur; cur = cur->next) {
117622 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
117623 + continue;
117624 + if (cur_node->num == cur->num)
117625 + return true;
117626 + }
117627 + return false;
117628 +}
117629 +
117630 +static void free_next_cgraph_node(struct next_cgraph_node *head)
117631 +{
117632 + struct next_cgraph_node *cur;
117633 +
117634 + while (head) {
117635 + cur = head->next;
117636 + free(head);
117637 + head = cur;
117638 + }
117639 +}
117640 +
117641 +static void remove_all_size_overflow_asm(void)
117642 +{
117643 + basic_block bb;
117644 +
117645 + FOR_ALL_BB_FN(bb, cfun) {
117646 + gimple_stmt_iterator si;
117647 +
117648 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117649 + remove_size_overflow_asm(gsi_stmt(si));
117650 + }
117651 +}
117652 +
117653 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
117654 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
117655 + * the newly collected interesting functions (they are interesting if there is control flow between
117656 + * the interesting stmts and them).
117657 + */
117658 +static struct visited *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited *visited)
117659 +{
117660 + struct interesting_node *head, *cur_node;
117661 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
117662 +
117663 + set_current_function_decl(NODE_DECL(node));
117664 + call_count = 0;
117665 +
117666 + head = collect_interesting_stmts(next_node);
117667 +
117668 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
117669 + if (is_visited_function(visited, cur_node))
117670 + continue;
117671 + cnodes_head = handle_interesting_stmt(cnodes_head, cur_node, node);
117672 + set_stmt_flag(cur_node->first_stmt, VISITED_STMT);
117673 + visited = insert_visited_function(visited, cur_node);
117674 + }
117675 +
117676 + free_interesting_node(head);
117677 + remove_all_size_overflow_asm();
117678 + unset_current_function_decl();
117679 +
117680 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
117681 + visited = handle_function(cur_cnodes->current_function, cur_cnodes, visited);
117682 +
117683 + free_next_cgraph_node(cnodes_head);
117684 + return visited;
117685 +}
117686 +
117687 +static void free_visited(struct visited *head)
117688 +{
117689 + struct visited *cur;
117690 +
117691 + while (head) {
117692 + cur = head->next;
117693 + free(head);
117694 + head = cur;
117695 + }
117696 +}
117697 +
117698 +// erase the local flag
117699 +static void set_plf_false(void)
117700 +{
117701 + basic_block bb;
117702 +
117703 + FOR_ALL_BB_FN(bb, cfun) {
117704 + gimple_stmt_iterator si;
117705 +
117706 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117707 + set_stmt_flag(gsi_stmt(si), NO_FLAGS);
117708 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
117709 + set_stmt_flag(gsi_stmt(si), NO_FLAGS);
117710 + }
117711 +}
117712 +
117713 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
117714 +static unsigned int search_function(void)
117715 +{
117716 + struct cgraph_node *node;
117717 + struct visited *visited = NULL;
117718 +
117719 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117720 + set_current_function_decl(NODE_DECL(node));
117721 + set_plf_false();
117722 + unset_current_function_decl();
117723 + }
117724 +
117725 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117726 + gcc_assert(cgraph_function_flags_ready);
117727 +#if BUILDING_GCC_VERSION <= 4007
117728 + gcc_assert(node->reachable);
117729 +#endif
117730 +
117731 + visited = handle_function(node, NULL, visited);
117732 + }
117733 +
117734 + free_visited(visited);
117735 + return 0;
117736 +}
117737 +
117738 +#if BUILDING_GCC_VERSION >= 4009
117739 +static const struct pass_data ipa_pass_data = {
117740 +#else
117741 +static struct ipa_opt_pass_d ipa_pass = {
117742 + .pass = {
117743 +#endif
117744 + .type = SIMPLE_IPA_PASS,
117745 + .name = "size_overflow",
117746 +#if BUILDING_GCC_VERSION >= 4008
117747 + .optinfo_flags = OPTGROUP_NONE,
117748 +#endif
117749 +#if BUILDING_GCC_VERSION >= 4009
117750 + .has_gate = false,
117751 + .has_execute = true,
117752 +#else
117753 + .gate = NULL,
117754 + .execute = search_function,
117755 + .sub = NULL,
117756 + .next = NULL,
117757 + .static_pass_number = 0,
117758 +#endif
117759 + .tv_id = TV_NONE,
117760 + .properties_required = 0,
117761 + .properties_provided = 0,
117762 + .properties_destroyed = 0,
117763 + .todo_flags_start = 0,
117764 + .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,
117765 +#if BUILDING_GCC_VERSION < 4009
117766 + },
117767 + .generate_summary = NULL,
117768 + .write_summary = NULL,
117769 + .read_summary = NULL,
117770 +#if BUILDING_GCC_VERSION >= 4006
117771 + .write_optimization_summary = NULL,
117772 + .read_optimization_summary = NULL,
117773 +#endif
117774 + .stmt_fixup = NULL,
117775 + .function_transform_todo_flags_start = 0,
117776 + .function_transform = NULL,
117777 + .variable_transform = NULL,
117778 +#endif
117779 +};
117780 +
117781 +#if BUILDING_GCC_VERSION >= 4009
117782 +namespace {
117783 +class ipa_pass : public ipa_opt_pass_d {
117784 +public:
117785 + ipa_pass() : ipa_opt_pass_d(ipa_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
117786 + unsigned int execute() { return search_function(); }
117787 +};
117788 +}
117789 +#endif
117790 +
117791 +static struct opt_pass *make_ipa_pass(void)
117792 +{
117793 +#if BUILDING_GCC_VERSION >= 4009
117794 + return new ipa_pass();
117795 +#else
117796 + return &ipa_pass.pass;
117797 +#endif
117798 +}
117799 +
117800 +// data for the size_overflow asm stmt
117801 +struct asm_data {
117802 + gimple def_stmt;
117803 + tree input;
117804 + tree output;
117805 +};
117806 +
117807 +#if BUILDING_GCC_VERSION <= 4007
117808 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
117809 +#else
117810 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
117811 +#endif
117812 +{
117813 + tree list;
117814 +#if BUILDING_GCC_VERSION <= 4007
117815 + VEC(tree, gc) *vec_list = NULL;
117816 +#else
117817 + vec<tree, va_gc> *vec_list = NULL;
117818 +#endif
117819 +
117820 + list = build_tree_list(NULL_TREE, string);
117821 + list = chainon(NULL_TREE, build_tree_list(list, io));
117822 +#if BUILDING_GCC_VERSION <= 4007
117823 + VEC_safe_push(tree, gc, vec_list, list);
117824 +#else
117825 + vec_safe_push(vec_list, list);
117826 +#endif
117827 + return vec_list;
117828 +}
117829 +
117830 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
117831 +{
117832 + gimple asm_stmt;
117833 + gimple_stmt_iterator gsi;
117834 +#if BUILDING_GCC_VERSION <= 4007
117835 + VEC(tree, gc) *input, *output = NULL;
117836 +#else
117837 + vec<tree, va_gc> *input, *output = NULL;
117838 +#endif
117839 +
117840 + input = create_asm_io_list(str_input, asm_data->input);
117841 +
117842 + if (asm_data->output)
117843 + output = create_asm_io_list(str_output, asm_data->output);
117844 +
117845 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
117846 + gsi = gsi_for_stmt(asm_data->def_stmt);
117847 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
117848 +
117849 + if (asm_data->output)
117850 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
117851 +}
117852 +
117853 +static void replace_call_lhs(const struct asm_data *asm_data)
117854 +{
117855 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
117856 + update_stmt(asm_data->def_stmt);
117857 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
117858 +}
117859 +
117860 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
117861 +{
117862 + enum mark cur_fndecl_attr;
117863 + gimple phi = get_def_stmt(result);
117864 + unsigned int i, n = gimple_phi_num_args(phi);
117865 +
117866 + pointer_set_insert(visited, phi);
117867 + for (i = 0; i < n; i++) {
117868 + tree arg = gimple_phi_arg_def(phi, i);
117869 +
117870 + cur_fndecl_attr = search_intentional(visited, arg);
117871 + if (cur_fndecl_attr != MARK_NO)
117872 + return cur_fndecl_attr;
117873 + }
117874 + return MARK_NO;
117875 +}
117876 +
117877 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
117878 +{
117879 + enum mark cur_fndecl_attr;
117880 + const_tree rhs1, rhs2;
117881 + gimple def_stmt = get_def_stmt(lhs);
117882 +
117883 + rhs1 = gimple_assign_rhs1(def_stmt);
117884 + rhs2 = gimple_assign_rhs2(def_stmt);
117885 +
117886 + cur_fndecl_attr = search_intentional(visited, rhs1);
117887 + if (cur_fndecl_attr != MARK_NO)
117888 + return cur_fndecl_attr;
117889 + return search_intentional(visited, rhs2);
117890 +}
117891 +
117892 +// Look up the intentional_overflow attribute on the caller and the callee functions.
117893 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
117894 +{
117895 + const_gimple def_stmt;
117896 +
117897 + if (TREE_CODE(lhs) != SSA_NAME)
117898 + return get_intentional_attr_type(lhs);
117899 +
117900 + def_stmt = get_def_stmt(lhs);
117901 + if (!def_stmt)
117902 + return MARK_NO;
117903 +
117904 + if (pointer_set_contains(visited, def_stmt))
117905 + return MARK_NO;
117906 +
117907 + switch (gimple_code(def_stmt)) {
117908 + case GIMPLE_NOP:
117909 + return search_intentional(visited, SSA_NAME_VAR(lhs));
117910 + case GIMPLE_ASM:
117911 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
117912 + return MARK_TURN_OFF;
117913 + return MARK_NO;
117914 + case GIMPLE_CALL:
117915 + return MARK_NO;
117916 + case GIMPLE_PHI:
117917 + return search_intentional_phi(visited, lhs);
117918 + case GIMPLE_ASSIGN:
117919 + switch (gimple_num_ops(def_stmt)) {
117920 + case 2:
117921 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
117922 + case 3:
117923 + return search_intentional_binary(visited, lhs);
117924 + }
117925 + case GIMPLE_RETURN:
117926 + return MARK_NO;
117927 + default:
117928 + debug_gimple_stmt((gimple)def_stmt);
117929 + error("%s: unknown gimple code", __func__);
117930 + gcc_unreachable();
117931 + }
117932 +}
117933 +
117934 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
117935 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
117936 +{
117937 + const_tree fndecl;
117938 + struct pointer_set_t *visited;
117939 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
117940 +
117941 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
117942 + if (is_end_intentional_intentional_attr(fndecl, argnum))
117943 + decl_attr = MARK_NOT_INTENTIONAL;
117944 + else if (is_yes_intentional_attr(fndecl, argnum))
117945 + decl_attr = MARK_YES;
117946 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
117947 + return MARK_TURN_OFF;
117948 + }
117949 +
117950 + visited = pointer_set_create();
117951 + cur_fndecl_attr = search_intentional(visited, arg);
117952 + pointer_set_destroy(visited);
117953 +
117954 + switch (cur_fndecl_attr) {
117955 + case MARK_NO:
117956 + case MARK_TURN_OFF:
117957 + return cur_fndecl_attr;
117958 + default:
117959 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
117960 + return MARK_YES;
117961 + }
117962 +}
117963 +
117964 +static void check_missing_size_overflow_attribute(tree var)
117965 +{
117966 + tree orig_fndecl;
117967 + unsigned int num;
117968 +
117969 + if (is_a_return_check(var))
117970 + orig_fndecl = DECL_ORIGIN(var);
117971 + else
117972 + orig_fndecl = DECL_ORIGIN(current_function_decl);
117973 +
117974 + num = get_function_num(var, orig_fndecl);
117975 + if (num == CANNOT_FIND_ARG)
117976 + return;
117977 +
117978 + is_missing_function(orig_fndecl, num);
117979 +}
117980 +
117981 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
117982 +{
117983 + gimple phi = get_def_stmt(result);
117984 + unsigned int i, n = gimple_phi_num_args(phi);
117985 +
117986 + pointer_set_insert(visited, phi);
117987 + for (i = 0; i < n; i++) {
117988 + tree arg = gimple_phi_arg_def(phi, i);
117989 +
117990 + search_size_overflow_attribute(visited, arg);
117991 + }
117992 +}
117993 +
117994 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
117995 +{
117996 + const_gimple def_stmt = get_def_stmt(lhs);
117997 + tree rhs1, rhs2;
117998 +
117999 + rhs1 = gimple_assign_rhs1(def_stmt);
118000 + rhs2 = gimple_assign_rhs2(def_stmt);
118001 +
118002 + search_size_overflow_attribute(visited, rhs1);
118003 + search_size_overflow_attribute(visited, rhs2);
118004 +}
118005 +
118006 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
118007 +{
118008 + const_gimple def_stmt;
118009 +
118010 + if (TREE_CODE(lhs) == PARM_DECL) {
118011 + check_missing_size_overflow_attribute(lhs);
118012 + return;
118013 + }
118014 +
118015 + def_stmt = get_def_stmt(lhs);
118016 + if (!def_stmt)
118017 + return;
118018 +
118019 + if (pointer_set_insert(visited, def_stmt))
118020 + return;
118021 +
118022 + switch (gimple_code(def_stmt)) {
118023 + case GIMPLE_NOP:
118024 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
118025 + case GIMPLE_ASM:
118026 + return;
118027 + case GIMPLE_CALL: {
118028 + tree fndecl = gimple_call_fndecl(def_stmt);
118029 +
118030 + if (fndecl == NULL_TREE)
118031 + return;
118032 + check_missing_size_overflow_attribute(fndecl);
118033 + return;
118034 + }
118035 + case GIMPLE_PHI:
118036 + return search_size_overflow_attribute_phi(visited, lhs);
118037 + case GIMPLE_ASSIGN:
118038 + switch (gimple_num_ops(def_stmt)) {
118039 + case 2:
118040 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
118041 + case 3:
118042 + return search_size_overflow_attribute_binary(visited, lhs);
118043 + }
118044 + default:
118045 + debug_gimple_stmt((gimple)def_stmt);
118046 + error("%s: unknown gimple code", __func__);
118047 + gcc_unreachable();
118048 + }
118049 +}
118050 +
118051 +// Search missing entries in the hash table (invoked from the gimple pass)
118052 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
118053 +{
118054 + tree fndecl = NULL_TREE;
118055 + tree lhs;
118056 + struct pointer_set_t *visited;
118057 +
118058 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
118059 + return;
118060 +
118061 + if (num == 0) {
118062 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
118063 + lhs = gimple_return_retval(stmt);
118064 + } else {
118065 + gcc_assert(is_gimple_call(stmt));
118066 + lhs = gimple_call_arg(stmt, num - 1);
118067 + fndecl = gimple_call_fndecl(stmt);
118068 + }
118069 +
118070 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
118071 + return;
118072 +
118073 + visited = pointer_set_create();
118074 + search_size_overflow_attribute(visited, lhs);
118075 + pointer_set_destroy(visited);
118076 +}
118077 +
118078 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
118079 +{
118080 + gimple_stmt_iterator gsi;
118081 + gimple assign;
118082 +
118083 + assign = gimple_build_assign(asm_data->input, asm_data->output);
118084 + gsi = gsi_for_stmt(stmt);
118085 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
118086 + asm_data->def_stmt = assign;
118087 +
118088 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
118089 + asm_data->output = make_ssa_name(asm_data->output, stmt);
118090 + if (gimple_code(stmt) == GIMPLE_RETURN)
118091 + gimple_return_set_retval(stmt, asm_data->output);
118092 + else
118093 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
118094 + update_stmt(stmt);
118095 +}
118096 +
118097 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
118098 +{
118099 + const char *fn_name;
118100 + char *asm_comment;
118101 + unsigned int len;
118102 +
118103 + if (argnum == 0)
118104 + fn_name = DECL_NAME_POINTER(current_function_decl);
118105 + else
118106 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
118107 +
118108 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
118109 + gcc_assert(len > 0);
118110 +
118111 + return asm_comment;
118112 +}
118113 +
118114 +static const char *convert_mark_to_str(enum mark mark)
118115 +{
118116 + switch (mark) {
118117 + case MARK_NO:
118118 + return OK_ASM_STR;
118119 + case MARK_YES:
118120 + case MARK_NOT_INTENTIONAL:
118121 + return YES_ASM_STR;
118122 + case MARK_TURN_OFF:
118123 + return TURN_OFF_ASM_STR;
118124 + }
118125 +
118126 + gcc_unreachable();
118127 +}
118128 +
118129 +/* Create the input of the size_overflow asm stmt.
118130 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
118131 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
118132 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
118133 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
118134 + */
118135 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
118136 +{
118137 + if (!asm_data->def_stmt) {
118138 + asm_data->input = NULL_TREE;
118139 + return;
118140 + }
118141 +
118142 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
118143 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
118144 +
118145 + switch (gimple_code(asm_data->def_stmt)) {
118146 + case GIMPLE_ASSIGN:
118147 + case GIMPLE_CALL:
118148 + replace_call_lhs(asm_data);
118149 + break;
118150 + case GIMPLE_PHI:
118151 + create_output_from_phi(stmt, argnum, asm_data);
118152 + break;
118153 + case GIMPLE_NOP: {
118154 + enum mark mark;
118155 + const char *mark_str;
118156 + char *asm_comment;
118157 +
118158 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
118159 +
118160 + asm_data->input = asm_data->output;
118161 + asm_data->output = NULL;
118162 + asm_data->def_stmt = stmt;
118163 +
118164 + mark_str = convert_mark_to_str(mark);
118165 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
118166 +
118167 + create_asm_stmt(asm_comment, build_string(2, "rm"), NULL, asm_data);
118168 + free(asm_comment);
118169 + asm_data->input = NULL_TREE;
118170 + break;
118171 + }
118172 + case GIMPLE_ASM:
118173 + if (is_size_overflow_asm(asm_data->def_stmt)) {
118174 + asm_data->input = NULL_TREE;
118175 + break;
118176 + }
118177 + default:
118178 + debug_gimple_stmt(asm_data->def_stmt);
118179 + gcc_unreachable();
118180 + }
118181 +}
118182 +
118183 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
118184 + * is of the right kind create the appropriate size_overflow asm stmts:
118185 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
118186 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
118187 + */
118188 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
118189 +{
118190 + struct asm_data asm_data;
118191 + const char *mark_str;
118192 + char *asm_comment;
118193 + enum mark mark;
118194 +
118195 + if (is_gimple_constant(output_node))
118196 + return;
118197 +
118198 + asm_data.output = output_node;
118199 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
118200 + if (mark != MARK_TURN_OFF)
118201 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
118202 +
118203 + asm_data.def_stmt = get_def_stmt(asm_data.output);
118204 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
118205 + return;
118206 +
118207 + create_asm_input(stmt, argnum, &asm_data);
118208 + if (asm_data.input == NULL_TREE)
118209 + return;
118210 +
118211 + mark_str = convert_mark_to_str(mark);
118212 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
118213 + create_asm_stmt(asm_comment, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
118214 + free(asm_comment);
118215 +}
118216 +
118217 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
118218 +static bool create_mark_asm(gimple stmt, enum mark mark)
118219 +{
118220 + struct asm_data asm_data;
118221 + const char *asm_str;
118222 +
118223 + switch (mark) {
118224 + case MARK_TURN_OFF:
118225 + asm_str = TURN_OFF_ASM_STR;
118226 + break;
118227 + case MARK_NOT_INTENTIONAL:
118228 + case MARK_YES:
118229 + asm_str = YES_ASM_STR;
118230 + break;
118231 + default:
118232 + gcc_unreachable();
118233 + }
118234 +
118235 + asm_data.def_stmt = stmt;
118236 + asm_data.output = gimple_call_lhs(stmt);
118237 +
118238 + if (asm_data.output == NULL_TREE) {
118239 + asm_data.input = gimple_call_arg(stmt, 0);
118240 + if (is_gimple_constant(asm_data.input))
118241 + return false;
118242 + asm_data.output = NULL;
118243 + create_asm_stmt(asm_str, build_string(2, "rm"), NULL, &asm_data);
118244 + return true;
118245 + }
118246 +
118247 + create_asm_input(stmt, 0, &asm_data);
118248 + gcc_assert(asm_data.input != NULL_TREE);
118249 +
118250 + create_asm_stmt(asm_str, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
118251 + return true;
118252 +}
118253 +
118254 +static bool is_from_cast(const_tree node)
118255 +{
118256 + gimple def_stmt = get_def_stmt(node);
118257 +
118258 + if (!def_stmt)
118259 + return false;
118260 +
118261 + if (gimple_assign_cast_p(def_stmt))
118262 + return true;
118263 +
118264 + return false;
118265 +}
118266 +
118267 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
118268 +static bool skip_ptr_minus(gimple stmt)
118269 +{
118270 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
118271 +
118272 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
118273 + return false;
118274 +
118275 + rhs1 = gimple_assign_rhs1(stmt);
118276 + if (!is_from_cast(rhs1))
118277 + return false;
118278 +
118279 + rhs2 = gimple_assign_rhs2(stmt);
118280 + if (!is_from_cast(rhs2))
118281 + return false;
118282 +
118283 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
118284 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
118285 +
118286 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
118287 + return false;
118288 +
118289 + create_mark_asm(stmt, MARK_YES);
118290 + return true;
118291 +}
118292 +
118293 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
118294 +{
118295 + gimple def_stmt;
118296 +
118297 + def_stmt = get_def_stmt(lhs);
118298 + if (!def_stmt)
118299 + return;
118300 +
118301 + if (pointer_set_insert(visited, def_stmt))
118302 + return;
118303 +
118304 + switch (gimple_code(def_stmt)) {
118305 + case GIMPLE_NOP:
118306 + case GIMPLE_ASM:
118307 + case GIMPLE_CALL:
118308 + break;
118309 + case GIMPLE_PHI: {
118310 + unsigned int i, n = gimple_phi_num_args(def_stmt);
118311 +
118312 + pointer_set_insert(visited, def_stmt);
118313 +
118314 + for (i = 0; i < n; i++) {
118315 + tree arg = gimple_phi_arg_def(def_stmt, i);
118316 +
118317 + walk_use_def_ptr(visited, arg);
118318 + }
118319 + }
118320 + case GIMPLE_ASSIGN:
118321 + switch (gimple_num_ops(def_stmt)) {
118322 + case 2:
118323 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
118324 + return;
118325 + case 3:
118326 + if (skip_ptr_minus(def_stmt))
118327 + return;
118328 +
118329 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
118330 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
118331 + return;
118332 + default:
118333 + return;
118334 + }
118335 + default:
118336 + debug_gimple_stmt((gimple)def_stmt);
118337 + error("%s: unknown gimple code", __func__);
118338 + gcc_unreachable();
118339 + }
118340 +}
118341 +
118342 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
118343 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
118344 +{
118345 + struct pointer_set_t *visited;
118346 +
118347 + visited = pointer_set_create();
118348 + walk_use_def_ptr(visited, arg);
118349 + pointer_set_destroy(visited);
118350 +}
118351 +
118352 +// Determine the return value and insert the asm stmt to mark the return stmt.
118353 +static void insert_asm_ret(gimple stmt)
118354 +{
118355 + tree ret;
118356 +
118357 + ret = gimple_return_retval(stmt);
118358 + create_size_overflow_asm(stmt, ret, 0);
118359 +}
118360 +
118361 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
118362 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
118363 +{
118364 + tree arg;
118365 + unsigned int argnum;
118366 +
118367 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
118368 + gcc_assert(argnum != 0);
118369 + if (argnum == CANNOT_FIND_ARG)
118370 + return;
118371 +
118372 + arg = gimple_call_arg(stmt, argnum - 1);
118373 + gcc_assert(arg != NULL_TREE);
118374 +
118375 + // skip all ptr - ptr expressions
118376 + insert_mark_not_intentional_asm_at_ptr(arg);
118377 +
118378 + create_size_overflow_asm(stmt, arg, argnum);
118379 +}
118380 +
118381 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
118382 +static void set_argnum_attribute(const_tree attr, bool *argnums)
118383 +{
118384 + unsigned int argnum;
118385 + tree attr_value;
118386 +
118387 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
118388 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
118389 + argnums[argnum] = true;
118390 + }
118391 +}
118392 +
118393 +// If a function arg or the return value is in the hash table then set its index in the array.
118394 +static void set_argnum_hash(tree fndecl, bool *argnums)
118395 +{
118396 + unsigned int num;
118397 + const struct size_overflow_hash *hash;
118398 +
118399 + hash = get_function_hash(DECL_ORIGIN(fndecl));
118400 + if (!hash)
118401 + return;
118402 +
118403 + for (num = 0; num <= MAX_PARAM; num++) {
118404 + if (!(hash->param & (1U << num)))
118405 + continue;
118406 +
118407 + argnums[num] = true;
118408 + }
118409 +}
118410 +
118411 +static bool is_all_the_argnums_empty(bool *argnums)
118412 +{
118413 + unsigned int i;
118414 +
118415 + for (i = 0; i <= MAX_PARAM; i++)
118416 + if (argnums[i])
118417 + return false;
118418 + return true;
118419 +}
118420 +
118421 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
118422 +static void search_interesting_args(tree fndecl, bool *argnums)
118423 +{
118424 + const_tree attr;
118425 +
118426 + set_argnum_hash(fndecl, argnums);
118427 + if (!is_all_the_argnums_empty(argnums))
118428 + return;
118429 +
118430 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
118431 + if (attr && TREE_VALUE(attr))
118432 + set_argnum_attribute(attr, argnums);
118433 +}
118434 +
118435 +/*
118436 + * Look up the intentional_overflow attribute that turns off ipa based duplication
118437 + * on the callee function.
118438 + */
118439 +static bool is_mark_turn_off_attribute(gimple stmt)
118440 +{
118441 + enum mark mark;
118442 + const_tree fndecl = gimple_call_fndecl(stmt);
118443 +
118444 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
118445 + if (mark == MARK_TURN_OFF)
118446 + return true;
118447 + return false;
118448 +}
118449 +
118450 +// 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
118451 +static void handle_interesting_function(gimple stmt)
118452 +{
118453 + unsigned int argnum;
118454 + tree fndecl;
118455 + bool orig_argnums[MAX_PARAM + 1] = {false};
118456 +
118457 + if (gimple_call_num_args(stmt) == 0)
118458 + return;
118459 + fndecl = gimple_call_fndecl(stmt);
118460 + if (fndecl == NULL_TREE)
118461 + return;
118462 + fndecl = DECL_ORIGIN(fndecl);
118463 +
118464 + if (is_mark_turn_off_attribute(stmt)) {
118465 + create_mark_asm(stmt, MARK_TURN_OFF);
118466 + return;
118467 + }
118468 +
118469 + search_interesting_args(fndecl, orig_argnums);
118470 +
118471 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
118472 + if (orig_argnums[argnum])
118473 + insert_asm_arg(stmt, argnum);
118474 +}
118475 +
118476 +// 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
118477 +static void handle_interesting_ret(gimple stmt)
118478 +{
118479 + bool orig_argnums[MAX_PARAM + 1] = {false};
118480 +
118481 + search_interesting_args(current_function_decl, orig_argnums);
118482 +
118483 + if (orig_argnums[0])
118484 + insert_asm_ret(stmt);
118485 +}
118486 +
118487 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
118488 +static unsigned int search_interesting_functions(void)
118489 +{
118490 + basic_block bb;
118491 +
118492 + FOR_ALL_BB_FN(bb, cfun) {
118493 + gimple_stmt_iterator gsi;
118494 +
118495 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
118496 + gimple stmt = gsi_stmt(gsi);
118497 +
118498 + if (is_size_overflow_asm(stmt))
118499 + continue;
118500 +
118501 + if (is_gimple_call(stmt))
118502 + handle_interesting_function(stmt);
118503 + else if (gimple_code(stmt) == GIMPLE_RETURN)
118504 + handle_interesting_ret(stmt);
118505 + }
118506 + }
118507 + return 0;
118508 +}
118509 +
118510 +/*
118511 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
118512 + * this pass inserts asm stmts to mark the interesting args
118513 + * that the ipa pass will detect and insert the size overflow checks for.
118514 + */
118515 +#if BUILDING_GCC_VERSION >= 4009
118516 +static const struct pass_data insert_size_overflow_asm_pass_data = {
118517 +#else
118518 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
118519 + .pass = {
118520 +#endif
118521 + .type = GIMPLE_PASS,
118522 + .name = "insert_size_overflow_asm",
118523 +#if BUILDING_GCC_VERSION >= 4008
118524 + .optinfo_flags = OPTGROUP_NONE,
118525 +#endif
118526 +#if BUILDING_GCC_VERSION >= 4009
118527 + .has_gate = false,
118528 + .has_execute = true,
118529 +#else
118530 + .gate = NULL,
118531 + .execute = search_interesting_functions,
118532 + .sub = NULL,
118533 + .next = NULL,
118534 + .static_pass_number = 0,
118535 +#endif
118536 + .tv_id = TV_NONE,
118537 + .properties_required = PROP_cfg,
118538 + .properties_provided = 0,
118539 + .properties_destroyed = 0,
118540 + .todo_flags_start = 0,
118541 + .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
118542 +#if BUILDING_GCC_VERSION < 4009
118543 + }
118544 +#endif
118545 +};
118546 +
118547 +#if BUILDING_GCC_VERSION >= 4009
118548 +namespace {
118549 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
118550 +public:
118551 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
118552 + unsigned int execute() { return search_interesting_functions(); }
118553 +};
118554 +}
118555 +#endif
118556 +
118557 +static struct opt_pass *make_insert_size_overflow_asm_pass(void)
118558 +{
118559 +#if BUILDING_GCC_VERSION >= 4009
118560 + return new insert_size_overflow_asm_pass();
118561 +#else
118562 + return &insert_size_overflow_asm_pass.pass;
118563 +#endif
118564 +}
118565 +
118566 +// Create the noreturn report_size_overflow() function decl.
118567 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
118568 +{
118569 + tree const_char_ptr_type_node;
118570 + tree fntype;
118571 +
118572 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
118573 +
118574 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
118575 + fntype = build_function_type_list(void_type_node,
118576 + const_char_ptr_type_node,
118577 + unsigned_type_node,
118578 + const_char_ptr_type_node,
118579 + const_char_ptr_type_node,
118580 + NULL_TREE);
118581 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
118582 +
118583 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
118584 + TREE_PUBLIC(report_size_overflow_decl) = 1;
118585 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
118586 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
118587 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
118588 +}
118589 +
118590 +static unsigned int dump_functions(void)
118591 +{
118592 + struct cgraph_node *node;
118593 +
118594 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
118595 + basic_block bb;
118596 +
118597 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
118598 + current_function_decl = NODE_DECL(node);
118599 +
118600 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
118601 +
118602 + FOR_ALL_BB_FN(bb, cfun) {
118603 + gimple_stmt_iterator si;
118604 +
118605 + fprintf(stderr, "<bb %u>:\n", bb->index);
118606 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
118607 + debug_gimple_stmt(gsi_stmt(si));
118608 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
118609 + debug_gimple_stmt(gsi_stmt(si));
118610 + fprintf(stderr, "\n");
118611 + }
118612 +
118613 + fprintf(stderr, "-------------------------------------------------------------------------\n");
118614 +
118615 + pop_cfun();
118616 + current_function_decl = NULL_TREE;
118617 + }
118618 +
118619 + fprintf(stderr, "###############################################################################\n");
118620 +
118621 + return 0;
118622 +}
118623 +
118624 +#if BUILDING_GCC_VERSION >= 4009
118625 +static const struct pass_data dump_pass_data = {
118626 +#else
118627 +static struct ipa_opt_pass_d dump_pass = {
118628 + .pass = {
118629 +#endif
118630 + .type = SIMPLE_IPA_PASS,
118631 + .name = "dump",
118632 +#if BUILDING_GCC_VERSION >= 4008
118633 + .optinfo_flags = OPTGROUP_NONE,
118634 +#endif
118635 +#if BUILDING_GCC_VERSION >= 4009
118636 + .has_gate = false,
118637 + .has_execute = true,
118638 +#else
118639 + .gate = NULL,
118640 + .execute = dump_functions,
118641 + .sub = NULL,
118642 + .next = NULL,
118643 + .static_pass_number = 0,
118644 +#endif
118645 + .tv_id = TV_NONE,
118646 + .properties_required = 0,
118647 + .properties_provided = 0,
118648 + .properties_destroyed = 0,
118649 + .todo_flags_start = 0,
118650 + .todo_flags_finish = 0,
118651 +#if BUILDING_GCC_VERSION < 4009
118652 + },
118653 + .generate_summary = NULL,
118654 + .write_summary = NULL,
118655 + .read_summary = NULL,
118656 +#if BUILDING_GCC_VERSION >= 4006
118657 + .write_optimization_summary = NULL,
118658 + .read_optimization_summary = NULL,
118659 +#endif
118660 + .stmt_fixup = NULL,
118661 + .function_transform_todo_flags_start = 0,
118662 + .function_transform = NULL,
118663 + .variable_transform = NULL,
118664 +#endif
118665 +};
118666 +
118667 +#if BUILDING_GCC_VERSION >= 4009
118668 +namespace {
118669 +class dump_pass : public ipa_opt_pass_d {
118670 +public:
118671 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
118672 + unsigned int execute() { return dump_functions(); }
118673 +};
118674 +}
118675 +#endif
118676 +
118677 +static struct opt_pass *make_dump_pass(void)
118678 +{
118679 +#if BUILDING_GCC_VERSION >= 4009
118680 + return new dump_pass();
118681 +#else
118682 + return &dump_pass.pass;
118683 +#endif
118684 +}
118685 +
118686 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
118687 +{
118688 + int i;
118689 + const char * const plugin_name = plugin_info->base_name;
118690 + const int argc = plugin_info->argc;
118691 + const struct plugin_argument * const argv = plugin_info->argv;
118692 + bool enable = true;
118693 + struct register_pass_info insert_size_overflow_asm_pass_info;
118694 + struct register_pass_info __unused dump_before_pass_info;
118695 + struct register_pass_info __unused dump_after_pass_info;
118696 + struct register_pass_info ipa_pass_info;
118697 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
118698 + {
118699 + .base = &report_size_overflow_decl,
118700 + .nelt = 1,
118701 + .stride = sizeof(report_size_overflow_decl),
118702 + .cb = &gt_ggc_mx_tree_node,
118703 + .pchw = &gt_pch_nx_tree_node
118704 + },
118705 + LAST_GGC_ROOT_TAB
118706 + };
118707 +
118708 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
118709 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
118710 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
118711 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
118712 +
118713 + dump_before_pass_info.pass = make_dump_pass();
118714 + dump_before_pass_info.reference_pass_name = "increase_alignment";
118715 + dump_before_pass_info.ref_pass_instance_number = 1;
118716 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118717 +
118718 + ipa_pass_info.pass = make_ipa_pass();
118719 + ipa_pass_info.reference_pass_name = "increase_alignment";
118720 + ipa_pass_info.ref_pass_instance_number = 1;
118721 + ipa_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118722 +
118723 + dump_after_pass_info.pass = make_dump_pass();
118724 + dump_after_pass_info.reference_pass_name = "increase_alignment";
118725 + dump_after_pass_info.ref_pass_instance_number = 1;
118726 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118727 +
118728 + if (!plugin_default_version_check(version, &gcc_version)) {
118729 + error(G_("incompatible gcc/plugin versions"));
118730 + return 1;
118731 + }
118732 +
118733 + for (i = 0; i < argc; ++i) {
118734 + if (!strcmp(argv[i].key, "no-size-overflow")) {
118735 + enable = false;
118736 + continue;
118737 + }
118738 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
118739 + }
118740 +
118741 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
118742 + if (enable) {
118743 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
118744 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
118745 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
118746 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
118747 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &ipa_pass_info);
118748 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
118749 + }
118750 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
118751 +
118752 + return 0;
118753 +}
118754 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
118755 new file mode 100644
118756 index 0000000..5c0b937
118757 --- /dev/null
118758 +++ b/tools/gcc/stackleak_plugin.c
118759 @@ -0,0 +1,374 @@
118760 +/*
118761 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
118762 + * Licensed under the GPL v2
118763 + *
118764 + * Note: the choice of the license means that the compilation process is
118765 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
118766 + * but for the kernel it doesn't matter since it doesn't link against
118767 + * any of the gcc libraries
118768 + *
118769 + * gcc plugin to help implement various PaX features
118770 + *
118771 + * - track lowest stack pointer
118772 + *
118773 + * TODO:
118774 + * - initialize all local variables
118775 + *
118776 + * BUGS:
118777 + * - none known
118778 + */
118779 +
118780 +#include "gcc-common.h"
118781 +
118782 +int plugin_is_GPL_compatible;
118783 +
118784 +static int track_frame_size = -1;
118785 +static const char track_function[] = "pax_track_stack";
118786 +static const char check_function[] = "pax_check_alloca";
118787 +static tree track_function_decl, check_function_decl;
118788 +static bool init_locals;
118789 +
118790 +static struct plugin_info stackleak_plugin_info = {
118791 + .version = "201402131920",
118792 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
118793 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
118794 +};
118795 +
118796 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
118797 +{
118798 + gimple check_alloca;
118799 + tree alloca_size;
118800 +
118801 + // insert call to void pax_check_alloca(unsigned long size)
118802 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
118803 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
118804 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
118805 +}
118806 +
118807 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
118808 +{
118809 + gimple track_stack;
118810 +
118811 + // insert call to void pax_track_stack(void)
118812 + track_stack = gimple_build_call(track_function_decl, 0);
118813 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
118814 +}
118815 +
118816 +static bool is_alloca(gimple stmt)
118817 +{
118818 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
118819 + return true;
118820 +
118821 +#if BUILDING_GCC_VERSION >= 4007
118822 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
118823 + return true;
118824 +#endif
118825 +
118826 + return false;
118827 +}
118828 +
118829 +static unsigned int execute_stackleak_tree_instrument(void)
118830 +{
118831 + basic_block bb, entry_bb;
118832 + bool prologue_instrumented = false, is_leaf = true;
118833 +
118834 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
118835 +
118836 + // 1. loop through BBs and GIMPLE statements
118837 + FOR_EACH_BB_FN(bb, cfun) {
118838 + gimple_stmt_iterator gsi;
118839 +
118840 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
118841 + gimple stmt;
118842 +
118843 + stmt = gsi_stmt(gsi);
118844 +
118845 + if (is_gimple_call(stmt))
118846 + is_leaf = false;
118847 +
118848 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
118849 + if (!is_alloca(stmt))
118850 + continue;
118851 +
118852 + // 2. insert stack overflow check before each __builtin_alloca call
118853 + stackleak_check_alloca(&gsi);
118854 +
118855 + // 3. insert track call after each __builtin_alloca call
118856 + stackleak_add_instrumentation(&gsi);
118857 + if (bb == entry_bb)
118858 + prologue_instrumented = true;
118859 + }
118860 + }
118861 +
118862 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
118863 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
118864 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
118865 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
118866 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
118867 + return 0;
118868 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
118869 + return 0;
118870 +
118871 + // 4. insert track call at the beginning
118872 + if (!prologue_instrumented) {
118873 + gimple_stmt_iterator gsi;
118874 +
118875 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
118876 + if (dom_info_available_p(CDI_DOMINATORS))
118877 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
118878 + gsi = gsi_start_bb(bb);
118879 + stackleak_add_instrumentation(&gsi);
118880 + }
118881 +
118882 + return 0;
118883 +}
118884 +
118885 +static unsigned int execute_stackleak_final(void)
118886 +{
118887 + rtx insn, next;
118888 +
118889 + if (cfun->calls_alloca)
118890 + return 0;
118891 +
118892 + // keep calls only if function frame is big enough
118893 + if (get_frame_size() >= track_frame_size)
118894 + return 0;
118895 +
118896 + // 1. find pax_track_stack calls
118897 + for (insn = get_insns(); insn; insn = next) {
118898 + // 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))
118899 + rtx body;
118900 +
118901 + next = NEXT_INSN(insn);
118902 + if (!CALL_P(insn))
118903 + continue;
118904 + body = PATTERN(insn);
118905 + if (GET_CODE(body) != CALL)
118906 + continue;
118907 + body = XEXP(body, 0);
118908 + if (GET_CODE(body) != MEM)
118909 + continue;
118910 + body = XEXP(body, 0);
118911 + if (GET_CODE(body) != SYMBOL_REF)
118912 + continue;
118913 +// if (strcmp(XSTR(body, 0), track_function))
118914 + if (SYMBOL_REF_DECL(body) != track_function_decl)
118915 + continue;
118916 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
118917 + // 2. delete call
118918 + delete_insn_and_edges(insn);
118919 +#if BUILDING_GCC_VERSION >= 4007
118920 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
118921 + insn = next;
118922 + next = NEXT_INSN(insn);
118923 + delete_insn_and_edges(insn);
118924 + }
118925 +#endif
118926 + }
118927 +
118928 +// print_simple_rtl(stderr, get_insns());
118929 +// print_rtl(stderr, get_insns());
118930 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
118931 +
118932 + return 0;
118933 +}
118934 +
118935 +static bool gate_stackleak_track_stack(void)
118936 +{
118937 + return track_frame_size >= 0;
118938 +}
118939 +
118940 +static void stackleak_start_unit(void *gcc_data, void *user_data)
118941 +{
118942 + tree fntype;
118943 +
118944 + // void pax_track_stack(void)
118945 + fntype = build_function_type_list(void_type_node, NULL_TREE);
118946 + track_function_decl = build_fn_decl(track_function, fntype);
118947 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
118948 + TREE_PUBLIC(track_function_decl) = 1;
118949 + DECL_EXTERNAL(track_function_decl) = 1;
118950 + DECL_ARTIFICIAL(track_function_decl) = 1;
118951 +
118952 + // void pax_check_alloca(unsigned long)
118953 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
118954 + check_function_decl = build_fn_decl(check_function, fntype);
118955 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
118956 + TREE_PUBLIC(check_function_decl) = 1;
118957 + DECL_EXTERNAL(check_function_decl) = 1;
118958 + DECL_ARTIFICIAL(check_function_decl) = 1;
118959 +}
118960 +
118961 +#if BUILDING_GCC_VERSION >= 4009
118962 +static const struct pass_data stackleak_tree_instrument_pass_data = {
118963 +#else
118964 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
118965 + .pass = {
118966 +#endif
118967 + .type = GIMPLE_PASS,
118968 + .name = "stackleak_tree_instrument",
118969 +#if BUILDING_GCC_VERSION >= 4008
118970 + .optinfo_flags = OPTGROUP_NONE,
118971 +#endif
118972 +#if BUILDING_GCC_VERSION >= 4009
118973 + .has_gate = true,
118974 + .has_execute = true,
118975 +#else
118976 + .gate = gate_stackleak_track_stack,
118977 + .execute = execute_stackleak_tree_instrument,
118978 + .sub = NULL,
118979 + .next = NULL,
118980 + .static_pass_number = 0,
118981 +#endif
118982 + .tv_id = TV_NONE,
118983 + .properties_required = PROP_gimple_leh | PROP_cfg,
118984 + .properties_provided = 0,
118985 + .properties_destroyed = 0,
118986 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
118987 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
118988 +#if BUILDING_GCC_VERSION < 4009
118989 + }
118990 +#endif
118991 +};
118992 +
118993 +#if BUILDING_GCC_VERSION >= 4009
118994 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
118995 +#else
118996 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
118997 + .pass = {
118998 +#endif
118999 + .type = RTL_PASS,
119000 + .name = "stackleak_final",
119001 +#if BUILDING_GCC_VERSION >= 4008
119002 + .optinfo_flags = OPTGROUP_NONE,
119003 +#endif
119004 +#if BUILDING_GCC_VERSION >= 4009
119005 + .has_gate = true,
119006 + .has_execute = true,
119007 +#else
119008 + .gate = gate_stackleak_track_stack,
119009 + .execute = execute_stackleak_final,
119010 + .sub = NULL,
119011 + .next = NULL,
119012 + .static_pass_number = 0,
119013 +#endif
119014 + .tv_id = TV_NONE,
119015 + .properties_required = 0,
119016 + .properties_provided = 0,
119017 + .properties_destroyed = 0,
119018 + .todo_flags_start = 0,
119019 + .todo_flags_finish = TODO_dump_func
119020 +#if BUILDING_GCC_VERSION < 4009
119021 + }
119022 +#endif
119023 +};
119024 +
119025 +#if BUILDING_GCC_VERSION >= 4009
119026 +namespace {
119027 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
119028 +public:
119029 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
119030 + bool gate() { return gate_stackleak_track_stack(); }
119031 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
119032 +};
119033 +
119034 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
119035 +public:
119036 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
119037 + bool gate() { return gate_stackleak_track_stack(); }
119038 + unsigned int execute() { return execute_stackleak_final(); }
119039 +};
119040 +}
119041 +#endif
119042 +
119043 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
119044 +{
119045 +#if BUILDING_GCC_VERSION >= 4009
119046 + return new stackleak_tree_instrument_pass();
119047 +#else
119048 + return &stackleak_tree_instrument_pass.pass;
119049 +#endif
119050 +}
119051 +
119052 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
119053 +{
119054 +#if BUILDING_GCC_VERSION >= 4009
119055 + return new stackleak_final_rtl_opt_pass();
119056 +#else
119057 + return &stackleak_final_rtl_opt_pass.pass;
119058 +#endif
119059 +}
119060 +
119061 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
119062 +{
119063 + const char * const plugin_name = plugin_info->base_name;
119064 + const int argc = plugin_info->argc;
119065 + const struct plugin_argument * const argv = plugin_info->argv;
119066 + int i;
119067 + struct register_pass_info stackleak_tree_instrument_pass_info;
119068 + struct register_pass_info stackleak_final_pass_info;
119069 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
119070 + {
119071 + .base = &track_function_decl,
119072 + .nelt = 1,
119073 + .stride = sizeof(track_function_decl),
119074 + .cb = &gt_ggc_mx_tree_node,
119075 + .pchw = &gt_pch_nx_tree_node
119076 + },
119077 + {
119078 + .base = &check_function_decl,
119079 + .nelt = 1,
119080 + .stride = sizeof(check_function_decl),
119081 + .cb = &gt_ggc_mx_tree_node,
119082 + .pchw = &gt_pch_nx_tree_node
119083 + },
119084 + LAST_GGC_ROOT_TAB
119085 + };
119086 +
119087 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
119088 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
119089 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
119090 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
119091 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
119092 +
119093 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
119094 + stackleak_final_pass_info.reference_pass_name = "final";
119095 + stackleak_final_pass_info.ref_pass_instance_number = 1;
119096 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
119097 +
119098 + if (!plugin_default_version_check(version, &gcc_version)) {
119099 + error(G_("incompatible gcc/plugin versions"));
119100 + return 1;
119101 + }
119102 +
119103 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
119104 +
119105 + for (i = 0; i < argc; ++i) {
119106 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
119107 + if (!argv[i].value) {
119108 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
119109 + continue;
119110 + }
119111 + track_frame_size = atoi(argv[i].value);
119112 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
119113 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
119114 + continue;
119115 + }
119116 + if (!strcmp(argv[i].key, "initialize-locals")) {
119117 + if (argv[i].value) {
119118 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
119119 + continue;
119120 + }
119121 + init_locals = true;
119122 + continue;
119123 + }
119124 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
119125 + }
119126 +
119127 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
119128 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
119129 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
119130 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
119131 +
119132 + return 0;
119133 +}
119134 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
119135 new file mode 100644
119136 index 0000000..796569a
119137 --- /dev/null
119138 +++ b/tools/gcc/structleak_plugin.c
119139 @@ -0,0 +1,273 @@
119140 +/*
119141 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
119142 + * Licensed under the GPL v2
119143 + *
119144 + * Note: the choice of the license means that the compilation process is
119145 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
119146 + * but for the kernel it doesn't matter since it doesn't link against
119147 + * any of the gcc libraries
119148 + *
119149 + * gcc plugin to forcibly initialize certain local variables that could
119150 + * otherwise leak kernel stack to userland if they aren't properly initialized
119151 + * by later code
119152 + *
119153 + * Homepage: http://pax.grsecurity.net/
119154 + *
119155 + * Usage:
119156 + * $ # for 4.5/4.6/C based 4.7
119157 + * $ 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
119158 + * $ # for C++ based 4.7/4.8+
119159 + * $ 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
119160 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
119161 + *
119162 + * TODO: eliminate redundant initializers
119163 + * increase type coverage
119164 + */
119165 +
119166 +#include "gcc-common.h"
119167 +
119168 +// unused C type flag in all versions 4.5-4.9
119169 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
119170 +
119171 +int plugin_is_GPL_compatible;
119172 +
119173 +static struct plugin_info structleak_plugin_info = {
119174 + .version = "201401260140",
119175 + .help = "disable\tdo not activate plugin\n",
119176 +};
119177 +
119178 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
119179 +{
119180 + *no_add_attrs = true;
119181 +
119182 + // check for types? for now accept everything linux has to offer
119183 + if (TREE_CODE(*node) != FIELD_DECL)
119184 + return NULL_TREE;
119185 +
119186 + *no_add_attrs = false;
119187 + return NULL_TREE;
119188 +}
119189 +
119190 +static struct attribute_spec user_attr = {
119191 + .name = "user",
119192 + .min_length = 0,
119193 + .max_length = 0,
119194 + .decl_required = false,
119195 + .type_required = false,
119196 + .function_type_required = false,
119197 + .handler = handle_user_attribute,
119198 +#if BUILDING_GCC_VERSION >= 4007
119199 + .affects_type_identity = true
119200 +#endif
119201 +};
119202 +
119203 +static void register_attributes(void *event_data, void *data)
119204 +{
119205 + register_attribute(&user_attr);
119206 +// register_attribute(&force_attr);
119207 +}
119208 +
119209 +static tree get_field_type(tree field)
119210 +{
119211 + return strip_array_types(TREE_TYPE(field));
119212 +}
119213 +
119214 +static bool is_userspace_type(tree type)
119215 +{
119216 + tree field;
119217 +
119218 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
119219 + tree fieldtype = get_field_type(field);
119220 + enum tree_code code = TREE_CODE(fieldtype);
119221 +
119222 + if (code == RECORD_TYPE || code == UNION_TYPE)
119223 + if (is_userspace_type(fieldtype))
119224 + return true;
119225 +
119226 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
119227 + return true;
119228 + }
119229 + return false;
119230 +}
119231 +
119232 +static void finish_type(void *event_data, void *data)
119233 +{
119234 + tree type = (tree)event_data;
119235 +
119236 + if (TYPE_USERSPACE(type))
119237 + return;
119238 +
119239 + if (is_userspace_type(type))
119240 + TYPE_USERSPACE(type) = 1;
119241 +}
119242 +
119243 +static void initialize(tree var)
119244 +{
119245 + basic_block bb;
119246 + gimple_stmt_iterator gsi;
119247 + tree initializer;
119248 + gimple init_stmt;
119249 +
119250 + // this is the original entry bb before the forced split
119251 + // TODO: check further BBs in case more splits occured before us
119252 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
119253 +
119254 + // first check if the variable is already initialized, warn otherwise
119255 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
119256 + gimple stmt = gsi_stmt(gsi);
119257 + tree rhs1;
119258 +
119259 + // we're looking for an assignment of a single rhs...
119260 + if (!gimple_assign_single_p(stmt))
119261 + continue;
119262 + rhs1 = gimple_assign_rhs1(stmt);
119263 +#if BUILDING_GCC_VERSION >= 4007
119264 + // ... of a non-clobbering expression...
119265 + if (TREE_CLOBBER_P(rhs1))
119266 + continue;
119267 +#endif
119268 + // ... to our variable...
119269 + if (gimple_get_lhs(stmt) != var)
119270 + continue;
119271 + // if it's an initializer then we're good
119272 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
119273 + return;
119274 + }
119275 +
119276 + // these aren't the 0days you're looking for
119277 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
119278 +
119279 + // build the initializer expression
119280 + initializer = build_constructor(TREE_TYPE(var), NULL);
119281 +
119282 + // build the initializer stmt
119283 + init_stmt = gimple_build_assign(var, initializer);
119284 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
119285 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
119286 + update_stmt(init_stmt);
119287 +}
119288 +
119289 +static unsigned int handle_function(void)
119290 +{
119291 + basic_block bb;
119292 + unsigned int ret = 0;
119293 + tree var;
119294 + unsigned int i;
119295 +
119296 + // split the first bb where we can put the forced initializers
119297 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
119298 + if (dom_info_available_p(CDI_DOMINATORS))
119299 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
119300 +
119301 + // enumarate all local variables and forcibly initialize our targets
119302 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
119303 + tree type = TREE_TYPE(var);
119304 +
119305 + gcc_assert(DECL_P(var));
119306 + if (!auto_var_in_fn_p(var, current_function_decl))
119307 + continue;
119308 +
119309 + // only care about structure types
119310 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
119311 + continue;
119312 +
119313 + // if the type is of interest, examine the variable
119314 + if (TYPE_USERSPACE(type))
119315 + initialize(var);
119316 + }
119317 +
119318 + return ret;
119319 +}
119320 +
119321 +#if BUILDING_GCC_VERSION >= 4009
119322 +static const struct pass_data structleak_pass_data = {
119323 +#else
119324 +static struct gimple_opt_pass structleak_pass = {
119325 + .pass = {
119326 +#endif
119327 + .type = GIMPLE_PASS,
119328 + .name = "structleak",
119329 +#if BUILDING_GCC_VERSION >= 4008
119330 + .optinfo_flags = OPTGROUP_NONE,
119331 +#endif
119332 +#if BUILDING_GCC_VERSION >= 4009
119333 + .has_gate = false,
119334 + .has_execute = true,
119335 +#else
119336 + .gate = NULL,
119337 + .execute = handle_function,
119338 + .sub = NULL,
119339 + .next = NULL,
119340 + .static_pass_number = 0,
119341 +#endif
119342 + .tv_id = TV_NONE,
119343 + .properties_required = PROP_cfg,
119344 + .properties_provided = 0,
119345 + .properties_destroyed = 0,
119346 + .todo_flags_start = 0,
119347 + .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
119348 +#if BUILDING_GCC_VERSION < 4009
119349 + }
119350 +#endif
119351 +};
119352 +
119353 +#if BUILDING_GCC_VERSION >= 4009
119354 +namespace {
119355 +class structleak_pass : public gimple_opt_pass {
119356 +public:
119357 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
119358 + unsigned int execute() { return handle_function(); }
119359 +};
119360 +}
119361 +#endif
119362 +
119363 +static struct opt_pass *make_structleak_pass(void)
119364 +{
119365 +#if BUILDING_GCC_VERSION >= 4009
119366 + return new structleak_pass();
119367 +#else
119368 + return &structleak_pass.pass;
119369 +#endif
119370 +}
119371 +
119372 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
119373 +{
119374 + int i;
119375 + const char * const plugin_name = plugin_info->base_name;
119376 + const int argc = plugin_info->argc;
119377 + const struct plugin_argument * const argv = plugin_info->argv;
119378 + bool enable = true;
119379 + struct register_pass_info structleak_pass_info;
119380 +
119381 + structleak_pass_info.pass = make_structleak_pass();
119382 + structleak_pass_info.reference_pass_name = "ssa";
119383 + structleak_pass_info.ref_pass_instance_number = 1;
119384 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
119385 +
119386 + if (!plugin_default_version_check(version, &gcc_version)) {
119387 + error(G_("incompatible gcc/plugin versions"));
119388 + return 1;
119389 + }
119390 +
119391 + if (strcmp(lang_hooks.name, "GNU C")) {
119392 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
119393 + enable = false;
119394 + }
119395 +
119396 + for (i = 0; i < argc; ++i) {
119397 + if (!strcmp(argv[i].key, "disable")) {
119398 + enable = false;
119399 + continue;
119400 + }
119401 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
119402 + }
119403 +
119404 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
119405 + if (enable) {
119406 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
119407 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
119408 + }
119409 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
119410 +
119411 + return 0;
119412 +}
119413 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
119414 index fbc6665..5e9ce79 100644
119415 --- a/tools/include/linux/compiler.h
119416 +++ b/tools/include/linux/compiler.h
119417 @@ -35,4 +35,12 @@
119418 # define unlikely(x) __builtin_expect(!!(x), 0)
119419 #endif
119420
119421 +#ifndef __size_overflow
119422 +# define __size_overflow(...)
119423 +#endif
119424 +
119425 +#ifndef __intentional_overflow
119426 +# define __intentional_overflow(...)
119427 +#endif
119428 +
119429 #endif /* _TOOLS_LINUX_COMPILER_H */
119430 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
119431 index ed2f51e..cc2d8f6 100644
119432 --- a/tools/lib/api/Makefile
119433 +++ b/tools/lib/api/Makefile
119434 @@ -14,7 +14,7 @@ LIB_OBJS += $(OUTPUT)fs/debugfs.o
119435
119436 LIBFILE = libapikfs.a
119437
119438 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
119439 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
119440 EXTLIBS = -lelf -lpthread -lrt -lm
119441 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
119442 ALL_LDFLAGS = $(LDFLAGS)
119443 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
119444 index 6789d78..4afd019e 100644
119445 --- a/tools/perf/util/include/asm/alternative-asm.h
119446 +++ b/tools/perf/util/include/asm/alternative-asm.h
119447 @@ -5,4 +5,7 @@
119448
119449 #define altinstruction_entry #
119450
119451 + .macro pax_force_retaddr rip=0, reload=0
119452 + .endm
119453 +
119454 #endif
119455 diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c
119456 index ce9ed99..8c805a0 100644
119457 --- a/virt/kvm/ioapic.c
119458 +++ b/virt/kvm/ioapic.c
119459 @@ -306,7 +306,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq, bool line_status)
119460 BUG_ON(ioapic->rtc_status.pending_eoi != 0);
119461 ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe,
119462 ioapic->rtc_status.dest_map);
119463 - ioapic->rtc_status.pending_eoi = ret;
119464 + ioapic->rtc_status.pending_eoi = (ret < 0 ? 0 : ret);
119465 } else
119466 ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe, NULL);
119467
119468 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
119469 index 03a0381..8b31923 100644
119470 --- a/virt/kvm/kvm_main.c
119471 +++ b/virt/kvm/kvm_main.c
119472 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
119473
119474 static cpumask_var_t cpus_hardware_enabled;
119475 static int kvm_usage_count = 0;
119476 -static atomic_t hardware_enable_failed;
119477 +static atomic_unchecked_t hardware_enable_failed;
119478
119479 struct kmem_cache *kvm_vcpu_cache;
119480 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
119481
119482 -static __read_mostly struct preempt_ops kvm_preempt_ops;
119483 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
119484 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
119485 +static struct preempt_ops kvm_preempt_ops = {
119486 + .sched_in = kvm_sched_in,
119487 + .sched_out = kvm_sched_out,
119488 +};
119489
119490 struct dentry *kvm_debugfs_dir;
119491
119492 @@ -758,7 +763,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
119493 /* We can read the guest memory with __xxx_user() later on. */
119494 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
119495 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
119496 - !access_ok(VERIFY_WRITE,
119497 + !access_ok_noprefault(VERIFY_WRITE,
119498 (void __user *)(unsigned long)mem->userspace_addr,
119499 mem->memory_size)))
119500 goto out;
119501 @@ -1615,9 +1620,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
119502
119503 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
119504 {
119505 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
119506 + int r;
119507 + unsigned long addr;
119508
119509 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
119510 + addr = gfn_to_hva(kvm, gfn);
119511 + if (kvm_is_error_hva(addr))
119512 + return -EFAULT;
119513 + r = __clear_user((void __user *)addr + offset, len);
119514 + if (r)
119515 + return -EFAULT;
119516 + mark_page_dirty(kvm, gfn);
119517 + return 0;
119518 }
119519 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
119520
119521 @@ -1867,7 +1880,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
119522 return 0;
119523 }
119524
119525 -static struct file_operations kvm_vcpu_fops = {
119526 +static file_operations_no_const kvm_vcpu_fops __read_only = {
119527 .release = kvm_vcpu_release,
119528 .unlocked_ioctl = kvm_vcpu_ioctl,
119529 #ifdef CONFIG_COMPAT
119530 @@ -2532,7 +2545,7 @@ out:
119531 }
119532 #endif
119533
119534 -static struct file_operations kvm_vm_fops = {
119535 +static file_operations_no_const kvm_vm_fops __read_only = {
119536 .release = kvm_vm_release,
119537 .unlocked_ioctl = kvm_vm_ioctl,
119538 #ifdef CONFIG_COMPAT
119539 @@ -2632,7 +2645,7 @@ out:
119540 return r;
119541 }
119542
119543 -static struct file_operations kvm_chardev_ops = {
119544 +static file_operations_no_const kvm_chardev_ops __read_only = {
119545 .unlocked_ioctl = kvm_dev_ioctl,
119546 .compat_ioctl = kvm_dev_ioctl,
119547 .llseek = noop_llseek,
119548 @@ -2658,7 +2671,7 @@ static void hardware_enable_nolock(void *junk)
119549
119550 if (r) {
119551 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
119552 - atomic_inc(&hardware_enable_failed);
119553 + atomic_inc_unchecked(&hardware_enable_failed);
119554 printk(KERN_INFO "kvm: enabling virtualization on "
119555 "CPU%d failed\n", cpu);
119556 }
119557 @@ -2714,10 +2727,10 @@ static int hardware_enable_all(void)
119558
119559 kvm_usage_count++;
119560 if (kvm_usage_count == 1) {
119561 - atomic_set(&hardware_enable_failed, 0);
119562 + atomic_set_unchecked(&hardware_enable_failed, 0);
119563 on_each_cpu(hardware_enable_nolock, NULL, 1);
119564
119565 - if (atomic_read(&hardware_enable_failed)) {
119566 + if (atomic_read_unchecked(&hardware_enable_failed)) {
119567 hardware_disable_all_nolock();
119568 r = -EBUSY;
119569 }
119570 @@ -3121,7 +3134,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
119571 kvm_arch_vcpu_put(vcpu);
119572 }
119573
119574 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119575 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119576 struct module *module)
119577 {
119578 int r;
119579 @@ -3168,7 +3181,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119580 if (!vcpu_align)
119581 vcpu_align = __alignof__(struct kvm_vcpu);
119582 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
119583 - 0, NULL);
119584 + SLAB_USERCOPY, NULL);
119585 if (!kvm_vcpu_cache) {
119586 r = -ENOMEM;
119587 goto out_free_3;
119588 @@ -3178,9 +3191,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119589 if (r)
119590 goto out_free;
119591
119592 + pax_open_kernel();
119593 kvm_chardev_ops.owner = module;
119594 kvm_vm_fops.owner = module;
119595 kvm_vcpu_fops.owner = module;
119596 + pax_close_kernel();
119597
119598 r = misc_register(&kvm_dev);
119599 if (r) {
119600 @@ -3190,9 +3205,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119601
119602 register_syscore_ops(&kvm_syscore_ops);
119603
119604 - kvm_preempt_ops.sched_in = kvm_sched_in;
119605 - kvm_preempt_ops.sched_out = kvm_sched_out;
119606 -
119607 r = kvm_init_debug();
119608 if (r) {
119609 printk(KERN_ERR "kvm: create debugfs files failed\n");